onflow / developer-grants

Grants for developers that contribute to the broader developer ecosystem
Apache License 2.0
50 stars 18 forks source link

PRNG - Pseudo Random Number Generator #104

Open justjoolz opened 1 year ago

justjoolz commented 1 year ago

PRNG - Pseudo Random Number Generator

Grant category

Please select one:

Description

A fully on-chain pseudo-random number generator written in Cadence and an off-chain Javascript equivalent that uses the exact same seeding mechanism (blockHash mixed with resourceID) and hence replicates the same stream of random data.

Problem statement

Using randomness is a big part of many NFT drops (randomized traits) and it's usually always done off-chain. This means it's harder to achieve transparency (most projects don't even attempt to). Also, it's prone to manipulation as has happened to several of Dapper's products.

Developers + creators who value transparency.

15 posts on the forum mentioning randomness: https://forum.onflow.org/search?q=random and plenty in discord too, a very common question with no solutions

Off-chain randomness exploits:

https://blog.nbatopshot.com/posts/elite-pack-distribution-audit https://blog.nflallday.com/posts/update-rams-team-nft-drop https://nftevening.com/dapper-labs-hand-out-free-nfts-after-their-ufc-drop-is-a-total-disaster/

Proposed solution

A resource-based PRNG that lives in its own contract and can supply a stream of randomness from a provided initial seed.

Including helper functions for picking numbers in more useful and dev-friendly ways than unsafeRandom provides.

ie. pickFrom(["sandwich","noodles", [1,9] ) one in ten chance I get a sandwich, 9/10 noodles range(10,15) returns a random number between 10 and 15

Impact

This will allow developers to use randomness in their contracts in a far safer and more versatile way than is currently offered.

Milestones and funding

Milestone Deliverables Timeline Risks USD proposal
1 - MVP Implementation with detailed documentation in git repo including usage examples 1 month - 5k
X - Expansion Write a series of in-depth articles showcasing and detailing a variety of possible implementation patterns with their pros+cons 2 months - 10k
X - Maintenance + Adoption Resolving users' issues and providing hands-on support to developers who wish to safely and securely use randomization in their Dapps. At least 3 projects using PRNG on mainnet 3 months - 10k

Total funding proposed: 25k

Team

Name Role Bio Contact
Julian Developer Flow community representative + FlipFest winner justjoolz@gmail.com
chrisackermann commented 1 year ago

Hi @justjoolz - thanks again for your proposal! We're reviewing and will follow up shortly.

chrisackermann commented 1 year ago

Hi @justjoolz - thanks for your patience! Just wanted to let you know that we've accepted this submission and will be following up directly with next steps. Thanks!

justjoolz commented 1 year ago

Hi @chrisackermann - thanks for the great news!