From bd6ae99eec052e7de5c55104beb8d0036ec61393 Mon Sep 17 00:00:00 2001 From: dbanks12 Date: Wed, 29 Jan 2025 16:27:17 +0000 Subject: [PATCH] chore: remove old public circuit public inputs --- yarn-project/bb-prover/src/bb/execute.ts | 2 +- yarn-project/bb-prover/src/test/test_avm.ts | 85 ---- .../circuit-types/src/test/factories.ts | 9 +- .../circuit-types/src/tx/processed_tx.ts | 16 +- .../circuits.js/src/structs/avm/avm.ts | 26 +- yarn-project/circuits.js/src/structs/index.ts | 1 - .../structs/public_circuit_public_inputs.ts | 390 ------------------ .../circuits.js/src/tests/factories.ts | 4 +- .../prover-client/src/bin/get-proof-inputs.ts | 2 +- .../prover-client/src/mocks/test_context.ts | 2 +- .../src/orchestrator/tx-proving-state.ts | 2 +- yarn-project/simulator/README.md | 2 +- .../fixtures/public_tx_simulation_tester.ts | 2 +- .../simulator/src/public/public_tx_context.ts | 2 - .../src/public/public_tx_simulator.test.ts | 22 +- yarn-project/txe/src/oracle/txe_oracle.ts | 10 +- 16 files changed, 41 insertions(+), 536 deletions(-) delete mode 100644 yarn-project/bb-prover/src/test/test_avm.ts delete mode 100644 yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts diff --git a/yarn-project/bb-prover/src/bb/execute.ts b/yarn-project/bb-prover/src/bb/execute.ts index 94abcd4535e..0b709c0523b 100644 --- a/yarn-project/bb-prover/src/bb/execute.ts +++ b/yarn-project/bb-prover/src/bb/execute.ts @@ -518,7 +518,7 @@ export async function generateAvmProof( try { // Write the inputs to the working directory. - await fs.writeFile(publicInputsPath, input.output.toBuffer()); + await fs.writeFile(publicInputsPath, input.publicInputs.toBuffer()); if (!filePresent(publicInputsPath)) { return { status: BB_RESULT.FAILURE, reason: `Could not write publicInputs at ${publicInputsPath}` }; } diff --git a/yarn-project/bb-prover/src/test/test_avm.ts b/yarn-project/bb-prover/src/test/test_avm.ts deleted file mode 100644 index 577f724a103..00000000000 --- a/yarn-project/bb-prover/src/test/test_avm.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { - AztecAddress, - BlockHeader, - ContractStorageRead, - ContractStorageUpdateRequest, - Gas, - GlobalVariables, - L2ToL1Message, - MAX_ENQUEUED_CALLS_PER_CALL, - MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL, - MAX_L2_TO_L1_MSGS_PER_CALL, - MAX_NOTE_HASHES_PER_CALL, - MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, - MAX_NULLIFIERS_PER_CALL, - MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, - MAX_NULLIFIER_READ_REQUESTS_PER_CALL, - MAX_PUBLIC_DATA_READS_PER_CALL, - MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, - MAX_PUBLIC_LOGS_PER_CALL, - NoteHash, - Nullifier, - PublicCircuitPublicInputs, - PublicInnerCallRequest, - PublicLog, - ReadRequest, - RevertCode, - TreeLeafReadRequest, -} from '@aztec/circuits.js'; -import { computeVarArgsHash } from '@aztec/circuits.js/hash'; -import { padArrayEnd } from '@aztec/foundation/collection'; -import { type PublicFunctionCallResult } from '@aztec/simulator/server'; - -// TODO: pub somewhere more usable - copied from abstract phase manager -export async function getPublicInputs(result: PublicFunctionCallResult): Promise { - return PublicCircuitPublicInputs.from({ - callContext: result.executionRequest.callContext, - proverAddress: AztecAddress.ZERO, - argsHash: await computeVarArgsHash(result.executionRequest.args), - noteHashes: padArrayEnd(result.noteHashes, NoteHash.empty(), MAX_NOTE_HASHES_PER_CALL), - nullifiers: padArrayEnd(result.nullifiers, Nullifier.empty(), MAX_NULLIFIERS_PER_CALL), - l2ToL1Msgs: padArrayEnd(result.l2ToL1Messages, L2ToL1Message.empty(), MAX_L2_TO_L1_MSGS_PER_CALL), - startSideEffectCounter: result.startSideEffectCounter, - endSideEffectCounter: result.endSideEffectCounter, - returnsHash: await computeVarArgsHash(result.returnValues), - noteHashReadRequests: padArrayEnd( - result.noteHashReadRequests, - TreeLeafReadRequest.empty(), - MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, - ), - nullifierReadRequests: padArrayEnd( - result.nullifierReadRequests, - ReadRequest.empty(), - MAX_NULLIFIER_READ_REQUESTS_PER_CALL, - ), - nullifierNonExistentReadRequests: padArrayEnd( - result.nullifierNonExistentReadRequests, - ReadRequest.empty(), - MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, - ), - l1ToL2MsgReadRequests: padArrayEnd( - result.l1ToL2MsgReadRequests, - TreeLeafReadRequest.empty(), - MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL, - ), - contractStorageReads: padArrayEnd( - result.contractStorageReads, - ContractStorageRead.empty(), - MAX_PUBLIC_DATA_READS_PER_CALL, - ), - contractStorageUpdateRequests: padArrayEnd( - result.contractStorageUpdateRequests, - ContractStorageUpdateRequest.empty(), - MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, - ), - publicCallRequests: padArrayEnd([], PublicInnerCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_CALL), - publicLogs: padArrayEnd(result.publicLogs, PublicLog.empty(), MAX_PUBLIC_LOGS_PER_CALL), - historicalHeader: BlockHeader.empty(), - globalVariables: GlobalVariables.empty(), - startGasLeft: Gas.from(result.startGasLeft), - endGasLeft: Gas.from(result.endGasLeft), - transactionFee: result.transactionFee, - // TODO(@just-mitch): need better mapping from simulator to revert code. - revertCode: result.reverted ? RevertCode.APP_LOGIC_REVERTED : RevertCode.OK, - }); -} diff --git a/yarn-project/circuit-types/src/test/factories.ts b/yarn-project/circuit-types/src/test/factories.ts index 2c71acb7e2a..b39226acc53 100644 --- a/yarn-project/circuit-types/src/test/factories.ts +++ b/yarn-project/circuit-types/src/test/factories.ts @@ -12,7 +12,6 @@ import { GlobalVariables, MAX_NULLIFIERS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, - PublicCircuitPublicInputs, PublicDataWrite, PublicLog, RevertCode, @@ -113,13 +112,7 @@ export async function makeBloatedProcessedTx({ seed + 0x2000, ); - const avmCircuitInputs = new AvmCircuitInputs( - '', - [], - PublicCircuitPublicInputs.empty(), - AvmExecutionHints.empty(), - avmOutput, - ); + const avmCircuitInputs = new AvmCircuitInputs('', [], AvmExecutionHints.empty(), avmOutput); const gasUsed = { totalGas: Gas.empty(), diff --git a/yarn-project/circuit-types/src/tx/processed_tx.ts b/yarn-project/circuit-types/src/tx/processed_tx.ts index 1d471ca0c2b..a94bd841c14 100644 --- a/yarn-project/circuit-types/src/tx/processed_tx.ts +++ b/yarn-project/circuit-types/src/tx/processed_tx.ts @@ -134,11 +134,11 @@ export async function makeProcessedTxFromTxWithPublicCalls( revertCode: RevertCode, revertReason: SimulationError | undefined, ): Promise { - const avmOutput = avmProvingRequest.inputs.output; + const avmPublicInputs = avmProvingRequest.inputs.publicInputs; - const constants = CombinedConstantData.combine(tx.data.constants, avmOutput.globalVariables); + const constants = CombinedConstantData.combine(tx.data.constants, avmPublicInputs.globalVariables); - const publicDataWrites = avmOutput.accumulatedData.publicDataWrites.filter(w => !w.isEmpty()); + const publicDataWrites = avmPublicInputs.accumulatedData.publicDataWrites.filter(w => !w.isEmpty()); const privateLogs = [ ...tx.data.forPublic!.nonRevertibleAccumulatedData.privateLogs, @@ -150,15 +150,15 @@ export async function makeProcessedTxFromTxWithPublicCalls( const txEffect = new TxEffect( revertCode, await tx.getTxHash(), - avmOutput.transactionFee, - avmOutput.accumulatedData.noteHashes.filter(h => !h.isZero()), - avmOutput.accumulatedData.nullifiers.filter(h => !h.isZero()), - avmOutput.accumulatedData.l2ToL1Msgs + avmPublicInputs.transactionFee, + avmPublicInputs.accumulatedData.noteHashes.filter(h => !h.isZero()), + avmPublicInputs.accumulatedData.nullifiers.filter(h => !h.isZero()), + avmPublicInputs.accumulatedData.l2ToL1Msgs .map(message => siloL2ToL1Message(message, constants.txContext.version, constants.txContext.chainId)) .filter(h => !h.isZero()), publicDataWrites, privateLogs, - avmOutput.accumulatedData.publicLogs.filter(l => !l.isEmpty()), + avmPublicInputs.accumulatedData.publicLogs.filter(l => !l.isEmpty()), new Fr(contractClassLogPreimagesLength), tx.contractClassLogs, ); diff --git a/yarn-project/circuits.js/src/structs/avm/avm.ts b/yarn-project/circuits.js/src/structs/avm/avm.ts index 868f587e78b..2728525635b 100644 --- a/yarn-project/circuits.js/src/structs/avm/avm.ts +++ b/yarn-project/circuits.js/src/structs/avm/avm.ts @@ -11,7 +11,6 @@ import { Encoder, addExtension } from 'msgpackr'; import { type ContractClassIdPreimage } from '../../contract/contract_class_id.js'; import { PublicKeys } from '../../types/public_keys.js'; -import { PublicCircuitPublicInputs } from '../public_circuit_public_inputs.js'; import { Vector } from '../shared.js'; import { NullifierLeafPreimage } from '../trees/nullifier_leaf.js'; import { AvmCircuitPublicInputs } from './avm_circuit_public_inputs.js'; @@ -847,9 +846,8 @@ export class AvmCircuitInputs { constructor( public readonly functionName: string, // only informational public readonly calldata: Fr[], - public readonly publicInputs: PublicCircuitPublicInputs, public readonly avmHints: AvmExecutionHints, - public output: AvmCircuitPublicInputs, // This should replace the above `publicInputs` eventually. + public publicInputs: AvmCircuitPublicInputs, // This should replace the above `publicInputs` eventually. ) {} /** @@ -863,9 +861,8 @@ export class AvmCircuitInputs { functionNameBuffer, this.calldata.length, this.calldata, - this.publicInputs.toBuffer(), this.avmHints.toBuffer(), - this.output, + this.publicInputs, ); } @@ -878,13 +875,7 @@ export class AvmCircuitInputs { } static empty(): AvmCircuitInputs { - return new AvmCircuitInputs( - '', - [], - PublicCircuitPublicInputs.empty(), - AvmExecutionHints.empty(), - AvmCircuitPublicInputs.empty(), - ); + return new AvmCircuitInputs('', [], AvmExecutionHints.empty(), AvmCircuitPublicInputs.empty()); } /** @@ -902,7 +893,7 @@ export class AvmCircuitInputs { * @returns An array of fields. */ static getFields(fields: FieldsOf) { - return [fields.functionName, fields.calldata, fields.publicInputs, fields.avmHints, fields.output] as const; + return [fields.functionName, fields.calldata, fields.avmHints, fields.publicInputs] as const; } /** @@ -915,7 +906,6 @@ export class AvmCircuitInputs { return new AvmCircuitInputs( /*functionName=*/ reader.readBuffer().toString(), /*calldata=*/ reader.readVector(Fr), - PublicCircuitPublicInputs.fromBuffer(reader), AvmExecutionHints.fromBuffer(reader), AvmCircuitPublicInputs.fromBuffer(reader), ); @@ -956,10 +946,10 @@ export class AvmCircuitInputs { contractInstances: [] as any[], contractClasses: [] as any[], initialTreeRoots: { - publicDataTree: this.output.startTreeSnapshots.publicDataTree.root, - nullifierTree: this.output.startTreeSnapshots.nullifierTree.root, - noteHashTree: this.output.startTreeSnapshots.noteHashTree.root, - l1ToL2MessageTree: this.output.startTreeSnapshots.l1ToL2MessageTree.root, + publicDataTree: this.publicInputs.startTreeSnapshots.publicDataTree.root, + nullifierTree: this.publicInputs.startTreeSnapshots.nullifierTree.root, + noteHashTree: this.publicInputs.startTreeSnapshots.noteHashTree.root, + l1ToL2MessageTree: this.publicInputs.startTreeSnapshots.l1ToL2MessageTree.root, }, }; const inputs = { diff --git a/yarn-project/circuits.js/src/structs/index.ts b/yarn-project/circuits.js/src/structs/index.ts index 7a727fcff51..64004a2cdb2 100644 --- a/yarn-project/circuits.js/src/structs/index.ts +++ b/yarn-project/circuits.js/src/structs/index.ts @@ -57,7 +57,6 @@ export * from './private_validation_requests.js'; export * from './proof.js'; export * from './public_call_request.js'; export * from './public_call_stack_item_compressed.js'; -export * from './public_circuit_public_inputs.js'; export * from './public_data_hint.js'; export * from './public_data_read.js'; export * from './public_data_update_request.js'; diff --git a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts deleted file mode 100644 index 21105d11047..00000000000 --- a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts +++ /dev/null @@ -1,390 +0,0 @@ -import { makeTuple } from '@aztec/foundation/array'; -import { AztecAddress } from '@aztec/foundation/aztec-address'; -import { Fr } from '@aztec/foundation/fields'; -import { - BufferReader, - FieldReader, - type Tuple, - serializeToBuffer, - serializeToFields, -} from '@aztec/foundation/serialize'; -import { type FieldsOf } from '@aztec/foundation/types'; - -import { inspect } from 'util'; - -import { - MAX_ENQUEUED_CALLS_PER_CALL, - MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL, - MAX_L2_TO_L1_MSGS_PER_CALL, - MAX_NOTE_HASHES_PER_CALL, - MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, - MAX_NULLIFIERS_PER_CALL, - MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, - MAX_NULLIFIER_READ_REQUESTS_PER_CALL, - MAX_PUBLIC_DATA_READS_PER_CALL, - MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, - MAX_PUBLIC_LOGS_PER_CALL, - PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH, -} from '../constants.gen.js'; -import { isEmptyArray } from '../utils/index.js'; -import { BlockHeader } from './block_header.js'; -import { CallContext } from './call_context.js'; -import { ContractStorageRead } from './contract_storage_read.js'; -import { ContractStorageUpdateRequest } from './contract_storage_update_request.js'; -import { Gas } from './gas.js'; -import { GlobalVariables } from './global_variables.js'; -import { L2ToL1Message } from './l2_to_l1_message.js'; -import { NoteHash } from './note_hash.js'; -import { Nullifier } from './nullifier.js'; -import { PublicInnerCallRequest } from './public_inner_call_request.js'; -import { PublicLog } from './public_log.js'; -import { ReadRequest } from './read_request.js'; -import { RevertCode } from './revert_code.js'; -import { TreeLeafReadRequest } from './tree_leaf_read_request.js'; - -// TO BE REMOVED -// This is currently the output of the AVM. It should be replaced by AvmCircuitPublicInputs eventually. -export class PublicCircuitPublicInputs { - constructor( - /** - * Current call context. - */ - public callContext: CallContext, - /** - * Pedersen hash of the arguments of the call. - */ - public argsHash: Fr, - /** - * Pedersen hash of the return values of the call. - */ - public returnsHash: Fr, - /** - * Note Hash tree read requests executed during the call. - */ - public noteHashReadRequests: Tuple, - /** - * Nullifier read requests executed during the call. - */ - public nullifierReadRequests: Tuple, - /** - * Nullifier non existent read requests executed during the call. - */ - public nullifierNonExistentReadRequests: Tuple< - ReadRequest, - typeof MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL - >, - /** - * L1 to L2 Message Read Requests per call. - */ - public l1ToL2MsgReadRequests: Tuple, - /** - * Contract storage update requests executed during the call. - */ - public contractStorageUpdateRequests: Tuple< - ContractStorageUpdateRequest, - typeof MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL - >, - /** - * Contract storage reads executed during the call. - */ - public contractStorageReads: Tuple, - /** - * Public call stack of the current kernel iteration. - */ - public publicCallRequests: Tuple, - /** - * New note hashes created within a public execution call - */ - public noteHashes: Tuple, - /** - * New nullifiers created within a public execution call - */ - public nullifiers: Tuple, - /** - * New L2 to L1 messages generated during the call. - */ - public l2ToL1Msgs: Tuple, - /** - * The side effect counter when this context was started. - */ - public startSideEffectCounter: Fr, - /** - * The side effect counter when this context finished. - */ - public endSideEffectCounter: Fr, - /** - * The public logs emitted in this function call. - */ - public publicLogs: Tuple, - /** - * Header of a block whose state is used during public execution. Set by sequencer to be a header of a block - * previous to the one in which the tx is included. - */ - public historicalHeader: BlockHeader, - /** Global variables for the block. */ - public globalVariables: GlobalVariables, - /** - * Address of the prover. - */ - public proverAddress: AztecAddress, - - /** - * Flag indicating if the call was reverted. - */ - public revertCode: RevertCode, - - /** How much gas was available for execution. */ - public startGasLeft: Gas, - - /** How much gas was left after execution. */ - public endGasLeft: Gas, - - /** Transaction fee in fee juice. Zero in all phases except teardown. */ - public transactionFee: Fr, - ) {} - - /** - * Create PublicCircuitPublicInputs from a fields dictionary. - * @param fields - The dictionary. - * @returns A PublicCircuitPublicInputs object. - */ - static from(fields: FieldsOf): PublicCircuitPublicInputs { - return new PublicCircuitPublicInputs(...PublicCircuitPublicInputs.getFields(fields)); - } - - /** - * Returns an empty instance. - * @returns An empty instance. - */ - public static empty() { - return new PublicCircuitPublicInputs( - CallContext.empty(), - Fr.ZERO, - Fr.ZERO, - makeTuple(MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, TreeLeafReadRequest.empty), - makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, ReadRequest.empty), - makeTuple(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, ReadRequest.empty), - makeTuple(MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL, TreeLeafReadRequest.empty), - makeTuple(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, ContractStorageUpdateRequest.empty), - makeTuple(MAX_PUBLIC_DATA_READS_PER_CALL, ContractStorageRead.empty), - makeTuple(MAX_ENQUEUED_CALLS_PER_CALL, PublicInnerCallRequest.empty), - makeTuple(MAX_NOTE_HASHES_PER_CALL, NoteHash.empty), - makeTuple(MAX_NULLIFIERS_PER_CALL, Nullifier.empty), - makeTuple(MAX_L2_TO_L1_MSGS_PER_CALL, L2ToL1Message.empty), - Fr.ZERO, - Fr.ZERO, - makeTuple(MAX_PUBLIC_LOGS_PER_CALL, PublicLog.empty), - BlockHeader.empty(), - GlobalVariables.empty(), - AztecAddress.ZERO, - RevertCode.OK, - Gas.empty(), - Gas.empty(), - Fr.ZERO, - ); - } - - isEmpty() { - return ( - this.callContext.isEmpty() && - this.argsHash.isZero() && - this.returnsHash.isZero() && - isEmptyArray(this.nullifierReadRequests) && - isEmptyArray(this.nullifierNonExistentReadRequests) && - isEmptyArray(this.l1ToL2MsgReadRequests) && - isEmptyArray(this.contractStorageUpdateRequests) && - isEmptyArray(this.contractStorageReads) && - isEmptyArray(this.publicCallRequests) && - isEmptyArray(this.noteHashes) && - isEmptyArray(this.nullifiers) && - isEmptyArray(this.l2ToL1Msgs) && - this.startSideEffectCounter.isZero() && - this.endSideEffectCounter.isZero() && - isEmptyArray(this.publicLogs) && - this.historicalHeader.isEmpty() && - this.globalVariables.isEmpty() && - this.proverAddress.isZero() && - this.revertCode.isOK() && - this.startGasLeft.isEmpty() && - this.endGasLeft.isEmpty() && - this.transactionFee.isZero() - ); - } - - /** - * Serialize into a field array. Low-level utility. - * @param fields - Object with fields. - * @returns The array. - */ - static getFields(fields: FieldsOf) { - return [ - fields.callContext, - fields.argsHash, - fields.returnsHash, - fields.noteHashReadRequests, - fields.nullifierReadRequests, - fields.nullifierNonExistentReadRequests, - fields.l1ToL2MsgReadRequests, - fields.contractStorageUpdateRequests, - fields.contractStorageReads, - fields.publicCallRequests, - fields.noteHashes, - fields.nullifiers, - fields.l2ToL1Msgs, - fields.startSideEffectCounter, - fields.endSideEffectCounter, - fields.publicLogs, - fields.historicalHeader, - fields.globalVariables, - fields.proverAddress, - fields.revertCode, - fields.startGasLeft, - fields.endGasLeft, - fields.transactionFee, - ] as const; - } - - /** - * Serialize this as a buffer. - * @returns The buffer. - */ - toBuffer(): Buffer { - return serializeToBuffer(...PublicCircuitPublicInputs.getFields(this)); - } - - toFields(): Fr[] { - const fields = serializeToFields(...PublicCircuitPublicInputs.getFields(this)); - if (fields.length !== PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH) { - throw new Error( - `Invalid number of fields for PublicCircuitPublicInputs. Expected ${PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH}, got ${fields.length}`, - ); - } - return fields; - } - - /** - * Deserializes from a buffer or reader. - * @param buffer - Buffer or reader to read from. - * @returns The deserialized instance. - */ - static fromBuffer(buffer: Buffer | BufferReader): PublicCircuitPublicInputs { - const reader = BufferReader.asReader(buffer); - return new PublicCircuitPublicInputs( - reader.readObject(CallContext), - reader.readObject(Fr), - reader.readObject(Fr), - reader.readArray(MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, TreeLeafReadRequest), - reader.readArray(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, ReadRequest), - reader.readArray(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, ReadRequest), - reader.readArray(MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL, TreeLeafReadRequest), - reader.readArray(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, ContractStorageUpdateRequest), - reader.readArray(MAX_PUBLIC_DATA_READS_PER_CALL, ContractStorageRead), - reader.readArray(MAX_ENQUEUED_CALLS_PER_CALL, PublicInnerCallRequest), - reader.readArray(MAX_NOTE_HASHES_PER_CALL, NoteHash), - reader.readArray(MAX_NULLIFIERS_PER_CALL, Nullifier), - reader.readArray(MAX_L2_TO_L1_MSGS_PER_CALL, L2ToL1Message), - reader.readObject(Fr), - reader.readObject(Fr), - reader.readArray(MAX_PUBLIC_LOGS_PER_CALL, PublicLog), - reader.readObject(BlockHeader), - reader.readObject(GlobalVariables), - reader.readObject(AztecAddress), - reader.readObject(RevertCode), - reader.readObject(Gas), - reader.readObject(Gas), - reader.readObject(Fr), - ); - } - - static fromFields(fields: Fr[] | FieldReader): PublicCircuitPublicInputs { - const reader = FieldReader.asReader(fields); - - return new PublicCircuitPublicInputs( - CallContext.fromFields(reader), - reader.readField(), - reader.readField(), - reader.readArray(MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, TreeLeafReadRequest), - reader.readArray(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, ReadRequest), - reader.readArray(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, ReadRequest), - reader.readArray(MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL, TreeLeafReadRequest), - reader.readArray(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, ContractStorageUpdateRequest), - reader.readArray(MAX_PUBLIC_DATA_READS_PER_CALL, ContractStorageRead), - reader.readArray(MAX_ENQUEUED_CALLS_PER_CALL, PublicInnerCallRequest), - reader.readArray(MAX_NOTE_HASHES_PER_CALL, NoteHash), - reader.readArray(MAX_NULLIFIERS_PER_CALL, Nullifier), - reader.readArray(MAX_L2_TO_L1_MSGS_PER_CALL, L2ToL1Message), - reader.readField(), - reader.readField(), - reader.readArray(MAX_PUBLIC_LOGS_PER_CALL, PublicLog), - BlockHeader.fromFields(reader), - GlobalVariables.fromFields(reader), - AztecAddress.fromFields(reader), - RevertCode.fromFields(reader), - Gas.fromFields(reader), - Gas.fromFields(reader), - reader.readField(), - ); - } - - [inspect.custom]() { - return `PublicCircuitPublicInputs { - callContext: ${inspect(this.callContext)}, - argsHash: ${inspect(this.argsHash)}, - returnsHash: ${inspect(this.returnsHash)}, - noteHashReadRequests: [${this.noteHashReadRequests - .filter(x => !x.isEmpty()) - .map(h => inspect(h)) - .join(', ')}]}, - nullifierReadRequests: [${this.nullifierReadRequests - .filter(x => !x.isEmpty()) - .map(h => inspect(h)) - .join(', ')}]}, - nullifierNonExistentReadRequests: [${this.nullifierNonExistentReadRequests - .filter(x => !x.isEmpty()) - .map(h => inspect(h)) - .join(', ')}]}, - l1ToL2MsgReadRequests: [${this.l1ToL2MsgReadRequests - .filter(x => !x.isEmpty()) - .map(h => inspect(h)) - .join(', ')}]}, - contractStorageUpdateRequests: [${this.contractStorageUpdateRequests - .filter(x => !x.isEmpty()) - .map(h => inspect(h)) - .join(', ')}]}, - contractStorageReads: [${this.contractStorageReads - .filter(x => !x.isEmpty()) - .map(h => inspect(h)) - .join(', ')}]}, - publicCallRequests: [${this.publicCallRequests - .filter(x => !x.isEmpty()) - .map(h => inspect(h)) - .join(', ')}]}, - noteHashes: [${this.noteHashes - .filter(x => !x.isEmpty()) - .map(h => inspect(h)) - .join(', ')}]}, - nullifiers: [${this.nullifiers - .filter(x => !x.isEmpty()) - .map(h => inspect(h)) - .join(', ')}]}, - l2ToL1Msgs: [${this.l2ToL1Msgs - .filter(x => !x.isEmpty()) - .map(h => inspect(h)) - .join(', ')}]}, - startSideEffectCounter: ${inspect(this.startSideEffectCounter)}, - endSideEffectCounter: ${inspect(this.endSideEffectCounter)}, - startSideEffectCounter: ${inspect(this.startSideEffectCounter)}, - publicLogs: [${this.publicLogs - .filter(x => !x.isEmpty()) - .map(h => inspect(h)) - .join(', ')}]}, - historicalHeader: ${inspect(this.historicalHeader)}, - globalVariables: ${inspect(this.globalVariables)}, - proverAddress: ${inspect(this.proverAddress)}, - revertCode: ${inspect(this.revertCode)}, - startGasLeft: ${inspect(this.startGasLeft)}, - endGasLeft: ${inspect(this.endGasLeft)}, - transactionFee: ${inspect(this.transactionFee)}, - }`; - } -} diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index bfb4bd5aa86..1d0cc54296e 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -83,7 +83,6 @@ import { PrivateToRollupAccumulatedData, Proof, PublicCallRequest, - PublicCircuitPublicInputs, PublicDataHint, PublicDataRead, PublicDataTreeLeaf, @@ -1501,9 +1500,8 @@ export async function makeAvmCircuitInputs( return AvmCircuitInputs.from({ functionName: `function${seed}`, calldata: makeArray((seed % 100) + 10, i => new Fr(i), seed + 0x1000), - publicInputs: PublicCircuitPublicInputs.empty(), avmHints: await makeAvmExecutionHints(seed + 0x3000), - output: makeAvmCircuitPublicInputs(seed + 0x4000), + publicInputs: makeAvmCircuitPublicInputs(seed + 0x4000), ...overrides, }); } diff --git a/yarn-project/prover-client/src/bin/get-proof-inputs.ts b/yarn-project/prover-client/src/bin/get-proof-inputs.ts index 37225c6fd9e..d5c194f2ba2 100644 --- a/yarn-project/prover-client/src/bin/get-proof-inputs.ts +++ b/yarn-project/prover-client/src/bin/get-proof-inputs.ts @@ -42,7 +42,7 @@ async function main() { function writeProofInputs(input: ProvingJobInputs, outDir: string) { switch (input.type) { case ProvingRequestType.PUBLIC_VM: { - writeFileSync(`${outDir}/${AVM_PUBLIC_INPUTS_FILENAME}`, input.inputs.output.toBuffer()); + writeFileSync(`${outDir}/${AVM_PUBLIC_INPUTS_FILENAME}`, input.inputs.publicInputs.toBuffer()); logger.info(`Wrote AVM public inputs to ${AVM_PUBLIC_INPUTS_FILENAME}`); writeFileSync(`${outDir}/${AVM_HINTS_FILENAME}`, input.inputs.avmHints.toBuffer()); logger.info(`Wrote AVM hints to ${AVM_HINTS_FILENAME}`); diff --git a/yarn-project/prover-client/src/mocks/test_context.ts b/yarn-project/prover-client/src/mocks/test_context.ts index 1b5224e2dc8..8a02c64e6be 100644 --- a/yarn-project/prover-client/src/mocks/test_context.ts +++ b/yarn-project/prover-client/src/mocks/test_context.ts @@ -232,7 +232,7 @@ export class TestContext { await updateExpectedTreesFromTxs(db, [tx]); const stateReference = await db.getStateReference(); if (tx.avmProvingRequest) { - tx.avmProvingRequest.inputs.output.endTreeSnapshots = new TreeSnapshots( + tx.avmProvingRequest.inputs.publicInputs.endTreeSnapshots = new TreeSnapshots( stateReference.l1ToL2MessageTree, stateReference.partial.noteHashTree, stateReference.partial.nullifierTree, diff --git a/yarn-project/prover-client/src/orchestrator/tx-proving-state.ts b/yarn-project/prover-client/src/orchestrator/tx-proving-state.ts index 2e5f00b7909..11f96c9569f 100644 --- a/yarn-project/prover-client/src/orchestrator/tx-proving-state.ts +++ b/yarn-project/prover-client/src/orchestrator/tx-proving-state.ts @@ -110,7 +110,7 @@ export class TxProvingState { ); const avmProofData = new AvmProofData( - this.processedTx.avmProvingRequest.inputs.output, + this.processedTx.avmProvingRequest.inputs.publicInputs, this.avm.proof, await this.#getAvmVkData(), ); diff --git a/yarn-project/simulator/README.md b/yarn-project/simulator/README.md index ec524980fc8..c6ae5029af6 100644 --- a/yarn-project/simulator/README.md +++ b/yarn-project/simulator/README.md @@ -22,7 +22,7 @@ Private functions can call another private function, and can request to call a p Public functions are simulated and proved on the sequencer side, and verified by the public kernel circuit. -The public inputs of public functions is defined [here](../circuits.js/src/structs/public_circuit_public_inputs.ts). +The public inputs of public functions is defined [here](../circuits.js/src/structs/avm_circuit_public_inputs.ts). They are run with the assistance of an oracle that provides any value read from the public state tree. diff --git a/yarn-project/simulator/src/public/fixtures/public_tx_simulation_tester.ts b/yarn-project/simulator/src/public/fixtures/public_tx_simulation_tester.ts index a35e62a0e4f..d6c30e8158d 100644 --- a/yarn-project/simulator/src/public/fixtures/public_tx_simulation_tester.ts +++ b/yarn-project/simulator/src/public/fixtures/public_tx_simulation_tester.ts @@ -122,7 +122,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester { const avmResult = await simulator.simulate(tx); if (avmResult.revertCode.isOK()) { - await this.commitTxStateUpdates(avmResult.avmProvingRequest.inputs.output); + await this.commitTxStateUpdates(avmResult.avmProvingRequest.inputs.publicInputs); } return avmResult; diff --git a/yarn-project/simulator/src/public/public_tx_context.ts b/yarn-project/simulator/src/public/public_tx_context.ts index 101b65fcbf4..2db16a4e6ca 100644 --- a/yarn-project/simulator/src/public/public_tx_context.ts +++ b/yarn-project/simulator/src/public/public_tx_context.ts @@ -22,7 +22,6 @@ import { MAX_NULLIFIERS_PER_TX, type PrivateToPublicAccumulatedData, type PublicCallRequest, - PublicCircuitPublicInputs, RevertCode, type StateReference, TreeSnapshots, @@ -380,7 +379,6 @@ export class PublicTxContext { inputs: new AvmCircuitInputs( 'public_dispatch', [], - PublicCircuitPublicInputs.empty(), hints, await this.generateAvmCircuitPublicInputs(endStateReference), ), diff --git a/yarn-project/simulator/src/public/public_tx_simulator.test.ts b/yarn-project/simulator/src/public/public_tx_simulator.test.ts index bdf18d83fcb..829deb020dc 100644 --- a/yarn-project/simulator/src/public/public_tx_simulator.test.ts +++ b/yarn-project/simulator/src/public/public_tx_simulator.test.ts @@ -163,7 +163,7 @@ describe('public_tx_simulator', () => { }; const checkNullifierRoot = async (txResult: PublicTxResult) => { - const siloedNullifiers = txResult.avmProvingRequest.inputs.output.accumulatedData.nullifiers; + const siloedNullifiers = txResult.avmProvingRequest.inputs.publicInputs.accumulatedData.nullifiers; // Loop helpful for debugging so you can see root progression //for (const nullifier of siloedNullifiers) { // await db.batchInsert( @@ -180,7 +180,7 @@ describe('public_tx_simulator', () => { NULLIFIER_SUBTREE_HEIGHT, ); const expectedRoot = (await db.getStateReference()).partial.nullifierTree.root; - const gotRoot = txResult.avmProvingRequest.inputs.output.endTreeSnapshots.nullifierTree.root; + const gotRoot = txResult.avmProvingRequest.inputs.publicInputs.endTreeSnapshots.nullifierTree.root; expect(gotRoot).toEqual(expectedRoot); }; @@ -299,7 +299,7 @@ describe('public_tx_simulator', () => { const availableGasForSecondSetup = availableGasForFirstSetup.sub(enqueuedCallGasUsed); expectAvailableGasForCalls([availableGasForFirstSetup, availableGasForSecondSetup]); - const output = txResult.avmProvingRequest!.inputs.output; + const output = txResult.avmProvingRequest!.inputs.publicInputs; const expectedGasUsedForFee = expectedTotalGas; const expectedTxFee = expectedTotalGas.computeFee(gasFees); @@ -335,7 +335,7 @@ describe('public_tx_simulator', () => { const availableGasForSecondAppLogic = availableGasForFirstAppLogic.sub(enqueuedCallGasUsed); expectAvailableGasForCalls([availableGasForFirstAppLogic, availableGasForSecondAppLogic]); - const output = txResult.avmProvingRequest!.inputs.output; + const output = txResult.avmProvingRequest!.inputs.publicInputs; const expectedGasUsedForFee = expectedTotalGas; const expectedTxFee = expectedTotalGas.computeFee(gasFees); @@ -369,7 +369,7 @@ describe('public_tx_simulator', () => { expectAvailableGasForCalls([teardownGasLimits]); - const output = txResult.avmProvingRequest!.inputs.output; + const output = txResult.avmProvingRequest!.inputs.publicInputs; const expectedGasUsedForFee = expectedTotalGas.sub(expectedTeardownGasUsed).add(teardownGasLimits); const expectedTxFee = expectedGasUsedForFee.computeFee(gasFees); @@ -418,7 +418,7 @@ describe('public_tx_simulator', () => { teardownGasLimits, ]); - const output = txResult.avmProvingRequest!.inputs.output; + const output = txResult.avmProvingRequest!.inputs.publicInputs; const expectedGasUsedForFee = expectedTotalGas.sub(expectedTeardownGasUsed).add(teardownGasLimits); const expectedTxFee = expectedGasUsedForFee.computeFee(gasFees); @@ -470,7 +470,7 @@ describe('public_tx_simulator', () => { expect(simulateInternal).toHaveBeenCalledTimes(3); - const output = txResult.avmProvingRequest!.inputs.output; + const output = txResult.avmProvingRequest!.inputs.publicInputs; const numPublicDataWrites = 3; expect(countAccumulatedItems(output.accumulatedData.publicDataWrites)).toBe(numPublicDataWrites); @@ -567,7 +567,7 @@ describe('public_tx_simulator', () => { teardownGasLimits, ]); - const output = txResult.avmProvingRequest!.inputs.output; + const output = txResult.avmProvingRequest!.inputs.publicInputs; const expectedGasUsedForFee = expectedTotalGas.sub(expectedTeardownGasUsed).add(teardownGasLimits); const expectedTxFee = expectedGasUsedForFee.computeFee(gasFees); @@ -649,7 +649,7 @@ describe('public_tx_simulator', () => { teardownGasLimits, ]); - const output = txResult.avmProvingRequest!.inputs.output; + const output = txResult.avmProvingRequest!.inputs.publicInputs; // Should still charge the full teardownGasLimits for fee even though teardown reverted. const expectedGasUsedForFee = expectedTotalGas.sub(expectedTeardownGasUsed).add(teardownGasLimits); @@ -733,7 +733,7 @@ describe('public_tx_simulator', () => { teardownGasLimits, ]); - const output = txResult.avmProvingRequest!.inputs.output; + const output = txResult.avmProvingRequest!.inputs.publicInputs; // Should still charge the full teardownGasLimits for fee even though teardown reverted. const expectedGasUsedForFee = expectedTotalGas.sub(expectedTeardownGasUsed).add(teardownGasLimits); @@ -811,7 +811,7 @@ describe('public_tx_simulator', () => { publicGas: expectedPublicGasUsed.add(expectedTeardownGasUsed), }); - const output = txResult.avmProvingRequest!.inputs.output; + const output = txResult.avmProvingRequest!.inputs.publicInputs; const expectedGasUsedForFee = expectedTotalGas.sub(expectedTeardownGasUsed).add(teardownGasLimits); expect(output.endGasUsed).toEqual(expectedGasUsedForFee); diff --git a/yarn-project/txe/src/oracle/txe_oracle.ts b/yarn-project/txe/src/oracle/txe_oracle.ts index 0391ce68d11..ec9cd0ee7c7 100644 --- a/yarn-project/txe/src/oracle/txe_oracle.ts +++ b/yarn-project/txe/src/oracle/txe_oracle.ts @@ -847,12 +847,14 @@ export class TXE implements TypedOracle { ); const result = await simulator.simulate(tx); - const noteHashes = result.avmProvingRequest.inputs.output.accumulatedData.noteHashes.filter(s => !s.isEmpty()); + const noteHashes = result.avmProvingRequest.inputs.publicInputs.accumulatedData.noteHashes.filter( + s => !s.isEmpty(), + ); await this.addUniqueNoteHashesFromPublic(noteHashes); this.addPublicLogs( - result.avmProvingRequest.inputs.output.accumulatedData.publicLogs.filter( + result.avmProvingRequest.inputs.publicInputs.accumulatedData.publicLogs.filter( log => !log.contractAddress.equals(AztecAddress.ZERO), ), ); @@ -904,7 +906,7 @@ export class TXE implements TypedOracle { } // Apply side effects - const sideEffects = executionResult.avmProvingRequest.inputs.output.accumulatedData; + const sideEffects = executionResult.avmProvingRequest.inputs.publicInputs.accumulatedData; const publicDataWrites = sideEffects.publicDataWrites.filter(s => !s.isEmpty()); const noteHashes = sideEffects.noteHashes.filter(s => !s.isEmpty()); @@ -1022,7 +1024,7 @@ export class TXE implements TypedOracle { // Apply side effects if (executionResult.revertCode.isOK()) { - const sideEffects = executionResult.avmProvingRequest.inputs.output.accumulatedData; + const sideEffects = executionResult.avmProvingRequest.inputs.publicInputs.accumulatedData; const publicDataWrites = sideEffects.publicDataWrites.filter(s => !s.isEmpty()); const noteHashes = sideEffects.noteHashes.filter(s => !s.isEmpty()); const { usedTxRequestHashForNonces } = this.noteCache.finish();