-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Rollup contracts moves msgs between L1 and L2 (#609)
* feat: rollup moves msgs * chore: forge fmt * fix: deploy registry, inbox, outbox for E2E and force insert into inbox.
- Loading branch information
Showing
10 changed files
with
238 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2023 Aztec Labs. | ||
pragma solidity >=0.8.18; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
|
||
import {DecoderTest} from "./Decoder.t.sol"; | ||
|
||
import {DataStructures} from "@aztec/core/libraries/DataStructures.sol"; | ||
|
||
import {Registry} from "@aztec/core/messagebridge/Registry.sol"; | ||
import {Inbox} from "@aztec/core/messagebridge/Inbox.sol"; | ||
import {Outbox} from "@aztec/core/messagebridge/Outbox.sol"; | ||
|
||
import {Decoder} from "@aztec/core/Decoder.sol"; | ||
import {Rollup} from "@aztec/core/Rollup.sol"; | ||
|
||
/** | ||
* Blocks are generated using the `integration_l1_publisher.test.ts` tests. | ||
* Main use of these test is shorter cycles when updating the decoder contract. | ||
*/ | ||
contract RollupTest is DecoderTest { | ||
Registry internal registry; | ||
Inbox internal inbox; | ||
Outbox internal outbox; | ||
Rollup internal rollup; | ||
|
||
function setUp() public override(DecoderTest) { | ||
super.setUp(); | ||
registry = new Registry(); | ||
inbox = new Inbox(address(registry)); | ||
outbox = new Outbox(address(registry)); | ||
rollup = new Rollup(registry); | ||
|
||
registry.setAddresses(address(rollup), address(inbox), address(outbox)); | ||
} | ||
|
||
function testEmptyBlock() public override(DecoderTest) { | ||
(,, bytes32 endStateHash,, bytes32[] memory l2ToL1Msgs, bytes32[] memory l1ToL2Msgs) = | ||
helper.decode(block_empty_1); | ||
|
||
vm.record(); | ||
rollup.process(bytes(""), block_empty_1); | ||
|
||
(, bytes32[] memory inboxWrites) = vm.accesses(address(inbox)); | ||
(, bytes32[] memory outboxWrites) = vm.accesses(address(outbox)); | ||
|
||
assertEq(inboxWrites.length, 0, "Invalid inbox writes"); | ||
assertEq(outboxWrites.length, 0, "Invalid outbox writes"); | ||
|
||
for (uint256 i = 0; i < l2ToL1Msgs.length; i++) { | ||
assertEq(l2ToL1Msgs[i], bytes32(0), "Invalid l2ToL1Msgs"); | ||
assertFalse(outbox.contains(l2ToL1Msgs[i]), "msg in outbox"); | ||
} | ||
for (uint256 i = 0; i < l1ToL2Msgs.length; i++) { | ||
assertEq(l1ToL2Msgs[i], bytes32(0), "Invalid l1ToL2Msgs"); | ||
assertFalse(inbox.contains(l1ToL2Msgs[i]), "msg in inbox"); | ||
} | ||
|
||
assertEq(rollup.rollupStateHash(), endStateHash, "Invalid rollup state hash"); | ||
} | ||
|
||
function testMixBlock() public override(DecoderTest) { | ||
(,, bytes32 endStateHash,, bytes32[] memory l2ToL1Msgs, bytes32[] memory l1ToL2Msgs) = | ||
helper.decode(block_mixed_1); | ||
|
||
for (uint256 i = 0; i < l1ToL2Msgs.length; i++) { | ||
_insertInboxEntry(l1ToL2Msgs[i]); | ||
assertTrue(inbox.contains(l1ToL2Msgs[i]), "msg not in inbox"); | ||
} | ||
|
||
vm.record(); | ||
rollup.process(bytes(""), block_mixed_1); | ||
|
||
(, bytes32[] memory inboxWrites) = vm.accesses(address(inbox)); | ||
(, bytes32[] memory outboxWrites) = vm.accesses(address(outbox)); | ||
|
||
assertEq(inboxWrites.length, 16, "Invalid inbox writes"); | ||
assertEq(outboxWrites.length, 8, "Invalid outbox writes"); | ||
|
||
for (uint256 i = 0; i < l2ToL1Msgs.length; i++) { | ||
// recreate the value generated by `integration_l1_publisher.test.ts`. | ||
bytes32 expectedValue = bytes32(uint256(0x300 + 32 * (1 + i / 2) + i % 2)); | ||
assertEq(l2ToL1Msgs[i], expectedValue, "Invalid l2ToL1Msgs"); | ||
assertTrue(outbox.contains(l2ToL1Msgs[i]), "msg not in outbox"); | ||
} | ||
|
||
for (uint256 i = 0; i < l1ToL2Msgs.length; i++) { | ||
assertEq(l1ToL2Msgs[i], bytes32(uint256(0x401 + i)), "Invalid l1ToL2Msgs"); | ||
assertFalse(inbox.contains(l1ToL2Msgs[i]), "msg not consumed"); | ||
} | ||
|
||
assertEq(rollup.rollupStateHash(), endStateHash, "Invalid rollup state hash"); | ||
} | ||
|
||
function _insertInboxEntry(bytes32 _entryHash) internal { | ||
// Compute where exactly we need to shove the entry | ||
bytes32 slot = keccak256(abi.encodePacked(_entryHash, uint256(0))); | ||
uint256 value = uint256(1) | uint256(type(uint32).max) << 128; | ||
vm.store(address(inbox), slot, bytes32(value)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.