Skip to content
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

Add base & implementation solidity contracts to demo secure randomness #20

Merged
merged 21 commits into from
Sep 20, 2024

Conversation

sisyphusSmiling
Copy link
Contributor

@sisyphusSmiling sisyphusSmiling commented Sep 17, 2024

Closes: #17

Description

  • Adds a Solidity implementation of CoinToss, extending a proposed secure random consumer abstract contract
  • Adds Cadence transactions to allow a COA to interact with the Solidity CoinToss implementation
  • Updates Cadence dependencies to use Mainnet deployments
  • Updates the README to include information about EVM implementations

@sisyphusSmiling sisyphusSmiling changed the title Add solidity implementation Add solidity implementation for secure randomness Sep 17, 2024
@sisyphusSmiling sisyphusSmiling marked this pull request as ready for review September 17, 2024 22:27
@sisyphusSmiling sisyphusSmiling requested a review from a team as a code owner September 17, 2024 22:27
@sisyphusSmiling sisyphusSmiling changed the title Add solidity implementation for secure randomness Add solidity base & implementation contracts to demo secure randomness Sep 17, 2024
@sisyphusSmiling sisyphusSmiling changed the title Add solidity base & implementation contracts to demo secure randomness Add base & implementation solidity contracts to demo secure randomness Sep 17, 2024
Copy link
Collaborator

@tarakby tarakby left a comment

Choose a reason for hiding this comment

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

Great docs and nice example 👏🏼

I've added minor comments about the mentions of PRG. I noticed from other discussions that PRGs and their purpose have been causing confusion so I suggest to only mention them when needed (their purpose being to expand a small source into many bytes)

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
solidity/src/CadenceRandomConsumer.sol Show resolved Hide resolved
Copy link

@ramtinms ramtinms left a comment

Choose a reason for hiding this comment

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

nice 👏


// fulfill the random request
uint64 randomResult = _fulfillRandomness(uint32(requestId));
uint8 coinFace = uint8(randomResult % 2);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tarakby is it safe to use modulo here to represent a resulting heads or tails?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes the modulo use is safe when the modulo divides the initial random range. For instance here 2 divides 2^64. In this case there won't be any bias

@sisyphusSmiling
Copy link
Contributor Author

I was running into issues with getRandomSource calls to Cadence Arch, but have since fixed them and validated that the contract is operational on Testnet.

@sisyphusSmiling sisyphusSmiling merged commit 92e7520 into main Sep 20, 2024
2 checks passed
@sisyphusSmiling sisyphusSmiling deleted the add-solidity-impl branch September 20, 2024 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add Solidity implementation using EVM randomness
3 participants