Skip to content

feat!: constrain AVM EmitNullifier opcode#15853

Merged
dbanks12 merged 1 commit intomerge-train/avmfrom
db/emitnullifier
Jul 22, 2025
Merged

feat!: constrain AVM EmitNullifier opcode#15853
dbanks12 merged 1 commit intomerge-train/avmfrom
db/emitnullifier

Conversation

@dbanks12
Copy link
Contributor

@dbanks12 dbanks12 commented Jul 21, 2025

Also adds handling for state-mutation attempts in C++ simulation.

Followup work:

  1. Constrain errors when attempting to mutate state or emit side effects in a static context.

Copy link
Contributor Author

dbanks12 commented Jul 21, 2025

Comment on lines 563 to 568

if (context.get_is_static()) {
throw OpcodeExecutionException("SSTORE: Cannot write to storage in static context");
}

if (!was_slot_written_before &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was missing from these other opcodes.

NiceMock<MockPoseidon2> poseidon2;
NiceMock<MockMerkleCheck> merkle_check;
NiceMock<MockRangeCheck> range_check;
NiceMock<MockFieldGreaterThan> field_gt;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should migrate these to StrictMocks. It looks like we actually do care about what these things do (looking at the EXPECTs that follow). This will cover us in case there are any missed expectations whose default values might impact our control flow.

FYI there are also now "fakes" (FakePoseidon and FakeGt) that might be helpful for you too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm happy to switch to StrictMocks. What exactly is the difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GPT says
image

Copy link
Contributor

Choose a reason for hiding this comment

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

I said this in a standup when you were OOO: NiceMock is almost always not what you want. It returns some default value which can change your control flow. StrictMock is what you want. If you are making 0 calls, strictmock will be fine. If you are making > 0 calls, then it is expected that the result of the call modifies your control flow so you want to set an EXPECT_CALL. The only case that might make sense for a NiceMock is when you call some void assert_... which will not change anything, but ideally you can just use StrickMock unless it becomes too verbose.

.WillOnce(Return(siloed_nullifier))
.WillOnce(Return(low_leaf_hash))
.WillOnce(Return(updated_low_leaf_hash))
.WillOnce(Return(new_leaf_hash));
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW i think this is a good use of the poseidon2 mock

uint32_t prev_num_nullifiers_emitted = 2;

// mock the nullifier > low leaf nullifier to return true
EXPECT_CALL(field_gt, ff_gt).WillOnce(Return(true));
Copy link
Contributor

Choose a reason for hiding this comment

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

not necessarily for this PR but looks like a FakeFieldGT might be useful at some point later

Base automatically changed from merge-train/avm to next July 22, 2025 15:13
@dbanks12 dbanks12 changed the base branch from next to graphite-base/15853 July 22, 2025 15:21
@dbanks12 dbanks12 force-pushed the graphite-base/15853 branch from 851f8be to 7aca68a Compare July 22, 2025 15:21
@dbanks12 dbanks12 changed the base branch from graphite-base/15853 to merge-train/avm July 22, 2025 15:21
@dbanks12 dbanks12 merged commit 8a7c9c2 into merge-train/avm Jul 22, 2025
7 of 9 checks passed
@dbanks12 dbanks12 deleted the db/emitnullifier branch July 22, 2025 15:22
@AztecBot AztecBot mentioned this pull request Jul 22, 2025
github-merge-queue bot pushed a commit that referenced this pull request Jul 23, 2025
See
[merge-train-readme.md](https://github.com/AztecProtocol/aztec-packages/blob/next/.github/workflows/merge-train-readme.md).

BEGIN_COMMIT_OVERRIDE
feat!: constrain AVM EmitNullifier opcode (#15853)
feat(avm)!: ecc add error handling (#15781)
END_COMMIT_OVERRIDE

---------

Co-authored-by: AztecBot <tech@aztecprotocol.com>
Co-authored-by: David Banks <47112877+dbanks12@users.noreply.github.com>
Co-authored-by: Ilyas Ridhuan <ilyas@aztecprotocol.com>
Co-authored-by: MirandaWood <miranda@aztecprotocol.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants