-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove note hash nullifier counter. (#7294)
- Loading branch information
Showing
41 changed files
with
429 additions
and
874 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
.../noir-protocol-circuits/crates/private-kernel-lib/src/components/reset_output_composer.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
mod squash_transient_data; | ||
|
||
use crate::components::reset_output_composer::squash_transient_data::squash_transient_data; | ||
use dep::types::{ | ||
abis::{ | ||
kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs, log_hash::NoteLogHash, | ||
note_hash::ScopedNoteHash, nullifier::ScopedNullifier | ||
}, | ||
constants::{MAX_NOTE_ENCRYPTED_LOGS_PER_TX, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX} | ||
}; | ||
|
||
struct PrivateKernelResetOutputs { | ||
note_hashes: [ScopedNoteHash; MAX_NOTE_HASHES_PER_TX], | ||
nullifiers: [ScopedNullifier; MAX_NULLIFIERS_PER_TX], | ||
note_encrypted_log_hashes: [NoteLogHash; MAX_NOTE_ENCRYPTED_LOGS_PER_TX], | ||
} | ||
|
||
struct ResetOutputComposer { | ||
output: PrivateKernelResetOutputs, | ||
} | ||
|
||
impl ResetOutputComposer { | ||
pub fn new( | ||
previous_kernel: PrivateKernelCircuitPublicInputs, | ||
transient_nullifier_indexes_for_note_hashes: [u32; MAX_NOTE_HASHES_PER_TX], | ||
transient_note_hash_indexes_for_nullifiers: [u32; MAX_NULLIFIERS_PER_TX] | ||
) -> Self { | ||
let (note_hashes, nullifiers, note_encrypted_log_hashes) = squash_transient_data( | ||
previous_kernel.end.note_hashes, | ||
previous_kernel.end.nullifiers, | ||
previous_kernel.end.note_encrypted_logs_hashes, | ||
transient_nullifier_indexes_for_note_hashes, | ||
transient_note_hash_indexes_for_nullifiers | ||
); | ||
let output = PrivateKernelResetOutputs { note_hashes, nullifiers, note_encrypted_log_hashes }; | ||
ResetOutputComposer { output } | ||
} | ||
|
||
pub fn finish(self) -> PrivateKernelResetOutputs { | ||
self.output | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...s/crates/private-kernel-lib/src/components/reset_output_composer/squash_transient_data.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use dep::types::abis::{note_hash::ScopedNoteHash, nullifier::ScopedNullifier, log_hash::NoteLogHash}; | ||
|
||
unconstrained pub fn squash_transient_data<M, N, P>( | ||
note_hashes: [ScopedNoteHash; M], | ||
nullifiers: [ScopedNullifier; N], | ||
logs: [NoteLogHash; P], | ||
transient_nullifier_indexes_for_note_hashes: [u32; M], | ||
transient_note_hash_indexes_for_nullifiers: [u32; N] | ||
) -> ([ScopedNoteHash; M], [ScopedNullifier; N], [NoteLogHash; P]) { | ||
let mut propagated_note_hashes = BoundedVec::new(); | ||
for i in 0..note_hashes.len() { | ||
if transient_nullifier_indexes_for_note_hashes[i] == N { | ||
propagated_note_hashes.push(note_hashes[i]); | ||
} | ||
} | ||
|
||
let mut propagated_nullifiers = BoundedVec::new(); | ||
for i in 0..N { | ||
if transient_note_hash_indexes_for_nullifiers[i] == M { | ||
propagated_nullifiers.push(nullifiers[i]); | ||
} | ||
} | ||
|
||
let mut propagated_logs = BoundedVec::new(); | ||
for i in 0..logs.len() { | ||
let log = logs[i]; | ||
let linked_note_hash_propagated = propagated_note_hashes.storage.any(|n: ScopedNoteHash| (n.counter() == log.note_hash_counter)); | ||
if linked_note_hash_propagated { | ||
propagated_logs.push(log); | ||
} | ||
} | ||
|
||
(propagated_note_hashes.storage, propagated_nullifiers.storage, propagated_logs.storage) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.