Open Sourcing the Art Gobblers Smart Contracts
Raw Text
About
Team
Portfolio
Writing
Fellowship
Opportunities
Contact
About
Portfolio
Opportunities
Contact
Team
Writing
Fellowship
Sep 20, 2022 | Frankie , Transmissions11 , Dave White , Justin Roiland
Contents
Introduction
Diving into the Contracts Custom ERC721 Implementations GobblersERC721 PagesERC721 Integrating GOO Progressive Reveals Testing and Security Testing Incentivized Play Testing Audits and C4 Contest
Custom ERC721 Implementations GobblersERC721 PagesERC721
GobblersERC721
PagesERC721
Integrating GOO
Progressive Reveals
Testing and Security Testing Incentivized Play Testing Audits and C4 Contest
Testing
Incentivized Play Testing
Audits and C4 Contest
Conclusion
Introduction
Today, we’re excited to announce that the Art Gobblers smart contracts are open source and available on our Github repo . We hope the systems we’ve built will capture your imagination, and we can’t wait to see what you’ll build on top of them.
Diving into the Contracts
In this post, we want to highlight a few of the interesting parts of the Art Gobblers codebase, like our custom ERC721 implementations, GOO integration, our progressive reveal system, and our approach to testing.
Custom ERC721 Implementations
GobblersERC721
Art Gobblers is significantly more complex than the average NFT project. Gobblers are sold using a VRGDA , and are paid for with a custom utility token (Goo). On top of this, each Gobbler is assigned an “emission multiple”, which determines the rate at which it continuously generates Goo tokens, using GOO issuance .
Nevertheless, we wanted the gas costs of minting & transferring Gobbler NFTs to be one of the lowest in the industry.
To achieve this, we built a custom ERC721 implementation that makes heavy use of struct packing to remain efficient. We are able to fit all of the state associated with each gobbler and user in the mappings typically used for owner and balance information.
For Gobbler state, we pack each Gobbler’s 160 bit owner address with 2 other variables: idx and emissionMultiple :
For owner state, we pack a 32 bit count of the gobblers owned by that user with 3 other variables related to GOO issuance: emissionMultiple , lastBalance and lastTimestamp :
While under the hood all this data is packed together in one 256 bit slot, GobblersERC721 is still 100% compliant with the ERC721 interface, thanks to helper functions which expose the specific storage sections needed for ownerOf and balanceOf :
Additionally, GobblersERC721 also features optimizations that leverage fundamental invariants of the Art Gobblers system (no tokens will be minted to address(0) , the supply cap of 10,000 , etc) to remove redundant assertions.
PagesERC721
Pages, while significantly less complex than Gobblers, also use a modified ERC721 implementation to improve improve gas costs and UX around feeding pages to gobblers.
Primarily, Pages automatically skip approval checks when being transferred by the Gobblers contract to make gobbling a single shot process with no extra hassle.
And, like Gobblers, Pages utilize known invariants of the Art Gobblers system to remove redundant assertions in their minting logic.
Integrating GOO
Gobblers generate Goo at a specified emission rate, which we discuss in GOO paper . Because Goo is generated continuously over time, goo balances need to be computed lazily. That is, a virtual balance is tracked which can be exchanged for a regular ERC20 balance at the user's convenience.
Because this virtual balance is a function of the user’s total emission multiple, one has to make sure that it remains correct when transfers happen. For example, when a user transfers a gobbler away, their total emission multiple should go down (and so should their future emissions), but their current Goo balance should not change.
In order to get around this, we overrode Gobbler’s transfer function to ensure that proper snapshots are taken of the user's state.
Since virtual balances are used to keep track of Goo, we wanted to avoid purchases being a multi-transaction process. Normally, users would have to submit one transaction to turn their virtual balance into a regular ERC20 balance, one transaction to approve Gobblers as a Goo spender, and another transaction to purchase the items.
To streamline this process, we modified the purchase functions in both Gobblers and Pages so that users are able to spend directly from their virtual balances, and set up permissions between contracts so that no additional approval transactions are required.
Progressive Reveals
The Art Gobblers mint and reveal process has some unique constraints. Our goal was for the process to be provably fair while remaining gas efficient. But since Gobblers will be mintable over a period of 10 years, waiting until the mint was over to do a full-collection reveal wasn't an option.
In order to achieve this, we’ve implemented a highly optimized batch reveal process using a Fisher-Yates Shuffle . This allow reveals to happen once per day, using Chainlink as our randomness provider.
During the reveal process, this randomness is used to assign metadata to every unrevealed gobbler. This includes both a token ID as well as an emission multiplier sampled from a predefined distribution.
Thanks to some clever struct packing and various additional optimization, this process can be run in a gas efficient manner.
We’ve also made our randomness provider upgradable (writing a thin provider interface and adaptors ). This was necessary because we were unable to find a VRF provider that guaranteed service for the duration of the mint (approximately 10 years).
Testing and Security
We’ve made significant efforts to try to ensure the correctness of these smart contracts, including various forms of testings and audits.
Testing
We’ve written multiple unit tests and fuzz tests, leveraging Foundry as a testing framework. We’ve also made heavy use of differential fuzzing to test some of the more mathematically complex behavior. Implementations of VRGDAs and Goo have been written in python, and these implementations have been fuzzed against Solidity to ensure the outputs are equivalent:
We’ve also made use of use of advanced security tooling, like Slither for static analysis, and Z3 for automated theorem proving , in order to verify some of our assumptions about the mechanism.
Incentivized Play Testing
It was also important for us to verify that Gobblers gameplay is balanced. We wanted to test whether there are any strategies that would allow players to end up with a disproportionate amount of the game’s resources (whether it’s Gobblers, Pages or Goo).
In order to do this, we ran an incentivized play test, organized with some help from Grug . We tuned the mechanism’s parameters to speed up gameplay by 30x, and invited a group of searchers and developers to play. We tasked them with trying to obtain as many Gobblers and as much Goo as they could, with Gobblers being given as prizes.
This was an interesting experiment, and we were able to observe some fun strategies emerge. We encourage developers building onchain games to include play testing as part of their development process.
Audits and C4 Contest
For audits, we underwent an internal review process by samczsun and Riley Holterhus . We also engaged Spearbit to conduct an audit of the protocol near the completion of its current development, which did not uncover any major vulnerabilities.
We are also excited to announce that today, a one-week audit contest is being kicked off with code4rena, with a $100,000 prize pool. We invite you all to participate and see what you can find.
Conclusion
We are excited to share the Art Gobblers contracts with you, and are looking forward to see what you’ll build.
If you have any projects in mind, we’d love to hear from you. You can reach us on twitter at @FrankieIsLost , @transmissions11 , @_Dave__White_ and @JustinRoiland .
Acknowledgments: samczsun , Riley Holterhus , Grug , Otto Suwen , misaka , Snoopy Mev , CuriousRabbit , Will Price , Snarks , Taarush , Ben Leimberger , QTpie Pluto
Graphics By: Achal Srinivasan
Written by: Frankie , Transmissions11 , Dave White , Justin Roiland
Disclaimer: This post is for general information purposes only. It does not constitute investment advice or a recommendation or solicitation to buy or sell any investment and should not be used in the evaluation of the merits of making any investment decision. It should not be relied upon for accounting, legal or tax advice or investment recommendations. This post reflects the current opinions of the authors and is not made on behalf of Paradigm or its affiliates and does not necessarily reflect the opinions of Paradigm, its affiliates or individuals associated with Paradigm. The opinions reflected herein are subject to change without being updated.
Website terms of use
Important disclosures
Single Line Text
About. Team. Portfolio. Writing. Fellowship. Opportunities. Contact. About. Portfolio. Opportunities. Contact. Team. Writing. Fellowship. Sep 20, 2022 | Frankie , Transmissions11 , Dave White , Justin Roiland. Contents. Introduction. Diving into the Contracts Custom ERC721 Implementations GobblersERC721 PagesERC721 Integrating GOO Progressive Reveals Testing and Security Testing Incentivized Play Testing Audits and C4 Contest. Custom ERC721 Implementations GobblersERC721 PagesERC721. GobblersERC721. PagesERC721. Integrating GOO. Progressive Reveals. Testing and Security Testing Incentivized Play Testing Audits and C4 Contest. Testing. Incentivized Play Testing. Audits and C4 Contest. Conclusion. Introduction. Today, we’re excited to announce that the Art Gobblers smart contracts are open source and available on our Github repo . We hope the systems we’ve built will capture your imagination, and we can’t wait to see what you’ll build on top of them. Diving into the Contracts. In this post, we want to highlight a few of the interesting parts of the Art Gobblers codebase, like our custom ERC721 implementations, GOO integration, our progressive reveal system, and our approach to testing. Custom ERC721 Implementations. GobblersERC721. Art Gobblers is significantly more complex than the average NFT project. Gobblers are sold using a VRGDA , and are paid for with a custom utility token (Goo). On top of this, each Gobbler is assigned an “emission multiple”, which determines the rate at which it continuously generates Goo tokens, using GOO issuance . Nevertheless, we wanted the gas costs of minting & transferring Gobbler NFTs to be one of the lowest in the industry. To achieve this, we built a custom ERC721 implementation that makes heavy use of struct packing to remain efficient. We are able to fit all of the state associated with each gobbler and user in the mappings typically used for owner and balance information. For Gobbler state, we pack each Gobbler’s 160 bit owner address with 2 other variables: idx and emissionMultiple : For owner state, we pack a 32 bit count of the gobblers owned by that user with 3 other variables related to GOO issuance: emissionMultiple , lastBalance and lastTimestamp : While under the hood all this data is packed together in one 256 bit slot, GobblersERC721 is still 100% compliant with the ERC721 interface, thanks to helper functions which expose the specific storage sections needed for ownerOf and balanceOf : Additionally, GobblersERC721 also features optimizations that leverage fundamental invariants of the Art Gobblers system (no tokens will be minted to address(0) , the supply cap of 10,000 , etc) to remove redundant assertions. PagesERC721. Pages, while significantly less complex than Gobblers, also use a modified ERC721 implementation to improve improve gas costs and UX around feeding pages to gobblers. Primarily, Pages automatically skip approval checks when being transferred by the Gobblers contract to make gobbling a single shot process with no extra hassle. And, like Gobblers, Pages utilize known invariants of the Art Gobblers system to remove redundant assertions in their minting logic. Integrating GOO. Gobblers generate Goo at a specified emission rate, which we discuss in GOO paper . Because Goo is generated continuously over time, goo balances need to be computed lazily. That is, a virtual balance is tracked which can be exchanged for a regular ERC20 balance at the user's convenience. Because this virtual balance is a function of the user’s total emission multiple, one has to make sure that it remains correct when transfers happen. For example, when a user transfers a gobbler away, their total emission multiple should go down (and so should their future emissions), but their current Goo balance should not change. In order to get around this, we overrode Gobbler’s transfer function to ensure that proper snapshots are taken of the user's state. Since virtual balances are used to keep track of Goo, we wanted to avoid purchases being a multi-transaction process. Normally, users would have to submit one transaction to turn their virtual balance into a regular ERC20 balance, one transaction to approve Gobblers as a Goo spender, and another transaction to purchase the items. To streamline this process, we modified the purchase functions in both Gobblers and Pages so that users are able to spend directly from their virtual balances, and set up permissions between contracts so that no additional approval transactions are required. Progressive Reveals. The Art Gobblers mint and reveal process has some unique constraints. Our goal was for the process to be provably fair while remaining gas efficient. But since Gobblers will be mintable over a period of 10 years, waiting until the mint was over to do a full-collection reveal wasn't an option. In order to achieve this, we’ve implemented a highly optimized batch reveal process using a Fisher-Yates Shuffle . This allow reveals to happen once per day, using Chainlink as our randomness provider. During the reveal process, this randomness is used to assign metadata to every unrevealed gobbler. This includes both a token ID as well as an emission multiplier sampled from a predefined distribution. Thanks to some clever struct packing and various additional optimization, this process can be run in a gas efficient manner. We’ve also made our randomness provider upgradable (writing a thin provider interface and adaptors ). This was necessary because we were unable to find a VRF provider that guaranteed service for the duration of the mint (approximately 10 years). Testing and Security. We’ve made significant efforts to try to ensure the correctness of these smart contracts, including various forms of testings and audits. Testing. We’ve written multiple unit tests and fuzz tests, leveraging Foundry as a testing framework. We’ve also made heavy use of differential fuzzing to test some of the more mathematically complex behavior. Implementations of VRGDAs and Goo have been written in python, and these implementations have been fuzzed against Solidity to ensure the outputs are equivalent: We’ve also made use of use of advanced security tooling, like Slither for static analysis, and Z3 for automated theorem proving , in order to verify some of our assumptions about the mechanism. Incentivized Play Testing. It was also important for us to verify that Gobblers gameplay is balanced. We wanted to test whether there are any strategies that would allow players to end up with a disproportionate amount of the game’s resources (whether it’s Gobblers, Pages or Goo). In order to do this, we ran an incentivized play test, organized with some help from Grug . We tuned the mechanism’s parameters to speed up gameplay by 30x, and invited a group of searchers and developers to play. We tasked them with trying to obtain as many Gobblers and as much Goo as they could, with Gobblers being given as prizes. This was an interesting experiment, and we were able to observe some fun strategies emerge. We encourage developers building onchain games to include play testing as part of their development process. Audits and C4 Contest. For audits, we underwent an internal review process by samczsun and Riley Holterhus . We also engaged Spearbit to conduct an audit of the protocol near the completion of its current development, which did not uncover any major vulnerabilities. We are also excited to announce that today, a one-week audit contest is being kicked off with code4rena, with a $100,000 prize pool. We invite you all to participate and see what you can find. Conclusion. We are excited to share the Art Gobblers contracts with you, and are looking forward to see what you’ll build. If you have any projects in mind, we’d love to hear from you. You can reach us on twitter at @FrankieIsLost , @transmissions11 , @_Dave__White_ and @JustinRoiland . Acknowledgments: samczsun , Riley Holterhus , Grug , Otto Suwen , misaka , Snoopy Mev , CuriousRabbit , Will Price , Snarks , Taarush , Ben Leimberger , QTpie Pluto. Graphics By: Achal Srinivasan. Written by: Frankie , Transmissions11 , Dave White , Justin Roiland. Disclaimer: This post is for general information purposes only. It does not constitute investment advice or a recommendation or solicitation to buy or sell any investment and should not be used in the evaluation of the merits of making any investment decision. It should not be relied upon for accounting, legal or tax advice or investment recommendations. This post reflects the current opinions of the authors and is not made on behalf of Paradigm or its affiliates and does not necessarily reflect the opinions of Paradigm, its affiliates or individuals associated with Paradigm. The opinions reflected herein are subject to change without being updated. Website terms of use. Important disclosures.