Skip to content

Commit

Permalink
chore: Pull noir for u64 as array lengths (#4787)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirasistant authored Feb 27, 2024
1 parent 2799f1f commit e69b586
Show file tree
Hide file tree
Showing 260 changed files with 5,799 additions and 2,142 deletions.
13 changes: 1 addition & 12 deletions avm-transpiler/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions avm-transpiler/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "1.72"
components = [ "rust-src" ]
channel = "1.73"
components = ["rust-src"]
targets = []
profile = "default"
4 changes: 2 additions & 2 deletions barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ bool accumulateAndVerifyGoblin(const std::string& bytecodePath, const std::strin

// TODO(https://github.com/AztecProtocol/barretenberg/issues/811): Don't hardcode dyadic circuit size. Currently set
// to max circuit size present in acir tests suite.
size_t hardcoded_bn254_dyadic_size_hack = 1 << 18;
size_t hardcoded_bn254_dyadic_size_hack = 1 << 19;
init_bn254_crs(hardcoded_bn254_dyadic_size_hack);
size_t hardcoded_grumpkin_dyadic_size_hack = 1 << 10; // For eccvm only
init_grumpkin_crs(hardcoded_grumpkin_dyadic_size_hack);
Expand Down Expand Up @@ -189,7 +189,7 @@ bool proveAndVerifyGoblin(const std::string& bytecodePath, const std::string& wi

// TODO(https://github.com/AztecProtocol/barretenberg/issues/811): Don't hardcode dyadic circuit size. Currently set
// to max circuit size present in acir tests suite.
size_t hardcoded_bn254_dyadic_size_hack = 1 << 18;
size_t hardcoded_bn254_dyadic_size_hack = 1 << 19;
init_bn254_crs(hardcoded_bn254_dyadic_size_hack);
size_t hardcoded_grumpkin_dyadic_size_hack = 1 << 10; // For eccvm only
init_grumpkin_crs(hardcoded_grumpkin_dyadic_size_hack);
Expand Down
10 changes: 5 additions & 5 deletions noir-projects/aztec-nr/authwit/src/entrypoint/app.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__SIGNATURE_PAYLOAD,
use crate::entrypoint::function_call::{FunctionCall, FUNCTION_CALL_SIZE_IN_BYTES};

// FUNCTION_CALL_SIZE * ACCOUNT_MAX_CALLS + 1
global APP_PAYLOAD_SIZE: Field = 17;
global APP_PAYLOAD_SIZE: u64 = 17;
// FUNCTION_CALL_SIZE_IN_BYTES * ACCOUNT_MAX_CALLS + 32
global APP_PAYLOAD_SIZE_IN_BYTES: Field = 420;
global APP_PAYLOAD_SIZE_IN_BYTES: u64 = 420;

global ACCOUNT_MAX_CALLS: Field = 4;
global ACCOUNT_MAX_CALLS: u64 = 4;

// Note: If you change the following struct you have to update default_entrypoint.ts
// docs:start:app-payload-struct
Expand All @@ -21,7 +21,7 @@ struct AppPayload {
impl Serialize<APP_PAYLOAD_SIZE> for AppPayload {
// Serializes the entrypoint struct
fn serialize(self) -> [Field; APP_PAYLOAD_SIZE] {
let mut fields: BoundedVec<Field, APP_PAYLOAD_SIZE> = BoundedVec::new(0);
let mut fields: BoundedVec<Field, APP_PAYLOAD_SIZE> = BoundedVec::new();
for call in self.function_calls {
fields.extend_from_array(call.serialize());
}
Expand All @@ -42,7 +42,7 @@ impl Hash for AppPayload {
impl AppPayload {
// Serializes the payload as an array of bytes. Useful for hashing with sha256.
fn to_be_bytes(self) -> [u8; APP_PAYLOAD_SIZE_IN_BYTES] {
let mut bytes: BoundedVec<u8, APP_PAYLOAD_SIZE_IN_BYTES> = BoundedVec::new(0);
let mut bytes: BoundedVec<u8, APP_PAYLOAD_SIZE_IN_BYTES> = BoundedVec::new();

for i in 0..ACCOUNT_MAX_CALLS {
bytes.extend_from_array(self.function_calls[i].to_be_bytes());
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct FeePayload {
impl Serialize<FEE_PAYLOAD_SIZE> for FeePayload {
// Serializes the entrypoint struct
fn serialize(self) -> [Field; FEE_PAYLOAD_SIZE] {
let mut fields: BoundedVec<Field, FEE_PAYLOAD_SIZE> = BoundedVec::new(0);
let mut fields: BoundedVec<Field, FEE_PAYLOAD_SIZE> = BoundedVec::new();
for i in 0..MAX_FEE_FUNCTION_CALLS {
fields.extend_from_array(self.function_calls[i].serialize());
}
Expand All @@ -40,7 +40,7 @@ impl Hash for FeePayload {

impl FeePayload {
fn to_be_bytes(self) -> [u8; FEE_PAYLOAD_SIZE_IN_BYTES] {
let mut bytes: BoundedVec<u8, FEE_PAYLOAD_SIZE_IN_BYTES> = BoundedVec::new(0);
let mut bytes: BoundedVec<u8, FEE_PAYLOAD_SIZE_IN_BYTES> = BoundedVec::new();

for i in 0..MAX_FEE_FUNCTION_CALLS {
bytes.extend_from_array(self.function_calls[i].to_be_bytes());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::protocol_types::traits::Serialize;

global PRIVATE_GLOBAL_VARIABLES_LENGTH: Field = 2;
global PRIVATE_GLOBAL_VARIABLES_LENGTH: u64 = 2;

// docs:start:private-global-variables
struct PrivateGlobalVariables {
Expand Down
16 changes: 8 additions & 8 deletions noir-projects/aztec-nr/aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ impl PrivateContext {
side_effect_counter,
min_revertible_side_effect_counter,
args_hash,
return_values: BoundedVec::new(0),
read_requests: BoundedVec::new(SideEffect::empty()),
nullifier_key_validation_requests: BoundedVec::new(NullifierKeyValidationRequest::empty()),
new_note_hashes: BoundedVec::new(SideEffect::empty()),
new_nullifiers: BoundedVec::new(SideEffectLinkedToNoteHash::empty()),
return_values: BoundedVec::new(),
read_requests: BoundedVec::new(),
nullifier_key_validation_requests: BoundedVec::new(),
new_note_hashes: BoundedVec::new(),
new_nullifiers: BoundedVec::new(),
historical_header: inputs.historical_header,
private_call_stack_hashes: BoundedVec::new(0),
public_call_stack_hashes: BoundedVec::new(0),
new_l2_to_l1_msgs: BoundedVec::new(L2ToL1Message::empty()),
private_call_stack_hashes: BoundedVec::new(),
public_call_stack_hashes: BoundedVec::new(),
new_l2_to_l1_msgs: BoundedVec::new(),
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)
// encrypted_logs_preimages: Vec::new(),
// unencrypted_logs_preimages: Vec::new(),
Expand Down
16 changes: 8 additions & 8 deletions noir-projects/aztec-nr/aztec/src/context/public_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ impl PublicContext {
inputs,
side_effect_counter: inputs.call_context.start_side_effect_counter,
args_hash,
return_values: BoundedVec::new(0),
contract_storage_update_requests: BoundedVec::new(empty_storage_update),
contract_storage_reads: BoundedVec::new(empty_storage_read),
public_call_stack_hashes: BoundedVec::new(0),
new_note_hashes: BoundedVec::new(SideEffect::empty()),
new_nullifiers: BoundedVec::new(SideEffectLinkedToNoteHash::empty()),
new_l2_to_l1_msgs: BoundedVec::new(L2ToL1Message::empty()),
unencrypted_logs_hash: BoundedVec::new(0),
return_values: BoundedVec::new(),
contract_storage_update_requests: BoundedVec::new(),
contract_storage_reads: BoundedVec::new(),
public_call_stack_hashes: BoundedVec::new(),
new_note_hashes: BoundedVec::new(),
new_nullifiers: BoundedVec::new(),
new_l2_to_l1_msgs: BoundedVec::new(),
unencrypted_logs_hash: BoundedVec::new(),
unencrypted_logs_preimages_length: 0,
historical_header: inputs.historical_header,
prover_address: AztecAddress::zero() // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ struct L1ToL2MessageGetterData {
leaf_index: Field
}

pub fn l1_to_l2_message_getter_len() -> Field {
pub fn l1_to_l2_message_getter_len() -> u64 {
L1_TO_L2_MESSAGE_LENGTH + 1 + L1_TO_L2_MSG_TREE_HEIGHT
}

pub fn make_l1_to_l2_message_getter_data<N>(
fields: [Field; N],
start: Field,
start: u64,
secret: Field
) -> L1ToL2MessageGetterData {
L1ToL2MessageGetterData {
Expand Down
8 changes: 4 additions & 4 deletions noir-projects/aztec-nr/aztec/src/note/note_getter_options.nr
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ impl<Note, N, FILTER_ARGS> NoteGetterOptions<Note, N, FILTER_ARGS> {
// This function initializes a NoteGetterOptions that simply returns the maximum number of notes allowed in a call.
pub fn new() -> NoteGetterOptions<Note, N, Field> where Note: NoteInterface<N> {
NoteGetterOptions {
selects: BoundedVec::new(Option::none()),
sorts: BoundedVec::new(Option::none()),
selects: BoundedVec::new(),
sorts: BoundedVec::new(),
limit: MAX_READ_REQUESTS_PER_CALL as u32,
offset: 0,
filter: return_all_notes,
Expand All @@ -108,8 +108,8 @@ impl<Note, N, FILTER_ARGS> NoteGetterOptions<Note, N, FILTER_ARGS> {
filter_args: FILTER_ARGS
) -> Self where Note: NoteInterface<N> {
NoteGetterOptions {
selects: BoundedVec::new(Option::none()),
sorts: BoundedVec::new(Option::none()),
selects: BoundedVec::new(),
sorts: BoundedVec::new(),
limit: MAX_READ_REQUESTS_PER_CALL as u32,
offset: 0,
filter,
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/note/note_viewer_options.nr
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ struct NoteViewerOptions<Note, N> {
impl<Note, N> NoteViewerOptions<Note, N> {
pub fn new() -> NoteViewerOptions<Note, N> where Note: NoteInterface<N> {
NoteViewerOptions {
selects: BoundedVec::new(Option::none()),
sorts: BoundedVec::new(Option::none()),
selects: BoundedVec::new(),
sorts: BoundedVec::new(),
limit: MAX_NOTES_PER_PAGE as u32,
offset: 0,
status: NoteStatus.ACTIVE
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/debug_log.nr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ unconstrained pub fn debug_log<T>(msg: T) {
/// Example:
/// debug_log_format("get_2(slot:{0}) =>\n\t0:{1}\n\t1:{2}", [storage_slot, note0_hash, note1_hash]);
unconstrained pub fn debug_log_format<T, N>(msg: T, args: [Field; N]) {
assert(debug_log_format_oracle(msg, args, args.len()) == 0);
assert(debug_log_format_oracle(msg, args, args.len() as Field) == 0);
}

/// Example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use dep::protocol_types::{
utils::arr_copy_slice
};

global LEAF_PREIMAGE_LENGTH: Field = 4;
global LEAF_PREIMAGE_LENGTH: u64 = 4;
global PUBLIC_DATA_WITNESS: Field = 45;

struct PublicDataWitness {
Expand All @@ -23,7 +23,7 @@ unconstrained pub fn get_public_data_witness(block_number: u32, leaf_slot: Field
let fields = get_public_data_witness_oracle(block_number, leaf_slot);
PublicDataWitness {
index: fields[0],
leaf_preimage: PublicDataTreeLeafPreimage { slot: fields[1], value: fields[2], next_index: fields[3] as u32, next_slot: fields[4] },
leaf_preimage: PublicDataTreeLeafPreimage { slot: fields[1], value: fields[2], next_index: fields[3] as u64, next_slot: fields[4] },
path: arr_copy_slice(fields, [0; PUBLIC_DATA_TREE_HEIGHT], 1 + LEAF_PREIMAGE_LENGTH)
}
}
10 changes: 5 additions & 5 deletions noir-projects/aztec-nr/aztec/src/oracle/notes.nr
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ unconstrained pub fn get_notes<Note, N, M, S, NS>(
status,
placeholder_fields
);
let num_notes = fields[0] as u32;
let num_notes = fields[0] as u64;
let contract_address = AztecAddress::from_field(fields[1]);
for i in 0..placeholder_opt_notes.len() {
if i as u32 < num_notes {
if i < num_notes {
// lengths named as per typescript.
let return_header_length: Field = 2; // num_notes & contract_address.
let extra_preimage_length: Field = 2; // nonce & is_transient.
let read_offset: Field = return_header_length + i * (N + extra_preimage_length);
let return_header_length: u64 = 2; // num_notes & contract_address.
let extra_preimage_length: u64 = 2; // nonce & is_transient.
let read_offset: u64 = return_header_length + i * (N + extra_preimage_length);
let nonce = fields[read_offset];
let is_transient = fields[read_offset + 1] as bool;
let header = NoteHeader { contract_address, nonce, storage_slot, is_transient };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<T> SharedImmutable<T> {
// - a membership proof of the value in the public tree of the header
prove_public_value_inclusion(
fields[i],
self.storage_slot + i,
self.storage_slot + i as Field,
(*private_context).this_address(),
(*private_context)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use dep::aztec::protocol_types::{
use dep::authwit::entrypoint::function_call::{FunctionCall, FUNCTION_CALL_SIZE_IN_BYTES};

// FUNCTION_CALL_SIZE * DAPP_MAX_CALLS + 1
global DAPP_PAYLOAD_SIZE: Field = 5;
global DAPP_PAYLOAD_SIZE: u64 = 5;
// FUNCTION_CALL_SIZE_IN_BYTES * DAPP_MAX_CALLS + 32
global DAPP_PAYLOAD_SIZE_IN_BYTES: Field = 129;
global DAPP_PAYLOAD_SIZE_IN_BYTES: u64 = 129;

global DAPP_MAX_CALLS: Field = 1;
global DAPP_MAX_CALLS: u64 = 1;

// Note: If you change the following struct you have to update default_entrypoint.ts
// docs:start:app-payload-struct
Expand All @@ -24,7 +24,7 @@ struct DAppPayload {
impl Serialize<DAPP_PAYLOAD_SIZE> for DAppPayload {
// Serializes the entrypoint struct
fn serialize(self) -> [Field; DAPP_PAYLOAD_SIZE] {
let mut fields: BoundedVec<Field, DAPP_PAYLOAD_SIZE> = BoundedVec::new(0);
let mut fields: BoundedVec<Field, DAPP_PAYLOAD_SIZE> = BoundedVec::new();
for call in self.function_calls {
fields.extend_from_array(call.serialize());
}
Expand All @@ -45,7 +45,7 @@ impl Hash for DAppPayload {
impl DAppPayload {
// Serializes the payload as an array of bytes. Useful for hashing with sha256.
fn to_be_bytes(self) -> [u8; DAPP_PAYLOAD_SIZE_IN_BYTES] {
let mut bytes: BoundedVec<u8, DAPP_PAYLOAD_SIZE_IN_BYTES> = BoundedVec::new(0);
let mut bytes: BoundedVec<u8, DAPP_PAYLOAD_SIZE_IN_BYTES> = BoundedVec::new();

for i in 0..DAPP_MAX_CALLS {
bytes.extend_from_array(self.function_calls[i].to_be_bytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract SlowTree {
use crate::types::{MembershipProof, deserialize_membership_proof};

// docs:start:constants_and_storage
global TREE_HEIGHT: Field = 254;
global TREE_HEIGHT: u64 = 254;
global MEMBERSHIP_SIZE: Field = 256; // TREE_HEIGHT + 2
global UPDATE_SIZE: Field = 512; // TREE_HEIGHT * 2 + 4

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ contract Test {
a_struct: DummyNote,
a_deep_struct: DeepStruct
) -> distinct pub PrivateCircuitPublicInputs {
let mut args: BoundedVec<Field, 17> = BoundedVec::new(0);
let mut args: BoundedVec<Field, 17> = BoundedVec::new();
args.push(a_field);
args.push(a_bool as Field);
args.push(a_number as Field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub fn update_end_values(

// Transient read requests and witnesses are accumulated in public_inputs.end
// We silo the read requests (domain separation per contract address)
let mut siloed_read_requests: BoundedVec<SideEffect, MAX_READ_REQUESTS_PER_CALL> = BoundedVec::new(SideEffect::empty());
let mut siloed_read_requests: BoundedVec<SideEffect, MAX_READ_REQUESTS_PER_CALL> = BoundedVec::new();
for i in 0..MAX_READ_REQUESTS_PER_CALL {
let read_request = read_requests[i].value;
let witness = read_request_membership_witnesses[i];
Expand All @@ -210,7 +210,7 @@ pub fn update_end_values(
// Enhance commitments and nullifiers with domain separation whereby domain is the contract.
//
// nullifiers
let mut siloed_new_nullifiers: BoundedVec<SideEffectLinkedToNoteHash, MAX_NEW_NULLIFIERS_PER_CALL> = BoundedVec::new(SideEffectLinkedToNoteHash::empty());
let mut siloed_new_nullifiers: BoundedVec<SideEffectLinkedToNoteHash, MAX_NEW_NULLIFIERS_PER_CALL> = BoundedVec::new();
for i in 0..MAX_NEW_NULLIFIERS_PER_CALL {
let new_nullifier = new_nullifiers[i];
if new_nullifier.value != 0 {
Expand All @@ -231,7 +231,7 @@ pub fn update_end_values(
public_inputs.end.new_nullifiers.extend_from_bounded_vec(siloed_new_nullifiers);

// note hashes
let mut siloed_new_note_hashes: BoundedVec<SideEffect, MAX_NEW_NOTE_HASHES_PER_CALL> = BoundedVec::new(SideEffect::empty());
let mut siloed_new_note_hashes: BoundedVec<SideEffect, MAX_NEW_NOTE_HASHES_PER_CALL> = BoundedVec::new();
for i in 0..MAX_NEW_NOTE_HASHES_PER_CALL {
let new_note_hash = new_note_hashes[i].value;
if new_note_hash != 0 {
Expand Down Expand Up @@ -262,7 +262,7 @@ pub fn update_end_values(

// new l2 to l1 messages
let new_l2_to_l1_msgs = private_call_public_inputs.new_l2_to_l1_msgs;
let mut new_l2_to_l1_msgs_to_insert : BoundedVec<Field, MAX_NEW_L2_TO_L1_MSGS_PER_CALL> = BoundedVec::new(0);
let mut new_l2_to_l1_msgs_to_insert : BoundedVec<Field, MAX_NEW_L2_TO_L1_MSGS_PER_CALL> = BoundedVec::new();
for i in 0..MAX_NEW_L2_TO_L1_MSGS_PER_CALL {
let msg = new_l2_to_l1_msgs[i];
if !is_empty(msg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ mod tests {
let mut full_new_note_hashes = [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_TX];
for i in 0..MAX_NEW_NOTE_HASHES_PER_TX {
full_new_note_hashes[i] = SideEffect {
value: i + 1,
value: i as Field + 1,
counter: i as u32,
};
}
Expand Down Expand Up @@ -750,7 +750,7 @@ mod tests {
fn zero_0th_nullifier_fails() {
let mut builder = PrivateKernelInnerInputsBuilder::new();

builder.previous_kernel.end.new_nullifiers = BoundedVec::new(SideEffectLinkedToNoteHash::empty());
builder.previous_kernel.end.new_nullifiers = BoundedVec::new();

builder.failed();
}
Expand Down
Loading

0 comments on commit e69b586

Please sign in to comment.