-
Notifications
You must be signed in to change notification settings - Fork 854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimized validation pattern #575
Comments
That's an interesting approach, indeed! Would be interesting to check how much gas it'd use if it supported all types of signatures that Safe supports (on-chain approvals, eip-191, eip-712, eip1271)
FYI, we spun out of Gnosis and are just Safe now 😉 |
Thanks, I'm currently working on EIP-1271 support; in terms of additional overhead it should only be a conditional statement and external call. Will try to get some better gas comparisons out this week. PS safe*** haha EDIT: While I remember, this could also be built as a SafeModule, will get one out as well. |
I build a similar contract in the past: https://github.com/rmeissner/stateless-vault/blob/main/packages/contracts/contracts/StatelessVault.sol#L185 (it uses MerkleProofs to optimize on the digest for Safes with many owners). It is an interesting approach, but would require a major rewrite of the Safe including how data is stored. Also it would have an impact of on-chain interaction with the Safe that need to be evaluated. |
* Add provider info * Use sdk personal sign * signOut with option * Remove provider * Sign safe transaction * Test in gnosis chain * Use ethers provider * Update naming from Web3Auth to SafeAuth * Renaming and persistent login * Add tests * set selected safe * Add clearInit call in pack * Remove signTransaction * Fix typed Data sign * Add test with ethers signer * Added proposed transaction instead execute to check signature * Throw error if the provider is not the web3auth one * use SafeTx as typedData * Metamask verify * Update example sign and execute code * sign transactions for testing purposes * Remove @toruslabs/ethereum-controllers * Publish - @safe-global/[email protected] * Fix wrong chain in example app
I have developed a validation pattern that can greatly reduce the gas associated with wallet deployment and usage. The concept behind this pattern is rather straightforward: instead of storing various parameters required for validation, such as the list of signers and the quorum, you only store a hash. This hash can be reconstructed by first recovering the list of signers and then hashing them together with any other variables that need to be validated, such as quorum.
To ensure proper reconstruction of the validation hash, it is crucial to provide the signatures in the exact order of the addresses that were hashed during the creation of the validation hash. Moreover, if a signer does not provide a signature, their address must be used as a replacement. This implies that whenever signatures are provided, they MUST ALWAYS be placed at the same index of signatures.
Gas is saved on deployment because only a single slot needs to be modified in order to initialize everything. Furthermore, only a two SLOADs are needed for transaction validation. 1 SLOAD for
nonce
, and 1 SLOAD for the validation hash as opposed to an SLOAD for each signer, and an additional SLOAD for the signers array length.Foundry says 77k gas to deploy my version via a clone factory and 45k for an ETH transfer when using 3 signers and with a quorum of 2.
PS: I understand these changes would require a redeployment, so I'm mostly here to bring awareness for the next iteration of Safe**.
Here's the example implementation.
The text was updated successfully, but these errors were encountered: