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)!: sync state root rather than signal service's storage root #15671

Merged
merged 56 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
ab12a57
breaking change by removing signal service overhead
dantaik Feb 5, 2024
3744fc8
Merge branch 'alpha-6' into alpha-7
dantaik Feb 5, 2024
b5728d1
Merge branch 'alpha-6' into alpha-7
dantaik Feb 6, 2024
a0f5efb
remove signalRoot step 1
dantaik Feb 7, 2024
019ef54
Update LibProving.sol
dantaik Feb 7, 2024
45e8ceb
more
dantaik Feb 7, 2024
9224460
Update LibUtils.sol
dantaik Feb 7, 2024
758ab07
Update LibVerifying.sol
dantaik Feb 7, 2024
71396f4
more
dantaik Feb 7, 2024
5aa18f5
Update TaikoL2.sol
dantaik Feb 7, 2024
b050af5
Update TaikoL2.sol
dantaik Feb 7, 2024
f978d83
Update TaikoL2.sol
dantaik Feb 7, 2024
7f48859
Make code compiling
Feb 7, 2024
ed3d47c
Add back helpers and uncomment lines
Feb 7, 2024
d6def2a
fix anchor
dantaik Feb 7, 2024
27de76a
Update TaikoL2.sol
dantaik Feb 7, 2024
05dd063
Update TaikoL2.t.sol
dantaik Feb 7, 2024
2e22f3e
minor
dantaik Feb 7, 2024
28134d6
rename
dantaik Feb 7, 2024
1e70e33
rename
dantaik Feb 7, 2024
425be15
update multi-hop bridging diagrams
dantaik Feb 7, 2024
7a2d7f2
more error messages in signal service
dantaik Feb 7, 2024
0a809f9
Update SignalService.sol
dantaik Feb 7, 2024
27f51d3
Update SignalService.sol
dantaik Feb 7, 2024
2bd445b
Update SignalService.sol
dantaik Feb 7, 2024
8200313
Update SignalService.sol
dantaik Feb 7, 2024
9ded143
comments
dantaik Feb 7, 2024
bef6290
Update LibVerifying.sol
dantaik Feb 7, 2024
c6e72ff
more
dantaik Feb 7, 2024
528288d
Update TaikoL2.sol
dantaik Feb 7, 2024
f8986e4
more
dantaik Feb 7, 2024
13e3f1f
more
dantaik Feb 7, 2024
70a26a4
remove unnecessary resolve
Feb 7, 2024
4ad3781
remove LibBlockHeader
dantaik Feb 8, 2024
5059135
Delete RLPWriter.sol
dantaik Feb 8, 2024
7ead006
Remove mint
dantaik Feb 8, 2024
dbd15c5
Merge branch 'alpha-7' into remove-signal-root
dantaik Feb 8, 2024
0821cad
Merge branch 'alpha-6' into alpha-7
dantaik Feb 8, 2024
9f3c136
Merge branch 'alpha-6' into alpha-7
dantaik Feb 8, 2024
b86f7c5
Merge branch 'alpha-7' into remove-signal-root
dantaik Feb 8, 2024
911c424
fix tests
dantaik Feb 8, 2024
92066ab
fix tests
dantaik Feb 8, 2024
458234a
Merge branch 'main' into remove-signal-root
dantaik Feb 9, 2024
4f12970
Update TaikoToken.sol
dantaik Feb 9, 2024
67b9e4f
fix
dantaik Feb 9, 2024
233f712
Update SignalService.sol
dantaik Feb 9, 2024
52147b3
reserve 2 slots for TaikoData.Transition
dantaik Feb 9, 2024
08c0ae2
Revert "reserve 2 slots for TaikoData.Transition"
dantaik Feb 9, 2024
0ed00af
fmt
dantaik Feb 9, 2024
2826b17
Merge branch 'main' into remove-signal-root
dantaik Feb 9, 2024
238f8a4
Update packages/protocol/contracts/L1/TaikoL1.sol
dantaik Feb 9, 2024
93869d9
Update packages/protocol/contracts/signal/SignalService.sol
dantaik Feb 9, 2024
57b73c5
Update packages/protocol/contracts/L2/TaikoL2.sol
dantaik Feb 9, 2024
298bd20
Update packages/protocol/contracts/signal/SignalService.sol
dantaik Feb 9, 2024
c0b39c8
Update PseZkVerifier.sol
dantaik Feb 9, 2024
a2771e7
Merge branch 'main' into remove-signal-root
dantaik Feb 10, 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
4 changes: 2 additions & 2 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ library TaikoData {
struct Transition {
bytes32 parentHash;
bytes32 blockHash;
bytes32 signalRoot;
bytes32 stateRoot;
bytes32 graffiti;
}

Expand All @@ -128,7 +128,7 @@ library TaikoData {
struct TransitionState {
bytes32 key; // slot 1, only written/read for the 1st state transition.
bytes32 blockHash; // slot 2
bytes32 signalRoot; // slot 3
bytes32 stateRoot; // slot 3
address prover; // slot 4
uint96 validityBond;
address contester; // slot 5
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/contracts/L1/TaikoEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ abstract contract TaikoEvents {
/// @param prover The prover whose transition is used for verifing the
/// block.
/// @param blockHash The hash of the verified block.
/// @param signalRoot The latest value of the signal service storage.
/// @param stateRoot The block's state root.
/// @param tier The tier ID of the proof.
/// @param contestations Number of total contestations.
event BlockVerified(
uint256 indexed blockId,
address indexed assignedProver,
address indexed prover,
bytes32 blockHash,
bytes32 signalRoot,
bytes32 stateRoot,
uint16 tier,
uint8 contestations
);
Expand Down
3 changes: 3 additions & 0 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ contract TaikoL1 is
}

/// @inheritdoc ICrossChainSync
/// @notice Important: as this contract doesn't send each block's state root as a signal when
/// the block is verified, bridging developers should subscribe to CrossChainSynced events
/// to ensure all synced state roots are verifiable using merkle proofs.
function getSyncedSnippet(uint64 blockId)
public
view
Expand Down
14 changes: 7 additions & 7 deletions packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ library LibProving {
{
// Make sure parentHash is not zero
// To contest an existing transition, simply use any non-zero value as
// the blockHash and signalRoot.
if (tran.parentHash == 0 || tran.blockHash == 0 || tran.signalRoot == 0) {
// the blockHash and stateRoot.
if (tran.parentHash == 0 || tran.blockHash == 0 || tran.stateRoot == 0) {
revert L1_INVALID_TRANSITION();
}

Expand All @@ -110,7 +110,7 @@ library LibProving {
}

// Each transition is uniquely identified by the parentHash, with the
// blockHash and signalRoot open for later updates as higher-tier proofs
// blockHash and stateRoot open for later updates as higher-tier proofs
// become available. In cases where a transition with the specified
// parentHash does not exist, the transition ID (tid) will be set to 0.
(uint32 tid, TaikoData.TransitionState storage ts) =
Expand Down Expand Up @@ -183,7 +183,7 @@ library LibProving {
}
}

bool sameTransition = tran.blockHash == ts.blockHash && tran.signalRoot == ts.signalRoot;
bool sameTransition = tran.blockHash == ts.blockHash && tran.stateRoot == ts.stateRoot;

if (proof.tier > ts.tier) {
// Handles the case when an incoming tier is higher than the current transition's tier.
Expand All @@ -210,7 +210,7 @@ library LibProving {

ts.prover = msg.sender;
ts.blockHash = tran.blockHash;
ts.signalRoot = tran.signalRoot;
ts.stateRoot = tran.stateRoot;

emit TransitionProved({
blockId: blk.blockId,
Expand Down Expand Up @@ -283,7 +283,7 @@ library LibProving {
// below.
ts = state.transitions[slot][tid];
ts.blockHash = 0;
ts.signalRoot = 0;
ts.stateRoot = 0;
ts.validityBond = 0;
ts.contester = address(0);
ts.contestBond = 1; // to save gas
Expand Down Expand Up @@ -376,7 +376,7 @@ library LibProving {

if (!sameTransition) {
ts.blockHash = tran.blockHash;
ts.signalRoot = tran.signalRoot;
ts.stateRoot = tran.stateRoot;
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/libs/LibUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ library LibUtils {
remoteBlockId: blockId,
syncedInBlock: blk.proposedIn,
blockHash: transition.blockHash,
signalRoot: transition.signalRoot
stateRoot: transition.stateRoot
});
}

Expand Down
22 changes: 13 additions & 9 deletions packages/protocol/contracts/L1/libs/LibVerifying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ library LibVerifying {
address indexed assignedProver,
address indexed prover,
bytes32 blockHash,
bytes32 signalRoot,
bytes32 stateRoot,
uint16 tier,
uint8 contestations
);

event CrossChainSynced(
uint64 indexed syncedInBlock, uint64 indexed blockId, bytes32 blockHash, bytes32 signalRoot
uint64 indexed syncedInBlock, uint64 indexed blockId, bytes32 blockHash, bytes32 stateRoot
);

// Warning: Any errors defined here must also be defined in TaikoErrors.sol.
Expand Down Expand Up @@ -78,7 +78,7 @@ library LibVerifying {
assignedProver: address(0),
prover: address(0),
blockHash: genesisBlockHash,
signalRoot: 0,
stateRoot: 0,
tier: 0,
contestations: 0
});
Expand Down Expand Up @@ -135,7 +135,7 @@ library LibVerifying {
// The `blockHash` variable represents the most recently trusted
// blockHash on L2.
bytes32 blockHash = state.transitions[slot][tid].blockHash;
bytes32 signalRoot;
bytes32 stateRoot;
uint64 processed;
address tierProvider;

Expand Down Expand Up @@ -185,7 +185,7 @@ library LibVerifying {

// Update variables
blockHash = ts.blockHash;
signalRoot = ts.signalRoot;
stateRoot = ts.stateRoot;

// We consistently return the liveness bond and the validity
// bond to the actual prover of the transition utilized for
Expand Down Expand Up @@ -222,7 +222,7 @@ library LibVerifying {
assignedProver: blk.assignedProver,
prover: ts.prover,
blockHash: blockHash,
signalRoot: signalRoot,
stateRoot: stateRoot,
tier: ts.tier,
contestations: ts.contestations
});
Expand All @@ -237,12 +237,16 @@ library LibVerifying {
// Update protocol level state variables
state.slotB.lastVerifiedBlockId = lastVerifiedBlockId;

// Store the L2's signal root as a signal to the local signal
// Store the L2's state root as a signal to the local signal
// service to allow for multi-hop bridging.
ISignalService(resolver.resolve("signal_service", false)).sendSignal(signalRoot);
//
// 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);

emit CrossChainSynced(
uint64(block.number), lastVerifiedBlockId, blockHash, signalRoot
uint64(block.number), lastVerifiedBlockId, blockHash, stateRoot
);
}
}
Expand Down
19 changes: 11 additions & 8 deletions packages/protocol/contracts/L2/TaikoL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,24 @@ contract TaikoL2 is CrossChainOwned, ICrossChainSync {
/// message verification.
/// @param l1BlockHash The latest L1 block hash when this block was
/// proposed.
/// @param l1SignalRoot The latest value of the L1 signal root.
/// @param l1StateRoot The latest L1 block's state root.
/// @param l1Height The latest L1 block height when this block was proposed.
/// @param parentGasUsed The gas used in the parent block.
function anchor(
bytes32 l1BlockHash,
bytes32 l1SignalRoot,
bytes32 l1StateRoot,
uint64 l1Height,
uint32 parentGasUsed
)
external
nonReentrant
{
if (
l1BlockHash == 0 || l1SignalRoot == 0 || l1Height == 0
l1BlockHash == 0 || l1StateRoot == 0 || l1Height == 0
|| (block.number != 1 && parentGasUsed == 0)
) revert L2_INVALID_PARAM();
) {
revert L2_INVALID_PARAM();
}

if (msg.sender != GOLDEN_TOUCH_ADDRESS) revert L2_INVALID_SENDER();

Expand All @@ -139,18 +141,19 @@ contract TaikoL2 is CrossChainOwned, ICrossChainSync {
revert L2_BASEFEE_MISMATCH();
}

// Store the L1's signal root as a signal to the local signal service to
// 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(l1SignalRoot);
emit CrossChainSynced(uint64(block.number), l1Height, l1BlockHash, l1SignalRoot);
ISignalService(resolve("signal_service", false)).sendSignal(l1StateRoot);

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

// Update state variables
l2Hashes[parentId] = blockhash(parentId);
snippets[l1Height] = ICrossChainSync.Snippet({
remoteBlockId: l1Height,
syncedInBlock: uint64(block.number),
blockHash: l1BlockHash,
signalRoot: l1SignalRoot
stateRoot: l1StateRoot
});
publicInputHash = publicInputHashNew;
latestSyncedL1Height = l1Height;
Expand Down
9 changes: 4 additions & 5 deletions packages/protocol/contracts/common/ICrossChainSync.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@ interface ICrossChainSync {
uint64 remoteBlockId;
uint64 syncedInBlock;
bytes32 blockHash;
bytes32 signalRoot;
bytes32 stateRoot;
}

/// @dev Emitted when a block has been synced across chains.
/// @param syncedInBlock The ID of this chain's block where the sync
/// happened.
/// @param blockId The ID of the remote block whose block hash and
/// signal root are synced.
/// @param blockId The ID of the remote block whose block hash are synced.
/// @param blockHash The hash of the synced block.
/// @param signalRoot The root hash representing cross-chain signals.
/// @param stateRoot The block's state root.
event CrossChainSynced(
uint64 indexed syncedInBlock, uint64 indexed blockId, bytes32 blockHash, bytes32 signalRoot
uint64 indexed syncedInBlock, uint64 indexed blockId, bytes32 blockHash, bytes32 stateRoot
);

/// @notice Fetches the hash of a block from the opposite chain.
Expand Down
Loading
Loading