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

chore: nargo fmt #6221

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions noir-projects/aztec-nr/aztec/src/context/public_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl PublicContext {
unencrypted_logs_hashes: BoundedVec::new(),
unencrypted_log_preimages_length: 0,
historical_header: inputs.historical_header,
prover_address: AztecAddress::zero(),
prover_address: AztecAddress::zero()
}
}

Expand Down Expand Up @@ -144,7 +144,6 @@ impl PublicContext {
}

pub fn finish(self) -> PublicCircuitPublicInputs {

// Compute the public call stack hashes
let pub_circuit_pub_inputs = PublicCircuitPublicInputs {
call_context: self.inputs.call_context, // Done
Expand Down Expand Up @@ -358,7 +357,7 @@ fn emit_unencrypted_log_oracle<T>(
_contract_address: AztecAddress,
_event_selector: Field,
_message: T,
_counter: u32,
_counter: u32
) -> Field {}

struct FunctionReturns<N> {
Expand Down
48 changes: 23 additions & 25 deletions noir-projects/aztec-nr/aztec/src/hash.nr
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,28 @@ pub fn compute_secret_hash(secret: Field) -> Field {
pedersen_hash([secret], GENERATOR_INDEX__SECRET_HASH)
}

pub fn compute_encrypted_log_hash<N, M, L>(
encrypted_log: [Field; M]
) -> Field where [Field; N]: LensForEncryptedLog<N, M, L> {
pub fn compute_encrypted_log_hash<N, M, L>(encrypted_log: [Field; M]) -> Field where [Field; N]: LensForEncryptedLog<N, M, L> {
let mut bytes = [0; L];
// Note that bytes.append(encrypted_log[i].to_be_bytes(31)) results in bound error
for i in 0..M-1 {
for i in 0..M - 1 {
let to_add = encrypted_log[i].to_be_bytes(31);
for j in 0..31 {
bytes[i*31 + j] = to_add[j];
}
}
// can't assign as L - not in scope error for: L-31*(M-1)
let num_bytes = bytes.len() as u32 - 31*(M-1);
let to_add_final = encrypted_log[M-1].to_be_bytes(num_bytes);
let num_bytes = bytes.len() as u32 - 31 * (M - 1);
let to_add_final = encrypted_log[M - 1].to_be_bytes(num_bytes);
for j in 0..num_bytes {
bytes[(M-1)*31 + j] = to_add_final[j];
bytes[(M-1)*31 + j] = to_add_final[j];
}
sha256_to_field(bytes)
}

pub fn compute_unencrypted_log_hash<T, N, M>(
contract_address: AztecAddress,
event_selector: Field,
log: T,
log: T
) -> Field where T: ToBytesForUnencryptedLog<N, M> {
let message_bytes: [u8; N] = log.to_be_bytes_arr();
// can't use N - not in scope error
Expand Down Expand Up @@ -182,42 +180,42 @@ fn compute_enc_log_hash_304() {
0x00b938289e563b0fe01982cd9b8d9e33e3069046768ad01c0fb05e429e7b7909,
0x00fbcc257a3211f705b471eee763b0f43876a2b2178fab6d2b09bd2b7e086584,
0x000000000000008c3289b5793b7448f4d45ecde039d004b6f037cad10b5c2336
];
];
let hash = compute_encrypted_log_hash(input);
assert(hash == 0x001e3c013994947fe28957a876bf1b2c3a69ac69cc92909efd4f2ae9b972f893);
}

#[test]
fn compute_enc_log_hash_368() {
let input = [
0x0000000000000000000000000000000000000000000000000000000000000000,
0x002190697d2a50e229a7a077e0951073f7d51e46679f10466153c308b63b1ea9,
0x00543e346facc6799b94514c9d461bcc836c04b083b13c2e4544a39130473c1e,
0x000df76d59526f8f953bcc7d9f77cdaefd36435931f0d7348f794bc275b42ded,
0x00a6d390ee1723af7f7ac1ae4fc81a266b2370fe07040a36d06dbe242e02413e,
0x00acbce15b6af1fbe94bd0f7b70f11768265dff77bfe63398f2a053efdfdf26d,
0x00b8b131b9f42c689beb095ba4f4a836d4d15c9068d0422e9add6ca82b786329,
0x00661a6a654b38f0f97d404ef5553e0efea9ed670561ae86685b31bbb2824fac,
0x00113a6b58edfaec0065b365f66ba8d8aa68254b8690035e8d671a17a843f0a1,
0x0023f2d2eae8c4449bac8f268a3e62a3faace1fe1401f0efdc8b0ccfbc8fb271,
0x00cf6603f8c61993dd2f662c719671c61727a2f4e925fb988b23d31feccd77d9,
0x0000000000a402a84b7294671799c38dd805f6a827a3a12633fdf91a57debe1f
];
0x0000000000000000000000000000000000000000000000000000000000000000,
0x002190697d2a50e229a7a077e0951073f7d51e46679f10466153c308b63b1ea9,
0x00543e346facc6799b94514c9d461bcc836c04b083b13c2e4544a39130473c1e,
0x000df76d59526f8f953bcc7d9f77cdaefd36435931f0d7348f794bc275b42ded,
0x00a6d390ee1723af7f7ac1ae4fc81a266b2370fe07040a36d06dbe242e02413e,
0x00acbce15b6af1fbe94bd0f7b70f11768265dff77bfe63398f2a053efdfdf26d,
0x00b8b131b9f42c689beb095ba4f4a836d4d15c9068d0422e9add6ca82b786329,
0x00661a6a654b38f0f97d404ef5553e0efea9ed670561ae86685b31bbb2824fac,
0x00113a6b58edfaec0065b365f66ba8d8aa68254b8690035e8d671a17a843f0a1,
0x0023f2d2eae8c4449bac8f268a3e62a3faace1fe1401f0efdc8b0ccfbc8fb271,
0x00cf6603f8c61993dd2f662c719671c61727a2f4e925fb988b23d31feccd77d9,
0x0000000000a402a84b7294671799c38dd805f6a827a3a12633fdf91a57debe1f
];
let hash = compute_encrypted_log_hash(input);
assert(hash == 0x00a0d651ac0cbc01b72430fa6a05d91738595af6e0229347b4c9968223387aeb);
assert(hash == 0x00a0d651ac0cbc01b72430fa6a05d91738595af6e0229347b4c9968223387aeb);
}

#[test]
fn compute_unenc_log_hash_array() {
let contract_address = AztecAddress::from_field(0x233a3e0df23b2b15b324194cb4a151f26c0b7333250781d34cc269d85dc334c6);
let event_selector = 5;
let log = [
let log = [
0x20660de09f35f876e3e69d227b2a35166ad05f09d82d06366ec9b6f65a51fec2,
0x1b52bfe3b8689761916f76dc3d38aa8810860db325cd39ca611eed980091f01c,
0x2e559c4045c378a56ad13b9edb1e8de4e7ad3b3aa35cc7ba9ec77f7a68fa43a4,
0x25d0f689c4a4178a29d59306f2675824d19be6d25e44fa03b03f49c263053dd2,
0x2d513a722d6f352dc0961f156afdc5e31495b9f0e35cb069261a8e55e2df67fd
];
];
let hash = compute_unencrypted_log_hash(contract_address, event_selector, log);
assert(hash == 0x00846d6969c8c2f61d39cd2762efcb0abb14f88d59c2675910251ef2bcffe9a7);
}
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/keys.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod getters;
mod point_to_symmetric_key;

use crate::keys::getters::{get_npk_m, get_ivpk_m,
use crate::keys::getters::{get_npk_m, get_ivpk_m
// Commented out as it's currently not enabled in key registry
// get_ovpk_m,
// get_tpk_m
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/note/constants.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ global MAX_NOTE_FIELDS_LENGTH: u64 = 20;
// + 2 for EXTRA_DATA: [number_of_return_notes, contract_address]
global GET_NOTE_ORACLE_RETURN_LENGTH: u64 = MAX_NOTE_FIELDS_LENGTH + 1 + 2;
global MAX_NOTES_PER_PAGE: u64 = 10;
global VIEW_NOTE_ORACLE_RETURN_LENGTH: u64 = MAX_NOTES_PER_PAGE * (MAX_NOTE_FIELDS_LENGTH + 1) + 2;
global VIEW_NOTE_ORACLE_RETURN_LENGTH: u64 = MAX_NOTES_PER_PAGE * (MAX_NOTE_FIELDS_LENGTH + 1) + 2;
11 changes: 9 additions & 2 deletions noir-projects/aztec-nr/aztec/src/note/note_getter.nr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use crate::note::{
};
use crate::oracle;

fn extract_property_value_from_selector<N>(serialized_note: [Field; N], selector: PropertySelector) -> Field {
fn extract_property_value_from_selector<N>(
serialized_note: [Field; N],
selector: PropertySelector
) -> Field {
// Selectors use PropertySelectors in order to locate note properties inside the serialized note.
// This allows easier packing and custom (de)serialization schemas. A note property is located
// inside the serialized note using the index inside the array, a byte offset and a length.
Expand All @@ -26,7 +29,11 @@ fn extract_property_value_from_selector<N>(serialized_note: [Field; N], selector
value_field
}

fn check_note_header<Note, N>(context: PrivateContext, storage_slot: Field, note: Note) where Note: NoteInterface<N> {
fn check_note_header<Note, N>(
context: PrivateContext,
storage_slot: Field,
note: Note
) where Note: NoteInterface<N> {
let header = note.get_header();
let contract_address = context.this_address();
assert(header.contract_address.eq(contract_address));
Expand Down
1 change: 0 additions & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/encryption.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#[oracle(aes128Encrypt)]
pub fn aes128_encrypt_oracle<N, M>(input: [u8; N], iv: [u8; 16], key: [u8; 16]) -> [u8; M] {}

Expand Down
26 changes: 10 additions & 16 deletions noir-projects/aztec-nr/aztec/src/oracle/keys.nr
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
use dep::protocol_types::{
address::{
AztecAddress,
PartialAddress,
},
grumpkin_point::GrumpkinPoint,
};
use dep::protocol_types::{address::{AztecAddress, PartialAddress}, grumpkin_point::GrumpkinPoint};

#[oracle(getPublicKeysAndPartialAddress)]
fn get_public_keys_and_partial_address_oracle(_address: AztecAddress) -> [Field; 9] {}

unconstrained fn get_public_keys_and_partial_address_oracle_wrapper(address: AztecAddress) -> [Field; 9] {
get_public_keys_and_partial_address_oracle(address)
get_public_keys_and_partial_address_oracle(address)
}

fn get_public_keys_and_partial_address(address: AztecAddress) -> ([GrumpkinPoint; 4], PartialAddress) {
let result = get_public_keys_and_partial_address_oracle_wrapper(address);
let result = get_public_keys_and_partial_address_oracle_wrapper(address);

let nullifier_pub_key = GrumpkinPoint::new(result[0], result[1]);
let incoming_pub_key = GrumpkinPoint::new(result[2], result[3]);
let outgoing_pub_key = GrumpkinPoint::new(result[4], result[5]);
let tagging_pub_key = GrumpkinPoint::new(result[6], result[7]);
let partial_address = PartialAddress::from_field(result[8]);
let nullifier_pub_key = GrumpkinPoint::new(result[0], result[1]);
let incoming_pub_key = GrumpkinPoint::new(result[2], result[3]);
let outgoing_pub_key = GrumpkinPoint::new(result[4], result[5]);
let tagging_pub_key = GrumpkinPoint::new(result[6], result[7]);
let partial_address = PartialAddress::from_field(result[8]);

([nullifier_pub_key, incoming_pub_key, outgoing_pub_key, tagging_pub_key], partial_address)
}
([nullifier_pub_key, incoming_pub_key, outgoing_pub_key, tagging_pub_key], partial_address)
}
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/logs.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn emit_encrypted_log_oracle<N, M>(
_note_type_id: Field,
_encryption_pub_key: GrumpkinPoint,
_preimage: [Field; N],
_counter: u32,
_counter: u32
) -> [Field; M] {}

unconstrained pub fn emit_encrypted_log<N, M>(
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/nullifier_key.nr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ unconstrained fn get_nullifier_keys_internal(account: AztecAddress) -> Nullifier
NullifierKeys {
account,
master_nullifier_public_key: GrumpkinPoint { x: result[0], y: result[1] },
app_nullifier_secret_key: result[2],
app_nullifier_secret_key: result[2]
}
}

Expand Down
5 changes: 1 addition & 4 deletions noir-projects/aztec-nr/tests/src/mock/test_note.nr
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use dep::aztec::context::PrivateContext;
use dep::aztec::note::{
note_header::NoteHeader,
note_interface::NoteInterface,
};
use dep::aztec::note::{note_header::NoteHeader, note_interface::NoteInterface};

global TEST_NOTE_LENGTH = 1;

Expand Down
5 changes: 1 addition & 4 deletions noir-projects/aztec-nr/value-note/src/value_note.nr
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use dep::aztec::{
keys::getters::get_ivpk_m,
protocol_types::{
address::AztecAddress, traits::{Deserialize, Serialize},
constants::GENERATOR_INDEX__NOTE_NULLIFIER
},
protocol_types::{address::AztecAddress, traits::{Deserialize, Serialize}, constants::GENERATOR_INDEX__NOTE_NULLIFIER},
note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_consumption},
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key},
hash::poseidon2_hash, context::PrivateContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use dep::aztec::prelude::{AztecAddress, PrivateContext, NoteHeader, NoteInterface};
use dep::aztec::{
keys::getters::get_ivpk_m,
protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER, note::utils::compute_note_hash_for_consumption,
hash::poseidon2_hash,
keys::getters::get_ivpk_m, protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER,
note::utils::compute_note_hash_for_consumption, hash::poseidon2_hash,
oracle::{nullifier_key::get_app_nullifier_secret_key}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use dep::aztec::prelude::{AztecAddress, FunctionSelector, PrivateContext, NoteHeader, NoteGetterOptions, NoteViewerOptions};

use dep::aztec::{
protocol_types::{
traits::{ToField, Serialize, FromField},
constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
},
protocol_types::{traits::{ToField, Serialize, FromField}, constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL},
context::{PublicContext, Context}, note::note_getter::view_notes, state_vars::PrivateSet,
note::constants::MAX_NOTES_PER_PAGE,
note::constants::MAX_NOTES_PER_PAGE
};
use dep::std;
use dep::std::{option::Option};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use dep::aztec::prelude::{AztecAddress, NoteInterface, NoteHeader, PrivateContext};
use dep::aztec::{
keys::getters::get_ivpk_m,
note::{utils::compute_note_hash_for_consumption},
oracle::nullifier_key::get_app_nullifier_secret_key,
hash::poseidon2_hash, protocol_types::{traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER},
keys::getters::get_ivpk_m, note::{utils::compute_note_hash_for_consumption},
oracle::nullifier_key::get_app_nullifier_secret_key, hash::poseidon2_hash,
protocol_types::{traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER}
};

// Shows how to create a custom note
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use dep::aztec::prelude::{
AztecAddress, FunctionSelector, NoteHeader, NoteInterface, NoteGetterOptions, PrivateContext
};
use dep::aztec::prelude::{AztecAddress, FunctionSelector, NoteHeader, NoteInterface, NoteGetterOptions, PrivateContext};

use dep::aztec::{
keys::getters::get_ivpk_m,
note::utils::compute_note_hash_for_consumption,
oracle::nullifier_key::get_app_nullifier_secret_key,
hash::poseidon2_hash, protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER,
keys::getters::get_ivpk_m, note::utils::compute_note_hash_for_consumption,
oracle::nullifier_key::get_app_nullifier_secret_key, hash::poseidon2_hash,
protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER
};

global ECDSA_PUBLIC_KEY_NOTE_LEN: Field = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ contract KeyRegistry {

use dep::aztec::{
state_vars::{SharedMutable, Map},
protocol_types::{
grumpkin_point::GrumpkinPoint, address::{AztecAddress, PartialAddress},
}
protocol_types::{grumpkin_point::GrumpkinPoint, address::{AztecAddress, PartialAddress}}
};

global KEY_ROTATION_DELAY = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
// be read/nullified before their creation etc.
contract PendingNoteHashes {
// Libs
use dep::aztec::prelude::{
AztecAddress, FunctionSelector, NoteHeader, NoteGetterOptions, PrivateContext, Map, PrivateSet
};
use dep::aztec::prelude::{AztecAddress, FunctionSelector, NoteHeader, NoteGetterOptions, PrivateContext, Map, PrivateSet};
use dep::value_note::{balance_utils, filter::filter_notes_min_sum, value_note::{VALUE_NOTE_LEN, ValueNote}};
use dep::aztec::context::{PublicContext, Context};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use dep::aztec::prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext};
use dep::aztec::{
keys::getters::get_ivpk_m,
note::utils::compute_note_hash_for_consumption, hash::poseidon2_hash,
keys::getters::get_ivpk_m, note::utils::compute_note_hash_for_consumption, hash::poseidon2_hash,
oracle::{nullifier_key::get_app_nullifier_secret_key},
protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER,
protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER
};

global PUBLIC_KEY_NOTE_LEN: Field = 3;
Expand Down
20 changes: 9 additions & 11 deletions noir-projects/noir-contracts/contracts/test_contract/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ contract Test {

use dep::aztec::protocol_types::{
abis::private_circuit_public_inputs::PrivateCircuitPublicInputs,
constants::{MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, CANONICAL_KEY_REGISTRY_ADDRESS}, traits::{Serialize, ToField, FromField},
grumpkin_point::GrumpkinPoint
constants::{MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, CANONICAL_KEY_REGISTRY_ADDRESS},
traits::{Serialize, ToField, FromField}, grumpkin_point::GrumpkinPoint
};

use dep::aztec::note::constants::MAX_NOTES_PER_PAGE;
Expand All @@ -27,10 +27,7 @@ contract Test {
note_getter_options::NoteStatus
},
deploy::deploy_contract as aztec_deploy_contract,
oracle::{
encryption::aes128_encrypt,
unsafe_rand::unsafe_rand
}
oracle::{encryption::aes128_encrypt, unsafe_rand::unsafe_rand}
};
use dep::token_portal_content_hash_lib::{get_mint_private_content_hash, get_mint_public_content_hash};
use dep::value_note::value_note::ValueNote;
Expand Down Expand Up @@ -424,15 +421,16 @@ contract Test {
let derived_slot = derive_storage_slot_in_map(storage_slot_of_shared_mutable, address_to_get_in_registry);

// It's a bit wonky because we need to know the delay for get_current_value_in_private to work correctly
let registry_private_getter: SharedMutablePrivateGetter<Field, 5> = SharedMutablePrivateGetter::new(context, AztecAddress::from_field(CANONICAL_KEY_REGISTRY_ADDRESS), derived_slot);
let registry_private_getter: SharedMutablePrivateGetter<Field, 5> = SharedMutablePrivateGetter::new(
context,
AztecAddress::from_field(CANONICAL_KEY_REGISTRY_ADDRESS),
derived_slot
);
registry_private_getter.get_current_value_in_private()
}

#[aztec(private)]
fn test_nullifier_key_freshness(
address: AztecAddress,
public_nullifying_key: GrumpkinPoint,
) {
fn test_nullifier_key_freshness(address: AztecAddress, public_nullifying_key: GrumpkinPoint) {
assert_eq(get_npk_m(&mut context, address), public_nullifying_key);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use dep::aztec::{
keys::getters::get_ivpk_m,
prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext},
keys::getters::get_ivpk_m, prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext},
protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER,
note::utils::compute_note_hash_for_consumption, hash::poseidon2_hash,
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use dep::aztec::{
keys::getters::get_ivpk_m,
prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext},
keys::getters::get_ivpk_m, prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext},
protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER,
note::utils::compute_note_hash_for_consumption, hash::poseidon2_hash,
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key}
Expand Down
Loading
Loading