NFT Keyed Ephemeral Counterfactual Minimal Proxy Contracts

These example contracts demonstrate a gas effective way to deploy counterfactual contracts using CREATE2. Using minimal proxy instances that are destroyed between transactions is a secure way to isolate assets in a way that only the key holder can access, Using the token ID of a known NFT contract allows this access to be transferred based on the permissions associated with that NFT.

This is an example of a simple “smart wallet” implementation. In practice allowing it to execute arbitrary calls will mean no other methods are needed, however additional security can be added by implementing explicit calls followed by selfdestruct().

[remote_content url='https://gist.githubusercontent.com/doublesharp/f940869ec92ab938fc4830bb161a6b99/raw/Implementation.sol' decode_atts="true" htmlentities="true"]

This factory contract will create new minimal proxy instances using the token ID as the salt. Only the token owner is allowed to call the function to create the contract, so any assets in the contracts storage location will be safe between calls.

[remote_content url='https://gist.githubusercontent.com/doublesharp/f940869ec92ab938fc4830bb161a6b99/raw/Create2Factory.sol' decode_atts="true" htmlentities="true"]

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *