Skip to content

Commit

Permalink
feat(protocol): force nonzero blockhash and signalroot (#15538)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik authored Jan 20, 2024
1 parent ff8690e commit bc0ca8d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 13 deletions.
15 changes: 3 additions & 12 deletions packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
//
Expand Down
51 changes: 50 additions & 1 deletion packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -825,4 +834,44 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase {
}
printVariables("");
}

function test_L1_ContestingWithLowerTierProofReverts() 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("");
}
}

0 comments on commit bc0ca8d

Please sign in to comment.