-
Notifications
You must be signed in to change notification settings - Fork 613
feat: public kernel in noir #3186
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 30 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
3845a05
add start of public kernel private previous
dan-aztec b3b78fc
Merge remote-tracking branch 'origin/master' into dan/public-kernel-noir
kevaundray 0ff674b
semver check
kevaundray ee3f910
more common functions
dan-aztec e4c0350
Update yarn-project/noir-protocol-circuits/src/crates/public-kernel-p…
dan-aztec 8f120b1
dont duplicate from private-kernel-lib
dan-aztec 134adc5
switch to private-kernel-lib for deps
dan-aztec bf7395f
Merge branch 'master' into dan/public-kernel-noir
sirasistant b8c2b84
fix: fix some import statements after reorg
sirasistant 0e40e98
fix: fix some imports
sirasistant 369f999
start compile fixes
dan-aztec c049a01
more bugs
dan-aztec 2de99bc
more bad code fixes
dan-aztec 0990b20
&mut
dan-aztec 0a75d50
Merge branch 'master' into dan/public-kernel-noir
sirasistant 47b8bf8
fix: fixed some compilation issues
sirasistant d6713cb
fix: fixed the last compile issues
sirasistant 557446a
feat: added type conversions
sirasistant 1c1c744
feat: wire up the public kernel private prev
sirasistant 17f1c3e
fix: hash mismatch fix
sirasistant 2b5f306
fix: run simulated public kernel
sirasistant 045f2d1
fix: fix shape of public call stack
sirasistant 007b27d
chore: added logs for the bench
sirasistant e4cb2b6
fix: actually simulate in parallel
sirasistant c510baa
Merge branch 'master' into dan/public-kernel-noir
sirasistant e3bd615
test: added interop testing for public call stack
sirasistant c28ae34
Merge branch 'master' into dan/public-kernel-noir
sirasistant c22e462
Merge remote-tracking branch 'origin/master' into dan/public-kernel-noir
LeilaWang c7f1572
Update type.
LeilaWang 9775d08
Update yarn-project/noir-protocol-circuits/src/crates/public-kernel-l…
kevaundray 025b5d0
merge conflicts
dan-aztec 0459fc7
bad merge deletions
dan-aztec c2cc7fc
formatting
dan-aztec 6782067
format hpp
dan-aztec 32e0146
formatting
dan-aztec c27244b
comments
dan-aztec 0aacd7d
correct return types in acvm execution
dan-aztec dd07f9a
Merge branch 'master' into dan/public-kernel-noir
dan-aztec 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
9 changes: 9 additions & 0 deletions
9
yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/Nargo.toml
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,9 @@ | ||
| [package] | ||
| name = "public_kernel_lib" | ||
| type = "lib" | ||
| authors = [""] | ||
| compiler_version = ">=0.18.0" | ||
|
|
||
| [dependencies] | ||
| aztec = { path = "../../../../aztec-nr/aztec" } | ||
| types = { path = "../types" } |
1 change: 1 addition & 0 deletions
1
yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/abis.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 public_call_data; |
15 changes: 15 additions & 0 deletions
15
...-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/abis/public_call_data.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,15 @@ | ||
| use dep::aztec::constants_gen::{MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL}; | ||
| use dep::types::address::{Address, EthAddress}; | ||
| use dep::types::utils::bounded_vec::BoundedVec; | ||
| use dep::types::abis::call_stack_item::PublicCallStackItem; | ||
| use dep::types::mocked::Proof; | ||
|
|
||
| struct PublicCallData { | ||
| call_stack_item: PublicCallStackItem, | ||
| public_call_stack_preimages: [PublicCallStackItem; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], | ||
|
|
||
| proof: Proof, | ||
| portal_contract_address: EthAddress, | ||
| bytecode_hash: Field, | ||
|
|
||
| } |
357 changes: 357 additions & 0 deletions
357
yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/common.nr
Large diffs are not rendered by default.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/hash.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,19 @@ | ||
| use dep::types::address::Address; | ||
| use dep::aztec::{ | ||
| constants_gen, | ||
| constants_gen::{GENERATOR_INDEX__PUBLIC_LEAF_INDEX}, | ||
| hash::sha256_to_field, | ||
| }; | ||
|
|
||
| pub fn compute_public_data_tree_index(contract_address: Address, storage_slot: Field) -> Field { | ||
| dep::std::hash::pedersen_hash_with_separator([ | ||
| contract_address.to_field(), | ||
| storage_slot | ||
| ], constants_gen::GENERATOR_INDEX__PUBLIC_LEAF_INDEX) | ||
| } | ||
|
|
||
| pub fn compute_public_data_tree_value(value: Field) -> Field { | ||
| // as it's a public value, it doesn't require hashing. | ||
| // leaving this function here in case we decide to change this. | ||
| value | ||
| } |
11 changes: 11 additions & 0 deletions
11
yarn-project/noir-protocol-circuits/src/crates/public-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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| mod abis; | ||
| // TODO: rename to be precise as to what its common to (the public kernel circuits). | ||
| mod common; | ||
|
|
||
| mod hash; | ||
|
|
||
| mod public_kernel_private_previous; | ||
| mod public_kernel_public_previous; | ||
|
|
||
| use public_kernel_private_previous::PublicKernelPrivatePreviousInputs; | ||
| use public_kernel_public_previous::PublicKernelPublicPreviousInputs; |
56 changes: 56 additions & 0 deletions
56
...noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_private_previous.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,56 @@ | ||
| use crate::abis::public_call_data::PublicCallData; | ||
| use dep::types::abis::previous_kernel_data::PreviousKernelData; | ||
| use dep::types::abis::kernel_circuit_public_inputs::{KernelCircuitPublicInputs, KernelCircuitPublicInputsBuilder}; | ||
| use crate::common; | ||
| use dep::std::unsafe; | ||
| // translated from cpp impl in | ||
| // aztec-packages/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp | ||
|
|
||
| struct PublicKernelPrivatePreviousInputs { | ||
| previous_kernel: PreviousKernelData, | ||
| public_call: PublicCallData, | ||
| } | ||
|
|
||
| impl PublicKernelPrivatePreviousInputs { | ||
|
|
||
| fn validate_inputs(self) { | ||
| let private_call_stack = self.previous_kernel.public_inputs.end.private_call_stack; | ||
| for i in 0..private_call_stack.len() { | ||
| let private_call = private_call_stack[i]; | ||
| assert(private_call == 0, | ||
| "Private call stack must be empty when executing in the public kernel (i.e. all private calls must have been completed)"); | ||
| } | ||
|
|
||
| let previous_call_is_private = self.previous_kernel.public_inputs.is_private; | ||
| assert(previous_call_is_private == true, | ||
| "Previous kernel must be private when in this public kernel version"); | ||
| } | ||
|
|
||
|
|
||
| fn public_kernel_private_previous(self) -> KernelCircuitPublicInputs { | ||
| // construct the circuit outputs | ||
| let mut public_inputs: KernelCircuitPublicInputsBuilder = unsafe::zeroed(); | ||
|
|
||
| // initialise the end state with our provided previous kernel state | ||
| common::initialize_end_values(self.previous_kernel, &mut public_inputs); | ||
|
|
||
| // validate the inputs common to all invocation circumstances | ||
| common::validate_inputs(self.public_call); | ||
|
|
||
| // validate the inputs unique to having a previous private kernel | ||
| self.validate_inputs(); | ||
|
|
||
| // to implement: | ||
| // validate the kernel execution common to all invocation circumstances | ||
| common::validate_kernel_execution(self.public_call); | ||
|
|
||
| // validate our public call hash | ||
| common::validate_this_public_call_hash(self.public_call,&mut public_inputs); | ||
|
|
||
| common::update_public_end_values(self.public_call,&mut public_inputs); | ||
|
|
||
| common::accumulate_unencrypted_logs(self.public_call, self.previous_kernel,&mut public_inputs); | ||
|
|
||
| public_inputs.finish() | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
.../noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_public_previous.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,50 @@ | ||
| use crate::abis::public_call_data::PublicCallData; | ||
| use dep::types::abis::previous_kernel_data::PreviousKernelData; | ||
| use dep::types::KernelCircuitPublicInputs; | ||
| use dep::types::abis::kernel_circuit_public_inputs::KernelCircuitPublicInputsBuilder; | ||
| use crate::common; | ||
| use dep::std::unsafe; | ||
|
|
||
|
|
||
| struct PublicKernelPublicPreviousInputs { | ||
| previous_kernel: PreviousKernelData, | ||
| public_call: PublicCallData, | ||
| } | ||
|
|
||
| impl PublicKernelPublicPreviousInputs { | ||
|
|
||
| // this is the only difference between the two PublicKernels' logic: | ||
| fn validate_inputs(self) { | ||
| let previous_call_is_private = self.previous_kernel.public_inputs.is_private; | ||
| assert(previous_call_is_private == false, | ||
| "Previous kernel must be private when in this public kernel version"); | ||
| } | ||
|
|
||
|
|
||
| fn public_kernel_public_previous(self) -> KernelCircuitPublicInputs { | ||
| // construct the circuit outputs | ||
| let mut public_inputs: KernelCircuitPublicInputsBuilder = unsafe::zeroed(); | ||
|
|
||
| // initialise the end state with our provided previous kernel state | ||
| common::initialize_end_values(self.previous_kernel, &mut public_inputs); | ||
|
|
||
| // validate the inputs common to all invocation circumstances | ||
| common::validate_inputs(self.public_call); | ||
|
|
||
| // validate the inputs unique to having a previous private kernel | ||
|
dan-aztec marked this conversation as resolved.
Outdated
|
||
| self.validate_inputs(); | ||
|
|
||
| // to implement: | ||
|
dan-aztec marked this conversation as resolved.
Outdated
|
||
| // validate the kernel execution common to all invocation circumstances | ||
| common::validate_kernel_execution(self.public_call); | ||
|
|
||
| // validate our public call hash | ||
| common::validate_this_public_call_hash(self.public_call, &mut public_inputs); | ||
|
|
||
| common::update_public_end_values(self.public_call,&mut public_inputs); | ||
|
|
||
| common::accumulate_unencrypted_logs(self.public_call, self.previous_kernel,&mut public_inputs); | ||
|
|
||
| public_inputs.finish() | ||
| } | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
...ect/noir-protocol-circuits/src/crates/public-kernel-private-previous-simulated/Nargo.toml
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,10 @@ | ||
| [package] | ||
| name = "public_kernel_private_previous_simulated" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = ">=0.18.0" | ||
|
|
||
| [dependencies] | ||
| types = { path = "../types" } | ||
| public_kernel_lib = { path = "../public-kernel-lib" } | ||
| aztec = { path = "../../../../aztec-nr/aztec" } |
6 changes: 6 additions & 0 deletions
6
...ct/noir-protocol-circuits/src/crates/public-kernel-private-previous-simulated/src/main.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,6 @@ | ||
| use dep::public_kernel_lib::{PublicKernelPrivatePreviousInputs}; | ||
| use dep::types::{KernelCircuitPublicInputs}; | ||
|
|
||
| unconstrained fn main(input: PublicKernelPrivatePreviousInputs) -> distinct pub KernelCircuitPublicInputs { | ||
| input.public_kernel_private_previous() // function naming? | ||
|
dan-aztec marked this conversation as resolved.
Outdated
|
||
| } | ||
10 changes: 10 additions & 0 deletions
10
yarn-project/noir-protocol-circuits/src/crates/public-kernel-private-previous/Nargo.toml
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,10 @@ | ||
| [package] | ||
| name = "public_kernel_private_previous" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = ">=0.18.0" | ||
|
|
||
| [dependencies] | ||
| types = { path = "../types" } | ||
| public_kernel_lib = { path = "../public-kernel-lib" } | ||
| aztec = { path = "../../../../aztec-nr/aztec" } |
6 changes: 6 additions & 0 deletions
6
yarn-project/noir-protocol-circuits/src/crates/public-kernel-private-previous/src/main.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,6 @@ | ||
| use dep::public_kernel_lib::{PublicKernelPrivatePreviousInputs}; | ||
| use dep::types::{KernelCircuitPublicInputs}; | ||
|
|
||
| fn main(input: PublicKernelPrivatePreviousInputs) -> distinct pub KernelCircuitPublicInputs { | ||
| input.public_kernel_private_previous() // function naming? | ||
|
dan-aztec marked this conversation as resolved.
Outdated
|
||
| } | ||
10 changes: 10 additions & 0 deletions
10
...ject/noir-protocol-circuits/src/crates/public-kernel-public-previous-simulated/Nargo.toml
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,10 @@ | ||
| [package] | ||
| name = "public_kernel_public_previous_simulated" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = ">=0.18.0" | ||
|
|
||
| [dependencies] | ||
| types = { path = "../types" } | ||
| public_kernel_lib = { path = "../public-kernel-lib" } | ||
| aztec = { path = "../../../../aztec-nr/aztec" } |
6 changes: 6 additions & 0 deletions
6
...ect/noir-protocol-circuits/src/crates/public-kernel-public-previous-simulated/src/main.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,6 @@ | ||
| use dep::public_kernel_lib::{PublicKernelPublicPreviousInputs}; | ||
| use dep::types::{KernelCircuitPublicInputs}; | ||
|
|
||
| unconstrained fn main(input: PublicKernelPublicPreviousInputs) -> distinct pub KernelCircuitPublicInputs { | ||
| input.public_kernel_public_previous() | ||
| } |
10 changes: 10 additions & 0 deletions
10
yarn-project/noir-protocol-circuits/src/crates/public-kernel-public-previous/Nargo.toml
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,10 @@ | ||
| [package] | ||
| name = "public_kernel_public_previous" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = ">=0.18.0" | ||
|
|
||
| [dependencies] | ||
| types = { path = "../types" } | ||
| public_kernel_lib = { path = "../public-kernel-lib" } | ||
| aztec = { path = "../../../../aztec-nr/aztec" } |
6 changes: 6 additions & 0 deletions
6
yarn-project/noir-protocol-circuits/src/crates/public-kernel-public-previous/src/main.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,6 @@ | ||
| use dep::public_kernel_lib::{PublicKernelPublicPreviousInputs}; | ||
| use dep::types::{KernelCircuitPublicInputs}; | ||
|
|
||
| fn main(input: PublicKernelPublicPreviousInputs) -> distinct pub KernelCircuitPublicInputs { | ||
| input.public_kernel_public_previous() | ||
| } |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.