-
Notifications
You must be signed in to change notification settings - Fork 180
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
[EVM] Add get random source to Cadence Arch #5742
Conversation
func RandomBeaconAddress(chainID flow.ChainID) flow.Address { | ||
return systemcontracts.SystemContractsForChain(chainID).RandomBeaconHistory.Address | ||
} | ||
|
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.
Does this have to be here, given we pass the chainID to the underlying layer. I know we do this for storage account but I think that's a legacy from the time EVM storage address was not part of system contracts.
func(u uint64) (uint64, error) { | ||
return rand, nil |
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.
I might add a line here to check if the input that is received is what is expected.
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.
good idea yeah
uint64 output = abi.decode(data, (uint64)); | ||
return output; |
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.
I usually use the verify methods to verify the output matches what is expected, for example see the verifyArchCallToFlowBlockHeight , we check the output produced matches the expected.
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.
I did that in Go test, but it makes sense to adpot the pattern you made
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.
Nice work 👏 , just added some minor comments
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.
very nice!
Closes: #5507
This PR implements a new function on the Cadence Arch precompile contract, that exposes access to Flow RandomBeaconHistory contract. This allows for retrieving a random source in the EVM which can be used as a seed for any PRG implementations.
The new method could be called like so:
It also allows for implementing commit-reveal schemes which are required for a lot of applications and was discussed on Discord: https://discord.com/channels/613813861610684416/1230199673629835375
We must keep in mind that the new function for obtaining random source relies on Cadence block heights not EVM block heights, which are not co-related but this is fine since we can use the get latest flow height function also available on Cadence arch.
@sisyphusSmiling even made a proof of concept that abstracts away this implementation detail https://gist.github.com/sisyphusSmiling/3e58dc3827c69afd038abe65ef8dda92