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: expect proper duplicate nullifier error patterns in e2e tests #10256

Merged
merged 2 commits into from
Nov 27, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ describe('e2e_voting_contract', () => {
expect(await votingContract.methods.get_vote(candidate).simulate()).toBe(1n);

// We try voting again, but our TX is dropped due to trying to emit duplicate nullifiers
await expect(votingContract.methods.cast_vote(candidate).send().wait()).rejects.toThrow(
'Reason: Tx dropped by P2P node.',
);
// 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
await expect(
votingContract.methods.cast_vote(candidate).send({ skipPublicSimulation: true }).wait(),
).rejects.toThrow('Reason: Tx dropped by P2P node.');
});
});
});
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 @@ -16,7 +16,7 @@ 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: 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/;
export const DUPLICATE_NULLIFIER_ERROR = /dropped|duplicate nullifier|reverted|Nullifier collision/;
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
21 changes: 19 additions & 2 deletions yarn-project/simulator/src/public/public_tx_simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { strict as assert } from 'assert';

import { type AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
import { type AvmPersistableStateManager, AvmSimulator } from '../avm/index.js';
import { NullifierCollisionError } from '../avm/journal/nullifiers.js';
import { getPublicFunctionDebugName } from '../common/debug_fn_name.js';
import { ExecutorMetrics } from './executor_metrics.js';
import { type WorldStateDB } from './public_db_sources.js';
Expand Down Expand Up @@ -385,7 +386,15 @@ export class PublicTxSimulator {
*/
public async insertNonRevertiblesFromPrivate(context: PublicTxContext) {
const stateManager = context.state.getActiveStateManager();
await stateManager.writeSiloedNullifiersFromPrivate(context.nonRevertibleAccumulatedDataFromPrivate.nullifiers);
try {
await stateManager.writeSiloedNullifiersFromPrivate(context.nonRevertibleAccumulatedDataFromPrivate.nullifiers);
} catch (e) {
if (e instanceof NullifierCollisionError) {
throw new NullifierCollisionError(
`Nullifier collision encountered when inserting non-revertible nullifiers from private.\nDetails: ${e.message}\n.Stack:${e.stack}`,
);
}
}
}

/**
Expand All @@ -396,6 +405,14 @@ export class PublicTxSimulator {
// Fork the state manager so we can rollback to end of setup if app logic reverts.
context.state.fork();
const stateManager = context.state.getActiveStateManager();
await stateManager.writeSiloedNullifiersFromPrivate(context.revertibleAccumulatedDataFromPrivate.nullifiers);
try {
await stateManager.writeSiloedNullifiersFromPrivate(context.revertibleAccumulatedDataFromPrivate.nullifiers);
} catch (e) {
if (e instanceof NullifierCollisionError) {
throw new NullifierCollisionError(
`Nullifier collision encountered when inserting revertible nullifiers from private. Details:\n${e.message}\n.Stack:${e.stack}`,
);
}
}
}
}
Loading