Skip to content

Commit

Permalink
Add RandomGenerator to Sui Framework (#15019)
Browse files Browse the repository at this point in the history
## 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)

- [x] 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
Add Move interfaces for generating secure random values.
  • Loading branch information
benr-ml authored and leecchh committed Mar 27, 2024
1 parent 7daeaf4 commit bb49d33
Show file tree
Hide file tree
Showing 10 changed files with 2,229 additions and 42 deletions.
4 changes: 2 additions & 2 deletions crates/sui-framework/docs/sui-framework/hmac.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ title: Module `0x2::hmac`
Returns the 32 bytes digest of HMAC-SHA3-256(key, msg).


<pre><code><b>public</b> <b>fun</b> <a href="hmac.md#0x2_hmac_hmac_sha3_256">hmac_sha3_256</a>(key: &<a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;, msg: &<a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;): <a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;
<pre><code><b>public</b> <b>fun</b> <a href="../sui-framework/hmac.md#0x2_hmac_hmac_sha3_256">hmac_sha3_256</a>(key: &<a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;, msg: &<a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;): <a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;
</code></pre>


Expand All @@ -30,7 +30,7 @@ Returns the 32 bytes digest of HMAC-SHA3-256(key, msg).
<summary>Implementation</summary>


<pre><code><b>public</b> <b>native</b> <b>fun</b> <a href="hmac.md#0x2_hmac_hmac_sha3_256">hmac_sha3_256</a>(key: &<a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;, msg: &<a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;): <a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;;
<pre><code><b>public</b> <b>native</b> <b>fun</b> <a href="../sui-framework/hmac.md#0x2_hmac_hmac_sha3_256">hmac_sha3_256</a>(key: &<a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;, msg: &<a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;): <a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;;
</code></pre>


Expand Down
Loading

0 comments on commit bb49d33

Please sign in to comment.