Skip to content

Commit

Permalink
feat(protocol): add proposer address to getMinTier func (#17919)
Browse files Browse the repository at this point in the history
Co-authored-by: David <[email protected]>
  • Loading branch information
dantaik and davidtaikocha authored Aug 15, 2024
1 parent d559ce8 commit d6ea6f3
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ library LibProposing {
);

// Use the difficulty as a random number
meta_.minTier = local.tierProvider.getMinTier(uint256(meta_.difficulty));
meta_.minTier = local.tierProvider.getMinTier(meta_.proposer, uint256(meta_.difficulty));

if (!local.postFork) {
metaV1_ = LibData.blockMetadataV2toV1(meta_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract DevnetTierProvider is TierProviderBase, ITierRouter {
}

/// @inheritdoc ITierProvider
function getMinTier(uint256) public pure override returns (uint16) {
function getMinTier(address, uint256) public pure override returns (uint16) {
return LibTiers.TIER_OPTIMISTIC;
}
}
3 changes: 2 additions & 1 deletion packages/protocol/contracts/L1/tiers/ITierProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ interface ITierProvider {
function getTierIds() external view returns (uint16[] memory);

/// @dev Determines the minimal tier for a block based on a random input.
/// @param proposer The address of the block proposer.
/// @param rand A pseudo-random number.
/// @return The tier id.
function getMinTier(uint256 rand) external view returns (uint16);
function getMinTier(address proposer, uint256 rand) external view returns (uint16);
}

/// @dev Tier ID cannot be zero!
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/tiers/TierProviderV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract TierProviderV2 is TierProviderBase {
}

/// @inheritdoc ITierProvider
function getMinTier(uint256) public pure override returns (uint16) {
function getMinTier(address, uint256) public pure override returns (uint16) {
return LibTiers.TIER_SGX;
}
}
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/tiers/TierProviderV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract TierProviderV3 is TierProviderBase {
}

/// @inheritdoc ITierProvider
function getMinTier(uint256) public pure override returns (uint16) {
function getMinTier(address, uint256) public pure override returns (uint16) {
return LibTiers.TIER_SGX2;
}
}
9 changes: 6 additions & 3 deletions packages/protocol/contracts/hekla/HeklaTierProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import "../L1/tiers/TierProviderBase.sol";
/// @title HeklaTierProvider
/// @custom:security-contact [email protected]
contract HeklaTierProvider is TierProviderBase {
address public constant LAB_PROPOSER = 0xD3f681bD6B49887A48cC9C9953720903967E9DC0;

/// @inheritdoc ITierProvider
function getTierIds() public pure override returns (uint16[] memory tiers_) {
tiers_ = new uint16[](5);
Expand All @@ -17,14 +19,15 @@ contract HeklaTierProvider is TierProviderBase {
}

/// @inheritdoc ITierProvider
function getMinTier(uint256 _rand) public pure override returns (uint16) {
if (_rand % 1000 == 0) {
function getMinTier(address _proposer, uint256 _rand) public pure override returns (uint16) {
if (_proposer == LAB_PROPOSER && _rand % 1000 == 0) {
// 0.1% of the total blocks will require ZKVM proofs.
return LibTiers.TIER_ZKVM_RISC0;
} else if (_rand % 2 == 0) {
// 50% of the total blocks will require SGX proofs.
return LibTiers.TIER_SGX;
} else {
return LibTiers.TIER_OPTIMISTIC;
}
return LibTiers.TIER_OPTIMISTIC;
}
}
2 changes: 1 addition & 1 deletion packages/protocol/test/L1/TestTierProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ contract TestTierProvider is ITierProvider, ITierRouter {
}

/// @inheritdoc ITierProvider
function getMinTier(uint256 _rand) public pure override returns (uint16) {
function getMinTier(address, uint256 _rand) public pure override returns (uint16) {
// 10% will be selected to require SGX proofs.
if (_rand % 10 == 0) return LibTiers.TIER_SGX;
// Other blocks are optimistic, without validity proofs.
Expand Down

0 comments on commit d6ea6f3

Please sign in to comment.