Created
March 10, 2022 17:34
-
-
Save jackpmorgan/d350953ba254e3ec54c740dca470fdcc to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.12+commit.f00d7308.js&optimize=false&runs=200&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
contract VRFRequestIDBase { | |
/** | |
* @notice returns the seed which is actually input to the VRF coordinator | |
* | |
* @dev To prevent repetition of VRF output due to repetition of the | |
* @dev user-supplied seed, that seed is combined in a hash with the | |
* @dev user-specific nonce, and the address of the consuming contract. The | |
* @dev risk of repetition is mostly mitigated by inclusion of a blockhash in | |
* @dev the final seed, but the nonce does protect against repetition in | |
* @dev requests which are included in a single block. | |
* | |
* @param _userSeed VRF seed input provided by user | |
* @param _requester Address of the requesting contract | |
* @param _nonce User-specific nonce at the time of the request | |
*/ | |
function makeVRFInputSeed( | |
bytes32 _keyHash, | |
uint256 _userSeed, | |
address _requester, | |
uint256 _nonce | |
) internal pure returns (uint256) { | |
return uint256(keccak256(abi.encode(_keyHash, _userSeed, _requester, _nonce))); | |
} | |
/** | |
* @notice Returns the id for this request | |
* @param _keyHash The serviceAgreement ID to be used for this request | |
* @param _vRFInputSeed The seed to be passed directly to the VRF | |
* @return The id for this request | |
* | |
* @dev Note that _vRFInputSeed is not the seed passed by the consuming | |
* @dev contract, but the one generated by makeVRFInputSeed | |
*/ | |
function makeRequestId(bytes32 _keyHash, uint256 _vRFInputSeed) internal pure returns (bytes32) { | |
return keccak256(abi.encodePacked(_keyHash, _vRFInputSeed)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment