-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Rollup contracts moves msgs between L1 and L2 #609
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be more gas efficient to just make one external call getting all addresses then destructure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If getting all the addresses we will be reading an extra storage slot for the rollup address as well, e.g., 1 contract access + 3 storage reads. Here we have 1 cold contract access and 1 hot + 2 storage reads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds right