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 <mark@spanbroek.net>
This commit is contained in:
Eric 2023-12-14 23:02:03 +00:00 committed by GitHub
parent 87461f6b83
commit b5f33992b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

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