Contract Source Code:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
// Import Entropy interfaces from the Pyth Network Entropy SDK.
import "@pythnetwork/entropy-sdk-solidity/IEntropy.sol";
import "@pythnetwork/entropy-sdk-solidity/IEntropyConsumer.sol";
// Import OpenZeppelin contracts for security and access control.
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/Pausable.sol";
/// @title Mutable-Bet-Limits CoinFlip Contract with Commission Wallet
/// @notice This contract implements a coin flip game using secure randomness via the Entropy SDK.
/// When a player wins, the full win amount (double their bet) is split:
/// - A commission (calculated in basis points) is sent to a designated commission wallet.
/// - The remaining amount is sent to the player.
/// The commission wallet is initially set to 0x86605872B0cbDF364C283E76921ee22546c692f2 and can be updated.
contract CoinFlip is IEntropyConsumer, ReentrancyGuard, Pausable {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event FlipRequested(uint64 sequenceNumber, address indexed player, uint256 betAmount);
event FlipResult(uint64 sequenceNumber, bool isHeads, address indexed player, uint256 betAmount, uint256 payout);
event BetRefunded(uint64 sequenceNumber, address indexed player, uint256 betAmount);
event BetLimitsUpdated(uint256 newMinBet, uint256 newMaxBet);
event ProviderUpdated(address newProvider);
event EntropyUpdated(address newEntropy);
event CommissionWalletUpdated(address newCommissionWallet);
/*//////////////////////////////////////////////////////////////
CONFIGURABLE PARAMETERS
//////////////////////////////////////////////////////////////*/
// Commission is defined in basis points (e.g., 2.5% = 250)
uint256 public constant COMMISSION = 250;
uint256 public constant BASIS_POINTS = 10000;
uint256 public constant REFUND_DELAY = 1 days;
// Mutable bet limits (modifiable by the owner)
uint256 public minBet;
uint256 public maxBet;
// The wallet that will receive the commission fees.
address public commissionWallet;
// Counter for pending bets
uint256 public pendingBetsCount;
/*//////////////////////////////////////////////////////////////
STATE VARIABLES
//////////////////////////////////////////////////////////////*/
IEntropy public entropy;
address public provider;
address public immutable owner;
// Structure representing a bet
struct Bet {
address player;
uint256 betAmount;
uint256 timestamp;
}
// Mapping to track pending bets using a sequence number.
mapping(uint64 => Bet) public pendingBets;
/*//////////////////////////////////////////////////////////////
MODIFIERS
//////////////////////////////////////////////////////////////*/
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_;
}
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
/// @notice Initializes the contract with the Entropy parameters, bet limits, and commission wallet.
/// @param _entropy The Entropy contract address.
/// @param _provider The randomness provider address.
/// @param _minBet The initial minimum bet.
/// @param _maxBet The initial maximum bet.
/// @param _commissionWallet The commission wallet address.
constructor(
address _entropy,
address _provider,
uint256 _minBet,
uint256 _maxBet,
address _commissionWallet
) payable {
require(_minBet <= _maxBet, "Initial min bet must not exceed max bet");
entropy = IEntropy(_entropy);
provider = _provider;
owner = msg.sender;
minBet = _minBet;
maxBet = _maxBet;
commissionWallet = _commissionWallet;
}
/*//////////////////////////////////////////////////////////////
OWNER FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Updates the minimum and maximum bet limits.
function setBetLimits(uint256 _minBet, uint256 _maxBet) external onlyOwner {
require(_minBet <= _maxBet, "Min bet must not exceed max bet");
minBet = _minBet;
maxBet = _maxBet;
emit BetLimitsUpdated(_minBet, _maxBet);
}
/// @notice Updates the randomness provider address.
function updateProvider(address _provider) external onlyOwner {
require(pendingBetsCount == 0, "Pending bets exist");
provider = _provider;
emit ProviderUpdated(_provider);
}
/// @notice Updates the Entropy contract address.
function updateEntropy(address _entropy) external onlyOwner {
require(pendingBetsCount == 0, "Pending bets exist");
entropy = IEntropy(_entropy);
emit EntropyUpdated(_entropy);
}
/// @notice Updates the commission wallet address.
function updateCommissionWallet(address _commissionWallet) external onlyOwner {
commissionWallet = _commissionWallet;
emit CommissionWalletUpdated(_commissionWallet);
}
/// @notice Pauses the contract.
function pause() external onlyOwner {
_pause();
}
/// @notice Unpauses the contract.
function unpause() external onlyOwner {
_unpause();
}
/*//////////////////////////////////////////////////////////////
IEntropyConsumer IMPLEMENTATION
//////////////////////////////////////////////////////////////*/
/// @notice Returns the Entropy contract address.
function getEntropy() internal view override returns (address) {
return address(entropy);
}
/// @notice Internal callback invoked when randomness is available.
/// @dev Processes the bet outcome. For a winning bet, the full win amount (2×bet) is split:
/// - The commission is sent to the commission wallet.
/// - The remaining payout is sent to the player.
function entropyCallback(
uint64 sequenceNumber,
address _unusedProvider,
bytes32 randomNumber
) internal override {
_unusedProvider; // Silence unused parameter warning.
Bet memory bet = pendingBets[sequenceNumber];
if (bet.player == address(0)) {
// Bet already processed or refunded.
return;
}
// Determine win condition: if the random number is even, the player wins.
bool isHeads = (uint256(randomNumber) % 2 == 0);
uint256 payout = 0;
if (isHeads) {
// Full win amount is twice the bet.
uint256 fullWin = 2 * bet.betAmount;
// Commission is a percentage of the full win.
uint256 commissionAmount = (2 * bet.betAmount * COMMISSION) / BASIS_POINTS;
// Player receives the win minus the commission.
uint256 playerPayout = fullWin - commissionAmount;
require(address(this).balance >= fullWin, "Insufficient funds for payout");
// Transfer commission directly to the commission wallet.
(bool commissionSent, ) = commissionWallet.call{value: commissionAmount}("");
require(commissionSent, "Commission transfer failed");
// Transfer the remaining payout to the player.
(bool playerSent, ) = bet.player.call{value: playerPayout}("");
require(playerSent, "Payout transfer failed");
payout = playerPayout;
}
// Remove the bet and update the pending bets counter.
delete pendingBets[sequenceNumber];
pendingBetsCount--;
emit FlipResult(sequenceNumber, isHeads, bet.player, bet.betAmount, payout);
}
/// @notice External wrapper for the entropy callback.
/// @dev This function is called by the Entropy provider. It ensures that only the trusted
/// Entropy contract can trigger the callback.
function receiveEntropy(
uint64 sequenceNumber,
address _unusedProvider,
bytes32 randomNumber
) external nonReentrant whenNotPaused {
require(msg.sender == address(entropy), "Unauthorized caller");
entropyCallback(sequenceNumber, _unusedProvider, randomNumber);
}
/*//////////////////////////////////////////////////////////////
BETTING FUNCTION
//////////////////////////////////////////////////////////////*/
/// @notice Initiates a coin flip bet.
/// @dev The caller must send enough ETH to cover both the bet and the randomness fee.
function flip(bytes32 userRandomNumber) external payable whenNotPaused nonReentrant {
uint128 requestFee = entropy.getFee(provider);
require(msg.value >= requestFee + minBet, "Not enough ETH for bet + fee");
require(msg.value <= requestFee + maxBet, "Bet exceeds maximum allowed");
uint256 betAmount = msg.value - requestFee;
uint64 sequenceNumber = entropy.requestWithCallback{value: requestFee}(provider, userRandomNumber);
pendingBets[sequenceNumber] = Bet({
player: msg.sender,
betAmount: betAmount,
timestamp: block.timestamp
});
pendingBetsCount++;
emit FlipRequested(sequenceNumber, msg.sender, betAmount);
}
/*//////////////////////////////////////////////////////////////
PENDING BET REFUND FUNCTION
//////////////////////////////////////////////////////////////*/
/// @notice Allows a player to claim a refund if the bet remains pending beyond the refund delay.
function claimRefund(uint64 sequenceNumber) external nonReentrant {
Bet memory bet = pendingBets[sequenceNumber];
require(bet.player != address(0), "No pending bet found");
require(msg.sender == bet.player, "Not the bet owner");
require(block.timestamp >= bet.timestamp + REFUND_DELAY, "Refund period not reached");
delete pendingBets[sequenceNumber];
pendingBetsCount--;
(bool sent, ) = bet.player.call{value: bet.betAmount}("");
require(sent, "Refund transfer failed");
emit BetRefunded(sequenceNumber, bet.player, bet.betAmount);
}
/*//////////////////////////////////////////////////////////////
POOL MANAGEMENT
//////////////////////////////////////////////////////////////*/
/// @notice Allows the owner to deposit ETH into the contract.
function deposit() external payable onlyOwner {}
/// @notice Allows the owner to withdraw ETH from the contract.
function withdraw(uint256 amount) external onlyOwner nonReentrant {
require(address(this).balance >= amount, "Insufficient contract balance");
(bool sent, ) = owner.call{value: amount}("");
require(sent, "Withdrawal failed");
}
/*//////////////////////////////////////////////////////////////
EMERGENCY RESOLUTION FUNCTION
//////////////////////////////////////////////////////////////*/
/// @notice Emergency function to manually resolve a bet.
function emergencyResolveBet(
uint64 sequenceNumber,
bool isHeadsOverride,
uint256 payoutOverride
) external onlyOwner nonReentrant {
Bet memory bet = pendingBets[sequenceNumber];
require(bet.player != address(0), "No pending bet found");
if (isHeadsOverride) {
require(address(this).balance >= payoutOverride, "Insufficient funds for payout");
(bool sent, ) = bet.player.call{value: payoutOverride}("");
require(sent, "Payout transfer failed");
}
delete pendingBets[sequenceNumber];
pendingBetsCount--;
emit FlipResult(sequenceNumber, isHeadsOverride, bet.player, bet.betAmount, payoutOverride);
}
/*//////////////////////////////////////////////////////////////
FALLBACK FUNCTION
//////////////////////////////////////////////////////////////*/
/// @notice Fallback function to accept ETH sent directly to the contract.
receive() external payable {}
}
// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.0;
import "./EntropyEvents.sol";
interface IEntropy is EntropyEvents {
// Register msg.sender as a randomness provider. The arguments are the provider's configuration parameters
// and initial commitment. Re-registering the same provider rotates the provider's commitment (and updates
// the feeInWei).
//
// chainLength is the number of values in the hash chain *including* the commitment, that is, chainLength >= 1.
function register(
uint128 feeInWei,
bytes32 commitment,
bytes calldata commitmentMetadata,
uint64 chainLength,
bytes calldata uri
) external;
// Withdraw a portion of the accumulated fees for the provider msg.sender.
// Calling this function will transfer `amount` wei to the caller (provided that they have accrued a sufficient
// balance of fees in the contract).
function withdraw(uint128 amount) external;
// Withdraw a portion of the accumulated fees for provider. The msg.sender must be the fee manager for this provider.
// Calling this function will transfer `amount` wei to the caller (provided that they have accrued a sufficient
// balance of fees in the contract).
function withdrawAsFeeManager(address provider, uint128 amount) external;
// As a user, request a random number from `provider`. Prior to calling this method, the user should
// generate a random number x and keep it secret. The user should then compute hash(x) and pass that
// as the userCommitment argument. (You may call the constructUserCommitment method to compute the hash.)
//
// This method returns a sequence number. The user should pass this sequence number to
// their chosen provider (the exact method for doing so will depend on the provider) to retrieve the provider's
// number. The user should then call fulfillRequest to construct the final random number.
//
// This method will revert unless the caller provides a sufficient fee (at least getFee(provider)) as msg.value.
// Note that excess value is *not* refunded to the caller.
function request(
address provider,
bytes32 userCommitment,
bool useBlockHash
) external payable returns (uint64 assignedSequenceNumber);
// Request a random number. The method expects the provider address and a secret random number
// in the arguments. It returns a sequence number.
//
// The address calling this function should be a contract that inherits from the IEntropyConsumer interface.
// The `entropyCallback` method on that interface will receive a callback with the generated random number.
//
// This method will revert unless the caller provides a sufficient fee (at least getFee(provider)) as msg.value.
// Note that excess value is *not* refunded to the caller.
function requestWithCallback(
address provider,
bytes32 userRandomNumber
) external payable returns (uint64 assignedSequenceNumber);
// Fulfill a request for a random number. This method validates the provided userRandomness and provider's proof
// against the corresponding commitments in the in-flight request. If both values are validated, this function returns
// the corresponding random number.
//
// Note that this function can only be called once per in-flight request. Calling this function deletes the stored
// request information (so that the contract doesn't use a linear amount of storage in the number of requests).
// If you need to use the returned random number more than once, you are responsible for storing it.
function reveal(
address provider,
uint64 sequenceNumber,
bytes32 userRevelation,
bytes32 providerRevelation
) external returns (bytes32 randomNumber);
// Fulfill a request for a random number. This method validates the provided userRandomness
// and provider's revelation against the corresponding commitment in the in-flight request. If both values are validated
// and the requestor address is a contract address, this function calls the requester's entropyCallback method with the
// sequence number, provider address and the random number as arguments. Else if the requestor is an EOA, it won't call it.
//
// Note that this function can only be called once per in-flight request. Calling this function deletes the stored
// request information (so that the contract doesn't use a linear amount of storage in the number of requests).
// If you need to use the returned random number more than once, you are responsible for storing it.
//
// Anyone can call this method to fulfill a request, but the callback will only be made to the original requester.
function revealWithCallback(
address provider,
uint64 sequenceNumber,
bytes32 userRandomNumber,
bytes32 providerRevelation
) external;
function getProviderInfo(
address provider
) external view returns (EntropyStructs.ProviderInfo memory info);
function getDefaultProvider() external view returns (address provider);
function getRequest(
address provider,
uint64 sequenceNumber
) external view returns (EntropyStructs.Request memory req);
function getFee(address provider) external view returns (uint128 feeAmount);
function getAccruedPythFees()
external
view
returns (uint128 accruedPythFeesInWei);
function setProviderFee(uint128 newFeeInWei) external;
function setProviderFeeAsFeeManager(
address provider,
uint128 newFeeInWei
) external;
function setProviderUri(bytes calldata newUri) external;
// Set manager as the fee manager for the provider msg.sender.
// After calling this function, manager will be able to set the provider's fees and withdraw them.
// Only one address can be the fee manager for a provider at a time -- calling this function again with a new value
// will override the previous value. Call this function with the all-zero address to disable the fee manager role.
function setFeeManager(address manager) external;
function constructUserCommitment(
bytes32 userRandomness
) external pure returns (bytes32 userCommitment);
function combineRandomValues(
bytes32 userRandomness,
bytes32 providerRandomness,
bytes32 blockHash
) external pure returns (bytes32 combinedRandomness);
}
// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.0;
abstract contract IEntropyConsumer {
// This method is called by Entropy to provide the random number to the consumer.
// It asserts that the msg.sender is the Entropy contract. It is not meant to be
// override by the consumer.
function _entropyCallback(
uint64 sequence,
address provider,
bytes32 randomNumber
) external {
address entropy = getEntropy();
require(entropy != address(0), "Entropy address not set");
require(msg.sender == entropy, "Only Entropy can call this function");
entropyCallback(sequence, provider, randomNumber);
}
// getEntropy returns Entropy contract address. The method is being used to check that the
// callback is indeed from Entropy contract. The consumer is expected to implement this method.
// Entropy address can be found here - https://docs.pyth.network/entropy/contract-addresses
function getEntropy() internal view virtual returns (address);
// This method is expected to be implemented by the consumer to handle the random number.
// It will be called by _entropyCallback after _entropyCallback ensures that the call is
// indeed from Entropy contract.
function entropyCallback(
uint64 sequence,
address provider,
bytes32 randomNumber
) internal virtual;
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
bool private _paused;
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
/**
* @dev The operation failed because the contract is paused.
*/
error EnforcedPause();
/**
* @dev The operation failed because the contract is not paused.
*/
error ExpectedPause();
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
if (paused()) {
revert EnforcedPause();
}
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
if (!paused()) {
revert ExpectedPause();
}
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
import "./EntropyStructs.sol";
interface EntropyEvents {
event Registered(EntropyStructs.ProviderInfo provider);
event Requested(EntropyStructs.Request request);
event RequestedWithCallback(
address indexed provider,
address indexed requestor,
uint64 indexed sequenceNumber,
bytes32 userRandomNumber,
EntropyStructs.Request request
);
event Revealed(
EntropyStructs.Request request,
bytes32 userRevelation,
bytes32 providerRevelation,
bytes32 blockHash,
bytes32 randomNumber
);
event RevealedWithCallback(
EntropyStructs.Request request,
bytes32 userRandomNumber,
bytes32 providerRevelation,
bytes32 randomNumber
);
event ProviderFeeUpdated(address provider, uint128 oldFee, uint128 newFee);
event ProviderUriUpdated(address provider, bytes oldUri, bytes newUri);
event ProviderFeeManagerUpdated(
address provider,
address oldFeeManager,
address newFeeManager
);
event Withdrawal(
address provider,
address recipient,
uint128 withdrawnAmount
);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.0;
contract EntropyStructs {
struct ProviderInfo {
uint128 feeInWei;
uint128 accruedFeesInWei;
// The commitment that the provider posted to the blockchain, and the sequence number
// where they committed to this. This value is not advanced after the provider commits,
// and instead is stored to help providers track where they are in the hash chain.
bytes32 originalCommitment;
uint64 originalCommitmentSequenceNumber;
// Metadata for the current commitment. Providers may optionally use this field to help
// manage rotations (i.e., to pick the sequence number from the correct hash chain).
bytes commitmentMetadata;
// Optional URI where clients can retrieve revelations for the provider.
// Client SDKs can use this field to automatically determine how to retrieve random values for each provider.
// TODO: specify the API that must be implemented at this URI
bytes uri;
// The first sequence number that is *not* included in the current commitment (i.e., an exclusive end index).
// The contract maintains the invariant that sequenceNumber <= endSequenceNumber.
// If sequenceNumber == endSequenceNumber, the provider must rotate their commitment to add additional random values.
uint64 endSequenceNumber;
// The sequence number that will be assigned to the next inbound user request.
uint64 sequenceNumber;
// The current commitment represents an index/value in the provider's hash chain.
// These values are used to verify requests for future sequence numbers. Note that
// currentCommitmentSequenceNumber < sequenceNumber.
//
// The currentCommitment advances forward through the provider's hash chain as values
// are revealed on-chain.
bytes32 currentCommitment;
uint64 currentCommitmentSequenceNumber;
// An address that is authorized to set / withdraw fees on behalf of this provider.
address feeManager;
}
struct Request {
// Storage slot 1 //
address provider;
uint64 sequenceNumber;
// The number of hashes required to verify the provider revelation.
uint32 numHashes;
// Storage slot 2 //
// The commitment is keccak256(userCommitment, providerCommitment). Storing the hash instead of both saves 20k gas by
// eliminating 1 store.
bytes32 commitment;
// Storage slot 3 //
// The number of the block where this request was created.
// Note that we're using a uint64 such that we have an additional space for an address and other fields in
// this storage slot. Although block.number returns a uint256, 64 bits should be plenty to index all of the
// blocks ever generated.
uint64 blockNumber;
// The address that requested this random number.
address requester;
// If true, incorporate the blockhash of blockNumber into the generated random value.
bool useBlockhash;
// If true, the requester will be called back with the generated random value.
bool isRequestWithCallback;
// There are 2 remaining bytes of free space in this slot.
}
}