-
Notifications
You must be signed in to change notification settings - Fork 57
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 a randomBytes
builtin to generate cryptographically secure bytes
#2902
Comments
On this note, we should add a pragma that would indicate that a certain identifier is "volatile" to prevent the optimisations from moving it around, duplicating and/or merging calls to it (this can happen currently). |
Could you describe this in more detail? Or raise an issue as it seems important. |
Yes, I'll raise an issue |
Link to discussed issue: |
Does type Nonce := mkNonce {unNonce : Nat};
type RandSeed := mkRandSeed {unRandSeed : Nat}; ? |
Current state of affairs:
Consequences:
|
This PR adds frontend support for the Anoma Random API: The frontend builtin APIs are: ``` builtin anoma-random-generator axiom RandomGenerator : Type; builtin anoma-random-generator-init axiom randomGeneratorInit : Nat -> RandomGenerator; builtin anoma-random-generator-split axiom randomGeneratorSplit : RandomGenerator -> Pair RandomGenerator RandomGenerator; builtin anoma-random-next-bytes axiom randomNextBytes : Nat -> RandomGenerator -> Pair ByteArray RandomGenerator; ``` ### Nockma Evaluator The Nockma evaluator intercepts the corresponding Anoma random stdlib calls using the [System.Random](https://hackage.haskell.org/package/random-1.2.1.2/docs/System-Random.html) API. The implementation uses the [splitmix](https://hackage.haskell.org/package/splitmix-0.1.0.5/docs/System-Random-SplitMix.html) generator directly because it has an API to destructure the generator into a pair of integers. We can use this to serialise the generator. * Closes #2902
Depends on
This issue proposes adding a builtin
randomBytes
function.This is required to populate the
rseed
andnonce
fields of an Anoma Resource. The types of these fields are not yet determined.Backend Representation
Core
We can use a Haskell library e.g crypto-rng to implement the builtin.
Nockma
We can use the same implementation as Core in the Juvix Nockma evaluator.
We will need a
randomBytes
implementation in the Anoma Hoon stdlib in order to run programs containing this builtin in the Anoma Nock VM.Native, Cairo, Risc0
The implementation of
randomBytes
for the native, Cairo and Risc0 backends is deferred.The text was updated successfully, but these errors were encountered: