Skip to content

Commit

Permalink
chore(1879): add use of PrivateKernelPublicInputs in TS whenever rele…
Browse files Browse the repository at this point in the history
…vant (#1911)

Resolves #1879 

# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if
the PR is ready to merge.
- [x] If the pull request requires a cryptography review (e.g.
cryptographic algorithm implementations) I have added the 'crypto' tag.
- [x] I have reviewed my diff in github, line by line and removed
unexpected formatting changes, testing logs, or commented-out code.
- [x] Every change is related to the PR description.
- [x] I have
[linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
this pull request to relevant issues (if any exist).
  • Loading branch information
jeanmon authored Aug 31, 2023
1 parent b7db6b7 commit 8d5f548
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 32 deletions.
4 changes: 2 additions & 2 deletions yarn-project/aztec-rpc/src/kernel_prover/kernel_prover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import {
AztecAddress,
CONTRACT_TREE_HEIGHT,
Fr,
KernelCircuitPublicInputs,
MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL,
MAX_READ_REQUESTS_PER_CALL,
MembershipWitness,
PreviousKernelData,
PrivateCallData,
PrivateCallStackItem,
PrivateKernelPublicInputs,
ReadRequestMembershipWitness,
TxRequest,
VK_TREE_HEIGHT,
Expand Down Expand Up @@ -78,7 +78,7 @@ export class KernelProver {
let previousVerificationKey = VerificationKey.makeFake();

let output: ProofOutput = {
publicInputs: KernelCircuitPublicInputs.empty(),
publicInputs: PrivateKernelPublicInputs.empty(),
proof: makeEmptyProof(),
};

Expand Down
4 changes: 4 additions & 0 deletions yarn-project/aztec-rpc/src/kernel_prover/proof_creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { createDebugLogger } from '@aztec/foundation/log';
export interface ProofOutput {
/**
* The public inputs required for the proof generation process.
* Note: C++ side does not define the specific data structure PrivateKernelPublicInputs and therefore
* would not generate a binding in circuits.gen.ts.
*/
publicInputs: KernelCircuitPublicInputs;
/**
Expand All @@ -39,6 +41,8 @@ export interface ProofOutput {
export interface ProofOutputFinal {
/**
* The public inputs required for the proof generation process.
* Note: C++ side does not define the specific data structure PrivateKernelPublicInputsFinal and therefore
* would not generate a binding in circuits.gen.ts.
*/
publicInputs: KernelCircuitPublicInputsFinal;
/**
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/circuits.js/src/structs/kernel/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {
makeAccumulatedData,
makeFinalAccumulatedData,
makeKernelPublicInputs,
makeKernelPublicInputsFinal,
makePreviousKernelData,
makePrivateKernelInputsInit,
makePrivateKernelInputsInner,
makePrivateKernelPublicInputsFinal,
makePublicKernelInputs,
makeSchnorrSignature,
} from '../../tests/factories.js';
Expand Down Expand Up @@ -63,7 +63,7 @@ describe('structs/kernel', () => {
});

it(`serializes and prints private_kernel_public_inputs for ordering circuit`, async () => {
const kernelInputs = makeKernelPublicInputsFinal();
const kernelInputs = makePrivateKernelPublicInputsFinal();
await expectSerializeToMatchSnapshot(
kernelInputs.toBuffer(),
'abis__test_roundtrip_serialize_kernel_circuit_public_inputs_final',
Expand Down
8 changes: 8 additions & 0 deletions yarn-project/circuits.js/src/structs/kernel/public_inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export class PublicKernelPublicInputs extends KernelCircuitPublicInputs {
constructor(end: CombinedAccumulatedData, constants: CombinedConstantData) {
super(end, constants, false);
}

static empty(): PublicKernelPublicInputs {
return new PublicKernelPublicInputs(CombinedAccumulatedData.empty(), CombinedConstantData.empty());
}
}

/**
Expand All @@ -63,4 +67,8 @@ export class PrivateKernelPublicInputs extends KernelCircuitPublicInputs {
constructor(end: CombinedAccumulatedData, constants: CombinedConstantData) {
super(end, constants, true);
}

static empty(): PrivateKernelPublicInputs {
return new PrivateKernelPublicInputs(CombinedAccumulatedData.empty(), CombinedConstantData.empty());
}
}
6 changes: 3 additions & 3 deletions yarn-project/circuits.js/src/tests/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
HISTORIC_BLOCKS_TREE_HEIGHT,
HistoricBlockData,
KernelCircuitPublicInputs,
KernelCircuitPublicInputsFinal,
L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH,
MAX_NEW_COMMITMENTS_PER_CALL,
MAX_NEW_COMMITMENTS_PER_TX,
Expand Down Expand Up @@ -68,6 +67,7 @@ import {
PrivateCircuitPublicInputs,
PrivateKernelInputsInit,
PrivateKernelInputsInner,
PrivateKernelPublicInputsFinal,
Proof,
PublicCallData,
PublicCallRequest,
Expand Down Expand Up @@ -346,8 +346,8 @@ export function makeKernelPublicInputs(seed = 1, fullAccumulatedData = true): Ke
* @param seed - The seed to use for generating the final ordering kernel circuit public inputs.
* @returns Final ordering kernel circuit public inputs.
*/
export function makeKernelPublicInputsFinal(seed = 1): KernelCircuitPublicInputsFinal {
return new KernelCircuitPublicInputsFinal(makeFinalAccumulatedData(seed, true), makeConstantData(seed + 0x100), true);
export function makePrivateKernelPublicInputsFinal(seed = 1): PrivateKernelPublicInputsFinal {
return new PrivateKernelPublicInputsFinal(makeFinalAccumulatedData(seed, true), makeConstantData(seed + 0x100));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { computeBlockHashWithGlobals, computeContractLeaf } from '@aztec/circuit
import {
fr,
makeBaseOrMergeRollupPublicInputs,
makeKernelPublicInputsFinal,
makeNewContractData,
makePrivateKernelPublicInputsFinal,
makeProof,
makePublicCallRequest,
makeRootRollupPublicInputs,
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('sequencer/solo_block_builder', () => {
};

const buildMockSimulatorInputs = async () => {
const kernelOutput = makeKernelPublicInputsFinal();
const kernelOutput = makePrivateKernelPublicInputsFinal();
kernelOutput.constants.blockData = await getHistoricBlockData(expectsDb);

const tx = await makeProcessedTx(
Expand Down
16 changes: 6 additions & 10 deletions yarn-project/sequencer-client/src/sequencer/processed_tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
CombinedAccumulatedData,
Fr,
HistoricBlockData,
KernelCircuitPublicInputs,
Proof,
PublicKernelPublicInputs,
makeEmptyProof,
} from '@aztec/circuits.js';
import { Tx, TxHash, TxL2Logs } from '@aztec/types';
Expand All @@ -16,7 +16,7 @@ export type ProcessedTx = Pick<Tx, 'proof' | 'encryptedLogs' | 'unencryptedLogs'
/**
* Output of the public kernel circuit for this tx.
*/
data: KernelCircuitPublicInputs;
data: PublicKernelPublicInputs;
/**
* Hash of the transaction.
*/
Expand Down Expand Up @@ -55,7 +55,7 @@ export async function makeProcessedTx(tx: Tx): Promise<ProcessedTx>;
*/
export async function makeProcessedTx(
tx: Tx,
kernelOutput: KernelCircuitPublicInputs,
kernelOutput: PublicKernelPublicInputs,
proof: Proof,
): Promise<ProcessedTx>;

Expand All @@ -67,18 +67,14 @@ export async function makeProcessedTx(
*/
export async function makeProcessedTx(
tx: Tx,
kernelOutput?: KernelCircuitPublicInputs,
kernelOutput?: PublicKernelPublicInputs,
proof?: Proof,
): Promise<ProcessedTx> {
return {
hash: await tx.getTxHash(),
data:
kernelOutput ??
new KernelCircuitPublicInputs(
CombinedAccumulatedData.fromFinalAccumulatedData(tx.data.end),
tx.data.constants,
tx.data.isPrivate,
),
new PublicKernelPublicInputs(CombinedAccumulatedData.fromFinalAccumulatedData(tx.data.end), tx.data.constants),
proof: proof ?? tx.proof,
encryptedLogs: tx.encryptedLogs,
unencryptedLogs: tx.unencryptedLogs,
Expand All @@ -95,7 +91,7 @@ export function makeEmptyProcessedTx(
chainId: Fr,
version: Fr,
): Promise<ProcessedTx> {
const emptyKernelOutput = KernelCircuitPublicInputs.empty();
const emptyKernelOutput = PublicKernelPublicInputs.empty();
emptyKernelOutput.constants.blockData = historicTreeRoots;
emptyKernelOutput.constants.txContext.chainId = chainId;
emptyKernelOutput.constants.txContext.version = version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import {
FunctionData,
GlobalVariables,
HistoricBlockData,
KernelCircuitPublicInputs,
MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX,
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
PUBLIC_DATA_TREE_HEIGHT,
Proof,
PublicCallRequest,
PublicKernelPublicInputs,
makeEmptyProof,
makeTuple,
} from '@aztec/circuits.js';
import { computeCallStackItemHash } from '@aztec/circuits.js/abis';
import {
makeAztecAddress,
makeKernelPublicInputsFinal,
makePrivateKernelPublicInputsFinal,
makePublicCallRequest,
makeSelector,
} from '@aztec/circuits.js/factories';
Expand Down Expand Up @@ -105,10 +105,9 @@ describe('public_processor', () => {
{
isEmpty: false,
hash,
data: new KernelCircuitPublicInputs(
data: new PublicKernelPublicInputs(
CombinedAccumulatedData.fromFinalAccumulatedData(tx.data.end),
tx.data.constants,
tx.data.isPrivate,
),
proof: tx.proof,
encryptedLogs: tx.encryptedLogs,
Expand Down Expand Up @@ -163,7 +162,7 @@ describe('public_processor', () => {
const callStackItems = await Promise.all(callRequests.map(call => call.toPublicCallStackItem()));
const callStackHashes = callStackItems.map(call => computeCallStackItemHash(wasm, call));

const kernelOutput = makeKernelPublicInputsFinal(0x10);
const kernelOutput = makePrivateKernelPublicInputsFinal(0x10);
kernelOutput.end.publicCallStack = padArrayEnd(callStackHashes, Fr.ZERO, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX);
kernelOutput.end.privateCallStack = padArrayEnd([], Fr.ZERO, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX);

Expand Down Expand Up @@ -193,7 +192,7 @@ describe('public_processor', () => {
const callStackItem = await callRequest.toPublicCallStackItem();
const callStackHash = computeCallStackItemHash(wasm, callStackItem);

const kernelOutput = makeKernelPublicInputsFinal(0x10);
const kernelOutput = makePrivateKernelPublicInputsFinal(0x10);
kernelOutput.end.publicCallStack = padArrayEnd([callStackHash], Fr.ZERO, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX);
kernelOutput.end.privateCallStack = padArrayEnd([], Fr.ZERO, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX);

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/types/src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
Proof,
} from '@aztec/circuits.js';
import { makeKernelPublicInputsFinal, makePublicCallRequest } from '@aztec/circuits.js/factories';
import { makePrivateKernelPublicInputsFinal, makePublicCallRequest } from '@aztec/circuits.js/factories';
import { ContractAbi } from '@aztec/foundation/abi';
import { randomBytes } from '@aztec/foundation/crypto';
import { Tuple } from '@aztec/foundation/serialize';
Expand All @@ -25,7 +25,7 @@ export function makeEmptyLogs(): TxL2Logs {

export const mockTx = (seed = 1) => {
return new Tx(
makeKernelPublicInputsFinal(seed),
makePrivateKernelPublicInputsFinal(seed),
new Proof(Buffer.alloc(0)),
TxL2Logs.random(8, 3), // 8 priv function invocations creating 3 encrypted logs each
TxL2Logs.random(11, 2), // 8 priv + 3 pub function invocations creating 2 unencrypted logs each
Expand Down
10 changes: 5 additions & 5 deletions yarn-project/types/src/tx/tx.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
KernelCircuitPublicInputsFinal,
MAX_NEW_CONTRACTS_PER_TX,
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
PrivateKernelPublicInputsFinal,
Proof,
PublicCallRequest,
} from '@aztec/circuits.js';
Expand All @@ -21,7 +21,7 @@ export class Tx {
/**
* Output of the private kernel circuit for this tx.
*/
public readonly data: KernelCircuitPublicInputsFinal,
public readonly data: PrivateKernelPublicInputsFinal,
/**
* Proof from the private kernel circuit.
*/
Expand Down Expand Up @@ -73,7 +73,7 @@ export class Tx {
static fromBuffer(buffer: Buffer | BufferReader): Tx {
const reader = BufferReader.asReader(buffer);
return new Tx(
reader.readObject(KernelCircuitPublicInputsFinal),
reader.readObject(PrivateKernelPublicInputsFinal),
reader.readObject(Proof),
reader.readObject(TxL2Logs),
reader.readObject(TxL2Logs),
Expand Down Expand Up @@ -118,7 +118,7 @@ export class Tx {
* @returns A Tx class object.
*/
public static fromJSON(obj: any) {
const publicInputs = KernelCircuitPublicInputsFinal.fromBuffer(Buffer.from(obj.data, 'hex'));
const publicInputs = PrivateKernelPublicInputsFinal.fromBuffer(Buffer.from(obj.data, 'hex'));
const encryptedLogs = TxL2Logs.fromBuffer(Buffer.from(obj.encryptedLogs, 'hex'));
const unencryptedLogs = TxL2Logs.fromBuffer(Buffer.from(obj.unencryptedLogs, 'hex'));
const proof = Buffer.from(obj.proof, 'hex');
Expand Down Expand Up @@ -162,7 +162,7 @@ export class Tx {
* @returns The cloned transaction.
*/
static clone(tx: Tx): Tx {
const publicInputs = KernelCircuitPublicInputsFinal.fromBuffer(tx.data.toBuffer());
const publicInputs = PrivateKernelPublicInputsFinal.fromBuffer(tx.data.toBuffer());
const proof = Proof.fromBuffer(tx.proof.toBuffer());
const encryptedLogs = TxL2Logs.fromBuffer(tx.encryptedLogs.toBuffer());
const unencryptedLogs = TxL2Logs.fromBuffer(tx.unencryptedLogs.toBuffer());
Expand Down

0 comments on commit 8d5f548

Please sign in to comment.