-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Entropy Solidity SDK & usage example #1124
Changes from all commits
a73a8c0
d28c6b7
ec25f17
dea60db
421ed80
af47031
af54db8
ded9192
c93cbe4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// SPDX-License-Identifier: Apache 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is copy/paste of the interface from PythRandom. I've called this IEntropy to match the new name scheme. I'll circle back and rename the other contracts as well (didn't want to intermingle in this one PR). |
||
pragma solidity ^0.8.0; | ||
|
||
import "./PythRandomEvents.sol"; | ||
|
||
interface IEntropy is PythRandomEvents { | ||
// Register msg.sender as a randomness provider. The arguments are the provider's configuration parameters | ||
// and initial commitment. Re-registering the same provider rotates the provider's commitment (and updates | ||
// the feeInWei). | ||
// | ||
// chainLength is the number of values in the hash chain *including* the commitment, that is, chainLength >= 1. | ||
function register( | ||
uint feeInWei, | ||
bytes32 commitment, | ||
bytes32 commitmentMetadata, | ||
uint64 chainLength | ||
) external; | ||
|
||
// Withdraw a portion of the accumulated fees for the provider msg.sender. | ||
// Calling this function will transfer `amount` wei to the caller (provided that they have accrued a sufficient | ||
// balance of fees in the contract). | ||
function withdraw(uint256 amount) external; | ||
|
||
// As a user, request a random number from `provider`. Prior to calling this method, the user should | ||
// generate a random number x and keep it secret. The user should then compute hash(x) and pass that | ||
// as the userCommitment argument. (You may call the constructUserCommitment method to compute the hash.) | ||
// | ||
// This method returns a sequence number. The user should pass this sequence number to | ||
// their chosen provider (the exact method for doing so will depend on the provider) to retrieve the provider's | ||
// number. The user should then call fulfillRequest to construct the final random number. | ||
// | ||
// This method will revert unless the caller provides a sufficient fee (at least getFee(provider)) as msg.value. | ||
// Note that excess value is *not* refunded to the caller. | ||
function request( | ||
address provider, | ||
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. | ||
// | ||
// Note that this function can only be called once per in-flight request. Calling this function deletes the stored | ||
// request information (so that the contract doesn't use a linear amount of storage in the number of requests). | ||
// If you need to use the returned random number more than once, you are responsible for storing it. | ||
function reveal( | ||
address provider, | ||
uint64 sequenceNumber, | ||
bytes32 userRandomness, | ||
bytes32 providerRevelation | ||
) external returns (bytes32 randomNumber); | ||
|
||
function getProviderInfo( | ||
address provider | ||
) external view returns (PythRandomStructs.ProviderInfo memory info); | ||
|
||
function getRequest( | ||
address provider, | ||
uint64 sequenceNumber | ||
) external view returns (PythRandomStructs.Request memory req); | ||
|
||
function getFee(address provider) external view returns (uint feeAmount); | ||
|
||
function getAccruedPythFees() | ||
external | ||
view | ||
returns (uint accruedPythFeesInWei); | ||
|
||
function constructUserCommitment( | ||
bytes32 userRandomness | ||
) external pure returns (bytes32 userCommitment); | ||
|
||
function combineRandomValues( | ||
bytes32 userRandomness, | ||
bytes32 providerRandomness, | ||
bytes32 blockHash | ||
) external pure returns (bytes32 combinedRandomness); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "@pythnetwork/entropy-sdk-solidity", | ||
"version": "0.1.0", | ||
"description": "Generate secure random numbers with Pyth Entropy", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/pyth-network/pyth-crosschain", | ||
"directory": "target_chains/ethereum/entropy_sdk/solidity" | ||
}, | ||
"scripts": { | ||
"format": "npx prettier --write ." | ||
}, | ||
"keywords": [ | ||
"pyth", | ||
"solidity", | ||
"random" | ||
], | ||
"author": "Douro Labs", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/pyth-network/pyth-crosschain/issues" | ||
}, | ||
"homepage": "https://github.com/pyth-network/pyth-crosschain/tree/main/target_chains/ethereum/entropy_sdk/solidity", | ||
"devDependencies": { | ||
"prettier": "^2.7.1", | ||
"prettier-plugin-solidity": "^1.0.0-rc.1", | ||
"solc": "^0.8.15" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
lib/* | ||
!lib/README.md | ||
cache | ||
out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drive-by: deployed on some other networks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ToDo: contract manager support