-
Notifications
You must be signed in to change notification settings - Fork 615
feat: prepare circuit output for validation #6678
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
Merged
Merged
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
2aa7ed2
Verify built output for private init.
LeilaWang 4bf7ad5
Tests for private kernel circuit public inputs composer.
LeilaWang cfb64c1
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang 90681c8
Fixes after merge.
LeilaWang 5a5bbd8
Update tests.
LeilaWang e07cef8
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang 92c792f
Move tests to folder.
LeilaWang 5354e92
Merge branch 'master' into lw/circuit_output_validation
ludamad 85f68c3
Use fixture builder for private call.
LeilaWang 2774eb2
Merge remote-tracking branch 'origin/lw/circuit_output_validation' in…
LeilaWang 4f54da1
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang 7b9504e
Fix after merge.
LeilaWang 026f359
Update tests.
LeilaWang b47042e
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang 7b4584b
Fix fixtures.
LeilaWang 611726a
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang 3dfd361
Move components to folder.
LeilaWang 50702a7
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang 7d06e86
Address feedback.
LeilaWang 3c245ae
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang b97e523
Check note logs in private call data validator.
LeilaWang 1901d3b
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang f3895fa
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang 09805ad
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang 02fd639
Fix.
LeilaWang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
1 change: 1 addition & 0 deletions
1
noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components.nr
This file contains hidden or 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 @@ | ||
| mod private_kernel_circuit_output_validator; |
434 changes: 434 additions & 0 deletions
434
...cuits/crates/private-kernel-lib/src/components/private_kernel_circuit_output_validator.nr
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/lib.nr
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -2,8 +2,8 @@ use dep::types::{ | |
| abis::{ | ||
| call_request::CallRequest, combined_constant_data::CombinedConstantData, | ||
| kernel_circuit_public_inputs::{PrivateKernelCircuitPublicInputs, PrivateKernelCircuitPublicInputsBuilder}, | ||
| max_block_number::MaxBlockNumber, nullifier::Nullifier, note_hash::ScopedNoteHash, | ||
| log_hash::NoteLogHash, | ||
| max_block_number::MaxBlockNumber, nullifier::{Nullifier, ScopedNullifier}, | ||
| note_hash::ScopedNoteHash, log_hash::NoteLogHash, | ||
| private_circuit_public_inputs::{PrivateCircuitPublicInputs, PrivateCircuitPublicInputsArrayLengths} | ||
| }, | ||
| address::AztecAddress, | ||
|
|
@@ -25,6 +25,10 @@ struct DataSource { | |
| public_teardown_call_request: CallRequest, | ||
| } | ||
|
|
||
| pub fn create_first_nullifier(tx_request: TxRequest) -> ScopedNullifier { | ||
| Nullifier { value: tx_request.hash(), note_hash: 0, counter: 0 }.scope(AztecAddress::zero()) | ||
| } | ||
|
|
||
| struct PrivateKernelCircuitPublicInputsComposer { | ||
| public_inputs: PrivateKernelCircuitPublicInputsBuilder, | ||
| } | ||
|
|
@@ -38,10 +42,8 @@ impl PrivateKernelCircuitPublicInputsComposer { | |
| tx_request.tx_context, | ||
| ); | ||
|
|
||
| public_inputs.min_revertible_side_effect_counter = private_call_public_inputs.min_revertible_side_effect_counter; | ||
|
|
||
| // Since it's the first iteration, we need to push the the tx hash nullifier into the `new_nullifiers` array | ||
| public_inputs.end.new_nullifiers.push(Nullifier { value: tx_request.hash(), note_hash: 0, counter: 0 }.scope(AztecAddress::zero())); | ||
| // Since it's the first iteration, we need to push the tx hash nullifier into the `new_nullifiers` array | ||
| public_inputs.end.new_nullifiers.push(create_first_nullifier(tx_request)); | ||
| // Note that we do not need to nullify the transaction request nonce anymore. | ||
| // Should an account want to additionally use nonces for replay protection or handling cancellations, | ||
| // they will be able to do so in the account contract logic: | ||
|
|
@@ -97,7 +99,16 @@ impl PrivateKernelCircuitPublicInputsComposer { | |
| public_call_requests, | ||
| public_teardown_call_request | ||
| }; | ||
| self.propagate_from_private_call(source); | ||
|
|
||
| *self | ||
| } | ||
|
|
||
| pub fn finish(self) -> PrivateKernelCircuitPublicInputs { | ||
| self.public_inputs.finish() | ||
| } | ||
|
|
||
| fn propagate_from_private_call(&mut self, source: DataSource) { | ||
| self.propagate_max_block_number(source); | ||
| self.propagate_note_hash_read_requests(source); | ||
| self.propagate_nullifier_read_requests(source); | ||
|
|
@@ -111,19 +122,15 @@ impl PrivateKernelCircuitPublicInputsComposer { | |
| self.propagate_public_teardown_call_request(source); | ||
| self.propagate_fee_payer(source); | ||
| self.propagate_min_revertible_side_effect_counter(source); | ||
|
|
||
| *self | ||
| } | ||
|
|
||
| pub fn finish(self) -> PrivateKernelCircuitPublicInputs { | ||
| self.public_inputs.finish() | ||
| } | ||
|
|
||
| fn propagate_min_revertible_side_effect_counter(&mut self, source: DataSource) { | ||
| self.public_inputs.min_revertible_side_effect_counter = if self.public_inputs.min_revertible_side_effect_counter > 0 { | ||
| self.public_inputs.min_revertible_side_effect_counter | ||
| if self.public_inputs.min_revertible_side_effect_counter != 0 { | ||
| assert( | ||
| source.private_call_public_inputs.min_revertible_side_effect_counter == 0, "cannot overwrite non-zero min_revertible_side_effect_counter" | ||
| ); | ||
| } else { | ||
| source.private_call_public_inputs.min_revertible_side_effect_counter | ||
| self.public_inputs.min_revertible_side_effect_counter = source.private_call_public_inputs.min_revertible_side_effect_counter; | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -204,6 +211,7 @@ impl PrivateKernelCircuitPublicInputsComposer { | |
| self.public_inputs.end.encrypted_logs_hashes.push(log.scope(source.storage_contract_address)); | ||
| } | ||
| } | ||
|
|
||
| let unencrypted_logs = source.private_call_public_inputs.unencrypted_logs_hashes; | ||
| for i in 0..unencrypted_logs.len() { | ||
| let log = unencrypted_logs[i]; | ||
|
|
@@ -213,15 +221,13 @@ impl PrivateKernelCircuitPublicInputsComposer { | |
| } | ||
|
|
||
| let note_logs = source.private_call_public_inputs.note_encrypted_logs_hashes; | ||
| let new_note_hashes = self.public_inputs.end.new_note_hashes; | ||
| for i in 0..note_logs.len() { | ||
| if !is_empty(note_logs[i]) { | ||
| let note_index = self.match_log_to_note(note_logs[i]); | ||
| assert( | ||
| note_index < MAX_NEW_NOTE_HASHES_PER_TX, "Could not find note hash linked to note log." | ||
| ); | ||
| assert( | ||
| note_logs[i].note_hash_counter | ||
| == self.public_inputs.end.new_note_hashes.get_unchecked(note_index).counter(), "Could not find note hash linked to note log." | ||
| assert(note_index < new_note_hashes.len(), "Could not find note hash linked to note log"); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to check against the number of non-empty items. Otherwise, we would be allowing a log to link to counter 0. |
||
| assert_eq( | ||
| note_logs[i].note_hash_counter, new_note_hashes.get_unchecked(note_index).counter(), "Could not find note hash linked to note log" | ||
| ); | ||
| self.public_inputs.end.note_encrypted_logs_hashes.push(note_logs[i]); | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assigning the min counter in
propagate_from_private_callinstead, which is run by both init and inner.