Skip to content
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: updating consensus payload #10017

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion l1-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"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",
"slither-has-diff": "./slither_has_diff.sh"
}
}
}
36 changes: 15 additions & 21 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
import {EpochProofQuoteLib} from "@aztec/core/libraries/EpochProofQuoteLib.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";
import {HeaderLib} from "@aztec/core/libraries/HeaderLib.sol";
import {ProposeArgs, ProposeLib} from "@aztec/core/libraries/ProposeLib.sol";
import {Timestamp, Slot, Epoch, SlotLib, EpochLib} from "@aztec/core/libraries/TimeMath.sol";
import {TxsDecoder} from "@aztec/core/libraries/TxsDecoder.sol";
import {Inbox} from "@aztec/core/messagebridge/Inbox.sol";
Expand All @@ -40,6 +41,7 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
using SlotLib for Slot;
using EpochLib for Epoch;
using SafeERC20 for IERC20;
using ProposeLib for ProposeArgs;

struct ChainTips {
uint256 pendingBlockNumber;
Expand Down Expand Up @@ -199,22 +201,17 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
* @notice Publishes the body and propose the block
* @dev `eth_log_handlers` rely on this function
*
* @param _header - The L2 block header
* @param _archive - A root of the archive tree after the L2 block is applied
* @param _blockHash - The poseidon2 hash of the header added to the archive tree in the rollup circuit
* @param _args - The arguments to propose the block
* @param _signatures - Signatures from the validators
* @param _body - The body of the L2 block
*/
function proposeAndClaim(
bytes calldata _header,
bytes32 _archive,
bytes32 _blockHash,
bytes32[] memory _txHashes,
ProposeArgs calldata _args,
SignatureLib.Signature[] memory _signatures,
bytes calldata _body,
EpochProofQuoteLib.SignedEpochProofQuote calldata _quote
) external override(IRollup) {
propose(_header, _archive, _blockHash, _txHashes, _signatures, _body);
propose(_args, _signatures, _body);
claimEpochProofRight(_quote);
}

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

// Decode and validate header
HeaderLib.Header memory header = HeaderLib.decode(_header);
HeaderLib.Header memory header = HeaderLib.decode(_args.header);

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

blocks[blockNumber] = BlockLog({
archive: _archive,
blockHash: _blockHash,
archive: _args.archive,
blockHash: _args.blockHash,
slotNumber: Slot.wrap(header.globalVariables.slotNumber)
});

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

emit L2BlockProposed(blockNumber, _archive);
emit L2BlockProposed(blockNumber, _args.archive);

// Automatically flag the block as proven if we have cheated and set assumeProvenThroughBlockNumber.
if (blockNumber <= assumeProvenThroughBlockNumber) {
Expand Down
13 changes: 3 additions & 10 deletions l1-contracts/src/core/interfaces/IRollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ pragma solidity >=0.8.27;

import {IInbox} from "@aztec/core/interfaces/messagebridge/IInbox.sol";
import {IOutbox} from "@aztec/core/interfaces/messagebridge/IOutbox.sol";

import {SignatureLib} from "@aztec/core/libraries/crypto/SignatureLib.sol";
import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
import {EpochProofQuoteLib} from "@aztec/core/libraries/EpochProofQuoteLib.sol";

import {ProposeArgs} from "@aztec/core/libraries/ProposeLib.sol";
import {Timestamp, Slot, Epoch} from "@aztec/core/libraries/TimeMath.sol";

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

function propose(
bytes calldata _header,
bytes32 _archive,
bytes32 _blockHash,
bytes32[] memory _txHashes,
ProposeArgs calldata _args,
SignatureLib.Signature[] memory _signatures,
bytes calldata _body
) external;

function proposeAndClaim(
bytes calldata _header,
bytes32 _archive,
bytes32 _blockHash,
bytes32[] memory _txHashes,
ProposeArgs calldata _args,
SignatureLib.Signature[] memory _signatures,
bytes calldata _body,
EpochProofQuoteLib.SignedEpochProofQuote calldata _quote
Expand Down
18 changes: 18 additions & 0 deletions l1-contracts/src/core/libraries/ProposeLib.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024 Aztec Labs.
pragma solidity >=0.8.27;

import {SignatureLib} from "@aztec/core/libraries/crypto/SignatureLib.sol";

struct ProposeArgs {
bytes32 archive;
bytes32 blockHash;
bytes header;
bytes32[] txHashes;
}

library ProposeLib {
function digest(ProposeArgs memory _args) internal pure returns (bytes32) {
return keccak256(abi.encode(SignatureLib.SignatureDomainSeperator.blockAttestation, _args));
}
}
72 changes: 57 additions & 15 deletions l1-contracts/test/Rollup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {TestConstants} from "./harnesses/TestConstants.sol";
import {RewardDistributor} from "@aztec/governance/RewardDistributor.sol";
import {TxsDecoderHelper} from "./decoders/helpers/TxsDecoderHelper.sol";
import {IERC20Errors} from "@oz/interfaces/draft-IERC6093.sol";
import {ProposeArgs, ProposeLib} from "@aztec/core/libraries/ProposeLib.sol";

import {
Timestamp, Slot, Epoch, SlotLib, EpochLib, TimeFns
Expand All @@ -40,6 +41,7 @@ import {
contract RollupTest is DecoderBase, TimeFns {
using SlotLib for Slot;
using EpochLib for Epoch;
using ProposeLib for ProposeArgs;

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

rollup.propose(header, archive, blockHash, txHashes, signatures, body);
ProposeArgs memory args =
ProposeArgs({header: header, archive: archive, blockHash: blockHash, txHashes: txHashes});
rollup.propose(args, signatures, body);

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

rollup.propose(header, archive, blockHash, txHashes, signatures, body);
ProposeArgs memory args =
ProposeArgs({header: header, archive: archive, blockHash: blockHash, txHashes: txHashes});
rollup.propose(args, signatures, body);

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

vm.expectRevert(abi.encodeWithSelector(Errors.Rollup__NonZeroDaFee.selector));
rollup.propose(header, data.archive, data.blockHash, txHashes, signatures, data.body);
ProposeArgs memory args = ProposeArgs({
header: header,
archive: data.archive,
blockHash: data.blockHash,
txHashes: txHashes
});
rollup.propose(args, signatures, data.body);
}

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

vm.expectRevert(abi.encodeWithSelector(Errors.Rollup__NonZeroL2Fee.selector));
rollup.propose(header, data.archive, data.blockHash, txHashes, signatures, data.body);
ProposeArgs memory args = ProposeArgs({
header: header,
archive: data.archive,
blockHash: data.blockHash,
txHashes: txHashes
});
rollup.propose(args, signatures, data.body);
}

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

// Assert that balance have NOT been increased by proposing the block
rollup.propose(header, data.archive, data.blockHash, txHashes, signatures, data.body);
ProposeArgs memory args = ProposeArgs({
header: header,
archive: data.archive,
blockHash: data.blockHash,
txHashes: txHashes
});
rollup.propose(args, signatures, data.body);
assertEq(testERC20.balanceOf(coinbase), 0, "invalid coinbase balance");
}

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

vm.warp(max(block.timestamp, data2.decodedHeader.globalVariables.timestamp));
rollup.propose(data2.header, data2.archive, data2.blockHash, txHashes, signatures, data2.body);
ProposeArgs memory args = ProposeArgs({
header: data2.header,
archive: data2.archive,
blockHash: data2.blockHash,
txHashes: txHashes
});
rollup.propose(args, signatures, data2.body);

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

vm.expectRevert(abi.encodeWithSelector(Errors.Rollup__InvalidBlockNumber.selector, 1, 0x420));
rollup.propose(header, archive, data.blockHash, txHashes, signatures, body);
ProposeArgs memory args =
ProposeArgs({header: header, archive: archive, blockHash: data.blockHash, txHashes: txHashes});
rollup.propose(args, signatures, body);
}

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

vm.expectRevert(abi.encodeWithSelector(Errors.Rollup__InvalidChainId.selector, 31337, 0x420));
rollup.propose(header, archive, data.blockHash, txHashes, signatures, body);
ProposeArgs memory args =
ProposeArgs({header: header, archive: archive, blockHash: data.blockHash, txHashes: txHashes});
rollup.propose(args, signatures, body);
}

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

vm.expectRevert(abi.encodeWithSelector(Errors.Rollup__InvalidVersion.selector, 1, 0x420));
rollup.propose(header, archive, data.blockHash, txHashes, signatures, body);
ProposeArgs memory args =
ProposeArgs({header: header, archive: archive, blockHash: data.blockHash, txHashes: txHashes});
rollup.propose(args, signatures, body);
}

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

