From 2df215b160b2125edab8fe0f545623324a8b6419 Mon Sep 17 00:00:00 2001 From: Leila Wang Date: Tue, 10 Dec 2024 18:38:39 +0000 Subject: [PATCH] Temporary fix for private kernel tail proving. --- .../tail_to_public_output_validator.nr | 14 +++--- .../src/private_kernel_tail_to_public.nr | 31 ++++++++++++- .../pxe/src/kernel_prover/kernel_prover.ts | 46 +++++++++++++++++++ 3 files changed, 83 insertions(+), 8 deletions(-) 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 8f85ec7f367..bbf93064ee1 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 @@ -86,13 +86,13 @@ impl TailToPublicOutputValidator { ); // private_logs - assert_split_transformed_value_arrays( - prev_data.private_logs, - output_non_revertible.private_logs, - output_revertible.private_logs, - |l: Scoped, out: PrivateLog| out == l.inner.log, - split_counter, - ); + // assert_split_transformed_value_arrays( + // prev_data.private_logs, + // output_non_revertible.private_logs, + // output_revertible.private_logs, + // |l: Scoped, out: PrivateLog| out == l.inner.log, + // split_counter, + // ); } fn validate_propagated_sorted_values(self) { 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 cbcb984f479..1e6ef6fc35f 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 @@ -58,7 +58,8 @@ mod tests { use dep::types::{ abis::{ gas::Gas, kernel_circuit_public_inputs::PrivateToPublicKernelCircuitPublicInputs, - note_hash::ScopedNoteHash, nullifier::ScopedNullifier, + note_hash::ScopedNoteHash, nullifier::ScopedNullifier, private_log::PrivateLogData, + side_effect::scoped::Scoped, }, address::{AztecAddress, EthAddress}, point::Point, @@ -212,6 +213,34 @@ mod tests { assert_eq(public_inputs.gas_used, Gas::tx_overhead() + Gas::new(da_gas, l2_gas)); } + #[test] + unconstrained fn split_private_logs() { + let mut builder = PrivateKernelTailToPublicInputsBuilder::new(); + + // expect 2 non-revertible note hashes + builder.previous_kernel.append_siloed_private_logs_for_note(2, 11); + builder.previous_kernel.end_setup(); + + // expect 2 revertible note hashes + builder.previous_kernel.append_siloed_private_logs_for_note(3, 12); + + let exposed_private_logs = builder.previous_kernel.private_logs.storage().map( + |n: Scoped| n.inner.log, + ); + + let public_inputs = builder.execute(); + + assert_array_eq( + public_inputs.non_revertible_accumulated_data.private_logs, + [exposed_private_logs[0], exposed_private_logs[1]], + ); + + assert_array_eq( + public_inputs.revertible_accumulated_data.private_logs, + [exposed_private_logs[2], exposed_private_logs[3], exposed_private_logs[4]], + ); + } + #[test(should_fail_with = "Non empty note hash read requests")] fn non_empty_note_hash_read_requests() { let mut builder = PrivateKernelTailToPublicInputsBuilder::new(); diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts index 4bb018a75b3..9969c9ab210 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts @@ -19,6 +19,8 @@ import { PrivateKernelInnerCircuitPrivateInputs, PrivateKernelTailCircuitPrivateInputs, type PrivateKernelTailCircuitPublicInputs, + type PrivateLog, + type ScopedPrivateLogData, type TxRequest, VK_TREE_HEIGHT, VerificationKeyAsFields, @@ -37,10 +39,48 @@ import { } from '@aztec/protocol-contracts'; import { type WitnessMap } from '@noir-lang/types'; +import { strict as assert } from 'assert'; import { PrivateKernelResetPrivateInputsBuilder } from './hints/build_private_kernel_reset_private_inputs.js'; import { type ProvingDataOracle } from './proving_data_oracle.js'; +// TODO(#10592): Temporary workaround to check that the private logs are correctly split into non-revertible set and revertible set. +// This should be done in TailToPublicOutputValidator in private kernel tail. +function checkPrivateLogs( + privateLogs: ScopedPrivateLogData[], + nonRevertiblePrivateLogs: PrivateLog[], + revertiblePrivateLogs: PrivateLog[], + splitCounter: number, +) { + let numNonRevertible = 0; + let numRevertible = 0; + privateLogs + .filter(privateLog => privateLog.inner.counter !== 0) + .forEach(privateLog => { + if (privateLog.inner.counter < splitCounter) { + assert( + privateLog.inner.log.toBuffer().equals(nonRevertiblePrivateLogs[numNonRevertible].toBuffer()), + `mismatch non-revertible private logs at index ${numNonRevertible}`, + ); + numNonRevertible++; + } else { + assert( + privateLog.inner.log.toBuffer().equals(revertiblePrivateLogs[numRevertible].toBuffer()), + `mismatch revertible private logs at index ${numRevertible}`, + ); + numRevertible++; + } + }); + assert( + nonRevertiblePrivateLogs.slice(numNonRevertible).every(l => l.isEmpty()), + 'Unexpected non-empty private log in non-revertible set.', + ); + assert( + revertiblePrivateLogs.slice(numRevertible).every(l => l.isEmpty()), + 'Unexpected non-empty private log in revertible set.', + ); +} + const NULL_PROVE_OUTPUT: PrivateKernelSimulateOutput = { publicInputs: PrivateKernelCircuitPublicInputs.empty(), verificationKey: VerificationKeyAsFields.makeEmpty(CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS), @@ -225,6 +265,12 @@ export class KernelProver { pushTestData('private-kernel-inputs-ordering', privateInputs); const tailOutput = await this.proofCreator.simulateProofTail(privateInputs); + if (tailOutput.publicInputs.forPublic) { + const privateLogs = privateInputs.previousKernel.publicInputs.end.privateLogs; + const nonRevertiblePrivateLogs = tailOutput.publicInputs.forPublic.nonRevertibleAccumulatedData.privateLogs; + const revertiblePrivateLogs = tailOutput.publicInputs.forPublic.revertibleAccumulatedData.privateLogs; + checkPrivateLogs(privateLogs, nonRevertiblePrivateLogs, revertiblePrivateLogs, validationRequestsSplitCounter); + } acirs.push(tailOutput.bytecode); witnessStack.push(tailOutput.outputWitness);