Skip to content

Commit

Permalink
make sure innerHandleOp gets enough gas. (#401)
Browse files Browse the repository at this point in the history
* make sure innerHandleOps gets enough gas.

UserOperation's call must receive at least callGasLimit.
If there isn't enough provided to handleOps, the bundle should revert.
  • Loading branch information
drortirosh authored Jan 11, 2024
1 parent f61b642 commit 63fb07a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
8 changes: 6 additions & 2 deletions contracts/core/EntryPoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard,
return _senderCreator;
}

//compensate for innerHandleOps' emit message and deposit refund.
// allow some slack for future gas price changes.
uint private constant INNER_GAS_OVERHEAD = 10000;

// Marker for inner call revert on out of gas
bytes32 private constant INNER_OUT_OF_GAS = hex"deaddead";

Expand Down Expand Up @@ -296,10 +300,10 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard,
unchecked {
// handleOps was called with gas limit too low. abort entire bundle.
if (
gasleft() <
gasleft() * 63 / 64 <
callGasLimit +
mUserOp.paymasterPostOpGasLimit +
5000
INNER_GAS_OVERHEAD
) {
assembly {
mstore(0, INNER_OUT_OF_GAS)
Expand Down
40 changes: 20 additions & 20 deletions reports/gas-checker.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,44 @@
║ │ │ │ (delta for │ (compared to ║
║ │ │ │ one UserOp) │ account.exec()) ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple │ 1 │ 81580 │ │ ║
║ simple │ 1 │ 81609 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple - diff from previous │ 2 │ │ 4374114762
║ simple - diff from previous │ 2 │ │ 4379414815
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple │ 10 │ 475536 │ │ ║
║ simple │ 10 │ 475874 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple - diff from previous │ 11 │ │ 4379814819
║ simple - diff from previous │ 11 │ │ 4379114812
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster │ 1 │ 87871 │ │ ║
║ simple paymaster │ 1 │ 87924 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster with diff │ 2 │ │ 4275713778
║ simple paymaster with diff │ 2 │ │ 4281013831
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster │ 10 │ 473045 │ │ ║
║ simple paymaster │ 10 │ 473311 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster with diff │ 11 │ │ 4283513856
║ simple paymaster with diff │ 11 │ │ 4287613897
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx 5k │ 1 │ 182638 │ │ ║
║ big tx 5k │ 1 │ 182667 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx - diff from previous │ 2 │ │ 14426419040
║ big tx - diff from previous │ 2 │ │ 14429319069
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx 5k │ 10 │ 1481207 │ │ ║
║ big tx 5k │ 10 │ 1481461 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx - diff from previous │ 11 │ │ 14434519121
║ big tx - diff from previous │ 11 │ │ 14435019126
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ paymaster+postOp │ 1 │ 89675 │ │ ║
║ paymaster+postOp │ 1 │ 89704 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ paymaster+postOp with diff │ 2 │ │ 4453615557
║ paymaster+postOp with diff │ 2 │ │ 4458915610
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ paymaster+postOp │ 10 │ 490829 │ │ ║
║ paymaster+postOp │ 10 │ 491155 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ paymaster+postOp with diff │ 11 │ │ 4460915630
║ paymaster+postOp with diff │ 11 │ │ 4463815659
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster │ 1 │ 130350 │ │ ║
║ token paymaster │ 1 │ 130379 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster with diff │ 2 │ │ 6793238953
║ token paymaster with diff │ 2 │ │ 6796138982
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster │ 10 │ 741961 │ │ ║
║ token paymaster │ 10 │ 742299 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster with diff │ 11 │ │ 6805139072
║ token paymaster with diff │ 11 │ │ 6803239053
╚════════════════════════════════╧═══════╧═══════════════╧════════════════╧═════════════════════╝

2 changes: 1 addition & 1 deletion test/entrypoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ describe('EntryPoint', function () {
sender: account.address,
callData: accountExec.data,
verificationGasLimit: 1e5,
callGasLimit: 11.5e5
callGasLimit: 11e5
}, accountOwner, entryPoint)
const inititalAccountBalance = await getBalance(account.address)
const beneficiaryAddress = createAddress()
Expand Down

0 comments on commit 63fb07a

Please sign in to comment.