chore: add `downtimeProduct` configuration parameter (#138)

* add `downtimeProduct` configuration parameter

* formatting
This commit is contained in:
Eric 2024-08-14 07:50:32 +02:00 committed by GitHub
parent 1d36256230
commit ed428767b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 11 additions and 6 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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
)
})

View File

@ -14,6 +14,7 @@ const exampleConfiguration = () => ({
timeout: 5,
downtime: 64,
zkeyHash: "",
downtimeProduct: 67,
},
})