diff --git a/contracts/core/EntryPoint.sol b/contracts/core/EntryPoint.sol index c0b42611..44501524 100644 --- a/contracts/core/EntryPoint.sol +++ b/contracts/core/EntryPoint.sol @@ -731,8 +731,9 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard, uint256 prefund = opInfo.prefund; if (prefund < actualGasCost) { if (mode == IPaymaster.PostOpMode.postOpReverted) { + actualGasCost = prefund; emitPrefundTooLow(opInfo); - emitUserOperationEvent(opInfo, false, prefund, actualGas); + emitUserOperationEvent(opInfo, false, actualGasCost, actualGas); } else { assembly ("memory-safe") { mstore(0, INNER_REVERT_LOW_PREFUND) diff --git a/reports/gas-checker.txt b/reports/gas-checker.txt index 65db487f..0db74a13 100644 --- a/reports/gas-checker.txt +++ b/reports/gas-checker.txt @@ -4,7 +4,7 @@ ╔══════════════════════════╤════════╗ ║ gas estimate "simple" │ 28979 ║ ╟──────────────────────────┼────────╢ -║ gas estimate "big tx 5k" │ 125224 ║ +║ gas estimate "big tx 5k" │ 125212 ║ ╚══════════════════════════╧════════╝ ╔════════════════════════════════╤═══════╤═══════════════╤════════════════╤═════════════════════╗ @@ -12,44 +12,44 @@ ║ │ │ │ (delta for │ (compared to ║ ║ │ │ │ one UserOp) │ account.exec()) ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple │ 1 │ 80003 │ │ ║ +║ simple │ 1 │ 79970 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple - diff from previous │ 2 │ │ 42201 │ 13222 ║ +║ simple - diff from previous │ 2 │ │ 42192 │ 13213 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple │ 10 │ 459987 │ │ ║ +║ simple │ 10 │ 459825 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple - diff from previous │ 11 │ │ 42292 │ 13313 ║ +║ simple - diff from previous │ 11 │ │ 42295 │ 13316 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple paymaster │ 1 │ 86149 │ │ ║ +║ simple paymaster │ 1 │ 86125 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ ║ simple paymaster with diff │ 2 │ │ 41060 │ 12081 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple paymaster │ 10 │ 455744 │ │ ║ +║ simple paymaster │ 10 │ 455660 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple paymaster with diff │ 11 │ │ 41148 │ 12169 ║ +║ simple paymaster with diff │ 11 │ │ 41136 │ 12157 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ big tx 5k │ 1 │ 181035 │ │ ║ +║ big tx 5k │ 1 │ 181014 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ big tx - diff from previous │ 2 │ │ 142711 │ 17487 ║ +║ big tx - diff from previous │ 2 │ │ 142702 │ 17490 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ big tx 5k │ 10 │ 1465557 │ │ ║ +║ big tx 5k │ 10 │ 1465359 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ big tx - diff from previous │ 11 │ │ 142695 │ 17471 ║ +║ big tx - diff from previous │ 11 │ │ 142758 │ 17546 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp │ 1 │ 87760 │ │ ║ +║ paymaster+postOp │ 1 │ 87748 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp with diff │ 2 │ │ 42671 │ 13692 ║ +║ paymaster+postOp with diff │ 2 │ │ 42647 │ 13668 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp │ 10 │ 471934 │ │ ║ +║ paymaster+postOp │ 10 │ 471838 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp with diff │ 11 │ │ 42716 │ 13737 ║ +║ paymaster+postOp with diff │ 11 │ │ 42644 │ 13665 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ token paymaster │ 1 │ 128777 │ │ ║ +║ token paymaster │ 1 │ 128753 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ ║ token paymaster with diff │ 2 │ │ 66410 │ 37431 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ token paymaster │ 10 │ 726600 │ │ ║ +║ token paymaster │ 10 │ 726456 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ token paymaster with diff │ 11 │ │ 66454 │ 37475 ║ +║ token paymaster with diff │ 11 │ │ 66442 │ 37463 ║ ╚════════════════════════════════╧═══════╧═══════════════╧════════════════╧═════════════════════╝ diff --git a/test/entrypoint.test.ts b/test/entrypoint.test.ts index ef4fe6bb..4a934c44 100644 --- a/test/entrypoint.test.ts +++ b/test/entrypoint.test.ts @@ -513,13 +513,16 @@ describe('EntryPoint', function () { const current = await counter.counters(account.address) // expect calldata to revert below minGas: + const beneficiaryBalance = await ethers.provider.getBalance(beneficiary) const rcpt = await entryPoint.handleOps([packUserOp(await createUserOpWithGas(vgl - 1, 0, minCallGas))], beneficiary).then(async r => r.wait()) expect(rcpt.events?.map(ev => ev.event)).to.eql([ 'BeforeExecution', 'UserOperationPrefundTooLow', 'UserOperationEvent']) - expect(await counter.counters(account.address)).to.eql(current, 'should revert account with prefund too low') const userOpEvent = rcpt.events?.find(e => e.event === 'UserOperationEvent') as UserOperationEventEvent + const collected = (await ethers.provider.getBalance(beneficiary)).sub(beneficiaryBalance) + expect(userOpEvent.args.actualGasCost).to.equal(collected) + expect(await counter.counters(account.address)).to.eql(current, 'should revert account with prefund too low') expect(userOpEvent.args.success).to.eql(false) }) @@ -529,6 +532,7 @@ describe('EntryPoint', function () { const minVerGas = await findUserOpWithMin(async (vgl: number) => createUserOpWithGas(vgl, 1e5, minCallGas), false, entryPoint, 5000, 100000, 2) const minPmVerGas = await findUserOpWithMin(async (pmVgl: number) => createUserOpWithGas(minVerGas, pmVgl, minCallGas), false, entryPoint, 1, 100000, 2) + const beneficiaryBalance = await ethers.provider.getBalance(beneficiary) const rcpt = await entryPoint.handleOps([packUserOp(await createUserOpWithGas(minVerGas, minPmVerGas - 1, minCallGas))], beneficiary) .then(async r => r.wait()) .catch((e: Error) => { throw new Error(decodeRevertReason(e, false) as any) }) @@ -539,6 +543,8 @@ describe('EntryPoint', function () { 'UserOperationEvent']) expect(await counter.counters(account.address)).to.eql(current, 'should revert account with prefund too low') const userOpEvent = rcpt.events?.find(e => e.event === 'UserOperationEvent') as UserOperationEventEvent + const collected = (await ethers.provider.getBalance(beneficiary)).sub(beneficiaryBalance) + expect(userOpEvent.args.actualGasCost).to.equal(collected) expect(userOpEvent.args.success).to.eql(false) }) })