EntropyStructs.sol 3.5 KB

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