Skip to content

Commit b31a9fa

Browse files
Merge pull request #363 from unknownunknown1/feat/beacon-rng-lookahead
fix(RNG): add lookahead of 132 blocks
2 parents 003bfee + b845c79 commit b31a9fa

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

contracts/standard/rng/BeaconRNGFallback.sol

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @authors: [@shalzz]
3-
* @reviewers: [@jaybuidl*, @geaxed]
2+
* @authors: [@shalzz, @unknownunknown1]
3+
* @reviewers: [@jaybuidl, @geaxed*]
44
* @auditors: []
55
* @bounties: []
66
* @deployments: []
@@ -18,6 +18,8 @@ contract BeaconRNGFallBack is RNG {
1818
RNG public beaconRNG;
1919
RNG public blockhashRNG;
2020

21+
uint public constant LOOKAHEAD = 132; // Number of blocks that has to pass before obtaining the random number. 4 epochs + 4 slots, according to EIP-4399.
22+
2123
/** @dev Constructor.
2224
* @param _beaconRNG The beacon chain RNG deployed contract address
2325
* @param _blockhashRNG The blockhash RNG deployed contract address
@@ -65,6 +67,10 @@ contract BeaconRNGFallBack is RNG {
6567
// fallback to blockhash RNG
6668
if (RN == 0) {
6769
RN = blockhashRNG.getRN(_block);
70+
} else if (block.number < _block + LOOKAHEAD) {
71+
// Beacon chain returns the random number, but sufficient number of blocks hasn't been mined yet.
72+
// In this case signal to the court that RN isn't ready.
73+
RN = 0;
6874
}
6975
}
7076
}

0 commit comments

Comments
 (0)