Skip to content

feat(avm)!: Note hash exists opcode#15699

Merged
sirasistant merged 12 commits into
nextfrom
arv/notehash_exists
Jul 16, 2025
Merged

feat(avm)!: Note hash exists opcode#15699
sirasistant merged 12 commits into
nextfrom
arv/notehash_exists

Conversation

@sirasistant

@sirasistant sirasistant commented Jul 14, 2025

Copy link
Copy Markdown
Contributor

Implement note hash exists, modify note hash tree check to expose a exists boolean that is one when the note hash doesn't match the leaf value

@sirasistant sirasistant requested a review from dbanks12 July 15, 2025 12:07

@dbanks12 dbanks12 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Just some comment nits and a request for @jeanmon to take a look at a constraint.

Comment on lines +133 to +136

pol PREV_LEAF_VALUE_UNIQUE_NOTE_HASH_DIFF = prev_leaf_value - unique_note_hash;
pol commit prev_leaf_value_unique_note_hash_diff_inv;
sel * (PREV_LEAF_VALUE_UNIQUE_NOTE_HASH_DIFF * (exists * (1 - prev_leaf_value_unique_note_hash_diff_inv) + prev_leaf_value_unique_note_hash_diff_inv) - 1 + exists) = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd comment "exists = 1 if prev_leaf_value == unique_note_hash"

Comment on lines 523 to +529
auto& memory = context.get_memory();
get_gas_tracker().consume_gas();

auto slot = memory.get(slot_addr);
set_and_validate_inputs(opcode, { slot });

get_gas_tracker().consume_gas();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Was this just a bug?

@dbanks12 dbanks12 Jul 15, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see consume_gas before set_and_validate_inputs in some* cases....

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's wrong (before) most likely. Gas comes after registers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes I saw that and thought it could create trouble

Comment on lines +21 to +26
pol commit note_hash_leaf_in_range;

pol LEAF_INDEX_GTE_NOTE_HASH_LEAF_COUNT = register[1] - constants.NOTE_HASH_TREE_LEAF_COUNT;
pol LEAF_INDEX_LT_NOTE_HASH_LEAF_COUNT = constants.NOTE_HASH_TREE_LEAF_COUNT - register[1] - 1;
pol commit note_hash_leaf_index_leaf_count_cmp_diff;
sel_execute_notehash_exists * ((LEAF_INDEX_LT_NOTE_HASH_LEAF_COUNT - LEAF_INDEX_GTE_NOTE_HASH_LEAF_COUNT) * note_hash_leaf_in_range + LEAF_INDEX_GTE_NOTE_HASH_LEAF_COUNT - note_hash_leaf_index_leaf_count_cmp_diff) = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's not clear to me exactly what this is doing. I imagine it's constraining note_hash_leaf_in_range, but i think it deserves a comment. And maybe @jeanmon can just take a brief look at it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is using a standard comparison between range constrained numbers https://hackmd.io/moq6viBpRJeLpWrHAogCZw?view#Comparison-between-range-constrained-numbers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a comment

@jeanmon jeanmon Jul 16, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is a standard constraint @dbanks12.
@sirasistant I do not see any boolean condition on note_hash_leaf_in_range though

As another comment, you might want to use the new gt gadget for doing this. Maybe we can discuss with the team if we want to migrate all these instances to the new gt gadget.

@sirasistant sirasistant Jul 16, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As another comment, you might want to use the new gt gadget for doing this. Maybe we can discuss with the team if we want to migrate all these instances to the new gt gadget.

It's not merged right?

I do not see any boolean condition on note_hash_leaf_in_range though

will add!

@sirasistant sirasistant enabled auto-merge July 16, 2025 09:10
@sirasistant sirasistant added this pull request to the merge queue Jul 16, 2025
Merged via the queue into next with commit f7d4acf Jul 16, 2025
4 checks passed
@sirasistant sirasistant deleted the arv/notehash_exists branch July 16, 2025 10:35
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.

4 participants