Skip to content

feat: dedup arrays before reset#20473

Open
LeilaWang wants to merge 2 commits intonextfrom
lw/dedup_before_reset
Open

feat: dedup arrays before reset#20473
LeilaWang wants to merge 2 commits intonextfrom
lw/dedup_before_reset

Conversation

@LeilaWang
Copy link
Contributor

Deduplicate note_hash_read_requests, nullifier_read_requests and key_validation_requests_and_generators before validating the requests.

The cost for dudup:

  • read requests: ~1.5k
  • key validation requests: ~3.4k

@LeilaWang LeilaWang force-pushed the lw/dedup_before_reset branch from 7869b93 to 519a15c Compare February 13, 2026 10:23
Copy link
Contributor

@iAmMichaelConnor iAmMichaelConnor left a comment

Choose a reason for hiding this comment

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

Not approving yet, because I don't know if we want it, and Nico will have opinions

Comment on lines -16 to -18
where
T: Empty,
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this change made? (I'm genuinely curious)

are_duplicates: fn[Env](T, T) -> bool,
) {
// Each original item must match its hinted deduped item.
original.for_each_i(|item, i| {
Copy link
Contributor

Choose a reason for hiding this comment

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

Waaaait a minute... you're using the helper function that you hate! 😲

/// Two read requests are considered duplicates if they read the same value from the same contract.
/// The counter (when the read happened) is irrelevant for dedup purposes.
pub fn are_duplicate_read_requests(a: Scoped<Counted<Field>>, b: Scoped<Counted<Field>>) -> bool {
(a.inner.inner == b.inner.inner) & (a.contract_address == b.contract_address)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still amazed that Noir makes this the same constraint cost as:

assert_eq(a.inner.inner, b.inner.inner);
assert_eq(a.contract_address, b.contract_address);

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.

2 participants