Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Aug 8, 2024
1 parent e73e86d commit 2a464b1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
19 changes: 15 additions & 4 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ import { createProverClient } from '@aztec/prover-client';
import {
AggregateTxValidator,
DataTxValidator,
DoubleSpendTxValidator,
type GlobalVariableBuilder,
SequencerClient,
getGlobalVariableBuilder,
} from '@aztec/sequencer-client';
import { PublicProcessorFactory, WASMSimulator, createSimulationProvider } from '@aztec/simulator';
import { PublicProcessorFactory, WASMSimulator, WorldStateDB, createSimulationProvider } from '@aztec/simulator';
import { type TelemetryClient } from '@aztec/telemetry-client';
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
import {
Expand Down Expand Up @@ -165,6 +166,7 @@ export class AztecNodeService implements AztecNode {
new DataTxValidator(),
new MetadataTxValidator(config.l1ChainId),
new TxProofValidator(proofVerifier),
new DoubleSpendTxValidator(new WorldStateDB(worldStateSynchronizer.getLatest())),
);

const simulationProvider = await createSimulationProvider(config, log);
Expand Down Expand Up @@ -339,9 +341,7 @@ export class AztecNodeService implements AztecNode {
const timer = new Timer();
this.log.info(`Received tx ${tx.getTxHash()}`);

const [_, invalidTxs] = await this.txValidator.validateTxs([tx]);
if (invalidTxs.length > 0) {
this.log.warn(`Rejecting tx ${tx.getTxHash()} because of validation errors`);
if ((await this.validateTx(tx)) === false) {
this.metrics.receivedTx(timer.ms(), false);
return;
}
Expand Down Expand Up @@ -768,6 +768,17 @@ export class AztecNodeService implements AztecNode {
);
}

public async validateTx(tx: Tx): Promise<boolean> {
const [_, invalidTxs] = await this.txValidator.validateTxs([tx]);
if (invalidTxs.length > 0) {
this.log.warn(`Rejecting tx ${tx.getTxHash()} because of validation errors`);

return false;
}

return true;
}

public async setConfig(config: Partial<SequencerConfig & ProverConfig>): Promise<void> {
const newConfig = { ...this.config, ...config };
this.sequencer?.updateSequencerConfig(config);
Expand Down
7 changes: 7 additions & 0 deletions yarn-project/circuit-types/src/interfaces/aztec-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ export interface AztecNode {
**/
simulatePublicCalls(tx: Tx): Promise<PublicSimulationOutput>;

/**
* Validates the correctness of the execution, namely that a transaction is valid if and
* only if the transaction can be added to a valid block at the current state.
* @param tx - The transaction to validate for correctness.
*/
validateTx(tx: Tx): Promise<boolean>;

/**
* Updates the configuration of this node.
* @param config - Updated configuration to be merged with the current one.
Expand Down
9 changes: 9 additions & 0 deletions yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,22 @@ export class PXEService implements PXE {
simulatePublic: boolean,
msgSender: AztecAddress | undefined = undefined,
scopes?: AztecAddress[],
offline: boolean = false,
): Promise<SimulatedTx> {
return await this.jobQueue.put(async () => {
const simulatedTx = await this.#simulateAndProve(txRequest, this.fakeProofCreator, msgSender, scopes);
if (simulatePublic) {
simulatedTx.publicOutput = await this.#simulatePublicCalls(simulatedTx.tx);
}

if (!offline) {
const isValidTx = await this.node.validateTx(simulatedTx.tx);

if (!isValidTx) {
throw new Error('The simulated transaction is unable to be added to state and is invalid.');
}
}

// We log only if the msgSender is undefined, as simulating with a different msgSender
// is unlikely to be a real transaction, and likely to be only used to read data.
// Meaning that it will not necessarily have produced a nullifier (and thus have no TxHash)
Expand Down
1 change: 1 addition & 0 deletions yarn-project/sequencer-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './publisher/index.js';
export * from './sequencer/index.js';
export * from './tx_validator/aggregate_tx_validator.js';
export * from './tx_validator/data_validator.js';
export * from './tx_validator/double_spend_validator.js';

// Used by the node to simulate public parts of transactions. Should these be moved to a shared library?
export * from './global_variable_builder/index.js';

0 comments on commit 2a464b1

Please sign in to comment.