Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(protocol): fix issue in slash amount calc #14272

Merged
merged 3 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/IProverPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ interface IProverPool {

function releaseProver(address prover) external;

function slashProver(address prover) external;
function slashProver(address prover, uint64 proofReward) external;
}
18 changes: 12 additions & 6 deletions packages/protocol/contracts/L1/ProverPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ contract ProverPool is EssentialContract, IProverPool {
// can support 1 block per second with an average proof time of 1 hour,
// then we need a min capacity of 3600, which means each prover shall
// provide a capacity of at least 3600/32=112.
uint32 public constant MAX_CAPACITY_LOWER_BOUND = 128;
uint32 public constant MIN_CAPACITY = 32;
uint64 public constant EXIT_PERIOD = 1 weeks;
uint64 public constant SLASH_POINTS = 25; // basis points or 0.25%
uint64 public constant SLASH_MULTIPLIER = 4;
uint64 public constant MIN_STAKE_PER_CAPACITY = 10_000;
uint64 public constant MIN_SLASH_AMOUNT = 1e8; // 1 token
uint256 public constant MAX_NUM_PROVERS = 32;
uint256 public constant MIN_CHANGE_DELAY = 1 hours;

Expand Down Expand Up @@ -135,7 +135,13 @@ contract ProverPool is EssentialContract, IProverPool {

/// @dev Slashes a prover.
/// @param addr The address of the prover to slash.
function slashProver(address addr) external onlyFromProtocol {
function slashProver(
address addr,
uint64 proofReward
)
external
onlyFromProtocol
{
(Staker memory staker, Prover memory prover) = getStaker(addr);
unchecked {
// if the exit is mature, we do not count it in the total slash-able
Expand All @@ -148,8 +154,8 @@ contract ProverPool is EssentialContract, IProverPool {
if (slashableAmount == 0) return;

uint64 amountToSlash = uint64(
(slashableAmount * SLASH_POINTS / 10_000).max(MIN_SLASH_AMOUNT)
.min(slashableAmount)
(slashableAmount * SLASH_POINTS / 10_000 / staker.maxCapacity)
.max(SLASH_MULTIPLIER * proofReward).min(slashableAmount)
);

if (amountToSlash <= staker.exitAmount) {
Expand Down Expand Up @@ -303,7 +309,7 @@ contract ProverPool is EssentialContract, IProverPool {
{
// Check parameters
if (
maxCapacity < MAX_CAPACITY_LOWER_BOUND
maxCapacity < MIN_CAPACITY
|| amount / maxCapacity < MIN_STAKE_PER_CAPACITY
|| rewardPerGas == 0
) revert INVALID_PARAMS();
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/TaikoConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ library TaikoConfig {
ethDepositGas: 21_000,
ethDepositMaxFee: 1 ether / 10,
// Group 5: tokenomics
rewardOpenMultipler: 200, // percentage
rewardOpenMultipler: 150, // percentage
rewardOpenMaxCount: 201_600, // blockMaxProposals / 2,
rewardMaxDelayPenalty: 250 // bps
});
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/contracts/L1/libs/LibVerifying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ library LibVerifying {
// proving out side of the proof window, by a prover other
// than the assigned prover
proofReward = proofReward * config.rewardOpenMultipler / 100;
proverPool.slashProver(blk.assignedProver);
proverPool.slashProver(blk.assignedProver, proofReward);
} else if (fc.provenAt <= blk.proposedAt + blk.proofWindow) {
// proving inside the window, by the assigned prover
uint64 proofDelay;
Expand Down Expand Up @@ -253,8 +253,8 @@ library LibVerifying {
);
} else {
// proving out side of the proof window, by the assigned prover
proverPool.slashProver(blk.assignedProver, proofReward);
proofReward = 0;
proverPool.slashProver(blk.assignedProver);
}

blk.verifiedForkChoiceId = fcId;
Expand Down
9 changes: 8 additions & 1 deletion packages/protocol/test/TaikoL1TestBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ contract MockProverPool is IProverPool {

function releaseProver(address prover) external pure override { }

function slashProver(address prover) external pure override { }
function slashProver(
address prover,
uint64 proofReward
)
external
pure
override
{ }
}

abstract contract TaikoL1TestBase is Test {
Expand Down