Skip to content

Commit

Permalink
chore: remove leonidas name from codebase (#11545)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 authored Jan 28, 2025
1 parent 1392322 commit cd990af
Show file tree
Hide file tree
Showing 19 changed files with 242 additions and 186 deletions.
12 changes: 6 additions & 6 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
import {IVerifier} from "@aztec/core/interfaces/IVerifier.sol";
import {IInbox} from "@aztec/core/interfaces/messagebridge/IInbox.sol";
import {IOutbox} from "@aztec/core/interfaces/messagebridge/IOutbox.sol";
import {Leonidas} from "@aztec/core/Leonidas.sol";
import {Constants} from "@aztec/core/libraries/ConstantsGen.sol";
import {MerkleLib} from "@aztec/core/libraries/crypto/MerkleLib.sol";
import {Signature} from "@aztec/core/libraries/crypto/SignatureLib.sol";
Expand All @@ -39,6 +38,7 @@ import {Timestamp, Slot, Epoch, SlotLib, EpochLib} from "@aztec/core/libraries/T
import {Inbox} from "@aztec/core/messagebridge/Inbox.sol";
import {Outbox} from "@aztec/core/messagebridge/Outbox.sol";
import {ProofCommitmentEscrow} from "@aztec/core/ProofCommitmentEscrow.sol";
import {ValidatorSelection} from "@aztec/core/ValidatorSelection.sol";
import {IRewardDistributor} from "@aztec/governance/interfaces/IRewardDistributor.sol";
import {MockVerifier} from "@aztec/mock/MockVerifier.sol";
import {Ownable} from "@oz/access/Ownable.sol";
Expand All @@ -62,7 +62,7 @@ struct Config {
* not giving a damn about gas costs.
* @dev WARNING: This contract is VERY close to the size limit (500B at time of writing).
*/
contract Rollup is EIP712("Aztec Rollup", "1"), Ownable, Leonidas, IRollup, ITestRollup {
contract Rollup is EIP712("Aztec Rollup", "1"), Ownable, ValidatorSelection, IRollup, ITestRollup {
using SlotLib for Slot;
using EpochLib for Epoch;
using ProposeLib for ProposeArgs;
Expand Down Expand Up @@ -111,7 +111,7 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Ownable, Leonidas, IRollup, ITes
Config memory _config
)
Ownable(_ares)
Leonidas(
ValidatorSelection(
_stakingAsset,
_config.minimumStake,
_config.slashingQuorum,
Expand Down Expand Up @@ -396,7 +396,7 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Ownable, Leonidas, IRollup, ITes
Signature[] memory sigs = new Signature[](0);
DataStructures.ExecutionFlags memory flags =
DataStructures.ExecutionFlags({ignoreDA: true, ignoreSignatures: true});
_validateLeonidas(slot, sigs, _archive, flags);
_validateValidatorSelection(slot, sigs, _archive, flags);

return (slot, pendingBlockNumber + 1);
}
Expand Down Expand Up @@ -867,7 +867,7 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Ownable, Leonidas, IRollup, ITes
/**
* @notice Validate a header for submission to the pending chain (sequencer selection checks)
*
* These validation checks are directly related to Leonidas.
* These validation checks are directly related to ValidatorSelection.
* Note that while these checks are strict, they can be relaxed with some changes to
* message boxes.
*
Expand Down Expand Up @@ -900,7 +900,7 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Ownable, Leonidas, IRollup, ITes
Epoch currentEpoch = getEpochAt(_currentTime);
require(epochNumber == currentEpoch, Errors.Rollup__InvalidEpoch(currentEpoch, epochNumber));

_validateLeonidas(_slot, _signatures, _digest, _flags);
_validateValidatorSelection(_slot, _signatures, _digest, _flags);
}

// Helper to avoid stack too deep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,32 @@
// Copyright 2024 Aztec Labs.
pragma solidity >=0.8.27;

import {ILeonidas, EpochData, LeonidasStorage} from "@aztec/core/interfaces/ILeonidas.sol";
import {
IValidatorSelection,
EpochData,
ValidatorSelectionStorage
} from "@aztec/core/interfaces/IValidatorSelection.sol";
import {Signature} from "@aztec/core/libraries/crypto/SignatureLib.sol";
import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";
import {LeonidasLib} from "@aztec/core/libraries/LeonidasLib/LeonidasLib.sol";
import {
Timestamp, Slot, Epoch, SlotLib, EpochLib, TimeFns
} from "@aztec/core/libraries/TimeMath.sol";
import {ValidatorSelectionLib} from
"@aztec/core/libraries/ValidatorSelectionLib/ValidatorSelectionLib.sol";
import {Staking} from "@aztec/core/staking/Staking.sol";

import {IERC20} from "@oz/token/ERC20/IERC20.sol";
import {EnumerableSet} from "@oz/utils/structs/EnumerableSet.sol";

/**
* @title Leonidas
* @author Anaxandridas II
* @notice Leonidas is the spartan king, it is his job to select the warriors progressing the state of the kingdom.
* He define the structure needed for committee and leader selection and provides logic for validating that
* the block and its "evidence" follows his rules.
* @title Validator Selection
*
* @dev Leonidas have one thing in mind, he provide a reference of the LOGIC going on for the spartan selection.
* He is not concerned about gas costs, he is a king, he just throw gas in the air like no-one cares.
* It will be the duty of his successor (Pleistarchus) to optimize the costs with same functionality.
* @dev Validator Selection has one thing in mind, he provide a reference of the LOGIC going on for the spartan selection.
* It is a reference implementation, it is not optimized for gas.
*
*/
contract Leonidas is Staking, TimeFns, ILeonidas {
contract ValidatorSelection is Staking, TimeFns, IValidatorSelection {
using EnumerableSet for EnumerableSet.AddressSet;

using SlotLib for Slot;
Expand All @@ -39,7 +40,7 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
// The time that the contract was deployed
Timestamp public immutable GENESIS_TIME;

LeonidasStorage private leonidasStore;
ValidatorSelectionStorage private validatorSelectionStore;

constructor(
IERC20 _stakingAsset,
Expand Down Expand Up @@ -71,19 +72,24 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
function getEpochCommittee(Epoch _epoch)
external
view
override(ILeonidas)
override(IValidatorSelection)
returns (address[] memory)
{
return leonidasStore.epochs[_epoch].committee;
return validatorSelectionStore.epochs[_epoch].committee;
}

/**
* @notice Get the validator set for the current epoch
* @return The validator set for the current epoch
*/
function getCurrentEpochCommittee() external view override(ILeonidas) returns (address[] memory) {
return LeonidasLib.getCommitteeAt(
leonidasStore, stakingStore, getCurrentEpoch(), TARGET_COMMITTEE_SIZE
function getCurrentEpochCommittee()
external
view
override(IValidatorSelection)
returns (address[] memory)
{
return ValidatorSelectionLib.getCommitteeAt(
validatorSelectionStore, stakingStore, getCurrentEpoch(), TARGET_COMMITTEE_SIZE
);
}

Expand All @@ -97,11 +103,11 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
function getCommitteeAt(Timestamp _ts)
external
view
override(ILeonidas)
override(IValidatorSelection)
returns (address[] memory)
{
return LeonidasLib.getCommitteeAt(
leonidasStore, stakingStore, getEpochAt(_ts), TARGET_COMMITTEE_SIZE
return ValidatorSelectionLib.getCommitteeAt(
validatorSelectionStore, stakingStore, getEpochAt(_ts), TARGET_COMMITTEE_SIZE
);
}

Expand All @@ -112,17 +118,22 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
*
* @return The sample seed for the given timestamp
*/
function getSampleSeedAt(Timestamp _ts) external view override(ILeonidas) returns (uint256) {
return LeonidasLib.getSampleSeed(leonidasStore, getEpochAt(_ts));
function getSampleSeedAt(Timestamp _ts)
external
view
override(IValidatorSelection)
returns (uint256)
{
return ValidatorSelectionLib.getSampleSeed(validatorSelectionStore, getEpochAt(_ts));
}

/**
* @notice Get the sample seed for the current epoch
*
* @return The sample seed for the current epoch
*/
function getCurrentSampleSeed() external view override(ILeonidas) returns (uint256) {
return LeonidasLib.getSampleSeed(leonidasStore, getCurrentEpoch());
function getCurrentSampleSeed() external view override(IValidatorSelection) returns (uint256) {
return ValidatorSelectionLib.getSampleSeed(validatorSelectionStore, getCurrentEpoch());
}

function initiateWithdraw(address _attester, address _recipient)
Expand All @@ -143,7 +154,7 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
setupEpoch();
require(
_attester != address(0) && _proposer != address(0),
Errors.Leonidas__InvalidDeposit(_attester, _proposer)
Errors.ValidatorSelection__InvalidDeposit(_attester, _proposer)
);
super.deposit(_attester, _proposer, _withdrawer, _amount);
}
Expand All @@ -154,19 +165,20 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
* - Set the seed for the epoch
* - Update the last seed
*
* @dev Since this is a reference optimising for simplicity, we leonidasStore the actual validator set in the epoch structure.
* @dev Since this is a reference optimising for simplicity, we ValidatorSelectionStore the actual validator set in the epoch structure.
* This is very heavy on gas, so start crying because the gas here will melt the poles
* https://i.giphy.com/U1aN4HTfJ2SmgB2BBK.webp
*/
function setupEpoch() public override(ILeonidas) {
function setupEpoch() public override(IValidatorSelection) {
Epoch epochNumber = getCurrentEpoch();
EpochData storage epoch = leonidasStore.epochs[epochNumber];
EpochData storage epoch = validatorSelectionStore.epochs[epochNumber];

if (epoch.sampleSeed == 0) {
epoch.sampleSeed = LeonidasLib.getSampleSeed(leonidasStore, epochNumber);
epoch.nextSeed = leonidasStore.lastSeed = _computeNextSeed(epochNumber);
epoch.committee =
LeonidasLib.sampleValidators(stakingStore, epoch.sampleSeed, TARGET_COMMITTEE_SIZE);
epoch.sampleSeed = ValidatorSelectionLib.getSampleSeed(validatorSelectionStore, epochNumber);
epoch.nextSeed = validatorSelectionStore.lastSeed = _computeNextSeed(epochNumber);
epoch.committee = ValidatorSelectionLib.sampleValidators(
stakingStore, epoch.sampleSeed, TARGET_COMMITTEE_SIZE
);
}
}

Expand All @@ -177,7 +189,7 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
*
* @return The validator set
*/
function getAttesters() public view override(ILeonidas) returns (address[] memory) {
function getAttesters() public view override(IValidatorSelection) returns (address[] memory) {
return stakingStore.attesters.values();
}

Expand All @@ -186,7 +198,7 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
*
* @return The current epoch number
*/
function getCurrentEpoch() public view override(ILeonidas) returns (Epoch) {
function getCurrentEpoch() public view override(IValidatorSelection) returns (Epoch) {
return getEpochAt(Timestamp.wrap(block.timestamp));
}

Expand All @@ -195,7 +207,7 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
*
* @return The current slot number
*/
function getCurrentSlot() public view override(ILeonidas) returns (Slot) {
function getCurrentSlot() public view override(IValidatorSelection) returns (Slot) {
return getSlotAt(Timestamp.wrap(block.timestamp));
}

Expand All @@ -209,7 +221,7 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
function getTimestampForSlot(Slot _slotNumber)
public
view
override(ILeonidas)
override(IValidatorSelection)
returns (Timestamp)
{
return GENESIS_TIME + toTimestamp(_slotNumber);
Expand All @@ -222,7 +234,7 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
*
* @return The address of the proposer
*/
function getCurrentProposer() public view override(ILeonidas) returns (address) {
function getCurrentProposer() public view override(IValidatorSelection) returns (address) {
return getProposerAt(Timestamp.wrap(block.timestamp));
}

Expand All @@ -247,11 +259,11 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
*
* @return The address of the proposer
*/
function getProposerAt(Timestamp _ts) public view override(ILeonidas) returns (address) {
function getProposerAt(Timestamp _ts) public view override(IValidatorSelection) returns (address) {
Slot slot = getSlotAt(_ts);
Epoch epochNumber = getEpochAtSlot(slot);
return LeonidasLib.getProposerAt(
leonidasStore, stakingStore, slot, epochNumber, TARGET_COMMITTEE_SIZE
return ValidatorSelectionLib.getProposerAt(
validatorSelectionStore, stakingStore, slot, epochNumber, TARGET_COMMITTEE_SIZE
);
}

Expand All @@ -262,7 +274,7 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
*
* @return The computed epoch
*/
function getEpochAt(Timestamp _ts) public view override(ILeonidas) returns (Epoch) {
function getEpochAt(Timestamp _ts) public view override(IValidatorSelection) returns (Epoch) {
return _ts < GENESIS_TIME ? Epoch.wrap(0) : epochFromTimestamp(_ts - GENESIS_TIME);
}

Expand All @@ -273,7 +285,7 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
*
* @return The computed slot
*/
function getSlotAt(Timestamp _ts) public view override(ILeonidas) returns (Slot) {
function getSlotAt(Timestamp _ts) public view override(IValidatorSelection) returns (Slot) {
return _ts < GENESIS_TIME ? Slot.wrap(0) : slotFromTimestamp(_ts - GENESIS_TIME);
}

Expand All @@ -284,7 +296,12 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
*
* @return The computed epoch
*/
function getEpochAtSlot(Slot _slotNumber) public view override(ILeonidas) returns (Epoch) {
function getEpochAtSlot(Slot _slotNumber)
public
view
override(IValidatorSelection)
returns (Epoch)
{
return Epoch.wrap(_slotNumber.unwrap() / EPOCH_DURATION);
}

Expand All @@ -297,7 +314,7 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
) internal {
require(
_attester != address(0) && _proposer != address(0),
Errors.Leonidas__InvalidDeposit(_attester, _proposer)
Errors.ValidatorSelection__InvalidDeposit(_attester, _proposer)
);

super.deposit(_attester, _proposer, _withdrawer, _amount);
Expand All @@ -319,15 +336,15 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
* @param _signatures - The signatures of the committee members
* @param _digest - The digest of the block
*/
function _validateLeonidas(
function _validateValidatorSelection(
Slot _slot,
Signature[] memory _signatures,
bytes32 _digest,
DataStructures.ExecutionFlags memory _flags
) internal view {
Epoch epochNumber = getEpochAtSlot(_slot);
LeonidasLib.validateLeonidas(
leonidasStore,
ValidatorSelectionLib.validateValidatorSelection(
validatorSelectionStore,
stakingStore,
_slot,
epochNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ struct EpochData {
uint256 nextSeed;
}

struct LeonidasStorage {
struct ValidatorSelectionStorage {
// A mapping to snapshots of the validator set
mapping(Epoch => EpochData) epochs;
// The last stored randao value, same value as `seed` in the last inserted epoch
uint256 lastSeed;
}

interface ILeonidas {
interface IValidatorSelection {
// Likely changing to optimize in Pleistarchus
function setupEpoch() external;
function getCurrentProposer() external view returns (address);
Expand Down
16 changes: 10 additions & 6 deletions l1-contracts/src/core/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {Timestamp, Slot, Epoch} from "@aztec/core/libraries/TimeMath.sol";
* @notice Library that contains errors used throughout the Aztec protocol
* Errors are prefixed with the contract name to make it easy to identify where the error originated
* when there are multiple contracts that could have thrown the error.
*
* Sigs are provided for easy reference, but don't trust; verify! run `forge inspect src/core/libraries/Errors.sol:Errors errors`
*/
library Errors {
// DEVNET related
Expand Down Expand Up @@ -93,12 +95,14 @@ library Errors {
// SampleLib
error SampleLib__IndexOutOfBounds(uint256 requested, uint256 bound); // 0xa12fc559

// Sequencer Selection (Leonidas)
error Leonidas__EpochNotSetup(); // 0xcf4e597e
error Leonidas__InvalidProposer(address expected, address actual); // 0xd02d278e
error Leonidas__InvalidDeposit(address attester, address proposer); // 0x1ef9a54b
error Leonidas__InsufficientAttestations(uint256 minimumNeeded, uint256 provided); // 0xbf1ca4cb
error Leonidas__InsufficientAttestationsProvided(uint256 minimumNeeded, uint256 provided); // 0xb3a697c2
// Sequencer Selection (ValidatorSelection)
error ValidatorSelection__EpochNotSetup(); // 0x10816cae
error ValidatorSelection__InvalidProposer(address expected, address actual); // 0xa8843a68
error ValidatorSelection__InvalidDeposit(address attester, address proposer); // 0x533169bd
error ValidatorSelection__InsufficientAttestations(uint256 minimumNeeded, uint256 provided); // 0xaf47297f
error ValidatorSelection__InsufficientAttestationsProvided(
uint256 minimumNeeded, uint256 provided
); // 0x4d4f66ac

// Staking
error Staking__AlreadyActive(address attester); // 0x5e206fa4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ library ValidationLib {

require(
_currentProposer == address(0) || _currentProposer == msg.sender,
Errors.Leonidas__InvalidProposer(_currentProposer, msg.sender)
Errors.ValidatorSelection__InvalidProposer(_currentProposer, msg.sender)
);

require(
Expand Down
Loading

0 comments on commit cd990af

Please sign in to comment.