Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(protocol): change bond amounts, proving windows, and cooldown windows #18371

Merged
merged 10 commits into from
Nov 4, 2024
2 changes: 1 addition & 1 deletion packages/protocol/contracts/layer1/based/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ library LibProving {
}

// If batch verifier name is not empty, verify the batch proof.
if (batchVerifierName != "") {
if (batchVerifierName != LibStrings.B_TIER_OPTIMISTIC) {
IVerifier(_resolver.resolve(batchVerifierName, false)).verifyBatchProof(
ctxs, batchProof
);
Expand Down
78 changes: 38 additions & 40 deletions packages/protocol/contracts/layer1/tiers/TierProviderBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,88 +15,86 @@ abstract contract TierProviderBase is ITierProvider {
/// service may be paused if gas prices are excessively high. Since block proving is
/// asynchronous, this grace period allows provers to defer submissions until gas
/// prices become more favorable, potentially reducing transaction costs.
dantaik marked this conversation as resolved.
Show resolved Hide resolved
uint16 public constant GRACE_PERIOD = 240; // minutes
uint96 public constant BOND_UNIT = 75 ether; // TAIKO tokens
uint96 public constant BOND_UNIT = 50 ether; // TAIKO tokens

/// @inheritdoc ITierProvider
/// @notice Each tier, except the top tier, has a validity bond that is 75 TAIKO higher than the
/// previous tier. Additionally, each tier's contest bond is 6.5625 times its validity bond.
function getTier(uint16 _tierId) public pure virtual returns (ITierProvider.Tier memory) {
if (_tierId == LibTiers.TIER_OPTIMISTIC) {
// cooldownWindow is 1440 minutes and provingWindow is 15 minutes
return _buildTier("", BOND_UNIT, 1440, 15);
return _buildTier(LibStrings.B_TIER_OPTIMISTIC, 1, 1440, 30);
}

// TEE Tiers
if (_tierId == LibTiers.TIER_SGX) return _buildTeeTier(LibStrings.B_TIER_SGX);
if (_tierId == LibTiers.TIER_TDX) return _buildTeeTier(LibStrings.B_TIER_TDX);
if (_tierId == LibTiers.TIER_TEE_ANY) return _buildTeeTier(LibStrings.B_TIER_TEE_ANY);
if (_tierId == LibTiers.TIER_SGX) {
// cooldownWindow is 60 minutes and provingWindow is 60 minutes
return _buildTier(LibStrings.B_TIER_SGX, 2, 60, 60);
}
if (_tierId == LibTiers.TIER_TDX) {
// cooldownWindow is 60 minutes and provingWindow is 60 minutes
return _buildTier(LibStrings.B_TIER_TDX, 2, 60, 60);
}
if (_tierId == LibTiers.TIER_TEE_ANY) {
// cooldownWindow is 60 minutes and provingWindow is 60 minutes
return _buildTier(LibStrings.B_TIER_TEE_ANY, 2, 60, 60);
}

// ZKVM Tiers
if (_tierId == LibTiers.TIER_ZKVM_RISC0) return _buildZkTier(LibStrings.B_TIER_ZKVM_RISC0);
if (_tierId == LibTiers.TIER_ZKVM_SP1) return _buildZkTier(LibStrings.B_TIER_ZKVM_SP1);
if (_tierId == LibTiers.TIER_ZKVM_ANY) return _buildZkTier(LibStrings.B_TIER_ZKVM_ANY);
if (_tierId == LibTiers.TIER_ZKVM_RISC0) {
// cooldownWindow is 60 minutes and provingWindow is 90 minutes
return _buildTier(LibStrings.B_TIER_ZKVM_RISC0, 3, 60, 90);
}
if (_tierId == LibTiers.TIER_ZKVM_SP1) {
// cooldownWindow is 60 minutes and provingWindow is 90 minutes
return _buildTier(LibStrings.B_TIER_ZKVM_SP1, 3, 60, 90);
}
if (_tierId == LibTiers.TIER_ZKVM_ANY) {
// cooldownWindow is 60 minutes and provingWindow is 90 minutes
return _buildTier(LibStrings.B_TIER_ZKVM_ANY, 3, 60, 90);
}
if (_tierId == LibTiers.TIER_ZKVM_AND_TEE) {
return _buildZkTier(LibStrings.B_TIER_ZKVM_AND_TEE);
// cooldownWindow is 60 minutes and provingWindow is 90 minutes
return _buildTier(LibStrings.B_TIER_ZKVM_AND_TEE, 3, 60, 90);
}

// Guardian Minority Tiers
if (_tierId == LibTiers.TIER_GUARDIAN_MINORITY) {
// cooldownWindow is 240 minutes and provingWindow is 2880 minutes
return _buildTier(LibStrings.B_TIER_GUARDIAN_MINORITY, BOND_UNIT * 3, 240, 0);
// cooldownWindow is 60 minutes and provingWindow is 120 minutes
return _buildTier(LibStrings.B_TIER_GUARDIAN_MINORITY, 4, 60, 120);
}

// Guardian Major Tiers
if (_tierId == LibTiers.TIER_GUARDIAN) {
// cooldownWindow is 1440 minutes and provingWindow is 2880 minutes
return _buildTier(LibStrings.B_TIER_GUARDIAN, 0, 240, 0);
// cooldownWindow is 120 minutes
return _buildTier(LibStrings.B_TIER_GUARDIAN, 0, 120, 0);
}

revert TIER_NOT_FOUND();
}

/// @dev Builds a TEE tier with a specific verifier name.
/// @param _verifierName The name of the verifier.
/// @return A Tier struct with predefined parameters for TEE.
function _buildTeeTier(bytes32 _verifierName)
private
pure
returns (ITierProvider.Tier memory)
{
// cooldownWindow is 1440 minutes and provingWindow is 60 minutes
return _buildTier(_verifierName, BOND_UNIT * 2, 240, 60);
}

/// @dev Builds a ZK tier with a specific verifier name.
/// @param _verifierName The name of the verifier.
/// @return A Tier struct with predefined parameters for ZK.
function _buildZkTier(bytes32 _verifierName) private pure returns (ITierProvider.Tier memory) {
// cooldownWindow is 1440 minutes and provingWindow is 180 minutes
return _buildTier(_verifierName, BOND_UNIT * 3, 240, 180);
}

/// @dev Builds a generic tier with specified parameters.
/// @param _verifierName The name of the verifier.
/// @param _validityBond The validity bond amount.
/// @param _validityBondUnits The units of validity bonds.
/// @param _cooldownWindow The cooldown window duration in minutes.
/// @param _provingWindow The proving window duration in minutes.
/// @return A Tier struct with the provided parameters.
function _buildTier(
bytes32 _verifierName,
uint96 _validityBond,
uint8 _validityBondUnits,
uint16 _cooldownWindow,
uint16 _provingWindow
)
private
pure
returns (ITierProvider.Tier memory)
{
uint96 validityBond = BOND_UNIT * _validityBondUnits;
return ITierProvider.Tier({
verifierName: _verifierName,
validityBond: _validityBond,
contestBond: _validityBond / 10_000 * 65_625,
validityBond: validityBond,
contestBond: validityBond / 10_000 * 65_625,
cooldownWindow: _cooldownWindow,
provingWindow: GRACE_PERIOD + _provingWindow,
provingWindow: _provingWindow,
maxBlocksToVerifyPerProof: 0
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/protocol/contracts/shared/common/LibStrings.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ library LibStrings {
bytes32 internal constant B_TAIKO_TOKEN = bytes32("taiko_token");
bytes32 internal constant B_TIER_GUARDIAN = bytes32("tier_guardian");
bytes32 internal constant B_TIER_GUARDIAN_MINORITY = bytes32("tier_guardian_minority");
bytes32 internal constant B_TIER_OPTIMISTIC = bytes32("tier_optimistic");
bytes32 internal constant B_TIER_ROUTER = bytes32("tier_router");
bytes32 internal constant B_TIER_SGX = bytes32("tier_sgx");
bytes32 internal constant B_TIER_TDX = bytes32("tier_tdx");
Expand Down