Skip to content

Commit ab8b223

Browse files
committed
feat: add a Beacon Chain RNG
1 parent 3c494f7 commit ab8b223

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @authors: [@shalzz
3+
* @reviewers: []
4+
* @auditors: []
5+
* @bounties: []
6+
* @deployments: []
7+
*/
8+
9+
pragma solidity ^0.4.15;
10+
11+
import "./RNG.sol";
12+
13+
/**
14+
* @title Random Number Generator using beacon chain random opcode
15+
*/
16+
contract BeaconRNG is RNG {
17+
18+
/**
19+
* @dev Since we don't really need to incentivise requesting the beacon chain randomness,
20+
* this is a stub implementation required for backwards compatibility with the
21+
* RNG interface.
22+
* @notice All the ETH sent here will be lost forever.
23+
* @param _block Block the random number is linked to.
24+
*/
25+
function contribute(uint _block) public payable {}
26+
27+
28+
/** @dev Return the random number from the PoS randomness beacon.
29+
* @param _block Block the random number is linked to.
30+
* @return RN Random Number. If the PoS upgrade defined by EIP-3675
31+
* has not yet executed 0 instead.
32+
*/
33+
function getRN(uint _block) public returns (uint RN) {
34+
if (block.difficulty <= 2**64)
35+
return 0;
36+
return block.difficulty;
37+
}
38+
}

0 commit comments

Comments
 (0)