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: remove note hash nullifier counter. #7294

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ impl PreviousKernelValidator {
}

fn verify_no_transient_data(self) {
// Currently all the transient note hashes and nullifiers must be cleared in the reset circuits.
// Check that the propagated note hashes don't link to a nullifier, and vice versa.
for note_hash in self.previous_kernel.end.note_hashes {
assert_eq(note_hash.nullifier_counter, 0, "Unresolved transient note hash");
}
// Currently all the transient nullifiers must be cleared in the reset circuits.
// When a transient nullifier is removed, the linked note hash and all the associated note logs will also be removed.
for nullifier in self.previous_kernel.end.nullifiers {
assert_eq(nullifier.nullified_note_hash(), 0, "Unresolved transient nullifier");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use dep::types::{
abis::{
call_request::CallRequest,
kernel_circuit_public_inputs::{PrivateKernelCircuitPublicInputs, PrivateKernelCircuitPublicInputsArrayLengths},
max_block_number::MaxBlockNumber, note_hash::ScopedNoteHash,
max_block_number::MaxBlockNumber,
private_circuit_public_inputs::{PrivateCircuitPublicInputs, PrivateCircuitPublicInputsArrayLengths},
private_kernel::private_call_data::PrivateCallData, side_effect::Scoped
},
Expand Down Expand Up @@ -103,28 +103,6 @@ fn validate_array_appended_reversed_scoped<ST, T, N, M>(
}
}

fn validate_note_hash_nullifier_counters<N, M>(
dest: [ScopedNoteHash; N],
note_hash_nullifier_counters: [u32; M],
num_source_items: u32,
num_prepended_items: u32
) {
let mut is_non_empty_item = true;
for i in 0..M {
is_non_empty_item &= i != num_source_items;
if is_non_empty_item {
let nullifier_counter = note_hash_nullifier_counters[i];
let note_hash = dest[i + num_prepended_items];
assert(
(nullifier_counter == 0) | (nullifier_counter > note_hash.counter()), "invalid nullifier counter"
);
assert_eq(
note_hash.nullifier_counter, nullifier_counter, "incorrect nullifier counter assigned to dest"
);
}
}
}

struct PrivateKernelCircuitOutputValidator {
output: PrivateKernelCircuitPublicInputs,
}
Expand All @@ -134,13 +112,12 @@ impl PrivateKernelCircuitOutputValidator {
PrivateKernelCircuitOutputValidator { output }
}

pub fn validate_as_first_call<NOTE_HASH_NULLIFIER_COUNTERS_LEN, PUBLIC_CALL_REQUESTS_LEN>(
pub fn validate_as_first_call<PUBLIC_CALL_REQUESTS_LEN>(
self,
tx_request: TxRequest,
private_call: PrivateCircuitPublicInputs,
private_call_array_lengths: PrivateCircuitPublicInputsArrayLengths,
contract_address: AztecAddress,
note_hash_nullifier_counters: [u32; NOTE_HASH_NULLIFIER_COUNTERS_LEN],
public_call_requests: [CallRequest; PUBLIC_CALL_REQUESTS_LEN],
public_teardown_call_request: CallRequest
) {
Expand All @@ -153,19 +130,17 @@ impl PrivateKernelCircuitOutputValidator {
offsets,
0, // num_popped_call
contract_address,
note_hash_nullifier_counters,
public_call_requests
);
}

pub fn validate_as_inner_call<NOTE_HASH_NULLIFIER_COUNTERS_LEN, PUBLIC_CALL_REQUESTS_LEN>(
pub fn validate_as_inner_call<PUBLIC_CALL_REQUESTS_LEN>(
self,
previous_kernel: PrivateKernelCircuitPublicInputs,
previous_kernel_array_lengths: PrivateKernelCircuitPublicInputsArrayLengths,
private_call: PrivateCircuitPublicInputs,
private_call_array_lengths: PrivateCircuitPublicInputsArrayLengths,
contract_address: AztecAddress,
note_hash_nullifier_counters: [u32; NOTE_HASH_NULLIFIER_COUNTERS_LEN],
public_call_requests: [CallRequest; PUBLIC_CALL_REQUESTS_LEN],
public_teardown_call_request: CallRequest
) {
Expand All @@ -177,7 +152,6 @@ impl PrivateKernelCircuitOutputValidator {
previous_kernel_array_lengths,
1, // num_popped_call
contract_address,
note_hash_nullifier_counters,
public_call_requests
);
}
Expand Down Expand Up @@ -336,14 +310,13 @@ impl PrivateKernelCircuitOutputValidator {
);
}

fn validate_propagated_from_private_call<NOTE_HASH_NULLIFIER_COUNTERS_LEN, PUBLIC_CALL_REQUESTS_LEN>(
fn validate_propagated_from_private_call<PUBLIC_CALL_REQUESTS_LEN>(
self,
private_call: PrivateCircuitPublicInputs,
array_lengths: PrivateCircuitPublicInputsArrayLengths,
offsets: PrivateKernelCircuitPublicInputsArrayLengths,
num_popped_call: u32,
contract_address: AztecAddress,
note_hash_nullifier_counters: [u32; NOTE_HASH_NULLIFIER_COUNTERS_LEN],
public_call_requests: [CallRequest; PUBLIC_CALL_REQUESTS_LEN]
) {
let storage_contract_address = private_call.call_context.storage_contract_address;
Expand Down Expand Up @@ -375,12 +348,6 @@ impl PrivateKernelCircuitOutputValidator {
offsets.note_hashes,
storage_contract_address
);
validate_note_hash_nullifier_counters(
self.output.end.note_hashes,
note_hash_nullifier_counters,
array_lengths.note_hashes,
offsets.note_hashes
);
validate_array_appended_scoped(
self.output.end.nullifiers,
private_call.nullifiers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use dep::types::{
},
address::AztecAddress,
constants::{
MAX_NOTE_HASHES_PER_CALL, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, MAX_NOTE_HASHES_PER_TX,
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, MAX_NOTE_HASHES_PER_TX,
MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL
},
hash::{
Expand All @@ -22,7 +22,6 @@ struct DataSource {
private_call_public_inputs: PrivateCircuitPublicInputs,
contract_address: AztecAddress,
storage_contract_address: AztecAddress,
note_hash_nullifier_counters: [u32; MAX_NOTE_HASHES_PER_CALL],
public_call_requests: [CallRequest; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL],
public_teardown_call_request: CallRequest,
}
Expand Down Expand Up @@ -91,7 +90,6 @@ impl PrivateKernelCircuitPublicInputsComposer {
&mut self,
private_call_public_inputs: PrivateCircuitPublicInputs,
contract_address: AztecAddress,
note_hash_nullifier_counters: [u32; MAX_NOTE_HASHES_PER_CALL],
public_call_requests: [CallRequest; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL],
public_teardown_call_request: CallRequest
) -> Self {
Expand All @@ -100,7 +98,6 @@ impl PrivateKernelCircuitPublicInputsComposer {
private_call_public_inputs,
contract_address,
storage_contract_address,
note_hash_nullifier_counters,
public_call_requests,
public_teardown_call_request
};
Expand Down Expand Up @@ -183,13 +180,9 @@ impl PrivateKernelCircuitPublicInputsComposer {
fn propagate_note_hashes(&mut self, source: DataSource) {
let note_hashes = source.private_call_public_inputs.note_hashes;
for i in 0..note_hashes.len() {
let mut note_hash = note_hashes[i];
let note_hash = note_hashes[i];
if note_hash.value != 0 {
let nullifier_counter = source.note_hash_nullifier_counters[i];
assert(
(nullifier_counter == 0) | (nullifier_counter > note_hash.counter), "Invalid nullifier counter"
);
self.public_inputs.end.note_hashes.push(note_hash.scope(nullifier_counter, source.storage_contract_address));
self.public_inputs.end.note_hashes.push(note_hash.scope(source.storage_contract_address));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@ use dep::types::{
kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs,
private_kernel::private_call_data::PrivateCallData
},
constants::MAX_NOTE_HASHES_PER_CALL, transaction::tx_request::TxRequest
transaction::tx_request::TxRequest
};

struct PrivateKernelInitHints {
// TODO: Remove note_hash_nullifier_counters.
note_hash_nullifier_counters: [u32; MAX_NOTE_HASHES_PER_CALL],
}

// Initialization struct for private inputs to the private kernel
struct PrivateKernelInitCircuitPrivateInputs {
tx_request: TxRequest,
private_call: PrivateCallData,
hints: PrivateKernelInitHints,
}

impl PrivateKernelInitCircuitPrivateInputs {
Expand All @@ -31,7 +25,6 @@ impl PrivateKernelInitCircuitPrivateInputs {
PrivateKernelCircuitPublicInputsComposer::new_from_tx_request(self.tx_request, private_call_public_inputs).with_private_call(
private_call_public_inputs,
self.private_call.call_stack_item.contract_address,
self.hints.note_hash_nullifier_counters,
self.private_call.public_call_stack,
self.private_call.public_teardown_call_request
).finish()
Expand All @@ -58,7 +51,6 @@ impl PrivateKernelInitCircuitPrivateInputs {
self.private_call.call_stack_item.public_inputs,
private_call_data_validator.array_lengths,
self.private_call.call_stack_item.contract_address,
self.hints.note_hash_nullifier_counters,
self.private_call.public_call_stack,
self.private_call.public_teardown_call_request
);
Expand All @@ -68,31 +60,28 @@ impl PrivateKernelInitCircuitPrivateInputs {
}

mod tests {
use crate::private_kernel_init::{PrivateKernelInitHints, PrivateKernelInitCircuitPrivateInputs};
use crate::private_kernel_init::PrivateKernelInitCircuitPrivateInputs;
use dep::types::{
abis::{kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs},
constants::MAX_NOTE_HASHES_PER_CALL,
tests::{fixture_builder::FixtureBuilder, utils::assert_array_eq},
transaction::tx_request::TxRequest
};

struct PrivateKernelInitInputsBuilder {
tx_request: TxRequest,
private_call: FixtureBuilder,
hints: PrivateKernelInitHints,
}

impl PrivateKernelInitInputsBuilder {
pub fn new() -> Self {
let private_call = FixtureBuilder::new();
let tx_request = private_call.build_tx_request();
let hints = PrivateKernelInitHints { note_hash_nullifier_counters: [0; MAX_NOTE_HASHES_PER_CALL] };
PrivateKernelInitInputsBuilder { tx_request, private_call, hints }
PrivateKernelInitInputsBuilder { tx_request, private_call }
}

pub fn execute(self) -> PrivateKernelCircuitPublicInputs {
let private_call = self.private_call.to_private_call_data();
PrivateKernelInitCircuitPrivateInputs { tx_request: self.tx_request, private_call, hints: self.hints }.execute()
PrivateKernelInitCircuitPrivateInputs { tx_request: self.tx_request, private_call }.execute()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,19 @@ use dep::types::{
abis::{
kernel_circuit_public_inputs::{PrivateKernelCircuitPublicInputs, PrivateKernelCircuitPublicInputsArrayLengths},
private_kernel_data::PrivateKernelData, private_kernel::private_call_data::PrivateCallData
},
constants::MAX_NOTE_HASHES_PER_CALL
};

struct PrivateKernelInnerHints {
note_hash_nullifier_counters: [u32; MAX_NOTE_HASHES_PER_CALL],
}
};

struct PrivateKernelInnerCircuitPrivateInputs {
previous_kernel: PrivateKernelData,
private_call: PrivateCallData,
hints: PrivateKernelInnerHints,
}

impl PrivateKernelInnerCircuitPrivateInputs {
unconstrained fn generate_output(self) -> PrivateKernelCircuitPublicInputs {
PrivateKernelCircuitPublicInputsComposer::new_from_previous_kernel(self.previous_kernel.public_inputs).pop_top_call_request().with_private_call(
self.private_call.call_stack_item.public_inputs,
self.private_call.call_stack_item.contract_address,
self.hints.note_hash_nullifier_counters,
self.private_call.public_call_stack,
self.private_call.public_teardown_call_request
).finish()
Expand Down Expand Up @@ -61,7 +54,6 @@ impl PrivateKernelInnerCircuitPrivateInputs {
self.private_call.call_stack_item.public_inputs,
private_call_data_validator.array_lengths,
self.private_call.call_stack_item.contract_address,
self.hints.note_hash_nullifier_counters,
self.private_call.public_call_stack,
self.private_call.public_teardown_call_request
);
Expand All @@ -71,29 +63,26 @@ impl PrivateKernelInnerCircuitPrivateInputs {
}

mod tests {
use crate::private_kernel_inner::{PrivateKernelInnerCircuitPrivateInputs, PrivateKernelInnerHints};
use crate::private_kernel_inner::PrivateKernelInnerCircuitPrivateInputs;
use dep::types::{
abis::{kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs},
constants::MAX_NOTE_HASHES_PER_CALL,
tests::{fixture_builder::FixtureBuilder, utils::assert_array_eq}
};

struct PrivateKernelInnerInputsBuilder {
previous_kernel: FixtureBuilder,
private_call: FixtureBuilder,
hints: PrivateKernelInnerHints,
}

impl PrivateKernelInnerInputsBuilder {
pub fn new() -> Self {
let mut previous_kernel = FixtureBuilder::new_from_counter(15).as_parent_contract();
let private_call = FixtureBuilder::new_from_counter(200);
let hints = PrivateKernelInnerHints { note_hash_nullifier_counters: [0; MAX_NOTE_HASHES_PER_CALL] };

// 0th nullifier must be non-zero.
previous_kernel.append_nullifiers(1);

PrivateKernelInnerInputsBuilder { previous_kernel, private_call, hints }
PrivateKernelInnerInputsBuilder { previous_kernel, private_call }
}

pub fn execute(&mut self) -> PrivateKernelCircuitPublicInputs {
Expand All @@ -104,7 +93,7 @@ mod tests {
self.previous_kernel.add_private_call_request(hash, is_delegate_call);
let previous_kernel = self.previous_kernel.to_private_kernel_data();

let kernel = PrivateKernelInnerCircuitPrivateInputs { previous_kernel, private_call, hints: self.hints };
let kernel = PrivateKernelInnerCircuitPrivateInputs { previous_kernel, private_call };

kernel.execute()
}
Expand Down
Loading
Loading