fix: addresses logic audit findings #22304
Open
suyash67 wants to merge 4 commits intomerge-train/barretenbergfrom
Open
fix: addresses logic audit findings #22304suyash67 wants to merge 4 commits intomerge-train/barretenbergfrom
suyash67 wants to merge 4 commits intomerge-train/barretenbergfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
L1: ACIR
num_bitsValidationStatus: won't fix
It is true that
create_logic_constraintusesBB_ASSERT(which aborts) rather than throwing an exception whennum_bitsis invalid.BB_ASSERTis the standard pattern throughout barretenberg for structural invariant checks. Additionally, thenum_bitsvalue originates from Noir'sIntegerBitSizeenum, which restricts values to {1, 8, 16, 32, 64, 128} at the compiler level, so invalid values cannot reach this code through normal operation.L2: OriginTag Provenance
Status: fixed 0f3ca1c
create_logic_constraintwas not propagatingOriginTagwhen converting constant inputs to witnesses, or when returning the final result. Tags are now copied onto the witness before recursing (for both the left-constant and right-constant paths), and the final accumulated result is tagged with the merged tag of both operands. Note we do not propagate tags to the chunks because these are intermediate circuit variables that are not used outside of logic.L3: Builder Context Validation
Status: fixed 249bfdc
When both inputs are witnesses, the code extracted the builder context from only one operand without verifying both refer to the same builder. Added
validate_context<Builder>(a.get_context(), b.get_context())to assert consistency, matching the pattern used in other stdlib primitives.L4: Write-VK Mode Guard for Constant Inputs
Status: fixed 5b3d4b8
In write-VK mode, when both inputs are constants,
create_logic_constraintreturns a constantfield_t. The ACIR bridge then attemptsassert_equalagainst a result witness that holds a dummy zero, causing a spurious failure. The fix usesbuilder.set_variable()to patch the result witness with the correct computed value before the equality check.I1: Witness Bounds Checks Are Debug-Only
Status: acknowledged, will be fixed later
The witness index bounds checks in
get_variable()useBB_ASSERT_DEBUG, which is compiled out in release builds. This is known and it affects every circuit component that callsget_variable(), not just the logic gadget. We are discussing this the noir team if it can be exploited in any meaningful way. Regardless, we will enable these asserts in release mode soon after ensuring no significant hit in performance because of the asserts.I2: Oversized Plookup Table
Status: won't fix
The code always uses
UINT32_XOR/UINT32_ANDplookup tables even when the last chunk is smaller than 32 bits. Smaller tables (UINT8, UINT16) exist and would use fewer sub-lookups. However, this is a minor optimization that would change the circuit structure, which we want to avoid at this point. The existing explicit range constraint on the last chunk ensures correctness regardless of table size.I3: Operator Precedence Bug in Test
Status: fixed — 2a597fb
The test computed
1 << num_bits - 1intending "all bits set" ((1 << num_bits) - 1), but C++ precedence evaluates it as1 << (num_bits - 1)(a single bit). Fornum_bits = 8, this gives128instead of255. Corrected the test.I4: Redundant Range Constraints
Status: won't fix
Yes there could be cases of redundant range constraints (on the noir side as well as barretenberg) but we prefer to have redundancy over missing a range constraint. This was a good find but we decided to not use the optimisation.