sui icon indicating copy to clipboard operation
sui copied to clipboard

Add RandomGenerator to Sui Framework

Open benr-ml opened this issue 1 year ago • 3 comments

Description

Add interfaces for fetching randomness: RandomGenerator is a PRG with a seed that is derived from the global randomness (which is the same between randomness rounds) and a fresh UID (which is guaranteed to be unique by the framework). In other words, the seed is unpredictable without knowing the global randomness, and different for each created generator (thus not predictable even by different functions invoked for the same tx).

RandomGenerator manages an internal state with a buffer of random bytes derived using the PRG, and provides high level functions for deriving integers from those random bytes.

Test Plan

Unit tests


If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process.

Type of Change (Check all that apply)

  • [ ] protocol change
  • [ ] user-visible impact
  • [ ] breaking change for a client SDKs
  • [x] breaking change for FNs (FN binary must upgrade)
  • [x] breaking change for validators or node operators (must upgrade binaries)
  • [ ] breaking change for on-chain data layout
  • [ ] necessitate either a data wipe or data migration

Release notes

benr-ml avatar Nov 23 '23 20:11 benr-ml

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

Name Status Preview Comments Updated (UTC)
explorer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2024 2:37pm
multisig-toolkit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2024 2:37pm
mysten-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2024 2:37pm
sui-core ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2024 2:37pm
sui-kiosk ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2024 2:37pm
sui-typescript-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2024 2:37pm

vercel[bot] avatar Nov 23 '23 20:11 vercel[bot]

All the interfaces are in. I didn't complete the tests yet but wanted to receive the first round of feedbacks before I add snapshots, etc.

@dariorussi , please let me know if the design makes sense, and whether any of the functions better be implemented as native ones. @jonas-lj , please review the different crypto "conversions".

@kchalkias , @aschran - CCed in case you have comments as well.

benr-ml avatar Nov 24 '23 18:11 benr-ml

The examples are currently insecure because of composition, please ignore them for now

benr-ml avatar Dec 05 '23 14:12 benr-ml

Waiting with updating the snapshots until we finish the review of the Move code.

benr-ml avatar Feb 21 '24 13:02 benr-ml

in case it helps.... 1- go to <sui>/crates/sui-framework/packages/sui-framework 2- run sui move test --coverage 3- sui move coverage summary will give you a summary of the percentage coverage for every module in the framework 4- sui move coverage bytecode --module random will tell you which bytecodes/branches are not covered by tests I can give you the results as of right now, though it's a bit of a verbose output, so let me know if you want them

dariorussi avatar Mar 13 '24 19:03 dariorussi

in case it helps.... 1- go to <sui>/crates/sui-framework/packages/sui-framework 2- run sui move test --coverage 3- sui move coverage summary will give you a summary of the percentage coverage for every module in the framework 4- sui move coverage bytecode --module random will tell you which bytecodes/branches are not covered by tests I can give you the results as of right now, though it's a bit of a verbose output, so let me know if you want them

Thanks @dariorussi - we cover all reachable code, except for unreachable assert aborts (for example, assert!(version == CURRENT_VERSION, EWrongInnerVersion))

benr-ml avatar Mar 14 '24 18:03 benr-ml