Skip to content

Commit

Permalink
fix(protocol): reward non-assigned prover 7/8 liveness bond (#18132)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik authored Sep 18, 2024
1 parent 10c2972 commit 9f99099
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 19 deletions.
14 changes: 11 additions & 3 deletions packages/protocol/contracts/layer1/based/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions packages/protocol/test/layer1/based/TaikoL1TestGroup1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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");
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
);
}

Expand All @@ -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);
}
}

Expand Down
20 changes: 16 additions & 4 deletions packages/protocol/test/layer1/based/TaikoL1TestGroup3.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/protocol/test/layer1/based/TaikoL1TestGroup4.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions packages/protocol/test/layer1/based/TaikoL1TestGroup5.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}
}
Expand Down
10 changes: 8 additions & 2 deletions packages/protocol/test/layer1/based/TaikoL1TestGroup9.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}
}
Expand Down

0 comments on commit 9f99099

Please sign in to comment.