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

Fix EntryPoint revert if postOp reverts with short revert reason #308

Merged
merged 16 commits into from
Aug 15, 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
7 changes: 5 additions & 2 deletions contracts/core/EntryPoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard
} catch {
bytes32 innerRevertCode;
assembly {
returndatacopy(0, 0, 32)
innerRevertCode := mload(0)
let len := returndatasize()
if eq(32,len) {
returndatacopy(0, 0, 32)
innerRevertCode := mload(0)
}
}
// handleOps was called with gas limit too low. abort entire bundle.
if (innerRevertCode == INNER_OUT_OF_GAS) {
Expand Down
30 changes: 30 additions & 0 deletions contracts/test/TestPaymasterRevertCustomError.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.12;

import "../core/BasePaymaster.sol";

/**
* test postOp revert with custom error
*/
error CustomError();

contract TestPaymasterRevertCustomError is BasePaymaster {
// solhint-disable no-empty-blocks
constructor(IEntryPoint _entryPoint) BasePaymaster(_entryPoint)
{}

function _validatePaymasterUserOp(UserOperation calldata userOp, bytes32, uint256)
internal virtual override view
returns (bytes memory context, uint256 validationData) {
validationData = 0;
context = abi.encodePacked(userOp.sender);
}

function _postOp(PostOpMode mode, bytes calldata, uint256) internal override {
if(mode == PostOpMode.postOpReverted) {
return;
}

revert CustomError();
}
}
24 changes: 12 additions & 12 deletions reports/gas-checker.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@
║ │ │ │ (delta for │ (compared to ║
║ │ │ │ one UserOp) │ account.exec()) ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple │ 1 │ 81891 │ │ ║
║ simple │ 1 │ 81921 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple - diff from previous │ 2 │ │ 4415415140
║ simple - diff from previous │ 2 │ │ 4420815194
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple │ 10 │ 479586 │ │ ║
║ simple │ 10 │ 479922 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple - diff from previous │ 11 │ │ 4425015236
║ simple - diff from previous │ 11 │ │ 4424415230
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster │ 1 │ 88162 │ │ ║
║ simple paymaster │ 1 │ 88192 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster with diff │ 2 │ │ 4314314129
║ simple paymaster with diff │ 2 │ │ 4319714183
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster │ 10 │ 476798 │ │ ║
║ simple paymaster │ 10 │ 477170 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster with diff │ 11 │ │ 4321414200
║ simple paymaster with diff │ 11 │ │ 4322014206
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx 5k │ 1 │ 182948 │ │ ║
║ big tx 5k │ 1 │ 182978 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx - diff from previous │ 2 │ │ 14468919429
║ big tx - diff from previous │ 2 │ │ 14468319423
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx 5k │ 10 │ 1485278 │ │ ║
║ big tx 5k │ 10 │ 1485506 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx - diff from previous │ 11 │ │ 14475019490
║ big tx - diff from previous │ 11 │ │ 14474419484
╚════════════════════════════════╧═══════╧═══════════════╧════════════════╧═════════════════════╝

21 changes: 20 additions & 1 deletion test/entrypoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
TestSignatureAggregator,
TestSignatureAggregator__factory,
MaliciousAccount__factory,
TestWarmColdAccount__factory
TestWarmColdAccount__factory,
TestPaymasterRevertCustomError__factory
} from '../typechain'
import {
AddressZero,
Expand Down Expand Up @@ -1171,6 +1172,24 @@ describe('EntryPoint', function () {
await expect(entryPoint.handleOps([op], beneficiaryAddress)).to.revertedWith('"AA31 paymaster deposit too low"')
})

it('should not revert when paymaster reverts with custom error on postOp', async function () {
const account3Owner = createAccountOwner()
const errorPostOp = await new TestPaymasterRevertCustomError__factory(ethersSigner).deploy(entryPoint.address)
await errorPostOp.addStake(globalUnstakeDelaySec, { value: paymasterStake })
await errorPostOp.deposit({ value: ONE_ETH })

const op = await fillAndSign({
paymasterAndData: errorPostOp.address,
callData: accountExecFromEntryPoint.data,
initCode: getAccountInitCode(account3Owner.address, simpleAccountFactory),

verificationGasLimit: 3e6,
callGasLimit: 1e6
}, account3Owner, entryPoint)
const beneficiaryAddress = createAddress()
await entryPoint.handleOps([op], beneficiaryAddress)
})

it('paymaster should pay for tx', async function () {
await paymaster.deposit({ value: ONE_ETH })
const op = await fillAndSign({
Expand Down