diff --git a/l1-contracts/src/core/Rollup.sol b/l1-contracts/src/core/Rollup.sol index 799657128a4..d5ae427883e 100644 --- a/l1-contracts/src/core/Rollup.sol +++ b/l1-contracts/src/core/Rollup.sol @@ -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 {ValidatorSelection} from "@aztec/core/ValidatorSelection.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"; @@ -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"; diff --git a/l1-contracts/src/core/ValidatorSelection.sol b/l1-contracts/src/core/ValidatorSelection.sol index 612571e4468..84f65ac1093 100644 --- a/l1-contracts/src/core/ValidatorSelection.sol +++ b/l1-contracts/src/core/ValidatorSelection.sol @@ -10,12 +10,13 @@ import { 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 {ValidatorSelectionLib} from - "@aztec/core/libraries/ValidatorSelectionLib/ValidatorSelectionLib.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"; @@ -39,7 +40,7 @@ contract ValidatorSelection is Staking, TimeFns, IValidatorSelection { // The time that the contract was deployed Timestamp public immutable GENESIS_TIME; - ValidatorSelectionStorage private ValidatorSelectionStore; + ValidatorSelectionStorage private validatorSelectionStore; constructor( IERC20 _stakingAsset, @@ -74,7 +75,7 @@ contract ValidatorSelection is Staking, TimeFns, IValidatorSelection { override(IValidatorSelection) returns (address[] memory) { - return ValidatorSelectionStore.epochs[_epoch].committee; + return validatorSelectionStore.epochs[_epoch].committee; } /** @@ -88,7 +89,7 @@ contract ValidatorSelection is Staking, TimeFns, IValidatorSelection { returns (address[] memory) { return ValidatorSelectionLib.getCommitteeAt( - ValidatorSelectionStore, stakingStore, getCurrentEpoch(), TARGET_COMMITTEE_SIZE + validatorSelectionStore, stakingStore, getCurrentEpoch(), TARGET_COMMITTEE_SIZE ); } @@ -106,7 +107,7 @@ contract ValidatorSelection is Staking, TimeFns, IValidatorSelection { returns (address[] memory) { return ValidatorSelectionLib.getCommitteeAt( - ValidatorSelectionStore, stakingStore, getEpochAt(_ts), TARGET_COMMITTEE_SIZE + validatorSelectionStore, stakingStore, getEpochAt(_ts), TARGET_COMMITTEE_SIZE ); } @@ -123,7 +124,7 @@ contract ValidatorSelection is Staking, TimeFns, IValidatorSelection { override(IValidatorSelection) returns (uint256) { - return ValidatorSelectionLib.getSampleSeed(ValidatorSelectionStore, getEpochAt(_ts)); + return ValidatorSelectionLib.getSampleSeed(validatorSelectionStore, getEpochAt(_ts)); } /** @@ -132,7 +133,7 @@ contract ValidatorSelection is Staking, TimeFns, IValidatorSelection { * @return The sample seed for the current epoch */ function getCurrentSampleSeed() external view override(IValidatorSelection) returns (uint256) { - return ValidatorSelectionLib.getSampleSeed(ValidatorSelectionStore, getCurrentEpoch()); + return ValidatorSelectionLib.getSampleSeed(validatorSelectionStore, getCurrentEpoch()); } function initiateWithdraw(address _attester, address _recipient) @@ -170,11 +171,11 @@ contract ValidatorSelection is Staking, TimeFns, IValidatorSelection { */ function setupEpoch() public override(IValidatorSelection) { Epoch epochNumber = getCurrentEpoch(); - EpochData storage epoch = ValidatorSelectionStore.epochs[epochNumber]; + EpochData storage epoch = validatorSelectionStore.epochs[epochNumber]; if (epoch.sampleSeed == 0) { - epoch.sampleSeed = ValidatorSelectionLib.getSampleSeed(ValidatorSelectionStore, epochNumber); - epoch.nextSeed = ValidatorSelectionStore.lastSeed = _computeNextSeed(epochNumber); + epoch.sampleSeed = ValidatorSelectionLib.getSampleSeed(validatorSelectionStore, epochNumber); + epoch.nextSeed = validatorSelectionStore.lastSeed = _computeNextSeed(epochNumber); epoch.committee = ValidatorSelectionLib.sampleValidators( stakingStore, epoch.sampleSeed, TARGET_COMMITTEE_SIZE ); @@ -262,7 +263,7 @@ contract ValidatorSelection is Staking, TimeFns, IValidatorSelection { Slot slot = getSlotAt(_ts); Epoch epochNumber = getEpochAtSlot(slot); return ValidatorSelectionLib.getProposerAt( - ValidatorSelectionStore, stakingStore, slot, epochNumber, TARGET_COMMITTEE_SIZE + validatorSelectionStore, stakingStore, slot, epochNumber, TARGET_COMMITTEE_SIZE ); } @@ -343,7 +344,7 @@ contract ValidatorSelection is Staking, TimeFns, IValidatorSelection { ) internal view { Epoch epochNumber = getEpochAtSlot(_slot); ValidatorSelectionLib.validateValidatorSelection( - ValidatorSelectionStore, + validatorSelectionStore, stakingStore, _slot, epochNumber, diff --git a/l1-contracts/src/core/libraries/ValidatorSelectionLib/ValidatorSelectionLib.sol b/l1-contracts/src/core/libraries/ValidatorSelectionLib/ValidatorSelectionLib.sol index 64f54de59c0..c647a3750a2 100644 --- a/l1-contracts/src/core/libraries/ValidatorSelectionLib/ValidatorSelectionLib.sol +++ b/l1-contracts/src/core/libraries/ValidatorSelectionLib/ValidatorSelectionLib.sol @@ -2,10 +2,10 @@ // Copyright 2024 Aztec Labs. pragma solidity >=0.8.27; +import {StakingStorage} from "@aztec/core/interfaces/IStaking.sol"; import { EpochData, ValidatorSelectionStorage } from "@aztec/core/interfaces/IValidatorSelection.sol"; -import {StakingStorage} from "@aztec/core/interfaces/IStaking.sol"; import {SampleLib} from "@aztec/core/libraries/crypto/SampleLib.sol"; import {SignatureLib, Signature} from "@aztec/core/libraries/crypto/SignatureLib.sol"; import {DataStructures} from "@aztec/core/libraries/DataStructures.sol"; @@ -36,25 +36,25 @@ library ValidatorSelectionLib { } function getProposerAt( - ValidatorSelectionStorage storage _ValidatorSelectionStore, + ValidatorSelectionStorage storage _validatorSelectionStore, StakingStorage storage _stakingStore, Slot _slot, Epoch _epochNumber, uint256 _targetCommitteeSize ) external view returns (address) { return _getProposerAt( - _ValidatorSelectionStore, _stakingStore, _slot, _epochNumber, _targetCommitteeSize + _validatorSelectionStore, _stakingStore, _slot, _epochNumber, _targetCommitteeSize ); } function getCommitteeAt( - ValidatorSelectionStorage storage _ValidatorSelectionStore, + ValidatorSelectionStorage storage _validatorSelectionStore, StakingStorage storage _stakingStore, Epoch _epochNumber, uint256 _targetCommitteeSize ) external view returns (address[] memory) { return - _getCommitteeAt(_ValidatorSelectionStore, _stakingStore, _epochNumber, _targetCommitteeSize); + _getCommitteeAt(_validatorSelectionStore, _stakingStore, _epochNumber, _targetCommitteeSize); } /** @@ -74,7 +74,7 @@ library ValidatorSelectionLib { * @param _digest - The digest of the block */ function validateValidatorSelection( - ValidatorSelectionStorage storage _ValidatorSelectionStore, + ValidatorSelectionStorage storage _validatorSelectionStore, StakingStorage storage _stakingStore, Slot _slot, Epoch _epochNumber, @@ -86,11 +86,11 @@ library ValidatorSelectionLib { // Same logic as we got in getProposerAt // Done do avoid duplicate computing the committee address[] memory committee = - _getCommitteeAt(_ValidatorSelectionStore, _stakingStore, _epochNumber, _targetCommitteeSize); + _getCommitteeAt(_validatorSelectionStore, _stakingStore, _epochNumber, _targetCommitteeSize); address attester = committee.length == 0 ? address(0) : committee[computeProposerIndex( - _epochNumber, _slot, getSampleSeed(_ValidatorSelectionStore, _epochNumber), committee.length + _epochNumber, _slot, getSampleSeed(_validatorSelectionStore, _epochNumber), committee.length )]; address proposer = _stakingStore.info[attester].proposer; @@ -151,7 +151,7 @@ library ValidatorSelectionLib { * * @return The sample seed for the epoch */ - function getSampleSeed(ValidatorSelectionStorage storage _ValidatorSelectionStore, Epoch _epoch) + function getSampleSeed(ValidatorSelectionStorage storage _validatorSelectionStore, Epoch _epoch) internal view returns (uint256) @@ -159,17 +159,17 @@ library ValidatorSelectionLib { if (Epoch.unwrap(_epoch) == 0) { return type(uint256).max; } - uint256 sampleSeed = _ValidatorSelectionStore.epochs[_epoch].sampleSeed; + uint256 sampleSeed = _validatorSelectionStore.epochs[_epoch].sampleSeed; if (sampleSeed != 0) { return sampleSeed; } - sampleSeed = _ValidatorSelectionStore.epochs[_epoch - Epoch.wrap(1)].nextSeed; + sampleSeed = _validatorSelectionStore.epochs[_epoch - Epoch.wrap(1)].nextSeed; if (sampleSeed != 0) { return sampleSeed; } - return _ValidatorSelectionStore.lastSeed; + return _validatorSelectionStore.lastSeed; } /** @@ -206,7 +206,7 @@ library ValidatorSelectionLib { } function _getProposerAt( - ValidatorSelectionStorage storage _ValidatorSelectionStore, + ValidatorSelectionStorage storage _validatorSelectionStore, StakingStorage storage _stakingStore, Slot _slot, Epoch _epochNumber, @@ -217,25 +217,25 @@ library ValidatorSelectionLib { // it can just return the proposer directly, but then we duplicate the code // which we just don't have room for right now... address[] memory committee = - _getCommitteeAt(_ValidatorSelectionStore, _stakingStore, _epochNumber, _targetCommitteeSize); + _getCommitteeAt(_validatorSelectionStore, _stakingStore, _epochNumber, _targetCommitteeSize); if (committee.length == 0) { return address(0); } address attester = committee[computeProposerIndex( - _epochNumber, _slot, getSampleSeed(_ValidatorSelectionStore, _epochNumber), committee.length + _epochNumber, _slot, getSampleSeed(_validatorSelectionStore, _epochNumber), committee.length )]; return _stakingStore.info[attester].proposer; } function _getCommitteeAt( - ValidatorSelectionStorage storage _ValidatorSelectionStore, + ValidatorSelectionStorage storage _validatorSelectionStore, StakingStorage storage _stakingStore, Epoch _epochNumber, uint256 _targetCommitteeSize ) private view returns (address[] memory) { - EpochData storage epoch = _ValidatorSelectionStore.epochs[_epochNumber]; + EpochData storage epoch = _validatorSelectionStore.epochs[_epochNumber]; if (epoch.sampleSeed != 0) { uint256 committeeSize = epoch.committee.length; @@ -251,7 +251,7 @@ library ValidatorSelectionLib { } // Emulate a sampling of the validators - uint256 sampleSeed = getSampleSeed(_ValidatorSelectionStore, _epochNumber); + uint256 sampleSeed = getSampleSeed(_validatorSelectionStore, _epochNumber); return _sampleValidators(_stakingStore, sampleSeed, _targetCommitteeSize); } diff --git a/l1-contracts/src/periphery/SlashFactory.sol b/l1-contracts/src/periphery/SlashFactory.sol index c942a7c7a90..e368a5b9a92 100644 --- a/l1-contracts/src/periphery/SlashFactory.sol +++ b/l1-contracts/src/periphery/SlashFactory.sol @@ -9,10 +9,10 @@ import {ISlashFactory} from "./interfaces/ISlashFactory.sol"; import {SlashPayload} from "./SlashPayload.sol"; contract SlashFactory is ISlashFactory { - IValidatorSelection public immutable ValidatorSelection; + IValidatorSelection public immutable VALIDATOR_SELECTION; - constructor(IValidatorSelection _ValidatorSelection) { - ValidatorSelection = _ValidatorSelection; + constructor(IValidatorSelection _validatorSelection) { + VALIDATOR_SELECTION = _validatorSelection; } function createSlashPayload(Epoch _epoch, uint256 _amount) @@ -27,7 +27,7 @@ contract SlashFactory is ISlashFactory { } SlashPayload payload = - new SlashPayload{salt: bytes32(Epoch.unwrap(_epoch))}(_epoch, ValidatorSelection, _amount); + new SlashPayload{salt: bytes32(Epoch.unwrap(_epoch))}(_epoch, VALIDATOR_SELECTION, _amount); emit SlashPayloadCreated(address(payload), _epoch, _amount); return IPayload(address(payload)); @@ -60,7 +60,7 @@ contract SlashFactory is ISlashFactory { salt, keccak256( abi.encodePacked( - type(SlashPayload).creationCode, abi.encode(_epoch, ValidatorSelection, _amount) + type(SlashPayload).creationCode, abi.encode(_epoch, VALIDATOR_SELECTION, _amount) ) ) ) diff --git a/l1-contracts/src/periphery/SlashPayload.sol b/l1-contracts/src/periphery/SlashPayload.sol index 55fd90980f0..7df173b6d55 100644 --- a/l1-contracts/src/periphery/SlashPayload.sol +++ b/l1-contracts/src/periphery/SlashPayload.sol @@ -2,8 +2,8 @@ // Copyright 2024 Aztec Labs. pragma solidity >=0.8.27; -import {IValidatorSelection} from "@aztec/core/interfaces/IValidatorSelection.sol"; import {IStaking} from "@aztec/core/interfaces/IStaking.sol"; +import {IValidatorSelection} from "@aztec/core/interfaces/IValidatorSelection.sol"; import {Epoch} from "@aztec/core/libraries/TimeMath.sol"; import {IPayload} from "@aztec/governance/interfaces/IPayload.sol"; @@ -12,22 +12,22 @@ import {IPayload} from "@aztec/governance/interfaces/IPayload.sol"; */ contract SlashPayload is IPayload { Epoch public immutable EPOCH; - IValidatorSelection public immutable ValidatorSelection; + IValidatorSelection public immutable VALIDATOR_SELECTION; uint256 public immutable AMOUNT; - constructor(Epoch _epoch, IValidatorSelection _ValidatorSelection, uint256 _amount) { + constructor(Epoch _epoch, IValidatorSelection _validatorSelection, uint256 _amount) { EPOCH = _epoch; - ValidatorSelection = _ValidatorSelection; + VALIDATOR_SELECTION = _validatorSelection; AMOUNT = _amount; } function getActions() external view override(IPayload) returns (IPayload.Action[] memory) { - address[] memory attesters = IValidatorSelection(ValidatorSelection).getEpochCommittee(EPOCH); + address[] memory attesters = IValidatorSelection(VALIDATOR_SELECTION).getEpochCommittee(EPOCH); IPayload.Action[] memory actions = new IPayload.Action[](attesters.length); for (uint256 i = 0; i < attesters.length; i++) { actions[i] = IPayload.Action({ - target: address(ValidatorSelection), + target: address(VALIDATOR_SELECTION), data: abi.encodeWithSelector(IStaking.slash.selector, attesters[i], AMOUNT) }); }