Skip to content

Commit

Permalink
refactor: renaming rand() as unsafe_rand() (#5457)
Browse files Browse the repository at this point in the history
Fixes #3746
  • Loading branch information
benesjan authored Mar 26, 2024
1 parent d80dbbf commit 19ad2bb
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 17 deletions.
11 changes: 11 additions & 0 deletions docs/docs/misc/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ keywords: [sandbox, cli, aztec, notes, migration, updating, upgrading]

Aztec is in full-speed development. Literally every version breaks compatibility with the previous ones. This page attempts to target errors and difficulties you might encounter when upgrading, and how to resolve them.

## TBD

### [Aztec.nr] rand oracle is now called unsafe_rand
`oracle::rand::rand` has been renamed to `oracle::unsafe_rand::unsafe_rand`.
This change was made to communicate that we do not constrain the value in circuit and instead we just trust our PXE.

```diff
- let random_value = rand();
+ let random_value = unsafe_rand();
```

## 0.31.0

### [Aztec.nr] Public storage historical read API improvement
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use dep::aztec::log::emit_encrypted_log;
use dep::aztec::{
protocol_types::{address::AztecAddress, traits::Empty},
note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_consumption},
oracle::{rand::rand, nullifier_key::get_nullifier_secret_key, get_public_key::get_public_key},
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_nullifier_secret_key, get_public_key::get_public_key},
hash::pedersen_hash, context::PrivateContext
};

Expand Down Expand Up @@ -61,7 +61,7 @@ impl NoteInterface<ADDRESS_NOTE_LEN> for AddressNote {

impl AddressNote {
pub fn new(address: AztecAddress, owner: AztecAddress) -> Self {
let randomness = rand();
let randomness = unsafe_rand();
AddressNote { address, owner, randomness, header: NoteHeader::empty() }
}
// docs:end:address_note_def
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/oracle.nr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod get_membership_witness;
mod get_public_key;
mod nullifier_key;
mod get_sibling_path;
mod rand;
mod unsafe_rand;
mod enqueue_public_function_call;
mod header;
mod public_call;
Expand Down
6 changes: 0 additions & 6 deletions noir-projects/aztec-nr/aztec/src/oracle/rand.nr

This file was deleted.

9 changes: 9 additions & 0 deletions noir-projects/aztec-nr/aztec/src/oracle/unsafe_rand.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[oracle(getRandomField)]
fn rand_oracle() -> Field {}


// Called `unsafe_rand` because we do not constrain in circuit that we are dealing with an actual random value.
// Instead we just trust our PXE.
unconstrained pub fn unsafe_rand() -> Field {
rand_oracle()
}
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/value-note/src/value_note.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use dep::aztec::{
protocol_types::{address::AztecAddress, traits::{Deserialize, Serialize}},
note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_consumption},
oracle::{rand::rand, nullifier_key::get_nullifier_secret_key, get_public_key::get_public_key},
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_nullifier_secret_key, get_public_key::get_public_key},
log::emit_encrypted_log, hash::pedersen_hash, context::PrivateContext
};

Expand Down Expand Up @@ -59,7 +59,7 @@ impl NoteInterface<VALUE_NOTE_LEN> for ValueNote {

impl ValueNote {
pub fn new(value: Field, owner: AztecAddress) -> Self {
let randomness = rand();
let randomness = unsafe_rand();
let header = NoteHeader::empty();
ValueNote { value, owner, randomness, header }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract Test {
note_getter_options::NoteStatus
},
deploy::deploy_contract as aztec_deploy_contract,
oracle::{get_public_key::get_public_key as get_public_key_oracle, context::get_portal_address, rand::rand},
oracle::{get_public_key::get_public_key as get_public_key_oracle, context::get_portal_address, unsafe_rand::unsafe_rand},
log::emit_unencrypted_log_from_private
};
use dep::token_portal_content_hash_lib::{get_mint_private_content_hash, get_mint_public_content_hash};
Expand Down Expand Up @@ -379,7 +379,7 @@ contract Test {

// Purely exists for testing
unconstrained fn get_random(kinda_seed: Field) -> pub Field {
kinda_seed * rand()
kinda_seed * unsafe_rand()
}

struct DummyNote {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::aztec::prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext, emit_encrypted_log};
use dep::aztec::{note::utils::compute_note_hash_for_consumption, hash::pedersen_hash};
use dep::aztec::oracle::{rand::rand, nullifier_key::get_nullifier_secret_key, get_public_key::get_public_key};
use dep::aztec::oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_nullifier_secret_key, get_public_key::get_public_key};

trait OwnedNote {
fn new(amount: U128, owner: AztecAddress) -> Self;
Expand Down Expand Up @@ -69,7 +69,7 @@ impl OwnedNote for TokenNote {
Self {
amount,
owner,
randomness: rand(),
randomness: unsafe_rand(),
header: NoteHeader::empty(),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use dep::aztec::prelude::{
PrivateSet, Map, emit_encrypted_log
};
use dep::aztec::{note::utils::compute_note_hash_for_consumption, hash::pedersen_hash};
use dep::aztec::oracle::{rand::rand, nullifier_key::get_nullifier_secret_key, get_public_key::get_public_key};
use dep::aztec::oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_nullifier_secret_key, get_public_key::get_public_key};

trait OwnedNote {
fn new(amount: U128, owner: AztecAddress) -> Self;
Expand Down Expand Up @@ -72,7 +72,7 @@ impl OwnedNote for TokenNote {
Self {
amount,
owner,
randomness: rand(),
randomness: unsafe_rand(),
header: NoteHeader::empty(),
}
}
Expand Down

0 comments on commit 19ad2bb

Please sign in to comment.