From 5d6d22ca416c6471428b56a55968e859334caa6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bene=C5=A1?= Date: Tue, 7 May 2024 11:40:14 +0200 Subject: [PATCH] feat: always including debug data in a function artifact (#6223) --- yarn-project/foundation/src/abi/abi.ts | 38 +++---------------- .../pxe/src/simulator_oracle/index.ts | 11 ++---- .../simulator/src/client/db_oracle.ts | 12 ++---- .../src/client/private_execution.test.ts | 10 +---- .../simulator/src/client/private_execution.ts | 4 +- .../simulator/src/client/simulator.test.ts | 10 ++--- .../simulator/src/client/simulator.ts | 8 ++-- .../src/client/unconstrained_execution.ts | 4 +- 8 files changed, 26 insertions(+), 71 deletions(-) diff --git a/yarn-project/foundation/src/abi/abi.ts b/yarn-project/foundation/src/abi/abi.ts index 3dbe2dc7036..ff1be9bcdd7 100644 --- a/yarn-project/foundation/src/abi/abi.ts +++ b/yarn-project/foundation/src/abi/abi.ts @@ -183,18 +183,14 @@ export interface FunctionAbi { * The artifact entry of a function. */ export interface FunctionArtifact extends FunctionAbi { - /** - * The ACIR bytecode of the function. - */ + /** The ACIR bytecode of the function. */ bytecode: Buffer; - /** - * The verification key of the function. - */ + /** The verification key of the function. */ verificationKey?: string; - /** - * Maps opcodes to source code pointers - */ + /** Maps opcodes to source code pointers */ debugSymbols: string; + /** Debug metadata for the function. */ + debug?: FunctionDebugMetadata; } /** @@ -350,14 +346,8 @@ export interface FunctionDebugMetadata { files: DebugFileMap; } -/** A function artifact with optional debug metadata */ -export interface FunctionArtifactWithDebugMetadata extends FunctionArtifact { - /** Debug metadata for the function. */ - debug?: FunctionDebugMetadata; -} - /** - * Gets a function artifact given its name or selector. + * Gets a function artifact including debug metadata given its name or selector. */ export function getFunctionArtifact( artifact: ContractArtifact, @@ -371,22 +361,6 @@ export function getFunctionArtifact( if (!functionArtifact) { throw new Error(`Unknown function ${functionNameOrSelector}`); } - return functionArtifact; -} - -/** @deprecated Use getFunctionArtifact instead */ -export function getFunctionArtifactWithSelector(artifact: ContractArtifact, selector: FunctionSelector) { - return getFunctionArtifact(artifact, selector); -} - -/** - * Gets a function artifact including debug metadata given its name or selector. - */ -export function getFunctionArtifactWithDebugMetadata( - artifact: ContractArtifact, - functionNameOrSelector: string | FunctionSelector, -): FunctionArtifactWithDebugMetadata { - const functionArtifact = getFunctionArtifact(artifact, functionNameOrSelector); const debugMetadata = getFunctionDebugMetadata(artifact, functionArtifact); return { ...functionArtifact, debug: debugMetadata }; } diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index 0a81cc5b1d6..12e540148b7 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -18,7 +18,7 @@ import { type Point, } from '@aztec/circuits.js'; import { computeL1ToL2MessageNullifier } from '@aztec/circuits.js/hash'; -import { type FunctionArtifactWithDebugMetadata, getFunctionArtifactWithDebugMetadata } from '@aztec/foundation/abi'; +import { type FunctionArtifact, getFunctionArtifact } from '@aztec/foundation/abi'; import { createDebugLogger } from '@aztec/foundation/log'; import { type DBOracle, MessageLoadOracleInputs, type NullifierKeys } from '@aztec/simulator'; import { type ContractInstance } from '@aztec/types/contracts'; @@ -107,10 +107,7 @@ export class SimulatorOracle implements DBOracle { })); } - async getFunctionArtifact( - contractAddress: AztecAddress, - selector: FunctionSelector, - ): Promise { + async getFunctionArtifact(contractAddress: AztecAddress, selector: FunctionSelector): Promise { const artifact = await this.contractDataOracle.getFunctionArtifact(contractAddress, selector); const debug = await this.contractDataOracle.getFunctionDebugMetadata(contractAddress, selector); return { @@ -122,10 +119,10 @@ export class SimulatorOracle implements DBOracle { async getFunctionArtifactByName( contractAddress: AztecAddress, functionName: string, - ): Promise { + ): Promise { const instance = await this.contractDataOracle.getContractInstance(contractAddress); const artifact = await this.contractDataOracle.getContractArtifact(instance.contractClassId); - return artifact && getFunctionArtifactWithDebugMetadata(artifact, functionName); + return artifact && getFunctionArtifact(artifact, functionName); } /** diff --git a/yarn-project/simulator/src/client/db_oracle.ts b/yarn-project/simulator/src/client/db_oracle.ts index eb545df6e11..a7e78619eb1 100644 --- a/yarn-project/simulator/src/client/db_oracle.ts +++ b/yarn-project/simulator/src/client/db_oracle.ts @@ -6,7 +6,7 @@ import { type PublicDataWitness, } from '@aztec/circuit-types'; import { type CompleteAddress, type Header } from '@aztec/circuits.js'; -import { type FunctionArtifactWithDebugMetadata, type FunctionSelector } from '@aztec/foundation/abi'; +import { type FunctionArtifact, type FunctionSelector } from '@aztec/foundation/abi'; import { type AztecAddress } from '@aztec/foundation/aztec-address'; import { type Fr, type Point } from '@aztec/foundation/fields'; import { type ContractInstance } from '@aztec/types/contracts'; @@ -102,10 +102,7 @@ export interface DBOracle extends CommitmentsDB { * @param selector - The corresponding function selector. * @returns A Promise that resolves to a FunctionArtifact object. */ - getFunctionArtifact( - contractAddress: AztecAddress, - selector: FunctionSelector, - ): Promise; + getFunctionArtifact(contractAddress: AztecAddress, selector: FunctionSelector): Promise; /** * Retrieves the artifact of a specified function within a given contract. @@ -115,10 +112,7 @@ export interface DBOracle extends CommitmentsDB { * @param functionName - The name of the function. * @returns The corresponding function's artifact as an object. */ - getFunctionArtifactByName( - contractAddress: AztecAddress, - functionName: string, - ): Promise; + getFunctionArtifactByName(contractAddress: AztecAddress, functionName: string): Promise; /** * Gets the index of a nullifier in the nullifier tree. diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index f82a4c265c8..3b93537e10c 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -29,13 +29,7 @@ import { } from '@aztec/circuits.js'; import { computeCommitmentNonce, computeSecretHash, computeVarArgsHash } from '@aztec/circuits.js/hash'; import { makeHeader } from '@aztec/circuits.js/testing'; -import { - type FunctionArtifact, - FunctionSelector, - encodeArguments, - getFunctionArtifact, - getFunctionArtifactWithSelector, -} from '@aztec/foundation/abi'; +import { type FunctionArtifact, FunctionSelector, encodeArguments, getFunctionArtifact } from '@aztec/foundation/abi'; import { asyncMap } from '@aztec/foundation/async-map'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { times } from '@aztec/foundation/collection'; @@ -871,7 +865,7 @@ describe('Private Execution test suite', () => { beforeEach(() => { oracle.getFunctionArtifact.mockImplementation((_, selector) => - Promise.resolve(getFunctionArtifactWithSelector(PendingNoteHashesContractArtifact, selector)), + Promise.resolve(getFunctionArtifact(PendingNoteHashesContractArtifact, selector)), ); oracle.getFunctionArtifactByName.mockImplementation((_, functionName: string) => Promise.resolve(getFunctionArtifact(PendingNoteHashesContractArtifact, functionName)), diff --git a/yarn-project/simulator/src/client/private_execution.ts b/yarn-project/simulator/src/client/private_execution.ts index 737d5820548..b787aa24544 100644 --- a/yarn-project/simulator/src/client/private_execution.ts +++ b/yarn-project/simulator/src/client/private_execution.ts @@ -1,5 +1,5 @@ import { type FunctionData, PrivateCallStackItem, PrivateCircuitPublicInputs } from '@aztec/circuits.js'; -import { type FunctionArtifactWithDebugMetadata } from '@aztec/foundation/abi'; +import { type FunctionArtifact } from '@aztec/foundation/abi'; import { type AztecAddress } from '@aztec/foundation/aztec-address'; import { createDebugLogger } from '@aztec/foundation/log'; @@ -15,7 +15,7 @@ import { AcirSimulator } from './simulator.js'; */ export async function executePrivateFunction( context: ClientExecutionContext, - artifact: FunctionArtifactWithDebugMetadata, + artifact: FunctionArtifact, contractAddress: AztecAddress, functionData: FunctionData, log = createDebugLogger('aztec:simulator:secret_execution'), diff --git a/yarn-project/simulator/src/client/simulator.test.ts b/yarn-project/simulator/src/client/simulator.test.ts index ef9fd366291..24211b5f35a 100644 --- a/yarn-project/simulator/src/client/simulator.test.ts +++ b/yarn-project/simulator/src/client/simulator.test.ts @@ -6,11 +6,7 @@ import { computeUniqueNoteHash, siloNoteHash, } from '@aztec/circuits.js/hash'; -import { - ABIParameterVisibility, - type FunctionArtifactWithDebugMetadata, - getFunctionArtifact, -} from '@aztec/foundation/abi'; +import { ABIParameterVisibility, type FunctionArtifact, getFunctionArtifact } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { poseidon2Hash } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; @@ -100,7 +96,7 @@ describe('Simulator', () => { it('throw if "compute_note_hash_and_nullifier" has the wrong number of parameters', async () => { const note = createNote(); - const modifiedArtifact: FunctionArtifactWithDebugMetadata = { + const modifiedArtifact: FunctionArtifact = { ...artifact, parameters: artifact.parameters.slice(1), }; @@ -119,7 +115,7 @@ describe('Simulator', () => { const note = createNote(); const wrongPreimageLength = note.length - 1; - const modifiedArtifact: FunctionArtifactWithDebugMetadata = { + const modifiedArtifact: FunctionArtifact = { ...artifact, parameters: [ ...artifact.parameters.slice(0, -1), diff --git a/yarn-project/simulator/src/client/simulator.ts b/yarn-project/simulator/src/client/simulator.ts index 3afb657a725..1fbb92ad03d 100644 --- a/yarn-project/simulator/src/client/simulator.ts +++ b/yarn-project/simulator/src/client/simulator.ts @@ -2,7 +2,7 @@ import { type AztecNode, type FunctionCall, type Note, type TxExecutionRequest } import { CallContext, FunctionData } from '@aztec/circuits.js'; import { type ArrayType, - type FunctionArtifactWithDebugMetadata, + type FunctionArtifact, FunctionSelector, FunctionType, encodeArguments, @@ -65,7 +65,7 @@ export class AcirSimulator { */ public async run( request: TxExecutionRequest, - entryPointArtifact: FunctionArtifactWithDebugMetadata, + entryPointArtifact: FunctionArtifact, contractAddress: AztecAddress, msgSender = AztecAddress.ZERO, ): Promise { @@ -129,7 +129,7 @@ export class AcirSimulator { */ public async runUnconstrained( request: FunctionCall, - entryPointArtifact: FunctionArtifactWithDebugMetadata, + entryPointArtifact: FunctionArtifact, contractAddress: AztecAddress, ) { if (entryPointArtifact.functionType !== FunctionType.UNCONSTRAINED) { @@ -167,7 +167,7 @@ export class AcirSimulator { noteTypeId: Fr, note: Note, ) { - const artifact: FunctionArtifactWithDebugMetadata | undefined = await this.db.getFunctionArtifactByName( + const artifact: FunctionArtifact | undefined = await this.db.getFunctionArtifactByName( contractAddress, 'compute_note_hash_and_nullifier', ); diff --git a/yarn-project/simulator/src/client/unconstrained_execution.ts b/yarn-project/simulator/src/client/unconstrained_execution.ts index d821ca9fea9..9b42a556009 100644 --- a/yarn-project/simulator/src/client/unconstrained_execution.ts +++ b/yarn-project/simulator/src/client/unconstrained_execution.ts @@ -1,5 +1,5 @@ import { type FunctionData } from '@aztec/circuits.js'; -import { type DecodedReturn, type FunctionArtifactWithDebugMetadata, decodeReturnValues } from '@aztec/foundation/abi'; +import { type DecodedReturn, type FunctionArtifact, decodeReturnValues } from '@aztec/foundation/abi'; import { type AztecAddress } from '@aztec/foundation/aztec-address'; import { type Fr } from '@aztec/foundation/fields'; import { createDebugLogger } from '@aztec/foundation/log'; @@ -16,7 +16,7 @@ import { type ViewDataOracle } from './view_data_oracle.js'; */ export async function executeUnconstrainedFunction( oracle: ViewDataOracle, - artifact: FunctionArtifactWithDebugMetadata, + artifact: FunctionArtifact, contractAddress: AztecAddress, functionData: FunctionData, args: Fr[],