Skip to content

Commit 6753d20

Browse files
authored
Remove missing proof leniency (#210)
1 parent 78c1571 commit 6753d20

File tree

7 files changed

+23
-32
lines changed

7 files changed

+23
-32
lines changed

configuration/configuration.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@ const DEFAULT_CONFIGURATION = {
66
collateral: {
77
repairRewardPercentage: 10,
88
maxNumberOfSlashes: 2,
9-
slashCriterion: 2,
109
slashPercentage: 20,
1110
},
1211
proofs: {
1312
// period has to be less than downtime * blocktime
1413
period: 120, // seconds
1514
timeout: 30, // seconds
1615
downtime: 64, // number of blocks
17-
downtimeProduct: 67 // number of blocks
16+
downtimeProduct: 67, // number of blocks
1817
},
1918
reservations: {
20-
maxReservations: 3
21-
}
19+
maxReservations: 3,
20+
},
2221
}
2322

2423
function loadConfiguration(name) {
2524
const path = `${BASE_PATH}/${name}/configuration.js`
26-
if(fs.existsSync(path)) {
25+
if (fs.existsSync(path)) {
2726
return require(path)
2827
} else {
2928
return DEFAULT_CONFIGURATION

configuration/networks/hardhat/configuration.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module.exports = {
22
collateral: {
33
repairRewardPercentage: 10,
44
maxNumberOfSlashes: 2,
5-
slashCriterion: 2,
65
slashPercentage: 20,
76
},
87
proofs: {
@@ -11,9 +10,9 @@ module.exports = {
1110
period: 90, // seconds
1211
timeout: 30, // seconds
1312
downtime: 96, // number of blocks
14-
downtimeProduct: 97 // number of blocks
13+
downtimeProduct: 97, // number of blocks
1514
},
1615
reservations: {
17-
maxReservations: 3
18-
}
16+
maxReservations: 3,
17+
},
1918
}

contracts/Configuration.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ struct CollateralConfig {
1313
/// @dev percentage of collateral that is used as repair reward
1414
uint8 repairRewardPercentage;
1515
uint8 maxNumberOfSlashes; // frees slot when the number of slashing reaches this value
16-
uint16 slashCriterion; // amount of proofs missed that lead to slashing
1716
uint8 slashPercentage; // percentage of the collateral that is slashed
1817
}
1918

contracts/FuzzMarketplace.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ contract FuzzMarketplace is Marketplace {
99
constructor()
1010
Marketplace(
1111
MarketplaceConfig(
12-
CollateralConfig(10, 5, 3, 10),
12+
CollateralConfig(10, 5, 10),
1313
ProofConfig(10, 5, 64, "", 67),
1414
SlotReservationsConfig(20)
1515
),

contracts/Marketplace.sol

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -336,18 +336,13 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
336336

337337
// TODO: Reward for validator that calls this function
338338

339-
if (missingProofs(slotId) % _config.collateral.slashCriterion == 0) {
340-
uint256 slashedAmount = (request.ask.collateralPerSlot() *
341-
_config.collateral.slashPercentage) / 100;
342-
slot.currentCollateral -= slashedAmount;
343-
if (
344-
missingProofs(slotId) / _config.collateral.slashCriterion >=
345-
_config.collateral.maxNumberOfSlashes
346-
) {
347-
// When the number of slashings is at or above the allowed amount,
348-
// free the slot.
349-
_forciblyFreeSlot(slotId);
350-
}
339+
uint256 slashedAmount = (request.ask.collateralPerSlot() *
340+
_config.collateral.slashPercentage) / 100;
341+
slot.currentCollateral -= slashedAmount;
342+
if (missingProofs(slotId) >= _config.collateral.maxNumberOfSlashes) {
343+
// When the number of slashings is at or above the allowed amount,
344+
// free the slot.
345+
_forciblyFreeSlot(slotId);
351346
}
352347
}
353348

test/Marketplace.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,17 +1362,17 @@ describe("Marketplace", function () {
13621362
})
13631363

13641364
describe("slashing when missing proofs", function () {
1365-
it("reduces collateral when too many proofs are missing", async function () {
1365+
it("reduces collateral when a proof is missing", async function () {
13661366
const id = slotId(slot)
1367-
const { slashCriterion, slashPercentage } = config.collateral
1367+
const { slashPercentage } = config.collateral
13681368
await marketplace.reserveSlot(slot.request, slot.index)
13691369
await marketplace.fillSlot(slot.request, slot.index, proof)
1370-
for (let i = 0; i < slashCriterion; i++) {
1371-
await waitUntilProofIsRequired(id)
1372-
let missedPeriod = periodOf(await currentTime())
1373-
await advanceTimeForNextBlock(period + 1)
1374-
await marketplace.markProofAsMissing(id, missedPeriod)
1375-
}
1370+
1371+
await waitUntilProofIsRequired(id)
1372+
let missedPeriod = periodOf(await currentTime())
1373+
await advanceTimeForNextBlock(period + 1)
1374+
await marketplace.markProofAsMissing(id, missedPeriod)
1375+
13761376
const collateral = collateralPerSlot(request)
13771377
const expectedBalance = Math.round(
13781378
(collateral * (100 - slashPercentage)) / 100

test/examples.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const exampleConfiguration = () => ({
66
collateral: {
77
repairRewardPercentage: 10,
88
maxNumberOfSlashes: 5,
9-
slashCriterion: 3,
109
slashPercentage: 10,
1110
},
1211
proofs: {

0 commit comments

Comments
 (0)