-
Notifications
You must be signed in to change notification settings - Fork 47
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
Fix Cadence's unsafe random #459
Conversation
// which provides a source of entropy to fvm context (required for Cadence's randomness). | ||
type dummyEntropyProvider struct{} | ||
|
||
var dummySource = make([]byte, 32) |
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.
This causes randomness on emulator to be:
- deterministic
- same for all txs/blocks
Feel free to update this to be any behaviour you prefer.
Codecov Report
@@ Coverage Diff @@
## master #459 +/- ##
==========================================
+ Coverage 54.89% 55.00% +0.10%
==========================================
Files 28 28
Lines 3614 3620 +6
==========================================
+ Hits 1984 1991 +7
Misses 1470 1470
+ Partials 160 159 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
does this break mainnet/testnet transaction replay ( simulation ) ? Is there a way we can solve this ? maybe by getting block (transaction ) random seed from archive nodes or similar? |
yes, it does break it... but, like you said, we can fix it by exposing the random beacon. |
maybe we can add to transaction result as random seed. |
The issue with the source of randomness is that it is part of the block payload data not the execution state. Archive nodes and other nodes in general are not required to store these data for all the history (most of them only store data since the root block of the current spork only, but not before that).
Yes this is a good idea - We can restrict it only to transactions that used Cadence's random function, since most of the transactions do not need it. I have no idea how to plug that seed into the emulator later when replaying a transaction. Does this PR need further changes to accommodate that? |
I think we can merge this in the mean time, for sure random seed in tx result would take some time |
Hi @turbolent, Approximately when can this PR be included in a certain release of |
@btspoony I only assist with reviews in this project. Please open an issue in this and the CLI repo. Thank you! |
Closes onflow/cadence#2691
Emulator now supports Cadence random function(s). The randoms are currently deterministic and equal for all blocks.
For contributor use:
master
branchFiles changed
in the GitHub PR explorer