IEntropy.sol 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. uint128 feeInWei,
  12. bytes32 commitment,
  13. bytes calldata commitmentMetadata,
  14. uint64 chainLength,
  15. bytes calldata uri
  16. ) external;
  17. // Withdraw a portion of the accumulated fees for the provider msg.sender.
  18. // Calling this function will transfer `amount` wei to the caller (provided that they have accrued a sufficient
  19. // balance of fees in the contract).
  20. function withdraw(uint128 amount) external;
  21. // As a user, request a random number from `provider`. Prior to calling this method, the user should
  22. // generate a random number x and keep it secret. The user should then compute hash(x) and pass that
  23. // as the userCommitment argument. (You may call the constructUserCommitment method to compute the hash.)
  24. //
  25. // This method returns a sequence number. The user should pass this sequence number to
  26. // their chosen provider (the exact method for doing so will depend on the provider) to retrieve the provider's
  27. // number. The user should then call fulfillRequest to construct the final random number.
  28. //
  29. // This method will revert unless the caller provides a sufficient fee (at least getFee(provider)) as msg.value.
  30. // Note that excess value is *not* refunded to the caller.
  31. function request(
  32. address provider,
  33. bytes32 userCommitment,
  34. bool useBlockHash
  35. ) external payable returns (uint64 assignedSequenceNumber);
  36. // Fulfill a request for a random number. This method validates the provided userRandomness and provider's proof
  37. // against the corresponding commitments in the in-flight request. If both values are validated, this function returns
  38. // the corresponding random number.
  39. //
  40. // Note that this function can only be called once per in-flight request. Calling this function deletes the stored
  41. // request information (so that the contract doesn't use a linear amount of storage in the number of requests).
  42. // If you need to use the returned random number more than once, you are responsible for storing it.
  43. function reveal(
  44. address provider,
  45. uint64 sequenceNumber,
  46. bytes32 userRandomness,
  47. bytes32 providerRevelation
  48. ) external returns (bytes32 randomNumber);
  49. function getProviderInfo(
  50. address provider
  51. ) external view returns (EntropyStructs.ProviderInfo memory info);
  52. function getDefaultProvider() external view returns (address provider);
  53. function getRequest(
  54. address provider,
  55. uint64 sequenceNumber
  56. ) external view returns (EntropyStructs.Request memory req);
  57. function getFee(address provider) external view returns (uint128 feeAmount);
  58. function getAccruedPythFees()
  59. external
  60. view
  61. returns (uint128 accruedPythFeesInWei);
  62. function setProviderFee(uint128 newFeeInWei) external;
  63. function setProviderUri(bytes calldata newUri) external;
  64. function constructUserCommitment(
  65. bytes32 userRandomness
  66. ) external pure returns (bytes32 userCommitment);
  67. function combineRandomValues(
  68. bytes32 userRandomness,
  69. bytes32 providerRandomness,
  70. bytes32 blockHash
  71. ) external pure returns (bytes32 combinedRandomness);
  72. }