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: Add first version of kernel reset circuit #6393

Merged
merged 23 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6204854
wip private kernel reset
sirasistant May 14, 2024
308b4be
integrate reset in ts
sirasistant May 14, 2024
b322d6f
Merge branch 'master' into arv/reset_circuit_v1
sirasistant May 14, 2024
c855f03
fix tail to public
sirasistant May 14, 2024
a6287c1
Merge branch 'master' into arv/reset_circuit_v1
sirasistant May 14, 2024
7b01f1b
test: reenable commented out tests
sirasistant May 14, 2024
0a17eca
test: move removed tests to the reset
sirasistant May 14, 2024
cd5a4d7
fix: tail to public again
sirasistant May 14, 2024
430cee8
test: fix unit
sirasistant May 14, 2024
9060138
Merge branch 'master' into arv/reset_circuit_v1
sirasistant May 15, 2024
ad4d43e
fix: typos
sirasistant May 15, 2024
083799d
test: added nk validation propagation to the test
sirasistant May 15, 2024
8ecf2b4
typo
sirasistant May 15, 2024
e9567db
Merge branch 'master' into arv/reset_circuit_v1
sirasistant May 15, 2024
bd78234
Merge branch 'master' into arv/reset_circuit_v1
sirasistant May 15, 2024
9596cb5
refactor: extract empty checks for rr to composer
sirasistant May 15, 2024
287a723
fix: actually call the function
sirasistant May 15, 2024
a53b93d
fix validation and add test
sirasistant May 15, 2024
aeba2ab
Merge branch 'master' into arv/reset_circuit_v1
sirasistant May 15, 2024
cf1903c
fix import
sirasistant May 15, 2024
7e3a0ec
Merge branch 'arv/reset_circuit_v1' of github.com:AztecProtocol/aztec…
sirasistant May 15, 2024
c2da9b0
fix: noir test
sirasistant May 15, 2024
0fb72d2
fmt
sirasistant May 15, 2024
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: 2 additions & 0 deletions noir-projects/noir-protocol-circuits/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ members = [
"crates/private-kernel-init-simulated",
"crates/private-kernel-inner",
"crates/private-kernel-inner-simulated",
"crates/private-kernel-reset",
"crates/private-kernel-reset-simulated",
"crates/private-kernel-tail",
"crates/private-kernel-tail-simulated",
"crates/private-kernel-tail-to-public",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use dep::reset_kernel_lib::verify_squashed_transient_note_hashes_and_nullifiers;
use dep::types::{
abis::{
private_kernel_data::PrivateKernelData,
Expand All @@ -23,12 +22,7 @@ fn asc_sort_by_counters<T>(a: T, b: T) -> bool where T: Ordered {
struct KernelCircuitPublicInputsComposer {
public_inputs: PrivateKernelCircuitPublicInputsBuilder,
previous_kernel: PrivateKernelData,
// Final data
note_hashes: [ScopedNoteHash; MAX_NEW_NOTE_HASHES_PER_TX],
nullifiers: [ScopedNullifier; MAX_NEW_NULLIFIERS_PER_TX],
// Hints
transient_nullifier_indexes_for_note_hashes: [u64; MAX_NEW_NOTE_HASHES_PER_TX],
transient_note_hash_indexes_for_nullifiers: [u64; MAX_NEW_NULLIFIERS_PER_TX],
sorted_note_hashes: [ScopedNoteHash; MAX_NEW_NOTE_HASHES_PER_TX],
sorted_note_hashes_indexes: [u64; MAX_NEW_NOTE_HASHES_PER_TX],
sorted_nullifiers: [ScopedNullifier; MAX_NEW_NULLIFIERS_PER_TX],
Expand All @@ -42,10 +36,6 @@ struct KernelCircuitPublicInputsComposer {
impl KernelCircuitPublicInputsComposer {
pub fn new(
previous_kernel: PrivateKernelData,
note_hashes: [ScopedNoteHash; MAX_NEW_NOTE_HASHES_PER_TX],
nullifiers: [ScopedNullifier; MAX_NEW_NULLIFIERS_PER_TX],
transient_nullifier_indexes_for_note_hashes: [u64; MAX_NEW_NOTE_HASHES_PER_TX],
transient_note_hash_indexes_for_nullifiers: [u64; MAX_NEW_NULLIFIERS_PER_TX],
sorted_note_hashes: [ScopedNoteHash; MAX_NEW_NOTE_HASHES_PER_TX],
sorted_note_hashes_indexes: [u64; MAX_NEW_NOTE_HASHES_PER_TX],
sorted_nullifiers: [ScopedNullifier; MAX_NEW_NULLIFIERS_PER_TX],
Expand All @@ -60,10 +50,6 @@ impl KernelCircuitPublicInputsComposer {
KernelCircuitPublicInputsComposer {
public_inputs,
previous_kernel,
note_hashes,
nullifiers,
transient_nullifier_indexes_for_note_hashes,
transient_note_hash_indexes_for_nullifiers,
sorted_note_hashes,
sorted_note_hashes_indexes,
sorted_nullifiers,
Expand All @@ -79,6 +65,7 @@ impl KernelCircuitPublicInputsComposer {
assert_eq(
array_length(self.previous_kernel.public_inputs.end.private_call_stack), 0, "Private call stack must be empty when executing the tail circuit"
);
self.verify_empty_validation_requests();

self.propagate_rollup_validation_requests();

Expand All @@ -88,8 +75,7 @@ impl KernelCircuitPublicInputsComposer {

self.propagate_fee_payer();

// TODO: Should be done in a reset circuit.
self.squash_transient_data();
self.verify_no_transient_data();

self.silo_values();

Expand Down Expand Up @@ -236,26 +222,28 @@ impl KernelCircuitPublicInputsComposer {
self.public_inputs.fee_payer = self.previous_kernel.public_inputs.fee_payer;
}

fn squash_transient_data(&mut self) {
verify_squashed_transient_note_hashes_and_nullifiers(
self.public_inputs.end.new_note_hashes.storage,
self.public_inputs.end.new_nullifiers.storage,
self.note_hashes,
self.nullifiers,
self.transient_nullifier_indexes_for_note_hashes,
self.transient_note_hash_indexes_for_nullifiers
);

// Currently all the transient note hashes and nullifiers must be cleared in the tail circuits.
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 i in 0..self.note_hashes.len() {
assert(self.note_hashes[i].nullifier_counter == 0, "Unresolved transient note hash");
for note_hash in self.public_inputs.end.new_note_hashes.storage {
assert(note_hash.nullifier_counter == 0, "Unresolved transient note hash");
}
for i in 0..self.nullifiers.len() {
assert(self.nullifiers[i].nullified_note_hash() == 0, "Unresolved transient nullifier");
for new_nullifier in self.public_inputs.end.new_nullifiers.storage {
assert(new_nullifier.nullified_note_hash() == 0, "Unresolved transient nullifier");
}
}

fn verify_empty_validation_requests(self) {
assert_eq(
array_length(self.previous_kernel.public_inputs.validation_requests.note_hash_read_requests), 0, "Non empty note hash read requests"
);

self.public_inputs.end.new_note_hashes = array_to_bounded_vec(self.note_hashes);
self.public_inputs.end.new_nullifiers = array_to_bounded_vec(self.nullifiers);
assert_eq(
array_length(self.previous_kernel.public_inputs.validation_requests.nullifier_read_requests), 0, "Non empty nullifier read requests"
);

assert_eq(
array_length(self.previous_kernel.public_inputs.validation_requests.nullifier_key_validation_requests), 0, "Non empty nullifier key validation requests"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ mod private_kernel_inner;
mod private_kernel_tail;
mod private_kernel_tail_to_public;
mod tests;
mod private_kernel_reset;

use private_kernel_init::PrivateKernelInitCircuitPrivateInputs;
use private_kernel_inner::PrivateKernelInnerCircuitPrivateInputs;
use private_kernel_reset::PrivateKernelResetCircuitPrivateInputs;
use private_kernel_tail::PrivateKernelTailCircuitPrivateInputs;
use private_kernel_tail_to_public::PrivateKernelTailToPublicCircuitPrivateInputs;
Loading
Loading