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

feat: a script which runs nargo fmt in all packages + running it #3803

Merged
merged 6 commits into from
Jan 4, 2024
Merged
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
2 changes: 1 addition & 1 deletion yarn-project/aztec-nr/aztec/src/history.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ mod note_inclusion;
mod note_validity;
mod nullifier_inclusion;
mod nullifier_non_inclusion;
mod public_value_inclusion;
mod public_value_inclusion;
7 changes: 3 additions & 4 deletions yarn-project/aztec-nr/aztec/src/history/note_inclusion.nr
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ pub fn prove_note_commitment_inclusion(

// 3) Prove that the commitment is in the note hash tree
assert(
block_header.note_hash_tree_root == compute_merkle_root(note_commitment, witness.index, witness.path),
"Proving note inclusion failed"
block_header.note_hash_tree_root
== compute_merkle_root(note_commitment, witness.index, witness.path), "Proving note inclusion failed"
);

// --> Now we have traversed the trees all the way up to archive root.
}

Expand All @@ -39,4 +38,4 @@ pub fn prove_note_inclusion<Note, N>(
let note_commitment = compute_unique_siloed_note_hash(note_interface, note_with_header);

prove_note_commitment_inclusion(note_commitment, block_number, context);
}
}
2 changes: 1 addition & 1 deletion yarn-project/aztec-nr/aztec/src/history/note_validity.nr
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ pub fn prove_note_validity<Note, N>(
) {
prove_note_inclusion(note_interface, note_with_header, block_number, context);
prove_note_not_nullified(note_interface, note_with_header, block_number, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@ pub fn l1_to_l2_message_getter_len() -> Field {
L1_TO_L2_MESSAGE_LENGTH + 1 + L1_TO_L2_MSG_TREE_HEIGHT + 1
}

pub fn make_l1_to_l2_message_getter_data<N>(fields: [Field; N], start: Field, secret: Field) -> L1ToL2MessageGetterData {
pub fn make_l1_to_l2_message_getter_data<N>(
fields: [Field; N],
start: Field,
secret: Field
) -> L1ToL2MessageGetterData {
L1ToL2MessageGetterData {
message: L1ToL2Message::deserialize(arr_copy_slice(fields, [0; L1_TO_L2_MESSAGE_LENGTH], start),
message: L1ToL2Message::deserialize(
arr_copy_slice(fields, [0; L1_TO_L2_MESSAGE_LENGTH], start),
secret,
fields[start + L1_TO_L2_MESSAGE_LENGTH]),
fields[start + L1_TO_L2_MESSAGE_LENGTH]
),
leaf_index: fields[start + L1_TO_L2_MESSAGE_LENGTH],
sibling_path: arr_copy_slice(fields,
sibling_path: arr_copy_slice(
fields,
[0; L1_TO_L2_MSG_TREE_HEIGHT],
L1_TO_L2_MESSAGE_LENGTH + 1),
L1_TO_L2_MESSAGE_LENGTH + 1
),
root: fields[start + L1_TO_L2_MESSAGE_LENGTH + L1_TO_L2_MSG_TREE_HEIGHT + 1]
}
}
48 changes: 37 additions & 11 deletions yarn-project/aztec-nr/aztec/src/note/note_getter.nr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ use crate::note::{
use crate::oracle;
use crate::types::vec::BoundedVec;

fn check_note_header<Note, N>(context: PrivateContext, storage_slot: Field, note_interface: NoteInterface<Note, N>, note: Note) {
fn check_note_header<Note, N>(
context: PrivateContext,
storage_slot: Field,
note_interface: NoteInterface<Note, N>,
note: Note
) {
let get_header = note_interface.get_header;
let header = get_header(note);
let contract_address = context.this_address();
Expand All @@ -31,7 +36,11 @@ fn check_note_fields<N>(fields: [Field; N], selects: BoundedVec<Option<Select>,
}
}

fn check_notes_order<N>(fields_0: [Field; N], fields_1: [Field; N], sorts: BoundedVec<Option<Sort>, N>) {
fn check_notes_order<N>(
fields_0: [Field; N],
fields_1: [Field; N],
sorts: BoundedVec<Option<Sort>, N>
) {
for i in 0..sorts.len {
let sort = sorts.get_unchecked(i).unwrap_unchecked();
let eq = fields_0[sort.field_index] == fields_1[sort.field_index];
Expand All @@ -44,7 +53,11 @@ fn check_notes_order<N>(fields_0: [Field; N], fields_1: [Field; N], sorts: Bound
}
}

pub fn get_note<Note, N>(context: &mut PrivateContext, storage_slot: Field, note_interface: NoteInterface<Note, N>) -> Note {
pub fn get_note<Note, N>(
context: &mut PrivateContext,
storage_slot: Field,
note_interface: NoteInterface<Note, N>
) -> Note {
let note = get_note_internal(storage_slot, note_interface);

check_note_header(*context, storage_slot, note_interface, note);
Expand Down Expand Up @@ -94,7 +107,8 @@ pub fn get_notes<Note, N, FILTER_ARGS>(
unconstrained fn get_note_internal<Note, N>(storage_slot: Field, note_interface: NoteInterface<Note, N>) -> Note {
let placeholder_note = [Option::none()];
let placeholder_fields = [0; GET_NOTE_ORACLE_RETURN_LENGTH];
oracle::notes::get_notes(storage_slot,
oracle::notes::get_notes(
storage_slot,
note_interface,
0,
[],
Expand All @@ -104,7 +118,8 @@ unconstrained fn get_note_internal<Note, N>(storage_slot: Field, note_interface:
1, // limit
0, // offset
placeholder_note,
placeholder_fields)[0].unwrap() // Notice: we don't allow dummies to be returned from get_note (singular).
placeholder_fields
)[0].unwrap() // Notice: we don't allow dummies to be returned from get_note (singular).
}

unconstrained fn get_notes_internal<Note, N, FILTER_ARGS>(
Expand All @@ -115,7 +130,8 @@ unconstrained fn get_notes_internal<Note, N, FILTER_ARGS>(
let (num_selects, select_by, select_values, sort_by, sort_order) = flatten_options(options.selects, options.sorts);
let placeholder_opt_notes = [Option::none(); MAX_READ_REQUESTS_PER_CALL];
let placeholder_fields = [0; GET_NOTES_ORACLE_RETURN_LENGTH];
let opt_notes = oracle::notes::get_notes(storage_slot,
let opt_notes = oracle::notes::get_notes(
storage_slot,
note_interface,
num_selects,
select_by,
Expand All @@ -125,18 +141,24 @@ unconstrained fn get_notes_internal<Note, N, FILTER_ARGS>(
options.limit,
options.offset,
placeholder_opt_notes,
placeholder_fields);
placeholder_fields
);

let filter = options.filter;
let filter_args = options.filter_args;
filter(opt_notes, filter_args)
}

unconstrained pub fn view_notes<Note, N>(storage_slot: Field, note_interface: NoteInterface<Note, N>, options: NoteViewerOptions<Note, N>) -> [Option<Note>; MAX_NOTES_PER_PAGE] {
unconstrained pub fn view_notes<Note, N>(
storage_slot: Field,
note_interface: NoteInterface<Note, N>,
options: NoteViewerOptions<Note, N>
) -> [Option<Note>; MAX_NOTES_PER_PAGE] {
let (num_selects, select_by, select_values, sort_by, sort_order) = flatten_options(options.selects, options.sorts);
let placeholder_opt_notes = [Option::none(); MAX_NOTES_PER_PAGE];
let placeholder_fields = [0; VIEW_NOTE_ORACLE_RETURN_LENGTH];
oracle::notes::get_notes(storage_slot,
oracle::notes::get_notes(
storage_slot,
note_interface,
num_selects,
select_by,
Expand All @@ -146,10 +168,14 @@ unconstrained pub fn view_notes<Note, N>(storage_slot: Field, note_interface: No
options.limit,
options.offset,
placeholder_opt_notes,
placeholder_fields)
placeholder_fields
)
}

unconstrained fn flatten_options<Note, N>(selects: BoundedVec<Option<Select>, N>, sorts: BoundedVec<Option<Sort>, N>) -> (u8, [u8; N], [Field; N], [u8; N], [u2; N]) {
unconstrained fn flatten_options<Note, N>(
selects: BoundedVec<Option<Select>, N>,
sorts: BoundedVec<Option<Sort>, N>
) -> (u8, [u8; N], [Field; N], [u8; N], [u2; N]) {
let mut num_selects = 0;
let mut select_by = [0; N];
let mut select_values = [0; N];
Expand Down
5 changes: 4 additions & 1 deletion yarn-project/aztec-nr/aztec/src/note/note_getter_options.nr
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ impl Sort {
}
}

fn return_all_notes<Note, N>(notes: [Option<Note>; MAX_READ_REQUESTS_PER_CALL], _p: Field) -> [Option<Note>; MAX_READ_REQUESTS_PER_CALL] {
fn return_all_notes<Note, N>(
notes: [Option<Note>; MAX_READ_REQUESTS_PER_CALL],
_p: Field
) -> [Option<Note>; MAX_READ_REQUESTS_PER_CALL] {
notes
}

Expand Down
6 changes: 5 additions & 1 deletion yarn-project/aztec-nr/aztec/src/note/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ pub fn compute_note_hash_for_read_or_nullify<Note, N>(note_interface: NoteInterf
}
}

pub fn compute_note_hash_and_nullifier<Note, N, S>(note_interface: NoteInterface<Note, N>, note_header: NoteHeader, serialized_note: [Field; S]) -> [Field; 4] {
pub fn compute_note_hash_and_nullifier<Note, N, S>(
note_interface: NoteInterface<Note, N>,
note_header: NoteHeader,
serialized_note: [Field; S]
) -> [Field; 4] {
let deserialize = note_interface.deserialize;
let set_header = note_interface.set_header;
let mut note = deserialize(arr_copy_slice(serialized_note, [0; N], 0));
Expand Down
12 changes: 10 additions & 2 deletions yarn-project/aztec-nr/aztec/src/oracle/call_private_function.nr
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ use dep::protocol_types::{
};

#[oracle(callPrivateFunction)]
fn call_private_function_oracle(_contract_address: AztecAddress, _function_selector: FunctionSelector, _args_hash: Field) -> [Field; CALL_PRIVATE_FUNCTION_RETURN_SIZE] {}
fn call_private_function_oracle(
_contract_address: AztecAddress,
_function_selector: FunctionSelector,
_args_hash: Field
) -> [Field; CALL_PRIVATE_FUNCTION_RETURN_SIZE] {}

unconstrained pub fn call_private_function_internal(contract_address: AztecAddress, function_selector: FunctionSelector, args_hash: Field) -> [Field; CALL_PRIVATE_FUNCTION_RETURN_SIZE] {
unconstrained pub fn call_private_function_internal(
contract_address: AztecAddress,
function_selector: FunctionSelector,
args_hash: Field
) -> [Field; CALL_PRIVATE_FUNCTION_RETURN_SIZE] {
call_private_function_oracle(contract_address, function_selector, args_hash)
}
4 changes: 2 additions & 2 deletions yarn-project/aztec-nr/aztec/src/oracle/debug_log.nr
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ fn debug_log_format_oracle<T, N>(_msg: T, _args: [Field; N], _num_args: Field) -
#[oracle(debugLog)]
fn debug_log_field_oracle(_field: Field) -> Field {}
#[oracle(debugLog)]
fn debug_log_array_oracle<T, N>(_arbitrary_array: [T;N]) -> Field {}
fn debug_log_array_oracle<T, N>(_arbitrary_array: [T; N]) -> Field {}
#[oracle(debugLogWithPrefix)]
fn debug_log_array_with_prefix_oracle<S, T, N>(_prefix: S, _arbitrary_array: [T;N]) -> Field {}
fn debug_log_array_with_prefix_oracle<S, T, N>(_prefix: S, _arbitrary_array: [T; N]) -> Field {}

/// NOTE: call this with a str<N> msg of length > 1
/// Example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ use dep::protocol_types::{
global ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_SIZE: Field = 14;

#[oracle(enqueuePublicFunctionCall)]
fn enqueue_public_function_call_oracle(_contract_address: AztecAddress, _function_selector: FunctionSelector, _args_hash: Field) -> [Field; ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_SIZE] {}
fn enqueue_public_function_call_oracle(
_contract_address: AztecAddress,
_function_selector: FunctionSelector,
_args_hash: Field
) -> [Field; ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_SIZE] {}

unconstrained pub fn enqueue_public_function_call_internal(contract_address: AztecAddress, function_selector: FunctionSelector, args_hash: Field) -> [Field; ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_SIZE] {
unconstrained pub fn enqueue_public_function_call_internal(
contract_address: AztecAddress,
function_selector: FunctionSelector,
args_hash: Field
) -> [Field; ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_SIZE] {
enqueue_public_function_call_oracle(contract_address, function_selector, args_hash)
}
9 changes: 7 additions & 2 deletions yarn-project/aztec-nr/aztec/src/oracle/get_block_header.nr
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ pub fn get_block_header(block_number: u32, context: PrivateContext) -> BlockHead

// 2) Check that the block header block number is more than or equal to the block number we want to prove against
// We could not perform the proof otherwise because the archive root from the header would not "contain" the block we want to prove against
assert(block_header_block_number >= block_number, "Block header block number is smaller than the block number we want to prove against");
assert(
block_header_block_number >= block_number, "Block header block number is smaller than the block number we want to prove against"
);

// 3) Get block header of a given block from oracle
let block_header = get_block_header_internal(block_number);
Expand All @@ -44,7 +46,10 @@ pub fn get_block_header(block_number: u32, context: PrivateContext) -> BlockHead
let witness = get_archive_membership_witness(block_header_block_number, block_hash);

// 6) Check that the block is in the archive (i.e. the witness is valid)
assert(context.block_header.archive_root == compute_merkle_root(block_hash, witness.index, witness.path), "Proving membership of a block in archive failed");
assert(
context.block_header.archive_root
== compute_merkle_root(block_hash, witness.index, witness.path), "Proving membership of a block in archive failed"
);

// 7) Return the block header
block_header
Expand Down
15 changes: 12 additions & 3 deletions yarn-project/aztec-nr/aztec/src/oracle/get_membership_witness.nr
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,28 @@ unconstrained pub fn get_membership_witness<N, M>(block_number: u32, tree_id: Fi
MembershipWitness { index: fields[0], path: arr_copy_slice(fields, [0; N], 1) }
}

unconstrained pub fn get_contract_membership_witness(block_number: u32, leaf_value: Field) -> MembershipWitness<CONTRACT_TREE_HEIGHT, CONTRACT_TREE_HEIGHT + 1> {
unconstrained pub fn get_contract_membership_witness(
block_number: u32,
leaf_value: Field
) -> MembershipWitness<CONTRACT_TREE_HEIGHT, CONTRACT_TREE_HEIGHT + 1> {
get_membership_witness(block_number, CONTRACT_TREE_ID, leaf_value)
}

// Note: get_nullifier_membership_witness function is implemented in get_nullifier_membership_witness.nr

unconstrained pub fn get_note_hash_membership_witness<N, M>(block_number: u32, leaf_value: Field) -> MembershipWitness<NOTE_HASH_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT + 1> {
unconstrained pub fn get_note_hash_membership_witness<N, M>(
block_number: u32,
leaf_value: Field
) -> MembershipWitness<NOTE_HASH_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT + 1> {
get_membership_witness(block_number, NOTE_HASH_TREE_ID, leaf_value)
}

// There is no `get_public_data_membership_witness` function because it doesn't make sense to be getting a membership
// witness for a value in the public data tree.

unconstrained pub fn get_archive_membership_witness(block_number: u32, leaf_value: Field) -> MembershipWitness<ARCHIVE_HEIGHT, ARCHIVE_HEIGHT + 1> {
unconstrained pub fn get_archive_membership_witness(
block_number: u32,
leaf_value: Field
) -> MembershipWitness<ARCHIVE_HEIGHT, ARCHIVE_HEIGHT + 1> {
get_membership_witness(block_number, ARCHIVE_TREE_ID, leaf_value)
}
12 changes: 8 additions & 4 deletions yarn-project/aztec-nr/aztec/src/oracle/notes.nr
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ unconstrained fn get_notes_oracle_wrapper<N, S>(
mut placeholder_fields: [Field; S]
) -> [Field; S] {
let return_size = placeholder_fields.len() as u32;
get_notes_oracle(storage_slot,
get_notes_oracle(
storage_slot,
num_selects,
select_by,
select_values,
Expand All @@ -56,7 +57,8 @@ unconstrained fn get_notes_oracle_wrapper<N, S>(
limit,
offset,
return_size,
placeholder_fields)
placeholder_fields
)
}

unconstrained pub fn get_notes<Note, N, M, S, NS>(
Expand All @@ -72,15 +74,17 @@ unconstrained pub fn get_notes<Note, N, M, S, NS>(
mut placeholder_opt_notes: [Option<Note>; S], // TODO: Remove it and use `limit` to initialize the note array.
placeholder_fields: [Field; NS] // TODO: Remove it and use `limit` to initialize the note array.
) -> [Option<Note>; S] {
let fields = get_notes_oracle_wrapper(storage_slot,
let fields = get_notes_oracle_wrapper(
storage_slot,
num_selects,
select_by,
select_values,
sort_by,
sort_order,
limit,
offset,
placeholder_fields);
placeholder_fields
);
let num_notes = fields[0] as u32;
let contract_address = AztecAddress::from_field(fields[1]);
let deserialize = note_interface.deserialize;
Expand Down
12 changes: 10 additions & 2 deletions yarn-project/aztec-nr/aztec/src/oracle/public_call.nr
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ use dep::protocol_types::{
};

#[oracle(callPublicFunction)]
fn call_public_function_oracle(_contract_address: AztecAddress, _function_selector: FunctionSelector, _args_hash: Field) -> [Field; RETURN_VALUES_LENGTH] {}
fn call_public_function_oracle(
_contract_address: AztecAddress,
_function_selector: FunctionSelector,
_args_hash: Field
) -> [Field; RETURN_VALUES_LENGTH] {}

unconstrained pub fn call_public_function_internal(contract_address: AztecAddress, function_selector: FunctionSelector, args_hash: Field) -> [Field; RETURN_VALUES_LENGTH] {
unconstrained pub fn call_public_function_internal(
contract_address: AztecAddress,
function_selector: FunctionSelector,
args_hash: Field
) -> [Field; RETURN_VALUES_LENGTH] {
call_public_function_oracle(contract_address, function_selector, args_hash)
}
2 changes: 1 addition & 1 deletion yarn-project/aztec-nr/aztec/src/oracle/storage.nr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ unconstrained fn storage_read_oracle_wrapper<N>(_storage_slot: Field) -> [Field;
storage_read_oracle(_storage_slot, N)
}

pub fn storage_read<T, N>(storage_slot: Field, deserialize: fn ([Field; N]) -> T) -> T {
pub fn storage_read<T, N>(storage_slot: Field, deserialize: fn([Field; N]) -> T) -> T {
let fields = storage_read_oracle_wrapper(storage_slot);
deserialize(fields)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use dep::std::option::Option;
use dep::protocol_types::{
address::AztecAddress,
};

use crate::context::{PrivateContext, Context};
use crate::note::{
lifecycle::create_note,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ fn serialize(value: AztecAddress) -> [Field; AZTEC_ADDRESS_SERIALIZED_LEN] {
global AddressSerializationMethods = TypeSerializationInterface {
deserialize,
serialize,
};
};
Loading