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 committed Sep 18, 2024
1 parent f514e5a commit 505c42d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 16 deletions.
5 changes: 5 additions & 0 deletions packages/protocol/contracts/layer1/based/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,11 @@ library LibProving {
_state, _local.assignedProver, _local.blockId, _local.meta.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 @@ -119,7 +119,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 @@ -178,7 +177,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 @@ -202,7 +204,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 @@ -354,17 +356,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 @@ -424,7 +425,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 @@ -448,7 +450,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 @@ -58,7 +58,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 @@ -166,7 +169,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 @@ -191,7 +197,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 @@ -223,7 +232,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 @@ -133,7 +133,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 @@ -268,7 +268,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 @@ -290,7 +292,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 @@ -295,7 +295,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 @@ -318,7 +321,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 505c42d

Please sign in to comment.