From 8d5f548e42d627da1685820f99fc28ff5f47abbe Mon Sep 17 00:00:00 2001 From: Jean M <132435771+jeanmon@users.noreply.github.com> Date: Thu, 31 Aug 2023 15:52:03 +0200 Subject: [PATCH] chore(1879): add use of PrivateKernelPublicInputs in TS whenever relevant (#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). --- .../aztec-rpc/src/kernel_prover/kernel_prover.ts | 4 ++-- .../aztec-rpc/src/kernel_prover/proof_creator.ts | 4 ++++ .../circuits.js/src/structs/kernel/index.test.ts | 4 ++-- .../src/structs/kernel/public_inputs.ts | 8 ++++++++ yarn-project/circuits.js/src/tests/factories.ts | 6 +++--- .../src/block_builder/solo_block_builder.test.ts | 4 ++-- .../src/sequencer/processed_tx.ts | 16 ++++++---------- .../src/sequencer/public_processor.test.ts | 11 +++++------ yarn-project/types/src/mocks.ts | 4 ++-- yarn-project/types/src/tx/tx.ts | 10 +++++----- 10 files changed, 39 insertions(+), 32 deletions(-) diff --git a/yarn-project/aztec-rpc/src/kernel_prover/kernel_prover.ts b/yarn-project/aztec-rpc/src/kernel_prover/kernel_prover.ts index 8791f403328..687c1a21aed 100644 --- a/yarn-project/aztec-rpc/src/kernel_prover/kernel_prover.ts +++ b/yarn-project/aztec-rpc/src/kernel_prover/kernel_prover.ts @@ -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, @@ -78,7 +78,7 @@ export class KernelProver { let previousVerificationKey = VerificationKey.makeFake(); let output: ProofOutput = { - publicInputs: KernelCircuitPublicInputs.empty(), + publicInputs: PrivateKernelPublicInputs.empty(), proof: makeEmptyProof(), }; diff --git a/yarn-project/aztec-rpc/src/kernel_prover/proof_creator.ts b/yarn-project/aztec-rpc/src/kernel_prover/proof_creator.ts index 1fc7712f33d..c0feff5f4d9 100644 --- a/yarn-project/aztec-rpc/src/kernel_prover/proof_creator.ts +++ b/yarn-project/aztec-rpc/src/kernel_prover/proof_creator.ts @@ -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; /** @@ -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; /** diff --git a/yarn-project/circuits.js/src/structs/kernel/index.test.ts b/yarn-project/circuits.js/src/structs/kernel/index.test.ts index 23d14a579b9..efc97550c87 100644 --- a/yarn-project/circuits.js/src/structs/kernel/index.test.ts +++ b/yarn-project/circuits.js/src/structs/kernel/index.test.ts @@ -3,10 +3,10 @@ import { makeAccumulatedData, makeFinalAccumulatedData, makeKernelPublicInputs, - makeKernelPublicInputsFinal, makePreviousKernelData, makePrivateKernelInputsInit, makePrivateKernelInputsInner, + makePrivateKernelPublicInputsFinal, makePublicKernelInputs, makeSchnorrSignature, } from '../../tests/factories.js'; @@ -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', diff --git a/yarn-project/circuits.js/src/structs/kernel/public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/public_inputs.ts index a31ac642faa..7c0ef83f164 100644 --- a/yarn-project/circuits.js/src/structs/kernel/public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/public_inputs.ts @@ -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()); + } } /** @@ -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()); + } } diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index e21871d2d8a..17a3a72340f 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -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, @@ -68,6 +67,7 @@ import { PrivateCircuitPublicInputs, PrivateKernelInputsInit, PrivateKernelInputsInner, + PrivateKernelPublicInputsFinal, Proof, PublicCallData, PublicCallRequest, @@ -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)); } /** diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts index 27d3653512c..5d88bb50bd9 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts @@ -22,8 +22,8 @@ import { computeBlockHashWithGlobals, computeContractLeaf } from '@aztec/circuit import { fr, makeBaseOrMergeRollupPublicInputs, - makeKernelPublicInputsFinal, makeNewContractData, + makePrivateKernelPublicInputsFinal, makeProof, makePublicCallRequest, makeRootRollupPublicInputs, @@ -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( diff --git a/yarn-project/sequencer-client/src/sequencer/processed_tx.ts b/yarn-project/sequencer-client/src/sequencer/processed_tx.ts index c4b4a93ed8d..c66eb8adb3e 100644 --- a/yarn-project/sequencer-client/src/sequencer/processed_tx.ts +++ b/yarn-project/sequencer-client/src/sequencer/processed_tx.ts @@ -2,8 +2,8 @@ import { CombinedAccumulatedData, Fr, HistoricBlockData, - KernelCircuitPublicInputs, Proof, + PublicKernelPublicInputs, makeEmptyProof, } from '@aztec/circuits.js'; import { Tx, TxHash, TxL2Logs } from '@aztec/types'; @@ -16,7 +16,7 @@ export type ProcessedTx = Pick; */ export async function makeProcessedTx( tx: Tx, - kernelOutput: KernelCircuitPublicInputs, + kernelOutput: PublicKernelPublicInputs, proof: Proof, ): Promise; @@ -67,18 +67,14 @@ export async function makeProcessedTx( */ export async function makeProcessedTx( tx: Tx, - kernelOutput?: KernelCircuitPublicInputs, + kernelOutput?: PublicKernelPublicInputs, proof?: Proof, ): Promise { 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, @@ -95,7 +91,7 @@ export function makeEmptyProcessedTx( chainId: Fr, version: Fr, ): Promise { - const emptyKernelOutput = KernelCircuitPublicInputs.empty(); + const emptyKernelOutput = PublicKernelPublicInputs.empty(); emptyKernelOutput.constants.blockData = historicTreeRoots; emptyKernelOutput.constants.txContext.chainId = chainId; emptyKernelOutput.constants.txContext.version = version; diff --git a/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts b/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts index efd21627ab2..56b59e72687 100644 --- a/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts @@ -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'; @@ -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, @@ -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); @@ -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); diff --git a/yarn-project/types/src/mocks.ts b/yarn-project/types/src/mocks.ts index a3b52f5ad77..f98dee06d6c 100644 --- a/yarn-project/types/src/mocks.ts +++ b/yarn-project/types/src/mocks.ts @@ -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'; @@ -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 diff --git a/yarn-project/types/src/tx/tx.ts b/yarn-project/types/src/tx/tx.ts index 0a47fbe56f7..7000165d8ea 100644 --- a/yarn-project/types/src/tx/tx.ts +++ b/yarn-project/types/src/tx/tx.ts @@ -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'; @@ -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. */ @@ -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), @@ -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'); @@ -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());