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 {
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;
}

View File

@ -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;

View File

@ -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
{

View File

@ -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,

View File

@ -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 () {