Skip to content

Commit

Permalink
making a mess here
Browse files Browse the repository at this point in the history
  • Loading branch information
jayantk committed Nov 24, 2023
1 parent 2b118c1 commit 210d753
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
36 changes: 35 additions & 1 deletion target_chains/ethereum/contracts/contracts/entropy/Entropy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ import "./EntropyState.sol";
// - off-chain data ERC support?
contract Entropy is IEntropy, EntropyState {
// TODO: Use an upgradeable proxy
constructor(uint pythFeeInWei) {
constructor(uint pythFeeInWei, address defaultProvider) {
_state.accruedPythFeesInWei = 0;
_state.pythFeeInWei = pythFeeInWei;
_state.defaultProvider = defaultProvider;
}

// Register msg.sender as a randomness provider. The arguments are the provider's configuration parameters
Expand Down Expand Up @@ -195,6 +196,17 @@ contract Entropy is IEntropy, EntropyState {
emit Requested(req);
}

function request(
bytes32 userCommitment,
bool useBlockHash
) external payable override returns (uint64 assignedSequenceNumber) {
assignedSequenceNumber = request(
getDefaultProvider(),
userCommitment,
useBlockHash
);
}

// Fulfill a request for a random number. This method validates the provided userRandomness and provider's proof
// against the corresponding commitments in the in-flight request. If both values are validated, this function returns
// the corresponding random number.
Expand Down Expand Up @@ -257,12 +269,34 @@ contract Entropy is IEntropy, EntropyState {
}
}

function reveal(
uint64 sequenceNumber,
bytes32 userRandomness,
bytes32 providerRevelation
) external override returns (bytes32 randomNumber) {
randomNumber = reveal(
getDefaultProvider(),
sequenceNumber,
userRandomness,
providerRevelation
);
}

function getProviderInfo(
address provider
) public view override returns (EntropyStructs.ProviderInfo memory info) {
info = _state.providers[provider];
}

function getDefaultProvider()
public
view
override
returns (address provider)
{
provider = _state.defaultProvider;
}

function getRequest(
address provider,
uint64 sequenceNumber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ contract EntropyInternalStructs {
struct State {
uint pythFeeInWei;
uint accruedPythFeesInWei;
address defaultProvider;
mapping(address => EntropyStructs.ProviderInfo) providers;
mapping(bytes32 => EntropyStructs.Request) requests;
}
Expand Down
6 changes: 5 additions & 1 deletion target_chains/ethereum/contracts/forge-test/Entropy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ contract EntropyTest is Test {
bytes32 ALL_ZEROS = bytes32(uint256(0));

function setUp() public {
random = new Entropy(pythFeeInWei);
random = new Entropy(pythFeeInWei, provider1);

bytes32[] memory hashChain1 = generateHashChain(
provider1,
Expand Down Expand Up @@ -486,4 +486,8 @@ contract EntropyTest is Test {
vm.expectRevert();
random.withdraw(providerOneBalance);
}

function testDefaultProvider() {
assert()
}
}
15 changes: 15 additions & 0 deletions target_chains/ethereum/entropy_sdk/solidity/IEntropy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ interface IEntropy is EntropyEvents {
bool useBlockHash
) external payable returns (uint64 assignedSequenceNumber);

// Same as `request` above using the default randomness provider configured in the contract.
function request(
bytes32 userCommitment,
bool useBlockHash
) external payable returns (uint64 assignedSequenceNumber);

// Fulfill a request for a random number. This method validates the provided userRandomness and provider's proof
// against the corresponding commitments in the in-flight request. If both values are validated, this function returns
// the corresponding random number.
Expand All @@ -51,10 +57,19 @@ interface IEntropy is EntropyEvents {
bytes32 providerRevelation
) external returns (bytes32 randomNumber);

// Same as `reveal` above using the default randomness provider configured in the contract.
function reveal(
uint64 sequenceNumber,
bytes32 userRandomness,
bytes32 providerRevelation
) external returns (bytes32 randomNumber);

function getProviderInfo(
address provider
) external view returns (EntropyStructs.ProviderInfo memory info);

function getDefaultProvider() external view returns (address provider);

function getRequest(
address provider,
uint64 sequenceNumber
Expand Down

0 comments on commit 210d753

Please sign in to comment.