Skip to content

Commit

Permalink
fix SimpleWallet slot allocations (#226)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
drortirosh authored Feb 16, 2023
1 parent 61f7d28 commit f3b5f79
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
4 changes: 4 additions & 0 deletions contracts/samples/SimpleAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 14 additions & 14 deletions reports/gas-checker.txt
Original file line number Diff line number Diff line change
@@ -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 │ │ 4344712402
║ simple - diff from previous │ 2 │ │ 4144910416
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple │ 10 │ 469609 │ │ ║
║ simple │ 10 │ 449053 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple - diff from previous │ 11 │ │ 4363012585
║ simple - diff from previous │ 11 │ │ 4156010527
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ 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 │ │ 14479417499
║ big tx - diff from previous │ 2 │ │ 14277215488
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx 5k │ 10 │ 1488695 │ │ ║
║ big tx 5k │ 10 │ 1468115 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx - diff from previous │ 11 │ │ 14632419029
║ big tx - diff from previous │ 11 │ │ 14429017006
╚════════════════════════════════╧═══════╧═══════════════╧════════════════╧═════════════════════╝

1 comment on commit f3b5f79

@Yardapestr
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This any better

Please sign in to comment.