Skip to content

Conversation

@usagi32
Copy link

@usagi32 usagi32 commented Oct 7, 2025

Motivation

for this issue in leo ProvableHQ/leo#28721

This PR adds a new 'in' instruction support at the synthesizer level. Without this developers would have to do a verbose unroll of the entire array and also instruction costs would increase for contracts for multiple checks, so this saves that.

Some notes:

  • The tests currently only checks for single dimensional literal arrays as for multi dimensional arrays and struct struct arrays, it would require a slight different infrastructure then the rest of the tests. But also there's no reason implementation won't work for all kinds of arrays.
  • Maybe the cost function can be optimized more, for e.g. rather than a constant, some heuristic approximation or maybe even linear multiple of the recursive array length, considering all the the inner members in structs etc.

If this PR is approved, I would also add the support in leo as well.

Test Plan

Added new tests

};

// Check if the array contains the value.
let output = (0..array.len()).any(|index| val.is_equal(&array[index]).eject_value());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not believe that this is sufficiently constrained. Generally, eject_value needs to be used with care in a circuit. One safe way to implement this is to construct an "or" expression over all of the equality operations, e.g, (val == arr[0] || val == arr[1] || ... || val == arr[k])

Copy link
Author

Choose a reason for hiding this comment

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

done

@usagi32 usagi32 requested a review from d0cd November 5, 2025 22:42
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