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(avm): nullifier handling #5488

Merged
merged 1 commit into from
Apr 4, 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 @@ -316,6 +316,11 @@ contract AvmTest {
context.nullifier_exists(nullifier)
}

#[aztec(public-vm)]
fn assert_nullifier_exists(nullifier: Field) {
assert(context.nullifier_exists(nullifier));
}

// Use the standard context interface to emit a new nullifier
#[aztec(public-vm)]
fn emit_nullifier_and_check(nullifier: Field) {
Expand Down
15 changes: 13 additions & 2 deletions yarn-project/end-to-end/src/e2e_avm_simulator.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AztecAddress, TxStatus, type Wallet } from '@aztec/aztec.js';
import { AztecAddress, Fr, TxStatus, type Wallet } from '@aztec/aztec.js';
import { AvmTestContract } from '@aztec/noir-contracts.js';

import { jest } from '@jest/globals';
Expand Down Expand Up @@ -51,9 +51,20 @@ describe('e2e_avm_simulator', () => {
});

describe('Nullifiers', () => {
it('Emit and check', async () => {
// Nullifier will not yet be siloed by the kernel.
it('Emit and check in the same tx', async () => {
const tx = await avmContact.methods.emit_nullifier_and_check(123456).send().wait();
expect(tx.status).toEqual(TxStatus.MINED);
});

// Nullifier will have been siloed by the kernel, but we check against the unsiloed one.
it('Emit and check in separate tx', async () => {
const nullifier = new Fr(123456);
let tx = await avmContact.methods.new_nullifier(nullifier).send().wait();
expect(tx.status).toEqual(TxStatus.MINED);

tx = await avmContact.methods.assert_nullifier_exists(nullifier).send().wait();
expect(tx.status).toEqual(TxStatus.MINED);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
L2ToL1Message,
type ReadRequest,
SideEffect,
type SideEffectLinkedToNoteHash,
SideEffectLinkedToNoteHash,
} from '@aztec/circuits.js';
import { Fr } from '@aztec/foundation/fields';

Expand Down Expand Up @@ -96,7 +96,9 @@ export function temporaryConvertAvmResults(
const nestedExecutions: PublicExecutionResult[] = [];
const nullifierReadRequests: ReadRequest[] = [];
const nullifierNonExistentReadRequests: ReadRequest[] = [];
const newNullifiers: SideEffectLinkedToNoteHash[] = [];
const newNullifiers: SideEffectLinkedToNoteHash[] = newWorldState.newNullifiers.map(
(nullifier, i) => new SideEffectLinkedToNoteHash(nullifier.toField(), Fr.zero(), new Fr(i + 1)),
);
const unencryptedLogs = UnencryptedFunctionL2Logs.empty();
const newL2ToL1Messages = newWorldState.newL1Messages.map(() => L2ToL1Message.empty());
// TODO keep track of side effect counters
Expand Down
Loading