From 0555097dccf948999287d5d34234257c944d9d64 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 23 Aug 2024 10:05:37 +0000 Subject: [PATCH] init --- .../aztec-node/src/aztec-node/server.ts | 15 +++++++--- .../aztec.js/src/contract/batch_call.ts | 2 +- .../src/interfaces/aztec-node.ts | 3 +- yarn-project/end-to-end/package.local.json | 2 +- .../end-to-end/src/e2e_prover/full.test.ts | 8 +++-- .../src/e2e_prover/with_padding.test.ts | 3 +- .../src/simulators/token_simulator.ts | 30 ++++++++++++++----- .../pxe/src/pxe_service/pxe_service.ts | 4 +-- 8 files changed, 47 insertions(+), 20 deletions(-) diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 27d0cbc032fb..da98547c0bf4 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -15,6 +15,7 @@ import { LogType, MerkleTreeId, NullifierMembershipWitness, + type ProcessedTx, type ProverConfig, PublicDataWitness, PublicSimulationOutput, @@ -25,6 +26,7 @@ import { type TxHash, TxReceipt, TxStatus, + type TxValidator, partitionReverts, } from '@aztec/circuit-types'; import { @@ -762,7 +764,7 @@ export class AztecNodeService implements AztecNode { ); } - public async isValidTx(tx: Tx): Promise { + public async isValidTx(tx: Tx, isSimulation: boolean = false): Promise { const blockNumber = (await this.blockSource.getBlockNumber()) + 1; const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables( @@ -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[] = [ 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) { diff --git a/yarn-project/aztec.js/src/contract/batch_call.ts b/yarn-project/aztec.js/src/contract/batch_call.ts index 3a02a7139015..19fb03999f69 100644 --- a/yarn-project/aztec.js/src/contract/batch_call.ts +++ b/yarn-project/aztec.js/src/contract/batch_call.ts @@ -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), ]); const results: any[] = []; diff --git a/yarn-project/circuit-types/src/interfaces/aztec-node.ts b/yarn-project/circuit-types/src/interfaces/aztec-node.ts index 70dbc3fb8b4f..16c64a1ac423 100644 --- a/yarn-project/circuit-types/src/interfaces/aztec-node.ts +++ b/yarn-project/circuit-types/src/interfaces/aztec-node.ts @@ -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; + isValidTx(tx: Tx, isSimulation?: boolean): Promise; /** * Updates the configuration of this node. diff --git a/yarn-project/end-to-end/package.local.json b/yarn-project/end-to-end/package.local.json index c76111c3c265..16ebe7dc24aa 100644 --- a/yarn-project/end-to-end/package.local.json +++ b/yarn-project/end-to-end/package.local.json @@ -5,4 +5,4 @@ "test": "TIME_TRAVELER=${TIME_TRAVELER:-true} 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" } -} \ No newline at end of file +} diff --git a/yarn-project/end-to-end/src/e2e_prover/full.test.ts b/yarn-project/end-to-end/src/e2e_prover/full.test.ts index f5881b11a1d9..e018100fb9ed 100644 --- a/yarn-project/end-to-end/src/e2e_prover/full.test.ts +++ b/yarn-project/end-to-end/src/e2e_prover/full.test.ts @@ -27,7 +27,8 @@ describe('full_prover', () => { }); afterEach(async () => { - await t.tokenSim.check(); + // TODO: (#8187) Tx validation is skipped here because checking the simulation fails the proof validation + await t.tokenSim.check(true); }); it( @@ -41,7 +42,10 @@ describe('full_prover', () => { expect(privateSendAmount).toBeGreaterThan(0n); const privateInteraction = provenAssets[0].methods.transfer(accounts[1].address, privateSendAmount); - const publicBalance = await provenAssets[1].methods.balance_of_public(accounts[0].address).simulate(); + // TODO: (#8187) This works with above private balance, but not public balance below. + const publicBalance = await provenAssets[1].methods.balance_of_public(accounts[0].address).simulate({ + skipTxValidation: true, + }); const publicSendAmount = publicBalance / 2n; expect(publicSendAmount).toBeGreaterThan(0n); const publicInteraction = provenAssets[1].methods.transfer_public( diff --git a/yarn-project/end-to-end/src/e2e_prover/with_padding.test.ts b/yarn-project/end-to-end/src/e2e_prover/with_padding.test.ts index 30e507012ab1..702c360876bd 100644 --- a/yarn-project/end-to-end/src/e2e_prover/with_padding.test.ts +++ b/yarn-project/end-to-end/src/e2e_prover/with_padding.test.ts @@ -19,7 +19,8 @@ describe('full_prover_with_padding_tx', () => { }); afterEach(async () => { - await t.tokenSim.check(); + // TODO: (#8187) Tx validation is skipped here because checking the simulation fails the proof validation + await t.tokenSim.check(true); }); it( diff --git a/yarn-project/end-to-end/src/simulators/token_simulator.ts b/yarn-project/end-to-end/src/simulators/token_simulator.ts index c4addad4b217..887ae00f64e3 100644 --- a/yarn-project/end-to-end/src/simulators/token_simulator.ts +++ b/yarn-project/end-to-end/src/simulators/token_simulator.ts @@ -97,7 +97,7 @@ export class TokenSimulator { return this.balancesPrivate.get(address.toString()) || 0n; } - async checkPublic() { + async checkPublic(skipTxValidation: boolean = false) { // public calls const calls = [this.token.methods.total_supply().request()]; for (const address of this.accounts) { @@ -105,7 +105,13 @@ export class TokenSimulator { } const results = ( - await Promise.all(chunk(calls, 4).map(batch => new BatchCall(this.defaultWallet, batch).simulate())) + await Promise.all( + chunk(calls, 4).map(batch => + new BatchCall(this.defaultWallet, batch).simulate({ + skipTxValidation, + }), + ), + ) ).flat(); expect(results[0]).toEqual(this.totalSupply); @@ -115,7 +121,7 @@ export class TokenSimulator { } } - async checkPrivate() { + async checkPrivate(skipTxValidation: boolean = false) { // Private calls const defaultLookups = []; const nonDefaultLookups = []; @@ -133,7 +139,13 @@ export class TokenSimulator { defaultCalls.push(this.token.methods.balance_of_private(address).request()); } const results = ( - await Promise.all(chunk(defaultCalls, 4).map(batch => new BatchCall(this.defaultWallet, batch).simulate())) + await Promise.all( + chunk(defaultCalls, 4).map(batch => + new BatchCall(this.defaultWallet, batch).simulate({ + skipTxValidation, + }), + ), + ) ).flat(); for (let i = 0; i < defaultLookups.length; i++) { expect(results[i]).toEqual(this.balanceOfPrivate(defaultLookups[i])); @@ -145,13 +157,15 @@ export class TokenSimulator { const wallet = this.lookupProvider.get(address.toString()); const asset = wallet ? this.token.withWallet(wallet) : this.token; - const actualPrivateBalance = await asset.methods.balance_of_private({ address }).simulate(); + const actualPrivateBalance = await asset.methods.balance_of_private({ address }).simulate({ + skipTxValidation, + }); expect(actualPrivateBalance).toEqual(this.balanceOfPrivate(address)); } } - public async check() { - await this.checkPublic(); - await this.checkPrivate(); + public async check(skipTxValidation: boolean = false) { + await this.checkPublic(skipTxValidation); + await this.checkPrivate(skipTxValidation); } } diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 972ef5ce916a..1b058896756b 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -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 { return await this.jobQueue.put(async () => { @@ -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.'); } }