Skip to content

Commit

Permalink
refactor: add encodeEvmInput library function
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzzzHui committed Oct 31, 2023
1 parent 3bce601 commit 0002d32
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
28 changes: 26 additions & 2 deletions onchain/rollups/contracts/library/LibInput.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,31 @@ library LibInput {
/// @notice Raised when input is larger than the machine limit.
error InputSizeExceedsLimit();

/// @notice Encode input with EvmInput signature
/// @param sender `msg.sender`
/// @param blockNumber `block.number`
/// @param blockTimestamp `block.timestamp`
/// @param index The index of the input in the input box
/// @param payload The input payload
/// @return The encoded EVM input
function encodeEvmInput(
address sender,
uint256 blockNumber,
uint256 blockTimestamp,
uint256 index,
bytes memory payload
) internal pure returns (bytes memory) {
return
abi.encodeWithSignature(
"EvmInput(address,uint256,uint256,uint256,bytes)",
sender,
blockNumber,
blockTimestamp,
index,
payload
);
}

/// @notice Summarize input data in a single hash.
/// @param sender `msg.sender`
/// @param blockNumber `block.number`
Expand All @@ -26,8 +51,7 @@ library LibInput {
uint256 index,
bytes calldata payload
) internal pure returns (bytes32) {
bytes memory input = abi.encodeWithSignature(
"EvmInput(address,uint256,uint256,uint256,bytes)",
bytes memory input = encodeEvmInput(
sender,
blockNumber,
blockTimestamp,
Expand Down
3 changes: 1 addition & 2 deletions onchain/rollups/test/foundry/inputs/InputBox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ contract InputBoxTest is Test {

function getMaxInputPayloadLength() internal pure returns (uint256) {
// an input blob instance
bytes memory blob = abi.encodeWithSignature(
"EvmInput(address,uint256,uint256,uint256,bytes)",
bytes memory blob = LibInput.encodeEvmInput(
address(0),
0,
0,
Expand Down

0 comments on commit 0002d32

Please sign in to comment.