From 1798b1cc701824dd268ed0e49e592febf01a1687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Rodr=C3=ADguez?= Date: Tue, 8 Oct 2024 15:49:49 +0200 Subject: [PATCH] feat: Integrate databus in the private kernels (#9028) Integrates the databus in the private kernels. We do this by annotating with call_data(0) for previous kernel public inputs and call_data(1) for app public inputs. Kernels and apps expose their own public inputs as return_data except the tail kernel who does it via the traditional public inputs mechanism for the tube. --- barretenberg/cpp/src/barretenberg/bb/main.cpp | 2 +- .../cpp/src/barretenberg/constants.hpp | 2 +- .../arithmetization/mega_arithmetization.hpp | 2 +- .../src/core/libraries/ConstantsGen.sol | 1 + .../aztec/src/macros/functions/mod.nr | 2 +- .../mock-private-kernel-tail/src/main.nr | 2 +- .../private-kernel-init-simulated/src/main.nr | 13 ++- .../crates/private-kernel-init/src/main.nr | 14 ++- .../src/main.nr | 18 +++- .../crates/private-kernel-inner/src/main.nr | 19 +++- .../src/private_kernel_init.nr | 12 ++- .../src/private_kernel_inner.nr | 16 +++- .../src/private_kernel_reset.nr | 10 +- .../src/private_kernel_tail.nr | 15 ++- .../src/private_kernel_tail_to_public.nr | 15 ++- .../src/main.nr | 17 +++- .../crates/private-kernel-reset/src/main.nr | 14 ++- .../private-kernel-tail-simulated/src/main.nr | 10 +- .../src/main.nr | 10 +- .../private-kernel-tail-to-public/src/main.nr | 11 ++- .../crates/private-kernel-tail/src/main.nr | 11 ++- .../crates/types/src/abis/mod.nr | 8 +- .../types/src/abis/private_call_stack_item.nr | 11 +++ .../crates/types/src/abis/private_kernel.nr | 2 +- .../abis/private_kernel/private_call_data.nr | 34 ++++++- .../types/src/abis/private_kernel_data.nr | 12 +++ .../crates/types/src/constants.nr | 1 + .../crates/types/src/transaction/mod.nr | 4 +- .../src/hir/comptime/interpreter/builtin.rs | 20 ++++ .../noir_stdlib/src/meta/function_def.nr | 3 + yarn-project/circuits.js/src/constants.gen.ts | 1 + .../noir-protocol-circuits-types/src/index.ts | 86 ++++++++++++----- .../src/type_conversion.ts | 94 +++---------------- .../src/client/client_execution_context.ts | 7 +- yarn-project/simulator/src/client/index.ts | 1 + .../simulator/src/client/private_execution.ts | 42 +++++++-- yarn-project/txe/src/oracle/txe_oracle.ts | 5 +- 37 files changed, 383 insertions(+), 164 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index acffa4f47f2..032f2eacd55 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -608,7 +608,7 @@ void prove_tube(const std::string& output_path) // set_public on each witness auto num_public_inputs = static_cast(static_cast(proof.folding_proof[1])); num_public_inputs -= bb::AGGREGATION_OBJECT_SIZE; // don't add the agg object - num_public_inputs -= 2 * 8; // don't add the databus return data commitments (2x) + num_public_inputs -= 1 * 8; // TODO(https://github.com/AztecProtocol/barretenberg/issues/1125) Make this dynamic for (size_t i = 0; i < num_public_inputs; i++) { auto offset = acir_format::HONK_RECURSION_PUBLIC_INPUT_OFFSET; builder->add_public_variable(proof.folding_proof[i + offset]); diff --git a/barretenberg/cpp/src/barretenberg/constants.hpp b/barretenberg/cpp/src/barretenberg/constants.hpp index 578888a752b..bdfa57e5f95 100644 --- a/barretenberg/cpp/src/barretenberg/constants.hpp +++ b/barretenberg/cpp/src/barretenberg/constants.hpp @@ -13,5 +13,5 @@ static constexpr uint32_t CONST_PG_LOG_N = 20; static constexpr uint32_t MAX_LOOKUP_TABLES_SIZE = 70000; -static constexpr uint32_t MAX_DATABUS_SIZE = 10; +static constexpr uint32_t MAX_DATABUS_SIZE = 10000; } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/mega_arithmetization.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/mega_arithmetization.hpp index 9f38f2a4bba..37fd9c0dd16 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/mega_arithmetization.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/mega_arithmetization.hpp @@ -94,7 +94,7 @@ template class MegaArith { this->elliptic = 80000; this->aux = 100000; this->lookup = 200000; - this->busread = 100; + this->busread = 6000; this->poseidon2_external = 30000; this->poseidon2_internal = 150000; } diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index ae2ea1b2961..4c153ea758d 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -191,6 +191,7 @@ library Constants { uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 544; uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 691; uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = 547; + uint256 internal constant PRIVATE_CONTEXT_INPUTS_LENGTH = 39; uint256 internal constant PUBLIC_CONTEXT_INPUTS_LENGTH = 42; uint256 internal constant AGGREGATION_OBJECT_LENGTH = 16; uint256 internal constant SCOPED_READ_REQUEST_LEN = 3; diff --git a/noir-projects/aztec-nr/aztec/src/macros/functions/mod.nr b/noir-projects/aztec-nr/aztec/src/macros/functions/mod.nr index ceee8c5178c..e46eecab75b 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/functions/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/functions/mod.nr @@ -215,10 +215,10 @@ pub comptime fn private(f: FunctionDefinition) -> Quoted { let modified_body = modify_fn_body(body, to_prepend, to_append); f.set_body(modified_body); f.add_attribute("recursive"); - f.set_return_public(true); f.set_return_type( quote { dep::protocol_types::abis::private_circuit_public_inputs::PrivateCircuitPublicInputs }.as_type() ); + f.set_return_data(); fn_abi } diff --git a/noir-projects/mock-protocol-circuits/crates/mock-private-kernel-tail/src/main.nr b/noir-projects/mock-protocol-circuits/crates/mock-private-kernel-tail/src/main.nr index 6b94d6eb0d7..93bd23cf813 100644 --- a/noir-projects/mock-protocol-circuits/crates/mock-private-kernel-tail/src/main.nr +++ b/noir-projects/mock-protocol-circuits/crates/mock-private-kernel-tail/src/main.nr @@ -1,7 +1,7 @@ use dep::mock_types::{PrivateKernelPublicInputs, KernelPublicInputs, MAX_COMMITMENT_READ_REQUESTS_PER_TX}; // The tail kernel finishes the client IVC chain exposing the final public inputs with no remaining calls or unfulfilled read requests. -fn main(prev_kernel_public_inputs: call_data(0) PrivateKernelPublicInputs) -> return_data KernelPublicInputs { +fn main(prev_kernel_public_inputs: call_data(0) PrivateKernelPublicInputs) -> pub KernelPublicInputs { assert_eq(prev_kernel_public_inputs.remaining_calls, 0); for i in 0..MAX_COMMITMENT_READ_REQUESTS_PER_TX { assert_eq(prev_kernel_public_inputs.read_requests[i], 0); diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-init-simulated/src/main.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-init-simulated/src/main.nr index af1a989750b..cd52419b7f9 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-init-simulated/src/main.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-init-simulated/src/main.nr @@ -1,6 +1,15 @@ use dep::private_kernel_lib::PrivateKernelInitCircuitPrivateInputs; use dep::types::PrivateKernelCircuitPublicInputs; +use types::transaction::tx_request::TxRequest; +use types::abis::private_kernel::private_call_data::PrivateCallDataWithoutPublicInputs; +use types::abis::private_circuit_public_inputs::PrivateCircuitPublicInputs; -unconstrained fn main(input: PrivateKernelInitCircuitPrivateInputs) -> pub PrivateKernelCircuitPublicInputs { - input.execute() +unconstrained fn main( + tx_request: TxRequest, + vk_tree_root: Field, + private_call: PrivateCallDataWithoutPublicInputs, + app_public_inputs: PrivateCircuitPublicInputs +) -> pub PrivateKernelCircuitPublicInputs { + let private_inputs = PrivateKernelInitCircuitPrivateInputs::new(tx_request, vk_tree_root, private_call, app_public_inputs); + private_inputs.execute() } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-init/src/main.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-init/src/main.nr index b76dc1205bc..40529705cd1 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-init/src/main.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-init/src/main.nr @@ -1,7 +1,15 @@ use dep::private_kernel_lib::PrivateKernelInitCircuitPrivateInputs; use dep::types::PrivateKernelCircuitPublicInputs; +use types::transaction::tx_request::TxRequest; +use types::abis::private_kernel::private_call_data::PrivateCallDataWithoutPublicInputs; +use types::abis::private_circuit_public_inputs::PrivateCircuitPublicInputs; -#[recursive] -fn main(input: PrivateKernelInitCircuitPrivateInputs) -> pub PrivateKernelCircuitPublicInputs { - input.execute() +fn main( + tx_request: TxRequest, + vk_tree_root: Field, + private_call: PrivateCallDataWithoutPublicInputs, + app_public_inputs: call_data(1) PrivateCircuitPublicInputs +) -> return_data PrivateKernelCircuitPublicInputs { + let private_inputs = PrivateKernelInitCircuitPrivateInputs::new(tx_request, vk_tree_root, private_call, app_public_inputs); + private_inputs.execute() } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-inner-simulated/src/main.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-inner-simulated/src/main.nr index 75d54f4f319..5f4180f1571 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-inner-simulated/src/main.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-inner-simulated/src/main.nr @@ -1,6 +1,20 @@ use dep::private_kernel_lib::PrivateKernelInnerCircuitPrivateInputs; use dep::types::PrivateKernelCircuitPublicInputs; +use types::abis::private_kernel_data::PrivateKernelDataWithoutPublicInputs; +use types::abis::private_kernel::private_call_data::PrivateCallDataWithoutPublicInputs; +use types::abis::private_circuit_public_inputs::PrivateCircuitPublicInputs; -unconstrained fn main(input: PrivateKernelInnerCircuitPrivateInputs) -> pub PrivateKernelCircuitPublicInputs { - input.execute() +unconstrained fn main( + previous_kernel: PrivateKernelDataWithoutPublicInputs, + previous_kernel_public_inputs: PrivateKernelCircuitPublicInputs, + private_call: PrivateCallDataWithoutPublicInputs, + app_public_inputs: PrivateCircuitPublicInputs +) -> pub PrivateKernelCircuitPublicInputs { + let private_inputs = PrivateKernelInnerCircuitPrivateInputs::new( + previous_kernel, + previous_kernel_public_inputs, + private_call, + app_public_inputs + ); + private_inputs.execute() } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-inner/src/main.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-inner/src/main.nr index e48714e175c..e9d4e26f921 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-inner/src/main.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-inner/src/main.nr @@ -1,7 +1,20 @@ use dep::private_kernel_lib::PrivateKernelInnerCircuitPrivateInputs; use dep::types::PrivateKernelCircuitPublicInputs; +use types::abis::private_kernel_data::PrivateKernelDataWithoutPublicInputs; +use types::abis::private_kernel::private_call_data::PrivateCallDataWithoutPublicInputs; +use types::abis::private_circuit_public_inputs::PrivateCircuitPublicInputs; -#[recursive] -fn main(input: PrivateKernelInnerCircuitPrivateInputs) -> pub PrivateKernelCircuitPublicInputs { - input.execute() +fn main( + previous_kernel: PrivateKernelDataWithoutPublicInputs, + previous_kernel_public_inputs: call_data(0) PrivateKernelCircuitPublicInputs, + private_call: PrivateCallDataWithoutPublicInputs, + app_public_inputs: call_data(1) PrivateCircuitPublicInputs +) -> return_data PrivateKernelCircuitPublicInputs { + let private_inputs = PrivateKernelInnerCircuitPrivateInputs::new( + previous_kernel, + previous_kernel_public_inputs, + private_call, + app_public_inputs + ); + private_inputs.execute() } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr index 8bd9f9d4a15..33a25275f18 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr @@ -8,7 +8,8 @@ use crate::{ use dep::types::{ abis::{ kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs, - private_kernel::private_call_data::PrivateCallData + private_kernel::private_call_data::{PrivateCallData, PrivateCallDataWithoutPublicInputs}, + private_circuit_public_inputs::PrivateCircuitPublicInputs }, transaction::tx_request::TxRequest }; @@ -21,6 +22,15 @@ pub struct PrivateKernelInitCircuitPrivateInputs { } impl PrivateKernelInitCircuitPrivateInputs { + pub fn new( + tx_request: TxRequest, + vk_tree_root: Field, + private_call: PrivateCallDataWithoutPublicInputs, + app_public_inputs: PrivateCircuitPublicInputs + ) -> Self { + Self { tx_request, vk_tree_root, private_call: private_call.to_private_call_data(app_public_inputs) } + } + unconstrained fn generate_output(self) -> PrivateKernelCircuitPublicInputs { let private_call_public_inputs = self.private_call.call_stack_item.public_inputs; PrivateKernelCircuitPublicInputsComposer::new_from_tx_request(self.tx_request, private_call_public_inputs, self.vk_tree_root).with_private_call( diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr index 06d0690ea71..585c8c0cf74 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr @@ -9,7 +9,9 @@ use crate::{ use dep::types::{ abis::{ kernel_circuit_public_inputs::{PrivateKernelCircuitPublicInputs, PrivateKernelCircuitPublicInputsArrayLengths}, - private_kernel_data::PrivateKernelData, private_kernel::private_call_data::PrivateCallData + private_kernel_data::{PrivateKernelData, PrivateKernelDataWithoutPublicInputs}, + private_kernel::private_call_data::{PrivateCallData, PrivateCallDataWithoutPublicInputs}, + private_circuit_public_inputs::PrivateCircuitPublicInputs }, constants::{PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX} }; @@ -26,6 +28,18 @@ pub struct PrivateKernelInnerCircuitPrivateInputs { } impl PrivateKernelInnerCircuitPrivateInputs { + pub fn new( + previous_kernel: PrivateKernelDataWithoutPublicInputs, + previous_kernel_public_inputs: PrivateKernelCircuitPublicInputs, + private_call: PrivateCallDataWithoutPublicInputs, + app_public_inputs: PrivateCircuitPublicInputs + ) -> Self { + Self { + previous_kernel: previous_kernel.to_private_kernel_data(previous_kernel_public_inputs), + private_call: private_call.to_private_call_data(app_public_inputs) + } + } + unconstrained fn generate_output(self) -> PrivateKernelCircuitPublicInputs { PrivateKernelCircuitPublicInputsComposer::new_from_previous_kernel(self.previous_kernel.public_inputs).pop_top_call_request().with_private_call( self.private_call.call_stack_item.public_inputs, diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr index 140c66bb34e..2317649881a 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr @@ -8,7 +8,7 @@ use dep::reset_kernel_lib::{ PrivateValidationRequestProcessor, TransientDataIndexHint }; use dep::types::{ - abis::private_kernel_data::PrivateKernelData, + abis::private_kernel_data::{PrivateKernelData, PrivateKernelDataWithoutPublicInputs}, constants::{PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX}, PrivateKernelCircuitPublicInputs }; @@ -40,6 +40,14 @@ impl< let KEY_VALIDATION_REQUESTS: u32, let TRANSIENT_DATA_AMOUNT: u32 > PrivateKernelResetCircuitPrivateInputs { + fn new( + previous_kernel: PrivateKernelDataWithoutPublicInputs, + previous_kernel_public_inputs: PrivateKernelCircuitPublicInputs, + hints: PrivateKernelResetHints + ) -> Self { + Self { previous_kernel: previous_kernel.to_private_kernel_data(previous_kernel_public_inputs), hints } + } + unconstrained fn generate_output( self, validation_request_processor: PrivateValidationRequestProcessor, diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr index ac5a26a9f0d..26b48c38174 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr @@ -3,8 +3,12 @@ use crate::components::{ tail_output_validator::TailOutputValidator }; use dep::types::{ - abis::{private_kernel_data::PrivateKernelData, kernel_circuit_public_inputs::KernelCircuitPublicInputs}, - constants::{PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX} + abis::{ + private_kernel_data::{PrivateKernelData, PrivateKernelDataWithoutPublicInputs}, + kernel_circuit_public_inputs::KernelCircuitPublicInputs +}, + constants::{PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX}, + PrivateKernelCircuitPublicInputs }; global ALLOWED_PREVIOUS_CIRCUITS = [ @@ -18,6 +22,13 @@ pub struct PrivateKernelTailCircuitPrivateInputs { } impl PrivateKernelTailCircuitPrivateInputs { + pub fn new( + previous_kernel: PrivateKernelDataWithoutPublicInputs, + previous_kernel_public_inputs: PrivateKernelCircuitPublicInputs + ) -> Self { + Self { previous_kernel: previous_kernel.to_private_kernel_data(previous_kernel_public_inputs) } + } + unconstrained fn generate_output(self) -> KernelCircuitPublicInputs { TailOutputComposer::new(self.previous_kernel.public_inputs).finish() } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr index 5b84c180672..c9e3c4682db 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr @@ -4,8 +4,12 @@ use crate::components::{ tail_to_public_output_validator::TailToPublicOutputValidator }; use dep::types::{ - abis::{private_kernel_data::PrivateKernelData, kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs}, - constants::{PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX} + abis::{ + private_kernel_data::{PrivateKernelData, PrivateKernelDataWithoutPublicInputs}, + kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs +}, + constants::{PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX}, + PrivateKernelCircuitPublicInputs }; global ALLOWED_PREVIOUS_CIRCUITS = [ @@ -19,6 +23,13 @@ pub struct PrivateKernelTailToPublicCircuitPrivateInputs { } impl PrivateKernelTailToPublicCircuitPrivateInputs { + pub fn new( + previous_kernel: PrivateKernelDataWithoutPublicInputs, + previous_kernel_public_inputs: PrivateKernelCircuitPublicInputs + ) -> Self { + Self { previous_kernel: previous_kernel.to_private_kernel_data(previous_kernel_public_inputs) } + } + unconstrained fn generate_output(self) -> PublicKernelCircuitPublicInputs { TailToPublicOutputComposer::new(self.previous_kernel.public_inputs).finish() } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-reset-simulated/src/main.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-reset-simulated/src/main.nr index e8cc201b335..3df55379852 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-reset-simulated/src/main.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-reset-simulated/src/main.nr @@ -1,4 +1,4 @@ -use dep::private_kernel_lib::PrivateKernelResetCircuitPrivateInputs; +use dep::private_kernel_lib::private_kernel_reset::{PrivateKernelResetHints, PrivateKernelResetCircuitPrivateInputs}; use dep::types::{ PrivateKernelCircuitPublicInputs, constants::{ @@ -6,10 +6,11 @@ use dep::types::{ MAX_NULLIFIER_READ_REQUESTS_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_KEY_VALIDATION_REQUESTS_PER_TX } }; +use types::abis::private_kernel_data::PrivateKernelDataWithoutPublicInputs; -global NOTE_HASH_PENDING_AMOUNT = MAX_NOTE_HASH_READ_REQUESTS_PER_TX; // 128 +global NOTE_HASH_PENDING_AMOUNT = MAX_NOTE_HASH_READ_REQUESTS_PER_TX; // 64 global NOTE_HASH_SETTLED_AMOUNT = MAX_NOTE_HASH_READ_REQUESTS_PER_TX; -global NULLIFIER_PENDING_AMOUNT = MAX_NULLIFIER_READ_REQUESTS_PER_TX; // 128 +global NULLIFIER_PENDING_AMOUNT = MAX_NULLIFIER_READ_REQUESTS_PER_TX; // 64 global NULLIFIER_SETTLED_AMOUNT = MAX_NULLIFIER_READ_REQUESTS_PER_TX; global NULLIFIER_KEYS = MAX_KEY_VALIDATION_REQUESTS_PER_TX; // 64 global TRANSIENT_DATA_AMOUNT = MAX_NULLIFIERS_PER_TX; // 64 @@ -17,10 +18,16 @@ global NOTE_HASH_SILOING_AMOUNT = MAX_NOTE_HASHES_PER_TX; // 64 global NULLIFIER_SILOING_AMOUNT = MAX_NULLIFIERS_PER_TX; // 64 global ENCRYPTED_LOG_SILOING_AMOUNT = MAX_ENCRYPTED_LOGS_PER_TX; // 8 -unconstrained fn main(input: PrivateKernelResetCircuitPrivateInputs) -> pub PrivateKernelCircuitPublicInputs { - input.execute( +unconstrained fn main( + previous_kernel: PrivateKernelDataWithoutPublicInputs, + previous_kernel_public_inputs: PrivateKernelCircuitPublicInputs, + hints: PrivateKernelResetHints +) -> pub PrivateKernelCircuitPublicInputs { + let private_inputs = PrivateKernelResetCircuitPrivateInputs::new(previous_kernel, previous_kernel_public_inputs, hints); + private_inputs.execute( NOTE_HASH_SILOING_AMOUNT, NULLIFIER_SILOING_AMOUNT, ENCRYPTED_LOG_SILOING_AMOUNT ) } + diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-reset/src/main.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-reset/src/main.nr index 2fc1297075a..c898f14e10c 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-reset/src/main.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-reset/src/main.nr @@ -1,4 +1,4 @@ -use dep::private_kernel_lib::PrivateKernelResetCircuitPrivateInputs; +use dep::private_kernel_lib::private_kernel_reset::{PrivateKernelResetHints, PrivateKernelResetCircuitPrivateInputs}; use dep::types::{ PrivateKernelCircuitPublicInputs, constants::{ @@ -6,6 +6,7 @@ use dep::types::{ MAX_NULLIFIER_READ_REQUESTS_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_KEY_VALIDATION_REQUESTS_PER_TX } }; +use types::abis::private_kernel_data::PrivateKernelDataWithoutPublicInputs; global NOTE_HASH_PENDING_AMOUNT = MAX_NOTE_HASH_READ_REQUESTS_PER_TX; // 64 global NOTE_HASH_SETTLED_AMOUNT = MAX_NOTE_HASH_READ_REQUESTS_PER_TX; @@ -17,11 +18,16 @@ global NOTE_HASH_SILOING_AMOUNT = MAX_NOTE_HASHES_PER_TX; // 64 global NULLIFIER_SILOING_AMOUNT = MAX_NULLIFIERS_PER_TX; // 64 global ENCRYPTED_LOG_SILOING_AMOUNT = MAX_ENCRYPTED_LOGS_PER_TX; // 8 -#[recursive] -fn main(input: PrivateKernelResetCircuitPrivateInputs) -> pub PrivateKernelCircuitPublicInputs { - input.execute( +fn main( + previous_kernel: PrivateKernelDataWithoutPublicInputs, + previous_kernel_public_inputs: call_data(0) PrivateKernelCircuitPublicInputs, + hints: PrivateKernelResetHints +) -> return_data PrivateKernelCircuitPublicInputs { + let private_inputs = PrivateKernelResetCircuitPrivateInputs::new(previous_kernel, previous_kernel_public_inputs, hints); + private_inputs.execute( NOTE_HASH_SILOING_AMOUNT, NULLIFIER_SILOING_AMOUNT, ENCRYPTED_LOG_SILOING_AMOUNT ) } + diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-tail-simulated/src/main.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-tail-simulated/src/main.nr index 5eebea5eef6..2d9ebe6ea0e 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-tail-simulated/src/main.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-tail-simulated/src/main.nr @@ -1,6 +1,12 @@ use dep::private_kernel_lib::PrivateKernelTailCircuitPrivateInputs; use dep::types::KernelCircuitPublicInputs; +use types::abis::private_kernel_data::PrivateKernelDataWithoutPublicInputs; +use types::abis::kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs; -unconstrained fn main(input: PrivateKernelTailCircuitPrivateInputs) -> pub KernelCircuitPublicInputs { - input.execute() +unconstrained fn main( + previous_kernel: PrivateKernelDataWithoutPublicInputs, + previous_kernel_public_inputs: PrivateKernelCircuitPublicInputs +) -> pub KernelCircuitPublicInputs { + let private_inputs = PrivateKernelTailCircuitPrivateInputs::new(previous_kernel, previous_kernel_public_inputs); + private_inputs.execute() } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-tail-to-public-simulated/src/main.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-tail-to-public-simulated/src/main.nr index 3683ecbd8cc..6716b11f017 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-tail-to-public-simulated/src/main.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-tail-to-public-simulated/src/main.nr @@ -1,6 +1,12 @@ use dep::private_kernel_lib::PrivateKernelTailToPublicCircuitPrivateInputs; use dep::types::PublicKernelCircuitPublicInputs; +use types::abis::private_kernel_data::PrivateKernelDataWithoutPublicInputs; +use types::abis::kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs; -unconstrained fn main(input: PrivateKernelTailToPublicCircuitPrivateInputs) -> pub PublicKernelCircuitPublicInputs { - input.execute() +unconstrained fn main( + previous_kernel: PrivateKernelDataWithoutPublicInputs, + previous_kernel_public_inputs: PrivateKernelCircuitPublicInputs +) -> pub PublicKernelCircuitPublicInputs { + let private_inputs = PrivateKernelTailToPublicCircuitPrivateInputs::new(previous_kernel, previous_kernel_public_inputs); + private_inputs.execute() } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-tail-to-public/src/main.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-tail-to-public/src/main.nr index fd35f8397f3..57bf8c74c43 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-tail-to-public/src/main.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-tail-to-public/src/main.nr @@ -1,7 +1,12 @@ use dep::private_kernel_lib::PrivateKernelTailToPublicCircuitPrivateInputs; use dep::types::PublicKernelCircuitPublicInputs; +use types::abis::private_kernel_data::PrivateKernelDataWithoutPublicInputs; +use types::abis::kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs; -#[recursive] -fn main(input: PrivateKernelTailToPublicCircuitPrivateInputs) -> pub PublicKernelCircuitPublicInputs { - input.execute() +fn main( + previous_kernel: PrivateKernelDataWithoutPublicInputs, + previous_kernel_public_inputs: call_data(0) PrivateKernelCircuitPublicInputs +) -> pub PublicKernelCircuitPublicInputs { + let private_inputs = PrivateKernelTailToPublicCircuitPrivateInputs::new(previous_kernel, previous_kernel_public_inputs); + private_inputs.execute() } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-tail/src/main.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-tail/src/main.nr index e20050715d7..8383ed5c782 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-tail/src/main.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-tail/src/main.nr @@ -1,7 +1,12 @@ use dep::private_kernel_lib::PrivateKernelTailCircuitPrivateInputs; use dep::types::KernelCircuitPublicInputs; +use types::abis::private_kernel_data::PrivateKernelDataWithoutPublicInputs; +use types::abis::kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs; -#[recursive] -fn main(input: PrivateKernelTailCircuitPrivateInputs) -> pub KernelCircuitPublicInputs { - input.execute() +fn main( + previous_kernel: PrivateKernelDataWithoutPublicInputs, + previous_kernel_public_inputs: call_data(0) PrivateKernelCircuitPublicInputs +) -> pub KernelCircuitPublicInputs { + let private_inputs = PrivateKernelTailCircuitPrivateInputs::new(previous_kernel, previous_kernel_public_inputs); + private_inputs.execute() } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/mod.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/mod.nr index 21df3495695..63bad5f2baa 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/mod.nr @@ -27,10 +27,10 @@ mod validation_requests; mod max_block_number; -mod private_kernel; -mod kernel_circuit_public_inputs; +pub mod private_kernel; +pub mod kernel_circuit_public_inputs; mod kernel_data; -mod private_kernel_data; +pub mod private_kernel_data; mod public_kernel_data; mod public_kernel_inner_data; @@ -46,7 +46,7 @@ mod enqueued_call_data; mod public_call_data; mod public_circuit_public_inputs; -mod private_circuit_public_inputs; +pub mod private_circuit_public_inputs; mod gas_fees; mod gas_settings; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr index e6dd0ca7dca..fdfd943522d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr @@ -15,6 +15,17 @@ pub struct PrivateCallStackItem { public_inputs: PrivateCircuitPublicInputs, } +pub struct PrivateCallStackItemWithoutPublicInputs { + contract_address: AztecAddress, + function_data: FunctionData, +} + +impl PrivateCallStackItemWithoutPublicInputs { + fn to_private_call_stack_item(self, public_inputs: PrivateCircuitPublicInputs) -> PrivateCallStackItem { + PrivateCallStackItem { contract_address: self.contract_address, function_data: self.function_data, public_inputs } + } +} + impl Eq for PrivateCallStackItem { fn eq(self, other: Self) -> bool { self.contract_address.eq(other.contract_address) diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel.nr index 58d93169101..52f137711c7 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel.nr @@ -1 +1 @@ -mod private_call_data; +pub mod private_call_data; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr index b60eed12cad..f7349a4f8c5 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr @@ -1,5 +1,8 @@ use crate::{ - abis::{private_call_stack_item::PrivateCallStackItem}, + abis::{ + private_call_stack_item::{PrivateCallStackItemWithoutPublicInputs, PrivateCallStackItem}, + private_circuit_public_inputs::PrivateCircuitPublicInputs +}, address::{SaltedInitializationHash, PublicKeysHash}, constants::FUNCTION_TREE_HEIGHT, merkle_tree::membership::MembershipWitness, recursion::{verification_key::VerificationKey} }; @@ -17,3 +20,32 @@ pub struct PrivateCallData { acir_hash: Field, } + +pub struct PrivateCallDataWithoutPublicInputs { + call_stack_item: PrivateCallStackItemWithoutPublicInputs, + + vk: VerificationKey, + + salted_initialization_hash: SaltedInitializationHash, + public_keys_hash: PublicKeysHash, + contract_class_artifact_hash: Field, + contract_class_public_bytecode_commitment: Field, + function_leaf_membership_witness: MembershipWitness, + + acir_hash: Field, +} + +impl PrivateCallDataWithoutPublicInputs { + pub fn to_private_call_data(self, public_inputs: PrivateCircuitPublicInputs) -> PrivateCallData { + PrivateCallData { + call_stack_item: self.call_stack_item.to_private_call_stack_item(public_inputs), + vk: self.vk, + salted_initialization_hash: self.salted_initialization_hash, + public_keys_hash: self.public_keys_hash, + contract_class_artifact_hash: self.contract_class_artifact_hash, + contract_class_public_bytecode_commitment: self.contract_class_public_bytecode_commitment, + function_leaf_membership_witness: self.function_leaf_membership_witness, + acir_hash: self.acir_hash + } + } +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr index 7b7f7ecc62d..1fe3479fd80 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr @@ -33,3 +33,15 @@ impl PrivateKernelData { ); } } + +pub struct PrivateKernelDataWithoutPublicInputs { + vk: VerificationKey, + vk_index: u32, + vk_path: [Field; VK_TREE_HEIGHT], +} + +impl PrivateKernelDataWithoutPublicInputs { + pub fn to_private_kernel_data(self, public_inputs: PrivateKernelCircuitPublicInputs) -> PrivateKernelData { + PrivateKernelData { public_inputs, vk: self.vk, vk_index: self.vk_index, vk_path: self.vk_path } + } +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index 8b92fb7e2f6..059fe4958b0 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -261,6 +261,7 @@ global HEADER_LENGTH: u32 = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + CONTENT_COMMITMEN global PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH: u32 = CALL_CONTEXT_LENGTH + 4 + MAX_BLOCK_NUMBER_LENGTH + (READ_REQUEST_LENGTH * MAX_NOTE_HASH_READ_REQUESTS_PER_CALL) + (READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL) + (KEY_VALIDATION_REQUEST_AND_GENERATOR_LENGTH * MAX_KEY_VALIDATION_REQUESTS_PER_CALL) + (NOTE_HASH_LENGTH * MAX_NOTE_HASHES_PER_CALL) + (NULLIFIER_LENGTH * MAX_NULLIFIERS_PER_CALL) + (PRIVATE_CALL_REQUEST_LENGTH * MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL) + (PUBLIC_CALL_REQUEST_LENGTH * MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL) + PUBLIC_CALL_REQUEST_LENGTH + (L2_TO_L1_MESSAGE_LENGTH * MAX_L2_TO_L1_MSGS_PER_CALL) + 2 + (NOTE_LOG_HASH_LENGTH * MAX_NOTE_ENCRYPTED_LOGS_PER_CALL) + (ENCRYPTED_LOG_HASH_LENGTH * MAX_ENCRYPTED_LOGS_PER_CALL) + (LOG_HASH_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + HEADER_LENGTH + TX_CONTEXT_LENGTH; global PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH: u32 = CALL_CONTEXT_LENGTH + /*argsHash + returnsHash*/ 2 + (TREE_LEAF_READ_REQUEST_LENGTH * MAX_NOTE_HASH_READ_REQUESTS_PER_CALL) + (READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL) + (READ_REQUEST_LENGTH * MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL) + (TREE_LEAF_READ_REQUEST_LENGTH * MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL) + (CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH * MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL) + (CONTRACT_STORAGE_READ_LENGTH * MAX_PUBLIC_DATA_READS_PER_CALL) + (PUBLIC_INNER_CALL_REQUEST_LENGTH * MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL) + (NOTE_HASH_LENGTH * MAX_NOTE_HASHES_PER_CALL) + (NULLIFIER_LENGTH * MAX_NULLIFIERS_PER_CALL) + (L2_TO_L1_MESSAGE_LENGTH * MAX_L2_TO_L1_MSGS_PER_CALL) + 2 + (LOG_HASH_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + AZTEC_ADDRESS_LENGTH + /* revert_code */ 1 + 2 * GAS_LENGTH + /* transaction_fee */ 1; global PRIVATE_CALL_STACK_ITEM_LENGTH: u32 = AZTEC_ADDRESS_LENGTH + FUNCTION_DATA_LENGTH + PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH; +global PRIVATE_CONTEXT_INPUTS_LENGTH: u32 = CALL_CONTEXT_LENGTH + HEADER_LENGTH + TX_CONTEXT_LENGTH + 1; global PUBLIC_CONTEXT_INPUTS_LENGTH: u32 = CALL_CONTEXT_LENGTH + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + GAS_LENGTH + 2; global AGGREGATION_OBJECT_LENGTH: u32 = 16; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/mod.nr b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/mod.nr index 023f66746a8..a9762c88f36 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/mod.nr @@ -1,2 +1,2 @@ -mod tx_request; -mod tx_context; +pub mod tx_request; +pub mod tx_context; diff --git a/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/interpreter/builtin.rs b/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/interpreter/builtin.rs index c80dbb480f5..495b1f0276c 100644 --- a/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/interpreter/builtin.rs +++ b/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/interpreter/builtin.rs @@ -130,6 +130,9 @@ impl<'local, 'context> Interpreter<'local, 'context> { "function_def_set_return_public" => { function_def_set_return_public(self, arguments, location) } + "function_def_set_return_data" => { + function_def_set_return_data(self, arguments, location) + } "function_def_set_unconstrained" => { function_def_set_unconstrained(self, arguments, location) } @@ -2516,6 +2519,23 @@ fn function_def_set_return_public( Ok(Value::Unit) } +// fn set_return_data(self) +fn function_def_set_return_data( + interpreter: &mut Interpreter, + arguments: Vec<(Value, Location)>, + location: Location, +) -> IResult { + let self_argument = check_one_argument(arguments, location)?; + + let func_id = get_function_def(self_argument)?; + check_function_not_yet_resolved(interpreter, func_id, location)?; + + let func_meta = interpreter.elaborator.interner.function_meta_mut(&func_id); + func_meta.return_visibility = Visibility::ReturnData; + + Ok(Value::Unit) +} + // fn set_unconstrained(self, value: bool) fn function_def_set_unconstrained( interpreter: &mut Interpreter, diff --git a/noir/noir-repo/noir_stdlib/src/meta/function_def.nr b/noir/noir-repo/noir_stdlib/src/meta/function_def.nr index 3c29d57e20c..11dc169b188 100644 --- a/noir/noir-repo/noir_stdlib/src/meta/function_def.nr +++ b/noir/noir-repo/noir_stdlib/src/meta/function_def.nr @@ -59,6 +59,9 @@ impl FunctionDefinition { pub comptime fn set_return_public(self, public: bool) {} // docs:end:set_return_public + #[builtin(function_def_set_return_data)] + comptime fn set_return_data(self) {} + #[builtin(function_def_set_unconstrained)] // docs:start:set_unconstrained pub comptime fn set_unconstrained(self, value: bool) {} diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 043302d2689..6374c9d0952 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -173,6 +173,7 @@ export const HEADER_LENGTH = 24; export const PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 544; export const PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 691; export const PRIVATE_CALL_STACK_ITEM_LENGTH = 547; +export const PRIVATE_CONTEXT_INPUTS_LENGTH = 39; export const PUBLIC_CONTEXT_INPUTS_LENGTH = 42; export const AGGREGATION_OBJECT_LENGTH = 16; export const SCOPED_READ_REQUEST_LEN = 3; diff --git a/yarn-project/noir-protocol-circuits-types/src/index.ts b/yarn-project/noir-protocol-circuits-types/src/index.ts index 535be5af1ad..d693f6d4ffd 100644 --- a/yarn-project/noir-protocol-circuits-types/src/index.ts +++ b/yarn-project/noir-protocol-circuits-types/src/index.ts @@ -51,17 +51,18 @@ import { mapBlockRootRollupInputsToNoir, mapEmptyBlockRootRollupInputsToNoir, mapEmptyKernelInputsToNoir, + mapFieldToNoir, mapKernelCircuitPublicInputsFromNoir, mapMergeRollupInputsToNoir, mapParityPublicInputsFromNoir, + mapPrivateCallDataToNoir, + mapPrivateCircuitPublicInputsToNoir, mapPrivateKernelCircuitPublicInputsFromNoir, - mapPrivateKernelInitCircuitPrivateInputsToNoir, - mapPrivateKernelInnerCircuitPrivateInputsToNoir, - mapPrivateKernelResetCircuitPrivateInputsToNoir, - mapPrivateKernelTailCircuitPrivateInputsToNoir, + mapPrivateKernelCircuitPublicInputsToNoir, + mapPrivateKernelDataToNoir, + mapPrivateKernelResetHintsToNoir, mapPrivateKernelTailCircuitPublicInputsForPublicFromNoir, mapPrivateKernelTailCircuitPublicInputsForRollupFromNoir, - mapPrivateKernelTailToPublicCircuitPrivateInputsToNoir, mapPublicKernelCircuitPrivateInputsToNoir, mapPublicKernelCircuitPublicInputsFromNoir, mapPublicKernelInnerCircuitPrivateInputsToNoir, @@ -69,6 +70,7 @@ import { mapRootParityInputsToNoir, mapRootRollupInputsToNoir, mapRootRollupPublicInputsFromNoir, + mapTxRequestToNoir, mapVMCircuitPublicInputsFromNoir, } from './type_conversion.js'; import { @@ -99,6 +101,8 @@ export { maxPrivateKernelResetDimensions, privateKernelResetDimensionsConfig } f export * from './utils/private_kernel_reset.js'; export * from './vks.js'; +/* eslint-disable camelcase */ + // TODO(Tom): This should be exported from noirc_abi /** * The decoded inputs from the circuit. @@ -123,7 +127,10 @@ export async function executeInit( privateKernelInitCircuitPrivateInputs: PrivateKernelInitCircuitPrivateInputs, ): Promise { const returnType = await executePrivateKernelInitWithACVM( - mapPrivateKernelInitCircuitPrivateInputsToNoir(privateKernelInitCircuitPrivateInputs), + mapTxRequestToNoir(privateKernelInitCircuitPrivateInputs.txRequest), + mapFieldToNoir(privateKernelInitCircuitPrivateInputs.vkTreeRoot), + mapPrivateCallDataToNoir(privateKernelInitCircuitPrivateInputs.privateCall), + mapPrivateCircuitPublicInputsToNoir(privateKernelInitCircuitPrivateInputs.privateCall.callStackItem.publicInputs), SimulatedClientCircuitArtifacts.PrivateKernelInitArtifact as CompiledCircuit, foreignCallHandler, ); @@ -140,7 +147,10 @@ export async function executeInner( privateKernelInnerCircuitPrivateInputs: PrivateKernelInnerCircuitPrivateInputs, ): Promise { const returnType = await executePrivateKernelInnerWithACVM( - mapPrivateKernelInnerCircuitPrivateInputsToNoir(privateKernelInnerCircuitPrivateInputs), + mapPrivateKernelDataToNoir(privateKernelInnerCircuitPrivateInputs.previousKernel), + mapPrivateKernelCircuitPublicInputsToNoir(privateKernelInnerCircuitPrivateInputs.previousKernel.publicInputs), + mapPrivateCallDataToNoir(privateKernelInnerCircuitPrivateInputs.privateCall), + mapPrivateCircuitPublicInputsToNoir(privateKernelInnerCircuitPrivateInputs.privateCall.callStackItem.publicInputs), SimulatedClientCircuitArtifacts.PrivateKernelInnerArtifact as CompiledCircuit, foreignCallHandler, ); @@ -174,7 +184,11 @@ export async function executeReset< const artifact = SimulatedClientCircuitArtifacts[getPrivateKernelResetArtifactName(dimensions)]; const program = new Noir(artifact as CompiledCircuit); const args: InputMap = { - input: mapPrivateKernelResetCircuitPrivateInputsToNoir(privateKernelResetCircuitPrivateInputs), + previous_kernel: mapPrivateKernelDataToNoir(privateKernelResetCircuitPrivateInputs.previousKernel), + previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( + privateKernelResetCircuitPrivateInputs.previousKernel.publicInputs, + ), + hints: mapPrivateKernelResetHintsToNoir(privateKernelResetCircuitPrivateInputs.hints), }; const { returnValue } = await program.execute(args, foreignCallHandler); return mapPrivateKernelCircuitPublicInputsFromNoir(returnValue as any); @@ -189,7 +203,8 @@ export async function executeTail( privateInputs: PrivateKernelTailCircuitPrivateInputs, ): Promise { const returnType = await executePrivateKernelTailWithACVM( - mapPrivateKernelTailCircuitPrivateInputsToNoir(privateInputs), + mapPrivateKernelDataToNoir(privateInputs.previousKernel), + mapPrivateKernelCircuitPublicInputsToNoir(privateInputs.previousKernel.publicInputs), SimulatedClientCircuitArtifacts.PrivateKernelTailArtifact as CompiledCircuit, foreignCallHandler, ); @@ -206,7 +221,8 @@ export async function executeTailForPublic( privateInputs: PrivateKernelTailCircuitPrivateInputs, ): Promise { const returnType = await executePrivateKernelTailToPublicWithACVM( - mapPrivateKernelTailToPublicCircuitPrivateInputsToNoir(privateInputs), + mapPrivateKernelDataToNoir(privateInputs.previousKernel), + mapPrivateKernelCircuitPublicInputsToNoir(privateInputs.previousKernel.publicInputs), SimulatedClientCircuitArtifacts.PrivateKernelTailToPublicArtifact as CompiledCircuit, foreignCallHandler, ); @@ -222,9 +238,13 @@ export async function executeTailForPublic( export function convertPrivateKernelInitInputsToWitnessMap( privateKernelInitCircuitPrivateInputs: PrivateKernelInitCircuitPrivateInputs, ): WitnessMap { - const mapped = mapPrivateKernelInitCircuitPrivateInputsToNoir(privateKernelInitCircuitPrivateInputs); const initialWitnessMap = abiEncode(ClientCircuitArtifacts.PrivateKernelInitArtifact.abi, { - input: mapped as any, + tx_request: mapTxRequestToNoir(privateKernelInitCircuitPrivateInputs.txRequest), + vk_tree_root: mapFieldToNoir(privateKernelInitCircuitPrivateInputs.vkTreeRoot), + private_call: mapPrivateCallDataToNoir(privateKernelInitCircuitPrivateInputs.privateCall), + app_public_inputs: mapPrivateCircuitPublicInputsToNoir( + privateKernelInitCircuitPrivateInputs.privateCall.callStackItem.publicInputs, + ), }); return initialWitnessMap; } @@ -237,8 +257,16 @@ export function convertPrivateKernelInitInputsToWitnessMap( export function convertPrivateKernelInnerInputsToWitnessMap( privateKernelInnerCircuitPrivateInputs: PrivateKernelInnerCircuitPrivateInputs, ): WitnessMap { - const mapped = mapPrivateKernelInnerCircuitPrivateInputsToNoir(privateKernelInnerCircuitPrivateInputs); - const initialWitnessMap = abiEncode(ClientCircuitArtifacts.PrivateKernelInnerArtifact.abi, { input: mapped as any }); + const initialWitnessMap = abiEncode(ClientCircuitArtifacts.PrivateKernelInnerArtifact.abi, { + previous_kernel: mapPrivateKernelDataToNoir(privateKernelInnerCircuitPrivateInputs.previousKernel), + previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( + privateKernelInnerCircuitPrivateInputs.previousKernel.publicInputs, + ), + private_call: mapPrivateCallDataToNoir(privateKernelInnerCircuitPrivateInputs.privateCall), + app_public_inputs: mapPrivateCircuitPublicInputsToNoir( + privateKernelInnerCircuitPrivateInputs.privateCall.callStackItem.publicInputs, + ), + }); return initialWitnessMap; } @@ -265,9 +293,15 @@ export function convertPrivateKernelResetInputsToWitnessMap< >, artifactName: PrivateResetArtifact, ): WitnessMap { - const mapped = mapPrivateKernelResetCircuitPrivateInputsToNoir(privateKernelResetCircuitPrivateInputs); + const args: InputMap = { + previous_kernel: mapPrivateKernelDataToNoir(privateKernelResetCircuitPrivateInputs.previousKernel), + previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( + privateKernelResetCircuitPrivateInputs.previousKernel.publicInputs, + ), + hints: mapPrivateKernelResetHintsToNoir(privateKernelResetCircuitPrivateInputs.hints), + }; const artifact = ClientCircuitArtifacts[artifactName]; - const initialWitnessMap = abiEncode(artifact.abi as Abi, { input: mapped as any }); + const initialWitnessMap = abiEncode(artifact.abi as Abi, args); return initialWitnessMap; } @@ -279,8 +313,13 @@ export function convertPrivateKernelResetInputsToWitnessMap< export function convertPrivateKernelTailInputsToWitnessMap( privateKernelTailCircuitPrivateInputs: PrivateKernelTailCircuitPrivateInputs, ): WitnessMap { - const mapped = mapPrivateKernelTailCircuitPrivateInputsToNoir(privateKernelTailCircuitPrivateInputs); - const initialWitnessMap = abiEncode(ClientCircuitArtifacts.PrivateKernelTailArtifact.abi, { input: mapped as any }); + const args: InputMap = { + previous_kernel: mapPrivateKernelDataToNoir(privateKernelTailCircuitPrivateInputs.previousKernel), + previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( + privateKernelTailCircuitPrivateInputs.previousKernel.publicInputs, + ), + }; + const initialWitnessMap = abiEncode(ClientCircuitArtifacts.PrivateKernelTailArtifact.abi, args); return initialWitnessMap; } @@ -292,10 +331,13 @@ export function convertPrivateKernelTailInputsToWitnessMap( export function convertPrivateKernelTailToPublicInputsToWitnessMap( privateKernelTailToPublicCircuitPrivateInputs: PrivateKernelTailCircuitPrivateInputs, ): WitnessMap { - const mapped = mapPrivateKernelTailToPublicCircuitPrivateInputsToNoir(privateKernelTailToPublicCircuitPrivateInputs); - const initialWitnessMap = abiEncode(ClientCircuitArtifacts.PrivateKernelTailToPublicArtifact.abi, { - input: mapped as any, - }); + const args: InputMap = { + previous_kernel: mapPrivateKernelDataToNoir(privateKernelTailToPublicCircuitPrivateInputs.previousKernel), + previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( + privateKernelTailToPublicCircuitPrivateInputs.previousKernel.publicInputs, + ), + }; + const initialWitnessMap = abiEncode(ClientCircuitArtifacts.PrivateKernelTailToPublicArtifact.abi, args); return initialWitnessMap; } diff --git a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts index 0ef38b37192..3e8ef9ae05e 100644 --- a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts +++ b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts @@ -86,11 +86,7 @@ import { PrivateKernelCircuitPublicInputs, type PrivateKernelData, type PrivateKernelEmptyInputs, - type PrivateKernelInitCircuitPrivateInputs, - type PrivateKernelInnerCircuitPrivateInputs, - type PrivateKernelResetCircuitPrivateInputsVariants, type PrivateKernelResetHints, - type PrivateKernelTailCircuitPrivateInputs, PrivateKernelTailCircuitPublicInputs, PrivateValidationRequests, PublicAccumulatedData, @@ -208,19 +204,14 @@ import type { PreviousRollupBlockData as PreviousRollupBlockDataNoir, PreviousRollupData as PreviousRollupDataNoir, PrivateAccumulatedData as PrivateAccumulatedDataNoir, - PrivateCallData as PrivateCallDataNoir, + PrivateCallDataWithoutPublicInputs as PrivateCallDataWithoutPublicInputsNoir, PrivateCallRequest as PrivateCallRequestNoir, - PrivateCallStackItem as PrivateCallStackItemNoir, + PrivateCallStackItemWithoutPublicInputs as PrivateCallStackItemWithoutPublicInputsNoir, PrivateCircuitPublicInputs as PrivateCircuitPublicInputsNoir, PrivateKernelCircuitPublicInputs as PrivateKernelCircuitPublicInputsNoir, - PrivateKernelData as PrivateKernelDataNoir, + PrivateKernelDataWithoutPublicInputs as PrivateKernelDataWithoutPublicInputsNoir, PrivateKernelEmptyPrivateInputs as PrivateKernelEmptyPrivateInputsNoir, - PrivateKernelInitCircuitPrivateInputs as PrivateKernelInitCircuitPrivateInputsNoir, - PrivateKernelInnerCircuitPrivateInputs as PrivateKernelInnerCircuitPrivateInputsNoir, - PrivateKernelResetCircuitPrivateInputs as PrivateKernelResetCircuitPrivateInputsNoir, PrivateKernelResetHints as PrivateKernelResetHintsNoir, - PrivateKernelTailCircuitPrivateInputs as PrivateKernelTailCircuitPrivateInputsNoir, - PrivateKernelTailToPublicCircuitPrivateInputs as PrivateKernelTailToPublicCircuitPrivateInputsNoir, PrivateValidationRequests as PrivateValidationRequestsNoir, PublicAccumulatedDataArrayLengths as PublicAccumulatedDataArrayLengthsNoir, PublicAccumulatedData as PublicAccumulatedDataNoir, @@ -998,11 +989,12 @@ export function mapPrivateCircuitPublicInputsToNoir( * @param privateCallStackItem - The private call stack item. * @returns The noir private call stack item. */ -export function mapPrivateCallStackItemToNoir(privateCallStackItem: PrivateCallStackItem): PrivateCallStackItemNoir { +export function mapPrivateCallStackItemToNoir( + privateCallStackItem: PrivateCallStackItem, +): PrivateCallStackItemWithoutPublicInputsNoir { return { contract_address: mapAztecAddressToNoir(privateCallStackItem.contractAddress), function_data: mapFunctionDataToNoir(privateCallStackItem.functionData), - public_inputs: mapPrivateCircuitPublicInputsToNoir(privateCallStackItem.publicInputs), }; } @@ -1011,7 +1003,7 @@ export function mapPrivateCallStackItemToNoir(privateCallStackItem: PrivateCallS * @param privateCallData - The private call data. * @returns The noir private call data. */ -export function mapPrivateCallDataToNoir(privateCallData: PrivateCallData): PrivateCallDataNoir { +export function mapPrivateCallDataToNoir(privateCallData: PrivateCallData): PrivateCallDataWithoutPublicInputsNoir { return { call_stack_item: mapPrivateCallStackItemToNoir(privateCallData.callStackItem), vk: mapVerificationKeyToNoir(privateCallData.vk), @@ -1712,9 +1704,10 @@ export function mapPrivateKernelCircuitPublicInputsToNoir( * @param privateKernelInnerData - The private kernel inner data. * @returns The noir private kernel inner data. */ -export function mapPrivateKernelDataToNoir(privateKernelInnerData: PrivateKernelData): PrivateKernelDataNoir { +export function mapPrivateKernelDataToNoir( + privateKernelInnerData: PrivateKernelData, +): PrivateKernelDataWithoutPublicInputsNoir { return { - public_inputs: mapPrivateKernelCircuitPublicInputsToNoir(privateKernelInnerData.publicInputs), vk: mapVerificationKeyToNoir(privateKernelInnerData.vk), vk_index: mapFieldToNoir(new Fr(privateKernelInnerData.vkIndex)), vk_path: mapTuple(privateKernelInnerData.vkPath, mapFieldToNoir), @@ -1754,25 +1747,6 @@ export function mapPrivateKernelTailCircuitPublicInputsForPublicFromNoir( ); } -export function mapPrivateKernelInitCircuitPrivateInputsToNoir( - inputs: PrivateKernelInitCircuitPrivateInputs, -): PrivateKernelInitCircuitPrivateInputsNoir { - return { - tx_request: mapTxRequestToNoir(inputs.txRequest), - private_call: mapPrivateCallDataToNoir(inputs.privateCall), - vk_tree_root: mapFieldToNoir(inputs.vkTreeRoot), - }; -} - -export function mapPrivateKernelInnerCircuitPrivateInputsToNoir( - inputs: PrivateKernelInnerCircuitPrivateInputs, -): PrivateKernelInnerCircuitPrivateInputsNoir { - return { - previous_kernel: mapPrivateKernelDataToNoir(inputs.previousKernel), - private_call: mapPrivateCallDataToNoir(inputs.privateCall), - }; -} - function mapTransientDataIndexHintToNoir(indexHint: TransientDataIndexHint): TransientDataIndexHintNoir { return { nullifier_index: mapNumberToNoir(indexHint.nullifierIndex), @@ -1780,7 +1754,7 @@ function mapTransientDataIndexHintToNoir(indexHint: TransientDataIndexHint): Tra }; } -function mapPrivateKernelResetHintsToNoir< +export function mapPrivateKernelResetHintsToNoir< NH_RR_PENDING extends number, NH_RR_SETTLED extends number, NLL_RR_PENDING extends number, @@ -1819,52 +1793,6 @@ function mapPrivateKernelResetHintsToNoir< }; } -export function mapPrivateKernelResetCircuitPrivateInputsToNoir< - NH_RR_PENDING extends number, - NH_RR_SETTLED extends number, - NLL_RR_PENDING extends number, - NLL_RR_SETTLED extends number, - KEY_VALIDATION_REQUESTS extends number, - NUM_TRANSIENT_DATA_HINTS extends number, ->( - inputs: PrivateKernelResetCircuitPrivateInputsVariants< - NH_RR_PENDING, - NH_RR_SETTLED, - NLL_RR_PENDING, - NLL_RR_SETTLED, - KEY_VALIDATION_REQUESTS, - NUM_TRANSIENT_DATA_HINTS - >, -): PrivateKernelResetCircuitPrivateInputsNoir< - NH_RR_PENDING, - NH_RR_SETTLED, - NLL_RR_PENDING, - NLL_RR_SETTLED, - KEY_VALIDATION_REQUESTS, - NUM_TRANSIENT_DATA_HINTS -> { - return { - previous_kernel: mapPrivateKernelDataToNoir(inputs.previousKernel), - hints: mapPrivateKernelResetHintsToNoir(inputs.hints), - }; -} - -export function mapPrivateKernelTailCircuitPrivateInputsToNoir( - inputs: PrivateKernelTailCircuitPrivateInputs, -): PrivateKernelTailCircuitPrivateInputsNoir { - return { - previous_kernel: mapPrivateKernelDataToNoir(inputs.previousKernel), - }; -} - -export function mapPrivateKernelTailToPublicCircuitPrivateInputsToNoir( - inputs: PrivateKernelTailCircuitPrivateInputs, -): PrivateKernelTailToPublicCircuitPrivateInputsNoir { - return { - previous_kernel: mapPrivateKernelDataToNoir(inputs.previousKernel), - }; -} - export function mapPublicKernelInnerCircuitPrivateInputsToNoir( inputs: PublicKernelInnerCircuitPrivateInputs, ): PublicKernelInnerCircuitPrivateInputsNoir { diff --git a/yarn-project/simulator/src/client/client_execution_context.ts b/yarn-project/simulator/src/client/client_execution_context.ts index 33e12d54bb8..6e0c900c5e1 100644 --- a/yarn-project/simulator/src/client/client_execution_context.ts +++ b/yarn-project/simulator/src/client/client_execution_context.ts @@ -17,6 +17,7 @@ import { CallContext, FunctionSelector, type Header, + PRIVATE_CONTEXT_INPUTS_LENGTH, PUBLIC_DISPATCH_SELECTOR, PrivateContextInputs, type TxContext, @@ -108,8 +109,12 @@ export class ClientExecutionContext extends ViewDataOracle { this.txContext, this.sideEffectCounter, ); + const privateContextInputsAsFields = privateContextInputs.toFields(); + if (privateContextInputsAsFields.length !== PRIVATE_CONTEXT_INPUTS_LENGTH) { + throw new Error('Invalid private context inputs size'); + } - const fields = [...privateContextInputs.toFields(), ...args]; + const fields = [...privateContextInputsAsFields, ...args]; return toACVMWitness(0, fields); } diff --git a/yarn-project/simulator/src/client/index.ts b/yarn-project/simulator/src/client/index.ts index c32520980eb..123138b079f 100644 --- a/yarn-project/simulator/src/client/index.ts +++ b/yarn-project/simulator/src/client/index.ts @@ -2,3 +2,4 @@ export * from './simulator.js'; export * from './db_oracle.js'; export * from './pick_notes.js'; export * from './execution_note_cache.js'; +export { extractPrivateCircuitPublicInputs } from './private_execution.js'; diff --git a/yarn-project/simulator/src/client/private_execution.ts b/yarn-project/simulator/src/client/private_execution.ts index 91c5c35f51f..83e2245d21b 100644 --- a/yarn-project/simulator/src/client/private_execution.ts +++ b/yarn-project/simulator/src/client/private_execution.ts @@ -1,13 +1,20 @@ import { PrivateExecutionResult } from '@aztec/circuit-types'; import { type CircuitWitnessGenerationStats } from '@aztec/circuit-types/stats'; -import { Fr, FunctionData, PrivateCallStackItem, PrivateCircuitPublicInputs } from '@aztec/circuits.js'; -import type { FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi'; +import { + Fr, + FunctionData, + PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH, + PRIVATE_CONTEXT_INPUTS_LENGTH, + PrivateCallStackItem, + PrivateCircuitPublicInputs, +} from '@aztec/circuits.js'; +import { type FunctionArtifact, type FunctionSelector, countArgumentsSize } from '@aztec/foundation/abi'; import { type AztecAddress } from '@aztec/foundation/aztec-address'; import { createDebugLogger } from '@aztec/foundation/log'; import { Timer } from '@aztec/foundation/timer'; -import { witnessMapToFields } from '../acvm/deserialize.js'; -import { Oracle, acvm, extractCallStack } from '../acvm/index.js'; +import { fromACVMField, witnessMapToFields } from '../acvm/deserialize.js'; +import { type ACVMWitness, Oracle, acvm, extractCallStack } from '../acvm/index.js'; import { ExecutionError } from '../common/errors.js'; import { type ClientExecutionContext } from './client_execution_context.js'; @@ -40,8 +47,7 @@ export async function executePrivateFunction( }); const duration = timer.ms(); const partialWitness = acirExecutionResult.partialWitness; - const returnWitness = witnessMapToFields(acirExecutionResult.returnWitness); - const publicInputs = PrivateCircuitPublicInputs.fromFields(returnWitness); + const publicInputs = extractPrivateCircuitPublicInputs(artifact, partialWitness); // TODO (alexg) estimate this size const initialWitnessSize = witnessMapToFields(initialWitness).length * Fr.SIZE_IN_BYTES; @@ -92,3 +98,27 @@ export async function executePrivateFunction( unencryptedLogs, ); } + +/** + * Get the private circuit public inputs from the partial witness. + * @param artifact - The function artifact + * @param partialWitness - The partial witness, result of simulating the function. + * @returns - The public inputs. + */ +export function extractPrivateCircuitPublicInputs( + artifact: FunctionArtifact, + partialWitness: ACVMWitness, +): PrivateCircuitPublicInputs { + const parametersSize = countArgumentsSize(artifact) + PRIVATE_CONTEXT_INPUTS_LENGTH; + const returnsSize = PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH; + const returnData = []; + // Return values always appear in the witness after arguments. + for (let i = parametersSize; i < parametersSize + returnsSize; i++) { + const returnedField = partialWitness.get(i); + if (returnedField === undefined) { + throw new Error(`Missing return value for index ${i}`); + } + returnData.push(fromACVMField(returnedField)); + } + return PrivateCircuitPublicInputs.fromFields(returnData); +} diff --git a/yarn-project/txe/src/oracle/txe_oracle.ts b/yarn-project/txe/src/oracle/txe_oracle.ts index 826516d8c5f..1f647cb8ce1 100644 --- a/yarn-project/txe/src/oracle/txe_oracle.ts +++ b/yarn-project/txe/src/oracle/txe_oracle.ts @@ -22,7 +22,6 @@ import { PUBLIC_DATA_SUBTREE_HEIGHT, type PUBLIC_DATA_TREE_HEIGHT, PUBLIC_DISPATCH_SELECTOR, - PrivateCircuitPublicInputs, PrivateContextInputs, PublicDataTreeLeaf, type PublicDataTreeLeafPreimage, @@ -58,6 +57,7 @@ import { acvm, createSimulationError, extractCallStack, + extractPrivateCircuitPublicInputs, pickNotes, toACVMWitness, witnessMapToFields, @@ -598,8 +598,7 @@ export class TXE implements TypedOracle { throw createSimulationError(execError); }); const duration = timer.ms(); - const returnWitness = witnessMapToFields(acirExecutionResult.returnWitness); - const publicInputs = PrivateCircuitPublicInputs.fromFields(returnWitness); + const publicInputs = extractPrivateCircuitPublicInputs(artifact, acirExecutionResult.partialWitness); const initialWitnessSize = witnessMapToFields(initialWitness).length * Fr.SIZE_IN_BYTES; this.logger.debug(`Ran external function ${targetContractAddress.toString()}:${functionSelector}`, {