Add Pyth Entropy lottery example with IEntropyV2 #68
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pyth Examples Contribution
Type of Contribution
Project Information
Project/Example Name: Lottery with Pyth Entropy
Pyth Product Used:
Blockchain/Platform:
Description
What does this contribution do?
This PR adds a complete lottery application example that demonstrates advanced usage of Pyth Entropy for provably fair random number generation. Unlike simple lottery implementations, this example ensures each ticket purchase draws its own unique random number from Pyth Entropy, and the winner is determined by which ticket's random number is closest to a final target random number.
The implementation includes:
Lottery.sol): Implements lottery logic usingIEntropyV2interfaceHow does it integrate with Pyth?
The contract uses Pyth Entropy V2 (
IEntropyV2) for verifiable randomness:buyTicket()call triggersentropy.requestV2()to request a unique random numberIEntropyConsumer.entropyCallback()to receive random numbersentropy.getFeeV2()Key implementation detail: The callback function distinguishes between ticket random numbers and the final winning number using sequence number comparison.
What problem does it solve or demonstrate?
This example demonstrates:
requestV2()callsDirectory Structure
Testing & Verification
How to Test This Contribution
Prerequisites
Setup & Deployment
Deployment Information
Networks Configured: Blast Sepolia, Optimism Sepolia, Arbitrum Sepolia
Entropy Addresses Used (from deployment module):
0x98046Bd286715D3B0BC227Dd7a956b83D8978603(Blast Sepolia)0x6CC14824Ea2918f5De5C2f75A9Da968ad4BD6344Ticket Price: 0.001 ETH (configurable in deployment script)
Checklist
Code Quality
coin_flipandgrowingexamples)Testing
Important Review Points
Critical Areas for Review
Callback Logic (
Lottery.sol:127-184):Winner Calculation (
Lottery.sol:236-240):IEntropyV2 Usage:
requestV2()without user random number (relies on in-contract PRNG)Edge Cases:
endLottery()is called with 0 tickets? ✓ Handled (reverts with NoTicketsSold)fulfilledtickets considered)Gas Optimization:
Configuration Verification Needed
Additional Context
Requested by: Jayant ([email protected]) / @jayantk
Session: https://app.devin.ai/sessions/f9d9e77ce0ca41f1a17358d6092311da
Key Requirements Met:
entropy/directoryNotes for Reviewers:
0x0000...) must be updated post-deploymentThank you for reviewing! Please pay special attention to the callback logic and edge cases around unfulfilled random numbers.