diff --git a/contracts/Configuration.sol b/contracts/Configuration.sol index c1ad61c..861a144 100644 --- a/contracts/Configuration.sol +++ b/contracts/Configuration.sol @@ -24,4 +24,8 @@ struct ProofConfig { uint256 timeout; // mark proofs as missing before the timeout (in seconds) uint8 downtime; // ignore this much recent blocks for proof requirements string zkeyHash; // hash of the zkey file which is linked to the verifier + // Ensures the pointer does not remain in downtime for many consecutive + // periods. For each period increase, move the pointer `pointerProduct` + // blocks. Should be a prime number to ensure there are no cycles. + uint8 downtimeProduct; } diff --git a/contracts/FuzzMarketplace.sol b/contracts/FuzzMarketplace.sol index 9fe5c7d..efdd902 100644 --- a/contracts/FuzzMarketplace.sol +++ b/contracts/FuzzMarketplace.sol @@ -10,7 +10,7 @@ contract FuzzMarketplace is Marketplace { Marketplace( MarketplaceConfig( CollateralConfig(10, 5, 3, 10), - ProofConfig(10, 5, 64, "") + ProofConfig(10, 5, 64, "", 67) ), new TestToken(), new TestVerifier() diff --git a/contracts/Proofs.sol b/contracts/Proofs.sol index 12aa148..5453228 100644 --- a/contracts/Proofs.sol +++ b/contracts/Proofs.sol @@ -69,10 +69,8 @@ abstract contract Proofs is Periods { */ function _getPointer(SlotId id, Period period) internal view returns (uint8) { uint256 blockNumber = block.number % 256; - // To ensure the pointer does not remain in downtime for many consecutive - // periods, for each period increase, move the pointer 67 blocks. We've - // chosen a prime number to ensure that we don't get cycles. - uint256 periodNumber = (Period.unwrap(period) * 67) % 256; + uint256 periodNumber = (Period.unwrap(period) * _config.downtimeProduct) % + 256; uint256 idOffset = uint256(SlotId.unwrap(id)) % 256; uint256 pointer = (blockNumber + periodNumber + idOffset) % 256; return uint8(pointer); diff --git a/deploy/marketplace.js b/deploy/marketplace.js index abdeb9c..e4bc570 100644 --- a/deploy/marketplace.js +++ b/deploy/marketplace.js @@ -14,6 +14,7 @@ const CONFIGURATION = { // `downtime` needs to be larger than `period` when running hardhat // in automine mode, because it can produce a block every second downtime: 64, + downtimeProduct: 67 }, } diff --git a/test/Proofs.test.js b/test/Proofs.test.js index 7ebe87c..b87bf3e 100644 --- a/test/Proofs.test.js +++ b/test/Proofs.test.js @@ -22,6 +22,7 @@ describe("Proofs", function () { const timeout = 5 const downtime = 64 const probability = 4 // require a proof roughly once every 4 periods + const downtimeProduct = 67 const { periodOf, periodEnd } = periodic(period) let proofs @@ -33,7 +34,7 @@ describe("Proofs", function () { await deployments.fixture(["Verifier"]) const verifier = await deployments.get("Groth16Verifier") proofs = await Proofs.deploy( - { period, timeout, downtime, zkeyHash: "" }, + { period, timeout, downtime, zkeyHash: "", downtimeProduct }, verifier.address ) }) diff --git a/test/examples.js b/test/examples.js index ab14677..06d8428 100644 --- a/test/examples.js +++ b/test/examples.js @@ -14,6 +14,7 @@ const exampleConfiguration = () => ({ timeout: 5, downtime: 64, zkeyHash: "", + downtimeProduct: 67, }, })