Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/docs/aztec/smart_contracts/functions/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ To generate the environment, the simulator gets the block header from the [PXE d

Once the execution environment is created, `runUtility` function is invoked on the simulator:

#include_code execute_utility_function yarn-project/simulator/src/private/simulator.ts typescript
#include_code execute_utility_function yarn-project/pxe/src/contract_function_simulator/contract_function_simulator.ts typescript

This:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public async runUtility(call: FunctionCall, authwits: AuthWitness[], scopes?: Az
});

const initialWitness = toACVMWitness(0, call.args);
const acirExecutionResult = await this.simulationProvider
const acirExecutionResult = await this.simulator
.executeUserCircuit(initialWitness, entryPointArtifact, new Oracle(oracle))
.catch((err: Error) => {
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@aztec/noir-protocol-circuits-types/client';
import type { ArtifactProvider, ClientProtocolArtifact } from '@aztec/noir-protocol-circuits-types/types';
import type { Abi, WitnessMap } from '@aztec/noir-types';
import type { SimulationProvider } from '@aztec/simulator/client';
import type { CircuitSimulator } from '@aztec/simulator/client';
import type { PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
import type {
PrivateExecutionStep,
Expand All @@ -37,7 +37,7 @@ import { mapProtocolArtifactNameToCircuitName } from '../../stats.js';
export abstract class BBPrivateKernelProver implements PrivateKernelProver {
constructor(
protected artifactProvider: ArtifactProvider,
protected simulationProvider: SimulationProvider,
protected simulator: CircuitSimulator,
protected log = createLogger('bb-prover'),
) {}

Expand Down Expand Up @@ -164,7 +164,7 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {

const witnessMap = convertInputs(inputs, compiledCircuit.abi);

const outputWitness = await this.simulationProvider
const outputWitness = await this.simulator
.executeProtocolCircuit(witnessMap, compiledCircuit, foreignCallHandler)
.catch((err: Error) => {
this.log.debug(`Failed to simulate ${circuitType}`, {
Expand Down Expand Up @@ -200,11 +200,7 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
await this.artifactProvider.getClientCircuitArtifactByName(circuitType);

const witnessMap = convertInputs(inputs, compiledCircuit.abi);
const outputWitness = await this.simulationProvider.executeProtocolCircuit(
witnessMap,
compiledCircuit,
foreignCallHandler,
);
const outputWitness = await this.simulator.executeProtocolCircuit(witnessMap, compiledCircuit, foreignCallHandler);
const output = convertOutputs(outputWitness.witness, compiledCircuit.abi);

this.log.debug(`Generated witness for ${circuitType}`, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { runInDirectory } from '@aztec/foundation/fs';
import { type Logger, createLogger } from '@aztec/foundation/log';
import { BundleArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/bundle';
import type { SimulationProvider } from '@aztec/simulator/server';
import type { CircuitSimulator } from '@aztec/simulator/server';
import { type PrivateExecutionStep, serializePrivateExecutionSteps } from '@aztec/stdlib/kernel';
import type { ClientIvcProof } from '@aztec/stdlib/proofs';

Expand All @@ -21,19 +21,19 @@ export class BBNativePrivateKernelProver extends BBPrivateKernelProver {
private bbBinaryPath: string,
private bbWorkingDirectory: string,
private skipCleanup: boolean,
protected override simulationProvider: SimulationProvider,
protected override simulator: CircuitSimulator,
protected override log = createLogger('bb-prover:native'),
) {
super(new BundleArtifactProvider(), simulationProvider, log);
super(new BundleArtifactProvider(), simulator, log);
}

public static async new(config: BBConfig, simulationProvider: SimulationProvider, log?: Logger) {
public static async new(config: BBConfig, simulator: CircuitSimulator, log?: Logger) {
await fs.mkdir(config.bbWorkingDirectory, { recursive: true });
return new BBNativePrivateKernelProver(
config.bbBinaryPath,
config.bbWorkingDirectory,
!!config.bbSkipCleanup,
simulationProvider,
simulator,
log,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createLogger } from '@aztec/foundation/log';
import { Timer } from '@aztec/foundation/timer';
import { serializeWitness } from '@aztec/noir-noirc_abi';
import type { ArtifactProvider } from '@aztec/noir-protocol-circuits-types/types';
import type { SimulationProvider } from '@aztec/simulator/client';
import type { CircuitSimulator } from '@aztec/simulator/client';
import type { PrivateExecutionStep } from '@aztec/stdlib/kernel';
import { ClientIvcProof } from '@aztec/stdlib/proofs';

Expand All @@ -14,11 +14,11 @@ import { BBPrivateKernelProver } from '../bb_private_kernel_prover.js';
export abstract class BBWASMPrivateKernelProver extends BBPrivateKernelProver {
constructor(
protected override artifactProvider: ArtifactProvider,
protected override simulationProvider: SimulationProvider,
protected override simulator: CircuitSimulator,
private threads: number = 1,
protected override log = createLogger('bb-prover:wasm'),
) {
super(artifactProvider, simulationProvider, log);
super(artifactProvider, simulator, log);
}

public override async createClientIvcProof(executionSteps: PrivateExecutionStep[]): Promise<ClientIvcProof> {
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/bb-prover/src/prover/client/wasm/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createLogger } from '@aztec/foundation/log';
import { BundleArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/bundle';
import type { SimulationProvider } from '@aztec/simulator/client';
import type { CircuitSimulator } from '@aztec/simulator/client';

import { BBWASMPrivateKernelProver } from './bb_wasm_private_kernel_prover.js';

export class BBWASMBundlePrivateKernelProver extends BBWASMPrivateKernelProver {
constructor(simulationProvider: SimulationProvider, threads = 16, log = createLogger('bb-prover:wasm:bundle')) {
super(new BundleArtifactProvider(), simulationProvider, threads, log);
constructor(simulator: CircuitSimulator, threads = 16, log = createLogger('bb-prover:wasm:bundle')) {
super(new BundleArtifactProvider(), simulator, threads, log);
}
}
6 changes: 3 additions & 3 deletions yarn-project/bb-prover/src/prover/client/wasm/lazy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createLogger } from '@aztec/foundation/log';
import { LazyArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/lazy';
import type { SimulationProvider } from '@aztec/simulator/client';
import type { CircuitSimulator } from '@aztec/simulator/client';

import { BBWASMPrivateKernelProver } from './bb_wasm_private_kernel_prover.js';

export class BBWASMLazyPrivateKernelProver extends BBWASMPrivateKernelProver {
constructor(simulationProvider: SimulationProvider, threads = 16, log = createLogger('bb-prover:wasm:lazy')) {
super(new LazyArtifactProvider(), simulationProvider, threads, log);
constructor(simulator: CircuitSimulator, threads = 16, log = createLogger('bb-prover:wasm:lazy')) {
super(new LazyArtifactProvider(), simulator, threads, log);
}
}
8 changes: 4 additions & 4 deletions yarn-project/bb-prover/src/test/test_circuit_prover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
} from '@aztec/noir-protocol-circuits-types/server';
import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types/server/vks';
import type { WitnessMap } from '@aztec/noir-types';
import { type SimulationProvider, WASMSimulatorWithBlobs, emitCircuitSimulationStats } from '@aztec/simulator/server';
import { type CircuitSimulator, WASMSimulatorWithBlobs, emitCircuitSimulationStats } from '@aztec/simulator/server';
import type { AvmCircuitInputs } from '@aztec/stdlib/avm';
import {
type ProofAndVerificationKey,
Expand Down Expand Up @@ -88,7 +88,7 @@ export class TestCircuitProver implements ServerCircuitProver {
private logger = createLogger('bb-prover:test-prover');

constructor(
private simulationProvider?: SimulationProvider,
private simulator?: CircuitSimulator,
private opts: TestDelay = { proverTestDelayType: 'fixed', proverTestDelayMs: 0 },
telemetry: TelemetryClient = getTelemetryClient(),
) {
Expand Down Expand Up @@ -353,7 +353,7 @@ export class TestCircuitProver implements ServerCircuitProver {
let witness: WitnessMap;
if (
['BlockRootRollupArtifact', 'SingleTxBlockRootRollupArtifact'].includes(artifactName) ||
this.simulationProvider == undefined
this.simulator == undefined
) {
// TODO(#10323): Native ACVM simulator does not support foreign call handler so we use the wasm simulator
// when simulating block root rollup and single tx block root rollup circuits or when the native ACVM simulator
Expand All @@ -367,7 +367,7 @@ export class TestCircuitProver implements ServerCircuitProver {
).witness;
} else {
witness = (
await this.simulationProvider.executeProtocolCircuit(
await this.simulator.executeProtocolCircuit(
witnessMap,
getSimulatedServerCircuitArtifact(artifactName),
undefined, // Native ACM simulator does not support foreign call handler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import { type Log, type ProverType, ProxyLogger, generateBenchmark } from './ben
type NativeProverConfig = { bbBinaryPath?: string; bbWorkingDirectory?: string };

async function createProver(config: NativeProverConfig = {}, log: Logger) {
const simulationProvider = new WASMSimulator();
const simulator = new WASMSimulator();
if (!config.bbBinaryPath || !config.bbWorkingDirectory) {
return { prover: new BBWASMBundlePrivateKernelProver(simulationProvider, 16, log), type: 'wasm' as ProverType };
return { prover: new BBWASMBundlePrivateKernelProver(simulator, 16, log), type: 'wasm' as ProverType };
} else {
const bbConfig = config as Required<NativeProverConfig>;
return {
prover: await BBNativePrivateKernelProver.new({ bbSkipCleanup: false, ...bbConfig }, simulationProvider, log),
prover: await BBNativePrivateKernelProver.new({ bbSkipCleanup: false, ...bbConfig }, simulator, log),
type: 'native' as ProverType,
};
}
Expand Down
17 changes: 7 additions & 10 deletions yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ import { type ProverNode, type ProverNodeConfig, createProverNode } from '@aztec
import {
type PXEService,
type PXEServiceConfig,
createPXEServiceWithSimulationProvider,
createPXEServiceWithSimulator,
getPXEServiceConfig,
} from '@aztec/pxe/server';
import type { SequencerClient } from '@aztec/sequencer-client';
import type { TestSequencerClient } from '@aztec/sequencer-client/test';
import { MemoryCircuitRecorder, SimulationProviderRecorderWrapper, WASMSimulator } from '@aztec/simulator/client';
import { MemoryCircuitRecorder, SimulatorRecorderWrapper, WASMSimulator } from '@aztec/simulator/client';
import { FileCircuitRecorder } from '@aztec/simulator/testing';
import { getContractClassFromArtifact, getContractInstanceFromDeployParams } from '@aztec/stdlib/contract';
import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
Expand Down Expand Up @@ -171,17 +171,14 @@ export async function setupPXEService(
pxeServiceConfig.dataDirectory = path.join(tmpdir(), randomBytes(8).toString('hex'));
}

const simulationProvider = new WASMSimulator();
const simulator = new WASMSimulator();
const recorder = process.env.CIRCUIT_RECORD_DIR
? new FileCircuitRecorder(process.env.CIRCUIT_RECORD_DIR)
: new MemoryCircuitRecorder();
const simulationProviderWithRecorder = new SimulationProviderRecorderWrapper(simulationProvider, recorder);
const pxe = await createPXEServiceWithSimulationProvider(
aztecNode,
simulationProviderWithRecorder,
pxeServiceConfig,
{ useLogSuffix },
);
const simulatorWithRecorder = new SimulatorRecorderWrapper(simulator, recorder);
const pxe = await createPXEServiceWithSimulator(aztecNode, simulatorWithRecorder, pxeServiceConfig, {
useLogSuffix,
});

const teardown = async () => {
if (!configuredDataDirectory) {
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/prover-client/src/mocks/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EthAddress } from '@aztec/foundation/eth-address';
import { Fr } from '@aztec/foundation/fields';
import type { Logger } from '@aztec/foundation/log';
import { fileURLToPath } from '@aztec/foundation/url';
import { NativeACVMSimulator, type SimulationProvider, WASMSimulatorWithBlobs } from '@aztec/simulator/server';
import { type CircuitSimulator, NativeACVMSimulator, WASMSimulatorWithBlobs } from '@aztec/simulator/server';
import { AztecAddress } from '@aztec/stdlib/aztec-address';
import { GasFees } from '@aztec/stdlib/gas';
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
Expand Down Expand Up @@ -64,10 +64,10 @@ export const getEnvironmentConfig = async (logger: Logger) => {
}
};

export async function getSimulationProvider(
export async function getSimulator(
config: { acvmWorkingDirectory: string | undefined; acvmBinaryPath: string | undefined },
logger?: Logger,
): Promise<SimulationProvider> {
): Promise<CircuitSimulator> {
if (config.acvmBinaryPath && config.acvmWorkingDirectory) {
try {
await fs.access(config.acvmBinaryPath, fs.constants.R_OK);
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/prover-client/src/mocks/test_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { buildBlockWithCleanDB } from '../block_builder/light.js';
import { ProvingOrchestrator } from '../orchestrator/index.js';
import { BrokerCircuitProverFacade } from '../proving_broker/broker_prover_facade.js';
import { TestBroker } from '../test/mock_prover.js';
import { getEnvironmentConfig, getSimulationProvider, makeGlobals, updateExpectedTreesFromTxs } from './fixtures.js';
import { getEnvironmentConfig, getSimulator, makeGlobals, updateExpectedTreesFromTxs } from './fixtures.js';

export class TestContext {
private headers: Map<number, BlockHeader> = new Map();
Expand Down Expand Up @@ -59,7 +59,7 @@ export class TestContext {
logger: Logger,
proverCount = 4,
createProver: (bbConfig: BBProverConfig) => Promise<ServerCircuitProver> = async (bbConfig: BBProverConfig) =>
new TestCircuitProver(await getSimulationProvider(bbConfig, logger)),
new TestCircuitProver(await getSimulator(bbConfig, logger)),
blockNumber = 1,
) {
const directoriesToCleanup: string[] = [];
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/prover-client/src/prover-client/prover-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ export function buildServerCircuitProver(
return BBNativeRollupProver.new(config, telemetry);
}

const simulationProvider = config.acvmBinaryPath
const simulator = config.acvmBinaryPath
? new NativeACVMSimulator(config.acvmWorkingDirectory, config.acvmBinaryPath)
: undefined;

return Promise.resolve(new TestCircuitProver(simulationProvider, config, telemetry));
return Promise.resolve(new TestCircuitProver(simulator, config, telemetry));
}
2 changes: 2 additions & 0 deletions yarn-project/pxe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"./server": "./dest/entrypoints/server/index.js",
"./client/lazy": "./dest/entrypoints/client/lazy/index.js",
"./client/bundle": "./dest/entrypoints/client/bundle/index.js",
"./simulator": "./dest/contract_function_simulator/index.js",
"./config": "./dest/config/index.js",
"./testing": "./dest/test/pxe_test_suite.js"
},
Expand Down Expand Up @@ -78,6 +79,7 @@
"viem": "2.23.7"
},
"devDependencies": {
"@aztec/merkle-tree": "workspace:^",
"@aztec/noir-test-contracts.js": "workspace:^",
"@jest/globals": "^29.5.0",
"@types/jest": "^29.5.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
import { Fr } from '@aztec/foundation/fields';
import { type Logger, createLogger } from '@aztec/foundation/log';
import {
type CircuitSimulator,
ExecutionError,
createSimulationError,
extractCallStack,
resolveAssertionMessageFromError,
toACVMWitness,
witnessMapToFields,
} from '@aztec/simulator/client';
import type { AbiDecoded, FunctionCall } from '@aztec/stdlib/abi';
import { FunctionSelector, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
import { AztecAddress } from '@aztec/stdlib/aztec-address';
import { CallContext, HashedValues, PrivateExecutionResult, TxExecutionRequest, collectNested } from '@aztec/stdlib/tx';

import { ExecutionError, createSimulationError, resolveAssertionMessageFromError } from '../common/errors.js';
import { Oracle, extractCallStack, toACVMWitness, witnessMapToFields } from './acvm/index.js';
import type { ExecutionDataProvider } from './execution_data_provider.js';
import { ExecutionNoteCache } from './execution_note_cache.js';
import { HashedValuesCache } from './hashed_values_cache.js';
import { executePrivateFunction, verifyCurrentClassId } from './private_execution.js';
import { PrivateExecutionOracle } from './private_execution_oracle.js';
import type { SimulationProvider } from './providers/simulation_provider.js';
import { UtilityExecutionOracle } from './utility_execution_oracle.js';
import { Oracle } from './oracle/oracle.js';
import { executePrivateFunction, verifyCurrentClassId } from './oracle/private_execution.js';
import { PrivateExecutionOracle } from './oracle/private_execution_oracle.js';
import { UtilityExecutionOracle } from './oracle/utility_execution_oracle.js';

/**
* The ACIR simulator.
* The contract function simulator.
*/
export class AcirSimulator {
export class ContractFunctionSimulator {
private log: Logger;

constructor(
private executionDataProvider: ExecutionDataProvider,
private simulationProvider: SimulationProvider,
private simulator: CircuitSimulator,
) {
this.log = createLogger('simulator');
}
Expand Down Expand Up @@ -83,7 +90,7 @@ export class AcirSimulator {
HashedValuesCache.create(request.argsOfCalls),
noteCache,
this.executionDataProvider,
this.simulationProvider,
this.simulator,
/*totalPublicArgsCount=*/ 0,
startSideEffectCounter,
undefined,
Expand All @@ -92,7 +99,7 @@ export class AcirSimulator {

try {
const executionResult = await executePrivateFunction(
this.simulationProvider,
this.simulator,
context,
entryPointArtifact,
contractAddress,
Expand Down Expand Up @@ -144,8 +151,8 @@ export class AcirSimulator {
});

const initialWitness = toACVMWitness(0, call.args);
const acirExecutionResult = await this.simulationProvider
.executeUserCircuit(initialWitness, entryPointArtifact, new Oracle(oracle))
const acirExecutionResult = await this.simulator
.executeUserCircuit(initialWitness, entryPointArtifact, new Oracle(oracle).toACIRCallback())
.catch((err: Error) => {
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
throw new ExecutionError(
Expand Down
Loading