diff --git a/yarn-project/archiver/package.json b/yarn-project/archiver/package.json index 1eff7e25ea0..40f0a179937 100644 --- a/yarn-project/archiver/package.json +++ b/yarn-project/archiver/package.json @@ -67,6 +67,7 @@ "ws": "^8.13.0" }, "devDependencies": { + "@aztec/noir-contracts.js": "workspace:^", "@jest/globals": "^29.5.0", "@types/debug": "^4.1.7", "@types/jest": "^29.5.0", diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index ad0f1a9eda8..9face3a26ae 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -22,6 +22,7 @@ import { isValidUnconstrainedFunctionMembershipProof, } from '@aztec/circuits.js/contract'; import { createEthereumChain } from '@aztec/ethereum'; +import { type ContractArtifact } from '@aztec/foundation/abi'; import { type AztecAddress } from '@aztec/foundation/aztec-address'; import { type EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; @@ -489,4 +490,12 @@ export class Archiver implements ArchiveSource { getContractClassIds(): Promise { return this.store.getContractClassIds(); } + + addContractArtifact(address: AztecAddress, artifact: ContractArtifact): Promise { + return this.store.addContractArtifact(address, artifact); + } + + getContractArtifact(address: AztecAddress): Promise { + return this.store.getContractArtifact(address); + } } diff --git a/yarn-project/archiver/src/archiver/archiver_store.ts b/yarn-project/archiver/src/archiver/archiver_store.ts index a018f8163f1..9b397b6fa42 100644 --- a/yarn-project/archiver/src/archiver/archiver_store.ts +++ b/yarn-project/archiver/src/archiver/archiver_store.ts @@ -15,6 +15,7 @@ import { type UnencryptedL2BlockL2Logs, } from '@aztec/circuit-types'; import { type Fr } from '@aztec/circuits.js'; +import { type ContractArtifact } from '@aztec/foundation/abi'; import { type AztecAddress } from '@aztec/foundation/aztec-address'; import { type ContractClassPublic, @@ -191,4 +192,7 @@ export interface ArchiverDataStore { /** Returns the list of all class ids known by the archiver. */ getContractClassIds(): Promise; + + addContractArtifact(address: AztecAddress, contract: ContractArtifact): Promise; + getContractArtifact(address: AztecAddress): Promise; } diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/contract_artifacts_store.test.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/contract_artifacts_store.test.ts new file mode 100644 index 00000000000..0735866154a --- /dev/null +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/contract_artifacts_store.test.ts @@ -0,0 +1,22 @@ +import { AztecAddress } from '@aztec/circuits.js'; +import { openTmpStore } from '@aztec/kv-store/utils'; +import { BenchmarkingContractArtifact } from '@aztec/noir-contracts.js/Benchmarking'; + +import { beforeEach } from '@jest/globals'; + +import { KVArchiverDataStore } from './kv_archiver_store.js'; + +describe('Contract Artifact Store', () => { + let archiverStore: KVArchiverDataStore; + + beforeEach(() => { + archiverStore = new KVArchiverDataStore(openTmpStore()); + }); + + it('Should add and return contract artifacts', async () => { + const artifact = BenchmarkingContractArtifact; + const address = AztecAddress.random(); + await archiverStore.addContractArtifact(address, artifact); + await expect(archiverStore.getContractArtifact(address)).resolves.toEqual(artifact); + }); +}); diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/contract_artifacts_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/contract_artifacts_store.ts new file mode 100644 index 00000000000..8e18df413f2 --- /dev/null +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/contract_artifacts_store.ts @@ -0,0 +1,22 @@ +import { type AztecAddress } from '@aztec/circuits.js'; +import { type ContractArtifact } from '@aztec/foundation/abi'; +import { type AztecKVStore, type AztecMap } from '@aztec/kv-store'; +import { contractArtifactFromBuffer, contractArtifactToBuffer } from '@aztec/types/abi'; + +export class ContractArtifactsStore { + #contractArtifacts: AztecMap; + + constructor(db: AztecKVStore) { + this.#contractArtifacts = db.openMap('archiver_contract_artifacts'); + } + + addContractArtifact(address: AztecAddress, contractArtifact: ContractArtifact): Promise { + return this.#contractArtifacts.set(address.toString(), contractArtifactToBuffer(contractArtifact)); + } + + getContractArtifact(address: AztecAddress): ContractArtifact | undefined { + const contractArtifact = this.#contractArtifacts.get(address.toString()); + // TODO(@spalladino): AztecMap lies and returns Uint8Arrays instead of Buffers, hence the extra Buffer.from. + return contractArtifact && contractArtifactFromBuffer(Buffer.from(contractArtifact)); + } +} diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts index 9cd32ee024c..ec8c98e5523 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts @@ -15,6 +15,7 @@ import { type UnencryptedL2BlockL2Logs, } from '@aztec/circuit-types'; import { type Fr } from '@aztec/circuits.js'; +import { type ContractArtifact } from '@aztec/foundation/abi'; import { type AztecAddress } from '@aztec/foundation/aztec-address'; import { createDebugLogger } from '@aztec/foundation/log'; import { type AztecKVStore } from '@aztec/kv-store'; @@ -29,6 +30,7 @@ import { type ArchiverDataStore, type ArchiverL1SynchPoint } from '../archiver_s import { type DataRetrieval } from '../data_retrieval.js'; import { BlockBodyStore } from './block_body_store.js'; import { BlockStore } from './block_store.js'; +import { ContractArtifactsStore } from './contract_artifacts_store.js'; import { ContractClassStore } from './contract_class_store.js'; import { ContractInstanceStore } from './contract_instance_store.js'; import { LogStore } from './log_store.js'; @@ -44,6 +46,7 @@ export class KVArchiverDataStore implements ArchiverDataStore { #messageStore: MessageStore; #contractClassStore: ContractClassStore; #contractInstanceStore: ContractInstanceStore; + #contractArtifactStore: ContractArtifactsStore; #log = createDebugLogger('aztec:archiver:data-store'); @@ -54,6 +57,15 @@ export class KVArchiverDataStore implements ArchiverDataStore { this.#messageStore = new MessageStore(db); this.#contractClassStore = new ContractClassStore(db); this.#contractInstanceStore = new ContractInstanceStore(db); + this.#contractArtifactStore = new ContractArtifactsStore(db); + } + + getContractArtifact(address: AztecAddress): Promise { + return Promise.resolve(this.#contractArtifactStore.getContractArtifact(address)); + } + + addContractArtifact(address: AztecAddress, contract: ContractArtifact): Promise { + return this.#contractArtifactStore.addContractArtifact(address, contract); } getContractClass(id: Fr): Promise { diff --git a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts index d4abada9c0d..eb483b552cf 100644 --- a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts +++ b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts @@ -17,6 +17,7 @@ import { type UnencryptedL2BlockL2Logs, } from '@aztec/circuit-types'; import { Fr, INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js'; +import { type ContractArtifact } from '@aztec/foundation/abi'; import { type AztecAddress } from '@aztec/foundation/aztec-address'; import { type ContractClassPublic, @@ -71,6 +72,8 @@ export class MemoryArchiverStore implements ArchiverDataStore { */ private l1ToL2Messages = new L1ToL2MessageStore(); + private contractArtifacts: Map = new Map(); + private contractClasses: Map = new Map(); private privateFunctions: Map = new Map(); @@ -438,4 +441,13 @@ export class MemoryArchiverStore implements ArchiverDataStore { messagesSynchedTo: this.lastL1BlockNewMessages, }); } + + public addContractArtifact(address: AztecAddress, contract: ContractArtifact): Promise { + this.contractArtifacts.set(address.toString(), contract); + return Promise.resolve(); + } + + public getContractArtifact(address: AztecAddress): Promise { + return Promise.resolve(this.contractArtifacts.get(address.toString())); + } } diff --git a/yarn-project/archiver/tsconfig.json b/yarn-project/archiver/tsconfig.json index 08c5ba86b06..ea0bb3a5469 100644 --- a/yarn-project/archiver/tsconfig.json +++ b/yarn-project/archiver/tsconfig.json @@ -29,6 +29,9 @@ }, { "path": "../types" + }, + { + "path": "../noir-contracts.js" } ], "include": ["src"] diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 78c48fd7a35..a08167fbe1a 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -45,6 +45,7 @@ import { } from '@aztec/circuits.js'; import { computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash'; import { type L1ContractAddresses, createEthereumChain } from '@aztec/ethereum'; +import { type ContractArtifact } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { createDebugLogger } from '@aztec/foundation/log'; import { type AztecKVStore } from '@aztec/kv-store'; @@ -764,6 +765,10 @@ export class AztecNodeService implements AztecNode { }); } + public addContractArtifact(address: AztecAddress, artifact: ContractArtifact): Promise { + return this.contractDataSource.addContractArtifact(address, artifact); + } + /** * Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched * @param blockNumber - The block number at which to get the data. diff --git a/yarn-project/aztec-node/tsconfig.json b/yarn-project/aztec-node/tsconfig.json index e4e9d2d50fc..f023c003bff 100644 --- a/yarn-project/aztec-node/tsconfig.json +++ b/yarn-project/aztec-node/tsconfig.json @@ -36,6 +36,9 @@ { "path": "../p2p" }, + { + "path": "../protocol-contracts" + }, { "path": "../prover-client" }, @@ -50,9 +53,6 @@ }, { "path": "../world-state" - }, - { - "path": "../protocol-contracts" } ], "include": ["src"] diff --git a/yarn-project/bb-prover/src/prover/bb_prover.ts b/yarn-project/bb-prover/src/prover/bb_prover.ts index 1e59d9636da..5870bfb13e2 100644 --- a/yarn-project/bb-prover/src/prover/bb_prover.ts +++ b/yarn-project/bb-prover/src/prover/bb_prover.ts @@ -4,7 +4,6 @@ import { type PublicInputsAndRecursiveProof, type PublicKernelNonTailRequest, type PublicKernelTailRequest, - PublicKernelType, type ServerCircuitProver, makePublicInputsAndRecursiveProof, } from '@aztec/circuit-types'; @@ -181,7 +180,7 @@ export class BBNativeRollupProver implements ServerCircuitProver { ): Promise> { const kernelOps = PublicKernelArtifactMapping[kernelRequest.type]; if (kernelOps === undefined) { - throw new Error(`Unable to prove kernel type ${PublicKernelType[kernelRequest.type]}`); + throw new Error(`Unable to prove kernel type ${kernelRequest.type}`); } // We may need to convert the recursive proof into fields format diff --git a/yarn-project/bb-prover/src/test/test_circuit_prover.ts b/yarn-project/bb-prover/src/test/test_circuit_prover.ts index d05e4407df9..c4c24794e8f 100644 --- a/yarn-project/bb-prover/src/test/test_circuit_prover.ts +++ b/yarn-project/bb-prover/src/test/test_circuit_prover.ts @@ -3,7 +3,6 @@ import { type PublicInputsAndRecursiveProof, type PublicKernelNonTailRequest, type PublicKernelTailRequest, - PublicKernelType, type ServerCircuitProver, makePublicInputsAndRecursiveProof, } from '@aztec/circuit-types'; @@ -265,7 +264,7 @@ export class TestCircuitProver implements ServerCircuitProver { const timer = new Timer(); const kernelOps = SimulatedPublicKernelArtifactMapping[kernelRequest.type]; if (kernelOps === undefined) { - throw new Error(`Unable to prove for kernel type ${PublicKernelType[kernelRequest.type]}`); + throw new Error(`Unable to prove for kernel type ${kernelRequest.type}`); } const witnessMap = kernelOps.convertInputs(kernelRequest.inputs); diff --git a/yarn-project/circuit-types/src/index.ts b/yarn-project/circuit-types/src/index.ts index 7a0b84d677c..43672170f4d 100644 --- a/yarn-project/circuit-types/src/index.ts +++ b/yarn-project/circuit-types/src/index.ts @@ -1,22 +1,22 @@ +export { CompleteAddress, GrumpkinPrivateKey, type PartialAddress, type PublicKey } from '@aztec/circuits.js'; +export * from './auth_witness.js'; +export * from './aztec_node/rpc/index.js'; +export * from './body.js'; export * from './function_call.js'; -export * from './notes/index.js'; -export * from './messaging/index.js'; +export * from './interfaces/index.js'; export * from './l2_block.js'; -export * from './body.js'; export * from './l2_block_downloader/index.js'; export * from './l2_block_source.js'; -export * from './public_data_witness.js'; -export * from './tx_effect.js'; export * from './logs/index.js'; export * from './merkle_tree_id.js'; +export * from './messaging/index.js'; export * from './mocks.js'; +export * from './notes/index.js'; +export * from './packed_values.js'; +export * from './public_data_witness.js'; export * from './public_data_write.js'; -export * from './simulation_error.js'; export * from './sibling_path/index.js'; +export * from './simulation_error.js'; export * from './tx/index.js'; +export * from './tx_effect.js'; export * from './tx_execution_request.js'; -export * from './packed_values.js'; -export * from './interfaces/index.js'; -export * from './auth_witness.js'; -export * from './aztec_node/rpc/index.js'; -export { CompleteAddress, type PublicKey, type PartialAddress, GrumpkinPrivateKey } from '@aztec/circuits.js'; diff --git a/yarn-project/circuit-types/src/interfaces/aztec-node.ts b/yarn-project/circuit-types/src/interfaces/aztec-node.ts index 36f93f63d08..0890b0c6904 100644 --- a/yarn-project/circuit-types/src/interfaces/aztec-node.ts +++ b/yarn-project/circuit-types/src/interfaces/aztec-node.ts @@ -7,6 +7,7 @@ import { type PUBLIC_DATA_TREE_HEIGHT, } from '@aztec/circuits.js'; import { type L1ContractAddresses } from '@aztec/ethereum'; +import { type ContractArtifact } from '@aztec/foundation/abi'; import { type AztecAddress } from '@aztec/foundation/aztec-address'; import { type Fr } from '@aztec/foundation/fields'; import { @@ -218,6 +219,13 @@ export interface AztecNode { */ getProtocolContractAddresses(): Promise; + /** + * Method to add a contract artifact to the database. + * @param aztecAddress + * @param artifact + */ + addContractArtifact(address: AztecAddress, artifact: ContractArtifact): Promise; + /** * Gets up to `limit` amount of logs starting from `from`. * @param from - Number of the L2 block to which corresponds the first logs to be returned. diff --git a/yarn-project/circuit-types/src/stats/metrics.ts b/yarn-project/circuit-types/src/stats/metrics.ts index 58fb1c1aca0..83f26969ea1 100644 --- a/yarn-project/circuit-types/src/stats/metrics.ts +++ b/yarn-project/circuit-types/src/stats/metrics.ts @@ -25,6 +25,18 @@ export interface Metric { /** Metric definitions to track from benchmarks. */ export const Metrics = [ + { + name: 'public_db_access_time_ms', + groupBy: 'chain-length', + description: 'Time to access a database.', + events: ['public-db-access'], + }, + { + name: 'avm_simulation_time_ms', + groupBy: 'app-circuit-name', + description: 'Time to simulate an AVM circuit.', + events: ['avm-simulation'], + }, { name: 'proof_construction_time_sha256_ms', groupBy: 'threads', diff --git a/yarn-project/circuit-types/src/stats/stats.ts b/yarn-project/circuit-types/src/stats/stats.ts index ca403a47d44..66d5b48f4eb 100644 --- a/yarn-project/circuit-types/src/stats/stats.ts +++ b/yarn-project/circuit-types/src/stats/stats.ts @@ -99,6 +99,21 @@ export type CircuitSimulationStats = { outputSize: number; }; +export type PublicDBAccessStats = { + eventName: 'public-db-access'; + duration: number; + operation: string; +}; + +export type AvmSimulationStats = { + /** name of the event. */ + eventName: 'avm-simulation'; + /** Name of the circuit. */ + appCircuitName: string; + /** Duration in ms. */ + duration: number; +}; + /** Stats for witness generation. */ export type CircuitWitnessGenerationStats = { /** name of the event. */ @@ -247,17 +262,19 @@ export type TxAddedToPoolStats = { /** Stats emitted in structured logs with an `eventName` for tracking. */ export type Stats = - | ProofConstructed - | L1PublishStats - | NodeSyncedChainHistoryStats - | CircuitSimulationStats + | AvmSimulationStats | CircuitProvingStats + | CircuitSimulationStats | CircuitWitnessGenerationStats + | PublicDBAccessStats + | L1PublishStats | L2BlockBuiltStats | L2BlockHandledStats + | NodeSyncedChainHistoryStats | NoteProcessorCaughtUpStats - | TxAddedToPoolStats - | TreeInsertionStats; + | ProofConstructed + | TreeInsertionStats + | TxAddedToPoolStats; /** Set of event names across emitted stats. */ export type StatsEventName = Stats['eventName']; diff --git a/yarn-project/circuit-types/src/tx/index.ts b/yarn-project/circuit-types/src/tx/index.ts index 0f134780c26..fe213cb0ec7 100644 --- a/yarn-project/circuit-types/src/tx/index.ts +++ b/yarn-project/circuit-types/src/tx/index.ts @@ -1,8 +1,8 @@ -export * from './tx.js'; +export * from './processed_tx.js'; +export * from './public_simulation_output.js'; export * from './simulated_tx.js'; +export * from './tx.js'; export * from './tx_hash.js'; export * from './tx_receipt.js'; -export * from './processed_tx.js'; -export * from './public_simulation_output.js'; -export * from './validator/tx_validator.js'; export * from './validator/aggregate_tx_validator.js'; +export * from './validator/tx_validator.js'; diff --git a/yarn-project/circuit-types/src/tx/processed_tx.ts b/yarn-project/circuit-types/src/tx/processed_tx.ts index fd14e21cea7..130cc4a6a6d 100644 --- a/yarn-project/circuit-types/src/tx/processed_tx.ts +++ b/yarn-project/circuit-types/src/tx/processed_tx.ts @@ -31,11 +31,11 @@ import { * Used to communicate to the prover which type of circuit to prove */ export enum PublicKernelType { - NON_PUBLIC, - SETUP, - APP_LOGIC, - TEARDOWN, - TAIL, + NON_PUBLIC = 'non-public', + SETUP = 'setup', + APP_LOGIC = 'app-logic', + TEARDOWN = 'teardown', + TAIL = 'tail', } export type PublicKernelTailRequest = { diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 0ae85c24293..cf329063fbd 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -258,6 +258,7 @@ export class PXEService implements PXE { ); } await this.db.addContractArtifact(contractClassId, artifact); + await this.node.addContractArtifact(instance.address, artifact); } else { // Otherwise, make sure there is an artifact already registered for that class id artifact = await this.db.getContractArtifact(instance.contractClassId); diff --git a/yarn-project/scripts/src/benchmarks/aggregate.ts b/yarn-project/scripts/src/benchmarks/aggregate.ts index e11a1d60d44..42a5b8d0d62 100644 --- a/yarn-project/scripts/src/benchmarks/aggregate.ts +++ b/yarn-project/scripts/src/benchmarks/aggregate.ts @@ -9,6 +9,7 @@ // And then run this script from the yarn-project/scripts folder // LOG_FOLDER=../end-to-end/log yarn bench-aggregate import { + type AvmSimulationStats, BENCHMARK_BLOCK_SIZES, BENCHMARK_HISTORY_BLOCK_SIZE, BENCHMARK_HISTORY_CHAIN_LENGTHS, @@ -25,6 +26,7 @@ import { type NodeSyncedChainHistoryStats, type NoteProcessorCaughtUpStats, type ProofConstructed, + type PublicDBAccessStats, type Stats, type TreeInsertionStats, type TxAddedToPoolStats, @@ -149,6 +151,14 @@ function processCircuitProving(entry: CircuitProvingStats, results: BenchmarkCol } } +function processAvmSimulation(entry: AvmSimulationStats, results: BenchmarkCollectedResults) { + append(results, 'avm_simulation_time_ms', entry.appCircuitName, entry.duration); +} + +function processDbAccess(entry: PublicDBAccessStats, results: BenchmarkCollectedResults) { + append(results, 'public_db_access_time_ms', entry.operation, entry.duration); +} + /** * Processes an entry with event name 'circuit-proving' and updates results * Buckets are circuit names @@ -258,6 +268,10 @@ function processEntry(entry: Stats, results: BenchmarkCollectedResults) { return processTxAddedToPool(entry, results); case 'tree-insertion': return processTreeInsertion(entry, results); + case 'avm-simulation': + return processAvmSimulation(entry, results); + case 'public-db-access': + return processDbAccess(entry, results); default: return; } diff --git a/yarn-project/scripts/src/benchmarks/markdown.ts b/yarn-project/scripts/src/benchmarks/markdown.ts index c915506b31b..5c7d55390d2 100644 --- a/yarn-project/scripts/src/benchmarks/markdown.ts +++ b/yarn-project/scripts/src/benchmarks/markdown.ts @@ -186,9 +186,13 @@ export function getMarkdown(prNumber: number) { const metricsByThreads = Metrics.filter(m => m.groupBy === 'threads').map(m => m.name); const metricsByBlockSize = Metrics.filter(m => m.groupBy === 'block-size').map(m => m.name); - const metricsByChainLength = Metrics.filter(m => m.groupBy === 'chain-length').map(m => m.name); + const metricsByChainLength = Metrics.filter(m => m.groupBy === 'chain-length') + .filter(m => m.name !== 'public_db_access_time_ms') + .map(m => m.name); const kernelCircuitMetrics = Metrics.filter(m => m.groupBy === 'protocol-circuit-name').map(m => m.name); - const appCircuitMetrics = Metrics.filter(m => m.groupBy === 'app-circuit-name').map(m => m.name); + const appCircuitMetrics = Metrics.filter(m => m.groupBy === 'app-circuit-name') + .filter(m => m.name !== 'avm_simulation_time_ms') + .map(m => m.name); const metricsByClassesRegistered = Metrics.filter(m => m.groupBy === 'classes-registered').map(m => m.name); const metricsByFeePaymentMethod = Metrics.filter(m => m.groupBy === 'fee-payment-method').map(m => m.name); const metricsByLeafCount = Metrics.filter(m => m.groupBy === 'leaf-count').map(m => m.name); @@ -252,6 +256,28 @@ ${getTableContent( 'app_circuit_', )} +### AVM Simulation + +Time to simulate various public functions in the AVM. +${getTableContent( + transpose(pick(benchmark, ['avm_simulation_time_ms'])), + transpose(baseBenchmark), + '', + 'Function', + 'avm_simulation_', +)} + +### Public DB Access + +Time to access various public DBs. +${getTableContent( + transpose(pick(benchmark, ['public_db_access_time_ms'])), + transpose(baseBenchmark), + '', + 'Function', + 'public_db_access_', +)} + ### Tree insertion stats The duration to insert a fixed batch of leaves into each tree type. diff --git a/yarn-project/sequencer-client/src/tx_validator/gas_validator.ts b/yarn-project/sequencer-client/src/tx_validator/gas_validator.ts index 2fbf9975058..e1b47f09539 100644 --- a/yarn-project/sequencer-client/src/tx_validator/gas_validator.ts +++ b/yarn-project/sequencer-client/src/tx_validator/gas_validator.ts @@ -1,8 +1,8 @@ -import { type Tx, type TxValidator } from '@aztec/circuit-types'; +import { PublicKernelType, type Tx, type TxValidator } from '@aztec/circuit-types'; import { type AztecAddress, type Fr } from '@aztec/circuits.js'; import { createDebugLogger } from '@aztec/foundation/log'; import { GasTokenArtifact } from '@aztec/protocol-contracts/gas-token'; -import { AbstractPhaseManager, PublicKernelPhase, computeFeePayerBalanceStorageSlot } from '@aztec/simulator'; +import { AbstractPhaseManager, computeFeePayerBalanceStorageSlot } from '@aztec/simulator'; /** Provides a view into public contract state */ export interface PublicStateSource { @@ -55,7 +55,7 @@ export class GasTxValidator implements TxValidator { ); // If there is a claim in this tx that increases the fee payer balance in gas token, add it to balance - const { [PublicKernelPhase.SETUP]: setupFns } = AbstractPhaseManager.extractEnqueuedPublicCallsByPhase(tx); + const { [PublicKernelType.SETUP]: setupFns } = AbstractPhaseManager.extractEnqueuedPublicCallsByPhase(tx); const claimFunctionCall = setupFns.find( fn => fn.contractAddress.equals(this.#gasTokenAddress) && diff --git a/yarn-project/sequencer-client/src/tx_validator/phases_validator.ts b/yarn-project/sequencer-client/src/tx_validator/phases_validator.ts index 3451ca9b1fd..87a8a6c7520 100644 --- a/yarn-project/sequencer-client/src/tx_validator/phases_validator.ts +++ b/yarn-project/sequencer-client/src/tx_validator/phases_validator.ts @@ -1,7 +1,7 @@ -import { type AllowedFunction, Tx, type TxValidator } from '@aztec/circuit-types'; +import { type AllowedFunction, PublicKernelType, Tx, type TxValidator } from '@aztec/circuit-types'; import { type PublicCallRequest } from '@aztec/circuits.js'; import { createDebugLogger } from '@aztec/foundation/log'; -import { AbstractPhaseManager, ContractsDataSourcePublicDB, PublicKernelPhase } from '@aztec/simulator'; +import { AbstractPhaseManager, ContractsDataSourcePublicDB } from '@aztec/simulator'; import { type ContractDataSource } from '@aztec/types/contracts'; export class PhasesTxValidator implements TxValidator { @@ -40,7 +40,7 @@ export class PhasesTxValidator implements TxValidator { return true; } - const { [PublicKernelPhase.SETUP]: setupFns } = AbstractPhaseManager.extractEnqueuedPublicCallsByPhase(tx); + const { [PublicKernelType.SETUP]: setupFns } = AbstractPhaseManager.extractEnqueuedPublicCallsByPhase(tx); for (const setupFn of setupFns) { if (!(await this.isOnAllowList(setupFn, this.setupAllowList))) { diff --git a/yarn-project/simulator/src/public/abstract_phase_manager.ts b/yarn-project/simulator/src/public/abstract_phase_manager.ts index 9f9214f0d9b..c8471d742ec 100644 --- a/yarn-project/simulator/src/public/abstract_phase_manager.ts +++ b/yarn-project/simulator/src/public/abstract_phase_manager.ts @@ -69,34 +69,14 @@ import { HintsBuilder } from './hints_builder.js'; import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js'; import { lastSideEffectCounter } from './utils.js'; -export enum PublicKernelPhase { - SETUP = 'setup', - APP_LOGIC = 'app-logic', - TEARDOWN = 'teardown', - TAIL = 'tail', -} - -export const PhaseIsRevertible: Record = { - [PublicKernelPhase.SETUP]: false, - [PublicKernelPhase.APP_LOGIC]: true, - [PublicKernelPhase.TEARDOWN]: true, - [PublicKernelPhase.TAIL]: false, +export const PhaseIsRevertible: Record = { + [PublicKernelType.NON_PUBLIC]: false, + [PublicKernelType.SETUP]: false, + [PublicKernelType.APP_LOGIC]: true, + [PublicKernelType.TEARDOWN]: true, + [PublicKernelType.TAIL]: false, }; -// REFACTOR: Unify both enums and move to types or circuit-types. -export function publicKernelPhaseToKernelType(phase: PublicKernelPhase): PublicKernelType { - switch (phase) { - case PublicKernelPhase.SETUP: - return PublicKernelType.SETUP; - case PublicKernelPhase.APP_LOGIC: - return PublicKernelType.APP_LOGIC; - case PublicKernelPhase.TEARDOWN: - return PublicKernelType.TEARDOWN; - case PublicKernelPhase.TAIL: - return PublicKernelType.TAIL; - } -} - export type PublicProvingInformation = { calldata: Fr[]; bytecode: Buffer; @@ -159,7 +139,7 @@ export abstract class AbstractPhaseManager { protected publicKernel: PublicKernelCircuitSimulator, protected globalVariables: GlobalVariables, protected historicalHeader: Header, - public phase: PublicKernelPhase, + public phase: PublicKernelType, ) { this.hintsBuilder = new HintsBuilder(db); this.log = createDebugLogger(`aztec:sequencer:${phase}`); @@ -171,14 +151,15 @@ export abstract class AbstractPhaseManager { */ abstract handle(tx: Tx, publicKernelPublicInputs: PublicKernelCircuitPublicInputs): Promise; - public static extractEnqueuedPublicCallsByPhase(tx: Tx): Record { + public static extractEnqueuedPublicCallsByPhase(tx: Tx): Record { const data = tx.data.forPublic; if (!data) { return { - [PublicKernelPhase.SETUP]: [], - [PublicKernelPhase.APP_LOGIC]: [], - [PublicKernelPhase.TEARDOWN]: [], - [PublicKernelPhase.TAIL]: [], + [PublicKernelType.NON_PUBLIC]: [], + [PublicKernelType.SETUP]: [], + [PublicKernelType.APP_LOGIC]: [], + [PublicKernelType.TEARDOWN]: [], + [PublicKernelType.TAIL]: [], }; } const publicCallsStack = tx.enqueuedPublicFunctionCalls.slice().reverse(); @@ -196,10 +177,11 @@ export abstract class AbstractPhaseManager { if (callRequestsStack.length === 0) { return { - [PublicKernelPhase.SETUP]: [], - [PublicKernelPhase.APP_LOGIC]: [], - [PublicKernelPhase.TEARDOWN]: [], - [PublicKernelPhase.TAIL]: [], + [PublicKernelType.NON_PUBLIC]: [], + [PublicKernelType.SETUP]: [], + [PublicKernelType.APP_LOGIC]: [], + [PublicKernelType.TEARDOWN]: [], + [PublicKernelType.TAIL]: [], }; } @@ -212,25 +194,28 @@ export abstract class AbstractPhaseManager { if (firstRevertibleCallIndex === 0) { return { - [PublicKernelPhase.SETUP]: [], - [PublicKernelPhase.APP_LOGIC]: publicCallsStack, - [PublicKernelPhase.TEARDOWN]: teardownCallStack, - [PublicKernelPhase.TAIL]: [], + [PublicKernelType.NON_PUBLIC]: [], + [PublicKernelType.SETUP]: [], + [PublicKernelType.APP_LOGIC]: publicCallsStack, + [PublicKernelType.TEARDOWN]: teardownCallStack, + [PublicKernelType.TAIL]: [], }; } else if (firstRevertibleCallIndex === -1) { // there's no app logic, split the functions between setup (many) and teardown (just one function call) return { - [PublicKernelPhase.SETUP]: publicCallsStack, - [PublicKernelPhase.APP_LOGIC]: [], - [PublicKernelPhase.TEARDOWN]: teardownCallStack, - [PublicKernelPhase.TAIL]: [], + [PublicKernelType.NON_PUBLIC]: [], + [PublicKernelType.SETUP]: publicCallsStack, + [PublicKernelType.APP_LOGIC]: [], + [PublicKernelType.TEARDOWN]: teardownCallStack, + [PublicKernelType.TAIL]: [], }; } else { return { - [PublicKernelPhase.SETUP]: publicCallsStack.slice(0, firstRevertibleCallIndex), - [PublicKernelPhase.APP_LOGIC]: publicCallsStack.slice(firstRevertibleCallIndex), - [PublicKernelPhase.TEARDOWN]: teardownCallStack, - [PublicKernelPhase.TAIL]: [], + [PublicKernelType.NON_PUBLIC]: [], + [PublicKernelType.SETUP]: publicCallsStack.slice(0, firstRevertibleCallIndex), + [PublicKernelType.APP_LOGIC]: publicCallsStack.slice(firstRevertibleCallIndex), + [PublicKernelType.TEARDOWN]: teardownCallStack, + [PublicKernelType.TAIL]: [], }; } } @@ -407,11 +392,11 @@ export abstract class AbstractPhaseManager { // We take a deep copy (clone) of these inputs to be passed to the prover const inputs = new PublicKernelCircuitPrivateInputs(previousKernel, callData); switch (this.phase) { - case PublicKernelPhase.SETUP: + case PublicKernelType.SETUP: return [inputs.clone(), await this.publicKernel.publicKernelCircuitSetup(inputs)]; - case PublicKernelPhase.APP_LOGIC: + case PublicKernelType.APP_LOGIC: return [inputs.clone(), await this.publicKernel.publicKernelCircuitAppLogic(inputs)]; - case PublicKernelPhase.TEARDOWN: + case PublicKernelType.TEARDOWN: return [inputs.clone(), await this.publicKernel.publicKernelCircuitTeardown(inputs)]; default: throw new Error(`No public kernel circuit for inputs`); diff --git a/yarn-project/simulator/src/public/app_logic_phase_manager.ts b/yarn-project/simulator/src/public/app_logic_phase_manager.ts index 692e0970c5e..bf25c580cdb 100644 --- a/yarn-project/simulator/src/public/app_logic_phase_manager.ts +++ b/yarn-project/simulator/src/public/app_logic_phase_manager.ts @@ -3,7 +3,7 @@ import { type GlobalVariables, type Header, type PublicKernelCircuitPublicInputs import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator'; import { type MerkleTreeOperations } from '@aztec/world-state'; -import { AbstractPhaseManager, PublicKernelPhase, makeAvmProvingRequest } from './abstract_phase_manager.js'; +import { AbstractPhaseManager, makeAvmProvingRequest } from './abstract_phase_manager.js'; import { type ContractsDataSourcePublicDB } from './public_db_sources.js'; import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js'; @@ -19,7 +19,7 @@ export class AppLogicPhaseManager extends AbstractPhaseManager { historicalHeader: Header, protected publicContractsDB: ContractsDataSourcePublicDB, protected publicStateDB: PublicStateDB, - phase: PublicKernelPhase = PublicKernelPhase.APP_LOGIC, + phase: PublicKernelType = PublicKernelType.APP_LOGIC, ) { super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase); } diff --git a/yarn-project/simulator/src/public/db_interfaces.ts b/yarn-project/simulator/src/public/db_interfaces.ts index d1c38e9927e..ca44044de82 100644 --- a/yarn-project/simulator/src/public/db_interfaces.ts +++ b/yarn-project/simulator/src/public/db_interfaces.ts @@ -67,6 +67,8 @@ export interface PublicContractsDB { * @returns The contract instance or undefined if not found. */ getContractInstance(address: AztecAddress): Promise; + + getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise; } /** Database interface for providing access to commitment tree, l1 to l2 message tree, and nullifier tree. */ diff --git a/yarn-project/simulator/src/public/executor.ts b/yarn-project/simulator/src/public/executor.ts index 387b6f49d58..2bf1e11d085 100644 --- a/yarn-project/simulator/src/public/executor.ts +++ b/yarn-project/simulator/src/public/executor.ts @@ -1,5 +1,7 @@ +import { type AvmSimulationStats } from '@aztec/circuit-types/stats'; import { Fr, type Gas, type GlobalVariables, type Header, type Nullifier, type TxContext } from '@aztec/circuits.js'; import { createDebugLogger } from '@aztec/foundation/log'; +import { Timer } from '@aztec/foundation/timer'; import { AvmContext } from '../avm/avm_context.js'; import { AvmMachineState } from '../avm/avm_machine_state.js'; @@ -41,8 +43,10 @@ export class PublicExecutor { const address = execution.contractAddress; const selector = execution.functionSelector; const startGas = availableGas; + const fnName = await this.contractsDb.getDebugFunctionName(address, selector); - PublicExecutor.log.verbose(`[AVM] Executing public external function ${address.toString()}:${selector}.`); + PublicExecutor.log.verbose(`[AVM] Executing public external function ${fnName}.`); + const timer = new Timer(); // Temporary code to construct the AVM context // These data structures will permeate across the simulator when the public executor is phased out @@ -75,9 +79,12 @@ export class PublicExecutor { await avmContext.persistableState.publicStorage.commitToDB(); PublicExecutor.log.verbose( - `[AVM] ${address.toString()}:${selector} returned, reverted: ${avmResult.reverted}, reason: ${ - avmResult.revertReason - }.`, + `[AVM] ${fnName} returned, reverted: ${avmResult.reverted}, reason: ${avmResult.revertReason}.`, + { + eventName: 'avm-simulation', + appCircuitName: fnName ?? 'unknown', + duration: timer.ms(), + } satisfies AvmSimulationStats, ); const executionResult = convertAvmResultsToPxResult( diff --git a/yarn-project/simulator/src/public/index.ts b/yarn-project/simulator/src/public/index.ts index 6b2032b571b..c30b7b1079d 100644 --- a/yarn-project/simulator/src/public/index.ts +++ b/yarn-project/simulator/src/public/index.ts @@ -1,16 +1,16 @@ +export * from './abstract_phase_manager.js'; export * from './db_interfaces.js'; export { - type PublicExecution, - type PublicExecutionResult, - isPublicExecutionResult, collectPublicDataReads, collectPublicDataUpdateRequests, + isPublicExecutionResult, + type PublicExecution, + type PublicExecutionResult, } from './execution.js'; export { PublicExecutor } from './executor.js'; -export { PublicProcessor, PublicProcessorFactory } from './public_processor.js'; +export * from './fee_payment.js'; +export { HintsBuilder } from './hints_builder.js'; export * from './public_db_sources.js'; -export * from './abstract_phase_manager.js'; -export * from './public_kernel_circuit_simulator.js'; export * from './public_kernel.js'; -export { HintsBuilder } from './hints_builder.js'; -export * from './fee_payment.js'; +export * from './public_kernel_circuit_simulator.js'; +export { PublicProcessor, PublicProcessorFactory } from './public_processor.js'; diff --git a/yarn-project/simulator/src/public/phase_manager_factory.ts b/yarn-project/simulator/src/public/phase_manager_factory.ts index 8c42e715a6a..5a71ff74863 100644 --- a/yarn-project/simulator/src/public/phase_manager_factory.ts +++ b/yarn-project/simulator/src/public/phase_manager_factory.ts @@ -1,9 +1,9 @@ -import { type Tx } from '@aztec/circuit-types'; +import { PublicKernelType, type Tx } from '@aztec/circuit-types'; import { type GlobalVariables, type Header, type PublicKernelCircuitPublicInputs } from '@aztec/circuits.js'; import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator'; import { type MerkleTreeOperations } from '@aztec/world-state'; -import { type AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js'; +import { type AbstractPhaseManager } from './abstract_phase_manager.js'; import { AppLogicPhaseManager } from './app_logic_phase_manager.js'; import { type ContractsDataSourcePublicDB } from './public_db_sources.js'; import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js'; @@ -12,7 +12,7 @@ import { TailPhaseManager } from './tail_phase_manager.js'; import { TeardownPhaseManager } from './teardown_phase_manager.js'; export class PhaseDidNotChangeError extends Error { - constructor(phase: PublicKernelPhase) { + constructor(phase: PublicKernelType) { super(`Tried to advance the phase from [${phase}] when the circuit still needs [${phase}]`); } } @@ -84,7 +84,7 @@ export class PhaseManagerFactory { if (output.needsSetup) { throw new CannotTransitionToSetupError(); } else if (output.needsAppLogic) { - if (currentPhaseManager.phase === PublicKernelPhase.APP_LOGIC) { + if (currentPhaseManager.phase === PublicKernelType.APP_LOGIC) { throw new PhaseDidNotChangeError(currentPhaseManager.phase); } return new AppLogicPhaseManager( @@ -97,7 +97,7 @@ export class PhaseManagerFactory { publicStateDB, ); } else if (output.needsTeardown) { - if (currentPhaseManager.phase === PublicKernelPhase.TEARDOWN) { + if (currentPhaseManager.phase === PublicKernelType.TEARDOWN) { throw new PhaseDidNotChangeError(currentPhaseManager.phase); } return new TeardownPhaseManager( @@ -109,7 +109,7 @@ export class PhaseManagerFactory { publicContractsDB, publicStateDB, ); - } else if (currentPhaseManager.phase !== PublicKernelPhase.TAIL) { + } else if (currentPhaseManager.phase !== PublicKernelType.TAIL) { return new TailPhaseManager( db, publicExecutor, diff --git a/yarn-project/simulator/src/public/public_db_sources.ts b/yarn-project/simulator/src/public/public_db_sources.ts index fe5ee2de74c..cfa3c935170 100644 --- a/yarn-project/simulator/src/public/public_db_sources.ts +++ b/yarn-project/simulator/src/public/public_db_sources.ts @@ -1,10 +1,11 @@ import { MerkleTreeId, NullifierMembershipWitness, type Tx } from '@aztec/circuit-types'; +import { type PublicDBAccessStats } from '@aztec/circuit-types/stats'; import { type AztecAddress, ContractClassRegisteredEvent, ContractInstanceDeployedEvent, Fr, - type FunctionSelector, + FunctionSelector, type L1_TO_L2_MSG_TREE_HEIGHT, type NULLIFIER_TREE_HEIGHT, type NullifierLeafPreimage, @@ -12,6 +13,7 @@ import { } from '@aztec/circuits.js'; import { computeL1ToL2MessageNullifier, computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash'; import { createDebugLogger } from '@aztec/foundation/log'; +import { Timer } from '@aztec/foundation/timer'; import { ClassRegistererAddress } from '@aztec/protocol-contracts/class-registerer'; import { type CommitmentsDB, @@ -94,6 +96,22 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB { } return contractClass.publicFunctions.find(f => f.selector.equals(selector))?.bytecode; } + + public async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise { + const artifact = await this.db.getContractArtifact(address); + if (!artifact) { + return Promise.resolve(undefined); + } + + const f = artifact.functions.find(f => + FunctionSelector.fromNameAndParameters(f.name, f.parameters).equals(selector), + ); + if (!f) { + return Promise.resolve(undefined); + } + + return Promise.resolve(`${artifact.name}:${f.name}`); + } } /** @@ -196,11 +214,14 @@ export class WorldStatePublicDB implements PublicStateDB { * Implements WorldState db using a world state database. */ export class WorldStateDB implements CommitmentsDB { + private log = createDebugLogger('aztec:sequencer:world-state-db'); + constructor(private db: MerkleTreeOperations) {} public async getNullifierMembershipWitnessAtLatestBlock( nullifier: Fr, ): Promise { + const timer = new Timer(); const index = await this.db.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer()); if (!index) { return undefined; @@ -218,6 +239,12 @@ export class WorldStateDB implements CommitmentsDB { return undefined; } + this.log.verbose(`[DB] Fetched nullifier membership`, { + eventName: 'public-db-access', + duration: timer.ms(), + operation: 'get-nullifier-membership-witness-at-latest-block', + } satisfies PublicDBAccessStats); + return new NullifierMembershipWitness(BigInt(index), leafPreimage as NullifierLeafPreimage, siblingPath); } @@ -232,6 +259,7 @@ export class WorldStateDB implements CommitmentsDB { // We iterate over messages until we find one whose nullifier is not in the nullifier tree --> we need to check // for nullifiers because messages can have duplicates. + const timer = new Timer(); do { messageIndex = (await this.db.findLeafIndexAfter(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, messageHash, startIndex))!; if (messageIndex === undefined) { @@ -249,18 +277,45 @@ export class WorldStateDB implements CommitmentsDB { messageIndex, ); + this.log.verbose(`[DB] Fetched L1 to L2 message membership`, { + eventName: 'public-db-access', + duration: timer.ms(), + operation: 'get-l1-to-l2-message-membership-witness', + } satisfies PublicDBAccessStats); + return new MessageLoadOracleInputs(messageIndex, siblingPath); } public async getL1ToL2LeafValue(leafIndex: bigint): Promise { - return await this.db.getLeafValue(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, leafIndex); + const timer = new Timer(); + const leafValue = await this.db.getLeafValue(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, leafIndex); + this.log.verbose(`[DB] Fetched L1 to L2 message leaf value`, { + eventName: 'public-db-access', + duration: timer.ms(), + operation: 'get-l1-to-l2-message-leaf-value', + } satisfies PublicDBAccessStats); + return leafValue; } public async getCommitmentIndex(commitment: Fr): Promise { - return await this.db.findLeafIndex(MerkleTreeId.NOTE_HASH_TREE, commitment); + const timer = new Timer(); + const index = await this.db.findLeafIndex(MerkleTreeId.NOTE_HASH_TREE, commitment); + this.log.verbose(`[DB] Fetched commitment index`, { + eventName: 'public-db-access', + duration: timer.ms(), + operation: 'get-commitment-index', + } satisfies PublicDBAccessStats); + return index; } public async getNullifierIndex(nullifier: Fr): Promise { - return await this.db.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer()); + const timer = new Timer(); + const index = await this.db.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer()); + this.log.verbose(`[DB] Fetched nullifier index`, { + eventName: 'public-db-access', + duration: timer.ms(), + operation: 'get-nullifier-index', + } satisfies PublicDBAccessStats); + return index; } } diff --git a/yarn-project/simulator/src/public/public_processor.ts b/yarn-project/simulator/src/public/public_processor.ts index 442e4c9ebd0..f5f5bd3749c 100644 --- a/yarn-project/simulator/src/public/public_processor.ts +++ b/yarn-project/simulator/src/public/public_processor.ts @@ -3,6 +3,7 @@ import { type FailedTx, NestedProcessReturnValues, type ProcessedTx, + PublicKernelType, type PublicProvingRequest, type SimulationError, Tx, @@ -32,11 +33,7 @@ import { import { type ContractDataSource } from '@aztec/types/contracts'; import { type MerkleTreeOperations } from '@aztec/world-state'; -import { - type AbstractPhaseManager, - PublicKernelPhase, - publicKernelPhaseToKernelType, -} from './abstract_phase_manager.js'; +import { type AbstractPhaseManager } from './abstract_phase_manager.js'; import { PhaseManagerFactory } from './phase_manager_factory.js'; import { ContractsDataSourcePublicDB, WorldStateDB, WorldStatePublicDB } from './public_db_sources.js'; import { RealPublicKernelCircuitSimulator } from './public_kernel.js'; @@ -231,8 +228,8 @@ export class PublicProcessor { const gasUsed: ProcessedTx['gasUsed'] = {}; while (phase) { const output = await phase.handle(tx, publicKernelPublicInput); - gasUsed[publicKernelPhaseToKernelType(phase.phase)] = output.gasUsed; - if (phase.phase === PublicKernelPhase.APP_LOGIC) { + gasUsed[phase.phase] = output.gasUsed; + if (phase.phase === PublicKernelType.APP_LOGIC) { returnValues = output.returnValues; } publicProvingRequests.push(...output.publicProvingRequests); diff --git a/yarn-project/simulator/src/public/setup_phase_manager.ts b/yarn-project/simulator/src/public/setup_phase_manager.ts index d26c97ec05a..ee75f637ac7 100644 --- a/yarn-project/simulator/src/public/setup_phase_manager.ts +++ b/yarn-project/simulator/src/public/setup_phase_manager.ts @@ -3,7 +3,7 @@ import { type GlobalVariables, type Header, type PublicKernelCircuitPublicInputs import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator'; import { type MerkleTreeOperations } from '@aztec/world-state'; -import { AbstractPhaseManager, PublicKernelPhase, makeAvmProvingRequest } from './abstract_phase_manager.js'; +import { AbstractPhaseManager, makeAvmProvingRequest } from './abstract_phase_manager.js'; import { type ContractsDataSourcePublicDB } from './public_db_sources.js'; import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js'; @@ -19,7 +19,7 @@ export class SetupPhaseManager extends AbstractPhaseManager { historicalHeader: Header, protected publicContractsDB: ContractsDataSourcePublicDB, protected publicStateDB: PublicStateDB, - phase: PublicKernelPhase = PublicKernelPhase.SETUP, + phase: PublicKernelType = PublicKernelType.SETUP, ) { super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase); } diff --git a/yarn-project/simulator/src/public/tail_phase_manager.ts b/yarn-project/simulator/src/public/tail_phase_manager.ts index ade82c5aae7..d0f547751d5 100644 --- a/yarn-project/simulator/src/public/tail_phase_manager.ts +++ b/yarn-project/simulator/src/public/tail_phase_manager.ts @@ -13,7 +13,7 @@ import { import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator'; import { type MerkleTreeOperations } from '@aztec/world-state'; -import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js'; +import { AbstractPhaseManager } from './abstract_phase_manager.js'; import { type ContractsDataSourcePublicDB } from './public_db_sources.js'; import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js'; @@ -26,7 +26,7 @@ export class TailPhaseManager extends AbstractPhaseManager { historicalHeader: Header, protected publicContractsDB: ContractsDataSourcePublicDB, protected publicStateDB: PublicStateDB, - phase: PublicKernelPhase = PublicKernelPhase.TAIL, + phase: PublicKernelType = PublicKernelType.TAIL, ) { super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase); } diff --git a/yarn-project/simulator/src/public/teardown_phase_manager.ts b/yarn-project/simulator/src/public/teardown_phase_manager.ts index 424ae9c5d30..bd1eafbcba9 100644 --- a/yarn-project/simulator/src/public/teardown_phase_manager.ts +++ b/yarn-project/simulator/src/public/teardown_phase_manager.ts @@ -11,7 +11,7 @@ import { type MerkleTreeOperations } from '@aztec/world-state'; import { inspect } from 'util'; -import { AbstractPhaseManager, PublicKernelPhase, makeAvmProvingRequest } from './abstract_phase_manager.js'; +import { AbstractPhaseManager, makeAvmProvingRequest } from './abstract_phase_manager.js'; import { type ContractsDataSourcePublicDB } from './public_db_sources.js'; import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js'; @@ -27,7 +27,7 @@ export class TeardownPhaseManager extends AbstractPhaseManager { historicalHeader: Header, protected publicContractsDB: ContractsDataSourcePublicDB, protected publicStateDB: PublicStateDB, - phase: PublicKernelPhase = PublicKernelPhase.TEARDOWN, + phase: PublicKernelType = PublicKernelType.TEARDOWN, ) { super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase); } diff --git a/yarn-project/types/src/contracts/contract_data_source.ts b/yarn-project/types/src/contracts/contract_data_source.ts index e785b948639..258f91dd034 100644 --- a/yarn-project/types/src/contracts/contract_data_source.ts +++ b/yarn-project/types/src/contracts/contract_data_source.ts @@ -1,4 +1,4 @@ -import { type FunctionSelector } from '@aztec/foundation/abi'; +import { type ContractArtifact, type FunctionSelector } from '@aztec/foundation/abi'; import { type AztecAddress } from '@aztec/foundation/aztec-address'; import { type Fr } from '@aztec/foundation/fields'; @@ -36,4 +36,7 @@ export interface ContractDataSource { * Returns the list of all class ids known. */ getContractClassIds(): Promise; + + getContractArtifact(address: AztecAddress): Promise; + addContractArtifact(address: AztecAddress, contract: ContractArtifact): Promise; } diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index a11516ba660..d1fe44fd9df 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -55,6 +55,7 @@ __metadata: "@aztec/foundation": "workspace:^" "@aztec/kv-store": "workspace:^" "@aztec/l1-artifacts": "workspace:^" + "@aztec/noir-contracts.js": "workspace:^" "@aztec/protocol-contracts": "workspace:^" "@aztec/types": "workspace:^" "@jest/globals": ^29.5.0