diff --git a/contracts/Proofs.sol b/contracts/Proofs.sol index ba536b3..538e1b2 100644 --- a/contracts/Proofs.sol +++ b/contracts/Proofs.sol @@ -4,11 +4,17 @@ pragma solidity ^0.8.0; contract Proofs { uint256 private immutable period; uint256 private immutable timeout; + uint8 private immutable downtime; - constructor(uint256 __period, uint256 __timeout) { + constructor( + uint256 __period, + uint256 __timeout, + uint8 __downtime + ) { require(block.number > 256, "Insufficient block height"); period = __period; timeout = __timeout; + downtime = __downtime; } mapping(bytes32 => bool) private ids; @@ -95,12 +101,11 @@ contract Proofs { return false; } uint8 pointer = _getPointer(id, proofPeriod); - // TODO: make configurable: - if (pointer < 64) { + if (pointer < downtime) { return false; } bytes32 challenge = _getChallenge(pointer); - uint256 probability = (probabilities[id] * (256 - 64)) / 256; + uint256 probability = (probabilities[id] * (256 - downtime)) / 256; return uint256(challenge) % probability == 0; } diff --git a/contracts/Storage.sol b/contracts/Storage.sol index de2a0fd..b6806d8 100644 --- a/contracts/Storage.sol +++ b/contracts/Storage.sol @@ -16,10 +16,14 @@ contract Storage is Collateral, Marketplace, Proofs { IERC20 token, uint256 _proofPeriod, uint256 _proofTimeout, + uint8 _proofDowntime, uint256 _collateralAmount, uint256 _slashMisses, uint256 _slashPercentage - ) Marketplace(token, _collateralAmount) Proofs(_proofPeriod, _proofTimeout) { + ) + Marketplace(token, _collateralAmount) + Proofs(_proofPeriod, _proofTimeout, _proofDowntime) + { collateralAmount = _collateralAmount; slashMisses = _slashMisses; slashPercentage = _slashPercentage; diff --git a/contracts/TestProofs.sol b/contracts/TestProofs.sol index 650004f..efc51d1 100644 --- a/contracts/TestProofs.sol +++ b/contracts/TestProofs.sol @@ -5,8 +5,12 @@ import "./Proofs.sol"; // exposes internal functions of Proofs for testing contract TestProofs is Proofs { - constructor(uint256 __period, uint256 __timeout) - Proofs(__period, __timeout) + constructor( + uint256 __period, + uint256 __timeout, + uint8 __downtime + ) + Proofs(__period, __timeout, __downtime) // solhint-disable-next-line no-empty-blocks { diff --git a/deploy/storage.js b/deploy/storage.js index 9633724..4bf482f 100644 --- a/deploy/storage.js +++ b/deploy/storage.js @@ -2,6 +2,7 @@ module.exports = async ({ deployments, getNamedAccounts }) => { const token = await deployments.get("TestToken") const proofPeriod = 10 const proofTimeout = 5 + const proofDowntime = 64 const collateralAmount = 100 const slashMisses = 3 const slashPercentage = 10 @@ -9,6 +10,7 @@ module.exports = async ({ deployments, getNamedAccounts }) => { token.address, proofPeriod, proofTimeout, + proofDowntime, collateralAmount, slashMisses, slashPercentage, diff --git a/test/Proofs.test.js b/test/Proofs.test.js index ea8d29e..d466fa2 100644 --- a/test/Proofs.test.js +++ b/test/Proofs.test.js @@ -14,6 +14,7 @@ describe("Proofs", function () { const id = ethers.utils.randomBytes(32) const period = 10 const timeout = 5 + const downtime = 64 const duration = 1000 const probability = 4 // require a proof roughly once every 4 periods @@ -23,7 +24,7 @@ describe("Proofs", function () { await snapshot() await ensureMinimumBlockHeight(256) const Proofs = await ethers.getContractFactory("TestProofs") - proofs = await Proofs.deploy(period, timeout) + proofs = await Proofs.deploy(period, timeout, downtime) }) afterEach(async function () {