vm.expectRevert(abi.encodeWithSelector(Errors.Rollup__InvalidTimestamp.selector, realTs, badTs));
rollup.propose(header, archive, data.blockHash, txHashes, signatures, body);
ProposeArgs memory args =
ProposeArgs({header: header, archive: archive, blockHash: data.blockHash, txHashes: txHashes});
rollup.propose(args, signatures, body);
}

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

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

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

rollup.propose(header, archive, full.block.blockHash, txHashes, signatures, body);
ProposeArgs memory args = ProposeArgs({
header: header,
archive: full.block.archive,
blockHash: full.block.blockHash,
txHashes: txHashes
});
rollup.propose(args, signatures, full.block.body);

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

_submitEpochProof(
rollup, 1, preArchive, archive, preBlockHash, full.block.blockHash, bytes32(0)
rollup, 1, preArchive, args.archive, preBlockHash, full.block.blockHash, bytes32(0)
);
assertEq(pre + 1, rollup.getProvenBlockNumber(), "Block not proven");
}
Expand Down Expand Up @@ -952,7 +994,7 @@ contract RollupTest is DecoderBase, TimeFns {
assertEq(root, bytes32(0), "Invalid outbox root");
}

assertEq(rollup.archive(), archive, "Invalid archive");
assertEq(rollup.archive(), args.archive, "Invalid archive");
}

function _populateInbox(address _sender, bytes32 _recipient, bytes32[] memory _contents) internal {
Expand Down
Loading