Skip to content

Commit

Permalink
Merge e03eb9a into 26408c1
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind authored Jul 25, 2024
2 parents 26408c1 + e03eb9a commit 7440df5
Show file tree
Hide file tree
Showing 12 changed files with 695 additions and 70 deletions.
54 changes: 18 additions & 36 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,29 @@ import {Hash} from "./libraries/Hash.sol";
import {Errors} from "./libraries/Errors.sol";
import {Constants} from "./libraries/ConstantsGen.sol";
import {MerkleLib} from "./libraries/MerkleLib.sol";
import {EnumerableSet} from "@oz/utils/structs/EnumerableSet.sol";
import {SignatureLib} from "./sequencer_selection/SignatureLib.sol";

// Contracts
import {MockVerifier} from "../mock/MockVerifier.sol";
import {Inbox} from "./messagebridge/Inbox.sol";
import {Outbox} from "./messagebridge/Outbox.sol";
import {Leonidas} from "./sequencer_selection/Leonidas.sol";

/**
* @title Rollup
* @author Aztec Labs
* @notice Rollup contract that is concerned about readability and velocity of development
* not giving a damn about gas costs.
*/
contract Rollup is IRollup {
IVerifier public verifier;
contract Rollup is Leonidas, IRollup {
IRegistry public immutable REGISTRY;
IAvailabilityOracle public immutable AVAILABILITY_ORACLE;
IInbox public immutable INBOX;
IOutbox public immutable OUTBOX;
uint256 public immutable VERSION;
IERC20 public immutable GAS_TOKEN;

IVerifier public verifier;
bytes32 public archive; // Root of the archive tree
uint256 public lastBlockTs;
// Tracks the last time time was warped on L2 ("warp" is the testing cheatcode).
Expand All @@ -47,16 +48,12 @@ contract Rollup is IRollup {

bytes32 public vkTreeRoot;

using EnumerableSet for EnumerableSet.AddressSet;

EnumerableSet.AddressSet private sequencers;

constructor(
IRegistry _registry,
IAvailabilityOracle _availabilityOracle,
IERC20 _gasToken,
bytes32 _vkTreeRoot
) {
) Leonidas(msg.sender) {
verifier = new MockVerifier();
REGISTRY = _registry;
AVAILABILITY_ORACLE = _availabilityOracle;
Expand All @@ -67,27 +64,6 @@ contract Rollup is IRollup {
VERSION = 1;
}

// HACK: Add a sequencer to set of potential sequencers
function addSequencer(address sequencer) external {
sequencers.add(sequencer);
}

// HACK: Remove a sequencer from the set of potential sequencers
function removeSequencer(address sequencer) external {
sequencers.remove(sequencer);
}

// HACK: Return whose turn it is to submit a block
function whoseTurnIsIt(uint256 blockNumber) public view returns (address) {
return
sequencers.length() == 0 ? address(0x0) : sequencers.at(blockNumber % sequencers.length());
}

// HACK: Return all the registered sequencers
function getSequencers() external view returns (address[] memory) {
return sequencers.values();
}

function setVerifier(address _verifier) external override(IRollup) {
// TODO remove, only needed for testing
verifier = IVerifier(_verifier);
Expand All @@ -101,8 +77,15 @@ contract Rollup is IRollup {
* @notice Process an incoming L2 block and progress the state
* @param _header - The L2 block header
* @param _archive - A root of the archive tree after the L2 block is applied
* @param _signatures - Signatures from the validators
*/
function process(bytes calldata _header, bytes32 _archive) external override(IRollup) {
function process(
bytes calldata _header,
bytes32 _archive,
SignatureLib.Signature[] memory _signatures
) public {
_processPendingBlock(_signatures, _archive);

// Decode and validate header
HeaderLib.Header memory header = HeaderLib.decode(_header);
HeaderLib.validate(header, VERSION, lastBlockTs, archive);
Expand All @@ -112,12 +95,6 @@ contract Rollup is IRollup {
revert Errors.Rollup__UnavailableTxs(header.contentCommitment.txsEffectsHash);
}

// Check that this is the current sequencer's turn
address sequencer = whoseTurnIsIt(header.globalVariables.blockNumber);
if (sequencer != address(0x0) && sequencer != msg.sender) {
revert Errors.Rollup__InvalidSequencer(msg.sender);
}

archive = _archive;
lastBlockTs = block.timestamp;

Expand All @@ -142,6 +119,11 @@ contract Rollup is IRollup {
emit L2BlockProcessed(header.globalVariables.blockNumber);
}

function process(bytes calldata _header, bytes32 _archive) external override(IRollup) {
SignatureLib.Signature[] memory emptySignatures = new SignatureLib.Signature[](0);
process(_header, _archive, emptySignatures);
}

function submitProof(
bytes calldata _header,
bytes32 _archive,
Expand Down
11 changes: 10 additions & 1 deletion l1-contracts/src/core/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ library Errors {
error Rollup__TimestampInFuture(); // 0xbc1ce916
error Rollup__TimestampTooOld(); // 0x72ed9c81
error Rollup__UnavailableTxs(bytes32 txsHash); // 0x414906c3
error Rollup__InvalidSequencer(address sequencer); // 0xa127a106

// Registry
error Registry__RollupNotRegistered(address rollup); // 0xa1fee4cf
Expand All @@ -61,4 +60,14 @@ library Errors {

// MerkleLib
error MerkleLib__InvalidRoot(bytes32 expected, bytes32 actual, bytes32 leaf, uint256 leafIndex); // 0x5f216bf1

// SignatureLib
error SignatureLib__CannotVerifyEmpty(); // 0xc7690a37
error SignatureLib__InvalidSignature(address expected, address recovered); // 0xd9cbae6c

// Sequencer Selection (Leonidas)
error Leonidas__NotGod(); // 0xabc2f815
error Leonidas__EpochNotSetup(); // 0xcf4e597e
error Leonidas__InvalidProposer(address expected, address actual); // 0xd02d278e
error Leonidas__InsufficientAttestations(uint256 expected, uint256 actual); // 0xbf1ca4cb
}
22 changes: 22 additions & 0 deletions l1-contracts/src/core/sequencer_selection/ILeonidas.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024 Aztec Labs.
pragma solidity >=0.8.18;

interface ILeonidas {
// Changing depending on sybil mechanism and slashing enforcement
function addValidator(address _validator) external;
function removeValidator(address _validator) external;

// Likely changing to optimize in Pleistarchus
function setupEpoch() external;
function getCurrentProposer() external view returns (address);

// Stable
function getCurrentEpoch() external view returns (uint256);
function getCurrentSlot() external view returns (uint256);

// Consider removing below this point
// Likely removal of these to replace with a size and indiviual getter
function getEpochCommittee(uint256 _epoch) external view returns (address[] memory);
function getValidators() external view returns (address[] memory);
}
Loading

0 comments on commit 7440df5

Please sign in to comment.