Skip to content

Update randomness doc #1281

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

Merged
merged 4 commits into from
May 12, 2025
Merged

Update randomness doc #1281

merged 4 commits into from
May 12, 2025

Conversation

tarakby
Copy link
Contributor

@tarakby tarakby commented May 12, 2025

No description provided.

Copy link

vercel bot commented May 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 12, 2025 9:13pm

* This hook is designed for simple use cases that **don’t require a [commit-reveal scheme]**, such as randomized UIs.
* For **more advanced use cases** that **do** require a [commit-reveal scheme], Flow provides built-in support for that pattern.
* Values are **deterministic**: if a transaction fails and retries, the same random value will be regenerated.
* Randomness is generated using Flow’s **on-chain `revertibleRandom`**, producing pseudorandom values tied to block and script execution.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are no transactions in this case, it's all script based (under the hood, this makes a difference in how randomness works).

* For **more advanced use cases** that **do** require a [commit-reveal scheme], Flow provides built-in support for that pattern.
* Values are **deterministic**: if a transaction fails and retries, the same random value will be regenerated.
* Randomness is generated using Flow’s **on-chain `revertibleRandom`**, producing pseudorandom values tied to block and script execution.
* Values are **deterministic**: The values returned for identical calls within the same block will be identical.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is described here in determinism, so I moved the "deterministic" note here

* Values are **deterministic**: if a transaction fails and retries, the same random value will be regenerated.
* Randomness is generated using Flow’s **on-chain `revertibleRandom`**, producing pseudorandom values tied to block and script execution.
* Values are **deterministic**: The values returned for identical calls within the same block will be identical.
* If `count ` is larger than one, the returned values are disctinct.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added this so that developers don't think determinism means all count values are equal

* Randomness is generated using Flow’s **on-chain `revertibleRandom`**, producing pseudorandom values tied to block and script execution.
* Values are **deterministic**: The values returned for identical calls within the same block will be identical.
* If `count ` is larger than one, the returned values are disctinct.
* This hook is designed for simple use cases that don't require unpredictability, such as randomized UIs.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit-reveal solves the reversibility issue, but here in the script nothing is reversible so commit-reveal doesn't add any advantage.

The main thing developers should be aware of is that the block random source in the lib is publicly known (since this is script-based). There is nothing wrong with that in many applications like the example mentioned here (UIs)

* If `count ` is larger than one, the returned values are disctinct.
* This hook is designed for simple use cases that don't require unpredictability, such as randomized UIs.
Since the hook uses script executions on existing blocks, Flow's randon source is already public and the randoms are predictable.
* For **more advanced use cases** that **do** require on-chain randomness logic via transactions, Flow provides built-in support using Cadence's `revertibleRandom` and [commit-reveal scheme].
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more advanced cases are the ones with the logic fully on-chain via transactions (not scripts). This is where randomness is unpredictable, and reversibility can or cannot be an issue, so I added the mention of transactions here. Both "reversibleRandom" and "commit-reveal" work in that case depending on the app.

@tarakby tarakby marked this pull request as ready for review May 12, 2025 19:00
Co-authored-by: Chase Fleming <chasefleming@users.noreply.github.com>
@briandoyle81 briandoyle81 merged commit 8fcbb48 into main May 12, 2025
2 of 3 checks passed
@briandoyle81 briandoyle81 deleted the tarakby-useRandom branch May 12, 2025 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants