IEntropy.sol 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // SPDX-License-Identifier: Apache 2
  2. pragma solidity ^0.8.0;
  3. import "./EntropyEvents.sol";
  4. interface IEntropy is EntropyEvents {
  5. // Register msg.sender as a randomness provider. The arguments are the provider's configuration parameters
  6. // and initial commitment. Re-registering the same provider rotates the provider's commitment (and updates
  7. // the feeInWei).
  8. //
  9. // chainLength is the number of values in the hash chain *including* the commitment, that is, chainLength >= 1.
  10. function register(
  11. uint feeInWei,
  12. bytes32 commitment,
  13. bytes32 commitmentMetadata,
  14. uint64 chainLength
  15. ) external;
  16. // Withdraw a portion of the accumulated fees for the provider msg.sender.
  17. // Calling this function will transfer `amount` wei to the caller (provided that they have accrued a sufficient
  18. // balance of fees in the contract).
  19. function withdraw(uint256 amount) external;
  20. // As a user, request a random number from `provider`. Prior to calling this method, the user should
  21. // generate a random number x and keep it secret. The user should then compute hash(x) and pass that
  22. // as the userCommitment argument. (You may call the constructUserCommitment method to compute the hash.)
  23. //
  24. // This method returns a sequence number. The user should pass this sequence number to
  25. // their chosen provider (the exact method for doing so will depend on the provider) to retrieve the provider's
  26. // number. The user should then call fulfillRequest to construct the final random number.
  27. //
  28. // This method will revert unless the caller provides a sufficient fee (at least getFee(provider)) as msg.value.
  29. // Note that excess value is *not* refunded to the caller.
  30. function request(
  31. address provider,
  32. bytes32 userCommitment,
  33. bool useBlockHash
  34. ) external payable returns (uint64 assignedSequenceNumber);
  35. // Fulfill a request for a random number. This method validates the provided userRandomness and provider's proof
  36. // against the corresponding commitments in the in-flight request. If both values are validated, this function returns
  37. // the corresponding random number.
  38. //
  39. // Note that this function can only be called once per in-flight request. Calling this function deletes the stored
  40. // request information (so that the contract doesn't use a linear amount of storage in the number of requests).
  41. // If you need to use the returned random number more than once, you are responsible for storing it.
  42. function reveal(
  43. address provider,
  44. uint64 sequenceNumber,
  45. bytes32 userRandomness,
  46. bytes32 providerRevelation
  47. ) external returns (bytes32 randomNumber);
  48. function getProviderInfo(
  49. address provider
  50. ) external view returns (EntropyStructs.ProviderInfo memory info);
  51. function getRequest(
  52. address provider,
  53. uint64 sequenceNumber
  54. ) external view returns (EntropyStructs.Request memory req);
  55. function getFee(address provider) external view returns (uint feeAmount);
  56. function getAccruedPythFees()
  57. external
  58. view
  59. returns (uint accruedPythFeesInWei);
  60. function constructUserCommitment(
  61. bytes32 userRandomness
  62. ) external pure returns (bytes32 userCommitment);
  63. function combineRandomValues(
  64. bytes32 userRandomness,
  65. bytes32 providerRandomness,
  66. bytes32 blockHash
  67. ) external pure returns (bytes32 combinedRandomness);
  68. }