-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(protocol): refactor tier provider & address caching and add …
…ComposeVerifier (#17960) Co-authored-by: dantaik <[email protected]> Co-authored-by: D <[email protected]>
- Loading branch information
1 parent
80176a1
commit ee464ca
Showing
47 changed files
with
1,097 additions
and
630 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
/// @title LibTiers | ||
/// @dev Tier ID cannot be zero! | ||
/// @custom:security-contact [email protected] | ||
library LibTiers { | ||
/// @notice Optimistic tier ID. | ||
uint16 public constant TIER_OPTIMISTIC = 100; | ||
|
||
/// @notice SGX proof | ||
uint16 public constant TIER_SGX = 200; | ||
|
||
/// @notice TDX proof | ||
uint16 public constant TIER_TDX = 200; | ||
|
||
/// @notice Any TEE proof | ||
uint16 public constant TIER_TEE_ANY = 200; | ||
|
||
/// @notice Risc0's ZKVM proof | ||
uint16 public constant TIER_ZKVM_RISC0 = 290; | ||
|
||
/// @notice SP1's ZKVM proof | ||
uint16 public constant TIER_ZKVM_SP1 = 290; | ||
|
||
/// @notice Any ZKVM proof | ||
uint16 public constant TIER_ZKVM_ANY = 290; | ||
|
||
/// @notice Guardian tier ID with minority approval. | ||
uint16 public constant TIER_GUARDIAN_MINORITY = 900; | ||
|
||
/// @notice Guardian tier ID with majority approval. | ||
uint16 public constant TIER_GUARDIAN = 1000; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ pragma solidity 0.8.24; | |
|
||
import "../../common/LibStrings.sol"; | ||
import "./ITierProvider.sol"; | ||
import "./LibTiers.sol"; | ||
|
||
/// @title TierProviderBase | ||
/// @custom:security-contact [email protected] | ||
|
@@ -12,97 +13,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. | ||
uint16 public constant GRACE_PERIOD = 240; // 4 hours | ||
uint16 public constant GRACE_PERIOD = 240; // minutes | ||
uint96 public constant BOND_UNIT = 75 ether; // TAIKO tokens | ||
|
||
/// @inheritdoc ITierProvider | ||
/// @notice Each tier, except the top tier, has a validity bond that is 50 TAIKO higher than the | ||
/// @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 | ||
override | ||
returns (ITierProvider.Tier memory) | ||
{ | ||
function getTier(uint16 _tierId) public pure virtual returns (ITierProvider.Tier memory) { | ||
if (_tierId == LibTiers.TIER_OPTIMISTIC) { | ||
return ITierProvider.Tier({ | ||
verifierName: "", | ||
validityBond: 100 ether, // TAIKO | ||
contestBond: 656.25 ether, // = 100 TAIKO * 6.5625 | ||
cooldownWindow: 1440, // 24 hours | ||
provingWindow: GRACE_PERIOD + 15, // 15 minutes | ||
maxBlocksToVerifyPerProof: 0 | ||
}); | ||
} | ||
|
||
if (_tierId == LibTiers.TIER_SGX) { | ||
return ITierProvider.Tier({ | ||
verifierName: LibStrings.B_TIER_SGX, | ||
validityBond: 150 ether, // TAIKO | ||
contestBond: 984.375 ether, // = 150 TAIKO * 6.5625 | ||
cooldownWindow: 1440, // 24 hours | ||
provingWindow: GRACE_PERIOD + 60, // 1 hour | ||
maxBlocksToVerifyPerProof: 0 | ||
}); | ||
// cooldownWindow is 1440 minutes and provingWindow is 15 minutes | ||
return _buildTier("", BOND_UNIT, 1440, 15); | ||
} | ||
|
||
if (_tierId == LibTiers.TIER_SGX2) { | ||
return ITierProvider.Tier({ | ||
verifierName: LibStrings.B_TIER_SGX2, | ||
validityBond: 150 ether, // TAIKO | ||
contestBond: 984.375 ether, // = 150 TAIKO * 6.5625 | ||
cooldownWindow: 1440, // 24 hours | ||
provingWindow: GRACE_PERIOD + 60, // 1 hour | ||
maxBlocksToVerifyPerProof: 0 | ||
}); | ||
} | ||
|
||
if (_tierId == LibTiers.TIER_ZKVM_RISC0) { | ||
return ITierProvider.Tier({ | ||
verifierName: LibStrings.B_TIER_ZKVM_RISC0, | ||
validityBond: 250 ether, // TAIKO | ||
contestBond: 1640.625 ether, // = 250 TAIKO * 6.5625 | ||
cooldownWindow: 1440, // 24 hours | ||
provingWindow: GRACE_PERIOD + 180, // 3 hours | ||
maxBlocksToVerifyPerProof: 0 | ||
}); | ||
} | ||
// 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_ZKVM) { | ||
return ITierProvider.Tier({ | ||
verifierName: LibStrings.B_TIER_SGX_ZKVM, | ||
validityBond: 300 ether, // TAIKO | ||
contestBond: 1968.75 ether, // = 300 TAIKO * 6.5625 | ||
cooldownWindow: 1440, // 24 hours | ||
provingWindow: GRACE_PERIOD + 240, // 4 hours | ||
maxBlocksToVerifyPerProof: 0 | ||
}); | ||
} | ||
// 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_GUARDIAN_MINORITY) { | ||
return ITierProvider.Tier({ | ||
verifierName: LibStrings.B_TIER_GUARDIAN_MINORITY, | ||
validityBond: 350 ether, // TAIKO | ||
contestBond: 2296.875 ether, // = 350 TAIKO * 6.5625 | ||
cooldownWindow: GRACE_PERIOD + 240, // 4 hours | ||
provingWindow: 2880, // 48 hours | ||
maxBlocksToVerifyPerProof: 0 | ||
}); | ||
// cooldownWindow is 240 minutes and provingWindow is 2880 minutes | ||
return _buildTier(LibStrings.B_TIER_GUARDIAN_MINORITY, BOND_UNIT * 4, 240, 2880); | ||
} | ||
|
||
if (_tierId == LibTiers.TIER_GUARDIAN) { | ||
return ITierProvider.Tier({ | ||
verifierName: LibStrings.B_TIER_GUARDIAN, | ||
validityBond: 0, // must be 0 for top tier | ||
contestBond: 0, // must be 0 for top tier | ||
cooldownWindow: 1440, // 24 hours | ||
provingWindow: GRACE_PERIOD + 2880, // 48 hours | ||
maxBlocksToVerifyPerProof: 0 | ||
}); | ||
// cooldownWindow is 1440 minutes and provingWindow is 2880 minutes | ||
return _buildTier(LibStrings.B_TIER_GUARDIAN, 0, 1440, 2880); | ||
} | ||
|
||
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, 1440, 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, 1440, 180); | ||
} | ||
|
||
/// @dev Builds a generic tier with specified parameters. | ||
/// @param _verifierName The name of the verifier. | ||
/// @param _validityBond The validity bond amount. | ||
/// @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, | ||
uint16 _cooldownWindow, | ||
uint16 _provingWindow | ||
) | ||
private | ||
pure | ||
returns (ITierProvider.Tier memory) | ||
{ | ||
return ITierProvider.Tier({ | ||
verifierName: _verifierName, | ||
validityBond: _validityBond, | ||
contestBond: _validityBond / 10_000 * 65_625, | ||
cooldownWindow: _cooldownWindow, | ||
provingWindow: GRACE_PERIOD + _provingWindow, | ||
maxBlocksToVerifyPerProof: 0 | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 0 additions & 55 deletions
55
packages/protocol/contracts/mainnet/LibRollupAddressCache.sol
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
packages/protocol/contracts/mainnet/addrcache/AddressCache.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
/// @title AddressCache | ||
/// @custom:security-contact [email protected] | ||
abstract contract AddressCache { | ||
/// @notice This function retrieves the address associated with a given chain ID and name. | ||
/// If the address is not found in the cache, it falls back to the provided function. | ||
/// @param _chainId The chain ID for which the address is to be retrieved. | ||
/// @param _name The name associated with the address to be retrieved. | ||
/// @param _fallbackFunc The fallback function to be used if the address is not found in the | ||
/// cache. | ||
/// @return The address associated with the given chain ID and name. | ||
function getAddress( | ||
uint64 _chainId, | ||
bytes32 _name, | ||
function (uint64, bytes32) view returns (address) _fallbackFunc | ||
) | ||
internal | ||
view | ||
returns (address) | ||
{ | ||
(bool found, address addr) = getCachedAddress(_chainId, _name); | ||
return found ? addr : _fallbackFunc(_chainId, _name); | ||
} | ||
|
||
/// @notice This function retrieves the cached address associated with a given chain ID and | ||
/// name. | ||
/// @dev This function is virtual and should be overridden in derived contracts. | ||
/// @param _chainId The chain ID for which the address is to be retrieved. | ||
/// @param _name The name associated with the address to be retrieved. | ||
/// @return found_ A boolean indicating whether the address was found in the cache. | ||
/// @return addr_ The address associated with the given chain ID and name, if found in the | ||
/// cache. | ||
function getCachedAddress( | ||
uint64 _chainId, | ||
bytes32 _name | ||
) | ||
internal | ||
pure | ||
virtual | ||
returns (bool found_, address addr_); | ||
} |
Oops, something went wrong.