Skip to content

Commit

Permalink
waste some gas
Browse files Browse the repository at this point in the history
  • Loading branch information
drortirosh committed Aug 21, 2023
1 parent 4887d64 commit e2f4703
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
8 changes: 8 additions & 0 deletions contracts/core/EntryPointSimulations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations {
//make sure depositTo cost is more than normal EntryPoint's cost.
// empiric test showed that without this wrapper, simulation depositTo costs less..
function depositTo(address account) public override(IStakeManager, StakeManager) payable {
uint x;
assembly {
//some silly code to waste ~200 gas
x := exp(mload(0),100)
}
if (x == 123) {
return;
}
StakeManager.depositTo(account);
}
}
27 changes: 18 additions & 9 deletions test/entrypointsimulations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,33 @@ describe('EntryPointSimulations', function () {
// await checkStateDiffSupported()
})

describe('Simulation Contract Sannity checks', () => {
describe.only('Simulation Contract Sannity checks', () => {
const addr = createAddress()

function costInRange (simCost: BigNumber, epCost: BigNumber, message: string): void {
const diff = simCost.sub(epCost).toNumber()
expect(diff).to.be.within(0, 300,
`${message} cost ${simCost.toNumber()} should be (up to 200) above ep cost ${epCost.toNumber()}`)
}
it('deposit on simulation must be >= real entrypoint', async () => {
expect(await epSimulation.estimateGas.depositTo(addr, { value: 1 }))
.to.be.gte(await entryPoint.estimateGas.depositTo(addr, { value: 1 }), 'sim depositTo must be higher')
costInRange(
await epSimulation.estimateGas.depositTo(addr, { value: 1 }),
await entryPoint.estimateGas.depositTo(addr, { value: 1 }), 'deposit with value')
})
it('deposit without value on simulation must be >= real entrypoint', async () => {
expect(await epSimulation.estimateGas.depositTo(addr, { value: 0 }))
.to.be.gte(await entryPoint.estimateGas.depositTo(addr, { value: 0 }), 'sim depositTo (even without value) must be higher')
costInRange(
await epSimulation.estimateGas.depositTo(addr, { value: 0 }),
await entryPoint.estimateGas.depositTo(addr, { value: 0 }), 'deposit without value')
})
it('eth transfer on simulation must be >= real entrypoint', async () => {
expect(await provider.estimateGas({ to: epSimulation.address, value: 1 }))
.to.be.gte(await provider.estimateGas({ to: entryPoint.address, value: 1 }))
costInRange(
await provider.estimateGas({ to: epSimulation.address, value: 1 }),
await provider.estimateGas({ to: entryPoint.address, value: 1 }), 'eth transfer with value')
})
it('eth transfer (even without value) on simulation must be >= real entrypoint', async () => {
expect(await provider.estimateGas({ to: epSimulation.address, value: 0 }))
.to.be.gte(await provider.estimateGas({ to: entryPoint.address, value: 0 }))
costInRange(
await provider.estimateGas({ to: epSimulation.address, value: 0 }),
await provider.estimateGas({ to: entryPoint.address, value: 0 }), 'eth transfer with value')
})
})
/*
Expand Down

0 comments on commit e2f4703

Please sign in to comment.