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

refactor(protocol): multiple improvements on implementation and tests #18483

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/guardian-prover-health-check-ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ jobs:
# vercel_org_id: ${{ secrets.VERCEL_ORG_ID }}
# vercel_token: ${{ secrets.VERCEL_TOKEN }}



deploy_guardians-ui_hekla_preview:
if: ${{ github.event.pull_request.draft == false && !startsWith(github.head_ref, 'release-please') }}
needs: build-and-test
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ on:
- "!packages/protocol/docs/**"
- "!packages/protocol/simulation/**"
- "!packages/protocol/deployments/**"
- "!packages/protocol/script/layer2/hekla/**"
- "!packages/protocol/script/layer2/mainnet/**"
- "!packages/protocol/script/layer1/hekla/**"
- "!packages/protocol/script/layer1/mainnet/**"
- "!packages/protocol/script/layer1/preconf/**"
- "!packages/protocol/script/layer1/provers/**"
- "!packages/protocol/script/layer1/team/**"
branches-ignore:
- release-please--branches--**

Expand Down
1,572 changes: 622 additions & 950 deletions packages/protocol/contract_layout_layer1.md

Large diffs are not rendered by default.

806 changes: 407 additions & 399 deletions packages/protocol/contract_layout_layer2.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ contract AutomataDcapV3Attestation is IAttestation, EssentialContract {
for (uint256 i; i < 3; ++i) {
bool isPckCert = i == 0; // additional parsing for PCKCert
bool certDecodedSuccessfully;
// todo! move decodeCert offchain
// TODO(Yue): move decodeCert offchain
(certDecodedSuccessfully, parsedQuoteCerts[i]) = pemCertLib.decodeCert(
authDataV3.certification.decodedCertDataArray[i], isPckCert
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ library V3Struct {

struct CertificationData {
uint16 certType;
// todo! In encoded path, we need to calculate the size of certDataArray
// TODO(Yue): In encoded path, we need to calculate the size of certDataArray
// certDataSize = len(join((BEGIN_CERT, certArray[i], END_CERT) for i in 0..3))
// But for plain bytes path, we don't need that.
uint32 certDataSize;
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/layer1/based/ITaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@ interface ITaikoL1 {

/// @notice Gets the configuration of the TaikoL1 contract.
/// @return Config struct containing configuration parameters.
function getConfig() external pure returns (TaikoData.Config memory);
function getConfig() external view returns (TaikoData.Config memory);
}
18 changes: 9 additions & 9 deletions packages/protocol/contracts/layer1/based/LibBonds.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ pragma solidity ^0.8.24;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "src/shared/common/IAddressResolver.sol";
import "src/shared/common/LibAddress.sol";
import "src/shared/common/LibStrings.sol";
import "src/shared/common/IResolver.sol";
import "src/shared/libs/LibAddress.sol";
import "src/shared/libs/LibStrings.sol";
import "./TaikoData.sol";

/// @title LibBonds
Expand Down Expand Up @@ -43,7 +43,7 @@ library LibBonds {
/// @param _amount The amount of tokens to deposit.
function depositBond(
TaikoData.State storage _state,
IAddressResolver _resolver,
IResolver _resolver,
uint256 _amount
)
public
Expand All @@ -58,7 +58,7 @@ library LibBonds {
/// @param _amount The amount of tokens to withdraw.
function withdrawBond(
TaikoData.State storage _state,
IAddressResolver _resolver,
IResolver _resolver,
uint256 _amount
)
public
Expand Down Expand Up @@ -97,7 +97,7 @@ library LibBonds {
/// @param _amount The amount of tokens to debit.
function debitBond(
TaikoData.State storage _state,
IAddressResolver _resolver,
IResolver _resolver,
address _user,
uint256 _blockId,
uint256 _amount
Expand Down Expand Up @@ -142,7 +142,7 @@ library LibBonds {
/// @param _resolver The address resolver.
/// @param _user The user who made the deposit
/// @param _amount The amount of tokens or Ether to deposit.
function _handleDeposit(IAddressResolver _resolver, address _user, uint256 _amount) private {
function _handleDeposit(IResolver _resolver, address _user, uint256 _amount) private {
address bondToken = _bondToken(_resolver);

if (bondToken != address(0)) {
Expand All @@ -158,7 +158,7 @@ library LibBonds {
/// is used as bond asset.
/// @param _resolver The address resolver.
/// @return The IERC20 interface of the TAIKO token.
function _bondToken(IAddressResolver _resolver) private view returns (address) {
return _resolver.resolve(LibStrings.B_BOND_TOKEN, true);
function _bondToken(IResolver _resolver) private view returns (address) {
return _resolver.resolve(block.chainid, LibStrings.B_BOND_TOKEN, true);
}
}
24 changes: 12 additions & 12 deletions packages/protocol/contracts/layer1/based/LibProposing.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "src/shared/common/LibAddress.sol";
import "src/shared/common/LibNetwork.sol";
import "src/shared/libs/LibAddress.sol";
import "src/shared/libs/LibNetwork.sol";
import "./LibBonds.sol";
import "./LibData.sol";
import "./LibUtils.sol";
Expand Down Expand Up @@ -55,7 +55,7 @@ library LibProposing {
function proposeBlocks(
TaikoData.State storage _state,
TaikoData.Config memory _config,
IAddressResolver _resolver,
IResolver _resolver,
bytes[] calldata _paramsArr,
bytes[] calldata _txListArr
)
Expand Down Expand Up @@ -91,7 +91,7 @@ library LibProposing {
function proposeBlock(
TaikoData.State storage _state,
TaikoData.Config memory _config,
IAddressResolver _resolver,
IResolver _resolver,
bytes calldata _params,
bytes calldata _txList
)
Expand All @@ -117,7 +117,7 @@ library LibProposing {
function _proposeBlock(
TaikoData.State storage _state,
TaikoData.Config memory _config,
IAddressResolver _resolver,
IResolver _resolver,
bytes calldata _params,
bytes calldata _txList
)
Expand All @@ -139,7 +139,8 @@ library LibProposing {
);
}

address preconfTaskManager = _resolver.resolve(LibStrings.B_PRECONF_TASK_MANAGER, true);
address preconfTaskManager =
_resolver.resolve(block.chainid, LibStrings.B_PRECONF_TASK_MANAGER, true);
if (preconfTaskManager != address(0)) {
require(preconfTaskManager == msg.sender, L1_INVALID_PROPOSER());
local.allowCustomProposer = true;
Expand Down Expand Up @@ -191,14 +192,13 @@ library LibProposing {
emit CalldataTxList(meta_.id, _txList);
}

local.tierProvider = ITierProvider(
ITierRouter(_resolver.resolve(LibStrings.B_TIER_ROUTER, false)).getProvider(
local.b.numBlocks
)
);
local.tierProvider =
ITierProvider(_resolver.resolve(block.chainid, LibStrings.B_TIER_PROVIDER, false));

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

// Create the block that will be stored onchain
TaikoData.BlockV2 memory blk = TaikoData.BlockV2({
Expand Down
23 changes: 11 additions & 12 deletions packages/protocol/contracts/layer1/based/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ library LibProving {
function proveBlocks(
TaikoData.State storage _state,
TaikoData.Config memory _config,
IAddressResolver _resolver,
IResolver _resolver,
uint64[] calldata _blockIds,
bytes[] calldata _inputs,
bytes calldata _batchProof
Expand Down Expand Up @@ -145,7 +145,7 @@ library LibProving {

// If batch verifier name is not empty, verify the batch proof.
if (batchVerifierName != LibStrings.B_TIER_OPTIMISTIC) {
IVerifier(_resolver.resolve(batchVerifierName, false)).verifyBatchProof(
IVerifier(_resolver.resolve(block.chainid, batchVerifierName, false)).verifyBatchProof(
ctxs, batchProof
);
}
Expand All @@ -162,7 +162,7 @@ library LibProving {
function proveBlock(
TaikoData.State storage _state,
TaikoData.Config memory _config,
IAddressResolver _resolver,
IResolver _resolver,
uint64 _blockId,
bytes calldata _input
)
Expand All @@ -187,7 +187,7 @@ library LibProving {
function _proveBlock(
TaikoData.State storage _state,
TaikoData.Config memory _config,
IAddressResolver _resolver,
IResolver _resolver,
uint64 _blockId,
bytes calldata _input,
TaikoData.TierProof memory _batchProof
Expand Down Expand Up @@ -248,11 +248,11 @@ library LibProving {
// Retrieve the tier configurations. If the tier is not supported, the subsequent action
// will result in a revert.
{
ITierRouter tierRouter = ITierRouter(_resolver.resolve(LibStrings.B_TIER_ROUTER, false));
ITierProvider tierProvider = ITierProvider(tierRouter.getProvider(local.blockId));
ITierProvider tierProvider =
ITierProvider(_resolver.resolve(block.chainid, LibStrings.B_TIER_PROVIDER, false));

local.tier = tierProvider.getTier(local.proof.tier);
local.minTier = tierProvider.getTier(local.meta.minTier);
local.tier = tierProvider.getTier(local.blockId, local.proof.tier);
local.minTier = tierProvider.getTier(local.blockId, local.meta.minTier);
local.isTopTier = local.tier.contestBond == 0;
}

Expand Down Expand Up @@ -295,9 +295,8 @@ library LibProving {

if (_batchProof.tier == 0) {
// In the case of per-transition proof, we verify the proof.
IVerifier(_resolver.resolve(local.tier.verifierName, false)).verifyProof(
LibData.verifierContextV2ToV1(ctx_), ctx_.tran, local.proof
);
IVerifier(_resolver.resolve(block.chainid, local.tier.verifierName, false))
.verifyProof(LibData.verifierContextV2ToV1(ctx_), ctx_.tran, local.proof);
}
}

Expand Down Expand Up @@ -468,7 +467,7 @@ library LibProving {
/// @param _local Current Local struct.
function _overrideWithHigherProof(
TaikoData.State storage _state,
IAddressResolver _resolver,
IResolver _resolver,
TaikoData.BlockV2 storage _blk,
TaikoData.TransitionState memory _ts,
TaikoData.Transition memory _tran,
Expand Down
7 changes: 3 additions & 4 deletions packages/protocol/contracts/layer1/based/LibUtils.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "src/shared/common/IAddressResolver.sol";
import "src/shared/common/LibStrings.sol";
import "src/shared/common/LibMath.sol";
import "src/shared/common/IResolver.sol";
import "src/shared/libs/LibStrings.sol";
import "src/shared/libs/LibMath.sol";
import "../tiers/ITierProvider.sol";
import "../tiers/ITierRouter.sol";
import "./TaikoData.sol";

/// @title LibUtils
Expand Down
21 changes: 11 additions & 10 deletions packages/protocol/contracts/layer1/based/LibVerifying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ library LibVerifying {
uint64 syncBlockId;
uint24 syncTransitionId;
address prover;
ITierRouter tierRouter;
ITierProvider tierProvider;
}

error L1_BLOCK_MISMATCH();
Expand All @@ -38,7 +38,7 @@ library LibVerifying {
function verifyBlocks(
TaikoData.State storage _state,
TaikoData.Config memory _config,
IAddressResolver _resolver,
IResolver _resolver,
uint64 _maxBlocksToVerify
)
internal
Expand Down Expand Up @@ -95,14 +95,14 @@ library LibVerifying {
break;
}

if (local.tierRouter == ITierRouter(address(0))) {
local.tierRouter =
ITierRouter(_resolver.resolve(LibStrings.B_TIER_ROUTER, false));
if (local.tierProvider == ITierProvider(address(0))) {
local.tierProvider = ITierProvider(
_resolver.resolve(block.chainid, LibStrings.B_TIER_PROVIDER, false)
);
}

uint24 cooldown = ITierProvider(local.tierRouter.getProvider(local.blockId)).getTier(
local.tier
).cooldownWindow;
uint24 cooldown =
local.tierProvider.getTier(local.blockId, local.tier).cooldownWindow;

if (!LibUtils.isPostDeadline(ts.timestamp, local.b.lastUnpausedAt, cooldown)) {
// If cooldownWindow is 0, the block can theoretically be proved and verified
Expand Down Expand Up @@ -162,8 +162,9 @@ library LibVerifying {
}

// Ask signal service to write cross chain signal
ISignalService(_resolver.resolve(LibStrings.B_SIGNAL_SERVICE, false))
.syncChainData(
ISignalService(
_resolver.resolve(block.chainid, LibStrings.B_SIGNAL_SERVICE, false)
).syncChainData(
_config.chainId,
LibStrings.H_STATE_ROOT,
local.syncBlockId,
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/layer1/based/TaikoData.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "src/shared/data/LibSharedData.sol";
import "src/shared/based/LibSharedData.sol";

/// @title TaikoData
/// @notice This library defines various data structures used in the Taiko protocol.
Expand Down
Loading
Loading