diff --git a/onchain/rollups/.changeset/cuddly-ears-obey.md b/onchain/rollups/.changeset/cuddly-ears-obey.md new file mode 100644 index 00000000..b6a9ee0e --- /dev/null +++ b/onchain/rollups/.changeset/cuddly-ears-obey.md @@ -0,0 +1,9 @@ +--- +"@cartesi/rollups": major +--- + +Renamed `inputIndex` as `index`, and `input` as `payload`. +This change was made to draw a clear distinction between input and payload, in the context of the `InputBox` contract. +When a user submits a payload, it is encoded along with metadata to form an input blob, which is then forwarded to the Cartesi Machine. +The `InputAdded` event now emits the input blob instead of the payload. +As a result, you can now feed the machine with the input blob as-is, and let it be decoded in user space. diff --git a/onchain/rollups/contracts/common/Inputs.sol b/onchain/rollups/contracts/common/Inputs.sol index 86b380a0..7ae66f68 100644 --- a/onchain/rollups/contracts/common/Inputs.sol +++ b/onchain/rollups/contracts/common/Inputs.sol @@ -10,14 +10,14 @@ interface Inputs { /// @param sender The address of whoever sent the input /// @param blockNumber The number of the block in which the input was added /// @param blockTimestamp The timestamp of the block in which the input was added - /// @param inputIndex The index of the input in the DApp's input box - /// @param input The payload provided by the sender + /// @param index The index of the input in the DApp's input box + /// @param payload The payload provided by the sender function EvmAdvance( address sender, uint256 blockNumber, uint256 blockTimestamp, - uint256 inputIndex, - bytes calldata input + uint256 index, + bytes calldata payload ) external; /// @notice An inspect request from an EVM-compatible blockchain to a Cartesi Machine. diff --git a/onchain/rollups/contracts/inputs/IInputBox.sol b/onchain/rollups/contracts/inputs/IInputBox.sol index a6887121..4602000b 100644 --- a/onchain/rollups/contracts/inputs/IInputBox.sol +++ b/onchain/rollups/contracts/inputs/IInputBox.sol @@ -10,20 +10,20 @@ 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 input The input payload + /// @param index The index of the input in the DApp's input box + /// @param input The input blob /// @dev MUST be triggered on a successful call to `addInput`. - event InputAdded(address indexed dapp, uint256 indexed inputIndex, bytes input); + event InputAdded(address indexed dapp, uint256 indexed index, bytes input); /// @notice Add an input to a DApp's input box. /// @param _dapp The address of the DApp - /// @param _input The input payload - /// @return The hash of the input plus some extra metadata + /// @param _payload The input payload + /// @return The hash of the input blob /// @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 66d6d620..3256c849 100644 --- a/onchain/rollups/contracts/inputs/InputBox.sol +++ b/onchain/rollups/contracts/inputs/InputBox.sol @@ -13,8 +13,8 @@ import {Inputs} from "../common/Inputs.sol"; /// data from anyone and adds a compound hash to an append-only list /// (called "input box"). Each DApp has its own input box. /// -/// The input hash is composed by the input payload, the block number and timestamp, -/// the address of the input sender, and the index of the input. +/// The input blob is composed of the address of the input sender, +/// the block number and timestamp, the input index and payload. /// /// Data availability is guaranteed by the emission of `InputAdded` events /// on every successful call to `addInput`. This ensures that inputs can be @@ -32,14 +32,14 @@ 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; bytes memory input = abi.encodeCall( Inputs.EvmAdvance, - (msg.sender, block.number, block.timestamp, inputIndex, _input) + (msg.sender, block.number, block.timestamp, index, _payload) ); if (input.length > CanonicalMachine.INPUT_MAX_SIZE) { @@ -48,11 +48,9 @@ contract InputBox is IInputBox { bytes32 inputHash = keccak256(input); - // 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, input); + emit InputAdded(_dapp, index, input); return inputHash; } diff --git a/onchain/rollups/contracts/portals/ERC1155BatchPortal.sol b/onchain/rollups/contracts/portals/ERC1155BatchPortal.sol index 1aeee7c7..4a4d5627 100644 --- a/onchain/rollups/contracts/portals/ERC1155BatchPortal.sol +++ b/onchain/rollups/contracts/portals/ERC1155BatchPortal.sol @@ -35,7 +35,7 @@ contract ERC1155BatchPortal is InputRelay, IERC1155BatchPortal { _baseLayerData ); - bytes memory input = InputEncoding.encodeBatchERC1155Deposit( + bytes memory payload = InputEncoding.encodeBatchERC1155Deposit( _token, msg.sender, _tokenIds, @@ -44,6 +44,6 @@ contract ERC1155BatchPortal is InputRelay, IERC1155BatchPortal { _execLayerData ); - inputBox.addInput(_dapp, input); + inputBox.addInput(_dapp, payload); } } diff --git a/onchain/rollups/contracts/portals/ERC1155SinglePortal.sol b/onchain/rollups/contracts/portals/ERC1155SinglePortal.sol index 747a2b62..f9c60266 100644 --- a/onchain/rollups/contracts/portals/ERC1155SinglePortal.sol +++ b/onchain/rollups/contracts/portals/ERC1155SinglePortal.sol @@ -35,7 +35,7 @@ contract ERC1155SinglePortal is InputRelay, IERC1155SinglePortal { _baseLayerData ); - bytes memory input = InputEncoding.encodeSingleERC1155Deposit( + bytes memory payload = InputEncoding.encodeSingleERC1155Deposit( _token, msg.sender, _tokenId, @@ -44,6 +44,6 @@ contract ERC1155SinglePortal is InputRelay, IERC1155SinglePortal { _execLayerData ); - inputBox.addInput(_dapp, input); + inputBox.addInput(_dapp, payload); } } diff --git a/onchain/rollups/contracts/portals/ERC20Portal.sol b/onchain/rollups/contracts/portals/ERC20Portal.sol index 98876571..adcfcc9d 100644 --- a/onchain/rollups/contracts/portals/ERC20Portal.sol +++ b/onchain/rollups/contracts/portals/ERC20Portal.sol @@ -30,13 +30,13 @@ contract ERC20Portal is InputRelay, IERC20Portal { ) external override { _token.safeTransferFrom(msg.sender, _dapp, _amount); - bytes memory input = InputEncoding.encodeERC20Deposit( + bytes memory payload = InputEncoding.encodeERC20Deposit( _token, msg.sender, _amount, _execLayerData ); - inputBox.addInput(_dapp, input); + inputBox.addInput(_dapp, payload); } } diff --git a/onchain/rollups/contracts/portals/ERC721Portal.sol b/onchain/rollups/contracts/portals/ERC721Portal.sol index 0e36bbe5..5d560c00 100644 --- a/onchain/rollups/contracts/portals/ERC721Portal.sol +++ b/onchain/rollups/contracts/portals/ERC721Portal.sol @@ -28,7 +28,7 @@ contract ERC721Portal is InputRelay, IERC721Portal { ) external override { _token.safeTransferFrom(msg.sender, _dapp, _tokenId, _baseLayerData); - bytes memory input = InputEncoding.encodeERC721Deposit( + bytes memory payload = InputEncoding.encodeERC721Deposit( _token, msg.sender, _tokenId, @@ -36,6 +36,6 @@ contract ERC721Portal is InputRelay, IERC721Portal { _execLayerData ); - inputBox.addInput(_dapp, input); + inputBox.addInput(_dapp, payload); } } diff --git a/onchain/rollups/contracts/portals/EtherPortal.sol b/onchain/rollups/contracts/portals/EtherPortal.sol index 46a9a9ba..fa772513 100644 --- a/onchain/rollups/contracts/portals/EtherPortal.sol +++ b/onchain/rollups/contracts/portals/EtherPortal.sol @@ -32,12 +32,12 @@ contract EtherPortal is InputRelay, IEtherPortal { revert EtherTransferFailed(); } - bytes memory input = InputEncoding.encodeEtherDeposit( + bytes memory payload = InputEncoding.encodeEtherDeposit( msg.sender, msg.value, _execLayerData ); - inputBox.addInput(_dapp, input); + inputBox.addInput(_dapp, payload); } } diff --git a/onchain/rollups/contracts/relays/DAppAddressRelay.sol b/onchain/rollups/contracts/relays/DAppAddressRelay.sol index ff3520e3..4188043f 100644 --- a/onchain/rollups/contracts/relays/DAppAddressRelay.sol +++ b/onchain/rollups/contracts/relays/DAppAddressRelay.sol @@ -18,7 +18,7 @@ contract DAppAddressRelay is InputRelay, IDAppAddressRelay { constructor(IInputBox _inputBox) InputRelay(_inputBox) {} function relayDAppAddress(address _dapp) external override { - bytes memory input = InputEncoding.encodeDAppAddressRelay(_dapp); - inputBox.addInput(_dapp, input); + bytes memory payload = InputEncoding.encodeDAppAddressRelay(_dapp); + inputBox.addInput(_dapp, payload); } } diff --git a/onchain/rollups/test/foundry/inputs/InputBox.t.sol b/onchain/rollups/test/foundry/inputs/InputBox.t.sol index c45c4106..cb606542 100644 --- a/onchain/rollups/test/foundry/inputs/InputBox.t.sol +++ b/onchain/rollups/test/foundry/inputs/InputBox.t.sol @@ -10,6 +10,8 @@ import {IInputBox} from "contracts/inputs/IInputBox.sol"; import {CanonicalMachine} from "contracts/common/CanonicalMachine.sol"; import {Inputs} from "contracts/common/Inputs.sol"; +import {EncodeEvmAdvance} from "../util/EncodeEvmAdvance.sol"; + contract InputBoxHandler is Test { IInputBox immutable inputBox; @@ -48,7 +50,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 +64,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 @@ -101,7 +103,7 @@ contract InputBoxHandler is Test { bytes32 computedInputHash = keccak256( abi.encodeCall( Inputs.EvmAdvance, - (msg.sender, block.number, block.timestamp, index, _input) + (msg.sender, block.number, block.timestamp, index, _payload) ) ); @@ -136,7 +138,7 @@ contract InputBoxTest is Test { InputBox inputBox; InputBoxHandler handler; - event InputAdded(address indexed dapp, uint256 indexed inputIndex, bytes input); + event InputAdded(address indexed dapp, uint256 indexed index, bytes input); function setUp() public { inputBox = new InputBox(); @@ -164,18 +166,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 @@ -184,16 +186,24 @@ contract InputBoxTest is Test { vm.expectEmit(true, true, false, true, address(inputBox)); // The event we expect - emit InputAdded(_dapp, i, _inputs[i]); + emit InputAdded( + _dapp, + i, + EncodeEvmAdvance.encodeEvmAdvance( + address(this), + i, + _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 = keccak256( abi.encodeCall( @@ -203,7 +213,7 @@ contract InputBoxTest is Test { i, // block.number i + year2022, // block.timestamp i, // inputBox.length - _inputs[i] + _payloads[i] ) ) ); diff --git a/onchain/rollups/test/foundry/portals/ERC1155BatchPortal.t.sol b/onchain/rollups/test/foundry/portals/ERC1155BatchPortal.t.sol index 563610b3..f8aa999b 100644 --- a/onchain/rollups/test/foundry/portals/ERC1155BatchPortal.t.sol +++ b/onchain/rollups/test/foundry/portals/ERC1155BatchPortal.t.sol @@ -12,6 +12,9 @@ import {IERC1155} from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol"; import {IERC1155Receiver} from "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol"; import {IInputBox} from "contracts/inputs/IInputBox.sol"; import {InputBox} from "contracts/inputs/InputBox.sol"; +import {InputEncoding} from "contracts/common/InputEncoding.sol"; + +import {EncodeEvmAdvance} from "../util/EncodeEvmAdvance.sol"; contract BatchToken is ERC1155 { constructor( @@ -71,7 +74,7 @@ contract ERC1155BatchPortalTest is Test { uint256[] ids, uint256[] values ); - event InputAdded(address indexed dapp, uint256 indexed inputIndex, bytes input); + event InputAdded(address indexed dapp, uint256 indexed index, bytes input); function setUp() public { inputBox = new InputBox(); @@ -107,7 +110,7 @@ contract ERC1155BatchPortalTest is Test { vm.expectEmit(true, true, true, true); emit TransferBatch(address(portal), alice, dapp, tokenIds, values); // Expect InputAdded to be emitted with the right arguments - bytes memory input = this.encodeBatchERC1155Deposit( + bytes memory payload = this.encodeBatchERC1155Deposit( token, alice, tokenIds, @@ -116,7 +119,11 @@ contract ERC1155BatchPortalTest is Test { execLayerData ); vm.expectEmit(true, true, false, true, address(inputBox)); - emit InputAdded(dapp, 0, input); + emit InputAdded( + dapp, + 0, + EncodeEvmAdvance.encodeEvmAdvance(address(portal), 0, payload) + ); portal.depositBatchERC1155Token( token, @@ -193,7 +200,7 @@ contract ERC1155BatchPortalTest is Test { vm.expectEmit(true, true, true, true); emit TransferBatch(address(portal), alice, dapp, tokenIds, values); // Expect InputAdded to be emitted with the right arguments - bytes memory input = this.encodeBatchERC1155Deposit( + bytes memory payload = this.encodeBatchERC1155Deposit( token, alice, tokenIds, @@ -202,7 +209,11 @@ contract ERC1155BatchPortalTest is Test { execLayerData ); vm.expectEmit(true, true, false, true, address(inputBox)); - emit InputAdded(dapp, 0, input); + emit InputAdded( + dapp, + 0, + EncodeEvmAdvance.encodeEvmAdvance(address(portal), 0, payload) + ); portal.depositBatchERC1155Token( token, diff --git a/onchain/rollups/test/foundry/portals/ERC1155SinglePortal.t.sol b/onchain/rollups/test/foundry/portals/ERC1155SinglePortal.t.sol index a2483f75..6c4d7efd 100644 --- a/onchain/rollups/test/foundry/portals/ERC1155SinglePortal.t.sol +++ b/onchain/rollups/test/foundry/portals/ERC1155SinglePortal.t.sol @@ -14,6 +14,8 @@ import {IInputBox} from "contracts/inputs/IInputBox.sol"; import {InputBox} from "contracts/inputs/InputBox.sol"; import {InputEncoding} from "contracts/common/InputEncoding.sol"; +import {EncodeEvmAdvance} from "../util/EncodeEvmAdvance.sol"; + contract NormalToken is ERC1155 { constructor( address tokenOwner, @@ -82,7 +84,7 @@ contract ERC1155SinglePortalTest is Test { uint256 id, uint256 value ); - event InputAdded(address indexed dapp, uint256 indexed inputIndex, bytes input); + event InputAdded(address indexed dapp, uint256 indexed index, bytes input); function setUp() public { inputBox = new InputBox(); @@ -115,7 +117,7 @@ contract ERC1155SinglePortalTest is Test { vm.expectEmit(true, true, true, true); emit TransferSingle(address(portal), alice, dapp, tokenId, value); // Expect InputAdded to be emitted with the right arguments - bytes memory input = InputEncoding.encodeSingleERC1155Deposit( + bytes memory payload = InputEncoding.encodeSingleERC1155Deposit( token, alice, tokenId, @@ -124,7 +126,11 @@ contract ERC1155SinglePortalTest is Test { execLayerData ); vm.expectEmit(true, true, false, true, address(inputBox)); - emit InputAdded(dapp, 0, input); + emit InputAdded( + dapp, + 0, + EncodeEvmAdvance.encodeEvmAdvance(address(portal), 0, payload) + ); portal.depositSingleERC1155Token( token, @@ -198,7 +204,7 @@ contract ERC1155SinglePortalTest is Test { vm.expectEmit(true, true, true, true); emit TransferSingle(address(portal), alice, dapp, tokenId, value); // Expect InputAdded to be emitted with the right arguments - bytes memory input = InputEncoding.encodeSingleERC1155Deposit( + bytes memory payload = InputEncoding.encodeSingleERC1155Deposit( token, alice, tokenId, @@ -207,7 +213,11 @@ contract ERC1155SinglePortalTest is Test { execLayerData ); vm.expectEmit(true, true, false, true, address(inputBox)); - emit InputAdded(dapp, 0, input); + emit InputAdded( + dapp, + 0, + EncodeEvmAdvance.encodeEvmAdvance(address(portal), 0, payload) + ); portal.depositSingleERC1155Token( token, diff --git a/onchain/rollups/test/foundry/portals/ERC20Portal.t.sol b/onchain/rollups/test/foundry/portals/ERC20Portal.t.sol index ac9c4179..c65aca82 100644 --- a/onchain/rollups/test/foundry/portals/ERC20Portal.t.sol +++ b/onchain/rollups/test/foundry/portals/ERC20Portal.t.sol @@ -11,6 +11,9 @@ import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IInputBox} from "contracts/inputs/IInputBox.sol"; import {InputBox} from "contracts/inputs/InputBox.sol"; +import {InputEncoding} from "contracts/common/InputEncoding.sol"; + +import {EncodeEvmAdvance} from "../util/EncodeEvmAdvance.sol"; contract NormalToken is ERC20 { constructor( @@ -117,7 +120,7 @@ contract ERC20PortalTest is Test { address alice; address dapp; - event InputAdded(address indexed dapp, uint256 indexed inputIndex, bytes input); + event InputAdded(address indexed dapp, uint256 indexed index, bytes input); event WatchedTransfer( address from, address to, @@ -140,8 +143,13 @@ contract ERC20PortalTest is Test { // Create a normal token token = new NormalToken(alice, _amount); - // Construct the ERC-20 deposit input - bytes memory input = abi.encodePacked(token, alice, _amount, _data); + // Construct the ERC-20 deposit input payload + bytes memory payload = InputEncoding.encodeERC20Deposit( + token, + alice, + _amount, + _data + ); vm.startPrank(alice); @@ -155,7 +163,11 @@ contract ERC20PortalTest is Test { // Expect InputAdded to be emitted with the right arguments vm.expectEmit(true, true, false, true, address(inputBox)); - emit InputAdded(dapp, 0, input); + emit InputAdded( + dapp, + 0, + EncodeEvmAdvance.encodeEvmAdvance(address(portal), 0, payload) + ); // Transfer ERC-20 tokens to the DApp via the portal portal.depositERC20Tokens(token, dapp, _amount, _data); diff --git a/onchain/rollups/test/foundry/portals/ERC721Portal.t.sol b/onchain/rollups/test/foundry/portals/ERC721Portal.t.sol index 8b480677..076222f1 100644 --- a/onchain/rollups/test/foundry/portals/ERC721Portal.t.sol +++ b/onchain/rollups/test/foundry/portals/ERC721Portal.t.sol @@ -14,6 +14,8 @@ import {IInputBox} from "contracts/inputs/IInputBox.sol"; import {InputBox} from "contracts/inputs/InputBox.sol"; import {InputEncoding} from "contracts/common/InputEncoding.sol"; +import {EncodeEvmAdvance} from "../util/EncodeEvmAdvance.sol"; + contract NormalToken is ERC721 { constructor( address _tokenOwner, @@ -89,7 +91,7 @@ contract ERC721PortalTest is Test { address alice; address dapp; - event InputAdded(address indexed dapp, uint256 indexed inputIndex, bytes input); + event InputAdded(address indexed dapp, uint256 indexed index, bytes input); event Transfer( address indexed from, address indexed to, @@ -124,8 +126,8 @@ contract ERC721PortalTest is Test { // Create a normal token with one NFT token = new NormalToken(alice, _tokenId); - // Construct the ERC-721 deposit input - bytes memory input = abi.encodePacked( + // Construct the ERC-721 deposit input payload + bytes memory payload = abi.encodePacked( token, alice, _tokenId, @@ -147,7 +149,11 @@ contract ERC721PortalTest is Test { // Expect InputAdded to be emitted with the right arguments vm.expectEmit(true, true, false, true, address(inputBox)); - emit InputAdded(dapp, 0, input); + emit InputAdded( + dapp, + 0, + EncodeEvmAdvance.encodeEvmAdvance(address(portal), 0, payload) + ); // Transfer ERC-721 tokens to the DApp via the portal portal.depositERC721Token( @@ -178,8 +184,8 @@ contract ERC721PortalTest is Test { // Create a normal token with one NFT token = new NormalToken(alice, _tokenId); - // Construct the ERC-721 deposit input - bytes memory input = abi.encodePacked( + // Construct the ERC-721 deposit input payload + bytes memory payload = abi.encodePacked( token, alice, _tokenId, @@ -201,7 +207,11 @@ contract ERC721PortalTest is Test { // Expect InputAdded to be emitted with the right arguments vm.expectEmit(true, true, false, true, address(inputBox)); - emit InputAdded(dapp, 0, input); + emit InputAdded( + dapp, + 0, + EncodeEvmAdvance.encodeEvmAdvance(address(portal), 0, payload) + ); // Transfer ERC-721 tokens to the DApp via the portal portal.depositERC721Token( @@ -295,8 +305,8 @@ contract ERC721PortalTest is Test { // Create a normal token with one NFT token = new NormalToken(alice, _tokenId); - // Construct the ERC-721 deposit input - bytes memory input = abi.encodePacked( + // Construct the ERC-721 deposit input payload + bytes memory payload = abi.encodePacked( token, alice, _tokenId, @@ -328,7 +338,11 @@ contract ERC721PortalTest is Test { // Expect InputAdded to be emitted with the right arguments vm.expectEmit(true, true, false, true, address(inputBox)); - emit InputAdded(dapp, 0, input); + emit InputAdded( + dapp, + 0, + EncodeEvmAdvance.encodeEvmAdvance(address(portal), 0, payload) + ); // Deposit token in DApp's account portal.depositERC721Token( diff --git a/onchain/rollups/test/foundry/portals/EtherPortal.t.sol b/onchain/rollups/test/foundry/portals/EtherPortal.t.sol index ca8f3dc0..5dd90846 100644 --- a/onchain/rollups/test/foundry/portals/EtherPortal.t.sol +++ b/onchain/rollups/test/foundry/portals/EtherPortal.t.sol @@ -11,6 +11,8 @@ import {IInputBox} from "contracts/inputs/IInputBox.sol"; import {InputBox} from "contracts/inputs/InputBox.sol"; import {InputEncoding} from "contracts/common/InputEncoding.sol"; +import {EncodeEvmAdvance} from "../util/EncodeEvmAdvance.sol"; + contract BadEtherReceiver { receive() external payable { revert("This contract does not accept Ether"); @@ -46,7 +48,7 @@ contract EtherPortalTest is Test { address alice; address dapp; - event InputAdded(address indexed dapp, uint256 indexed inputIndex, bytes input); + event InputAdded(address indexed dapp, uint256 indexed index, bytes input); event WatchedFallback( address sender, uint256 value, @@ -65,8 +67,8 @@ contract EtherPortalTest is Test { } function testEtherDeposit(uint256 value, bytes calldata data) public { - // Construct the Ether deposit input - bytes memory input = abi.encodePacked(alice, value, data); + // Construct the Ether deposit input payload + bytes memory payload = abi.encodePacked(alice, value, data); // Transfer Ether to Alice and start impersonating her startHoax(alice, value); @@ -78,7 +80,11 @@ contract EtherPortalTest is Test { // Expect InputAdded to be emitted with the right arguments vm.expectEmit(true, true, false, true, address(inputBox)); - emit InputAdded(dapp, 0, input); + emit InputAdded( + dapp, + 0, + EncodeEvmAdvance.encodeEvmAdvance(address(etherPortal), 0, payload) + ); // Deposit Ether in the DApp via the portal etherPortal.depositEther{value: value}(dapp, data); diff --git a/onchain/rollups/test/foundry/relays/DAppAddressRelay.t.sol b/onchain/rollups/test/foundry/relays/DAppAddressRelay.t.sol index 6f392546..b7b1f760 100644 --- a/onchain/rollups/test/foundry/relays/DAppAddressRelay.t.sol +++ b/onchain/rollups/test/foundry/relays/DAppAddressRelay.t.sol @@ -11,11 +11,13 @@ import {IInputBox} from "contracts/inputs/IInputBox.sol"; import {InputBox} from "contracts/inputs/InputBox.sol"; import {InputEncoding} from "contracts/common/InputEncoding.sol"; +import {EncodeEvmAdvance} from "../util/EncodeEvmAdvance.sol"; + contract DAppAddressRelayTest is Test { IInputBox inputBox; IDAppAddressRelay relay; - event InputAdded(address indexed dapp, uint256 indexed inputIndex, bytes input); + event InputAdded(address indexed dapp, uint256 indexed index, bytes input); function setUp() public { inputBox = new InputBox(); @@ -30,12 +32,16 @@ contract DAppAddressRelayTest is Test { // Check the DApp's input box before assertEq(inputBox.getNumberOfInputs(_dapp), 0); - // Construct the DApp address relay input - bytes memory input = abi.encodePacked(_dapp); + // Construct the DApp address relay input payload + bytes memory payload = abi.encodePacked(_dapp); // Expect InputAdded to be emitted with the right arguments vm.expectEmit(true, true, false, true, address(inputBox)); - emit InputAdded(_dapp, 0, input); + emit InputAdded( + _dapp, + 0, + EncodeEvmAdvance.encodeEvmAdvance(address(relay), 0, payload) + ); // Relay the DApp's address relay.relayDAppAddress(_dapp); diff --git a/onchain/rollups/test/foundry/util/EncodeEvmAdvance.sol b/onchain/rollups/test/foundry/util/EncodeEvmAdvance.sol new file mode 100644 index 00000000..8c653f88 --- /dev/null +++ b/onchain/rollups/test/foundry/util/EncodeEvmAdvance.sol @@ -0,0 +1,21 @@ +// (c) Cartesi and individual authors (see AUTHORS) +// SPDX-License-Identifier: Apache-2.0 (see LICENSE) + +/// @title Test base contract +pragma solidity ^0.8.8; + +import {Inputs} from "contracts/common/Inputs.sol"; + +library EncodeEvmAdvance { + function encodeEvmAdvance( + address _sender, + uint256 _index, + bytes memory _payload + ) internal view returns (bytes memory) { + return + abi.encodeCall( + Inputs.EvmAdvance, + (_sender, block.number, block.timestamp, _index, _payload) + ); + } +}