Skip to content

Commit 85c8a3b

Browse files
authored
feat: updating consensus payload (#10017)
1 parent 9643dcd commit 85c8a3b

File tree

13 files changed

+152
-80
lines changed

13 files changed

+152
-80
lines changed

l1-contracts/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
"slither": "forge clean && forge build --build-info --skip '*/test/**' --force && slither . --checklist --ignore-compile --show-ignored-findings --config-file ./slither.config.json | tee slither_output.md",
1414
"slither-has-diff": "./slither_has_diff.sh"
1515
}
16-
}
16+
}

l1-contracts/src/core/Rollup.sol

+15-21
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
1616
import {EpochProofQuoteLib} from "@aztec/core/libraries/EpochProofQuoteLib.sol";
1717
import {Errors} from "@aztec/core/libraries/Errors.sol";
1818
import {HeaderLib} from "@aztec/core/libraries/HeaderLib.sol";
19+
import {ProposeArgs, ProposeLib} from "@aztec/core/libraries/ProposeLib.sol";
1920
import {Timestamp, Slot, Epoch, SlotLib, EpochLib} from "@aztec/core/libraries/TimeMath.sol";
2021
import {TxsDecoder} from "@aztec/core/libraries/TxsDecoder.sol";
2122
import {Inbox} from "@aztec/core/messagebridge/Inbox.sol";
@@ -40,6 +41,7 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
4041
using SlotLib for Slot;
4142
using EpochLib for Epoch;
4243
using SafeERC20 for IERC20;
44+
using ProposeLib for ProposeArgs;
4345

