diff --git a/src/Kernel.sol b/src/Kernel.sol index 890214c1..547b3379 100644 --- a/src/Kernel.sol +++ b/src/Kernel.sol @@ -108,9 +108,11 @@ contract Kernel is EIP712, Compatibility, KernelStorage { bytes memory data = call.data; assembly { let success := call(gas(), to, value, add(data, 0x20), mload(data), 0, 0) - returndatacopy(0, 0, returndatasize()) switch success - case 0 { revert(0, returndatasize()) } + case 0 { + returndatacopy(0, 0, returndatasize()) + revert(0, returndatasize()) + } default { i := add(i, 1) } } } diff --git a/src/common/Constants.sol b/src/common/Constants.sol index b69cb162..a8de9076 100644 --- a/src/common/Constants.sol +++ b/src/common/Constants.sol @@ -4,7 +4,7 @@ import {ValidationData} from "./Types.sol"; // Constants for kernel metadata string constant KERNEL_NAME = "Kernel"; -string constant KERNEL_VERSION = "0.2.3"; +string constant KERNEL_VERSION = "0.2.4"; // ERC4337 constants uint256 constant SIG_VALIDATION_FAILED_UINT = 1; diff --git a/src/mock/TestCallee.sol b/src/mock/TestCallee.sol index d3528a9f..d23830f2 100644 --- a/src/mock/TestCallee.sol +++ b/src/mock/TestCallee.sol @@ -2,6 +2,17 @@ pragma solidity ^0.8.0; contract TestCallee { uint256 public result; + address public caller; + uint256 public sent; + bytes public message; + + receive() external payable {} + + fallback() external payable { + message = msg.data; + sent = msg.value; + caller = msg.sender; + } function test_ignore() external {} @@ -14,5 +25,15 @@ contract TestCallee { require(success, string(data)); } + function returnLong() external payable returns (string memory) { + return + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent nec nunc sed nisi sollicitudin suscipit at at nulla. Aenean porttitor tellus felis, dapibus lacinia elit ullamcorper id. Ut dapibus efficitur neque posuere varius. Aenean in sem ac dolor accumsan egestas ut sit amet arcu. Vestibulum nunc urna, imperdiet ut enim eu, venenatis placerat mi. Aliquam a nibh a augue sollicitudin rutrum. Donec eleifend semper elit eu facilisis."; + } + + function returnLongBytes() external payable returns (bytes memory) { + return + hex"0000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; + } + function notThis() external {} } diff --git a/src/utils/KernelTestBase.sol b/src/utils/KernelTestBase.sol index 8411c6bc..78167ae3 100644 --- a/src/utils/KernelTestBase.sol +++ b/src/utils/KernelTestBase.sol @@ -24,6 +24,7 @@ import {TestValidator} from "../mock/TestValidator.sol"; import {TestExecutor} from "../mock/TestExecutor.sol"; import {TestERC721} from "../mock/TestERC721.sol"; import {TestERC1155} from "../mock/TestERC1155.sol"; +import {TestCallee} from "../mock/TestCallee.sol"; using ERC4337Utils for IEntryPoint; @@ -135,8 +136,24 @@ abstract contract KernelTestBase is Test { } function test_external_call_batch_execute_success() external virtual { - Call[] memory calls = new Call[](1); + TestCallee callee = new TestCallee(); + Call[] memory calls = new Call[](3); calls[0] = Call(owner, 0, ""); + calls[1] = Call(address(callee), 0, abi.encodeWithSelector(callee.returnLong.selector)); + calls[2] = Call(address(callee), 0, abi.encode("HelloWorld")); + vm.prank(owner); + kernel.executeBatch(calls); + assertEq(callee.caller(), address(kernel)); + assertEq(callee.sent(), 0); + assertEq(keccak256(callee.message()), keccak256(abi.encode("HelloWorld"))); + calls = new Call[](3); + calls[0] = Call(owner, 0, ""); + calls[1] = Call(address(callee), 0, abi.encodeWithSelector(callee.returnLongBytes.selector)); + calls[2] = Call(address(callee), 0, abi.encode("HelloWorld")); + assertEq(callee.caller(), address(kernel)); + assertEq(callee.sent(), 0); + assertEq(keccak256(callee.message()), keccak256(abi.encode("HelloWorld"))); + vm.prank(owner); kernel.executeBatch(calls); }