The highly-anticipated virtual land sale related to the Bored Ape Yacht Club went live hours ago and affected a large portion of the entire crypto market. The massive demand led to ETH fees worth nearly $200 million to be spent on gas for the land sale in one hour. This is because their contract had nearly zero gas optimizations.
Will Papper, the co-founder of Syndicate DAO, tweeted a few “tricks” that could have “saved many millions.” Here are some parts of the Twitter thread:
Gas optimization 1: Remove the ERC721Enumerable extension.
https://preview.redd.it/h36vcy84ouw81.png?1200&format=png&auto=webp&s=0fe910f48ab3529bf7f5abba2c4d4aab3d677602
The ERC721Enumerable extension is used to track the owners of an NFT on-chain. Mints that remove the ERC721Enumerable extension save around 70% in gas costs. This tiny change would have saved around $70M that hour. The ERC721Enumerable extension is mostly unnecessary. In the majority of cases, tracking ownership on-chain is not useful. Why? You can just grab the data off-chain on the front-end and pass it into smart contracts instead! Every front-end is able to handle this easily.
Gas optimization 2: Use ERC721A (erc721a.org). ERC721A is a standard developed by the @AzukiOfficial team.
This extension means that minting multiple NFTs to the same wallet is nearly the same price as minting a single NFT. This would save money for every multi-mint. ERC721A makes transfers slightly more expensive but mints dramatically cheaper. In this case where the gas fees on the mint are so high, this is clearly worth it. The vast majority of the mints were multi-mints. All of these incurred 2X or more in unnecessary costs ($10M+)
Gas optimization 3: Switch from _safeMint() to _mint()
https://preview.redd.it/8p5c8zg8ouw81.png?1199&format=png&auto=webp&s=a1cf3f45f2826502d7ea517cf948d8573adb9b70
_safeMint() checks every address to ensure that it can handle NFTs. If the address is not able to handle NFTs, it ensures that the transaction will fail. This is unnecessary. Every address minting can likely handle NFTs. Image _safeMint() is one of the more annoying and unnecessary parts of the ERC721 standard. In theory it ensures that mints are going to wallets that can handle NFTs, in practice it adds gas and makes mints less safe!
https://preview.redd.it/ahzeq1neouw81.png?1199&format=png&auto=webp&s=1719f786d9941d7690cfa7b833f0bea33ce609d3
This condition is only hit for very non-standard smart contracts. Image Implementing these gas optimizations would be as simple as:
- Change the word "ERC721Enumerable" to "ERC721"
- Import ERC721A
- Change the word "_safeMint()" to "_mint()"
Modifying a few words would have saved $80M+.
Yuga Labs also addressed the event
https://preview.redd.it/c669czzoouw81.png?1058&format=png&auto=webp&s=09b6b7ef2a5cfe22ed3ebcc334c1d2e76af6d96f
I have my own little conspiracy theory that they had this inefficient launch on purpose to justify having an “ApeChain”.
I actually think it’s kind of neat that the ETH got burned because of yuga’s carelessness (and my selfishness lol). Instead of that $100m going to yuga and the apes, it got kinda redistributed to every other ETH holder.
submitted by
Comments