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
4 changes: 2 additions & 2 deletions yarn-project/aztec-node/src/aztec-node/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { RollupValidationRequests } from '@aztec/stdlib/kernel';
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
import { mockTx } from '@aztec/stdlib/testing';
import { MerkleTreeId, PublicDataTreeLeaf, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
import { BlockHeader, GlobalVariables, MaxBlockNumber } from '@aztec/stdlib/tx';
import { BlockHeader, GlobalVariables, MaxBlockNumber, TX_ERROR_INVALID_BLOCK_NUMBER } from '@aztec/stdlib/tx';

import { readFileSync } from 'fs';
import { type MockProxy, mock } from 'jest-mock-extended';
Expand Down Expand Up @@ -219,7 +219,7 @@ describe('aztec node', () => {
// Tx with max block number < current block number should be invalid
expect(await node.isValidTx(invalidMaxBlockNumberMetadata)).toEqual({
result: 'invalid',
reason: ['Invalid block number'],
reason: [TX_ERROR_INVALID_BLOCK_NUMBER],
});
// Tx with max block number >= current block number should be valid
expect(await node.isValidTx(validMaxBlockNumberMetadata)).toEqual({ result: 'valid' });
Expand Down
14 changes: 3 additions & 11 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
* @param tx - The transaction to be submitted.
*/
public async sendTx(tx: Tx) {
await this.txQueue
.put(async () => {
await this.#sendTx(tx);
})
.catch(error => {
this.log.error(`Error sending tx`, { error });
});
await this.txQueue.put(() => this.#sendTx(tx));
}

async #sendTx(tx: Tx) {
Expand All @@ -480,10 +474,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
if (valid.result !== 'valid') {
const reason = valid.reason.join(', ');
this.metrics.receivedTx(timer.ms(), false);
this.log.warn(`Invalid tx ${txHash}: ${reason}`, { txHash });
// TODO(#10967): Throw when receiving an invalid tx instead of just returning
// throw new Error(`Invalid tx: ${reason}`);
return;
this.log.warn(`Received invalid tx ${txHash}: ${reason}`, { txHash });
throw new Error(`Invalid tx: ${reason}`);
}

await this.p2pClient!.sendTx(tx);
Expand Down
10 changes: 7 additions & 3 deletions yarn-project/end-to-end/src/e2e_block_building.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
TelemetryPublicTxSimulator,
} from '@aztec/simulator/server';
import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
import type { Tx } from '@aztec/stdlib/tx';
import { TX_ERROR_EXISTING_NULLIFIER, type Tx } from '@aztec/stdlib/tx';
import type { TelemetryClient } from '@aztec/telemetry-client';

import { jest } from '@jest/globals';
Expand Down Expand Up @@ -369,7 +369,9 @@ describe('e2e_block_building', () => {
it('private -> private', async () => {
const nullifier = Fr.random();
await contract.methods.emit_nullifier(nullifier).send().wait();
await expect(contract.methods.emit_nullifier(nullifier).send().wait()).rejects.toThrow('dropped');
await expect(contract.methods.emit_nullifier(nullifier).send().wait()).rejects.toThrow(
TX_ERROR_EXISTING_NULLIFIER,
);
});

it('public -> public', async () => {
Expand All @@ -391,7 +393,9 @@ describe('e2e_block_building', () => {
it('public -> private', async () => {
const nullifier = Fr.random();
await contract.methods.emit_nullifier_public(nullifier).send().wait();
await expect(contract.methods.emit_nullifier(nullifier).send().wait()).rejects.toThrow('dropped');
await expect(contract.methods.emit_nullifier(nullifier).send().wait()).rejects.toThrow(
TX_ERROR_EXISTING_NULLIFIER,
);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { StatefulTestContract } from '@aztec/noir-contracts.js/StatefulTest';
import { TestContractArtifact } from '@aztec/noir-contracts.js/Test';
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
import { TX_ERROR_EXISTING_NULLIFIER } from '@aztec/stdlib/tx';

import { DeployTest } from './deploy_test.js';

Expand Down Expand Up @@ -82,7 +83,7 @@ describe('e2e_deploy_contract legacy', () => {
const deployer = new ContractDeployer(TestContractArtifact, wallet);

await deployer.deploy().send({ contractAddressSalt }).wait({ wallet });
await expect(deployer.deploy().send({ contractAddressSalt }).wait()).rejects.toThrow(/dropped/);
await expect(deployer.deploy().send({ contractAddressSalt }).wait()).rejects.toThrow(TX_ERROR_EXISTING_NULLIFIER);
});

it('should not deploy a contract which failed the public part of the execution', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type AztecNode, BatchCall, Fr, type Logger, type Wallet } from '@aztec/
import { StatefulTestContract } from '@aztec/noir-contracts.js/StatefulTest';
import { TestContract } from '@aztec/noir-contracts.js/Test';
import { siloNullifier } from '@aztec/stdlib/hash';
import { TX_ERROR_EXISTING_NULLIFIER } from '@aztec/stdlib/tx';

import { DeployTest, type StatefulContractCtorArgs } from './deploy_test.js';

Expand Down Expand Up @@ -87,7 +88,7 @@ describe('e2e_deploy_contract private initialization', () => {
.constructor(...initArgs)
.send()
.wait(),
).rejects.toThrow(/dropped/);
).rejects.toThrow(TX_ERROR_EXISTING_NULLIFIER);
});

it('refuses to call a private function that requires initialization', async () => {
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/end-to-end/src/e2e_fees/fee_settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CheatCodes } from '@aztec/aztec.js/testing';
import { Fr } from '@aztec/foundation/fields';
import { TestContract } from '@aztec/noir-contracts.js/Test';
import type { GasSettings } from '@aztec/stdlib/gas';
import { TX_ERROR_INSUFFICIENT_FEE_PER_GAS } from '@aztec/stdlib/tx';

import { inspect } from 'util';

Expand Down Expand Up @@ -82,7 +83,7 @@ describe('e2e_fees fee settings', () => {
const sentWithNoPadding = txWithNoPadding.send();
const sentWithDefaultPadding = txWithDefaultPadding.send();
t.logger.info(`Awaiting txs`);
await expect(sentWithNoPadding.wait({ timeout: 30 })).rejects.toThrow(/dropped./i);
await expect(sentWithNoPadding.wait({ timeout: 30 })).rejects.toThrow(TX_ERROR_INSUFFICIENT_FEE_PER_GAS);
await sentWithDefaultPadding.wait({ timeout: 30 });
});
});
Expand Down
5 changes: 3 additions & 2 deletions yarn-project/end-to-end/src/e2e_max_block_number.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Fr, type PXE, type Wallet } from '@aztec/aztec.js';
import { TestContract } from '@aztec/noir-contracts.js/Test';
import { TX_ERROR_INVALID_BLOCK_NUMBER } from '@aztec/stdlib/tx';

import { setup } from './fixtures/utils.js';

Expand Down Expand Up @@ -72,7 +73,7 @@ describe('e2e_max_block_number', () => {
it('invalidates the transaction', async () => {
await expect(
contract.methods.set_tx_max_block_number(maxBlockNumber, enqueuePublicCall).send().wait(),
).rejects.toThrow('dropped');
).rejects.toThrow(TX_ERROR_INVALID_BLOCK_NUMBER);
});
});

Expand All @@ -88,7 +89,7 @@ describe('e2e_max_block_number', () => {
it('invalidates the transaction', async () => {
await expect(
contract.methods.set_tx_max_block_number(maxBlockNumber, enqueuePublicCall).send().wait(),
).rejects.toThrow('dropped');
).rejects.toThrow(TX_ERROR_INVALID_BLOCK_NUMBER);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type AccountWallet, type AztecAddress, Fr, type Logger } from '@aztec/aztec.js';
import { EasyPrivateVotingContract } from '@aztec/noir-contracts.js/EasyPrivateVoting';
import { TX_ERROR_EXISTING_NULLIFIER } from '@aztec/stdlib/tx';

import { setup } from './fixtures/utils.js';

Expand Down Expand Up @@ -33,10 +34,10 @@ describe('e2e_voting_contract', () => {
// We try voting again, but our TX is dropped due to trying to emit duplicate nullifiers
// first confirm that it fails simulation
await expect(votingContract.methods.cast_vote(candidate).send().wait()).rejects.toThrow(/Nullifier collision/);
// if we skip simulation, tx is dropped
// if we skip simulation, tx fails
await expect(
votingContract.methods.cast_vote(candidate).send({ skipPublicSimulation: true }).wait(),
).rejects.toThrow('Reason: Tx dropped by P2P node.');
).rejects.toThrow(TX_ERROR_EXISTING_NULLIFIER);
});
});
});
9 changes: 4 additions & 5 deletions yarn-project/end-to-end/src/e2e_prover/full.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { FeeJuicePortalAbi, RewardDistributorAbi, TestERC20Abi } from '@aztec/l1
import { Gas } from '@aztec/stdlib/gas';
import { PrivateKernelTailCircuitPublicInputs } from '@aztec/stdlib/kernel';
import { ClientIvcProof } from '@aztec/stdlib/proofs';
import { TX_ERROR_INVALID_PROOF } from '@aztec/stdlib/tx';

import TOML from '@iarna/toml';
import '@jest/globals';
Expand Down Expand Up @@ -285,8 +286,8 @@ describe('full_prover', () => {
sentPublicTx.wait({ timeout: 10, interval: 0.1 }),
]);

expect(String((results[0] as PromiseRejectedResult).reason)).toMatch(/Tx dropped by P2P node/);
expect(String((results[1] as PromiseRejectedResult).reason)).toMatch(/Tx dropped by P2P node/);
expect(String((results[0] as PromiseRejectedResult).reason)).toMatch(TX_ERROR_INVALID_PROOF);
expect(String((results[1] as PromiseRejectedResult).reason)).toMatch(TX_ERROR_INVALID_PROOF);
});

it(
Expand Down Expand Up @@ -352,9 +353,7 @@ describe('full_prover', () => {

// Assert that the large influx of invalid txs are rejected and do not ddos the node
for (let i = 0; i < NUM_INVALID_TXS; i++) {
const invalidTxReceipt = (results[i] as PromiseFulfilledResult<FieldsOf<TxReceipt>>).value;
expect(invalidTxReceipt.status).toBe(TxStatus.DROPPED);
expect(invalidTxReceipt.error).toMatch(/Tx dropped by P2P node/);
expect(String((results[i] as PromiseRejectedResult).reason)).toMatch(TX_ERROR_INVALID_PROOF);
}

// Assert that the valid tx is successfully sent and mined
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/fixtures/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const U128_UNDERFLOW_ERROR = "Assertion failed: attempt to subtract with
export const U128_OVERFLOW_ERROR = "Assertion failed: attempt to add with overflow 'self + other'";
export const BITSIZE_TOO_BIG_ERROR = "Assertion failed: call to assert_max_bit_size 'self.__assert_max_bit_size'";
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/5818): Make these a fixed error after transition.
export const DUPLICATE_NULLIFIER_ERROR = /dropped|duplicate nullifier|reverted|Nullifier collision/;
export const DUPLICATE_NULLIFIER_ERROR = /dropped|nullifier|reverted/i;
export const NO_L1_TO_L2_MSG_ERROR =
/No non-nullified L1 to L2 message found for message hash|Tried to consume nonexistent L1-to-L2 message/;
export const STATIC_CALL_STATE_MODIFICATION_ERROR =
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/guides/dapp_testing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('guides/dapp/testing', () => {
const provenCall2 = await call2.prove();

await provenCall1.send().wait();
await expect(provenCall2.send().wait()).rejects.toThrow(/dropped/);
await expect(provenCall2.send().wait()).rejects.toThrow(/dropped|nullifier/i);
// docs:end:tx-dropped
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fr } from '@aztec/foundation/fields';
import { mockTxForRollup } from '@aztec/stdlib/testing';
import type { AnyTx, TxValidationResult } from '@aztec/stdlib/tx';
import { type AnyTx, TX_ERROR_BLOCK_HEADER, type TxValidationResult } from '@aztec/stdlib/tx';

import { type MockProxy, mock, mockFn } from 'jest-mock-extended';

Expand Down Expand Up @@ -35,7 +35,7 @@ describe('BlockHeaderTxValidator', () => {
await expect(txValidator.validateTx(goodTx)).resolves.toEqual({ result: 'valid' } satisfies TxValidationResult);
await expect(txValidator.validateTx(badTx)).resolves.toEqual({
result: 'invalid',
reason: ['Block header not found'],
reason: [TX_ERROR_BLOCK_HEADER],
} satisfies TxValidationResult);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Fr } from '@aztec/foundation/fields';
import { createLogger } from '@aztec/foundation/log';
import { type AnyTx, Tx, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
import { type AnyTx, TX_ERROR_BLOCK_HEADER, Tx, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';

export interface ArchiveSource {
getArchiveIndices: (archives: Fr[]) => Promise<(bigint | undefined)[]>;
Expand All @@ -18,7 +18,7 @@ export class BlockHeaderTxValidator<T extends AnyTx> implements TxValidator<T> {
const [index] = await this.#archiveSource.getArchiveIndices([await tx.data.constants.historicalHeader.hash()]);
if (index === undefined) {
this.#log.warn(`Rejecting tx ${await Tx.getHash(tx)} for referencing an unknown block header`);
return { result: 'invalid', reason: ['Block header not found'] };
return { result: 'invalid', reason: [TX_ERROR_BLOCK_HEADER] };
}
return { result: 'valid' };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
import { ScopedLogHash } from '@aztec/stdlib/kernel';
import { ContractClassLog } from '@aztec/stdlib/logs';
import { mockTx } from '@aztec/stdlib/testing';
import type { Tx } from '@aztec/stdlib/tx';
import {
TX_ERROR_CALLDATA_COUNT_MISMATCH,
TX_ERROR_CALLDATA_COUNT_TOO_LARGE,
TX_ERROR_CONTRACT_CLASS_LOGS,
TX_ERROR_CONTRACT_CLASS_LOG_COUNT,
TX_ERROR_CONTRACT_CLASS_LOG_LENGTH,
TX_ERROR_INCORRECT_CALLDATA,
type Tx,
} from '@aztec/stdlib/tx';

import { DataTxValidator } from './data_validator.js';

Expand Down Expand Up @@ -98,7 +106,7 @@ describe('TxDataValidator', () => {

for (let i = 0; i < badTxSettings.length; i++) {
const badTx = await mockTx(2, badTxSettings[i]);
await expectInvalid(badTx, 'Total calldata too large for enqueued public calls');
await expectInvalid(badTx, TX_ERROR_CALLDATA_COUNT_TOO_LARGE);
}
});

Expand All @@ -110,8 +118,8 @@ describe('TxDataValidator', () => {

await expectValid(goodTxs);

await expectInvalid(badTxs[0], 'Incorrect calldata for public call');
await expectInvalid(badTxs[1], 'Incorrect calldata for public call');
await expectInvalid(badTxs[0], TX_ERROR_INCORRECT_CALLDATA);
await expectInvalid(badTxs[1], TX_ERROR_INCORRECT_CALLDATA);
});

it('rejects txs with mismatch calldata for revertible public calls', async () => {
Expand All @@ -122,8 +130,8 @@ describe('TxDataValidator', () => {

await expectValid(goodTxs);

await expectInvalid(badTxs[0], 'Incorrect calldata for public call');
await expectInvalid(badTxs[1], 'Incorrect calldata for public call');
await expectInvalid(badTxs[0], TX_ERROR_INCORRECT_CALLDATA);
await expectInvalid(badTxs[1], TX_ERROR_INCORRECT_CALLDATA);
});

it('rejects txs with mismatch calldata for teardown call', async () => {
Expand All @@ -134,8 +142,8 @@ describe('TxDataValidator', () => {

await expectValid(goodTxs);

await expectInvalid(badTxs[0], 'Incorrect calldata for public call');
await expectInvalid(badTxs[1], 'Incorrect calldata for public call');
await expectInvalid(badTxs[0], TX_ERROR_INCORRECT_CALLDATA);
await expectInvalid(badTxs[1], TX_ERROR_INCORRECT_CALLDATA);
});

it('rejects txs with mismatch number of calldata', async () => {
Expand All @@ -148,8 +156,8 @@ describe('TxDataValidator', () => {

await expectValid(goodTxs);

await expectInvalid(badTxs[0], 'Wrong number of calldata for public calls');
await expectInvalid(badTxs[1], 'Wrong number of calldata for public calls');
await expectInvalid(badTxs[0], TX_ERROR_CALLDATA_COUNT_MISMATCH);
await expectInvalid(badTxs[1], TX_ERROR_CALLDATA_COUNT_MISMATCH);
});

it('rejects txs with mismatch number of contract class logs', async () => {
Expand All @@ -169,8 +177,8 @@ describe('TxDataValidator', () => {

await expectValid(goodTxs);

await expectInvalid(badTxs[0], 'Mismatched number of contract class logs');
await expectInvalid(badTxs[1], 'Mismatched number of contract class logs');
await expectInvalid(badTxs[0], TX_ERROR_CONTRACT_CLASS_LOG_COUNT);
await expectInvalid(badTxs[1], TX_ERROR_CONTRACT_CLASS_LOG_COUNT);
});

// Can uncomment below if MAX_CONTRACT_CLASS_LOGS_PER_TX > 1:
Expand Down Expand Up @@ -201,8 +209,8 @@ describe('TxDataValidator', () => {

await expectValid(goodTxs);

await expectInvalid(badTxs[0], 'Mismatched contract class logs');
await expectInvalid(badTxs[1], 'Mismatched contract class logs');
await expectInvalid(badTxs[0], TX_ERROR_CONTRACT_CLASS_LOGS);
await expectInvalid(badTxs[1], TX_ERROR_CONTRACT_CLASS_LOGS);
});

it('rejects txs with mismatched contract class logs length', async () => {
Expand All @@ -217,7 +225,7 @@ describe('TxDataValidator', () => {

await expectValid(goodTxs);

await expectInvalid(badTxs[0], 'Mismatched contract class logs length');
await expectInvalid(badTxs[1], 'Mismatched contract class logs length');
await expectInvalid(badTxs[0], TX_ERROR_CONTRACT_CLASS_LOG_LENGTH);
await expectInvalid(badTxs[1], TX_ERROR_CONTRACT_CLASS_LOG_LENGTH);
});
});
Loading