IEntropy.sol 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // SPDX-License-Identifier: Apache 2
  2. pragma solidity ^0.8.0;
  3. import "./EntropyEvents.sol";
  4. import "./EntropyEventsV2.sol";
  5. import "./EntropyStructsV2.sol";
  6. import "./IEntropyV2.sol";
  7. /// @notice DEPRECATED: This interface is deprecated. Please use IEntropyV2 instead for new implementations.
  8. /// IEntropyV2 provides better callback handling and improved functionality.
  9. interface IEntropy is EntropyEvents, EntropyEventsV2, IEntropyV2 {
  10. // Register msg.sender as a randomness provider. The arguments are the provider's configuration parameters
  11. // and initial commitment. Re-registering the same provider rotates the provider's commitment (and updates
  12. // the feeInWei).
  13. //
  14. // chainLength is the number of values in the hash chain *including* the commitment, that is, chainLength >= 1.
  15. function register(
  16. uint128 feeInWei,
  17. bytes32 commitment,
  18. bytes calldata commitmentMetadata,
  19. uint64 chainLength,
  20. bytes calldata uri
  21. ) external;
  22. // Withdraw a portion of the accumulated fees for the provider msg.sender.
  23. // Calling this function will transfer `amount` wei to the caller (provided that they have accrued a sufficient
  24. // balance of fees in the contract).
  25. function withdraw(uint128 amount) external;
  26. // Withdraw a portion of the accumulated fees for provider. The msg.sender must be the fee manager for this provider.
  27. // Calling this function will transfer `amount` wei to the caller (provided that they have accrued a sufficient
  28. // balance of fees in the contract).
  29. function withdrawAsFeeManager(address provider, uint128 amount) external;
  30. // As a user, request a random number from `provider`. Prior to calling this method, the user should
  31. // generate a random number x and keep it secret. The user should then compute hash(x) and pass that
  32. // as the userCommitment argument. (You may call the constructUserCommitment method to compute the hash.)
  33. //
  34. // This method returns a sequence number. The user should pass this sequence number to
  35. // their chosen provider (the exact method for doing so will depend on the provider) to retrieve the provider's
  36. // number. The user should then call fulfillRequest to construct the final random number.
  37. //
  38. // WARNING: This method does NOT invoke a user callback. If you need callback functionality,
  39. // use requestV2 from the IEntropyV2 interface instead.
  40. //
  41. // This method will revert unless the caller provides a sufficient fee (at least getFee(provider)) as msg.value.
  42. // Note that excess value is *not* refunded to the caller.
  43. function request(
  44. address provider,
  45. bytes32 userCommitment,
  46. bool useBlockHash
  47. ) external payable returns (uint64 assignedSequenceNumber);
  48. // Request a random number. The method expects the provider address and a secret random number
  49. // in the arguments. It returns a sequence number.
  50. //
  51. // DEPRECATED: This method is deprecated. Please use requestV2 from the IEntropyV2 interface instead,
  52. // which provides better callback handling and gas limit control.
  53. //
  54. // The address calling this function should be a contract that inherits from the IEntropyConsumer interface.
  55. // The `entropyCallback` method on that interface will receive a callback with the generated random number.
  56. // `entropyCallback` will be run with the provider's default gas limit (see `getProviderInfo(provider).defaultGasLimit`).
  57. // If your callback needs additional gas, please use the function `requestv2` from `IEntropyV2` interface
  58. // with gasLimit as the input parameter.
  59. //
  60. // This method will revert unless the caller provides a sufficient fee (at least `getFee(provider)`) as msg.value.
  61. // Note that excess value is *not* refunded to the caller.
  62. function requestWithCallback(
  63. address provider,
  64. bytes32 userRandomNumber
  65. ) external payable returns (uint64 assignedSequenceNumber);
  66. // Fulfill a request for a random number. This method validates the provided userRandomness and provider's proof
  67. // against the corresponding commitments in the in-flight request. If both values are validated, this function returns
  68. // the corresponding random number.
  69. //
  70. // Note that this function can only be called once per in-flight request. Calling this function deletes the stored
  71. // request information (so that the contract doesn't use a linear amount of storage in the number of requests).
  72. // If you need to use the returned random number more than once, you are responsible for storing it.
  73. function reveal(
  74. address provider,
  75. uint64 sequenceNumber,
  76. bytes32 userRevelation,
  77. bytes32 providerRevelation
  78. ) external returns (bytes32 randomNumber);
  79. // Fulfill a request for a random number. This method validates the provided userRandomness
  80. // and provider's revelation against the corresponding commitment in the in-flight request. If both values are validated
  81. // and the requestor address is a contract address, this function calls the requester's entropyCallback method with the
  82. // sequence number, provider address and the random number as arguments. Else if the requestor is an EOA, it won't call it.
  83. //
  84. // Note that this function can only be called once per in-flight request. Calling this function deletes the stored
  85. // request information (so that the contract doesn't use a linear amount of storage in the number of requests).
  86. // If you need to use the returned random number more than once, you are responsible for storing it.
  87. //
  88. // Anyone can call this method to fulfill a request, but the callback will only be made to the original requester.
  89. function revealWithCallback(
  90. address provider,
  91. uint64 sequenceNumber,
  92. bytes32 userRandomNumber,
  93. bytes32 providerRevelation
  94. ) external;
  95. function getProviderInfo(
  96. address provider
  97. ) external view returns (EntropyStructs.ProviderInfo memory info);
  98. function getRequest(
  99. address provider,
  100. uint64 sequenceNumber
  101. ) external view returns (EntropyStructs.Request memory req);
  102. // Get the fee charged by provider for a request with the default gasLimit (`request` or `requestWithCallback`).
  103. // If you are calling any of the `requestV2` methods, please use `getFeeV2`.
  104. function getFee(address provider) external view returns (uint128 feeAmount);
  105. function getAccruedPythFees()
  106. external
  107. view
  108. returns (uint128 accruedPythFeesInWei);
  109. function setProviderFee(uint128 newFeeInWei) external;
  110. function setProviderFeeAsFeeManager(
  111. address provider,
  112. uint128 newFeeInWei
  113. ) external;
  114. function setProviderUri(bytes calldata newUri) external;
  115. // Set manager as the fee manager for the provider msg.sender.
  116. // After calling this function, manager will be able to set the provider's fees and withdraw them.
  117. // Only one address can be the fee manager for a provider at a time -- calling this function again with a new value
  118. // will override the previous value. Call this function with the all-zero address to disable the fee manager role.
  119. function setFeeManager(address manager) external;
  120. // Set the maximum number of hashes to record in a request. This should be set according to the maximum gas limit
  121. // the provider supports for callbacks.
  122. function setMaxNumHashes(uint32 maxNumHashes) external;
  123. // Set the default gas limit for a request. If 0, no
  124. function setDefaultGasLimit(uint32 gasLimit) external;
  125. // Advance the provider commitment and increase the sequence number.
  126. // This is used to reduce the `numHashes` required for future requests which leads to reduced gas usage.
  127. function advanceProviderCommitment(
  128. address provider,
  129. uint64 advancedSequenceNumber,
  130. bytes32 providerRevelation
  131. ) external;
  132. function constructUserCommitment(
  133. bytes32 userRandomness
  134. ) external pure returns (bytes32 userCommitment);
  135. function combineRandomValues(
  136. bytes32 userRandomness,
  137. bytes32 providerRandomness,
  138. bytes32 blockHash
  139. ) external pure returns (bytes32 combinedRandomness);
  140. }