Skip to content

Commit

Permalink
use encodeCall before calling innerHandleOp
Browse files Browse the repository at this point in the history
just using encodeCall saves gas
  • Loading branch information
drortirosh committed Jan 1, 2024
1 parent 98e6a95 commit f72fa45
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 23 deletions.
18 changes: 12 additions & 6 deletions contracts/core/EntryPoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,18 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard,
(uint256 collected) {
uint256 preGas = gasleft();
bytes memory context = getMemoryBytesFromOffset(opInfo.contextOffset);

try this.innerHandleOp(userOp.callData, opInfo, context) returns (
uint256 _actualGasCost
) {
collected = _actualGasCost;
} catch {
uint saveFreePtr;
assembly {
saveFreePtr := mload(0x40)
}
bytes memory innerCall = abi.encodeCall(this.innerHandleOp,(userOp.callData, opInfo, context));
bool success;
assembly {
success := call(gas(), address(), 0, add(innerCall, 0x20), mload(innerCall), 0, 32)
collected := mload(0)
mstore(0x40, saveFreePtr)
}
if (!success) {
bytes32 innerRevertCode;
assembly {
let len := returndatasize()
Expand Down
18 changes: 18 additions & 0 deletions contracts/interfaces/IAccountExecute.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;

import "./UserOperation.sol";

interface IAccountExecute {
/**
* Account MAY implement this execute method.
* passing this methodSig as callData will cause the entryPoint to pass the full UserOp (and hash)
* to the account.
* @param userOp - The operation that was just validated.
* @param userOpHash - Hash of the user's request data.
*/
function executeUserOp(
UserOperation calldata userOp,
bytes32 userOpHash
) external;
}
34 changes: 17 additions & 17 deletions reports/gas-checker.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,44 @@
╔══════════════════════════╤════════╗
║ gas estimate "simple" │ 29014 ║
╟──────────────────────────┼────────╢
║ gas estimate "big tx 5k" │ 125260
║ gas estimate "big tx 5k" │ 125248
╚══════════════════════════╧════════╝

╔════════════════════════════════╤═══════╤═══════════════╤════════════════╤═════════════════════╗
║ handleOps description │ count │ total gasUsed │ per UserOp gas │ per UserOp overhead ║
║ │ │ │ (delta for │ (compared to ║
║ │ │ │ one UserOp) │ account.exec()) ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple │ 1 │ 81918 │ │ ║
║ simple │ 1 │ 81808 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple - diff from previous │ 2 │ │ 4418715173
║ simple - diff from previous │ 2 │ │ 4404115027
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple │ 10 │ 479730 │ │ ║
║ simple │ 10 │ 478604 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple - diff from previous │ 11 │ │ 4424715233
║ simple - diff from previous │ 11 │ │ 4409615082
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster │ 1 │ 89813 │ │ ║
║ simple paymaster │ 1 │ 89670 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster with diff │ 2 │ │ 4479615782
║ simple paymaster with diff │ 2 │ │ 4467115657
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster │ 10 │ 493254 │ │ ║
║ simple paymaster │ 10 │ 491926 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster with diff │ 11 │ │ 4482015806
║ simple paymaster with diff │ 11 │ │ 4475215738
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx 5k │ 1 │ 182975 │ │ ║
║ big tx 5k │ 1 │ 182841 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx - diff from previous │ 2 │ │ 14469819438
║ big tx - diff from previous │ 2 │ │ 14457619328
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx 5k │ 10 │ 1485374 │ │ ║
║ big tx 5k │ 10 │ 1484244 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx - diff from previous │ 11 │ │ 14475919499
║ big tx - diff from previous │ 11 │ │ 14462019372
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster │ 1 │ 148244 │ │ ║
║ token paymaster │ 1 │ 148138 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster with diff │ 2 │ │ 7292043906
║ token paymaster with diff │ 2 │ │ 7279443780
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster │ 10 │ 804795 │ │ ║
║ token paymaster │ 10 │ 803643 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster with diff │ 11 │ │ 7301544001
║ token paymaster with diff │ 11 │ │ 7292243908
╚════════════════════════════════╧═══════╧═══════════════╧════════════════╧═════════════════════╝

0 comments on commit f72fa45

Please sign in to comment.