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

fix: make simulations validate resulting tx by default #8157

Merged
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
15 changes: 11 additions & 4 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
LogType,
MerkleTreeId,
NullifierMembershipWitness,
type ProcessedTx,
type ProverConfig,
PublicDataWitness,
PublicSimulationOutput,
Expand All @@ -25,6 +26,7 @@ import {
type TxHash,
TxReceipt,
TxStatus,
type TxValidator,
partitionReverts,
} from '@aztec/circuit-types';
import {
Expand Down Expand Up @@ -762,7 +764,7 @@ export class AztecNodeService implements AztecNode {
);
}

public async isValidTx(tx: Tx): Promise<boolean> {
public async isValidTx(tx: Tx, isSimulation: boolean = false): Promise<boolean> {
const blockNumber = (await this.blockSource.getBlockNumber()) + 1;

const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(
Expand All @@ -775,12 +777,17 @@ export class AztecNodeService implements AztecNode {
// These validators are taken from the sequencer, and should match.
// The reason why `phases` and `gas` tx validator is in the sequencer and not here is because
// those tx validators are customizable by the sequencer.
const txValidator = new AggregateTxValidator(
const txValidators: TxValidator<Tx | ProcessedTx>[] = [
new DataTxValidator(),
new MetadataTxValidator(newGlobalVariables),
new DoubleSpendTxValidator(new WorldStateDB(this.worldStateSynchronizer.getLatest())),
new TxProofValidator(this.proofVerifier),
);
];

if (!isSimulation) {
txValidators.push(new TxProofValidator(this.proofVerifier));
}

const txValidator = new AggregateTxValidator(...txValidators);

const [_, invalidTxs] = await txValidator.validateTxs([tx]);
if (invalidTxs.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/contract/batch_call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class BatchCall extends BaseContractInteraction {

const [unconstrainedResults, simulatedTx] = await Promise.all([
Promise.all(unconstrainedCalls),
this.wallet.simulateTx(txRequest, true, options?.from),
this.wallet.simulateTx(txRequest, true, options?.from, options?.skipTxValidation),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This had to be added here to allow for the param to be passed down into the wallet. It was already done on the non-batch call.

]);

const results: any[] = [];
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/circuit-types/src/interfaces/aztec-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,9 @@ export interface AztecNode {
* made invalid by *other* transactions if e.g. they emit the same nullifiers, or come become invalid
* due to e.g. the max_block_number property.
* @param tx - The transaction to validate for correctness.
* @param isSimulation - True if the transaction is a simulated one without generated proofs. (Optional)
*/
isValidTx(tx: Tx): Promise<boolean>;
isValidTx(tx: Tx, isSimulation?: boolean): Promise<boolean>;

/**
* Updates the configuration of this node.
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/package.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"test": "LOG_LEVEL=${LOG_LEVEL:-verbose} DEBUG_COLORS=1 NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --testTimeout=300000 --forceExit",
"test:unit": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest src/fixtures"
}
}
}
4 changes: 2 additions & 2 deletions yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ export class PXEService implements PXE {
txRequest: TxExecutionRequest,
simulatePublic: boolean,
msgSender: AztecAddress | undefined = undefined,
skipTxValidation: boolean = true, // TODO(#7956): make the default be false
skipTxValidation: boolean = false,
scopes?: AztecAddress[],
): Promise<SimulatedTx> {
return await this.jobQueue.put(async () => {
Expand All @@ -542,7 +542,7 @@ export class PXEService implements PXE {
}

if (!skipTxValidation) {
if (!(await this.node.isValidTx(simulatedTx.tx))) {
if (!(await this.node.isValidTx(simulatedTx.tx, true))) {
throw new Error('The simulated transaction is unable to be added to state and is invalid.');
}
}
Expand Down
Loading