4446
struct ChainTips {
4547
uint256 pendingBlockNumber;
@@ -199,22 +201,17 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
199201
* @notice Publishes the body and propose the block
200202
* @dev `eth_log_handlers` rely on this function
201203
*
202-
* @param _header - The L2 block header
203-
* @param _archive - A root of the archive tree after the L2 block is applied
204-
* @param _blockHash - The poseidon2 hash of the header added to the archive tree in the rollup circuit
204+
* @param _args - The arguments to propose the block
205205
* @param _signatures - Signatures from the validators
206206
* @param _body - The body of the L2 block
207207
*/
208208
function proposeAndClaim(
209-
bytes calldata _header,
210-
bytes32 _archive,
211-
bytes32 _blockHash,
212-
bytes32[] memory _txHashes,
209+
ProposeArgs calldata _args,
213210
SignatureLib.Signature[] memory _signatures,
214211
bytes calldata _body,
215212
EpochProofQuoteLib.SignedEpochProofQuote calldata _quote
216213
) external override(IRollup) {
217-
propose(_header, _archive, _blockHash, _txHashes, _signatures, _body);
214+
propose(_args, _signatures, _body);
218215
claimEpochProofRight(_quote);
219216
}
220217

@@ -464,30 +461,27 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
464461
* @notice Publishes the body and propose the block
465462
* @dev `eth_log_handlers` rely on this function
466463
*
467-
* @param _header - The L2 block header
468-
* @param _archive - A root of the archive tree after the L2 block is applied
469-
* @param _blockHash - The poseidon2 hash of the header added to the archive tree in the rollup circuit
464+
* @param _args - The arguments to propose the block
470465
* @param _signatures - Signatures from the validators
471466
* @param _body - The body of the L2 block
472467
*/
473468
function propose(
474-
bytes calldata _header,
475-
bytes32 _archive,
476-
bytes32 _blockHash,
477-
bytes32[] memory _txHashes,
469+
ProposeArgs calldata _args,
478470
SignatureLib.Signature[] memory _signatures,
479471
bytes calldata _body
480472
) public override(IRollup) {
481473
if (canPrune()) {
482474
_prune();
483475
}
476+
// The `body` is passed outside the "args" as it does not directly need to be in the digest
477+
// as long as the `txsEffectsHash` is included and matches what is in the header.
478+
// Which we are checking in the `_validateHeader` call below.
484479
bytes32 txsEffectsHash = TxsDecoder.decode(_body);
485480

486481
// Decode and validate header
487-
HeaderLib.Header memory header = HeaderLib.decode(_header);
482+
HeaderLib.Header memory header = HeaderLib.decode(_args.header);
488483

489-
uint8 domainSeperator = uint8(SignatureLib.SignatureDomainSeperator.blockAttestation);
490-
bytes32 digest = keccak256(abi.encode(domainSeperator, _archive, _txHashes));
484+
bytes32 digest = _args.digest();
491485
setupEpoch();
492486
_validateHeader({
493487
_header: header,
@@ -501,8 +495,8 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
501495
uint256 blockNumber = ++tips.pendingBlockNumber;
502496

503497
blocks[blockNumber] = BlockLog({
504-
archive: _archive,
505-
blockHash: _blockHash,
498+
archive: _args.archive,
499+
blockHash: _args.blockHash,
506500
slotNumber: Slot.wrap(header.globalVariables.slotNumber)
507501
});
508502

@@ -519,7 +513,7 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
519513
uint256 l2ToL1TreeMinHeight = min + 1;
520514
OUTBOX.insert(blockNumber, header.contentCommitment.outHash, l2ToL1TreeMinHeight);
521515

522-
emit L2BlockProposed(blockNumber, _archive);
516+
emit L2BlockProposed(blockNumber, _args.archive);
523517

524518
// Automatically flag the block as proven if we have cheated and set assumeProvenThroughBlockNumber.
525519
if (blockNumber <= assumeProvenThroughBlockNumber) {

l1-contracts/src/core/interfaces/IRollup.sol

+3-10
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ pragma solidity >=0.8.27;
44

55
import {IInbox} from "@aztec/core/interfaces/messagebridge/IInbox.sol";
66
import {IOutbox} from "@aztec/core/interfaces/messagebridge/IOutbox.sol";
7-
87
import {SignatureLib} from "@aztec/core/libraries/crypto/SignatureLib.sol";
98
import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
109
import {EpochProofQuoteLib} from "@aztec/core/libraries/EpochProofQuoteLib.sol";
11-
10+
import {ProposeArgs} from "@aztec/core/libraries/ProposeLib.sol";
1211
import {Timestamp, Slot, Epoch} from "@aztec/core/libraries/TimeMath.sol";
1312

1413
interface ITestRollup {
@@ -35,19 +34,13 @@ interface IRollup {
3534
function claimEpochProofRight(EpochProofQuoteLib.SignedEpochProofQuote calldata _quote) external;
3635

3736
function propose(
38-
bytes calldata _header,
39-
bytes32 _archive,
40-
bytes32 _blockHash,
41-
bytes32[] memory _txHashes,
37+
ProposeArgs calldata _args,
4238
SignatureLib.Signature[] memory _signatures,
4339
bytes calldata _body
4440
) external;
4541

4642
function proposeAndClaim(
47-
bytes calldata _header,
48-
bytes32 _archive,
49-
bytes32 _blockHash,
50-
bytes32[] memory _txHashes,
43+
ProposeArgs calldata _args,
5144
SignatureLib.Signature[] memory _signatures,
5245
bytes calldata _body,
5346
EpochProofQuoteLib.SignedEpochProofQuote calldata _quote
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright 2024 Aztec Labs.
3+
pragma solidity >=0.8.27;
4+
5+
import {SignatureLib} from "@aztec/core/libraries/crypto/SignatureLib.sol";
6+
7+
struct ProposeArgs {
8+
bytes32 archive;
9+
bytes32 blockHash;
10+
bytes header;
11+
bytes32[] txHashes;
12+
}
13+
14+
library ProposeLib {
15+
function digest(ProposeArgs memory _args) internal pure returns (bytes32) {
16+
return keccak256(abi.encode(SignatureLib.SignatureDomainSeperator.blockAttestation, _args));
17+
}
18+
}

l1-contracts/test/Rollup.t.sol

+57-15
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {TestConstants} from "./harnesses/TestConstants.sol";
2626
import {RewardDistributor} from "@aztec/governance/RewardDistributor.sol";
2727
import {TxsDecoderHelper} from "./decoders/helpers/TxsDecoderHelper.sol";
2828
import {IERC20Errors} from "@oz/interfaces/draft-IERC6093.sol";
29+
import {ProposeArgs, ProposeLib} from "@aztec/core/libraries/ProposeLib.sol";
2930

3031
import {
3132
Timestamp, Slot, Epoch, SlotLib, EpochLib, TimeFns
@@ -40,6 +41,7 @@ import {
4041
contract RollupTest is DecoderBase, TimeFns {
4142
using SlotLib for Slot;
4243
using EpochLib for Epoch;
44+
using ProposeLib for ProposeArgs;
4345

4446
Registry internal registry;
4547
Inbox internal inbox;
@@ -258,7 +260,9 @@ contract RollupTest is DecoderBase, TimeFns {
258260
// We jump to the time of the block. (unless it is in the past)
259261
vm.warp(max(block.timestamp, data.decodedHeader.globalVariables.timestamp));
260262

261-
rollup.propose(header, archive, blockHash, txHashes, signatures, body);
263+
ProposeArgs memory args =
264+
ProposeArgs({header: header, archive: archive, blockHash: blockHash, txHashes: txHashes});
265+
rollup.propose(args, signatures, body);
262266

263267
quote.epochToProve = Epoch.wrap(1);
264268
quote.validUntilSlot = toSlots(Epoch.wrap(2));
@@ -424,7 +428,9 @@ contract RollupTest is DecoderBase, TimeFns {
424428
// We jump to the time of the block. (unless it is in the past)
425429
vm.warp(max(block.timestamp, data.decodedHeader.globalVariables.timestamp));
426430

427-
rollup.propose(header, archive, blockHash, txHashes, signatures, body);
431+
ProposeArgs memory args =
432+
ProposeArgs({header: header, archive: archive, blockHash: blockHash, txHashes: txHashes});
433+
rollup.propose(args, signatures, body);
428434

429435
(bytes32 preArchive, bytes32 preBlockHash,) = rollup.blocks(0);
430436
_submitEpochProof(rollup, 1, preArchive, archive, preBlockHash, blockHash, proverId);
@@ -556,7 +562,13 @@ contract RollupTest is DecoderBase, TimeFns {
556562
vm.warp(max(block.timestamp, data.decodedHeader.globalVariables.timestamp));
557563

558564
vm.expectRevert(abi.encodeWithSelector(Errors.Rollup__NonZeroDaFee.selector));
559-
rollup.propose(header, data.archive, data.blockHash, txHashes, signatures, data.body);
565+
ProposeArgs memory args = ProposeArgs({
566+
header: header,
567+
archive: data.archive,
568+
blockHash: data.blockHash,
569+
txHashes: txHashes
570+
});
571+
rollup.propose(args, signatures, data.body);
560572
}
561573

562574
function testNonZeroL2Fee() public setUpFor("mixed_block_1") {
@@ -574,7 +586,13 @@ contract RollupTest is DecoderBase, TimeFns {
574586
vm.warp(max(block.timestamp, data.decodedHeader.globalVariables.timestamp));
575587

576588
vm.expectRevert(abi.encodeWithSelector(Errors.Rollup__NonZeroL2Fee.selector));
577-
rollup.propose(header, data.archive, data.blockHash, txHashes, signatures, data.body);
589+
ProposeArgs memory args = ProposeArgs({
590+
header: header,
591+
archive: data.archive,
592+
blockHash: data.blockHash,
593+
txHashes: txHashes
594+
});
595+
rollup.propose(args, signatures, data.body);
578596
}
579597

580598
function testBlockFee() public setUpFor("mixed_block_1") {
@@ -603,7 +621,13 @@ contract RollupTest is DecoderBase, TimeFns {
603621
assertEq(coinbaseBalance, 0, "invalid initial coinbase balance");
604622

605623
// Assert that balance have NOT been increased by proposing the block
606-
rollup.propose(header, data.archive, data.blockHash, txHashes, signatures, data.body);
624+
ProposeArgs memory args = ProposeArgs({
625+
header: header,
626+
archive: data.archive,
627+
blockHash: data.blockHash,
628+
txHashes: txHashes
629+
});
630+
rollup.propose(args, signatures, data.body);
607631
assertEq(testERC20.balanceOf(coinbase), 0, "invalid coinbase balance");
608632
}
609633

@@ -704,7 +728,13 @@ contract RollupTest is DecoderBase, TimeFns {
704728
bytes32[] memory txHashes = new bytes32[](0);
705729

706730
vm.warp(max(block.timestamp, data2.decodedHeader.globalVariables.timestamp));
707-
rollup.propose(data2.header, data2.archive, data2.blockHash, txHashes, signatures, data2.body);
731+
ProposeArgs memory args = ProposeArgs({
732+
header: data2.header,
733+
archive: data2.archive,
734+
blockHash: data2.blockHash,
735+
txHashes: txHashes
736+
});
737+
rollup.propose(args, signatures, data2.body);
708738

709739
// Skips proving of block 1
710740
(bytes32 preArchive,,) = rollup.blocks(0);
@@ -749,7 +779,9 @@ contract RollupTest is DecoderBase, TimeFns {
749779
}
750780

751781
vm.expectRevert(abi.encodeWithSelector(Errors.Rollup__InvalidBlockNumber.selector, 1, 0x420));
752-
rollup.propose(header, archive, data.blockHash, txHashes, signatures, body);
782+
ProposeArgs memory args =
783+
ProposeArgs({header: header, archive: archive, blockHash: data.blockHash, txHashes: txHashes});
784+
rollup.propose(args, signatures, body);
753785
}
754786

755787
function testRevertInvalidChainId() public setUpFor("empty_block_1") {
@@ -764,7 +796,9 @@ contract RollupTest is DecoderBase, TimeFns {
764796
}
765797

766798
vm.expectRevert(abi.encodeWithSelector(Errors.Rollup__InvalidChainId.selector, 31337, 0x420));
767-
rollup.propose(header, archive, data.blockHash, txHashes, signatures, body);
799+
ProposeArgs memory args =
800+
ProposeArgs({header: header, archive: archive, blockHash: data.blockHash, txHashes: txHashes});
801+
rollup.propose(args, signatures, body);
768802
}
769803

770804
function testRevertInvalidVersion() public setUpFor("empty_block_1") {
@@ -779,7 +813,9 @@ contract RollupTest is DecoderBase, TimeFns {
779813
}
780814

781815
vm.expectRevert(abi.encodeWithSelector(Errors.Rollup__InvalidVersion.selector, 1, 0x420));
782-
rollup.propose(header, archive, data.blockHash, txHashes, signatures, body);
816+
ProposeArgs memory args =
817+
ProposeArgs({header: header, archive: archive, blockHash: data.blockHash, txHashes: txHashes});
818+
rollup.propose(args, signatures, body);
783819
}
784820

785821
function testRevertInvalidTimestamp() public setUpFor("empty_block_1") {
@@ -799,7 +835,9 @@ contract RollupTest is DecoderBase, TimeFns {
799835
}
800836

801837
vm.expectRevert(abi.encodeWithSelector(Errors.Rollup__InvalidTimestamp.selector, realTs, badTs));
802-
rollup.propose(header, archive, data.blockHash, txHashes, signatures, body);
838+
ProposeArgs memory args =
839+
ProposeArgs({header: header, archive: archive, blockHash: data.blockHash, txHashes: txHashes});
840+
rollup.propose(args, signatures, body);
803841
}
804842

805843
function testBlocksWithAssumeProven() public setUpFor("mixed_block_1") {
@@ -879,8 +917,6 @@ contract RollupTest is DecoderBase, TimeFns {
879917
function _testBlock(string memory name, bool _submitProof, uint256 _slotNumber) public {
880918
DecoderBase.Full memory full = load(name);
881919
bytes memory header = full.block.header;
882-
bytes32 archive = full.block.archive;
883-
bytes memory body = full.block.body;
884920
uint32 numTxs = full.block.numTxs;
885921
bytes32[] memory txHashes = new bytes32[](0);
886922

@@ -903,14 +939,20 @@ contract RollupTest is DecoderBase, TimeFns {
903939

904940
_populateInbox(full.populate.sender, full.populate.recipient, full.populate.l1ToL2Content);
905941

906-
rollup.propose(header, archive, full.block.blockHash, txHashes, signatures, body);
942+
ProposeArgs memory args = ProposeArgs({
943+
header: header,
944+
archive: full.block.archive,
945+
blockHash: full.block.blockHash,
946+
txHashes: txHashes
947+
});
948+
rollup.propose(args, signatures, full.block.body);
907949

908950
if (_submitProof) {
909951
uint256 pre = rollup.getProvenBlockNumber();
910952
(bytes32 preArchive, bytes32 preBlockHash,) = rollup.blocks(pre);
911953

912954
_submitEpochProof(
913-
rollup, 1, preArchive, archive, preBlockHash, full.block.blockHash, bytes32(0)
955+
rollup, 1, preArchive, args.archive, preBlockHash, full.block.blockHash, bytes32(0)
914956
);
915957
assertEq(pre + 1, rollup.getProvenBlockNumber(), "Block not proven");
916958
}
@@ -952,7 +994,7 @@ contract RollupTest is DecoderBase, TimeFns {
952994
assertEq(root, bytes32(0), "Invalid outbox root");
953995
}
954996

955-
assertEq(rollup.archive(), archive, "Invalid archive");
997+
assertEq(rollup.archive(), args.archive, "Invalid archive");
956998
}
957999

9581000
function _populateInbox(address _sender, bytes32 _recipient, bytes32[] memory _contents) internal {

0 commit comments

Comments
 (0)