Skip to content

Commit

Permalink
AA-222 add delegateAndRevert helper, to simulate code execution from …
Browse files Browse the repository at this point in the history
…entryPoint. (#365)

Minimal "static" call from EntryPoint to simulate special cases. Equivalent to the EntryPointSimulations in purpose, but doesn't require stateOverride.
Executes code on behalf of entryPoint using delegateCall, and revert with the result
  • Loading branch information
drortirosh committed Jan 3, 2024
1 parent 1f73d25 commit cb6d163
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
6 changes: 6 additions & 0 deletions contracts/core/EntryPoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -753,4 +753,10 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard,
data := offset
}
}

/// @inheritdoc IEntryPoint
function delegateAndRevert(address target, bytes calldata data) external {
(bool success, bytes memory ret) = target.delegatecall(data);
revert DelegateAndRevert(success, ret);
}
}
9 changes: 9 additions & 0 deletions contracts/interfaces/IEntryPoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,13 @@ interface IEntryPoint is IStakeManager, INonceManager {
*/
function getSenderAddress(bytes memory initCode) external;

error DelegateAndRevert(bool success, bytes ret);

/**
* Helper method for dry-run testing.
* @dev calling this method, the EntryPoint will make a delegatecall to the given data, and report (via revert) the result.
* The method always revert, so is only useful off-chain for dry run calls, in cases where state-override to replace
* actual EntryPoint code is less convenient.
*/
function delegateAndRevert(address target, bytes calldata data) external;
}
12 changes: 6 additions & 6 deletions reports/gas-checker.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple - diff from previous │ 2 │ │ 44187 │ 15173 ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple │ 10 │ 479694 │ │ ║
║ simple │ 10 │ 479742 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple - diff from previous │ 11 │ │ 44247 │ 15233 ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster │ 1 │ 88187 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster with diff │ 2 │ │ 4313814124
║ simple paymaster with diff │ 2 │ │ 4311414100
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster │ 10 │ 476718 │ │ ║
║ simple paymaster │ 10 │ 476706 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster with diff │ 11 │ │ 4318514171
║ simple paymaster with diff │ 11 │ │ 4317314159
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx 5k │ 1 │ 182987 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx - diff from previous │ 2 │ │ 144698 │ 19438 ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx 5k │ 10 │ 1485290 │ │ ║
║ big tx 5k │ 10 │ 1485386 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx - diff from previous │ 11 │ │ 14469919439
║ big tx - diff from previous │ 11 │ │ 14475919499
╚════════════════════════════════╧═══════╧═══════════════╧════════════════╧═════════════════════╝

13 changes: 3 additions & 10 deletions test/entrypoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
SimpleAccountFactory__factory,
IStakeManager__factory,
INonceManager__factory,
EntryPoint__factory,
EntryPoint
} from '../typechain'
import {
Expand Down Expand Up @@ -1310,19 +1309,13 @@ describe('EntryPoint', function () {
})

it('should return true for pure EntryPoint, IStakeManager and INonceManager interface IDs', async function () {
const epInterface = EntryPoint__factory.createInterface()
const epInterface = IEntryPoint__factory.createInterface()
const smInterface = IStakeManager__factory.createInterface()
const nmInterface = INonceManager__factory.createInterface()
// note: manually generating "pure", solidity-like "type(IEntryPoint).interfaceId" without inherited methods
const inheritedMethods = new Set([...smInterface.fragments, ...nmInterface.fragments].map(f => f.name))
const epPureInterfaceFunctions = [
...epInterface.fragments.filter(it => [
'handleOps',
'handleAggregatedOps',
'getUserOpHash',
'getSenderAddress',
'simulateValidation',
'simulateHandleOp'
].includes(it.name))
...epInterface.fragments.filter(it => !inheritedMethods.has(it.name) && it.type === 'function')
]
const epPureInterfaceID = getERC165InterfaceID(epPureInterfaceFunctions)
const smInterfaceID = getERC165InterfaceID([...smInterface.fragments])
Expand Down

0 comments on commit cb6d163

Please sign in to comment.