fix SimpleWallet slot allocations (#226)

Fit nonce and owner into the same slot, to save unneeded SLOAD during
validation
(They used to be in the same slot, and got "unaligned" when added a
proxy, since using "Initializeable" uses the first 2 bytes in the
storage.
This commit is contained in:
Dror Tirosh
2023-02-17 00:32:02 +02:00
committed by GitHub
parent 61f7d2898d
commit f3b5f79551
2 changed files with 18 additions and 14 deletions

View File

@@ -20,6 +20,10 @@ import "../core/BaseAccount.sol";
contract SimpleAccount is BaseAccount, UUPSUpgradeable, Initializable {
using ECDSA for bytes32;
//filler member, to push the nonce and owner to the same slot
// the "Initializeble" class takes 2 bytes in the first slot
bytes28 private _filler;
//explicit sizes of nonce, to fit a single storage cell with "owner"
uint96 private _nonce;
address public owner;

View File

@@ -1,35 +1,35 @@
== gas estimate of direct calling the account's "execFromEntryPoint" method
the destination is "account.nonce()", which is known to be "hot" address used by this account
it little higher than EOA call: its an exec from entrypoint (or account owner) into account contract, verifying msg.sender and exec to target)
- gas estimate "simple" - 31045
- gas estimate "big tx 5k" - 127295
- gas estimate "simple" - 31033
- gas estimate "big tx 5k" - 127284
╔════════════════════════════════╤═══════╤═══════════════╤════════════════╤═════════════════════╗
║ handleOps description │ count │ total gasUsed │ per UserOp gas │ per UserOp overhead ║
║ │ │ │ (delta for │ (compared to ║
║ │ │ │ one UserOp) │ account.exec()) ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple │ 1 │ 78018 │ │ ║
║ simple │ 1 │ 75948 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple - diff from previous │ 2 │ │ 43447 │ 12402
║ simple - diff from previous │ 2 │ │ 41449 │ 10416
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple │ 10 │ 469609 │ │ ║
║ simple │ 10 │ 449053 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple - diff from previous │ 11 │ │ 43630 │ 12585
║ simple - diff from previous │ 11 │ │ 41560 │ 10527
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster │ 1 │ 84303 │ │ ║
║ simple paymaster │ 1 │ 82245 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster with diff │ 2 │ │ 4249011445 ║
║ simple paymaster with diff │ 2 │ │ 40408 9375 ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster │ 10 │ 466934 │ │ ║
║ simple paymaster │ 10 │ 446306 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster with diff │ 11 │ │ 4260211557 ║
║ simple paymaster with diff │ 11 │ │ 40604 9571
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx 5k │ 1 │ 179739 │ │ ║
║ big tx 5k │ 1 │ 177693 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx - diff from previous │ 2 │ │ 144794 │ 17499
║ big tx - diff from previous │ 2 │ │ 142772 │ 15488
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx 5k │ 10 │ 1488695 │ │ ║
║ big tx 5k │ 10 │ 1468115 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx - diff from previous │ 11 │ │ 146324 │ 19029
║ big tx - diff from previous │ 11 │ │ 144290 │ 17006
╚════════════════════════════════╧═══════╧═══════════════╧════════════════╧═════════════════════╝