Make pointer downtime configurable

This commit is contained in:
Mark Spanbroek 2022-03-10 10:19:21 +01:00 committed by markspanbroek
parent 476956c4d5
commit fd55afcc5a
5 changed files with 24 additions and 8 deletions

View File

@ -4,11 +4,17 @@ pragma solidity ^0.8.0;
contract Proofs { contract Proofs {
uint256 private immutable period; uint256 private immutable period;
uint256 private immutable timeout; 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"); require(block.number > 256, "Insufficient block height");
period = __period; period = __period;
timeout = __timeout; timeout = __timeout;
downtime = __downtime;
} }
mapping(bytes32 => bool) private ids; mapping(bytes32 => bool) private ids;
@ -95,12 +101,11 @@ contract Proofs {
return false; return false;
} }
uint8 pointer = _getPointer(id, proofPeriod); uint8 pointer = _getPointer(id, proofPeriod);
// TODO: make configurable: if (pointer < downtime) {
if (pointer < 64) {
return false; return false;
} }
bytes32 challenge = _getChallenge(pointer); bytes32 challenge = _getChallenge(pointer);
uint256 probability = (probabilities[id] * (256 - 64)) / 256; uint256 probability = (probabilities[id] * (256 - downtime)) / 256;
return uint256(challenge) % probability == 0; return uint256(challenge) % probability == 0;
} }

View File

@ -16,10 +16,14 @@ contract Storage is Collateral, Marketplace, Proofs {
IERC20 token, IERC20 token,
uint256 _proofPeriod, uint256 _proofPeriod,
uint256 _proofTimeout, uint256 _proofTimeout,
uint8 _proofDowntime,
uint256 _collateralAmount, uint256 _collateralAmount,
uint256 _slashMisses, uint256 _slashMisses,
uint256 _slashPercentage uint256 _slashPercentage
) Marketplace(token, _collateralAmount) Proofs(_proofPeriod, _proofTimeout) { )
Marketplace(token, _collateralAmount)
Proofs(_proofPeriod, _proofTimeout, _proofDowntime)
{
collateralAmount = _collateralAmount; collateralAmount = _collateralAmount;
slashMisses = _slashMisses; slashMisses = _slashMisses;
slashPercentage = _slashPercentage; slashPercentage = _slashPercentage;

View File

@ -5,8 +5,12 @@ import "./Proofs.sol";
// exposes internal functions of Proofs for testing // exposes internal functions of Proofs for testing
contract TestProofs is Proofs { contract TestProofs is Proofs {
constructor(uint256 __period, uint256 __timeout) constructor(
Proofs(__period, __timeout) uint256 __period,
uint256 __timeout,
uint8 __downtime
)
Proofs(__period, __timeout, __downtime)
// solhint-disable-next-line no-empty-blocks // solhint-disable-next-line no-empty-blocks
{ {

View File

@ -2,6 +2,7 @@ module.exports = async ({ deployments, getNamedAccounts }) => {
const token = await deployments.get("TestToken") const token = await deployments.get("TestToken")
const proofPeriod = 10 const proofPeriod = 10
const proofTimeout = 5 const proofTimeout = 5
const proofDowntime = 64
const collateralAmount = 100 const collateralAmount = 100
const slashMisses = 3 const slashMisses = 3
const slashPercentage = 10 const slashPercentage = 10
@ -9,6 +10,7 @@ module.exports = async ({ deployments, getNamedAccounts }) => {
token.address, token.address,
proofPeriod, proofPeriod,
proofTimeout, proofTimeout,
proofDowntime,
collateralAmount, collateralAmount,
slashMisses, slashMisses,
slashPercentage, slashPercentage,

View File

@ -14,6 +14,7 @@ describe("Proofs", function () {
const id = ethers.utils.randomBytes(32) const id = ethers.utils.randomBytes(32)
const period = 10 const period = 10
const timeout = 5 const timeout = 5
const downtime = 64
const duration = 1000 const duration = 1000
const probability = 4 // require a proof roughly once every 4 periods const probability = 4 // require a proof roughly once every 4 periods
@ -23,7 +24,7 @@ describe("Proofs", function () {
await snapshot() await snapshot()
await ensureMinimumBlockHeight(256) await ensureMinimumBlockHeight(256)
const Proofs = await ethers.getContractFactory("TestProofs") const Proofs = await ethers.getContractFactory("TestProofs")
proofs = await Proofs.deploy(period, timeout) proofs = await Proofs.deploy(period, timeout, downtime)
}) })
afterEach(async function () { afterEach(async function () {