From b5f33992b67df3733042a7d912c854700e8c863c Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Thu, 14 Dec 2023 23:02:03 +0000 Subject: [PATCH] Increase pointer by 67 blocks each time the period is increased (#75) * Increase pointer by 67 instead of 64 for each period Use a prime number to ensure that we don't get cycles where we're looking at the same hash four periods from now. --------- Co-authored-by: Mark Spanbroek --- contracts/Proofs.sol | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contracts/Proofs.sol b/contracts/Proofs.sol index a442789..bca3cfe 100644 --- a/contracts/Proofs.sol +++ b/contracts/Proofs.sol @@ -36,7 +36,10 @@ abstract contract Proofs is Periods { function _getPointer(SlotId id, Period period) internal view returns (uint8) { uint256 blockNumber = block.number % 256; - uint256 periodNumber = Period.unwrap(period) % 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 idOffset = uint256(SlotId.unwrap(id)) % 256; uint256 pointer = (blockNumber + periodNumber + idOffset) % 256; return uint8(pointer);