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: making sent tx's fail at validation, rather than waiting for the non inclusion of the tx at a block #7841

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
8 changes: 6 additions & 2 deletions yarn-project/end-to-end/src/e2e_block_building.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,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(
'The simulated transaction is unable to be added to state and is invalid.',
Comment on lines +213 to +214
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to have the validators pass further context to the error, e.g. in this case explain that it's due to a duplicated nullifier?

);
});

it('public -> public', async () => {
Expand All @@ -232,7 +234,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(
'The simulated transaction is unable to be added to state and is invalid.',
);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ 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(
/The simulated transaction is unable to be added to state and is invalid./,
);
});

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 @@ -93,7 +93,7 @@ describe('e2e_deploy_contract private initialization', () => {
.constructor(...initArgs)
.send()
.wait(),
).rejects.toThrow(/dropped/);
).rejects.toThrow(/The simulated transaction is unable to be added to state and is invalid./);
});

it('refuses to call a private function that requires initialization', async () => {
Expand Down
4 changes: 2 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
Expand Up @@ -72,7 +72,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('The simulated transaction is unable to be added to state and is invalid.');
});
});

Expand All @@ -88,7 +88,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('The simulated transaction is unable to be added to state and is invalid.');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('e2e_voting_contract', () => {
// We try voting again, but our TX is dropped due to trying to emit duplicate nullifiers as the voting contract
// ignored our previous key rotation.
await expect(votingContract.methods.cast_vote(candidate).send().wait()).rejects.toThrow(
'Reason: Tx dropped by P2P node.',
'The simulated transaction is unable to be added to state and is invalid.',
);
});
});
Expand Down
8 changes: 6 additions & 2 deletions yarn-project/end-to-end/src/e2e_prover/full.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ 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(
/Error: The simulated transaction is unable to be added to state and is invalid./,
);
expect(String((results[1] as PromiseRejectedResult).reason)).toMatch(
/Error: The simulated transaction is unable to be added to state and is invalid./,
);
});
});
3 changes: 2 additions & 1 deletion yarn-project/end-to-end/src/fixtures/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export const U128_UNDERFLOW_ERROR = "Assertion failed: attempt to subtract with
export const U128_OVERFLOW_ERROR = "Assertion failed: attempt to add with overflow 'hi == high'";
export const BITSIZE_TOO_BIG_ERROR = "Assertion failed. '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/;
export const DUPLICATE_NULLIFIER_ERROR =
/dropped|duplicate nullifier|reverted|The simulated transaction is unable to be added to state and is invalid./;
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
4 changes: 3 additions & 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 @@ -214,7 +214,9 @@ describe('guides/dapp/testing', () => {
await call2.prove();

await call1.send().wait();
await expect(call2.send().wait()).rejects.toThrow(/dropped/);
await expect(call2.send().wait()).rejects.toThrow(
/The simulated transaction is unable to be added to state and is invalid./,
);
// docs:end:tx-dropped
});

Expand Down
5 changes: 5 additions & 0 deletions yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,11 @@ export class PXEService implements PXE {
if (await this.node.getTxEffect(txHash)) {
throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
}

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

this.log.info(`Sending transaction ${txHash}`);
await this.node.sendTx(tx);
this.log.info(`Sent transaction ${txHash}`);
Expand Down
Loading