Skip to content

Commit

Permalink
feat: use prelude bounded vec
Browse files Browse the repository at this point in the history
  • Loading branch information
sirasistant committed Jan 31, 2024
1 parent c9560ac commit 923caa7
Show file tree
Hide file tree
Showing 33 changed files with 93 additions and 444 deletions.
10 changes: 5 additions & 5 deletions noir/aztec_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,11 +846,11 @@ fn make_return_push(push_value: Expression) -> Statement {
/// Make Return push array
///
/// Translates to:
/// `context.return_values.push_array({push_value})`
fn make_return_push_array(push_value: Expression) -> Statement {
/// `context.return_values.extend_from_array({push_value})`
fn make_return_extend_from_array(push_value: Expression) -> Statement {
make_statement(StatementKind::Semi(method_call(
context_return_values(),
"push_array",
"extend_from_array",
vec![push_value],
)))
}
Expand All @@ -859,14 +859,14 @@ fn make_return_push_array(push_value: Expression) -> Statement {
///
/// Translates to:
/// ```noir
/// `context.return_values.push_array({push_value}.serialize())`
/// `context.return_values.extend_from_array({push_value}.serialize())`
fn make_struct_return_type(expression: Expression) -> Statement {
let serialized_call = method_call(
expression, // variable
"serialize", // method name
vec![], // args
);
make_return_push_array(serialized_call)
make_return_extend_from_array(serialized_call)
}

/// Make array return type
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/aztec-nr/authwit/src/entrypoint.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use dep::aztec::abi;
use dep::aztec::types::vec::BoundedVec;
use dep::aztec::context::PrivateContext;
use dep::aztec::protocol_types::{
abis::{
Expand Down Expand Up @@ -66,7 +65,7 @@ impl Serialize<ENTRYPOINT_PAYLOAD_SIZE> for EntrypointPayload {
fn serialize(self) -> [Field; ENTRYPOINT_PAYLOAD_SIZE] {
let mut fields: BoundedVec<Field, ENTRYPOINT_PAYLOAD_SIZE> = BoundedVec::new(0);
for call in self.function_calls {
fields.push_array(call.serialize());
fields.extend_from_array(call.serialize());
}
fields.push(self.nonce);
fields.storage
Expand Down
1 change: 0 additions & 1 deletion yarn-project/aztec-nr/aztec/src/context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::{
header::get_header_at,
nullifier_key::{get_nullifier_key_pair, NullifierKeyPair},
},
types::vec::BoundedVec,
utils::Reader,
};
use dep::protocol_types::{
Expand Down
1 change: 0 additions & 1 deletion yarn-project/aztec-nr/aztec/src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ mod messaging;
mod note;
mod oracle;
mod state_vars;
mod types;
mod utils;
use dep::protocol_types;
1 change: 0 additions & 1 deletion yarn-project/aztec-nr/aztec/src/note/note_getter.nr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::note::{
utils::compute_note_hash_for_read_or_nullify,
};
use crate::oracle;
use crate::types::vec::BoundedVec;

fn check_note_header<Note, N>(
context: PrivateContext,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use dep::std::option::Option;
use crate::types::vec::BoundedVec;
use dep::protocol_types::{
constants::MAX_READ_REQUESTS_PER_CALL,
traits::Deserialize,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use dep::std::option::Option;
use crate::note::note_getter_options::{Select, Sort, Comparator, NoteStatus};
use crate::types::vec::BoundedVec;
use dep::protocol_types::{
constants::MAX_NOTES_PER_PAGE,
traits::Deserialize,
Expand Down
1 change: 0 additions & 1 deletion yarn-project/aztec-nr/aztec/src/types.nr

This file was deleted.

126 changes: 0 additions & 126 deletions yarn-project/aztec-nr/aztec/src/types/vec.nr

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ contract SchnorrHardcodedAccount {
use dep::aztec::{
abi::{ PrivateCircuitPublicInputs, PrivateContextInputs, Hasher },
context::PrivateContext,
types::vec::BoundedVec,
};

use dep::authwit:: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ contract Test {
},
state_vars::immutable_singleton::ImmutableSingleton,
log::emit_unencrypted_log_from_private,
types::vec::BoundedVec,
};
use dep::token_portal_content_hash_lib::{get_mint_private_content_hash, get_mint_public_content_hash};
use dep::field_note::field_note::FieldNote;
Expand Down Expand Up @@ -193,7 +192,7 @@ contract Test {
args.push(a_field);
args.push(a_bool as Field);
args.push(a_number as Field);
args.push_array(an_array);
args.extend_from_array(an_array);
args.push(a_struct.amount);
args.push(a_struct.secret_hash);
args.push(a_deep_struct.a_field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ use dep::types::{
array_to_bounded_vec,
validate_array,
},
bounded_vec::BoundedVec,
},
traits::{is_empty, is_empty_array},
};

pub fn validate_arrays(app_public_inputs: PrivateCircuitPublicInputs) {
// Each of the following arrays is expected to be zero-padded.
// In addition, some of the following arrays (new_commitments, etc...) are passed
// to push_array_to_array() routines which rely on the passed arrays to be well-formed.
// to extend_from_array_to_array() routines which rely on the passed arrays to be well-formed.

validate_array(app_public_inputs.return_values);
validate_array(app_public_inputs.read_requests);
Expand Down Expand Up @@ -197,7 +196,7 @@ pub fn update_end_values(private_call: PrivateCallData, public_inputs: &mut Kern
)
}
}
public_inputs.end.read_requests.push_vec(siloed_read_requests);
public_inputs.end.read_requests.extend_from_bounded_vec(siloed_read_requests);

// Nullifier key validation requests.
for i in 0..MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL {
Expand Down Expand Up @@ -228,7 +227,7 @@ pub fn update_end_values(private_call: PrivateCallData, public_inputs: &mut Kern
);
}
}
public_inputs.end.new_nullifiers.push_vec(siloed_new_nullifiers);
public_inputs.end.new_nullifiers.extend_from_bounded_vec(siloed_new_nullifiers);

// commitments
let mut siloed_new_commitments: BoundedVec<SideEffect, MAX_NEW_COMMITMENTS_PER_CALL> = BoundedVec::new(SideEffect::empty());
Expand All @@ -240,7 +239,7 @@ pub fn update_end_values(private_call: PrivateCallData, public_inputs: &mut Kern
);
}
}
public_inputs.end.new_commitments.push_vec(siloed_new_commitments);
public_inputs.end.new_commitments.extend_from_bounded_vec(siloed_new_commitments);

// Call stacks
// Private call stack.
Expand All @@ -250,15 +249,15 @@ pub fn update_end_values(private_call: PrivateCallData, public_inputs: &mut Kern
private_call_public_inputs.private_call_stack_hashes,
private_call
);
public_inputs.end.private_call_stack.push_vec(private_call_stack);
public_inputs.end.private_call_stack.extend_from_bounded_vec(private_call_stack);
// Public call stack.
let public_call_stack = array_to_bounded_vec(private_call.public_call_stack);
validate_call_requests(
public_call_stack,
private_call_public_inputs.public_call_stack_hashes,
private_call
);
public_inputs.end.public_call_stack.push_vec(public_call_stack);
public_inputs.end.public_call_stack.extend_from_bounded_vec(public_call_stack);

// new l2 to l1 messages
let portal_contract_address = private_call.portal_contract_address;
Expand All @@ -277,7 +276,7 @@ pub fn update_end_values(private_call: PrivateCallData, public_inputs: &mut Kern
new_l2_to_l1_msgs_to_insert.push(new_l2_to_l1_msgs)
}
}
public_inputs.end.new_l2_to_l1_msgs.push_vec(new_l2_to_l1_msgs_to_insert);
public_inputs.end.new_l2_to_l1_msgs.extend_from_bounded_vec(new_l2_to_l1_msgs_to_insert);

// logs hashes
// See the following thread if not clear:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ mod tests {
fn input_validation_malformed_arrays_return_values() {
let mut builder = PrivateKernelInitInputsBuilder::new_constructor();

builder.private_call.public_inputs.return_values.push_array([0, 9123]);
builder.private_call.public_inputs.return_values.extend_from_array([0, 9123]);

builder.failed();
}
Expand All @@ -273,7 +273,7 @@ mod tests {
fn input_validation_malformed_arrays_read_requests() {
let mut builder = PrivateKernelInitInputsBuilder::new_constructor();

builder.private_call.public_inputs.read_requests.push_array(
builder.private_call.public_inputs.read_requests.extend_from_array(
[
SideEffect { value: 0, counter: 0 },
SideEffect { value: 9123, counter: 1 }
Expand All @@ -287,7 +287,7 @@ mod tests {
fn input_validation_malformed_arrays_commitments() {
let mut builder = PrivateKernelInitInputsBuilder::new_constructor();

builder.private_call.public_inputs.new_commitments.push_array(
builder.private_call.public_inputs.new_commitments.extend_from_array(
[
SideEffect { value: 0, counter: 0 },
SideEffect { value: 9123, counter: 1 }
Expand All @@ -301,7 +301,7 @@ mod tests {
fn input_validation_malformed_arrays_nullifiers() {
let mut builder = PrivateKernelInitInputsBuilder::new_constructor();

builder.private_call.public_inputs.new_nullifiers.push_array(
builder.private_call.public_inputs.new_nullifiers.extend_from_array(
[
SideEffectLinkedToNoteHash { value: 0, note_hash: 0, counter: 0 },
SideEffectLinkedToNoteHash { value: 9123, note_hash: 0, counter: 1 }
Expand All @@ -315,7 +315,7 @@ mod tests {
fn input_validation_malformed_arrays_private_call_stack() {
let mut builder = PrivateKernelInitInputsBuilder::new_constructor();

builder.private_call.public_inputs.private_call_stack_hashes.push_array([0, 9123]);
builder.private_call.public_inputs.private_call_stack_hashes.extend_from_array([0, 9123]);

builder.failed();
}
Expand All @@ -324,7 +324,7 @@ mod tests {
fn input_validation_malformed_arrays_public_call_stack() {
let mut builder = PrivateKernelInitInputsBuilder::new_constructor();

builder.private_call.public_inputs.public_call_stack_hashes.push_array([0, 9123]);
builder.private_call.public_inputs.public_call_stack_hashes.extend_from_array([0, 9123]);

builder.failed();
}
Expand All @@ -333,7 +333,7 @@ mod tests {
fn input_validation_malformed_arrays_new_l2_to_l1_msgs() {
let mut builder = PrivateKernelInitInputsBuilder::new_constructor();

builder.private_call.public_inputs.new_l2_to_l1_msgs.push_array([0, 9123]);
builder.private_call.public_inputs.new_l2_to_l1_msgs.extend_from_array([0, 9123]);

builder.failed();
}
Expand Down
Loading

0 comments on commit 923caa7

Please sign in to comment.