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/execute batch #85

Merged
merged 3 commits into from
Feb 22, 2024
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
6 changes: 4 additions & 2 deletions src/Kernel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions src/mock/TestCallee.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand All @@ -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 {}
}
19 changes: 18 additions & 1 deletion src/utils/KernelTestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
Loading