Skip to content

Commit

Permalink
refactor: rename input related terms
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzzzHui committed Oct 31, 2023
1 parent a846f4a commit 3bce601
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 47 deletions.
12 changes: 6 additions & 6 deletions onchain/rollups/contracts/inputs/IInputBox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions onchain/rollups/contracts/inputs/InputBox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
18 changes: 9 additions & 9 deletions onchain/rollups/contracts/library/LibInput.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
32 changes: 16 additions & 16 deletions onchain/rollups/test/foundry/inputs/InputBox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -103,7 +103,7 @@ contract InputBoxHandler is Test {
block.number,
block.timestamp,
index,
_input
_payload
);

// Check if the input hash matches the computed one
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions onchain/rollups/test/foundry/portals/ERC20Portal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions onchain/rollups/test/foundry/portals/ERC721Portal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions onchain/rollups/test/foundry/portals/EtherPortal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions onchain/rollups/test/foundry/relays/DAppAddressRelay.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3bce601

Please sign in to comment.