Skip to content

Commit

Permalink
feat: constraining slots
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Aug 2, 2024
1 parent 71acc4e commit 9d7e062
Show file tree
Hide file tree
Showing 32 changed files with 986 additions and 587 deletions.
334 changes: 261 additions & 73 deletions l1-contracts/src/core/Rollup.sol

Large diffs are not rendered by default.

25 changes: 24 additions & 1 deletion l1-contracts/src/core/interfaces/IRollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,33 @@
// Copyright 2023 Aztec Labs.
pragma solidity >=0.8.18;

import {SignatureLib} from "../sequencer_selection/SignatureLib.sol";

interface ITestRollup {
function setDevNet(bool _devNet) external;
function setVerifier(address _verifier) external;
function setVkTreeRoot(bytes32 _vkTreeRoot) external;
}

interface IRollup {
event L2BlockProcessed(uint256 indexed blockNumber);
event L2ProofVerified(uint256 indexed blockNumber, bytes32 indexed proverId);
event ProgressedState(uint256 provenBlockCount, uint256 pendingBlockCount);

function publishAndProcess(
bytes calldata _header,
bytes32 _archive,
SignatureLib.Signature[] memory _signatures,
bytes calldata _body
) external;
function publishAndProcess(bytes calldata _header, bytes32 _archive, bytes calldata _body)
external;
function process(bytes calldata _header, bytes32 _archive) external;
function process(
bytes calldata _header,
bytes32 _archive,
SignatureLib.Signature[] memory _signatures
) external;

function submitProof(
bytes calldata _header,
Expand All @@ -17,5 +38,7 @@ interface IRollup {
bytes calldata _proof
) external;

function setVerifier(address _verifier) external;
function archive() external view returns (bytes32);
function isBlockProven(uint256 _blockNumber) external view returns (bool);
function archiveAt(uint256 _blockNumber) external view returns (bytes32);
}
1 change: 1 addition & 0 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ library Constants {
uint256 internal constant BASE_ROLLUP_INDEX = 20;
uint256 internal constant MERGE_ROLLUP_INDEX = 21;
uint256 internal constant ROOT_ROLLUP_INDEX = 22;
uint256 internal constant ETHEREUM_SLOT_DURATION = 12;
uint256 internal constant FUNCTION_SELECTOR_NUM_BYTES = 4;
uint256 internal constant ARGS_HASH_CHUNK_LENGTH = 16;
uint256 internal constant ARGS_HASH_CHUNK_COUNT = 16;
Expand Down
9 changes: 7 additions & 2 deletions l1-contracts/src/core/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ library Errors {
error Rollup__InvalidArchive(bytes32 expected, bytes32 actual); // 0xb682a40e
error Rollup__InvalidProposedArchive(bytes32 expected, bytes32 actual); // 0x32532e73
error Rollup__InvalidBlockNumber(uint256 expected, uint256 actual); // 0xe5edf847
error Rollup__SlotValueTooLarge(uint256 slot); // 0x7234f4fe
error Rollup__SlotAlreadyInChain(uint256 lastSlot, uint256 proposedSlot); // 0x83510bd0
error Rollup__InvalidEpoch(uint256 expected, uint256 actual); // 0x3c6d65e6
error Rollup__TryingToProveNonExistingBlock(); // 0x34ef4954
error Rollup__InvalidInHash(bytes32 expected, bytes32 actual); // 0xcd6f4233
error Rollup__InvalidProof(); // 0xa5b2ba17
error Rollup__InvalidChainId(uint256 expected, uint256 actual); // 0x37b5bc12
error Rollup__InvalidVersion(uint256 expected, uint256 actual); // 0x9ef30794
error Rollup__InvalidTimestamp(uint256 expected, uint256 actual); // 0x3132e895
error Rollup__TimestampInFuture(); // 0xbc1ce916
error Rollup__TimestampTooOld(); // 0x72ed9c81
error Rollup__UnavailableTxs(bytes32 txsHash); // 0x414906c3
Expand All @@ -60,6 +64,7 @@ library Errors {

// HeaderLib
error HeaderLib__InvalidHeaderSize(uint256 expected, uint256 actual); // 0xf3ccb247
error HeaderLib__InvalidSlotNumber(uint256 expected, uint256 actual); // 0x09ba91ff

// MerkleLib
error MerkleLib__InvalidRoot(bytes32 expected, bytes32 actual, bytes32 leaf, uint256 leafIndex); // 0x5f216bf1
Expand All @@ -72,8 +77,8 @@ library Errors {
error SampleLib__IndexOutOfBounds(uint256 requested, uint256 bound); // 0xa12fc559

// 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
error Leonidas__InsufficientAttestations(uint256 minimumNeeded, uint256 provided); // 0xbf1ca4cb
error Leonidas__InsufficientAttestationsProvided(uint256 minimumNeeded, uint256 provided); // 0x2e7debe9
}
48 changes: 0 additions & 48 deletions l1-contracts/src/core/libraries/HeaderLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pragma solidity >=0.8.18;
// Libraries
import {Errors} from "./Errors.sol";
import {Constants} from "./ConstantsGen.sol";
import {Hash} from "./Hash.sol";

/**
* @title Header Library
Expand Down Expand Up @@ -108,53 +107,6 @@ library HeaderLib {

uint256 private constant HEADER_LENGTH = 0x268; // Header byte length

/**
* @notice Validates the header
* @param _header - The decoded header
* @param _version - The expected version
* @param _slot - The expected slot number
* @dev @todo currently unused, but must be constrained and used to
* constrain the timestamp instead of `lastBlockTs`
* @param _lastBlockTs - The timestamp of the last block
* @param _archive - The expected archive root
*/
function validate(
Header memory _header,
uint256 _version,
uint256 _slot,
uint256 _lastBlockTs,
bytes32 _archive
) internal view {
if (block.chainid != _header.globalVariables.chainId) {
revert Errors.Rollup__InvalidChainId(block.chainid, _header.globalVariables.chainId);
}

if (_header.globalVariables.version != _version) {
revert Errors.Rollup__InvalidVersion(_version, _header.globalVariables.version);
}

// block number already constrained by archive root check

// @todo Constrain slot number + update timestamp to be linked to slot number

if (_header.globalVariables.timestamp > block.timestamp) {
revert Errors.Rollup__TimestampInFuture();
}

// @todo @LHerskind consider if this is too strict
// This will make multiple l2 blocks in the same l1 block impractical.
// e.g., the first block will update timestamp which will make the second fail.
// Could possibly allow multiple blocks if in same l1 block
if (_header.globalVariables.timestamp < _lastBlockTs) {
revert Errors.Rollup__TimestampTooOld();
}

// TODO(#4148) Proper genesis state. If the state is empty, we allow anything for now.
if (_archive != bytes32(0) && _archive != _header.lastArchive.root) {
revert Errors.Rollup__InvalidArchive(_archive, _header.lastArchive.root);
}
}

/**
* @notice Decodes the header
* @param _header - The header calldata
Expand Down
4 changes: 4 additions & 0 deletions l1-contracts/src/core/sequencer_selection/ILeonidas.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ interface ILeonidas {
// Likely changing to optimize in Pleistarchus
function setupEpoch() external;
function getCurrentProposer() external view returns (address);
function getProposerAt(uint256 _ts) external view returns (address);

// Stable
function getCurrentEpoch() external view returns (uint256);
function getCurrentSlot() external view returns (uint256);
function isValidator(address _validator) external view returns (bool);

// Consider removing below this point
function getTimestampForSlot(uint256 _slotNumber) external view returns (uint256);

// 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);
Expand Down
Loading

0 comments on commit 9d7e062

Please sign in to comment.