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: squashing transient note hashes and nullifiers #6059

Merged
merged 13 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
14 changes: 7 additions & 7 deletions noir-projects/aztec-nr/aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use dep::protocol_types::{
private_circuit_public_inputs::PrivateCircuitPublicInputs,
public_call_stack_item::PublicCallStackItem,
public_circuit_public_inputs::PublicCircuitPublicInputs, read_request::ReadRequest,
side_effect::{SideEffect, SideEffectLinkedToNoteHash}
note_hash::NoteHash, nullifier::Nullifier, side_effect::SideEffect
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating specific structs for note hashes and nullifiers. Logs are still using SideEffect because Miranda is working on logs so I don't want to change it to create more conflicts.

},
address::{AztecAddress, EthAddress},
constants::{
Expand Down Expand Up @@ -53,8 +53,8 @@ struct PrivateContext {
nullifier_read_requests: BoundedVec<ReadRequest, MAX_NULLIFIER_READ_REQUESTS_PER_CALL>,
nullifier_key_validation_requests: BoundedVec<NullifierKeyValidationRequest, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL>,

new_note_hashes: BoundedVec<SideEffect, MAX_NEW_NOTE_HASHES_PER_CALL>,
new_nullifiers: BoundedVec<SideEffectLinkedToNoteHash, MAX_NEW_NULLIFIERS_PER_CALL>,
new_note_hashes: BoundedVec<NoteHash, MAX_NEW_NOTE_HASHES_PER_CALL>,
new_nullifiers: BoundedVec<Nullifier, MAX_NEW_NULLIFIERS_PER_CALL>,

private_call_stack_hashes : BoundedVec<Field, MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL>,
public_call_stack_hashes : BoundedVec<Field, MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL>,
Expand Down Expand Up @@ -103,13 +103,13 @@ impl ContextInterface for PrivateContext {
}

fn push_new_note_hash(&mut self, note_hash: Field) {
let side_effect = SideEffect { value: note_hash, counter: self.side_effect_counter };
let side_effect = NoteHash { value: note_hash, counter: self.side_effect_counter };
self.new_note_hashes.push(side_effect);
self.side_effect_counter = self.side_effect_counter + 1;
}

fn push_new_nullifier(&mut self, nullifier: Field, nullified_commitment: Field) {
let side_effect = SideEffectLinkedToNoteHash { value: nullifier, note_hash: nullified_commitment, counter: self.side_effect_counter };
let side_effect = Nullifier { value: nullifier, note_hash: nullified_commitment, counter: self.side_effect_counter };
self.new_nullifiers.push(side_effect);
self.side_effect_counter = self.side_effect_counter + 1;
}
Expand Down Expand Up @@ -496,8 +496,8 @@ impl PrivateContext {
contract_storage_update_requests: [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL],
contract_storage_reads: [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL],
public_call_stack_hashes: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL],
new_note_hashes: [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL],
new_nullifiers: [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL],
new_note_hashes: [NoteHash::empty(); MAX_NEW_NOTE_HASHES_PER_CALL],
new_nullifiers: [Nullifier::empty(); MAX_NEW_NULLIFIERS_PER_CALL],
new_l2_to_l1_msgs: [L2ToL1Message::empty(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL],
start_side_effect_counter: 0,
end_side_effect_counter: 0,
Expand Down
10 changes: 5 additions & 5 deletions noir-projects/aztec-nr/aztec/src/context/public_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use dep::protocol_types::{
private_circuit_public_inputs::PrivateCircuitPublicInputs,
public_call_stack_item::PublicCallStackItem,
public_circuit_public_inputs::PublicCircuitPublicInputs, read_request::ReadRequest,
side_effect::{SideEffect, SideEffectLinkedToNoteHash}
note_hash::NoteHash, nullifier::Nullifier, side_effect::SideEffect
},
hash::silo_nullifier, address::{AztecAddress, EthAddress},
constants::{
Expand All @@ -40,8 +40,8 @@ struct PublicContext {
contract_storage_reads: BoundedVec<StorageRead, MAX_PUBLIC_DATA_READS_PER_CALL>,
public_call_stack_hashes: BoundedVec<Field, MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL>,

new_note_hashes: BoundedVec<SideEffect, MAX_NEW_NOTE_HASHES_PER_CALL>,
new_nullifiers: BoundedVec<SideEffectLinkedToNoteHash, MAX_NEW_NULLIFIERS_PER_CALL>,
new_note_hashes: BoundedVec<NoteHash, MAX_NEW_NOTE_HASHES_PER_CALL>,
new_nullifiers: BoundedVec<Nullifier, MAX_NEW_NULLIFIERS_PER_CALL>,

new_l2_to_l1_msgs: BoundedVec<L2ToL1Message, MAX_NEW_L2_TO_L1_MSGS_PER_CALL>,

Expand Down Expand Up @@ -207,13 +207,13 @@ impl ContextInterface for PublicContext {
}

fn push_new_note_hash(&mut self, note_hash: Field) {
let side_effect = SideEffect { value: note_hash, counter: self.side_effect_counter };
let side_effect = NoteHash { value: note_hash, counter: self.side_effect_counter };
self.new_note_hashes.push(side_effect);
self.side_effect_counter = self.side_effect_counter + 1;
}

fn push_new_nullifier(&mut self, nullifier: Field, _nullified_commitment: Field) {
let side_effect = SideEffectLinkedToNoteHash {
let side_effect = Nullifier {
value: nullifier,
note_hash: 0, // cannot nullify pending notes in public context
counter: self.side_effect_counter
Expand Down
8 changes: 6 additions & 2 deletions noir-projects/aztec-nr/aztec/src/note/lifecycle.nr
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ pub fn create_note<Note, N>(

// TODO: Strong typing required because of https://github.com/noir-lang/noir/issues/4088
let serialized_note: [Field; N] = Note::serialize_content(*note);
let note_hash_counter = context.side_effect_counter;
assert(
notify_created_note(
storage_slot,
Note::get_note_type_id(),
serialized_note,
inner_note_hash
inner_note_hash,
note_hash_counter
)
== 0
);
Expand Down Expand Up @@ -69,7 +71,9 @@ pub fn destroy_note<Note, N>(context: &mut PrivateContext, note: Note) where Not
// TODO(1718): Can we reuse the note hash computed in `compute_nullifier`?
consumed_note_hash = compute_note_hash_for_consumption(note);
}
assert(notify_nullified_note(nullifier, consumed_note_hash) == 0);

let nullifier_counter = context.side_effect_counter;
assert(notify_nullified_note(nullifier, consumed_note_hash, nullifier_counter) == 0);

context.push_new_nullifier(nullifier, consumed_note_hash)
}
28 changes: 22 additions & 6 deletions noir-projects/aztec-nr/aztec/src/oracle/notes.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,39 @@ fn notify_created_note_oracle<N>(
_storage_slot: Field,
_note_type_id: Field,
_serialized_note: [Field; N],
_inner_note_hash: Field
_inner_note_hash: Field,
_counter: u32
) -> Field {}

unconstrained pub fn notify_created_note<N>(
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; N],
inner_note_hash: Field
inner_note_hash: Field,
counter: u32
) -> Field {
notify_created_note_oracle(storage_slot, note_type_id, serialized_note, inner_note_hash)
notify_created_note_oracle(
storage_slot,
note_type_id,
serialized_note,
inner_note_hash,
counter
)
}

#[oracle(notifyNullifiedNote)]
fn notify_nullified_note_oracle<N>(_nullifier: Field, _inner_note_hash: Field) -> Field {}
fn notify_nullified_note_oracle<N>(
_nullifier: Field,
_inner_note_hash: Field,
_counter: u32
) -> Field {}

unconstrained pub fn notify_nullified_note<N>(nullifier: Field, inner_note_hash: Field) -> Field {
notify_nullified_note_oracle(nullifier, inner_note_hash)
unconstrained pub fn notify_nullified_note<N>(
nullifier: Field,
inner_note_hash: Field,
counter: u32
) -> Field {
notify_nullified_note_oracle(nullifier, inner_note_hash, counter)
}

#[oracle(getNotes)]
Expand Down
8 changes: 2 additions & 6 deletions noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use dep::protocol_types::{
constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
abis::side_effect::{SideEffect, SideEffectLinkedToNoteHash}
};
use dep::protocol_types::{constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, abis::side_effect::SideEffect};
use crate::context::{PrivateContext, PublicContext, Context};
use crate::note::{
constants::MAX_NOTES_PER_PAGE,
lifecycle::{create_note, create_note_hash_from_public, destroy_note},
constants::MAX_NOTES_PER_PAGE, lifecycle::{create_note, create_note_hash_from_public, destroy_note},
note_getter::{get_notes, view_notes}, note_getter_options::NoteGetterOptions,
note_header::NoteHeader, note_interface::NoteInterface, note_viewer_options::NoteViewerOptions,
utils::compute_note_hash_for_consumption
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use dep::types::{
max_block_number::MaxBlockNumber, membership_witness::NoteHashReadRequestMembershipWitness,
private_circuit_public_inputs::PrivateCircuitPublicInputs,
private_kernel::private_call_data::PrivateCallData, kernel_data::PrivateKernelData,
side_effect::{SideEffect, SideEffectLinkedToNoteHash}
nullifier::Nullifier, side_effect::SideEffect
},
address::{AztecAddress, EthAddress, PartialAddress, compute_initialization_hash},
contract_class_id::ContractClassId,
constants::{
MAX_NEW_NULLIFIERS_PER_CALL, MAX_NEW_L2_TO_L1_MSGS_PER_CALL, MAX_NEW_NOTE_HASHES_PER_CALL,
MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
MAX_NULLIFIER_READ_REQUESTS_PER_CALL, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL
MAX_NEW_NULLIFIERS_PER_CALL, MAX_NEW_L2_TO_L1_MSGS_PER_CALL, MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL,
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, MAX_NULLIFIER_READ_REQUESTS_PER_CALL,
MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL
},
hash::{
compute_l2_to_l1_hash, pedersen_hash, private_functions_root_from_siblings, silo_note_hash,
Expand Down Expand Up @@ -83,37 +83,6 @@ pub fn validate_note_hash_read_requests(
}
}

pub fn initialize_end_values(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to private_kernel_circuit_public_inputs_composer.

previous_kernel: PrivateKernelData,
public_inputs: &mut PrivateKernelCircuitPublicInputsBuilder
) {
public_inputs.constants = previous_kernel.public_inputs.constants;
public_inputs.min_revertible_side_effect_counter = previous_kernel.public_inputs.min_revertible_side_effect_counter;

let start = previous_kernel.public_inputs.validation_requests;
public_inputs.validation_requests.max_block_number = start.for_rollup.max_block_number;
public_inputs.validation_requests.note_hash_read_requests = array_to_bounded_vec(start.note_hash_read_requests);
public_inputs.validation_requests.nullifier_read_requests = array_to_bounded_vec(start.nullifier_read_requests);
public_inputs.validation_requests.nullifier_key_validation_requests = array_to_bounded_vec(start.nullifier_key_validation_requests);

// Ensure the arrays are the same as previously, before we start pushing more data onto them in other
// functions within this circuit:
let start = previous_kernel.public_inputs.end;

public_inputs.end.new_note_hashes = array_to_bounded_vec(start.new_note_hashes);
public_inputs.end.new_nullifiers = array_to_bounded_vec(start.new_nullifiers);

public_inputs.end.private_call_stack = array_to_bounded_vec(start.private_call_stack);
public_inputs.end.public_call_stack = array_to_bounded_vec(start.public_call_stack);
public_inputs.end.new_l2_to_l1_msgs = array_to_bounded_vec(start.new_l2_to_l1_msgs);

public_inputs.end.encrypted_logs_hashes = array_to_bounded_vec(start.encrypted_logs_hashes);
public_inputs.end.unencrypted_logs_hashes = array_to_bounded_vec(start.unencrypted_logs_hashes);

public_inputs.end.encrypted_log_preimages_length = start.encrypted_log_preimages_length;
public_inputs.end.unencrypted_log_preimages_length = start.unencrypted_log_preimages_length;
}

fn perform_static_call_checks(private_call: PrivateCallData) {
let public_inputs = private_call.call_stack_item.public_inputs;
let is_static_call = public_inputs.call_context.is_static_call;
Expand Down Expand Up @@ -217,11 +186,9 @@ pub fn update_end_values(
}
}

// Enhance commitments and nullifiers with domain separation whereby domain is the contract.
//
// nullifiers
// Nullifiers
let new_nullifiers = private_call_public_inputs.new_nullifiers;
let mut siloed_new_nullifiers: BoundedVec<SideEffectLinkedToNoteHash, MAX_NEW_NULLIFIERS_PER_CALL> = BoundedVec::new();
let mut siloed_new_nullifiers: BoundedVec<Nullifier, 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 +198,7 @@ pub fn update_end_values(
silo_note_hash(storage_contract_address, new_nullifier.note_hash)
};
siloed_new_nullifiers.push(
SideEffectLinkedToNoteHash {
Nullifier {
value: silo_nullifier(storage_contract_address, new_nullifier.value),
counter: new_nullifier.counter,
note_hash: siloed_note_hash
Expand All @@ -241,19 +208,6 @@ pub fn update_end_values(
}
public_inputs.end.new_nullifiers.extend_from_bounded_vec(siloed_new_nullifiers);

// note hashes
let new_note_hashes = private_call_public_inputs.new_note_hashes;
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 {
siloed_new_note_hashes.push(
SideEffect { value: silo_note_hash(storage_contract_address, new_note_hash), counter: new_note_hashes[i].counter }
);
}
}
public_inputs.end.new_note_hashes.extend_from_bounded_vec(siloed_new_note_hashes);

// Call stacks
// Private call stack.
let private_call_stack = array_to_bounded_vec(private_call.private_call_stack);
Expand Down
Loading