Skip to content
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

AA-222 add delegateAndRevert helper, to simulate code execution from entryPoint. #365

Merged
merged 7 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading