From 1c04f71756caeac356aa31b1826d475eb5958087 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Sat, 20 Jan 2024 16:29:27 +0800 Subject: [PATCH 1/3] force nonzero blockhash and signalroot --- .../protocol/contracts/L1/libs/LibProving.sol | 15 +++------------ .../test/L1/TaikoL1LibProvingWithTiers.t.sol | 11 ++++++++++- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/protocol/contracts/L1/libs/LibProving.sol b/packages/protocol/contracts/L1/libs/LibProving.sol index 363543eb29..bdb1a8a6aa 100644 --- a/packages/protocol/contracts/L1/libs/LibProving.sol +++ b/packages/protocol/contracts/L1/libs/LibProving.sol @@ -78,7 +78,9 @@ library LibProving { returns (uint8 maxBlocksToVerify) { // Make sure parentHash is not zero - if (tran.parentHash == 0) revert L1_INVALID_TRANSITION(); + if (tran.parentHash == 0 || tran.blockHash == 0 || tran.signalRoot == 0) { + revert L1_INVALID_TRANSITION(); + } // Check that the block has been proposed but has not yet been verified. TaikoData.SlotB memory b = state.slotB; @@ -227,12 +229,6 @@ library LibProving { // It means prover is right (not the contester) bool sameTransition = tran.blockHash == ts.blockHash && tran.signalRoot == ts.signalRoot; - // We should outright prohibit the use of zero values for both - // blockHash and signalRoot since, when we initialize a new - // transition, we set both blockHash and signalRoot to 0. - if (tran.blockHash == 0 || tran.signalRoot == 0) { - revert L1_INVALID_TRANSITION(); - } // A special return value from the top tier prover can signal this // contract to return all liveness bond. @@ -317,11 +313,6 @@ library LibProving { // proving mode. This works even if this transition's contester is // address zero, see more info below. - // zero values are not allowed - if (tran.blockHash == 0 || tran.signalRoot == 0) { - revert L1_INVALID_TRANSITION(); - } - // The ability to prove a transition is granted under the following // two circumstances: // diff --git a/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol b/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol index 1bdd01613b..9d8a8e8f8d 100644 --- a/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol +++ b/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol @@ -435,7 +435,16 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { proveBlock(Bob, Bob, meta, parentHash, blockHash, signalRoot, meta.minTier, ""); console2.log("mintTier is:", meta.minTier); // Try to contest - proveBlock(Carol, Carol, meta, parentHash, 0, 0, meta.minTier, ""); + proveBlock( + Carol, + Carol, + meta, + parentHash, + bytes32(uint256(1)), + bytes32(uint256(1)), + meta.minTier, + "" + ); vm.roll(block.number + 15 * 12); uint16 minTier = meta.minTier; From 836e1528a5eb8512eff8b7c55b306e1b163da282 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Sat, 20 Jan 2024 16:43:28 +0800 Subject: [PATCH 2/3] Update TaikoL1LibProvingWithTiers.t.sol --- .../test/L1/TaikoL1LibProvingWithTiers.t.sol | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol b/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol index 9d8a8e8f8d..72d4feeb85 100644 --- a/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol +++ b/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol @@ -834,4 +834,44 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { } printVariables(""); } + + function test_L1_ContestingWithLowerTierProofRevertspn() external { + giveEthAndTko(Alice, 1e7 ether, 1000 ether); + giveEthAndTko(Carol, 1e7 ether, 1000 ether); + console2.log("Alice balance:", tko.balanceOf(Alice)); + // This is a very weird test (code?) issue here. + // If this line is uncommented, + // Alice/Bob has no balance.. (Causing reverts !!!) + // Current investigations are ongoing with foundry team + giveEthAndTko(Bob, 1e6 ether, 100 ether); + console2.log("Bob balance:", tko.balanceOf(Bob)); + // Bob + vm.prank(Bob, Bob); + + bytes32 parentHash = GENESIS_BLOCK_HASH; + printVariables("before propose"); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); + //printVariables("after propose"); + mine(1); + + bytes32 blockHash = bytes32(uint256(1)); + bytes32 signalRoot = bytes32(uint256(1)); + proveBlock( + Bob, Bob, meta, parentHash, blockHash, signalRoot, LibTiers.TIER_SGX_AND_PSE_ZKEVM, "" + ); + + // Try to contest with a lower tier proof- but should revert with L1_INVALID_TIER + proveBlock( + Carol, + Carol, + meta, + parentHash, + blockHash, + signalRoot, + LibTiers.TIER_SGX, + TaikoErrors.L1_INVALID_TIER.selector + ); + + printVariables(""); + } } From 39dcbf7fb07411856d6c39b54c3f11d00607a78e Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Sat, 20 Jan 2024 16:45:38 +0800 Subject: [PATCH 3/3] Update TaikoL1LibProvingWithTiers.t.sol --- packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol b/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol index 72d4feeb85..8856aea4a9 100644 --- a/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol +++ b/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol @@ -835,7 +835,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { printVariables(""); } - function test_L1_ContestingWithLowerTierProofRevertspn() external { + function test_L1_ContestingWithLowerTierProofReverts() external { giveEthAndTko(Alice, 1e7 ether, 1000 ether); giveEthAndTko(Carol, 1e7 ether, 1000 ether); console2.log("Alice balance:", tko.balanceOf(Alice));