Skip to content

Commit

Permalink
fix: temporary fix for private kernel tail proving (#10593)
Browse files Browse the repository at this point in the history
Please read [contributing guidelines](CONTRIBUTING.md) and remove this
line.

Co-authored-by: just-mitch <[email protected]>
  • Loading branch information
LeilaWang and just-mitch authored Dec 10, 2024
1 parent a4dfe13 commit d194cdf
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<PrivateLogData>, 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<PrivateLogData>, out: PrivateLog| out == l.inner.log,
// split_counter,
// );
}

fn validate_propagated_sorted_values(self) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<PrivateLogData>| 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();
Expand Down
46 changes: 46 additions & 0 deletions yarn-project/pxe/src/kernel_prover/kernel_prover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
PrivateKernelInnerCircuitPrivateInputs,
PrivateKernelTailCircuitPrivateInputs,
type PrivateKernelTailCircuitPublicInputs,
type PrivateLog,
type ScopedPrivateLogData,
type TxRequest,
VK_TREE_HEIGHT,
VerificationKeyAsFields,
Expand All @@ -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<PrivateKernelCircuitPublicInputs> = {
publicInputs: PrivateKernelCircuitPublicInputs.empty(),
verificationKey: VerificationKeyAsFields.makeEmpty(CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS),
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d194cdf

Please sign in to comment.