Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions contracts/standard/rng/BeaconRNGFallback.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @authors: [@shalzz]
* @reviewers: [@jaybuidl*, @geaxed]
* @authors: [@shalzz, @unknownunknown1]
* @reviewers: [@jaybuidl, @geaxed*]
* @auditors: []
* @bounties: []
* @deployments: []
Expand All @@ -18,6 +18,8 @@ contract BeaconRNGFallBack is RNG {
RNG public beaconRNG;
RNG public blockhashRNG;

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.

/** @dev Constructor.
* @param _beaconRNG The beacon chain RNG deployed contract address
* @param _blockhashRNG The blockhash RNG deployed contract address
Expand Down Expand Up @@ -65,6 +67,10 @@ contract BeaconRNGFallBack is RNG {
// fallback to blockhash RNG
if (RN == 0) {
RN = blockhashRNG.getRN(_block);
} else if (block.number < _block + LOOKAHEAD) {
// Beacon chain returns the random number, but sufficient number of blocks hasn't been mined yet.
// In this case signal to the court that RN isn't ready.
RN = 0;
}
}
}