Skip to content

Commit d194cdf

Browse files
fix: temporary fix for private kernel tail proving (#10593)
Please read [contributing guidelines](CONTRIBUTING.md) and remove this line. Co-authored-by: just-mitch <68168980+just-mitch@users.noreply.github.com>
1 parent a4dfe13 commit d194cdf

File tree

3 files changed

+83
-8
lines changed

3 files changed

+83
-8
lines changed

noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_validator.nr

+7-7
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ impl TailToPublicOutputValidator {
8686
);
8787

8888
// private_logs
89-
assert_split_transformed_value_arrays(
90-
prev_data.private_logs,
91-
output_non_revertible.private_logs,
92-
output_revertible.private_logs,
93-
|l: Scoped<PrivateLogData>, out: PrivateLog| out == l.inner.log,
94-
split_counter,
95-
);
89+
// assert_split_transformed_value_arrays(
90+
// prev_data.private_logs,
91+
// output_non_revertible.private_logs,
92+
// output_revertible.private_logs,
93+
// |l: Scoped<PrivateLogData>, out: PrivateLog| out == l.inner.log,
94+
// split_counter,
95+
// );
9696
}
9797

9898
fn validate_propagated_sorted_values(self) {

noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr

+30-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ mod tests {
5858
use dep::types::{
5959
abis::{
6060
gas::Gas, kernel_circuit_public_inputs::PrivateToPublicKernelCircuitPublicInputs,
61-
note_hash::ScopedNoteHash, nullifier::ScopedNullifier,
61+
note_hash::ScopedNoteHash, nullifier::ScopedNullifier, private_log::PrivateLogData,
62+
side_effect::scoped::Scoped,
6263
},
6364
address::{AztecAddress, EthAddress},
6465
point::Point,
@@ -212,6 +213,34 @@ mod tests {
212213
assert_eq(public_inputs.gas_used, Gas::tx_overhead() + Gas::new(da_gas, l2_gas));
213214
}
214215

216+
#[test]
217+
unconstrained fn split_private_logs() {
218+
let mut builder = PrivateKernelTailToPublicInputsBuilder::new();
219+
220+
// expect 2 non-revertible note hashes
221+
builder.previous_kernel.append_siloed_private_logs_for_note(2, 11);
222+
builder.previous_kernel.end_setup();
223+
224+
// expect 2 revertible note hashes
225+
builder.previous_kernel.append_siloed_private_logs_for_note(3, 12);
226+
227+
let exposed_private_logs = builder.previous_kernel.private_logs.storage().map(
228+
|n: Scoped<PrivateLogData>| n.inner.log,
229+
);
230+
231+
let public_inputs = builder.execute();
232+
233+
assert_array_eq(
234+
public_inputs.non_revertible_accumulated_data.private_logs,
235+
[exposed_private_logs[0], exposed_private_logs[1]],
236+
);
237+
238+
assert_array_eq(
239+
public_inputs.revertible_accumulated_data.private_logs,
240+
[exposed_private_logs[2], exposed_private_logs[3], exposed_private_logs[4]],
241+
);
242+
}
243+
215244
#[test(should_fail_with = "Non empty note hash read requests")]
216245
fn non_empty_note_hash_read_requests() {
217246
let mut builder = PrivateKernelTailToPublicInputsBuilder::new();

yarn-project/pxe/src/kernel_prover/kernel_prover.ts

+46
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import {
1919
PrivateKernelInnerCircuitPrivateInputs,
2020
PrivateKernelTailCircuitPrivateInputs,
2121
type PrivateKernelTailCircuitPublicInputs,
22+
type PrivateLog,
23+
type ScopedPrivateLogData,
2224
type TxRequest,
2325
VK_TREE_HEIGHT,
2426
VerificationKeyAsFields,
@@ -37,10 +39,48 @@ import {
3739
} from '@aztec/protocol-contracts';
3840

3941
import { type WitnessMap } from '@noir-lang/types';
42+
import { strict as assert } from 'assert';
4043

4144
import { PrivateKernelResetPrivateInputsBuilder } from './hints/build_private_kernel_reset_private_inputs.js';
4245
import { type ProvingDataOracle } from './proving_data_oracle.js';
4346

47+
// TODO(#10592): Temporary workaround to check that the private logs are correctly split into non-revertible set and revertible set.
48+
// This should be done in TailToPublicOutputValidator in private kernel tail.
49+
function checkPrivateLogs(
50+
privateLogs: ScopedPrivateLogData[],
51+
nonRevertiblePrivateLogs: PrivateLog[],
52+
revertiblePrivateLogs: PrivateLog[],
53+
splitCounter: number,
54+
) {
55+
let numNonRevertible = 0;
56+
let numRevertible = 0;
57+
privateLogs
58+
.filter(privateLog => privateLog.inner.counter !== 0)
59+
.forEach(privateLog => {
60+
if (privateLog.inner.counter < splitCounter) {
61+
assert(
62+
privateLog.inner.log.toBuffer().equals(nonRevertiblePrivateLogs[numNonRevertible].toBuffer()),
63+
`mismatch non-revertible private logs at index ${numNonRevertible}`,
64+
);
65+
numNonRevertible++;
66+
} else {
67+
assert(
68+
privateLog.inner.log.toBuffer().equals(revertiblePrivateLogs[numRevertible].toBuffer()),
69+
`mismatch revertible private logs at index ${numRevertible}`,
70+
);
71+
numRevertible++;
72+
}
73+
});
74+
assert(
75+
nonRevertiblePrivateLogs.slice(numNonRevertible).every(l => l.isEmpty()),
76+
'Unexpected non-empty private log in non-revertible set.',
77+
);
78+
assert(
79+
revertiblePrivateLogs.slice(numRevertible).every(l => l.isEmpty()),
80+
'Unexpected non-empty private log in revertible set.',
81+
);
82+
}
83+
4484
const NULL_PROVE_OUTPUT: PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs> = {
4585
publicInputs: PrivateKernelCircuitPublicInputs.empty(),
4686
verificationKey: VerificationKeyAsFields.makeEmpty(CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS),
@@ -225,6 +265,12 @@ export class KernelProver {
225265

226266
pushTestData('private-kernel-inputs-ordering', privateInputs);
227267
const tailOutput = await this.proofCreator.simulateProofTail(privateInputs);
268+
if (tailOutput.publicInputs.forPublic) {
269+
const privateLogs = privateInputs.previousKernel.publicInputs.end.privateLogs;
270+
const nonRevertiblePrivateLogs = tailOutput.publicInputs.forPublic.nonRevertibleAccumulatedData.privateLogs;
271+
const revertiblePrivateLogs = tailOutput.publicInputs.forPublic.revertibleAccumulatedData.privateLogs;
272+
checkPrivateLogs(privateLogs, nonRevertiblePrivateLogs, revertiblePrivateLogs, validationRequestsSplitCounter);
273+
}
228274

229275
acirs.push(tailOutput.bytecode);
230276
witnessStack.push(tailOutput.outputWitness);

0 commit comments

Comments
 (0)