fix(circuits)!: Ensure global uniqueness of side effect counters #18679
+3,553
−926
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, we were only checking local uniqueness of counters (within a single sideffect type of a single call) to keep gate counts low.
However, some code in the reset circuits assumes global uniqueness of counters, and in general, this is a big source of issues. This PR implements validation for global uniqueness of sideffect counters, by checking in a call request that all counters of all sideffects are unique, that they are within the call sideffect counter bounds, and that they don't fall within the allocated counters for any nested call. This three things ensure that no sideffect counters can repeat in a TX, other than padded side effects that are always injected with MAX_U32_VALUE counter.
The cost of verifying global uniqueness of counters this way is ~5000 gates (~10% of init, ~5% of inner)