diff --git a/.gitmodules b/.gitmodules index 918f59a3..3f78d886 100644 --- a/.gitmodules +++ b/.gitmodules @@ -5,7 +5,6 @@ [submodule "lib/forge-std"] path = lib/forge-std url = https://github.com/foundry-rs/forge-std - branch = v1.5.2 [submodule "lib/openzeppelin-contracts"] path = lib/openzeppelin-contracts url = https://github.com/OpenZeppelin/openzeppelin-contracts @@ -13,3 +12,6 @@ [submodule "lib/solady"] path = lib/solady url = https://github.com/vectorized/solady +[submodule "lib/aa-benchmark"] + path = lib/aa-benchmark + url = https://github.com/zerodevapp/aa-benchmark diff --git a/lib/aa-benchmark b/lib/aa-benchmark new file mode 160000 index 00000000..30fa9720 --- /dev/null +++ b/lib/aa-benchmark @@ -0,0 +1 @@ +Subproject commit 30fa97200557e6ebb76b5497366de1975b8b8997 diff --git a/lib/forge-std b/lib/forge-std index 2b58ecbc..705263c9 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 2b58ecbcf3dfde7a75959dc7b4eb3d0670278de6 +Subproject commit 705263c95892a906d7af65f0f73ce8a4a0c80b80 diff --git a/src/Kernel.sol b/src/Kernel.sol index 0d4fdfd2..bdd9c67f 100644 --- a/src/Kernel.sol +++ b/src/Kernel.sol @@ -147,7 +147,7 @@ contract Kernel is EIP712, Compatibility, KernelStorage { } if (missingAccountFunds != 0) { assembly { - pop(call(gas(), caller(), missingAccountFunds, 0, 0, 0, 0)) + pop(call(gas(), caller(), add(missingAccountFunds,1), 0, 0, 0, 0)) } //ignore failure (its EntryPoint's job to verify, not account.) } diff --git a/test/foundry/Benchmark.t.sol b/test/foundry/Benchmark.t.sol new file mode 100644 index 00000000..dd4e585c --- /dev/null +++ b/test/foundry/Benchmark.t.sol @@ -0,0 +1,62 @@ +pragma solidity ^0.8.0; + +import "aa-benchmark/src/TestBase.sol"; +import {Kernel,KernelStorage} from "src/Kernel.sol"; +import {KernelFactory} from "src/factory/KernelFactory.sol"; +import {ECDSAValidator} from "src/validator/ECDSAValidator.sol"; +contract Benchmark is AAGasProfileBase { + Kernel kernelImpl; + KernelFactory factory; + ECDSAValidator validator; + address factoryOwner; + + function setUp() external { + factoryOwner = address(0); + initializeTest("kernelv2_1"); + factory = new KernelFactory(factoryOwner, entryPoint); + kernelImpl = new Kernel(entryPoint); + vm.startPrank(factoryOwner); + factory.setImplementation(address(kernelImpl), true); + vm.stopPrank(); + validator = new ECDSAValidator(); + setAccount(); + } + + function fillData(address _to, uint256 _value, bytes memory _data) internal override returns (bytes memory) { + return abi.encodeWithSelector(Kernel.execute.selector, _to, _value, _data, uint8(0)); + } + + function createAccount(address _owner) internal override { + if (address(account).code.length == 0) { + factory.createAccount( + address(kernelImpl), + abi.encodeWithSelector(KernelStorage.initialize.selector, validator, abi.encodePacked(_owner)), + 0 + ); + } + } + + function getAccountAddr(address _owner) internal override returns (IAccount) { + return IAccount( + factory.getAccountAddress( + abi.encodeWithSelector(KernelStorage.initialize.selector, validator, abi.encodePacked(_owner)), 0 + ) + ); + } + + function getInitCode(address _owner) internal override returns (bytes memory) { + return abi.encodePacked( + address(factory), + abi.encodeWithSelector( + factory.createAccount.selector, + kernelImpl, + abi.encodeWithSelector(KernelStorage.initialize.selector, validator, abi.encodePacked(_owner)), + 0 + ) + ); + } + + function getSignature(UserOperation memory _op) internal override returns (bytes memory) { + return abi.encodePacked(bytes4(0x00000000), signUserOpHash(key, _op)); + } +}