artblocks-contracts icon indicating copy to clipboard operation
artblocks-contracts copied to clipboard

Set-price ETH minter, in Vyper (reference implementation)

Open jakerockland opened this issue 2 years ago • 5 comments

This is a proof-of-concept of writing a minter that is written in Vyper rather than Solidity, while being compatible with the broader existing MinterSuite architecture, in the interest of exploring whether or not re-writing our minter contracts in Vyper may unlock improved gas performance for minting which in turn would provide an improved experience to collectors from a cost-perspective.

Additionally, in my opinion there are benefits to using Vyper from a language safety perspective, due to the rigorous approach taken by the Vyper team with how the language is designed: https://vyper.readthedocs.io/en/stable/#principles-and-goals

This PR is currently very much a work-in-progress and an exploration. If we are to find that there are not meaningful gas savings with this Solidity-->Vyper switch, we likely should abandon this approach for now.

Due to an issue I was currently running into with the Vyper<->hardhat integration (https://github.com/NomicFoundation/hardhat/issues/2812), I have not yet integrated the build process for this new Vyper contract into our compilation steps nor written any unit-tests for this new minter implementation. Nor have I yet had any bandwidth to do manual deployment/testing of this minter with our testnet setups.

That said, I have verified that this contract indeed compiles without issue while conforming to the IFilteredMinterV0 interface (I've made the compiler happy at the least), which I have currently been verifying for development purposes by installing and running the Vyper compile locally with:

$ python3 -m venv env && source env/bin/activate && pip install -r requirements.txt
$ vyper contracts/minter-suite/minter_set_price_v1.vy

Which spits out some tasty bytecode:

0x6020610d716000396000518060a01c610d6c576040526020610d916000396000518060a01c610d6c5760605260106080527f4d696e746572536574507269636556310000000000000000000000000000000060a05260808051806001556020820180516002555050506040516300000c1d526040516300000c3d526060516300000c5d526060516300000c7d526040516392a10f83608052602060806004609c60006300000c7d515af16100b8573d600060003e3d6000fd5b60203d10610d6c576080518060a01c610d6c5760c05260c0511461013557601860e0527f496c6c6567616c20636f6e74726163742070616972696e6700000000000000006101005260e05060e051806101000181600003601f1636823750506308c379a060a052602060c052601f19601f60e051011660440160bcfd5b610c1d61014e630000000039610c1d6080016300000000f3600436101561000d576106be565b60003560e01c63efef39a1811861004d57600054610c185760016000556020336101a0526004356101c0526100436102806109a0565b6102806000600055f35b63891407c08118610099576004358060a01c610c185761028052600054610c185760016000556020610280516101a0526024356101c05261008f6102a06109a0565b6102a06000600055f35b34610c18576392a10f8381186100bd576020610c1d60003960005160405260206040f35b63dd85582f81186100dc576020610c5d60003960005160405260206040f35b63f7bd4b88811861030657633af32abf60405233606052602060406024605c6020610c3d6000396000515afa610117573d600060003e3d6000fd5b60203d10610c18576040518060011c610c185760805260805161019157601560a0527f4f6e6c7920436f72652077686974656c6973746564000000000000000000000060c05260a05060a0518060c00181600003601f1636823750506308c379a06060526020608052601f19601f60a0510116604401607cfd5b60e036604037600061016052610160805180610120525050600061016052638c2c3622610180526004356101a052610160610180602461019c6020610c3d6000396000515afa6101e6573d600060003e3d6000fd5b6101403d10610c1857610180518060a01c610c1857610300526101a051610320526101c051610340526101e05161036052610200518060011c610c185761038052610220518060a01c610c18576103a052610240516103c05261026051610180016008815111610c18578051806103e05260208201805161040052505050610280518060a01c610c1857610420526103008051608052602081015160a05260408101516040526060810151606052608081015160c05260a081015160e05260c08101516101005260e08101805180610120526020820180516101405250505061012081015161016052506060516004600435602052600052604060002055606051604051101561030457600060036004356020526000526040600020555b005b6340d1397e811861041d5763a47d29cb604052600435606052602060406024605c6020610c3d6000396000515afa610343573d600060003e3d6000fd5b60203d10610c18576040518060a01c610c185760805260805133146103bf57600b60a0527f4f6e6c792041727469737400000000000000000000000000000000000000000060c05260a05060a0518060c00181600003601f1636823750506308c379a06060526020608052601f19601f60a0510116604401607cfd5b60146040527f416374696f6e206e6f7420737570706f727465640000000000000000000000006060526040506040518060600181600003601f1636823750506308c379a06000526020602052601f19601f6040510116604401601cfd005b636cb9b7ff811861052b5763a47d29cb604052600435606052602060406024605c6020610c3d6000396000515afa61045a573d600060003e3d6000fd5b60203d10610c18576040518060a01c610c185760805260805133146104d657600b60a0527f4f6e6c792041727469737400000000000000000000000000000000000000000060c05260a05060a0518060c00181600003601f1636823750506308c379a06060526020608052601f19601f60a0510116604401607cfd5b6024356005600435602052600052604060002055600160066004356020526000526040600020556024356004357f26118a27aca826f829f3bfe21b140b4455c00b434849bd0da50d1e1a9720fb5c60006040a3005b63774159c681186105d85760806006600435602052600052604060002054608052600560043560205260005260406000205460a0528060c05260036040527f45544800000000000000000000000000000000000000000000000000000000006060526040816080018151808252602083016020830181518152505050805180602083010181600003601f163682375050601f19601f825160200101169050905081019050600060e0526080f35b63e9d1e8ac811861062857602080604052806040016001548082526020820160025481525050805180602083010181600003601f163682375050601f19601f825160200101169050810190506040f35b63462add46811861064d57600360043560205260005260406000205460405260206040f35b6356690aaf811861067257600460043560205260005260406000205460405260206040f35b63f70c0f04811861069757600560043560205260005260406000205460405260206040f35b632cfbc88581186106bc57600660043560205260005260406000205460405260206040f35b505b60006000fd5b346106ce5761099e565b600560405160205260005260406000205460605234606051808210610c18578082039050905060805260006080511115610717576000600060006000608051336000f115610c18575b606051634f029c3960c052602060c0600460dc6020610c3d6000396000515afa610746573d600060003e3d6000fd5b60203d10610c185760c051808202821582848304141715610c18579050905060648082049050905060a052600060a05111156107d757600060006000600060a051633949f90660c052602060c0600460dc6020610c3d6000396000515afa6107b3573d600060003e3d6000fd5b60203d10610c185760c0518060a01c610c185761010052610100516000f115610c18575b60605160a051808210610c18578082039050905060c052600060e052600063cc74234b61010052604051610120526020610100602461011c6020610c3d6000396000515afa61082b573d600060003e3d6000fd5b60203d10610c18576101005111156109135760c05163cc74234b61014052604051610160526020610140602461015c6020610c3d6000396000515afa610876573d600060003e3d6000fd5b60203d10610c185761014051808202821582848304141715610c18579050905060648082049050905060e052600060e051111561091357600060006000600060e05163d7b044b661014052604051610160526020610140602461015c6020610c3d6000396000515afa6108ee573d600060003e3d6000fd5b60203d10610c1857610140518060a01c610c185761018052610180516000f115610c18575b60c05160e051808210610c18578082039050905061010052600061010051111561099e5760006000600060006101005163a47d29cb61012052604051610140526020610120602461013c6020610c3d6000396000515afa610979573d600060003e3d6000fd5b60203d10610c1857610120518060a01c610c185761016052610160516000f115610c18575b565b60036101c05160205260005260406000205415610a425760256101e0527f4d6178696d756d206e756d626572206f6620696e766f636174696f6e73207265610200527f6163686564000000000000000000000000000000000000000000000000000000610220526101e0506101e051806102000181600003601f1636823750506308c379a06101a05260206101c052601f19601f6101e05101166044016101bcfd5b60066101c051602052600052604060002054610abe5760146101e0527f5072696365206e6f7420636f6e66696775726564000000000000000000000000610200526101e0506101e051806102000181600003601f1636823750506308c379a06101a05260206101c052601f19601f6101e05101166044016101bcfd5b60056101c051602052600052604060002054341015610b3d5760206101e0527f4d7573742073656e64206d696e696d756d2076616c756520746f206d696e7421610200526101e0506101e051806102000181600003601f1636823750506308c379a06101a05260206101c052601f19601f6101e05101166044016101bcfd5b630d4d1513610200526101a051610220526101c0516102405233610260526020610200606461021c60006020610c7d6000396000515af1610b83573d600060003e3d6000fd5b60203d10610c1857610200516101e052600060046101c05160205260005260406000205411610bb3576000610be6565b60046101c0516020526000526040600020546001808210610c1857808203905090506101e051620f424080820690509050145b15610c0057600160036101c0516020526000526040600020555b6101c051604052610c0f6106c4565b6101e051815250565b600080fd005b600080fd

While we have yet to do any gas profiling of this against the existing MinterSetPriceV1 minter, it is interesting to note that size-wise this Vyper variant of the minter is meaningfully smaller, only being ~7kb vs. ~12kb–very interested to see how our gas-cost profiling shakes out.

jakerockland avatar Jun 10 '22 01:06 jakerockland

From some initial manual profiling, initial test mints suggest that this Vyper port does not provide gas savings due to compiler performance that would be passed on to minters.

https://gist.github.com/jakerockland/be6648e48b84acb0b6902e1d457c5767

That said, Ryley pointed out that this reference implementation is still worthwhile as an example for potential minter contributors/developers who are more Python-familiar and who may want to use this as a starting place for proposed minters to be added to the suite.

With that context in mind (this being a reference implementation) I'm not sure that we need to block this PR on resolution of https://github.com/NomicFoundation/hardhat/issues/2812 and rather can follow up w/ hardhat integrations as a separate effort once that issue is resolved, so I'm going to move this out of draft mode.

jakerockland avatar Jun 10 '22 05:06 jakerockland

I believe the item holding this up may have been fixed: https://github.com/vyperlang/vyper/issues/2903#issuecomment-1370273109

ryley-o avatar Jan 12 '23 00:01 ryley-o

I believe the item holding this up may have been fixed: vyperlang/vyper#2903 (comment)

Indeed–very rad. I will have to loop back and TAL at this again–unless you'd like to ser.

jakerockland avatar Jan 12 '23 17:01 jakerockland

Still running into minor issue here, though this is definitely surmountable if we want to merge (filed https://github.com/vyperlang/vyper/issues/3329).

That said, I've updated this reference implementation for better reference and with the goal that if we can get a good updated working reference implementation working it may be worth another benchmark at some point down the road.

Potentially is meaningful even to have a working reference for collaborators/partners who want to branch off of this to implement their own minters for the minter suite – especially as we move towards a unified shared minter suite across all V3 contracts)

Mostly though, this is fun to have this example (though now it is pretty outdated w/ latest minter suite setup) 😄

Another note – hardhat vyper plugin is now working as expected for compilations! 🙌

jakerockland avatar Mar 31 '23 23:03 jakerockland

Vyper folks very quickly fixed the issue I surfaced 🙌

https://github.com/vyperlang/vyper/pull/3334

Once this lands in release cut, I'll update this PR to incorporate the changes.

jakerockland avatar Apr 10 '23 17:04 jakerockland

Going to close this PR to clean up the pending PRs in this repo. PR will remain available in closed state as a point of reference in the future if we ever want to consider building a vyper-based shared minter contract in the future 👍

ryley-o avatar Jun 04 '24 18:06 ryley-o