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-499 fix EntryPointSimulations config #522

Merged
merged 1 commit into from
Dec 26, 2024
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
10 changes: 8 additions & 2 deletions contracts/core/EntryPoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard,
} catch {
revert FailedOpWithRevert(opIndex, "AA33 reverted", Exec.getReturnData(REVERT_REASON_MAX_LEN));
}
if (preGas - gasleft() > pmVerificationGasLimit) {
if (preGas - gasleft() > _getVerificationGasLimit(pmVerificationGasLimit)) {
revert FailedOp(opIndex, "AA36 over paymasterVerificationGasLimit");
}
}
Expand Down Expand Up @@ -652,7 +652,7 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard,
}

unchecked {
if (preGas - gasleft() > verificationGasLimit) {
if (preGas - gasleft() > _getVerificationGasLimit(verificationGasLimit)) {
revert FailedOp(opIndex, "AA26 over verificationGasLimit");
}
}
Expand All @@ -673,6 +673,12 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard,
}
}

// return verification gas limit.
// This method is overridden in EntryPointSimulations, for slightly stricter gas limits.
function _getVerificationGasLimit(uint256 verificationGasLimit) internal pure virtual returns (uint256) {
return verificationGasLimit;
}

/**
* Process post-operation, called just after the callData is executed.
* If a paymaster is defined and its validation returned a non-empty context, its postOp is called.
Expand Down
10 changes: 7 additions & 3 deletions contracts/core/EntryPointSimulations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import "../interfaces/IEntryPointSimulations.sol";
* This contract should never be deployed on-chain and is only used as a parameter for the "eth_call" request.
*/
contract EntryPointSimulations is EntryPoint, IEntryPointSimulations {
// solhint-disable-next-line var-name-mixedcase
AggregatorStakeInfo private NOT_AGGREGATED = AggregatorStakeInfo(address(0), StakeInfo(0, 0));

SenderCreator private _senderCreator;

Expand Down Expand Up @@ -75,7 +73,7 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations {
getMemoryBytesFromOffset(outOpInfo.contextOffset)
);

AggregatorStakeInfo memory aggregatorInfo = NOT_AGGREGATED;
AggregatorStakeInfo memory aggregatorInfo; // = NOT_AGGREGATED;
if (uint160(aggregator) != SIG_VALIDATION_SUCCESS && uint160(aggregator) != SIG_VALIDATION_FAILED) {
aggregatorInfo = AggregatorStakeInfo(
aggregator,
Expand Down Expand Up @@ -187,4 +185,10 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations {
StakeManager.depositTo(account);
}
}

//slightly stricter gas limit than the real EntryPoint
function _getVerificationGasLimit(uint256 verificationGasLimit) internal pure virtual override returns (uint256) {
return verificationGasLimit - 300;
}

}
7 changes: 4 additions & 3 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function getNetwork (name: string): { url: string, accounts: { mnemonic: string
// return getNetwork1(`wss://${name}.infura.io/ws/v3/${process.env.INFURA_ID}`)
}

const optimizedComilerSettings = {
const optimizedCompilerSettings = {
version: '0.8.23',
settings: {
optimizer: { enabled: true, runs: 1000000 },
Expand All @@ -50,8 +50,9 @@ const config: HardhatUserConfig = {
}
}],
overrides: {
'contracts/core/EntryPoint.sol': optimizedComilerSettings,
'contracts/samples/SimpleAccount.sol': optimizedComilerSettings
'contracts/core/EntryPoint.sol': optimizedCompilerSettings,
'contracts/core/EntryPointSimulations.sol': optimizedCompilerSettings,
'contracts/samples/SimpleAccount.sol': optimizedCompilerSettings
}
},
networks: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint:js": "eslint -f unix .",
"lint-fix": "eslint -f unix . --fix",
"lint:sol": "solhint -f unix \"contracts/**/*.sol\" --max-warnings 0",
"gas-calc": "./scripts/gascalc",
"gas-calc": "yarn compile && ./scripts/gascalc",
"mocha-gascalc": "TS_NODE_TRANSPILE_ONLY=1 npx ts-mocha --bail gascalc/*",
"test": "./scripts/hh-wrapper test",
"coverage": "COVERAGE=1 hardhat coverage",
Expand Down
32 changes: 16 additions & 16 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 │ 80004 │ │ ║
║ simple │ 1 │ 79968 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple - diff from previous │ 2 │ │ 42168 │ 12841 ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple │ 10 │ 459895 │ │ ║
║ simple │ 10 │ 459883 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple - diff from previous │ 11 │ │ 4223512908
║ simple - diff from previous │ 11 │ │ 4227112944
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster │ 1 │ 86147 │ │ ║
║ simple paymaster │ 1 │ 86135 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster with diff │ 2 │ │ 4104811721
║ simple paymaster with diff │ 2 │ │ 4103611709
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster │ 10 │ 455682 │ │ ║
║ simple paymaster │ 10 │ 455634 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster with diff │ 11 │ │ 4114811821
║ simple paymaster with diff │ 11 │ │ 4113611809
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx 5k │ 1 │ 181036 │ │ ║
║ big tx 5k │ 1 │ 181048 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx - diff from previous │ 2 │ │ 14270216604
║ big tx - diff from previous │ 2 │ │ 14267816580
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx 5k │ 10 │ 1465441 │ │ ║
║ big tx 5k │ 10 │ 1465429 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx - diff from previous │ 11 │ │ 14272216624
║ big tx - diff from previous │ 11 │ │ 14274616648
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ paymaster+postOp │ 1 │ 87758 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ paymaster+postOp with diff │ 2 │ │ 42647 │ 13320 ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ paymaster+postOp │ 10 │ 471848 │ │ ║
║ paymaster+postOp │ 10 │ 471764 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ paymaster+postOp with diff │ 11 │ │ 4270413377
║ paymaster+postOp with diff │ 11 │ │ 4271613389
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster │ 1 │ 128809 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster with diff │ 2 │ │ 6638437057
║ token paymaster with diff │ 2 │ │ 6639637069
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster │ 10 │ 726686 │ │ ║
║ token paymaster │ 10 │ 726722 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster with diff │ 11 │ │ 6653637209
║ token paymaster with diff │ 11 │ │ 6645237125
╚════════════════════════════════╧═══════╧═══════════════╧════════════════╧═════════════════════╝

3 changes: 2 additions & 1 deletion test/entrypointsimulations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe('EntryPointSimulations', function () {
function costInRange (simCost: BigNumber, epCost: BigNumber, message: string): void {
const diff = simCost.sub(epCost).toNumber()
const max = 350
console.log(`validate ${message} cost ${simCost.toNumber()} should be slightly above ep cost ${epCost.toNumber()} actual diff=${diff}`)
expect(diff).to.be.within(0, max,
`${message} cost ${simCost.toNumber()} should be (up to ${max}) above ep cost ${epCost.toNumber()}`)
}
Expand Down Expand Up @@ -294,7 +295,7 @@ describe('EntryPointSimulations', function () {
describe(`compare to execution ${withPaymaster} paymaster`, () => {
let execVgl: number
let execPmVgl: number
const diff = 2000
const diff = 500
before(async () => {
execPmVgl = withPaymaster === 'without' ? 0 : await findUserOpWithMin(async n => userOpWithGas(1e6, n), false, entryPoint, 1, 500000)
execVgl = await findUserOpWithMin(async n => userOpWithGas(n, execPmVgl), false, entryPoint, 1, 500000)
Expand Down
Loading