Skip to content

Commit

Permalink
report exactly used gas on prefund too low
Browse files Browse the repository at this point in the history
  • Loading branch information
drortirosh committed Feb 13, 2024
1 parent c579477 commit 6a1c25e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
3 changes: 2 additions & 1 deletion contracts/core/EntryPoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 19 additions & 19 deletions reports/gas-checker.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,52 @@
╔══════════════════════════╤════════╗
║ gas estimate "simple" │ 28979 ║
╟──────────────────────────┼────────╢
║ gas estimate "big tx 5k" │ 125224
║ gas estimate "big tx 5k" │ 125212
╚══════════════════════════╧════════╝

╔════════════════════════════════╤═══════╤═══════════════╤════════════════╤═════════════════════╗
║ handleOps description │ count │ total gasUsed │ per UserOp gas │ per UserOp overhead ║
║ │ │ │ (delta for │ (compared to ║
║ │ │ │ one UserOp) │ account.exec()) ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple │ 1 │ 80003 │ │ ║
║ simple │ 1 │ 79970 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple - diff from previous │ 2 │ │ 4220113222
║ simple - diff from previous │ 2 │ │ 4219213213
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple │ 10 │ 459987 │ │ ║
║ simple │ 10 │ 459825 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple - diff from previous │ 11 │ │ 4229213313
║ simple - diff from previous │ 11 │ │ 4229513316
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ 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 │ │ 4114812169
║ simple paymaster with diff │ 11 │ │ 4113612157
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx 5k │ 1 │ 181035 │ │ ║
║ big tx 5k │ 1 │ 181014 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx - diff from previous │ 2 │ │ 14271117487
║ big tx - diff from previous │ 2 │ │ 14270217490
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx 5k │ 10 │ 1465557 │ │ ║
║ big tx 5k │ 10 │ 1465359 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx - diff from previous │ 11 │ │ 14269517471
║ big tx - diff from previous │ 11 │ │ 14275817546
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ paymaster+postOp │ 1 │ 87760 │ │ ║
║ paymaster+postOp │ 1 │ 87748 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ paymaster+postOp with diff │ 2 │ │ 4267113692
║ paymaster+postOp with diff │ 2 │ │ 4264713668
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ paymaster+postOp │ 10 │ 471934 │ │ ║
║ paymaster+postOp │ 10 │ 471838 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ paymaster+postOp with diff │ 11 │ │ 4271613737
║ paymaster+postOp with diff │ 11 │ │ 4264413665
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ 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 │ │ 6645437475
║ token paymaster with diff │ 11 │ │ 6644237463
╚════════════════════════════════╧═══════╧═══════════════╧════════════════╧═════════════════════╝

8 changes: 7 additions & 1 deletion test/entrypoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand All @@ -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) })
Expand All @@ -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)
})
})
Expand Down

0 comments on commit 6a1c25e

Please sign in to comment.