diff --git a/packages/protocol/contracts/layer1/based/LibProving.sol b/packages/protocol/contracts/layer1/based/LibProving.sol index 753fa6f097b..0c96335ec8d 100644 --- a/packages/protocol/contracts/layer1/based/LibProving.sol +++ b/packages/protocol/contracts/layer1/based/LibProving.sol @@ -588,8 +588,9 @@ library LibProving { // The contested transition is proven to be invalid, contester wins the game. // Contester gets 3/4 of reward, the new prover gets 1/4. reward = _rewardAfterFriction(_ts.validityBond) >> 2; - - LibBonds.creditBond(_state, _ts.contester, _ts.contestBond + reward * 3); + unchecked { + LibBonds.creditBond(_state, _ts.contester, _ts.contestBond + reward * 3); + } } } else { if (_local.sameTransition) revert L1_ALREADY_PROVED(); @@ -607,10 +608,17 @@ library LibProving { if (_returnLivenessBond(_local, _proof.data)) { if (_local.assignedProver == msg.sender) { - reward += _local.livenessBond; + unchecked { + reward += _local.livenessBond; + } } else { LibBonds.creditBond(_state, _local.assignedProver, _local.livenessBond); } + } else { + // Reward a majority of liveness bond to the actual prover + unchecked { + reward += _rewardAfterFriction(_local.livenessBond); + } } } } diff --git a/packages/protocol/test/layer1/based/TaikoL1TestGroup1.t.sol b/packages/protocol/test/layer1/based/TaikoL1TestGroup1.t.sol index 7192f3b8e6c..93aff49bbe5 100644 --- a/packages/protocol/test/layer1/based/TaikoL1TestGroup1.t.sol +++ b/packages/protocol/test/layer1/based/TaikoL1TestGroup1.t.sol @@ -116,7 +116,6 @@ contract TaikoL1TestGroup1 is TaikoL1TestGroupBase { printBlockAndTrans(0); giveEthAndTko(Alice, 10_000 ether, 1000 ether); - giveEthAndTko(Taylor, 10_000 ether, 1000 ether); ITierProvider.Tier memory tierOp = TestTierProvider(cp).getTier(LibTiers.TIER_OPTIMISTIC); @@ -171,7 +170,10 @@ contract TaikoL1TestGroup1 is TaikoL1TestGroupBase { provenAt = ts.timestamp; - assertEq(totalTkoBalance(tko, L1, Taylor), 10_000 ether - tierOp.validityBond); + assertEq( + totalTkoBalance(tko, L1, Taylor), + 10_000 ether - tierOp.validityBond + livenessBond * 7 / 8 + ); } console2.log("====== Verify block"); @@ -196,7 +198,7 @@ contract TaikoL1TestGroup1 is TaikoL1TestGroupBase { assertEq(ts.timestamp, provenAt); assertEq(totalTkoBalance(tko, L1, Alice), 10_000 ether - livenessBond); - assertEq(totalTkoBalance(tko, L1, Taylor), 10_000 ether); + assertEq(totalTkoBalance(tko, L1, Taylor), 10_000 ether + livenessBond * 7 / 8); } } @@ -351,17 +353,16 @@ contract TaikoL1TestGroup1 is TaikoL1TestGroupBase { assertEq(totalTkoBalance(tko, L1, Alice), 10_000 ether - L1.getConfig().livenessBond); } } + // Test summary: // 1. Alice proposes a block, // 2. Alice proves the block outside the proving window, using the correct parent hash. // 3. Alice's proof is used to verify the block. - function test_taikoL1_group_1_case_6() external { vm.warp(1_000_000); printBlockAndTrans(0); giveEthAndTko(Alice, 10_000 ether, 1000 ether); - giveEthAndTko(Taylor, 10_000 ether, 1000 ether); ITierProvider.Tier memory tierOp = TestTierProvider(cp).getTier(LibTiers.TIER_OPTIMISTIC); @@ -417,7 +418,8 @@ contract TaikoL1TestGroup1 is TaikoL1TestGroupBase { provenAt = ts.timestamp; assertEq( - totalTkoBalance(tko, L1, Alice), 10_000 ether - tierOp.validityBond - livenessBond + totalTkoBalance(tko, L1, Alice), + 10_000 ether - tierOp.validityBond - livenessBond / 8 ); } @@ -442,7 +444,7 @@ contract TaikoL1TestGroup1 is TaikoL1TestGroupBase { assertEq(ts.validityBond, tierOp.validityBond); assertEq(ts.timestamp, provenAt); - assertEq(totalTkoBalance(tko, L1, Alice), 10_000 ether - livenessBond); + assertEq(totalTkoBalance(tko, L1, Alice), 10_000 ether - livenessBond / 8); } } diff --git a/packages/protocol/test/layer1/based/TaikoL1TestGroup3.t.sol b/packages/protocol/test/layer1/based/TaikoL1TestGroup3.t.sol index b27ffda2c9e..000fefb99ea 100644 --- a/packages/protocol/test/layer1/based/TaikoL1TestGroup3.t.sol +++ b/packages/protocol/test/layer1/based/TaikoL1TestGroup3.t.sol @@ -59,7 +59,10 @@ contract TaikoL1TestGroup3 is TaikoL1TestGroupBase { assertEq(ts.timestamp, block.timestamp); assertEq(totalTkoBalance(tko, L1, Alice), 10_000 ether - livenessBond); - assertEq(totalTkoBalance(tko, L1, James), 10_000 ether - tierOp.validityBond); + assertEq( + totalTkoBalance(tko, L1, James), + 10_000 ether - tierOp.validityBond + livenessBond * 7 / 8 + ); assertEq(totalTkoBalance(tko, L1, Taylor), 10_000 ether - tierOp.contestBond); } @@ -169,7 +172,10 @@ contract TaikoL1TestGroup3 is TaikoL1TestGroupBase { assertEq(ts.timestamp, block.timestamp); assertEq(totalTkoBalance(tko, L1, Alice), 10_000 ether - livenessBond); - assertEq(totalTkoBalance(tko, L1, James), 10_000 ether - tierOp.validityBond); + assertEq( + totalTkoBalance(tko, L1, James), + 10_000 ether - tierOp.validityBond + livenessBond * 7 / 8 + ); assertEq(totalTkoBalance(tko, L1, Taylor), 10_000 ether - tierOp.contestBond); } @@ -195,7 +201,10 @@ contract TaikoL1TestGroup3 is TaikoL1TestGroupBase { assertEq(ts.timestamp, block.timestamp); assertEq(totalTkoBalance(tko, L1, Alice), 10_000 ether - livenessBond); - assertEq(totalTkoBalance(tko, L1, James), 10_000 ether - tierOp.validityBond); + assertEq( + totalTkoBalance(tko, L1, James), + 10_000 ether - tierOp.validityBond + livenessBond * 7 / 8 + ); uint256 quarterReward = tierOp.validityBond * 7 / 8 / 4; assertEq(totalTkoBalance(tko, L1, Taylor), 10_000 ether + quarterReward * 3); @@ -227,7 +236,10 @@ contract TaikoL1TestGroup3 is TaikoL1TestGroupBase { assertEq(totalTkoBalance(tko, L1, Alice), 10_000 ether - livenessBond); uint256 quarterReward = tierOp.validityBond * 7 / 8 / 4; - assertEq(totalTkoBalance(tko, L1, James), 10_000 ether - tierOp.validityBond); + assertEq( + totalTkoBalance(tko, L1, James), + 10_000 ether - tierOp.validityBond + livenessBond * 7 / 8 + ); assertEq(totalTkoBalance(tko, L1, Taylor), 10_000 ether + quarterReward * 3); assertEq(totalTkoBalance(tko, L1, William), 10_000 ether + quarterReward); } diff --git a/packages/protocol/test/layer1/based/TaikoL1TestGroup4.t.sol b/packages/protocol/test/layer1/based/TaikoL1TestGroup4.t.sol index c5850ebf3bc..01b503f5cd6 100644 --- a/packages/protocol/test/layer1/based/TaikoL1TestGroup4.t.sol +++ b/packages/protocol/test/layer1/based/TaikoL1TestGroup4.t.sol @@ -135,7 +135,9 @@ contract TaikoL1TestGroup4 is TaikoL1TestGroupBase { assertEq(ts.timestamp, block.timestamp); assertEq(totalTkoBalance(tko, L1, Alice), 10_000 ether - livenessBond); - assertEq(tko.balanceOf(David), 10_000 ether - tierOp.validityBond); + assertEq( + tko.balanceOf(David), 10_000 ether - tierOp.validityBond + livenessBond * 7 / 8 + ); assertEq( tko.balanceOf(Taylor), 10_000 ether - tierSgx.validityBond + tierOp.validityBond * 7 / 8 diff --git a/packages/protocol/test/layer1/based/TaikoL1TestGroup5.t.sol b/packages/protocol/test/layer1/based/TaikoL1TestGroup5.t.sol index d6d1a294b2f..ac7d7fc0efe 100644 --- a/packages/protocol/test/layer1/based/TaikoL1TestGroup5.t.sol +++ b/packages/protocol/test/layer1/based/TaikoL1TestGroup5.t.sol @@ -274,7 +274,9 @@ contract TaikoL1TestGroup5 is TaikoL1TestGroupBase { assertEq(ts.timestamp, block.timestamp); assertEq(totalTkoBalance(tko, L1, Alice), 10_000 ether - livenessBond); - assertEq(tko.balanceOf(David), 10_000 ether - tierOp.validityBond); + assertEq( + tko.balanceOf(David), 10_000 ether - tierOp.validityBond + livenessBond * 7 / 8 + ); assertEq(totalTkoBalance(tko, L1, William), 10_000 ether); } @@ -297,7 +299,9 @@ contract TaikoL1TestGroup5 is TaikoL1TestGroupBase { assertEq(ts.prover, address(gp)); assertEq(totalTkoBalance(tko, L1, Alice), 10_000 ether - livenessBond); - assertEq(tko.balanceOf(David), 10_000 ether - tierOp.validityBond); + assertEq( + tko.balanceOf(David), 10_000 ether - tierOp.validityBond + livenessBond * 7 / 8 + ); assertEq(totalTkoBalance(tko, L1, William), 10_000 ether); } } diff --git a/packages/protocol/test/layer1/based/TaikoL1TestGroup9.t.sol b/packages/protocol/test/layer1/based/TaikoL1TestGroup9.t.sol index e1aa9e67bf8..563512ef66b 100644 --- a/packages/protocol/test/layer1/based/TaikoL1TestGroup9.t.sol +++ b/packages/protocol/test/layer1/based/TaikoL1TestGroup9.t.sol @@ -301,7 +301,10 @@ contract TaikoL1TestGroup5 is TaikoL1TestGroupBase { assertEq(ts.timestamp, block.timestamp); assertEq(totalTkoBalance(tko, L1, Alice), 10_000 ether - livenessBond); - assertEq(totalTkoBalance(tko, L1, Carol), 10_000 ether - tierOp.validityBond); + assertEq( + totalTkoBalance(tko, L1, Carol), + 10_000 ether - tierOp.validityBond + livenessBond * 7 / 8 + ); assertEq(totalTkoBalance(tko, L1, William), 10_000 ether); } @@ -325,7 +328,10 @@ contract TaikoL1TestGroup5 is TaikoL1TestGroupBase { assertEq(ts.prover, address(gp)); assertEq(totalTkoBalance(tko, L1, Alice), 10_000 ether - livenessBond); - assertEq(totalTkoBalance(tko, L1, Carol), 10_000 ether - tierOp.validityBond); + assertEq( + totalTkoBalance(tko, L1, Carol), + 10_000 ether - tierOp.validityBond + livenessBond * 7 / 8 + ); assertEq(totalTkoBalance(tko, L1, William), 10_000 ether); } }