Skip to content

Commit

Permalink
fix(avm): nullifier handling (#5488)
Browse files Browse the repository at this point in the history
Add nullifiers when converting state.

We still need to do more work to unify the nullifier APIs.
  • Loading branch information
fcarreiro authored Apr 4, 2024
1 parent ceacba6 commit bc8211d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
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

0 comments on commit bc8211d

Please sign in to comment.