Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: stop calling public kernels #9981

Open
wants to merge 1 commit into
base: db/stop-calling-kernels
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,6 @@ export class AztecNodeService implements AztecNode {
const prevHeader = (await this.blockSource.getBlock(-1))?.header;
const publicProcessorFactory = new PublicProcessorFactory(
this.contractDataSource,
new WASMSimulator(),
this.telemetry,
);

Expand Down
3 changes: 1 addition & 2 deletions yarn-project/prover-node/src/prover-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class ProverNode implements ClaimsMonitorHandler, EpochMonitorHandler, Pr
private readonly contractDataSource: ContractDataSource,
private readonly worldState: WorldStateSynchronizer,
private readonly coordination: ProverCoordination & Maybe<Service>,
private readonly simulator: SimulationProvider,
private readonly _simulator: SimulationProvider,
private readonly quoteProvider: QuoteProvider,
private readonly quoteSigner: QuoteSigner,
private readonly claimsMonitor: ClaimsMonitor,
Expand Down Expand Up @@ -245,7 +245,6 @@ export class ProverNode implements ClaimsMonitorHandler, EpochMonitorHandler, Pr
// Create a processor using the forked world state
const publicProcessorFactory = new PublicProcessorFactory(
this.contractDataSource,
this.simulator,
this.telemetryClient,
);

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/sequencer-client/src/client/sequencer-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ export class SequencerClient {
contractDataSource: ContractDataSource,
l2BlockSource: L2BlockSource,
l1ToL2MessageSource: L1ToL2MessageSource,
simulationProvider: SimulationProvider,
_simulationProvider: SimulationProvider,
telemetryClient: TelemetryClient,
) {
const publisher = new L1Publisher(config, telemetryClient);
const globalsBuilder = new GlobalVariableBuilder(config);

const publicProcessorFactory = new PublicProcessorFactory(contractDataSource, simulationProvider, telemetryClient);
const publicProcessorFactory = new PublicProcessorFactory(contractDataSource, telemetryClient);

const rollup = publisher.getRollupContract();
const [l1GenesisTime, slotDuration] = await Promise.all([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ import { makeTuple } from '@aztec/foundation/array';
import { padArrayEnd } from '@aztec/foundation/collection';
import { Fr } from '@aztec/foundation/fields';
import { createDebugLogger } from '@aztec/foundation/log';
import { type Tuple } from '@aztec/foundation/serialize';

import { assert } from 'console';

Expand Down Expand Up @@ -631,9 +630,9 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
/** How much gas was available for this public execution. */
gasLimits: GasSettings,
/** Call requests for setup phase. */
publicSetupCallRequests: Tuple<PublicCallRequest, typeof MAX_ENQUEUED_CALLS_PER_TX>,
publicSetupCallRequests: PublicCallRequest[],
/** Call requests for app logic phase. */
publicAppLogicCallRequests: Tuple<PublicCallRequest, typeof MAX_ENQUEUED_CALLS_PER_TX>,
publicAppLogicCallRequests: PublicCallRequest[],
/** Call request for teardown phase. */
publicTeardownCallRequest: PublicCallRequest,
/** End tree snapshots. */
Expand All @@ -653,8 +652,8 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
startTreeSnapshots,
startGasUsed,
gasLimits,
publicSetupCallRequests,
publicAppLogicCallRequests,
padArrayEnd(publicSetupCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX),
padArrayEnd(publicAppLogicCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX),
publicTeardownCallRequest,
/*previousNonRevertibleAccumulatedDataArrayLengths=*/ PrivateToAvmAccumulatedDataArrayLengths.empty(),
/*previousRevertibleAccumulatedDataArrayLengths=*/ PrivateToAvmAccumulatedDataArrayLengths.empty(),
Expand Down
13 changes: 1 addition & 12 deletions yarn-project/simulator/src/public/public_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,17 @@ import { Timer } from '@aztec/foundation/timer';
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
import { Attributes, type TelemetryClient, type Tracer, trackSpan } from '@aztec/telemetry-client';

import { type SimulationProvider } from '../providers/index.js';
import { PublicExecutor } from './executor.js';
import { computeFeePayerBalanceLeafSlot, computeFeePayerBalanceStorageSlot } from './fee_payment.js';
import { WorldStateDB } from './public_db_sources.js';
import { RealPublicKernelCircuitSimulator } from './public_kernel.js';
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
import { PublicProcessorMetrics } from './public_processor_metrics.js';
import { PublicTxSimulator } from './public_tx_simulator.js';

/**
* Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
*/
export class PublicProcessorFactory {
constructor(
private contractDataSource: ContractDataSource,
private simulator: SimulationProvider,
private telemetryClient: TelemetryClient,
) {}
constructor(private contractDataSource: ContractDataSource, private telemetryClient: TelemetryClient) {}

/**
* Creates a new instance of a PublicProcessor.
Expand All @@ -66,12 +59,10 @@ export class PublicProcessorFactory {

const worldStateDB = new WorldStateDB(merkleTree, this.contractDataSource);
const publicExecutor = new PublicExecutor(worldStateDB, telemetryClient);
const publicKernelSimulator = new RealPublicKernelCircuitSimulator(this.simulator);

return PublicProcessor.create(
merkleTree,
publicExecutor,
publicKernelSimulator,
globalVariables,
historicalHeader,
worldStateDB,
Expand Down Expand Up @@ -101,7 +92,6 @@ export class PublicProcessor {
static create(
db: MerkleTreeWriteOperations,
publicExecutor: PublicExecutor,
publicKernelSimulator: PublicKernelCircuitSimulator,
globalVariables: GlobalVariables,
historicalHeader: Header,
worldStateDB: WorldStateDB,
Expand All @@ -110,7 +100,6 @@ export class PublicProcessor {
const enqueuedCallsProcessor = PublicTxSimulator.create(
db,
publicExecutor,
publicKernelSimulator,
globalVariables,
historicalHeader,
worldStateDB,
Expand Down
70 changes: 39 additions & 31 deletions yarn-project/simulator/src/public/public_tx_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
Gas,
type GasSettings,
type GlobalVariables,
type PrivateToPublicAccumulatedData,
PublicAccumulatedDataArrayLengths,
type PublicCallRequest,
type PublicKernelCircuitPublicInputs,
PublicValidationRequestArrayLengths,
RevertCode,
type StateReference,
Expand All @@ -30,7 +30,12 @@ import { DualSideEffectTrace } from './dual_side_effect_trace.js';
import { PublicEnqueuedCallSideEffectTrace } from './enqueued_call_side_effect_trace.js';
import { type WorldStateDB } from './public_db_sources.js';
import { PublicSideEffectTrace } from './side_effect_trace.js';
import { generateAvmCircuitPublicInputs, getCallRequestsByPhase, getExecutionRequestsByPhase, getPublicKernelCircuitPublicInputs } from './utils.js';
import {
convertPrivateToPublicAccumulatedData,
generateAvmCircuitPublicInputs,
getCallRequestsByPhase,
getExecutionRequestsByPhase,
} from './utils.js';

export class PublicTxContext {
private log: DebugLogger;
Expand All @@ -49,20 +54,20 @@ export class PublicTxContext {

constructor(
public readonly state: PhaseStateManager,
public readonly tx: Tx, // tmp hack
public readonly tx: Tx, // TODO(dbanks12): remove
public readonly globalVariables: GlobalVariables,
public readonly constants: CombinedConstantData, // tmp hack
public readonly constants: CombinedConstantData, // TODO(dbanks12): remove
public readonly startStateReference: StateReference,
startGasUsed: Gas,
private readonly startGasUsed: Gas,
private readonly gasSettings: GasSettings,
private readonly setupCallRequests: PublicCallRequest[],
private readonly appLogicCallRequests: PublicCallRequest[],
private readonly teardownCallRequests: PublicCallRequest[],
private readonly setupExecutionRequests: PublicExecutionRequest[],
private readonly appLogicExecutionRequests: PublicExecutionRequest[],
private readonly teardownExecutionRequests: PublicExecutionRequest[],
private firstPublicKernelOutput: PublicKernelCircuitPublicInputs,
public latestPublicKernelOutput: PublicKernelCircuitPublicInputs,
private readonly nonRevertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData,
private readonly revertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData,
public trace: PublicEnqueuedCallSideEffectTrace,
) {
this.log = createDebugLogger(`aztec:public_tx_context`);
Expand All @@ -75,29 +80,25 @@ export class PublicTxContext {
tx: Tx,
globalVariables: GlobalVariables,
) {
const privateKernelOutput = tx.data;
const firstPublicKernelOutput = getPublicKernelCircuitPublicInputs(privateKernelOutput, globalVariables);
const nonRevertibleAccumulatedDataFromPrivate = convertPrivateToPublicAccumulatedData(
tx.data.forPublic!.nonRevertibleAccumulatedData,
);
const revertibleAccumulatedDataFromPrivate = convertPrivateToPublicAccumulatedData(
tx.data.forPublic!.revertibleAccumulatedData,
);

const nonRevertibleNullifiersFromPrivate = firstPublicKernelOutput.endNonRevertibleData.nullifiers
const nonRevertibleNullifiersFromPrivate = nonRevertibleAccumulatedDataFromPrivate.nullifiers
.filter(n => !n.isEmpty())
.map(n => n.value);
const _revertibleNullifiersFromPrivate = firstPublicKernelOutput.end.nullifiers
const _revertibleNullifiersFromPrivate = revertibleAccumulatedDataFromPrivate.nullifiers
.filter(n => !n.isEmpty())
.map(n => n.value);

// During SETUP, non revertible side effects from private are our "previous data"
const prevAccumulatedData = firstPublicKernelOutput.endNonRevertibleData;
const previousValidationRequestArrayLengths = PublicValidationRequestArrayLengths.new(
firstPublicKernelOutput.validationRequests,
);

const previousAccumulatedDataArrayLengths = PublicAccumulatedDataArrayLengths.new(prevAccumulatedData);

const innerCallTrace = new PublicSideEffectTrace();
const enqueuedCallTrace = new PublicEnqueuedCallSideEffectTrace(
/*startSideEffectCounter=*/ 0,
previousValidationRequestArrayLengths,
previousAccumulatedDataArrayLengths,
PublicValidationRequestArrayLengths.empty(),
PublicAccumulatedDataArrayLengths.new(nonRevertibleAccumulatedDataFromPrivate),
);
const trace = new DualSideEffectTrace(innerCallTrace, enqueuedCallTrace);

Expand All @@ -122,8 +123,8 @@ export class PublicTxContext {
getExecutionRequestsByPhase(tx, TxExecutionPhase.SETUP),
getExecutionRequestsByPhase(tx, TxExecutionPhase.APP_LOGIC),
getExecutionRequestsByPhase(tx, TxExecutionPhase.TEARDOWN),
firstPublicKernelOutput,
firstPublicKernelOutput,
tx.data.forPublic!.nonRevertibleAccumulatedData,
tx.data.forPublic!.revertibleAccumulatedData,
enqueuedCallTrace,
);
}
Expand Down Expand Up @@ -258,25 +259,33 @@ export class PublicTxContext {
return txFee;
}

private async generateAvmCircuitPublicInputs(endStateReference: StateReference): Promise<AvmCircuitPublicInputs> {
assert(this.currentPhase === TxExecutionPhase.TEARDOWN, 'Can only get AvmCircuitPublicInputs after teardown (tx done)');
private generateAvmCircuitPublicInputs(endStateReference: StateReference): AvmCircuitPublicInputs {
assert(
this.currentPhase === TxExecutionPhase.TEARDOWN,
'Can only get AvmCircuitPublicInputs after teardown (tx done)',
);
return generateAvmCircuitPublicInputs(
this.tx,
this.trace,
this.globalVariables,
this.startStateReference,
this.startGasUsed,
this.gasSettings,
this.setupCallRequests,
this.appLogicCallRequests,
this.teardownCallRequests,
this.nonRevertibleAccumulatedDataFromPrivate,
this.revertibleAccumulatedDataFromPrivate,
endStateReference,
this.gasUsed,
/*endGasUsed=*/ this.gasUsed,
this.getFinalTransactionFee(),
this.revertCode,
this.firstPublicKernelOutput,
);
}

async generateProvingRequest(endStateReference: StateReference): Promise<AvmProvingRequest> {
generateProvingRequest(endStateReference: StateReference): AvmProvingRequest {
// TODO(dbanks12): Once we actually have tx-level proving, this will generate the entire
// proving request for the first time
this.avmProvingRequest!.inputs.output = await this.generateAvmCircuitPublicInputs(endStateReference);
this.avmProvingRequest!.inputs.output = this.generateAvmCircuitPublicInputs(endStateReference);
return this.avmProvingRequest!;
}
}
Expand Down Expand Up @@ -313,4 +322,3 @@ class PhaseStateManager {
this.currentlyActiveStateManager = undefined;
}
}

7 changes: 0 additions & 7 deletions yarn-project/simulator/src/public/public_tx_simulator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ import { type MockProxy, mock } from 'jest-mock-extended';

import { type AvmPersistableStateManager } from '../avm/journal/journal.js';
import { PublicExecutionResultBuilder } from '../mocks/fixtures.js';
import { WASMSimulator } from '../providers/acvm_wasm.js';
import { type PublicExecutor } from './executor.js';
import { type WorldStateDB } from './public_db_sources.js';
import { RealPublicKernelCircuitSimulator } from './public_kernel.js';
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
import { PublicTxSimulator } from './public_tx_simulator.js';

describe('public_tx_simulator', () => {
Expand All @@ -53,7 +50,6 @@ describe('public_tx_simulator', () => {

let db: MockProxy<MerkleTreeWriteOperations>;
let publicExecutor: MockProxy<PublicExecutor>;
let publicKernel: PublicKernelCircuitSimulator;
let worldStateDB: MockProxy<WorldStateDB>;

let root: Buffer;
Expand Down Expand Up @@ -163,12 +159,9 @@ describe('public_tx_simulator', () => {
db.getPreviousValueIndex.mockResolvedValue({ index: 0n, alreadyPresent: true });
db.getLeafPreimage.mockResolvedValue(new PublicDataTreeLeafPreimage(new Fr(0), new Fr(0), new Fr(0), 0n));

publicKernel = new RealPublicKernelCircuitSimulator(new WASMSimulator());

processor = PublicTxSimulator.create(
db,
publicExecutor,
publicKernel,
GlobalVariables.from({ ...GlobalVariables.empty(), gasFees }),
Header.empty(),
worldStateDB,
Expand Down
Loading
Loading