Skip to content

Commit

Permalink
feat: pre testnet release updates
Browse files Browse the repository at this point in the history
  • Loading branch information
AnshuJalan committed Jan 9, 2025
1 parent c46e659 commit ae52e6e
Show file tree
Hide file tree
Showing 18 changed files with 544 additions and 11 deletions.
3 changes: 2 additions & 1 deletion packages/protocol/contracts/layer1/based/ITaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,6 @@ interface ITaikoL1 {

/// @notice Gets the configuration of the TaikoL1 contract.
/// @return Config struct containing configuration parameters.
function getConfig() external pure returns (TaikoData.Config memory);
// Surge: switch to `view` to allow for dynamic chainid
function getConfig() external view returns (TaikoData.Config memory);
}
4 changes: 3 additions & 1 deletion packages/protocol/contracts/layer1/based/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents {

/// @inheritdoc ITaikoL1
function pauseProving(bool _pause) external {
// Surge: disable pausing of proving
_disable();
_authorizePause(msg.sender, _pause);
LibProving.pauseProving(state, _pause);
Expand Down Expand Up @@ -289,7 +290,8 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents {
}

/// @inheritdoc ITaikoL1
function getConfig() public pure virtual returns (TaikoData.Config memory) {
// Surge: switch to `view` to allow for dynamic chainid
function getConfig() public view virtual returns (TaikoData.Config memory) {
return TaikoData.Config({
chainId: LibNetwork.TAIKO_MAINNET,
blockMaxProposals: 324_000, // = 7200 * 45
Expand Down
36 changes: 36 additions & 0 deletions packages/protocol/contracts/layer1/surge/SurgeTaikoL1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "../based/TaikoL1.sol";

/// @title SurgeTaikoL1
/// @dev Labeled in AddressResolver as "taiko"
contract SurgeTaikoL1 is TaikoL1 {
uint64 private immutable chainId;

constructor(uint64 _chainId) {
chainId = _chainId;
}

/// @inheritdoc ITaikoL1
function getConfig() public view override returns (TaikoData.Config memory) {
return TaikoData.Config({
chainId: chainId,
blockMaxProposals: 324_000,
blockRingBufferSize: 360_000,
maxBlocksToVerify: 16,
blockMaxGasLimit: 240_000_000,
livenessBond: 0.07 ether,
stateRootSyncInternal: 16,
maxAnchorHeightOffset: 64,
baseFeeConfig: LibSharedData.BaseFeeConfig({
adjustmentQuotient: 8,
sharingPctg: 75,
gasIssuancePerSecond: 5_000_000,
minGasExcess: 1_340_000_000,
maxGasIssuancePerBlock: 600_000_000
}),
ontakeForkHeight: 1
});
}
}
53 changes: 53 additions & 0 deletions packages/protocol/contracts/layer1/surge/SurgeTierProviderBase.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "src/shared/common/LibStrings.sol";
import "../tiers/ITierProvider.sol";
import "../tiers/LibTiers.sol";

/// @title SurgeTierProviderBase
/// @notice This contract is a version of Taiko's TierProviderBase modified for Nethermind's Surge
/// @dev Modification include:
/// - Removed guardian tiers
/// - Only one proving tier i.e TWO_OF_THREE
/// - No contestation for the proof
abstract contract SurgeTierProviderBase is ITierProvider {
uint96 public constant BOND_UNIT = 0.04 ether;

/// @inheritdoc ITierProvider
function getTier(uint16 _tierId) public pure virtual returns (ITierProvider.Tier memory) {
if (_tierId == LibTiers.TIER_TWO_OF_THREE) {
// No validity or contestation period
return _buildTier(LibStrings.B_TIER_TWO_OF_THREE, 0, 0, 180);
}

revert TIER_NOT_FOUND();
}

/// @dev Builds a generic tier with specified parameters.
/// @param _verifierName The name of the verifier.
/// @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,
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,
cooldownWindow: _cooldownWindow,
provingWindow: _provingWindow,
maxBlocksToVerifyPerProof: 0
});
}
}
24 changes: 24 additions & 0 deletions packages/protocol/contracts/layer1/surge/SurgeTierRouter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "./SurgeTierProviderBase.sol";
import "../tiers/ITierRouter.sol";

/// @title SurgeTierRouter
contract SurgeTierRouter is SurgeTierProviderBase, ITierRouter {
/// @inheritdoc ITierRouter
function getProvider(uint256) external view returns (address) {
return address(this);
}

/// @inheritdoc ITierProvider
function getTierIds() external pure returns (uint16[] memory tiers_) {
tiers_ = new uint16[](1);
tiers_[0] = LibTiers.TIER_TWO_OF_THREE;
}

/// @inheritdoc ITierProvider
function getMinTier(address, uint256) public pure override returns (uint16) {
return LibTiers.TIER_TWO_OF_THREE;
}
}
6 changes: 4 additions & 2 deletions packages/protocol/contracts/layer1/verifiers/SgxVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ contract SgxVerifier is EssentialContract, IVerifier {
TaikoData.TierProof calldata _proof
)
external
// Surge: Allow either TaikoL1 or the composite verifier to call this
onlyFromNamedEither(LibStrings.B_TAIKO, LibStrings.B_TIER_TWO_OF_THREE)
{
// ^ Access controls removed for testnet.

// Do not run proof verification to contest an existing proof
if (_ctx.isContesting) return;
Expand Down Expand Up @@ -177,7 +178,8 @@ contract SgxVerifier is EssentialContract, IVerifier {
TaikoData.TierProof calldata _proof
)
external
onlyFromNamedEither(LibStrings.B_TAIKO, LibStrings.B_TIER_TEE_ANY)
// Surge: Allow either TaikoL1 or the composite verifier to call this
onlyFromNamedEither(LibStrings.B_TAIKO, LibStrings.B_TIER_TWO_OF_THREE)
{
// Size is: 109 bytes
// 4 bytes + 20 bytes + 20 bytes + 65 bytes (signature) = 109
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ abstract contract ComposeVerifier is EssentialContract, IVerifier {
TaikoData.TierProof calldata _proof
)
external
onlyAuthorizedCaller
nonReentrant
{
(address[] memory verifiers, uint256 numSubProofs_) = getSubVerifiersAndThreshold();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "src/shared/common/LibStrings.sol";
import "./ComposeVerifier.sol";

/// @title TwoOfThreeVerifier
/// @custom:security-contact [email protected]
/// @dev Surge: Allows using any two of the three verifier from SGX / RISC0 / SP1
contract TwoOfThreeVerifier is ComposeVerifier {
uint256[50] private __gap;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ abstract contract EssentialContract is UUPSUpgradeable, Ownable2StepUpgradeable,
error REENTRANT_CALL();
error ZERO_ADDRESS();
error ZERO_VALUE();

// Surge: revert message for when a function is disable for a surge chain
error FUNCTION_DISABLED();

/// @dev Modifier that ensures the caller is the owner or resolved address of a given name.
Expand Down Expand Up @@ -79,7 +81,7 @@ abstract contract EssentialContract is UUPSUpgradeable, Ownable2StepUpgradeable,

/// @notice Pauses the contract.
function pause() public virtual {
_disable();
_disable(); // Surge: disable pausing of contracts
_pause();
// We call the authorize function here to avoid:
// Warning (5740): Unreachable code.
Expand Down Expand Up @@ -139,6 +141,7 @@ abstract contract EssentialContract is UUPSUpgradeable, Ownable2StepUpgradeable,
emit Unpaused(msg.sender);
}

// Surge: use this to block entry to a function in Taiko stack
function _disable() internal pure {
revert FUNCTION_DISABLED();
}
Expand Down
3 changes: 3 additions & 0 deletions packages/protocol/contracts/shared/common/LibNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ library LibNetwork {
uint256 internal constant ETHEREUM_HOLESKY = 17_000;
uint256 internal constant ETHEREUM_SEPOLIA = 11_155_111;

// Surge: updated chainid for surge
uint64 internal constant TAIKO_MAINNET = 763_374;
uint64 internal constant TAIKO_HEKLA = 167_009;

// Surge: required for enabling blob support
uint64 internal constant KURTOSIS_DEVNET = 3_151_908;

/// @dev Checks if the chain ID represents an Ethereum testnet.
Expand Down Expand Up @@ -53,6 +55,7 @@ library LibNetwork {
/// @param _chainId The chain ID.
/// @return true if the chain supports Dencun hardfork, false otherwise.
function isDencunSupported(uint256 _chainId) internal pure returns (bool) {
// Surge: Kurtosis based devnet should support Dencun
return _chainId == LibNetwork.ETHEREUM_MAINNET || _chainId == LibNetwork.ETHEREUM_HOLESKY
|| _chainId == LibNetwork.ETHEREUM_SEPOLIA || _chainId == LibNetwork.KURTOSIS_DEVNET || isTaikoDevnet(_chainId);
}
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 @@ -32,6 +32,7 @@ library LibStrings {
bytes32 internal constant B_TIER_ZKVM_SP1 = bytes32("tier_zkvm_sp1");
bytes32 internal constant B_TIER_ZKVM_ANY = bytes32("tier_zkvm_any");
bytes32 internal constant B_TIER_ZKVM_AND_TEE = bytes32("tier_zkvm_and_tee");
// Surge: Tier to choose two of three from SGX / RISC0 / SP1
bytes32 internal constant B_TIER_TWO_OF_THREE = bytes32("tier_two_of_three");
bytes32 internal constant B_RISCZERO_GROTH16_VERIFIER = bytes32("risc0_groth16_verifier");
bytes32 internal constant B_WITHDRAWER = bytes32("withdrawer");
Expand Down
Loading

0 comments on commit ae52e6e

Please sign in to comment.