forked from keep-network/keep-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IRandomBeacon.sol
106 lines (99 loc) · 6.38 KB
/
IRandomBeacon.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
▓▓▌ ▓▓ ▐▓▓ ▓▓▓▓▓▓▓▓▓▓▌▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▄
▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▌▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓ ▓▓▓▓▓▓▓▀ ▐▓▓▓▓▓▓ ▐▓▓▓▓▓ ▓▓▓▓▓▓ ▓▓▓▓▓ ▐▓▓▓▓▓▌ ▐▓▓▓▓▓▓
▓▓▓▓▓▓▄▄▓▓▓▓▓▓▓▀ ▐▓▓▓▓▓▓▄▄▄▄ ▓▓▓▓▓▓▄▄▄▄ ▐▓▓▓▓▓▌ ▐▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▀ ▐▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▌ ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▀▀▓▓▓▓▓▓▄ ▐▓▓▓▓▓▓▀▀▀▀ ▓▓▓▓▓▓▀▀▀▀ ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▀
▓▓▓▓▓▓ ▀▓▓▓▓▓▓▄ ▐▓▓▓▓▓▓ ▓▓▓▓▓ ▓▓▓▓▓▓ ▓▓▓▓▓ ▐▓▓▓▓▓▌
▓▓▓▓▓▓▓▓▓▓ █▓▓▓▓▓▓▓▓▓ ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓ ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓
Trust math, not hardware.
*/
pragma solidity 0.5.17;
/// @title Keep Random Beacon
///
/// @notice Keep Random Beacon generates verifiable randomness that is resistant
/// to bad actors both in the relay network and on the anchoring blockchain.
interface IRandomBeacon {
/// @notice Event emitted for each new relay entry generated. It contains
/// request ID allowing to associate the generated relay entry with relay
/// request created previously with `requestRelayEntry` function. Event is
/// emitted no matter if callback was executed or not.
///
/// @param requestId Relay request ID for which entry was generated.
/// @param entry Generated relay entry.
event RelayEntryGenerated(uint256 requestId, uint256 entry);
/// @notice Provides the customer with an estimated entry fee in wei to use
/// in the request. The fee estimate is only valid for the transaction it is
/// called in, so the customer must make the request immediately after
/// obtaining the estimate. Insufficient payment will lead to the request
/// being rejected and the transaction reverted.
///
/// The customer may decide to provide more ether for an entry fee than
/// estimated by this function. This is especially helpful when callback gas
/// cost fluctuates. Any surplus between the passed fee and the actual cost
/// of producing an entry and executing a callback is returned back to the
/// customer.
/// @param callbackGas Gas required for the callback.
function entryFeeEstimate(uint256 callbackGas)
external
view
returns (uint256);
/// @notice Submits a request to generate a new relay entry. Executes
/// callback on the provided callback contract with the generated entry and
/// emits `RelayEntryGenerated(uint256 requestId, uint256 entry)` event.
/// Callback contract has to declare public `__beaconCallback(uint256)`
/// function that is going to be executed with the result, once ready.
/// It is recommended to implement `IRandomBeaconConsumer` interface to
/// ensure the correct callback function signature.
///
/// @dev Beacon does not support concurrent relay requests. No new requests
/// should be made while the beacon is already processing another request.
/// Requests made while the beacon is busy will be rejected and the
/// transaction reverted.
///
/// @param callbackContract Callback contract address. Callback is called
/// once a new relay entry has been generated. Must declare public
/// `__beaconCallback(uint256)` function. It is recommended to implement
/// `IRandomBeaconConsumer` interface to ensure the correct callback function
/// signature.
/// @param callbackGas Gas required for the callback.
/// The customer needs to ensure they provide a sufficient callback gas
/// to cover the gas fee of executing the callback. Any surplus is returned
/// to the customer. If the callback gas amount turns to be not enough to
/// execute the callback, callback execution is skipped.
/// @return An uint256 representing uniquely generated relay request ID
function requestRelayEntry(address callbackContract, uint256 callbackGas)
external
payable
returns (uint256);
/// @notice Submits a request to generate a new relay entry. Emits
/// `RelayEntryGenerated(uint256 requestId, uint256 entry)` event for the
/// generated entry.
///
/// @dev Beacon does not support concurrent relay requests. No new requests
/// should be made while the beacon is already processing another request.
/// Requests made while the beacon is busy will be rejected and the
/// transaction reverted.
///
/// @return An uint256 representing uniquely generated relay request ID
function requestRelayEntry() external payable returns (uint256);
}
/// @title Keep Random Beacon Consumer
///
/// @notice Receives Keep Random Beacon relay entries with `__beaconCallback`
/// function. Contract implementing this interface does not have to be the one
/// requesting relay entry but it is the one receiving the requested relay entry
/// once it is produced.
///
/// @dev Use this interface to indicate the contract receives relay entries from
/// the beacon and to ensure the correctness of callback function signature.
interface IRandomBeaconConsumer {
/// @notice Receives relay entry produced by Keep Random Beacon. This function
/// should be called only by Keep Random Beacon.
///
/// @param relayEntry Relay entry (random number) produced by Keep Random
/// Beacon.
function __beaconCallback(uint256 relayEntry) external;
}