Skip to content

Commit

Permalink
fix: import order
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 committed Jan 28, 2025
1 parent 3e0a747 commit 49dd42c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 43 deletions.
2 changes: 1 addition & 1 deletion 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 {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";
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 Down
27 changes: 14 additions & 13 deletions l1-contracts/src/core/ValidatorSelection.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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,
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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
);
}

Expand All @@ -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
);
}

Expand All @@ -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));
}

/**
Expand All @@ -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)
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
}

Expand Down Expand Up @@ -343,7 +344,7 @@ contract ValidatorSelection is Staking, TimeFns, IValidatorSelection {
) internal view {
Epoch epochNumber = getEpochAtSlot(_slot);
ValidatorSelectionLib.validateValidatorSelection(
ValidatorSelectionStore,
validatorSelectionStore,
stakingStore,
_slot,
epochNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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,
Expand All @@ -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;

Expand Down Expand Up @@ -151,25 +151,25 @@ 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)
{
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;
}

/**
Expand Down Expand Up @@ -206,7 +206,7 @@ library ValidatorSelectionLib {
}

function _getProposerAt(
ValidatorSelectionStorage storage _ValidatorSelectionStore,
ValidatorSelectionStorage storage _validatorSelectionStore,
StakingStorage storage _stakingStore,
Slot _slot,
Epoch _epochNumber,
Expand All @@ -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;
Expand All @@ -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);
}

Expand Down
10 changes: 5 additions & 5 deletions l1-contracts/src/periphery/SlashFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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));
Expand Down Expand Up @@ -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)
)
)
)
Expand Down
12 changes: 6 additions & 6 deletions l1-contracts/src/periphery/SlashPayload.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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)
});
}
Expand Down

0 comments on commit 49dd42c

Please sign in to comment.