EntropyStructs.sol 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-License-Identifier: Apache 2
  2. pragma solidity ^0.8.0;
  3. // This contract holds old versions of the Entropy structs that are no longer used for contract storage.
  4. // However, they are still used in EntropyEvents to maintain the public interface of prior versions of
  5. // the Entropy contract.
  6. //
  7. // See EntropyStructsV2 for the struct definitions currently in use.
  8. contract EntropyStructs {
  9. struct ProviderInfo {
  10. uint128 feeInWei;
  11. uint128 accruedFeesInWei;
  12. // The commitment that the provider posted to the blockchain, and the sequence number
  13. // where they committed to this. This value is not advanced after the provider commits,
  14. // and instead is stored to help providers track where they are in the hash chain.
  15. bytes32 originalCommitment;
  16. uint64 originalCommitmentSequenceNumber;
  17. // Metadata for the current commitment. Providers may optionally use this field to help
  18. // manage rotations (i.e., to pick the sequence number from the correct hash chain).
  19. bytes commitmentMetadata;
  20. // Optional URI where clients can retrieve revelations for the provider.
  21. // Client SDKs can use this field to automatically determine how to retrieve random values for each provider.
  22. // TODO: specify the API that must be implemented at this URI
  23. bytes uri;
  24. // The first sequence number that is *not* included in the current commitment (i.e., an exclusive end index).
  25. // The contract maintains the invariant that sequenceNumber <= endSequenceNumber.
  26. // If sequenceNumber == endSequenceNumber, the provider must rotate their commitment to add additional random values.
  27. uint64 endSequenceNumber;
  28. // The sequence number that will be assigned to the next inbound user request.
  29. uint64 sequenceNumber;
  30. // The current commitment represents an index/value in the provider's hash chain.
  31. // These values are used to verify requests for future sequence numbers. Note that
  32. // currentCommitmentSequenceNumber < sequenceNumber.
  33. //
  34. // The currentCommitment advances forward through the provider's hash chain as values
  35. // are revealed on-chain.
  36. bytes32 currentCommitment;
  37. uint64 currentCommitmentSequenceNumber;
  38. // An address that is authorized to set / withdraw fees on behalf of this provider.
  39. address feeManager;
  40. // Maximum number of hashes to record in a request. This should be set according to the maximum gas limit
  41. // the provider supports for callbacks.
  42. uint32 maxNumHashes;
  43. }
  44. struct Request {
  45. // Storage slot 1 //
  46. address provider;
  47. uint64 sequenceNumber;
  48. // The number of hashes required to verify the provider revelation.
  49. uint32 numHashes;
  50. // Storage slot 2 //
  51. // The commitment is keccak256(userCommitment, providerCommitment). Storing the hash instead of both saves 20k gas by
  52. // eliminating 1 store.
  53. bytes32 commitment;
  54. // Storage slot 3 //
  55. // The number of the block where this request was created.
  56. // Note that we're using a uint64 such that we have an additional space for an address and other fields in
  57. // this storage slot. Although block.number returns a uint256, 64 bits should be plenty to index all of the
  58. // blocks ever generated.
  59. uint64 blockNumber;
  60. // The address that requested this random number.
  61. address requester;
  62. // If true, incorporate the blockhash of blockNumber into the generated random value.
  63. bool useBlockhash;
  64. // True if this is a request that expects a callback.
  65. bool isRequestWithCallback;
  66. }
  67. }