-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
starting rewrite based off of #2740 literal cpp -> noir translation for first conversion --------- Co-authored-by: kevaundray <[email protected]> Co-authored-by: Álvaro Rodríguez <[email protected]> Co-authored-by: Leila Wang <[email protected]>
- Loading branch information
1 parent
8ae44dd
commit 15a522b
Showing
45 changed files
with
1,342 additions
and
21 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
9 changes: 9 additions & 0 deletions
9
yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/Nargo.toml
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,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 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 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 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 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; |
55 changes: 55 additions & 0 deletions
55
...noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_private_previous.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,55 @@ | ||
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(); | ||
|
||
// 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() | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
.../noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_public_previous.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,49 @@ | ||
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 public 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 public kernel | ||
self.validate_inputs(); | ||
|
||
// 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 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 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() | ||
} |
10 changes: 10 additions & 0 deletions
10
yarn-project/noir-protocol-circuits/src/crates/public-kernel-private-previous/Nargo.toml
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,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 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() | ||
} |
10 changes: 10 additions & 0 deletions
10
...ject/noir-protocol-circuits/src/crates/public-kernel-public-previous-simulated/Nargo.toml
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,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 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 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 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 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
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.