Skip to content

fix: read boundary sentinel values from the sorted keys - #26

Open
iAmMichaelConnor wants to merge 1 commit into
mike/02-fix-public-apifrom
mike/03-fix-boundary-values
Open

iAmMichaelConnor wants to merge 1 commit into
mike/02-fix-public-apifrom
mike/03-fix-boundary-values

Conversation

@iAmMichaelConnor

Copy link
Copy Markdown
Contributor

Stacked on #25; please review and merge in order.

What

Key 0 and maximum are also the start and end sentinels, which must hold the same values as
the input entries for those keys. create copied the value for key 0 only when 0 was the
first input key, and the value for maximum only when it was the last input key. Otherwise
the sentinel held the default value, so:

  • get(0) returned 0 when key 0 was not first in the input (honest lookups find the
    sentinel first);
  • a prover could point the lookup hint for maximum at the end sentinel and read 0.

After sorting, those keys can only be keys[1] and keys[M], so check those instead. This
is cheaper than scanning the inputs and applies to both array types.

Testing

New test_sparse_lookup_unsorted_boundary_keys (create([9, 5, 0], ...)) checks both
lookups and both sentinel values; get(0) fails on master. nargo test (Noir 1.0.0):
18/18 passed.

create() copied the value of key 0 into the start sentinel only when 0
was the first input key, and the value of `maximum` into the end
sentinel only when it was the last input key. Otherwise the sentinel
held the default value, so get(0) returned 0 and a prover could choose
the sentinel slot to read `maximum` as 0. After sorting, those keys
can only be keys[1] and keys[M], so check those instead.
@TomAFrench
TomAFrench force-pushed the mike/03-fix-boundary-values branch from 2a1cb29 to 2ad0621 Compare November 3, 2026 03:53
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.

1 participant