From 3bce6013803ee75f8caa8df5be0eb72e7d3262f3 Mon Sep 17 00:00:00 2001 From: Zehui Zheng Date: Thu, 12 Oct 2023 02:07:24 +0800 Subject: [PATCH] refactor: rename input related terms --- .../rollups/contracts/inputs/IInputBox.sol | 12 +++---- onchain/rollups/contracts/inputs/InputBox.sol | 16 +++++----- .../rollups/contracts/library/LibInput.sol | 18 +++++------ .../test/foundry/inputs/InputBox.t.sol | 32 +++++++++---------- .../test/foundry/portals/ERC20Portal.t.sol | 4 +-- .../test/foundry/portals/ERC721Portal.t.sol | 4 +-- .../test/foundry/portals/EtherPortal.t.sol | 4 +-- .../foundry/relays/DAppAddressRelay.t.sol | 4 +-- 8 files changed, 47 insertions(+), 47 deletions(-) diff --git a/onchain/rollups/contracts/inputs/IInputBox.sol b/onchain/rollups/contracts/inputs/IInputBox.sol index c6a38469..991724b2 100644 --- a/onchain/rollups/contracts/inputs/IInputBox.sol +++ b/onchain/rollups/contracts/inputs/IInputBox.sol @@ -7,26 +7,26 @@ pragma solidity ^0.8.8; interface IInputBox { /// @notice Emitted when an input is added to a DApp's input box. /// @param dapp The address of the DApp - /// @param inputIndex The index of the input in the input box + /// @param index The index of the input in the input box /// @param sender The address that sent the input - /// @param input The input payload + /// @param payload The input payload /// @dev MUST be triggered on a successful call to `addInput`. event InputAdded( address indexed dapp, - uint256 indexed inputIndex, + uint256 indexed index, address sender, - bytes input + bytes payload ); /// @notice Add an input to a DApp's input box. /// @param _dapp The address of the DApp - /// @param _input The input payload + /// @param _payload The input payload /// @return The hash of the input plus some extra metadata /// @dev MUST fire an `InputAdded` event accordingly. /// Input larger than machine limit will raise `InputSizeExceedsLimit` error. function addInput( address _dapp, - bytes calldata _input + bytes calldata _payload ) external returns (bytes32); /// @notice Get the number of inputs in a DApp's input box. diff --git a/onchain/rollups/contracts/inputs/InputBox.sol b/onchain/rollups/contracts/inputs/InputBox.sol index 015bf9f6..fd3984fc 100644 --- a/onchain/rollups/contracts/inputs/InputBox.sol +++ b/onchain/rollups/contracts/inputs/InputBox.sol @@ -8,11 +8,11 @@ import {LibInput} from "../library/LibInput.sol"; /// @title Input Box /// -/// @notice Trustless and permissionless contract that receives arbitrary blobs -/// (called "inputs") from anyone and adds a compound hash to an append-only list +/// @notice Trustless and permissionless contract that receives arbitrary +/// input payload from anyone and adds a compound hash to an append-only list /// (called "input box"). Each DApp has its own input box. /// -/// The hash that is stored on-chain is composed by the hash of the input blob, +/// The hash that is stored on-chain is composed by the hash of the input payload, /// the block number and timestamp, the input sender address, and the input index. /// /// Data availability is guaranteed by the emission of `InputAdded` events @@ -29,24 +29,24 @@ contract InputBox is IInputBox { function addInput( address _dapp, - bytes calldata _input + bytes calldata _payload ) external override returns (bytes32) { bytes32[] storage inputBox = inputBoxes[_dapp]; - uint256 inputIndex = inputBox.length; + uint256 index = inputBox.length; bytes32 inputHash = LibInput.computeEvmInputHash( msg.sender, block.number, block.timestamp, - inputIndex, - _input + index, + _payload ); // add input to the input box inputBox.push(inputHash); // block.number and timestamp can be retrieved by the event metadata itself - emit InputAdded(_dapp, inputIndex, msg.sender, _input); + emit InputAdded(_dapp, index, msg.sender, _payload); return inputHash; } diff --git a/onchain/rollups/contracts/library/LibInput.sol b/onchain/rollups/contracts/library/LibInput.sol index a8bf4cc7..4f537961 100644 --- a/onchain/rollups/contracts/library/LibInput.sol +++ b/onchain/rollups/contracts/library/LibInput.sol @@ -16,29 +16,29 @@ library LibInput { /// @param sender `msg.sender` /// @param blockNumber `block.number` /// @param blockTimestamp `block.timestamp` - /// @param inputIndex The index of the input in the input box - /// @param input The input payload + /// @param index The index of the input in the input box + /// @param payload The input payload /// @return The EVM input hash function computeEvmInputHash( address sender, uint256 blockNumber, uint256 blockTimestamp, - uint256 inputIndex, - bytes calldata input + uint256 index, + bytes calldata payload ) internal pure returns (bytes32) { - bytes memory inputBlob = abi.encodeWithSignature( + bytes memory input = abi.encodeWithSignature( "EvmInput(address,uint256,uint256,uint256,bytes)", sender, blockNumber, blockTimestamp, - inputIndex, - input + index, + payload ); - if (inputBlob.length > CanonicalMachine.INPUT_MAX_SIZE) { + if (input.length > CanonicalMachine.INPUT_MAX_SIZE) { revert InputSizeExceedsLimit(); } - return keccak256(inputBlob); + return keccak256(input); } } diff --git a/onchain/rollups/test/foundry/inputs/InputBox.t.sol b/onchain/rollups/test/foundry/inputs/InputBox.t.sol index dfdb1744..9db0d94f 100644 --- a/onchain/rollups/test/foundry/inputs/InputBox.t.sol +++ b/onchain/rollups/test/foundry/inputs/InputBox.t.sol @@ -48,7 +48,7 @@ contract InputBoxHandler is Test { vm.roll(blockNumber); } - function addInput(address _dapp, bytes calldata _input) external { + function addInput(address _dapp, bytes calldata _payload) external { // For some reason, the invariant testing framework doesn't // record changes made to block properties, so we have to // set them in the beginning of every call @@ -62,7 +62,7 @@ contract InputBoxHandler is Test { // Make the sender add the input to the DApp's input box vm.prank(msg.sender); - bytes32 inputHash = inputBox.addInput(_dapp, _input); + bytes32 inputHash = inputBox.addInput(_dapp, _payload); // If this is the first input being added to the DApp's input box, // then push the dapp to the array of dapps @@ -103,7 +103,7 @@ contract InputBoxHandler is Test { block.number, block.timestamp, index, - _input + _payload ); // Check if the input hash matches the computed one @@ -139,9 +139,9 @@ contract InputBoxTest is Test { event InputAdded( address indexed dapp, - uint256 indexed inputIndex, + uint256 indexed index, address sender, - bytes input + bytes payload ); function setUp() public { @@ -186,18 +186,18 @@ contract InputBoxTest is Test { } // fuzz testing with multiple inputs - function testAddInput(address _dapp, bytes[] calldata _inputs) public { - uint256 numInputs = _inputs.length; - bytes32[] memory returnedValues = new bytes32[](numInputs); + function testAddInput(address _dapp, bytes[] calldata _payloads) public { + uint256 numPayloads = _payloads.length; + bytes32[] memory returnedValues = new bytes32[](numPayloads); uint256 year2022 = 1641070800; // Unix Timestamp for 2022 - // assume #bytes for each input is within bounds - for (uint256 i; i < numInputs; ++i) { - vm.assume(_inputs[i].length <= getMaxInputPayloadLength()); + // assume #bytes for each payload is within bounds + for (uint256 i; i < numPayloads; ++i) { + vm.assume(_payloads[i].length <= getMaxInputPayloadLength()); } // adding inputs - for (uint256 i; i < numInputs; ++i) { + for (uint256 i; i < numPayloads; ++i) { // test for different block number and timestamp vm.roll(i); vm.warp(i + year2022); // year 2022 @@ -206,23 +206,23 @@ contract InputBoxTest is Test { vm.expectEmit(true, true, false, true, address(inputBox)); // The event we expect - emit InputAdded(_dapp, i, address(this), _inputs[i]); + emit InputAdded(_dapp, i, address(this), _payloads[i]); - returnedValues[i] = inputBox.addInput(_dapp, _inputs[i]); + returnedValues[i] = inputBox.addInput(_dapp, _payloads[i]); // test whether the number of inputs has increased assertEq(i + 1, inputBox.getNumberOfInputs(_dapp)); } // testing added inputs - for (uint256 i; i < numInputs; ++i) { + for (uint256 i; i < numPayloads; ++i) { // compute input hash for each input bytes32 inputHash = LibInput.computeEvmInputHash( address(this), i, // block.number i + year2022, // block.timestamp i, // inputBox.length - _inputs[i] + _payloads[i] ); // test if input hash is the same as in InputBox assertEq(inputHash, inputBox.getInputHash(_dapp, i)); diff --git a/onchain/rollups/test/foundry/portals/ERC20Portal.t.sol b/onchain/rollups/test/foundry/portals/ERC20Portal.t.sol index 8fc454e4..2a104db0 100644 --- a/onchain/rollups/test/foundry/portals/ERC20Portal.t.sol +++ b/onchain/rollups/test/foundry/portals/ERC20Portal.t.sol @@ -92,9 +92,9 @@ contract ERC20PortalTest is Test { event InputAdded( address indexed dapp, - uint256 indexed inputIndex, + uint256 indexed index, address sender, - bytes input + bytes payload ); event WatchedTransfer( address from, diff --git a/onchain/rollups/test/foundry/portals/ERC721Portal.t.sol b/onchain/rollups/test/foundry/portals/ERC721Portal.t.sol index 3cd25216..0b4ca620 100644 --- a/onchain/rollups/test/foundry/portals/ERC721Portal.t.sol +++ b/onchain/rollups/test/foundry/portals/ERC721Portal.t.sol @@ -91,9 +91,9 @@ contract ERC721PortalTest is Test { event InputAdded( address indexed dapp, - uint256 indexed inputIndex, + uint256 indexed index, address sender, - bytes input + bytes payload ); event Transfer( address indexed from, diff --git a/onchain/rollups/test/foundry/portals/EtherPortal.t.sol b/onchain/rollups/test/foundry/portals/EtherPortal.t.sol index 90816aba..f313c175 100644 --- a/onchain/rollups/test/foundry/portals/EtherPortal.t.sol +++ b/onchain/rollups/test/foundry/portals/EtherPortal.t.sol @@ -48,9 +48,9 @@ contract EtherPortalTest is Test { event InputAdded( address indexed dapp, - uint256 indexed inputIndex, + uint256 indexed index, address sender, - bytes input + bytes payload ); event WatchedFallback( address sender, diff --git a/onchain/rollups/test/foundry/relays/DAppAddressRelay.t.sol b/onchain/rollups/test/foundry/relays/DAppAddressRelay.t.sol index b2f70209..7428f459 100644 --- a/onchain/rollups/test/foundry/relays/DAppAddressRelay.t.sol +++ b/onchain/rollups/test/foundry/relays/DAppAddressRelay.t.sol @@ -17,9 +17,9 @@ contract DAppAddressRelayTest is Test { event InputAdded( address indexed dapp, - uint256 indexed inputIndex, + uint256 indexed index, address sender, - bytes input + bytes payload ); function setUp() public {