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

feat(protocol)!: re-implement multi-hop bridging with optional caching #15761

Merged
merged 54 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
6649b4d
add trusted hops and relay chain data
dantaik Feb 13, 2024
6ce392f
improved hop processing
dantaik Feb 13, 2024
0249dd5
Update ISignalService.sol
dantaik Feb 13, 2024
da1b121
impl
dantaik Feb 13, 2024
fc82575
delete IHopRelayRegistry
dantaik Feb 13, 2024
c84a075
fix
dantaik Feb 13, 2024
76cdb83
fix tests
dantaik Feb 13, 2024
1a170dd
Update SignalService.sol
dantaik Feb 13, 2024
24be6ff
more
dantaik Feb 13, 2024
a657fe8
fmt
dantaik Feb 13, 2024
1f5e57d
more
dantaik Feb 13, 2024
adbacc8
fmt
dantaik Feb 13, 2024
3f8031a
lint
dantaik Feb 13, 2024
2b5eeb0
Update SignalService.sol
dantaik Feb 13, 2024
33d4332
Update SignalService.sol
dantaik Feb 13, 2024
870b613
Update TaikoL2.t.sol
dantaik Feb 13, 2024
8535c7f
fix test
dantaik Feb 13, 2024
786cc9b
feat(protocol): only keep one latest copy of synced snippet (#15767)
dantaik Feb 13, 2024
5e4b4a9
Merge branch 'main' into improve_signal_service_and_multihop
dantaik Feb 13, 2024
c1d1e08
fix: fix deplyoment issues
davidtaikocha Feb 13, 2024
59ef70a
Update packages/protocol/contracts/libs/LibTrieProof.sol
dantaik Feb 13, 2024
bfdba14
fix (#15769)
dantaik Feb 13, 2024
37260db
remove setTrustedRelay
dantaik Feb 13, 2024
ec8339e
Update SignalService.sol
dantaik Feb 13, 2024
d7c8752
revert some changes (#15774)
dantaik Feb 13, 2024
b823c64
chore(protocol): update multihop_bridging_deployment.md (#15772)
dantaik Feb 13, 2024
148dfbf
Merge branch 'main' into improve_signal_service_and_multihop
dantaik Feb 13, 2024
ea715d0
Update LibUtils.sol
dantaik Feb 13, 2024
1ff27a5
Update LibUtils.sol
dantaik Feb 13, 2024
58895f9
Update LibTrieProof.t.sol
dantaik Feb 13, 2024
3b44376
Update LibTrieProof.t.sol
dantaik Feb 13, 2024
261103e
improve
dantaik Feb 14, 2024
5e38dbc
Update SignalService.t.sol
dantaik Feb 14, 2024
87002e4
fix
dantaik Feb 14, 2024
6bf0cfc
Merge branch 'main' into improve_signal_service_and_multihop
dantaik Feb 14, 2024
4a9fb8b
fmt
dantaik Feb 14, 2024
4ac4c0e
Merge branch 'improve_signal_service_and_multihop' of github.com:taik…
dantaik Feb 14, 2024
70920b2
feat(protocol): more flexible signal service caching (#15777)
dantaik Feb 14, 2024
78ea8f3
+syncedInBlock
dantaik Feb 14, 2024
7f0e3a4
fix
dantaik Feb 14, 2024
7285f13
catch signal errors
dantaik Feb 14, 2024
e6af695
Update SignalService.t.sol
dantaik Feb 14, 2024
caee5bf
Merge branch 'main' into improve_signal_service_and_multihop
dantaik Feb 14, 2024
8254a3f
Update how_taiko_proves_blocks.md
dantaik Feb 14, 2024
f09b36a
feat(protocol): remove unused imports (#15781)
adaki2004 Feb 14, 2024
429285e
Update TaikoTest.sol
dantaik Feb 14, 2024
479bf24
Update LibFixedPointMath.t.sol
dantaik Feb 14, 2024
a9fe655
Update GenerateGenesis.g.sol
dantaik Feb 14, 2024
4bcbda1
Merge branch 'main' into improve_signal_service_and_multihop
dantaik Feb 14, 2024
3207979
fix
dantaik Feb 14, 2024
1f1de03
Update foundry.toml
dantaik Feb 14, 2024
b03c001
Merge branch 'main' into improve_signal_service_and_multihop
dantaik Feb 14, 2024
b3fa5db
add isChainDataRelayed to ISignalService (#15787)
dantaik Feb 14, 2024
32057a2
Merge branch 'main' into improve_signal_service_and_multihop
dantaik Feb 15, 2024
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
5 changes: 4 additions & 1 deletion packages/protocol/contracts/L1/libs/LibVerifying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import "../../common/AddressResolver.sol";
import "../../libs/LibMath.sol";
import "../../signal/ISignalService.sol";
import "../../signal/LibSignals.sol";
import "../tiers/ITierProvider.sol";
import "../TaikoData.sol";
import "./LibUtils.sol";
Expand Down Expand Up @@ -247,7 +248,9 @@ library LibVerifying {
// This also means if we verified more than one block, only the last one's stateRoot
// is sent as a signal and verifiable with merkle proofs, all other blocks'
// stateRoot are not.
ISignalService(resolver.resolve("signal_service", false)).sendSignal(stateRoot);
ISignalService(resolver.resolve("signal_service", false)).relayChainData(
config.chainId, LibSignals.STATE_ROOT, stateRoot
);

emit CrossChainSynced(
uint64(block.number), lastVerifiedBlockId, blockHash, stateRoot
Expand Down
6 changes: 4 additions & 2 deletions packages/protocol/contracts/L2/TaikoL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import "lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";

import "../common/ICrossChainSync.sol";
import "../signal/ISignalService.sol";
import "../signal/LibSignals.sol";
import "../libs/LibAddress.sol";
import "../libs/LibMath.sol";
import "./Lib1559Math.sol";
Expand Down Expand Up @@ -143,7 +144,9 @@ contract TaikoL2 is CrossChainOwned, ICrossChainSync {

// Store the L1's state root as a signal to the local signal service to
// allow for multi-hop bridging.
ISignalService(resolve("signal_service", false)).sendSignal(l1StateRoot);
ISignalService(resolve("signal_service", false)).relayChainData(
ownerChainId, LibSignals.STATE_ROOT, l1StateRoot
);

emit CrossChainSynced(uint64(block.number), l1Height, l1BlockHash, l1StateRoot);

Expand All @@ -157,7 +160,6 @@ contract TaikoL2 is CrossChainOwned, ICrossChainSync {
});
publicInputHash = publicInputHashNew;
latestSyncedL1Height = l1Height;

emit Anchored(blockhash(parentId), gasExcess);
}

Expand Down
7 changes: 3 additions & 4 deletions packages/protocol/contracts/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ contract Bridge is EssentialContract, IBridge {
/// @param signal The signal.
/// @param chainId The ID of the chain the signal is stored on
/// @param proof The merkle inclusion proof.
/// @return True if the message was received.
/// @return success True if the message was received.
function _proveSignalReceived(
address signalService,
bytes32 signal,
Expand All @@ -584,13 +584,12 @@ contract Bridge is EssentialContract, IBridge {
)
private
view
returns (bool)
returns (bool success)
{
bytes memory data = abi.encodeCall(
ISignalService.proveSignalReceived,
(chainId, resolve(chainId, "bridge", false), signal, proof)
);
(bool success, bytes memory ret) = signalService.staticcall(data);
return success ? abi.decode(ret, (bool)) : false;
(success,) = signalService.staticcall(data);
}
}
47 changes: 26 additions & 21 deletions packages/protocol/contracts/libs/LibTrieProof.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,42 @@ library LibTrieProof {
error LTP_INVALID_ACCOUNT_PROOF();
error LTP_INVALID_INCLUSION_PROOF();

/**
* Verifies that the value of a slot in the storage of an account is value.
*
* @param stateRoot The merkle root of state tree.
* @param addr The address of contract.
* @param slot The slot in the contract.
* @param value The value to be verified.
* @param mkproof The proof obtained by encoding storage proof.
*/
function verifyFullMerkleProof(
bytes32 stateRoot,
/// @notice Verifies that the value of a slot in the storage of an account is value.
///
/// @param rootHash The merkle root of state tree or the account tree. If accountProof's length
/// is zero, it is used as the account's storage root, otherwise it will be used as the state
/// root.
/// @param addr The address of contract.
/// @param slot The slot in the contract.
/// @param value The value to be verified.
/// @param accountProof The account proof
/// @param storageProof The storage proof
/// @return storageRoot The account's storage root
function verifyMerkleProof(
bytes32 rootHash,
address addr,
bytes32 slot,
bytes memory value,
bytes memory mkproof
bytes[] memory accountProof,
bytes[] memory storageProof
)
internal
pure
returns (bytes32 storageRoot)
{
(bytes[] memory accountProof, bytes[] memory storageProof) =
abi.decode(mkproof, (bytes[], bytes[]));
if (accountProof.length != 0) {
bytes memory rlpAccount =
SecureMerkleTrie.get(abi.encodePacked(addr), accountProof, rootHash);

bytes memory rlpAccount =
SecureMerkleTrie.get(abi.encodePacked(addr), accountProof, stateRoot);
if (rlpAccount.length == 0) revert LTP_INVALID_ACCOUNT_PROOF();

if (rlpAccount.length == 0) revert LTP_INVALID_ACCOUNT_PROOF();
RLPReader.RLPItem[] memory accountState = RLPReader.readList(rlpAccount);

RLPReader.RLPItem[] memory accountState = RLPReader.readList(rlpAccount);

bytes memory storageRoot =
RLPReader.readBytes(accountState[ACCOUNT_FIELD_INDEX_STORAGE_HASH]);
storageRoot =
bytes32(RLPReader.readBytes(accountState[ACCOUNT_FIELD_INDEX_STORAGE_HASH]));
} else {
storageRoot = rootHash;
}

bool verified = SecureMerkleTrie.verifyInclusionProof(
bytes.concat(slot), value, storageProof, bytes32(storageRoot)
Expand Down
101 changes: 0 additions & 101 deletions packages/protocol/contracts/signal/HopRelayRegistry.sol

This file was deleted.

35 changes: 0 additions & 35 deletions packages/protocol/contracts/signal/IHopRelayRegistry.sol

This file was deleted.

40 changes: 25 additions & 15 deletions packages/protocol/contracts/signal/ISignalService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,43 @@ pragma solidity 0.8.24;
/// a merkle proof.

interface ISignalService {
/// @notice Send a signal (message) by setting the storage slot to a value
/// of 1.
/// @notice Send a signal (message) by setting the storage slot to a value of 1.
/// @param signal The signal (message) to send.
/// @return storageSlot The location in storage where this signal is stored.
function sendSignal(bytes32 signal) external returns (bytes32 storageSlot);
/// @return slot The location in storage where this signal is stored.
function sendSignal(bytes32 signal) external returns (bytes32 slot);

/// @notice Verifies if a particular signal has already been sent.
/// @param app The address that initiated the signal.
/// @param signal The signal (message) that was sent.
/// @return True if the signal has been sent, otherwise false.
function isSignalSent(address app, bytes32 signal) external view returns (bool);
/// @notice Relay a data from a remote chain locally as a signal. The signal is calculated
/// uniquely from chainId, kind, and data.
/// @param chainId The remote chainId.
/// @param kind A value to mark the data type.
/// @param data The remote data.
/// @return slot The location in storage where this signal is stored.
function relayChainData(
uint64 chainId,
bytes32 kind,
bytes32 data
)
external
returns (bytes32 slot);

/// @notice Verifies if a signal has been received on the target chain.
/// @param srcChainId The identifier for the source chain from which the
/// @param chainId The identifier for the source chain from which the
/// signal originated.
/// @param app The address that initiated the signal.
/// @param signal The signal (message) to send.
/// @param proof Merkle proof that the signal was persisted on the
/// source chain.
/// @return True if the signal has been received, otherwise false.
function proveSignalReceived(
uint64 srcChainId,
uint64 chainId,
address app,
bytes32 signal,
bytes calldata proof
)
external
view
returns (bool);
external;

/// @notice Verifies if a particular signal has already been sent.
/// @param app The address that initiated the signal.
/// @param signal The signal (message) that was sent.
/// @return True if the signal has been sent, otherwise false.
function isSignalSent(address app, bytes32 signal) external view returns (bool);
}
21 changes: 21 additions & 0 deletions packages/protocol/contracts/signal/LibSignals.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
// _____ _ _ _ _
// |_ _|_ _(_) |_____ | | __ _| |__ ___
// | |/ _` | | / / _ \ | |__/ _` | '_ (_-<
// |_|\__,_|_|_\_\___/ |____\__,_|_.__/__/
//
// Email: [email protected]
// Website: https://taiko.xyz
// GitHub: https://github.com/taikoxyz
// Discord: https://discord.gg/taikoxyz
// Twitter: https://twitter.com/taikoxyz
// Blog: https://mirror.xyz/labs.taiko.eth
// Youtube: https://www.youtube.com/@taikoxyz

pragma solidity 0.8.24;

/// @title LibSignals
library LibSignals {
bytes32 public constant STATE_ROOT = keccak256("STATE_ROOT");
bytes32 public constant SIGNAL_ROOT = keccak256("SIGNAL_ROOT");
}
Loading
Loading