Skip to content

Commit

Permalink
feat(protocol): support multi-hop bridging & add SGX prover (#14954)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Wang <dong77@gmail.com>
Co-authored-by: adaki2004 <keszeydani@gmail.com>
Co-authored-by: jeff <113397187+cyberhorsey@users.noreply.github.com>
Co-authored-by: David <david@taiko.xyz>
Co-authored-by: D <51912515+adaki2004@users.noreply.github.com>
  • Loading branch information
6 people authored Oct 17, 2023
1 parent 22c4a5a commit 6945598
Show file tree
Hide file tree
Showing 88 changed files with 2,468 additions and 4,838 deletions.
3 changes: 1 addition & 2 deletions packages/protocol/.solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"not-rely-on-time": "off",
"ordering": "warn",
"payable-fallback": "off",
"no-console": "off",
"one-contract-per-file": "off"
"no-console": "off"
}
}
1 change: 0 additions & 1 deletion packages/protocol/.solhintignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
node_modules/
lib/
contracts/test/TestLibRLPReader.sol
contracts/test/TestLibRLPWriter.sol
**/contracts/thirdparty/**/*.sol
test/GasComparison.t.sol
test/TestLn.sol
4 changes: 2 additions & 2 deletions packages/protocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
- **protocol:** add special logics for alpha-2 testnet ([#12987](https://github.com/taikoxyz/taiko-mono/issues/12987)) ([3b71285](https://github.com/taikoxyz/taiko-mono/commit/3b712857b5d5ede2a3683d949d1974c8cceeb69a))
- **protocol:** deploy the generated Yul plonk verifier ([#13016](https://github.com/taikoxyz/taiko-mono/issues/13016)) ([eb5d564](https://github.com/taikoxyz/taiko-mono/commit/eb5d564ec469b1ec79619b4d563c3f9989d264c2))
- **protocol:** enable two dimensional circuit/verifier lookup. ([#13066](https://github.com/taikoxyz/taiko-mono/issues/13066)) ([51d1f67](https://github.com/taikoxyz/taiko-mono/commit/51d1f67aa45fec8e2de73c1ed5a992306c6339c1))
- **protocol:** implement `Bridge.isMessageFailed` ([#13004](https://github.com/taikoxyz/taiko-mono/issues/13004)) ([45153d9](https://github.com/taikoxyz/taiko-mono/commit/45153d92cbcd0e80438c925d5ce5c52df3abd696))
- **protocol:** implement `Bridge.proveMessageFailed` ([#13004](https://github.com/taikoxyz/taiko-mono/issues/13004)) ([45153d9](https://github.com/taikoxyz/taiko-mono/commit/45153d92cbcd0e80438c925d5ce5c52df3abd696))
- **protocol:** implement releaseEther & releaseERC20 ([#13008](https://github.com/taikoxyz/taiko-mono/issues/13008)) ([088933e](https://github.com/taikoxyz/taiko-mono/commit/088933e74f7163459e328d61d8331235ab87e388))
- **protocol:** improve sync header storage on L2 ([#13041](https://github.com/taikoxyz/taiko-mono/issues/13041)) ([86c9fe4](https://github.com/taikoxyz/taiko-mono/commit/86c9fe44a3200490032610c017bfc88c3a57a8dd))
- **protocol:** temporarily force an `oracle prover` to be the first prover ([#13070](https://github.com/taikoxyz/taiko-mono/issues/13070)) ([d7401a2](https://github.com/taikoxyz/taiko-mono/commit/d7401a20c66a3c52330c4f92c95c71c902d74452))
Expand All @@ -227,7 +227,7 @@

### Features

- **bridge:** add getMessageStatusSlot function ([#12940](https://github.com/taikoxyz/taiko-mono/issues/12940)) ([9837fa3](https://github.com/taikoxyz/taiko-mono/commit/9837fa3dceb5d702b2247879af52988be4da333d))
- **bridge:** add messageStatusSlot function ([#12940](https://github.com/taikoxyz/taiko-mono/issues/12940)) ([9837fa3](https://github.com/taikoxyz/taiko-mono/commit/9837fa3dceb5d702b2247879af52988be4da333d))
- **bridge:** bridge transactions ([#411](https://github.com/taikoxyz/taiko-mono/issues/411)) ([19dd7ab](https://github.com/taikoxyz/taiko-mono/commit/19dd7abd4a2f5bc83e43d31938e43501472ff108))
- **bridge:** implement the bridge relayer ([#191](https://github.com/taikoxyz/taiko-mono/issues/191)) ([9f49e4c](https://github.com/taikoxyz/taiko-mono/commit/9f49e4c87304853c9d94693434d23a6b8258eac6))
- **deployment:** fund L1 bridge ([#400](https://github.com/taikoxyz/taiko-mono/issues/400)) ([e7ef53e](https://github.com/taikoxyz/taiko-mono/commit/e7ef53e27cb906d7128a3e512e7082e4176786e4))
Expand Down
2 changes: 0 additions & 2 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ library TaikoData {
// ---------------------------------------------------------------------
// The chain ID of the network where Taiko contracts are deployed.
uint256 chainId;
// Flag indicating whether the relay signal root is enabled or not.
bool relaySignalRoot;
// ---------------------------------------------------------------------
// Group 2: Block level configs
// ---------------------------------------------------------------------
Expand Down
123 changes: 44 additions & 79 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ contract TaikoL1 is
initializer
{
EssentialContract._init(_addressManager);
LibVerifying.init({
state: state,
config: getConfig(),
genesisBlockHash: _genesisBlockHash
});
LibVerifying.init(state, getConfig(), _genesisBlockHash);
}

/// @notice Proposes a Taiko L2 block.
Expand All @@ -83,22 +79,22 @@ contract TaikoL1 is
returns (TaikoData.BlockMetadata memory meta)
{
TaikoData.Config memory config = getConfig();
meta = LibProposing.proposeBlock({
state: state,
config: config,
resolver: AddressResolver(this),
txListHash: txListHash,
extraData: extraData,
assignment: abi.decode(assignment, (TaikoData.ProverAssignment)),
txList: txList
});
meta = LibProposing.proposeBlock(
state,
config,
AddressResolver(this),
txListHash,
extraData,
abi.decode(assignment, (TaikoData.ProverAssignment)),
txList
);
if (config.maxBlocksToVerifyPerProposal > 0) {
LibVerifying.verifyBlocks({
state: state,
config: config,
resolver: AddressResolver(this),
maxBlocksToVerify: config.maxBlocksToVerifyPerProposal
});
LibVerifying.verifyBlocks(
state,
config,
AddressResolver(this),
config.maxBlocksToVerifyPerProposal
);
}
}

Expand All @@ -114,45 +110,39 @@ contract TaikoL1 is
nonReentrant
{
TaikoData.Config memory config = getConfig();
uint8 maxBlocksToVerify = LibProving.proveBlock({
state: state,
config: config,
resolver: AddressResolver(this),
blockId: blockId,
evidence: abi.decode(input, (TaikoData.BlockEvidence))
});
uint8 maxBlocksToVerify = LibProving.proveBlock(
state,
config,
AddressResolver(this),
blockId,
abi.decode(input, (TaikoData.BlockEvidence))
);
if (maxBlocksToVerify > 0) {
LibVerifying.verifyBlocks({
state: state,
config: config,
resolver: AddressResolver(this),
maxBlocksToVerify: maxBlocksToVerify
});
LibVerifying.verifyBlocks(
state, config, AddressResolver(this), maxBlocksToVerify
);
}
}

/// @notice Verifies up to N blocks.
/// @param maxBlocksToVerify Max number of blocks to verify.
function verifyBlocks(uint64 maxBlocksToVerify) external nonReentrant {
if (maxBlocksToVerify == 0) revert L1_INVALID_PARAM();
LibVerifying.verifyBlocks({
state: state,
config: getConfig(),
resolver: AddressResolver(this),
maxBlocksToVerify: maxBlocksToVerify
});
LibVerifying.verifyBlocks(
state, getConfig(), AddressResolver(this), maxBlocksToVerify
);
}

/// @notice Deposit Taiko token to this contract
/// @param amount Amount of Taiko token to deposit.
function depositTaikoToken(uint256 amount) public {
LibTaikoToken.depositToken(state, AddressResolver(this), amount);
LibTaikoToken.depositTaikoToken(state, AddressResolver(this), amount);
}

/// @notice Withdraw Taiko token from this contract
/// @param amount Amount of Taiko token to withdraw.
function withdrawTaikoToken(uint256 amount) public {
LibTaikoToken.withdrawToken(state, AddressResolver(this), amount);
LibTaikoToken.withdrawTaikoToken(state, AddressResolver(this), amount);
}

function ownerWithdrawTaikoToken(
Expand All @@ -162,30 +152,23 @@ contract TaikoL1 is
public
onlyOwner
{
LibTaikoToken.ownerWithdrawToken(AddressResolver(this), to, amount);
LibTaikoToken.ownerWithdrawTaikoToken(AddressResolver(this), to, amount);
}

/// @notice Deposits Ether to Layer 2.
/// @param recipient Address of the recipient for the deposited Ether on
/// Layer 2.
function depositEtherToL2(address recipient) public payable {
LibDepositing.depositEtherToL2({
state: state,
config: getConfig(),
resolver: AddressResolver(this),
recipient: recipient
});
LibDepositing.depositEtherToL2(
state, getConfig(), AddressResolver(this), recipient
);
}

/// @notice Checks if Ether deposit is allowed for Layer 2.
/// @param amount Amount of Ether to be deposited.
/// @return true if Ether deposit is allowed, false otherwise.
function canDepositEthToL2(uint256 amount) public view returns (bool) {
return LibDepositing.canDepositEthToL2({
state: state,
config: getConfig(),
amount: amount
});
return LibDepositing.canDepositEthToL2(state, getConfig(), amount);
}

/// @notice Gets the details of a block.
Expand All @@ -196,11 +179,7 @@ contract TaikoL1 is
view
returns (TaikoData.Block memory blk)
{
return LibUtils.getBlock({
state: state,
config: getConfig(),
blockId: blockId
});
return LibUtils.getBlock(state, getConfig(), blockId);
}

/// @notice Gets the state transition for a specific block.
Expand All @@ -215,34 +194,21 @@ contract TaikoL1 is
view
returns (TaikoData.Transition memory)
{
return LibUtils.getTransition({
state: state,
config: getConfig(),
blockId: blockId,
parentHash: parentHash
});
return LibUtils.getTransition(state, getConfig(), blockId, parentHash);
}

/// @inheritdoc ICrossChainSync
function getCrossChainBlockHash(uint64 blockId)
function getSyncedSnippet(uint64 blockId)
public
view
override
returns (bytes32)
returns (ICrossChainSync.Snippet memory data)
{
return LibUtils.getVerifyingTransition(state, getConfig(), blockId)
.blockHash;
}
TaikoData.Transition storage transition =
LibUtils.getVerifyingTransition(state, getConfig(), blockId);

/// @inheritdoc ICrossChainSync
function getCrossChainSignalRoot(uint64 blockId)
public
view
override
returns (bytes32)
{
return LibUtils.getVerifyingTransition(state, getConfig(), blockId)
.signalRoot;
data.blockHash = transition.blockHash;
data.signalRoot = transition.signalRoot;
}

/// @notice Gets the state variables of the TaikoL1 contract.
Expand Down Expand Up @@ -308,7 +274,6 @@ contract TaikoL1 is
{
return TaikoData.Config({
chainId: 167_007,
relaySignalRoot: false,
blockMaxProposals: 403_200,
blockRingBufferSize: 403_210,
maxBlocksToVerifyPerProposal: 10,
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/TaikoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ contract TaikoToken is
__ERC20Permit_init(_name);
__ERC20Votes_init();

for (uint256 i = 0; i < _premintRecipients.length; ++i) {
for (uint256 i; i < _premintRecipients.length; ++i) {
_mint(_premintRecipients[i], _premintAmounts[i]);
}
}
Expand Down
13 changes: 4 additions & 9 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ library LibProposing {
// transition is not the initial one or if it was generated and
// validated by different provers. Instead, a portion of the assignment
// bond serves as a reward for the actual prover.
LibTaikoToken.debitToken(
LibTaikoToken.debitTaikoToken(
state, resolver, blk.assignedProver, config.livenessBond
);

Expand All @@ -171,11 +171,8 @@ library LibProposing {

// Validate the prover assignment, then charge Ether or ERC20 as the
// prover fee based on the block's minTier.
uint256 proverFee = _validateAssignment({
minTier: blk.minTier,
txListHash: txListHash,
assignment: assignment
});
uint256 proverFee =
_validateAssignment(blk.minTier, txListHash, assignment);

emit BlockProposed({
blockId: blk.blockId,
Expand Down Expand Up @@ -284,9 +281,7 @@ library LibProposing {
returns (uint256)
{
for (uint256 i; i < tierFees.length; ++i) {
if (tierFees[i].tier == tierId) {
return tierFees[i].fee;
}
if (tierFees[i].tier == tierId) return tierFees[i].fee;
}
revert L1_TIER_NOT_FOUND();
}
Expand Down
16 changes: 8 additions & 8 deletions packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ library LibProving {
evidence.proof.length == 32
&& bytes32(evidence.proof) == keccak256("RETURN_LIVENESS_BOND")
) {
LibTaikoToken.creditToken(
LibTaikoToken.creditTaikoToken(
state, resolver, blk.assignedProver, blk.livenessBond, false
);
}
Expand Down Expand Up @@ -273,7 +273,7 @@ library LibProving {
if (tran.contester != address(0)) revert L1_ALREADY_CONTESTED();

// Burn the contest bond from the prover.
LibTaikoToken.debitToken(
LibTaikoToken.debitTaikoToken(
state, resolver, msg.sender, tier.contestBond
);

Expand Down Expand Up @@ -352,7 +352,7 @@ library LibProving {
}

// Burn the validity bond from the prover.
LibTaikoToken.debitToken(
LibTaikoToken.debitTaikoToken(
state, resolver, msg.sender, tier.validityBond
);

Expand All @@ -372,7 +372,7 @@ library LibProving {

// Mint the reward and the validity bond and return it to
// the previous prover.
LibTaikoToken.creditToken(
LibTaikoToken.creditTaikoToken(
state,
resolver,
tran.prover,
Expand All @@ -389,17 +389,17 @@ library LibProving {
// for the tier-0 transition. Consequently, we only grant a
// reward to the contester if it is not a zero-address.
if (tran.contester != address(0)) {
LibTaikoToken.creditToken(
LibTaikoToken.creditTaikoToken(
state,
resolver,
tran.contester,
reward + tran.contestBond,
false
);
} else if (reward != 0) {
//The prover is also the contester, so the reward is
// The prover is also the contester, so the reward is
// sent to him.
LibTaikoToken.creditToken(
LibTaikoToken.creditTaikoToken(
state, resolver, msg.sender, reward, false
);
}
Expand All @@ -415,7 +415,7 @@ library LibProving {
// In theory, the reward can also be zero for certain tiers if
// their validity bonds are set to zero.
if (reward != 0) {
LibTaikoToken.creditToken(
LibTaikoToken.creditTaikoToken(
state, resolver, msg.sender, reward, false
);
}
Expand Down
Loading

0 comments on commit 6945598

Please sign in to comment.