From 73a9f623385ff45fa4a9e0fdf80c503252ddc36a Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Wed, 31 Jul 2024 15:51:41 -0300 Subject: [PATCH 1/2] chore: Validate outputs in kernel circuits --- .../crates/private-kernel-lib/src/private_kernel_init.nr | 2 +- .../crates/private-kernel-lib/src/private_kernel_inner.nr | 2 +- .../crates/private-kernel-lib/src/private_kernel_reset.nr | 2 +- .../crates/private-kernel-lib/src/private_kernel_tail.nr | 2 +- .../src/private_kernel_tail_to_public.nr | 2 +- .../noir-protocol-circuits/crates/types/src/lib.nr | 1 + .../noir-protocol-circuits/crates/types/src/validate.nr | 8 ++++++++ 7 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/validate.nr 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 34042b5cb68c..bbab4520c7bf 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 @@ -40,7 +40,7 @@ impl PrivateKernelInitCircuitPrivateInputs { private_call_data_validator.validate(output.end.note_hashes); // Validate output. - if !std::runtime::is_unconstrained() { + if dep::types::validate::should_validate_output() { PrivateKernelCircuitOutputValidator::new(output).validate_as_first_call( self.tx_request, self.private_call.call_stack_item.public_inputs, 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 f9a16f54ca29..7bd4c789aecc 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 @@ -58,7 +58,7 @@ impl PrivateKernelInnerCircuitPrivateInputs { } // Validate output. - if !std::runtime::is_unconstrained() { + if dep::types::validate::should_validate_output() { PrivateKernelCircuitOutputValidator::new(output).validate_as_inner_call( self.previous_kernel.public_inputs, previous_kernel_array_lengths, 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 fa5a9f2f9fd1..3247024809ec 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 @@ -61,7 +61,7 @@ impl bool { + true +} From bac2c9bbf827ea21c4a7cf16684cf7d3edfa9943 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Wed, 31 Jul 2024 16:25:23 -0300 Subject: [PATCH 2/2] Fix TailToPublicOutputValidator Co-authored-by: Leila Wang --- .../src/components/tail_to_public_output_validator.nr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_validator.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_validator.nr index 4d569989d9af..1950268b642f 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_validator.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_validator.nr @@ -178,7 +178,7 @@ impl TailToPublicOutputValidator { // unencrypted_logs_hashes assert_split_sorted_transformed_value_arrays_asc( prev_data.unencrypted_logs_hashes, - prev_data.unencrypted_logs_hashes, + prev_data.unencrypted_logs_hashes.map(|log: ScopedLogHash| log.expose_to_public()), split_counter, output_non_revertible.unencrypted_logs_hashes, output_revertible.unencrypted_logs_hashes,