diff --git a/packages/protocol/contracts/L1/TaikoData.sol b/packages/protocol/contracts/L1/TaikoData.sol index e1ddb52e61..e66625c989 100644 --- a/packages/protocol/contracts/L1/TaikoData.sol +++ b/packages/protocol/contracts/L1/TaikoData.sol @@ -119,7 +119,7 @@ library TaikoData { struct Transition { bytes32 parentHash; bytes32 blockHash; - bytes32 signalRoot; + bytes32 stateRoot; bytes32 graffiti; } @@ -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 diff --git a/packages/protocol/contracts/L1/TaikoEvents.sol b/packages/protocol/contracts/L1/TaikoEvents.sol index 3f434306c1..d094697eb4 100644 --- a/packages/protocol/contracts/L1/TaikoEvents.sol +++ b/packages/protocol/contracts/L1/TaikoEvents.sol @@ -43,7 +43,7 @@ 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( @@ -51,7 +51,7 @@ abstract contract TaikoEvents { address indexed assignedProver, address indexed prover, bytes32 blockHash, - bytes32 signalRoot, + bytes32 stateRoot, uint16 tier, uint8 contestations ); diff --git a/packages/protocol/contracts/L1/TaikoL1.sol b/packages/protocol/contracts/L1/TaikoL1.sol index 7a0b8a6041..694de59b79 100644 --- a/packages/protocol/contracts/L1/TaikoL1.sol +++ b/packages/protocol/contracts/L1/TaikoL1.sol @@ -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 diff --git a/packages/protocol/contracts/L1/libs/LibProving.sol b/packages/protocol/contracts/L1/libs/LibProving.sol index df61712397..3f0e512e5b 100644 --- a/packages/protocol/contracts/L1/libs/LibProving.sol +++ b/packages/protocol/contracts/L1/libs/LibProving.sol @@ -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(); } @@ -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) = @@ -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. @@ -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, @@ -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 @@ -376,7 +376,7 @@ library LibProving { if (!sameTransition) { ts.blockHash = tran.blockHash; - ts.signalRoot = tran.signalRoot; + ts.stateRoot = tran.stateRoot; } } diff --git a/packages/protocol/contracts/L1/libs/LibUtils.sol b/packages/protocol/contracts/L1/libs/LibUtils.sol index 37ee670eab..8824f4aa5b 100644 --- a/packages/protocol/contracts/L1/libs/LibUtils.sol +++ b/packages/protocol/contracts/L1/libs/LibUtils.sol @@ -77,7 +77,7 @@ library LibUtils { remoteBlockId: blockId, syncedInBlock: blk.proposedIn, blockHash: transition.blockHash, - signalRoot: transition.signalRoot + stateRoot: transition.stateRoot }); } diff --git a/packages/protocol/contracts/L1/libs/LibVerifying.sol b/packages/protocol/contracts/L1/libs/LibVerifying.sol index 03e9e12f91..5b95e4d3d0 100644 --- a/packages/protocol/contracts/L1/libs/LibVerifying.sol +++ b/packages/protocol/contracts/L1/libs/LibVerifying.sol @@ -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. @@ -78,7 +78,7 @@ library LibVerifying { assignedProver: address(0), prover: address(0), blockHash: genesisBlockHash, - signalRoot: 0, + stateRoot: 0, tier: 0, contestations: 0 }); @@ -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; @@ -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 @@ -222,7 +222,7 @@ library LibVerifying { assignedProver: blk.assignedProver, prover: ts.prover, blockHash: blockHash, - signalRoot: signalRoot, + stateRoot: stateRoot, tier: ts.tier, contestations: ts.contestations }); @@ -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 ); } } diff --git a/packages/protocol/contracts/L2/TaikoL2.sol b/packages/protocol/contracts/L2/TaikoL2.sol index 6c5757c631..2d620b7e66 100644 --- a/packages/protocol/contracts/L2/TaikoL2.sol +++ b/packages/protocol/contracts/L2/TaikoL2.sol @@ -100,12 +100,12 @@ 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 ) @@ -113,9 +113,11 @@ contract TaikoL2 is CrossChainOwned, ICrossChainSync { 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(); @@ -139,10 +141,11 @@ 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); @@ -150,7 +153,7 @@ contract TaikoL2 is CrossChainOwned, ICrossChainSync { remoteBlockId: l1Height, syncedInBlock: uint64(block.number), blockHash: l1BlockHash, - signalRoot: l1SignalRoot + stateRoot: l1StateRoot }); publicInputHash = publicInputHashNew; latestSyncedL1Height = l1Height; diff --git a/packages/protocol/contracts/common/ICrossChainSync.sol b/packages/protocol/contracts/common/ICrossChainSync.sol index 4b58484be6..97d22e8af9 100644 --- a/packages/protocol/contracts/common/ICrossChainSync.sol +++ b/packages/protocol/contracts/common/ICrossChainSync.sol @@ -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. diff --git a/packages/protocol/contracts/signal/SignalService.sol b/packages/protocol/contracts/signal/SignalService.sol index 18738ff503..b9dc173ccf 100644 --- a/packages/protocol/contracts/signal/SignalService.sol +++ b/packages/protocol/contracts/signal/SignalService.sol @@ -34,22 +34,29 @@ import "./ISignalService.sol"; contract SignalService is AuthorizableContract, ISignalService { using SafeCast for uint256; - // storageProof represents ABI-encoded tuple of (key, value, and proof) + // merkleProof represents ABI-encoded tuple of (key, value, and proof) // returned from the eth_getProof() API. struct Hop { - address signalRootRelay; - bytes32 signalRoot; - bytes storageProof; + address relay; + bytes32 stateRoot; + bytes merkleProof; } struct Proof { address crossChainSync; uint64 height; - bytes storageProof; + bytes merkleProof; Hop[] hops; } + error SS_INVALID_FUNC_PARAMS(); + error SS_INVALID_PROOF_PARAMS(); + error SS_CROSS_CHAIN_SYNC_UNAUTHORIZED(uint256 chaindId); + error SS_CROSS_CHAIN_SYNC_ZERO_STATE_ROOT(); + error SS_HOP_RELAYER_UNAUTHORIZED(); error SS_INVALID_APP(); + error SS_INVALID_APP_PROOF(); + error SS_INVALID_HOP_PROOF(); error SS_INVALID_SIGNAL(); error SS_UNSUPPORTED(); @@ -93,59 +100,64 @@ contract SignalService is AuthorizableContract, ISignalService { returns (bool) { if (app == address(0) || signal == 0 || srcChainId == 0 || srcChainId == block.chainid) { - return false; + revert SS_INVALID_FUNC_PARAMS(); } Proof memory p = abi.decode(proof, (Proof)); - if (p.crossChainSync == address(0) || p.storageProof.length == 0) { - return false; + if (p.crossChainSync == address(0) || p.merkleProof.length == 0) { + revert SS_INVALID_PROOF_PARAMS(); } for (uint256 i; i < p.hops.length; ++i) { - if (p.hops[i].signalRoot == 0) return false; - if (p.hops[i].storageProof.length == 0) return false; + if (p.hops[i].stateRoot == 0 || p.hops[i].merkleProof.length == 0) { + revert SS_INVALID_PROOF_PARAMS(); + } } - // Check a chain of inclusion proofs. If this chain is chainA, and the - // message is sent on chainC, and we have chainB in the middle, we - // verify that chainB's signalRoot has been sent as a signal by chainB's - // "taiko" contract, then using chainB's signalRoot, we further check - // the signal is sent by chainC's "bridge" contract. + // p.crossChainSync is either a TaikoL1 contract or a TaikoL2 contract if (!isAuthorizedAs(p.crossChainSync, bytes32(block.chainid))) { - return false; + revert SS_CROSS_CHAIN_SYNC_UNAUTHORIZED(block.chainid); } - bytes32 signalRoot = ICrossChainSync(p.crossChainSync).getSyncedSnippet(p.height).signalRoot; - - if (signalRoot == 0) return false; + bytes32 stateRoot = ICrossChainSync(p.crossChainSync).getSyncedSnippet(p.height).stateRoot; + if (stateRoot == 0) revert SS_CROSS_CHAIN_SYNC_ZERO_STATE_ROOT(); + // If a signal is sent from chainA -> chainB -> chainC (this chain), we verify the proofs in + // the following order: + // 1. using chainC's latest parent's stateRoot to verify that chainB's TaikoL1/TaikoL2 contract has + // sent a given hop stateRoot on chainB using its own signal service. + // 2. using the verified hop stateRoot to verify that the source app on chainA has sent a + // signal using its own signal service. + // We always verify the proofs in the reversed order (top to bottom). for (uint256 i; i < p.hops.length; ++i) { Hop memory hop = p.hops[i]; + if (hop.stateRoot == stateRoot) revert SS_INVALID_HOP_PROOF(); - bytes32 label = authorizedAddresses[hop.signalRootRelay]; - if (label == 0) return false; - uint64 chainId = uint256(label).toUint64(); - - bytes32 slot = getSignalSlot( - chainId, // use label as chainId - hop.signalRootRelay, - hop.signalRoot // as a signal - ); + bytes32 label = authorizedAddresses[hop.relay]; + if (label == 0) revert SS_HOP_RELAYER_UNAUTHORIZED(); - bool verified = SecureMerkleTrie.verifyInclusionProof( - bytes.concat(slot), hex"01", _transcode(hop.storageProof), signalRoot - ); - if (!verified) return false; + uint64 hopChainId = uint256(label).toUint64(); - signalRoot = hop.signalRoot; + verifyMerkleProof(stateRoot, hopChainId, hop.relay, hop.stateRoot, hop.merkleProof); + stateRoot = hop.stateRoot; } - return SecureMerkleTrie.verifyInclusionProof( - bytes.concat(getSignalSlot(srcChainId, app, signal)), - hex"01", - _transcode(p.storageProof), - signalRoot - ); + verifyMerkleProof(stateRoot, srcChainId, app, signal, p.merkleProof); + return true; + } + + function verifyMerkleProof( + bytes32 stateRoot, + uint64 srcChainId, + address srcApp, + bytes32 srcSignal, + bytes memory merkleProof + ) + public + view + virtual + { + // TODO(dani): implement this please } /// @notice Get the storage slot of the signal. @@ -166,6 +178,12 @@ contract SignalService is AuthorizableContract, ISignalService { return keccak256(abi.encodePacked("SIGNAL", chainId, app, signal)); } + /// @notice Tells if we need to check real proof or it is a test. + /// @return Returns true to skip checking inclusion proofs. + function skipProofCheck() public pure virtual returns (bool) { + return false; + } + /// @notice Translate a RLP-encoded list of RLP-encoded TrieNodes into a list of LP-encoded /// TrieNodes. function _transcode(bytes memory proof) internal pure returns (bytes[] memory proofs) { diff --git a/packages/protocol/contracts/thirdparty/README.md b/packages/protocol/contracts/thirdparty/README.md index d9882d04b2..cb2583efe3 100644 --- a/packages/protocol/contracts/thirdparty/README.md +++ b/packages/protocol/contracts/thirdparty/README.md @@ -1,3 +1,3 @@ # ABOUT THIRDPARTY CODE -- /optimism: code copied from https://github.com/ethereum-optimism/optimism/releases/tag/op-batcher%2Fv1.4.3 as-is with only solidity pragma changed. +- /optimism: code copied from `packages/contracts-bedrock/src/libraries` in https://github.com/ethereum-optimism/optimism/releases/tag/op-batcher%2Fv1.4.3 as-is with only solidity pragma changed. diff --git a/packages/protocol/contracts/verifiers/PseZkVerifier.sol b/packages/protocol/contracts/verifiers/PseZkVerifier.sol index cbfbf5e64d..00320bb36a 100644 --- a/packages/protocol/contracts/verifiers/PseZkVerifier.sol +++ b/packages/protocol/contracts/verifiers/PseZkVerifier.sol @@ -144,7 +144,7 @@ contract PseZkVerifier is EssentialContract, IVerifier { abi.encode( tran.parentHash, tran.blockHash, - tran.signalRoot, + tran.stateRoot, tran.graffiti, metaHash, prover, diff --git a/packages/protocol/docs/how_taiko_proves_blocks.md b/packages/protocol/docs/how_taiko_proves_blocks.md index 24ccb65e61..f6f72877bc 100644 --- a/packages/protocol/docs/how_taiko_proves_blocks.md +++ b/packages/protocol/docs/how_taiko_proves_blocks.md @@ -321,7 +321,7 @@ subgraph L1Storage[L1 Storage] b_l1_taiko_addr[/taikoL1Address/] b_l1_signal_service_addr[/L1 signalServiceAddress/] b_l2_signal_service_addr[/L2 signalServiceAddress/] -b_signal_root[/signalRoot/] +b_signal_root[/stateRoot/] end L1Storage:::group @@ -331,7 +331,7 @@ subgraph L2Storage[L2 Storage] s_public_input_hash[/publicInputHash/] s_parent_timestamp[/parentTimestamp/] s_gas_excess[/gasExcess/] -s_signal_root[/signalRoot/] +s_signal_root[/stateRoot/] end L2Storage:::group @@ -340,7 +340,7 @@ subgraph BlockEvidence e_meta_hash(metaHash) e_parent_hash(parentHash):::transition e_block_hash(blockHash) -e_signal_root(signalRoot) +e_signal_root(stateRoot) e_graffiti(graffiti) e_prover(prover) e_parent_gas_used(parentGasUsed):::transition diff --git a/packages/protocol/docs/multihop/L1_to_L2.png b/packages/protocol/docs/multihop/L1_to_L2.png index 3d913e36d9..cacc2042a2 100644 Binary files a/packages/protocol/docs/multihop/L1_to_L2.png and b/packages/protocol/docs/multihop/L1_to_L2.png differ diff --git a/packages/protocol/docs/multihop/L2A_to_L3.png b/packages/protocol/docs/multihop/L2A_to_L3.png index 4b1f4580f9..53fe72df69 100644 Binary files a/packages/protocol/docs/multihop/L2A_to_L3.png and b/packages/protocol/docs/multihop/L2A_to_L3.png differ diff --git a/packages/protocol/docs/multihop/L2_to_L1.png b/packages/protocol/docs/multihop/L2_to_L1.png index 3e8a8c6c0e..50e07b96cc 100644 Binary files a/packages/protocol/docs/multihop/L2_to_L1.png and b/packages/protocol/docs/multihop/L2_to_L1.png differ diff --git a/packages/protocol/docs/multihop/L2_to_L2.png b/packages/protocol/docs/multihop/L2_to_L2.png index f204ec135f..b77cd790bf 100644 Binary files a/packages/protocol/docs/multihop/L2_to_L2.png and b/packages/protocol/docs/multihop/L2_to_L2.png differ diff --git a/packages/protocol/docs/multihop_bridging_deployment.md b/packages/protocol/docs/multihop_bridging_deployment.md index be2832d8cf..71f2014c69 100644 --- a/packages/protocol/docs/multihop_bridging_deployment.md +++ b/packages/protocol/docs/multihop_bridging_deployment.md @@ -6,7 +6,7 @@ First of all, we need to ensures some contracts are shared by multiple Taiko dep ## Shared contracts -On L2 or any laer, then following contracts shall be deployed as sigletonsshared by multiple TaikoL1 deployments. +On L2 or any layer, then following contracts shall be deployed as sigletons shared by multiple TaikoL1 deployments. - SignalService - Bridge @@ -24,18 +24,18 @@ These 1-to-1 dependency relations are acheived by AddressResolver with a name-ba SignalService also uses AuthorizableContract to authorize multiple TaikoL1 and TaikoL2 contracts deployed **on each chain** that is part of the path of multi-hop bridging. -For each TaikoL1/TaikoL2 contractswe need to perform: +For each TaikoL1/TaikoL2 contracts, we need to perform the following: ```solidity // 1 is Ethereum's chainID -SignalService(ss).authorize(address(TaikoL1A), 1); -SignalService(ss).authorize(address(TaikoL1B), 1); +SignalService(sharedSignalServiceAddr).authorize(address(TaikoL1A), 1); +SignalService(sharedSignalServiceAddr).authorize(address(TaikoL1B), 1); // 10001 is the L2A's chainId -SignalService(ss).authorize(address(TaikoL2A, 10001); +SignalService(sharedSignalServiceAddr).authorize(address(TaikoL2A), 10001); // 10002 is the L2B's chainId -SignalService(ss).authorize(address(TaikoL2B, 10002); +SignalService(sharedSignalServiceAddr).authorize(address(TaikoL2B), 10002); ... ``` @@ -51,7 +51,7 @@ Bridge depends on a local SignalService .Therefore, we need to registered the se addManager.setAddress(block.chainId, "signal_service", localSignalService); ``` -Bridge also need to know each and every conterparty bridge deployed **on each chain** that is part of the path of multi-hop bridging. +Bridge also need to know each and every conterparty bridge deployed **on each chain** that is part of the multi-hop bridging. ```solidity addManager.setAddress(remoteChainId1, "bridge", remoteBridge1); diff --git a/packages/protocol/test/HelperContracts.sol b/packages/protocol/test/HelperContracts.sol index bb740f347f..f3ad180196 100644 --- a/packages/protocol/test/HelperContracts.sol +++ b/packages/protocol/test/HelperContracts.sol @@ -55,9 +55,9 @@ contract SkipProofCheckSignal is SignalService { contract DummyCrossChainSync is EssentialContract, ICrossChainSync { Snippet private _snippet; - function setSyncedData(bytes32 blockHash, bytes32 signalRoot) external { + function setSyncedData(bytes32 blockHash, bytes32 stateRoot) external { _snippet.blockHash = blockHash; - _snippet.signalRoot = signalRoot; + _snippet.stateRoot = stateRoot; } function getSyncedSnippet(uint64) external view returns (Snippet memory) { diff --git a/packages/protocol/test/L1/TaikoL1.t.sol b/packages/protocol/test/L1/TaikoL1.t.sol index 4c2c659c8e..86ade3ceea 100644 --- a/packages/protocol/test/L1/TaikoL1.t.sol +++ b/packages/protocol/test/L1/TaikoL1.t.sol @@ -52,8 +52,8 @@ contract TaikoL1Test is TaikoL1TestBase { mine(1); bytes32 blockHash = bytes32(1e10 + blockId); - bytes32 signalRoot = bytes32(1e9 + blockId); - proveBlock(Bob, Bob, meta, parentHash, blockHash, signalRoot, meta.minTier, ""); + bytes32 stateRoot = bytes32(1e9 + blockId); + proveBlock(Bob, Bob, meta, parentHash, blockHash, stateRoot, meta.minTier, ""); vm.roll(block.number + 15 * 12); uint16 minTier = meta.minTier; @@ -84,9 +84,9 @@ contract TaikoL1Test is TaikoL1TestBase { printVariables("after propose"); bytes32 blockHash = bytes32(1e10 + blockId); - bytes32 signalRoot = bytes32(1e9 + blockId); + bytes32 stateRoot = bytes32(1e9 + blockId); - proveBlock(Bob, Bob, meta, parentHash, blockHash, signalRoot, meta.minTier, ""); + proveBlock(Bob, Bob, meta, parentHash, blockHash, stateRoot, meta.minTier, ""); vm.roll(block.number + 15 * 12); uint16 minTier = meta.minTier; vm.warp(block.timestamp + L1.getTier(minTier).cooldownWindow + 1); @@ -115,9 +115,9 @@ contract TaikoL1Test is TaikoL1TestBase { printVariables("after propose"); bytes32 blockHash = bytes32(1e10 + blockId); - bytes32 signalRoot = bytes32(1e9 + blockId); + bytes32 stateRoot = bytes32(1e9 + blockId); - proveBlock(Bob, Bob, meta, parentHash, blockHash, signalRoot, meta.minTier, ""); + proveBlock(Bob, Bob, meta, parentHash, blockHash, stateRoot, meta.minTier, ""); parentHash = blockHash; } @@ -207,7 +207,7 @@ contract TaikoL1Test is TaikoL1TestBase { // Declare here so that block prop/prove/verif. can be used in 1 place TaikoData.BlockMetadata memory meta; bytes32 blockHash; - bytes32 signalRoot; + bytes32 stateRoot; bytes32[] memory parentHashes = new bytes32[](count); parentHashes[0] = GENESIS_BLOCK_HASH; @@ -223,10 +223,10 @@ contract TaikoL1Test is TaikoL1TestBase { mine(5); blockHash = bytes32(1e10 + uint256(blockId)); - signalRoot = bytes32(1e9 + uint256(blockId)); + stateRoot = bytes32(1e9 + uint256(blockId)); proveBlock( - Bob, Bob, meta, parentHashes[blockId - 1], blockHash, signalRoot, meta.minTier, "" + Bob, Bob, meta, parentHashes[blockId - 1], blockHash, stateRoot, meta.minTier, "" ); vm.roll(block.number + 15 * 12); @@ -245,12 +245,12 @@ contract TaikoL1Test is TaikoL1TestBase { uint64 queriedBlockId = 1; bytes32 expectedSR = bytes32(1e9 + uint256(queriedBlockId)); - assertEq(expectedSR, L1.getSyncedSnippet(queriedBlockId).signalRoot); + assertEq(expectedSR, L1.getSyncedSnippet(queriedBlockId).stateRoot); // 2nd queriedBlockId = 2; expectedSR = bytes32(1e9 + uint256(queriedBlockId)); - assertEq(expectedSR, L1.getSyncedSnippet(queriedBlockId).signalRoot); + assertEq(expectedSR, L1.getSyncedSnippet(queriedBlockId).stateRoot); // Not found -> reverts vm.expectRevert(TaikoErrors.L1_BLOCK_MISMATCH.selector); diff --git a/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol b/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol index 92940f9c22..a1d35e73d6 100644 --- a/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol +++ b/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol @@ -30,7 +30,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { function proveHigherTierProof( TaikoData.BlockMetadata memory meta, bytes32 parentHash, - bytes32 signalRoot, + bytes32 stateRoot, bytes32 blockHash, uint16 minTier ) @@ -44,7 +44,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { } else if (minTier == LibTiers.TIER_SGX_AND_PSE_ZKEVM) { tierToProveWith = LibTiers.TIER_GUARDIAN; } - proveBlock(Carol, Carol, meta, parentHash, blockHash, signalRoot, tierToProveWith, ""); + proveBlock(Carol, Carol, meta, parentHash, blockHash, stateRoot, tierToProveWith, ""); } function test_L1_ContestingWithSameProof() external { @@ -68,10 +68,10 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { mine(1); bytes32 blockHash = bytes32(1e10 + blockId); - bytes32 signalRoot = bytes32(1e9 + blockId); + bytes32 stateRoot = bytes32(1e9 + blockId); // This proof cannot be verified obviously because of // blockhash:blockId - proveBlock(Bob, Bob, meta, parentHash, blockHash, signalRoot, meta.minTier, ""); + proveBlock(Bob, Bob, meta, parentHash, blockHash, stateRoot, meta.minTier, ""); // Try to contest - but should revert with L1_ALREADY_PROVED proveBlock( @@ -80,7 +80,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { meta, parentHash, blockHash, - signalRoot, + stateRoot, meta.minTier, TaikoErrors.L1_ALREADY_PROVED.selector ); @@ -118,15 +118,15 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { mine(1); bytes32 blockHash = bytes32(1e10 + blockId); - bytes32 signalRoot = bytes32(1e9 + blockId); + bytes32 stateRoot = bytes32(1e9 + blockId); // This proof cannot be verified obviously because of - // signalRoot instead of blockHash + // stateRoot instead of blockHash uint16 minTier = meta.minTier; - proveBlock(Bob, Bob, meta, parentHash, signalRoot, signalRoot, minTier, ""); + proveBlock(Bob, Bob, meta, parentHash, stateRoot, stateRoot, minTier, ""); // Try to contest - proveBlock(Carol, Carol, meta, parentHash, blockHash, signalRoot, minTier, ""); + proveBlock(Carol, Carol, meta, parentHash, blockHash, stateRoot, minTier, ""); vm.roll(block.number + 15 * 12); @@ -135,7 +135,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { // Cannot verify block because it is contested.. verifyBlock(Carol, 1); - proveHigherTierProof(meta, parentHash, signalRoot, blockHash, minTier); + proveHigherTierProof(meta, parentHash, stateRoot, blockHash, minTier); vm.warp(block.timestamp + L1.getTier(LibTiers.TIER_GUARDIAN).cooldownWindow + 1); // Now can verify @@ -168,14 +168,14 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { mine(1); bytes32 blockHash = bytes32(1e10 + blockId); - bytes32 signalRoot = bytes32(1e9 + blockId); + bytes32 stateRoot = bytes32(1e9 + blockId); // This proof cannot be verified obviously because of - // signalRoot instead of blockHash + // stateRoot instead of blockHash uint16 minTier = meta.minTier; - proveBlock(Bob, Bob, meta, parentHash, signalRoot, signalRoot, minTier, ""); + proveBlock(Bob, Bob, meta, parentHash, stateRoot, stateRoot, minTier, ""); // Try to contest - proveBlock(Carol, Carol, meta, parentHash, blockHash, signalRoot, minTier, ""); + proveBlock(Carol, Carol, meta, parentHash, blockHash, stateRoot, minTier, ""); vm.roll(block.number + 15 * 12); @@ -184,7 +184,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { // Cannot verify block because it is contested.. verifyBlock(Carol, 1); - proveHigherTierProof(meta, parentHash, signalRoot, blockHash, minTier); + proveHigherTierProof(meta, parentHash, stateRoot, blockHash, minTier); // Otherwise just not contest vm.warp(block.timestamp + L1.getTier(LibTiers.TIER_GUARDIAN).cooldownWindow + 1); @@ -217,16 +217,16 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { mine(1); bytes32 blockHash = bytes32(1e10 + blockId); - bytes32 signalRoot = bytes32(1e9 + blockId); + bytes32 stateRoot = bytes32(1e9 + blockId); // This proof cannot be verified obviously because of - // signalRoot instead of blockHash + // stateRoot instead of blockHash uint16 minTier = meta.minTier; - proveBlock(Bob, Bob, meta, parentHash, blockHash, signalRoot, minTier, ""); + proveBlock(Bob, Bob, meta, parentHash, blockHash, stateRoot, minTier, ""); if (minTier == LibTiers.TIER_OPTIMISTIC) { // Try to contest - proveBlock(Carol, Carol, meta, parentHash, signalRoot, signalRoot, minTier, ""); + proveBlock(Carol, Carol, meta, parentHash, stateRoot, stateRoot, minTier, ""); vm.roll(block.number + 15 * 12); @@ -241,7 +241,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { meta, parentHash, blockHash, - signalRoot, + stateRoot, LibTiers.TIER_SGX_AND_PSE_ZKEVM, "" ); @@ -278,15 +278,15 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { mine(1); bytes32 blockHash = bytes32(1e10 + blockId); - bytes32 signalRoot = bytes32(1e9 + blockId); + bytes32 stateRoot = bytes32(1e9 + blockId); // This proof cannot be verified obviously because of - // signalRoot instead of blockHash + // stateRoot instead of blockHash uint16 minTier = meta.minTier; - proveBlock(Bob, Bob, meta, parentHash, signalRoot, signalRoot, minTier, ""); + proveBlock(Bob, Bob, meta, parentHash, stateRoot, stateRoot, minTier, ""); if (minTier == LibTiers.TIER_OPTIMISTIC) { // Try to contest - proveBlock(Carol, Carol, meta, parentHash, blockHash, signalRoot, minTier, ""); + proveBlock(Carol, Carol, meta, parentHash, blockHash, stateRoot, minTier, ""); vm.roll(block.number + 15 * 12); @@ -301,7 +301,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { meta, parentHash, 0, - signalRoot, + stateRoot, LibTiers.TIER_SGX_AND_PSE_ZKEVM, TaikoErrors.L1_INVALID_TRANSITION.selector ); @@ -338,14 +338,14 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { mine(1); bytes32 blockHash = bytes32(1e10 + blockId); - bytes32 signalRoot = bytes32(1e9 + blockId); + bytes32 stateRoot = bytes32(1e9 + blockId); proveBlock( Carol, Carol, meta, parentHash, blockHash, - signalRoot, + stateRoot, meta.minTier, TaikoErrors.L1_NOT_ASSIGNED_PROVER.selector ); @@ -381,7 +381,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { mine(1); bytes32 blockHash = bytes32(1e10 + blockId); - bytes32 signalRoot = bytes32(1e9 + blockId); + bytes32 stateRoot = bytes32(1e9 + blockId); vm.roll(block.number + 15 * 12); @@ -394,7 +394,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { meta, parentHash, blockHash, - signalRoot, + stateRoot, meta.minTier, TaikoErrors.L1_ASSIGNED_PROVER_NOT_ALLOWED.selector ); @@ -426,13 +426,13 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { mine(1); bytes32 blockHash = bytes32(1e10 + blockId); - bytes32 signalRoot = bytes32(1e9 + blockId); + bytes32 stateRoot = bytes32(1e9 + blockId); // This proof cannot be verified obviously because of // blockhash:blockId (, TaikoData.SlotB memory b) = L1.getStateVariables(); uint64 lastVerifiedBlockBefore = b.lastVerifiedBlockId; - proveBlock(Bob, Bob, meta, parentHash, blockHash, signalRoot, meta.minTier, ""); + proveBlock(Bob, Bob, meta, parentHash, blockHash, stateRoot, meta.minTier, ""); console2.log("mintTier is:", meta.minTier); // Try to contest proveBlock( @@ -461,7 +461,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { // Guardian can prove with the original (good) hashes. proveBlock( - Carol, Carol, meta, parentHash, blockHash, signalRoot, LibTiers.TIER_GUARDIAN, "" + Carol, Carol, meta, parentHash, blockHash, stateRoot, LibTiers.TIER_GUARDIAN, "" ); vm.roll(block.number + 15 * 12); @@ -494,10 +494,10 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { mine(1); bytes32 blockHash = bytes32(1e10 + blockId); - bytes32 signalRoot = bytes32(1e9 + blockId); + bytes32 stateRoot = bytes32(1e9 + blockId); // This proof cannot be verified obviously because of // blockhash:blockId - proveBlock(Bob, Bob, meta, parentHash, blockHash, signalRoot, meta.minTier, ""); + proveBlock(Bob, Bob, meta, parentHash, blockHash, stateRoot, meta.minTier, ""); // Try to contest - but should revert with L1_ALREADY_PROVED proveBlock( @@ -506,7 +506,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { meta, parentHash, 0, - signalRoot, + stateRoot, LibTiers.TIER_GUARDIAN, TaikoErrors.L1_INVALID_TRANSITION.selector ); @@ -544,14 +544,14 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { mine(1); bytes32 blockHash = bytes32(1e10 + blockId); - bytes32 signalRoot = bytes32(1e9 + blockId); + bytes32 stateRoot = bytes32(1e9 + blockId); // This proof cannot be verified obviously because of // blockhash:blockId - proveBlock(Bob, Bob, meta, parentHash, signalRoot, signalRoot, meta.minTier, ""); + proveBlock(Bob, Bob, meta, parentHash, stateRoot, stateRoot, meta.minTier, ""); // Prove as guardian proveBlock( - Carol, Carol, meta, parentHash, blockHash, signalRoot, LibTiers.TIER_GUARDIAN, "" + Carol, Carol, meta, parentHash, blockHash, stateRoot, LibTiers.TIER_GUARDIAN, "" ); vm.roll(block.number + 15 * 12); @@ -589,10 +589,10 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { mine(1); bytes32 blockHash = bytes32(1e10 + blockId); - bytes32 signalRoot = bytes32(1e9 + blockId); + bytes32 stateRoot = bytes32(1e9 + blockId); // This proof cannot be verified obviously because of // blockhash:blockId - proveBlock(Bob, Bob, meta, parentHash, signalRoot, signalRoot, meta.minTier, ""); + proveBlock(Bob, Bob, meta, parentHash, stateRoot, stateRoot, meta.minTier, ""); // Prove as guardian but in reality not a guardian proveBlock( @@ -601,7 +601,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { meta, parentHash, blockHash, - signalRoot, + stateRoot, LibTiers.TIER_GUARDIAN, GuardianVerifier.PERMISSION_DENIED.selector ); @@ -641,7 +641,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { mine(1); bytes32 blockHash = bytes32(1e10 + blockId); - bytes32 signalRoot = bytes32(1e9 + blockId); + bytes32 stateRoot = bytes32(1e9 + blockId); meta.id = 100; proveBlock( @@ -650,7 +650,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { meta, parentHash, blockHash, - signalRoot, + stateRoot, LibTiers.TIER_PSE_ZKEVM, TaikoErrors.L1_INVALID_BLOCK_ID.selector ); @@ -683,7 +683,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { mine(1); bytes32 blockHash = bytes32(1e10 + blockId); - bytes32 signalRoot = bytes32(1e9 + blockId); + bytes32 stateRoot = bytes32(1e9 + blockId); // Mess up metahash meta.l1Height = 200; @@ -693,7 +693,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { meta, parentHash, blockHash, - signalRoot, + stateRoot, LibTiers.TIER_PSE_ZKEVM, TaikoErrors.L1_BLOCK_MISMATCH.selector ); @@ -724,14 +724,14 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { mine(1); bytes32 blockHash = bytes32(1e10 + blockId); - bytes32 signalRoot = bytes32(1e9 + blockId); + bytes32 stateRoot = bytes32(1e9 + blockId); // This proof cannot be verified obviously because of blockhash is - // exchanged with signalRoot - proveBlock(Bob, Bob, meta, parentHash, signalRoot, signalRoot, meta.minTier, ""); + // exchanged with stateRoot + proveBlock(Bob, Bob, meta, parentHash, stateRoot, stateRoot, meta.minTier, ""); // Prove as guardian proveBlock( - Carol, Carol, meta, parentHash, blockHash, signalRoot, LibTiers.TIER_GUARDIAN, "" + Carol, Carol, meta, parentHash, blockHash, stateRoot, LibTiers.TIER_GUARDIAN, "" ); // Try to re-prove but reverts @@ -740,8 +740,8 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { Bob, meta, parentHash, - signalRoot, - signalRoot, + stateRoot, + stateRoot, LibTiers.TIER_PSE_ZKEVM, TaikoErrors.L1_INVALID_TIER.selector ); @@ -779,17 +779,17 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { mine(1); bytes32 blockHash = bytes32(1e10 + blockId); - bytes32 signalRoot = bytes32(1e9 + blockId); + bytes32 stateRoot = bytes32(1e9 + blockId); // This proof cannot be verified obviously because of blockhash is - // exchanged with signalRoot - proveBlock(Bob, Bob, meta, parentHash, signalRoot, signalRoot, meta.minTier, ""); + // exchanged with stateRoot + proveBlock(Bob, Bob, meta, parentHash, stateRoot, stateRoot, meta.minTier, ""); // Let's say the 10th block is unprovable so prove accordingly if (blockId == 10) { TaikoData.Transition memory tran = TaikoData.Transition({ parentHash: parentHash, blockHash: blockHash, - signalRoot: signalRoot, + stateRoot: stateRoot, graffiti: 0x0 }); @@ -813,14 +813,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { } else { // Prove as guardian proveBlock( - Carol, - Carol, - meta, - parentHash, - blockHash, - signalRoot, - LibTiers.TIER_GUARDIAN, - "" + Carol, Carol, meta, parentHash, blockHash, stateRoot, LibTiers.TIER_GUARDIAN, "" ); } vm.roll(block.number + 15 * 12); @@ -855,9 +848,9 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { mine(1); bytes32 blockHash = bytes32(uint256(1)); - bytes32 signalRoot = bytes32(uint256(1)); + bytes32 stateRoot = bytes32(uint256(1)); proveBlock( - Bob, Bob, meta, parentHash, blockHash, signalRoot, LibTiers.TIER_SGX_AND_PSE_ZKEVM, "" + Bob, Bob, meta, parentHash, blockHash, stateRoot, LibTiers.TIER_SGX_AND_PSE_ZKEVM, "" ); // Try to contest with a lower tier proof- but should revert with L1_INVALID_TIER @@ -867,7 +860,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { meta, parentHash, blockHash, - signalRoot, + stateRoot, LibTiers.TIER_SGX, TaikoErrors.L1_INVALID_TIER.selector ); diff --git a/packages/protocol/test/L1/TaikoL1TestBase.sol b/packages/protocol/test/L1/TaikoL1TestBase.sol index 7dd97a7b81..6350071286 100644 --- a/packages/protocol/test/L1/TaikoL1TestBase.sol +++ b/packages/protocol/test/L1/TaikoL1TestBase.sol @@ -239,7 +239,7 @@ abstract contract TaikoL1TestBase is TaikoTest { TaikoData.BlockMetadata memory meta, bytes32 parentHash, bytes32 blockHash, - bytes32 signalRoot, + bytes32 stateRoot, uint16 tier, bytes4 revertReason ) @@ -248,7 +248,7 @@ abstract contract TaikoL1TestBase is TaikoTest { TaikoData.Transition memory tran = TaikoData.Transition({ parentHash: parentHash, blockHash: blockHash, - signalRoot: signalRoot, + stateRoot: stateRoot, graffiti: 0x0 }); diff --git a/packages/protocol/test/L2/TaikoL2.t.sol b/packages/protocol/test/L2/TaikoL2.t.sol index 08445f64c8..2392dc1367 100644 --- a/packages/protocol/test/L2/TaikoL2.t.sol +++ b/packages/protocol/test/L2/TaikoL2.t.sol @@ -244,14 +244,14 @@ contract TestTaikoL2 is TaikoTest { function _anchor(uint32 parentGasLimit) private { bytes32 l1Hash = randBytes32(); - bytes32 l1SignalRoot = randBytes32(); - L2.anchor(l1Hash, l1SignalRoot, 12_345, parentGasLimit); + bytes32 l1StateRoot = randBytes32(); + L2.anchor(l1Hash, l1StateRoot, 12_345, parentGasLimit); } function _anchorSimulation(uint32 parentGasLimit, uint64 l1Height) private { bytes32 l1Hash = randBytes32(); - bytes32 l1SignalRoot = randBytes32(); - L2skip.anchor(l1Hash, l1SignalRoot, l1Height, parentGasLimit); + bytes32 l1StateRoot = randBytes32(); + L2skip.anchor(l1Hash, l1StateRoot, l1Height, parentGasLimit); } // Semi-random number generator diff --git a/packages/protocol/test/bridge/Bridge.t.sol b/packages/protocol/test/bridge/Bridge.t.sol index 8c23579f4c..c935866d92 100644 --- a/packages/protocol/test/bridge/Bridge.t.sol +++ b/packages/protocol/test/bridge/Bridge.t.sol @@ -22,7 +22,7 @@ contract UntrustedSendMessageRelayer { contract TwoStepBridge is Bridge { function getInvocationDelays() public - view + pure override returns (uint256 invocationDelay, uint256 invocationExtraDelay) { diff --git a/packages/protocol/test/signal/SignalService.t.sol b/packages/protocol/test/signal/SignalService.t.sol index 2b81f2d08c..3b74007be5 100644 --- a/packages/protocol/test/signal/SignalService.t.sol +++ b/packages/protocol/test/signal/SignalService.t.sol @@ -5,7 +5,7 @@ import "../TaikoTest.sol"; contract TestSignalService is TaikoTest { AddressManager addressManager; - SignalService signalService; + SignalService relayer; SignalService destSignalService; DummyCrossChainSync crossChainSync; uint64 public destChainId = 7; @@ -25,7 +25,7 @@ contract TestSignalService is TaikoTest { }) ); - signalService = SignalService( + relayer = SignalService( deployProxy({ name: "signal_service", impl: address(new SignalService()), @@ -58,122 +58,34 @@ contract TestSignalService is TaikoTest { function test_SignalService_sendSignal_revert() public { vm.expectRevert(SignalService.SS_INVALID_SIGNAL.selector); - signalService.sendSignal(0); + relayer.sendSignal(0); } function test_SignalService_isSignalSent_revert() public { bytes32 signal = bytes32(uint256(1)); vm.expectRevert(SignalService.SS_INVALID_APP.selector); - signalService.isSignalSent(address(0), signal); + relayer.isSignalSent(address(0), signal); signal = bytes32(uint256(0)); vm.expectRevert(SignalService.SS_INVALID_SIGNAL.selector); - signalService.isSignalSent(Alice, signal); + relayer.isSignalSent(Alice, signal); } function test_SignalService_sendSignal_isSignalSent() public { vm.startPrank(Alice); bytes32 signal = bytes32(uint256(1)); - signalService.sendSignal(signal); + relayer.sendSignal(signal); - assertTrue(signalService.isSignalSent(Alice, signal)); + assertTrue(relayer.isSignalSent(Alice, signal)); } function test_SignalService_getSignalSlot() public { vm.startPrank(Alice); for (uint8 i = 1; i < 100; ++i) { bytes32 signal = bytes32(block.prevrandao + i); - signalService.sendSignal(signal); + relayer.sendSignal(signal); - assertTrue(signalService.isSignalSent(Alice, signal)); + assertTrue(relayer.isSignalSent(Alice, signal)); } } - - function test_SignalService_proveSignalReceived_L1_L2() public { - uint64 chainId = 11_155_111; // Created the proofs on a deployed Sepolia - // contract, this is why this chainId. - address app = 0x927a146e18294efb36edCacC99D9aCEA6aB16b95; // Mock app, - // actually it is an EOA, but it is ok for tests! - bytes32 signal = 0x21761f7cd1af3972774272b39a0f4602dbcd418325cddb14e156b4bb073d52a8; - bytes memory inclusionProof = - hex"e5a4e3a1209749684f52b5c0717a7ca78127fb56043d637d81763c04e9d30ba4d4746d56e901"; //eth_getProof's - // result RLP encoded storage proof - bytes32 signalRoot = 0xf7916f389ccda56e3831e115238b7389b30750886785a3c21265601572698f0f; //eth_getProof - // result's storage hash - - vm.startPrank(Alice); - signalService.authorize(address(crossChainSync), bytes32(uint256(block.chainid))); - - crossChainSync.setSyncedData("", signalRoot); - - SignalService.Proof memory p; - SignalService.Hop[] memory h; - p.crossChainSync = address(crossChainSync); - p.height = 10; - p.storageProof = inclusionProof; - p.hops = h; - - bool isSignalReceived = - signalService.proveSignalReceived(chainId, app, signal, abi.encode(p)); - assertEq(isSignalReceived, true); - } - - function test_SignalService_proveSignalReceived_L2_L2() public { - uint64 chainId = 11_155_111; // Created the proofs on a deployed - // Sepolia contract, this is why this chainId. This works as a - // static 'chainId' becuase i imitated 2 contracts (L2A and L1 - // Signal Service contracts) on Sepolia. - address app = 0x927a146e18294efb36edCacC99D9aCEA6aB16b95; // Mock app, - // actually it is an EOA, but it is ok for tests! Same applies here, - // i imitated everything with one 'app' (Bridge) with my same EOA - // wallet. - bytes32 signal_of_L2A_msgHash = - 0x21761f7cd1af3972774272b39a0f4602dbcd418325cddb14e156b4bb073d52a8; - bytes memory inclusionProof_of_L2A_msgHash = - hex"e5a4e3a1209749684f52b5c0717a7ca78127fb56043d637d81763c04e9d30ba4d4746d56e901"; //eth_getProof's - // result RLP encoded storage proof - bytes32 signalRoot_of_L2 = - 0xf7916f389ccda56e3831e115238b7389b30750886785a3c21265601572698f0f; //eth_getProof - // result's storage hash - bytes memory hop_inclusionProof_from_L1_SignalService = - hex"e5a4e3a120bade38703a7b19341b10a4dd482698dc8ffdd861e83ce41de2980bed39b6a02501"; //eth_getProof's - // result RLP encoded storage proof - bytes32 l1_common_signalService_root = - 0x5c5fd43df8bcd7ad44cfcae86ed73a11e0baa9a751f0b520d029358ea284833b; //eth_getProof - // result's storage hash - - // Important to note, we need to have authorized the "relayers' - // addresses" on the source chain we are claiming. - // (TaikoL1 or TaikoL2 depending on where we are) - vm.startPrank(Alice); - signalService.authorize(address(crossChainSync), bytes32(block.chainid)); - signalService.authorize(address(app), bytes32(uint256(chainId))); - - vm.startPrank(Alice); - addressManager.setAddress(chainId, "taiko", app); - - crossChainSync.setSyncedData("", l1_common_signalService_root); - - SignalService.Proof memory p; - p.crossChainSync = address(crossChainSync); - p.height = 10; - p.storageProof = inclusionProof_of_L2A_msgHash; - - // Imagine this scenario: L2A to L2B bridging. - // The 'hop' proof is the one that proves to L2B, that L1 Signal service - // contains the signalRoot (as storage slot / leaf) with value 0x1. - // The 'normal' proof is the one which proves that the resolving - // hop.signalRoot is the one which belongs to L2A, and the proof is - // accordingly. - SignalService.Hop[] memory h = new SignalService.Hop[](1); - h[0].signalRootRelay = app; - h[0].signalRoot = signalRoot_of_L2; - h[0].storageProof = hop_inclusionProof_from_L1_SignalService; - - p.hops = h; - - bool isSignalReceived = - signalService.proveSignalReceived(chainId, app, signal_of_L2A_msgHash, abi.encode(p)); - assertEq(isSignalReceived, true); - } } diff --git a/packages/protocol/test/verifiers/GuardianVerifier.t.sol b/packages/protocol/test/verifiers/GuardianVerifier.t.sol index b216bddb41..043534e38b 100644 --- a/packages/protocol/test/verifiers/GuardianVerifier.t.sol +++ b/packages/protocol/test/verifiers/GuardianVerifier.t.sol @@ -16,7 +16,7 @@ contract TestGuardianVerifier is TaikoL1TestBase { } // Tests `verifyProof()` with the correct prover - function test_verifyProof() public { + function test_verifyProof() public view { // Context IVerifier.Context memory ctx = IVerifier.Context({ metaHash: bytes32(0), @@ -31,7 +31,7 @@ contract TestGuardianVerifier is TaikoL1TestBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32(0), blockHash: bytes32(0), - signalRoot: bytes32(0), + stateRoot: bytes32(0), graffiti: bytes32(0) }); @@ -58,7 +58,7 @@ contract TestGuardianVerifier is TaikoL1TestBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32(0), blockHash: bytes32(0), - signalRoot: bytes32(0), + stateRoot: bytes32(0), graffiti: bytes32(0) }); diff --git a/packages/protocol/test/verifiers/PseZkVerifier.t.sol b/packages/protocol/test/verifiers/PseZkVerifier.t.sol index 51e658fd37..9225394fd8 100644 --- a/packages/protocol/test/verifiers/PseZkVerifier.t.sol +++ b/packages/protocol/test/verifiers/PseZkVerifier.t.sol @@ -34,7 +34,7 @@ contract TestPseZkVerifier is TaikoL1TestBase { } // Test `verifyProof()` when contesting - function test_verifyProof_isContesting() external { + function test_verifyProof_isContesting() external view { // Context IVerifier.Context memory ctx = IVerifier.Context({ metaHash: bytes32("ab"), @@ -49,7 +49,7 @@ contract TestPseZkVerifier is TaikoL1TestBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32(0), blockHash: bytes32(0), - signalRoot: bytes32(0), + stateRoot: bytes32(0), graffiti: bytes32(0) }); @@ -76,7 +76,7 @@ contract TestPseZkVerifier is TaikoL1TestBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32(0), blockHash: bytes32(0), - signalRoot: bytes32(0), + stateRoot: bytes32(0), graffiti: bytes32(0) }); @@ -112,7 +112,7 @@ contract TestPseZkVerifier is TaikoL1TestBase { } // Test `verifyProof()` without blob, happy path - function test_verifyProof() external { + function test_verifyProof() external view { // Context IVerifier.Context memory ctx = IVerifier.Context({ metaHash: bytes32("ab"), @@ -127,7 +127,7 @@ contract TestPseZkVerifier is TaikoL1TestBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32("12"), blockHash: bytes32("23"), - signalRoot: bytes32("34"), + stateRoot: bytes32("34"), graffiti: bytes32("1234") }); @@ -164,7 +164,7 @@ contract TestPseZkVerifier is TaikoL1TestBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32("12"), blockHash: bytes32("23"), - signalRoot: bytes32("34"), + stateRoot: bytes32("34"), graffiti: bytes32("1234") }); @@ -193,7 +193,7 @@ contract TestPseZkVerifier is TaikoL1TestBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32("12"), blockHash: bytes32("23"), - signalRoot: bytes32("34"), + stateRoot: bytes32("34"), graffiti: bytes32("1234") }); @@ -231,7 +231,7 @@ contract TestPseZkVerifier is TaikoL1TestBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32("12"), blockHash: bytes32("23"), - signalRoot: bytes32("34"), + stateRoot: bytes32("34"), graffiti: bytes32("1234") }); @@ -268,7 +268,7 @@ contract TestPseZkVerifier is TaikoL1TestBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32("12"), blockHash: bytes32("23"), - signalRoot: bytes32("34"), + stateRoot: bytes32("34"), graffiti: bytes32("1234") }); @@ -302,7 +302,7 @@ contract TestPseZkVerifier is TaikoL1TestBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32("12"), blockHash: bytes32("23"), - signalRoot: bytes32("34"), + stateRoot: bytes32("34"), graffiti: bytes32("1234") }); @@ -343,7 +343,7 @@ contract TestPseZkVerifier is TaikoL1TestBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32("12"), blockHash: bytes32("23"), - signalRoot: bytes32("34"), + stateRoot: bytes32("34"), graffiti: bytes32("1234") }); @@ -384,7 +384,7 @@ contract TestPseZkVerifier is TaikoL1TestBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32("12"), blockHash: bytes32("23"), - signalRoot: bytes32("34"), + stateRoot: bytes32("34"), graffiti: bytes32("1234") }); @@ -422,7 +422,7 @@ contract TestPseZkVerifier is TaikoL1TestBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32("12"), blockHash: bytes32("23"), - signalRoot: bytes32("34"), + stateRoot: bytes32("34"), graffiti: bytes32("1234") }); diff --git a/packages/protocol/test/verifiers/SgxVerifier.t.sol b/packages/protocol/test/verifiers/SgxVerifier.t.sol index c8e483d09c..8382a3f320 100644 --- a/packages/protocol/test/verifiers/SgxVerifier.t.sol +++ b/packages/protocol/test/verifiers/SgxVerifier.t.sol @@ -194,7 +194,7 @@ contract TestSgxVerifier is TaikoL1TestBase, AttestationBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32("12"), blockHash: bytes32("34"), - signalRoot: bytes32("56"), + stateRoot: bytes32("56"), graffiti: bytes32("78") }); @@ -242,7 +242,7 @@ contract TestSgxVerifier is TaikoL1TestBase, AttestationBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32("12"), blockHash: bytes32("34"), - signalRoot: bytes32("56"), + stateRoot: bytes32("56"), graffiti: bytes32("78") }); @@ -273,7 +273,7 @@ contract TestSgxVerifier is TaikoL1TestBase, AttestationBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32("12"), blockHash: bytes32("34"), - signalRoot: bytes32("56"), + stateRoot: bytes32("56"), graffiti: bytes32("78") }); @@ -306,7 +306,7 @@ contract TestSgxVerifier is TaikoL1TestBase, AttestationBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32("12"), blockHash: bytes32("34"), - signalRoot: bytes32("56"), + stateRoot: bytes32("56"), graffiti: bytes32("78") }); @@ -344,7 +344,7 @@ contract TestSgxVerifier is TaikoL1TestBase, AttestationBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32("12"), blockHash: bytes32("34"), - signalRoot: bytes32("56"), + stateRoot: bytes32("56"), graffiti: bytes32("78") }); @@ -383,7 +383,7 @@ contract TestSgxVerifier is TaikoL1TestBase, AttestationBase { TaikoData.Transition memory transition = TaikoData.Transition({ parentHash: bytes32("12"), blockHash: bytes32("34"), - signalRoot: bytes32("56"), + stateRoot: bytes32("56"), graffiti: bytes32("78") });