Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
relation_failure.test.cpp File Reference

Failure/negative tests for Translator scattered masking layout. More...

Go to the source code of this file.

Classes

class  TranslatorRelationFailureTests
 

Functions

 TEST_F (TranslatorRelationFailureTests, PermutationFailsOnConcatenatedCorruption)
 Corrupt a non-masking value in concatenated_range_constraints_0, creating a multiset mismatch (numerator changes but ordered/denominator is not updated).
 
 TEST_F (TranslatorRelationFailureTests, DeltaRangeFailsOnMaxValueCorruption)
 Corrupt the value at lagrange_real_last position (circuit_size - MAX_RANDOM - 1) in an ordered poly. Subrelations 5-9 check that ordered[real_last] == 2^14 - 1; this is the only position they are active.
 
 TEST_F (TranslatorRelationFailureTests, PermutationFailsOnZPermCorruption)
 Corrupt z_perm at a mid position, breaking the running product consistency.
 
 TEST_F (TranslatorRelationFailureTests, PermutationFailsOnZPermNonZeroAtFirstRow)
 Test that z_perm must be zero at the lagrange_first row.
 
 TEST_F (TranslatorRelationFailureTests, DeltaRangeFailsOnOrderedMaskingBoundary)
 Corrupt ordered poly at position circuit_size - MAX_RANDOM - 2, the last row where the delta constraint is enforced. This is right before lagrange_real_last + lagrange_ordered_masking kicks in.
 
 TEST_F (TranslatorRelationFailureTests, DeltaRangeFailsOnNegativeDelta)
 Swap two adjacent sorted values to create a negative delta (descending pair). In the field, ordered[i+1] - ordered[i] becomes a huge element, not in {0,1,2,3}.
 
 TEST_F (TranslatorRelationFailureTests, DeltaRangeFailsOnDeltaFour)
 Set delta = 4 (smallest forbidden step) between adjacent ordered values. D ∈ {0,1,2,3} passes; D = 4 is the exact boundary that must fail.
 
 TEST_F (TranslatorRelationFailureTests, DeltaRangeFailsOnFirstSortedValueTooLarge)
 Corrupt position 1 in an ordered poly (the first real sorted value after virtual zero at pos 0). If ordered[1] > 3, the delta from 0 to ordered[1] violates the step constraint.
 
 TEST_F (TranslatorRelationFailureTests, DeltaRangeFailsOnFifthOrderedPolyCorruption)
 Corrupt ordered_range_constraints_4 (the 5th ordered poly, built from the extra denominator). This poly is constructed from a different code path than the first 4. Verify subrelation 4 catches it.
 
 TEST_F (TranslatorRelationFailureTests, PermutationFailsOnOrderedCorruption)
 Corrupt a value in ordered_range_constraints_0 (denominator side of the permutation), creating a multiset mismatch without updating z_perm.
 
 TEST_F (TranslatorRelationFailureTests, InRangeValueInMaskingFlowsToOrderedTail)
 Place a small in-range value (42) at a wire masking position and verify it flows correctly through concatenation into the ordered polynomial's contiguous masking tail.
 
 TEST_F (TranslatorRelationFailureTests, PermutationFailsOnExtraNumeratorCorruption)
 Corrupt ordered_extra_range_constraints_numerator (the 5th factor in the permutation numerator), creating a multiset mismatch without updating z_perm.
 
 TEST_F (TranslatorRelationFailureTests, AccumulatorTransferFailsOnOddRowCorruption)
 Corrupt an accumulator limb at an interior odd row to break the transfer chain. Subrelations 0-3 enforce acc[odd] == acc[odd+1] at odd minicircuit rows (except the last).
 
 TEST_F (TranslatorRelationFailureTests, AccumulatorTransferFailsOnZeroInitCorruption)
 Set a non-zero accumulator at the last minicircuit row where zero-init is enforced. Subrelations 4-7 check acc * lagrange_last_in_minicircuit == 0 at position MINI - NUM_MASKED - 1 (= 8187).
 
 TEST_F (TranslatorRelationFailureTests, AccumulatorTransferFailsOnResultMismatch)
 Mismatch accumulated_result[0] with the actual accumulator value at RESULT_ROW (= 8). Subrelations 8-11 check (acc - expected) * lagrange_result_row == 0.
 
 TEST_F (TranslatorRelationFailureTests, AccumulatorTransferPassesWithMaskingRegionValues)
 Place arbitrary non-zero values in accumulator limbs at masking positions ([2,7] and [8188,8191]). Verify the relation still passes — masking regions must not leak into the accumulator transfer relation.
 
 TEST_F (TranslatorRelationFailureTests, AccumulatorTransferFailsAtFirstTransferRow)
 Corrupt the accumulator at row 9 (first odd row in minicircuit, left boundary of transfer chain). lagrange_odd_in_minicircuit is first active at RESULT_ROW + 1 = 9.
 
 TEST_F (TranslatorRelationFailureTests, AccumulatorTransferFailsAtLastTransferRow)
 Corrupt the accumulator at the penultimate odd row (right boundary of the transfer chain, just before the zero-init row 8187). Row 8185 is the last odd row where the transfer subrelation is active (lagrange_odd = 1, lagrange_last = 0).
 
 TEST_F (TranslatorRelationFailureTests, PermutationFailsOnConcatenatedBlockBoundaryCorruption)
 Place a non-zero value at position j*MINI (block boundary, below start_index) in a concatenated poly. This position is normally zero because wire data starts at start_index=1 within each block. Changing it alters the permutation numerator without updating ordered polys.
 
 TEST_F (TranslatorRelationFailureTests, NonNativeFieldRejectsAccumulatorAlias)
 Regression for AztecProtocol/barretenberg#2492: verify that the accumulator alias attack (current_acc += q, quotient -= 1) is caught by the higher carry check.
 

Detailed Description

Failure/negative tests for Translator scattered masking layout.

Each test builds a fully valid TranslatorProvingKey (via build_valid_translator_state()), asserts that the target relation passes on clean data, then corrupts a specific witness value and verifies detection. All corruptions are witness-level only.

Permutation relation (TranslatorPermutationRelation) — 5 tests: PermutationFailsOnConcatenatedCorruption — numerator (concatenated poly, block interior) PermutationFailsOnZPermCorruption — running product (z_perm mid-circuit) PermutationFailsOnOrderedCorruption — denominator (ordered poly, interior) PermutationFailsOnExtraNumeratorCorruption — 5th numerator factor (extra range numerator) PermutationFailsOnConcatenatedBlockBoundaryCorruption — block boundary (position j*MINI, zero gap)

Delta range relation (TranslatorDeltaRangeConstraintRelation) — 6 tests: DeltaRangeFailsOnMaxValueCorruption — real_last position != 2^14-1 (subrelations 5-9) DeltaRangeFailsOnOrderedMaskingBoundary — last enforced row before masking region DeltaRangeFailsOnNegativeDelta — descending pair (D < 0 in field) DeltaRangeFailsOnDeltaFour — smallest forbidden step (D = 4) DeltaRangeFailsOnFirstSortedValueTooLarge — position 0->1 transition (virtual zero start) DeltaRangeFailsOnFifthOrderedPolyCorruption — 5th ordered poly (different build path)

Accumulator transfer relation (TranslatorAccumulatorTransferRelation) — 6 tests: AccumulatorTransferFailsOnOddRowCorruption — interior odd row (transfer chain) AccumulatorTransferFailsOnZeroInitCorruption — last minicircuit row (zero-init) AccumulatorTransferFailsOnResultMismatch — result row vs expected (subrelations 8-11) AccumulatorTransferPassesWithMaskingRegionValues — masking regions excluded by selectors AccumulatorTransferFailsAtFirstTransferRow — row 9 (left boundary of transfer chain) AccumulatorTransferFailsAtLastTransferRow — row 8185 (right boundary before zero-init)

Non-native field relation (TranslatorNonNativeFieldRelation) — 1 test: NonNativeFieldRejectsAccumulatorAlias — #2492 regression: acc += q, quot -= 1 caught by higher carry check (subrelation 1)

Pipeline correctness — 1 test: InRangeValueInMaskingFlowsToOrderedTail — trace FF(42) from wire masking through concatenation into ordered poly tail

Definition in file relation_failure.test.cpp.

Function Documentation

◆ TEST_F() [1/20]

TEST_F ( TranslatorRelationFailureTests  ,
AccumulatorTransferFailsAtFirstTransferRow   
)

Corrupt the accumulator at row 9 (first odd row in minicircuit, left boundary of transfer chain). lagrange_odd_in_minicircuit is first active at RESULT_ROW + 1 = 9.

Definition at line 699 of file relation_failure.test.cpp.

◆ TEST_F() [2/20]

TEST_F ( TranslatorRelationFailureTests  ,
AccumulatorTransferFailsAtLastTransferRow   
)

Corrupt the accumulator at the penultimate odd row (right boundary of the transfer chain, just before the zero-init row 8187). Row 8185 is the last odd row where the transfer subrelation is active (lagrange_odd = 1, lagrange_last = 0).

Definition at line 723 of file relation_failure.test.cpp.

◆ TEST_F() [3/20]

TEST_F ( TranslatorRelationFailureTests  ,
AccumulatorTransferFailsOnOddRowCorruption   
)

Corrupt an accumulator limb at an interior odd row to break the transfer chain. Subrelations 0-3 enforce acc[odd] == acc[odd+1] at odd minicircuit rows (except the last).

Definition at line 595 of file relation_failure.test.cpp.

◆ TEST_F() [4/20]

TEST_F ( TranslatorRelationFailureTests  ,
AccumulatorTransferFailsOnResultMismatch   
)

Mismatch accumulated_result[0] with the actual accumulator value at RESULT_ROW (= 8). Subrelations 8-11 check (acc - expected) * lagrange_result_row == 0.

Definition at line 640 of file relation_failure.test.cpp.

◆ TEST_F() [5/20]

TEST_F ( TranslatorRelationFailureTests  ,
AccumulatorTransferFailsOnZeroInitCorruption   
)

Set a non-zero accumulator at the last minicircuit row where zero-init is enforced. Subrelations 4-7 check acc * lagrange_last_in_minicircuit == 0 at position MINI - NUM_MASKED - 1 (= 8187).

Definition at line 618 of file relation_failure.test.cpp.

◆ TEST_F() [6/20]

TEST_F ( TranslatorRelationFailureTests  ,
AccumulatorTransferPassesWithMaskingRegionValues   
)

Place arbitrary non-zero values in accumulator limbs at masking positions ([2,7] and [8188,8191]). Verify the relation still passes — masking regions must not leak into the accumulator transfer relation.

This is the key test for the new concatenated layout: lagrange_odd_in_minicircuit is only active at odd positions in [RESULT_ROW, MINI - NUM_MASKED), lagrange_last_in_minicircuit at 8187, and lagrange_result_row at 8. None of these cover masking positions [2,7] or [8188,8191]. If any selector were accidentally set at a masking position, non-zero accumulator values there would cause a failure.

Definition at line 667 of file relation_failure.test.cpp.

◆ TEST_F() [7/20]

TEST_F ( TranslatorRelationFailureTests  ,
DeltaRangeFailsOnDeltaFour   
)

Set delta = 4 (smallest forbidden step) between adjacent ordered values. D ∈ {0,1,2,3} passes; D = 4 is the exact boundary that must fail.

Definition at line 384 of file relation_failure.test.cpp.

◆ TEST_F() [8/20]

TEST_F ( TranslatorRelationFailureTests  ,
DeltaRangeFailsOnFifthOrderedPolyCorruption   
)

Corrupt ordered_range_constraints_4 (the 5th ordered poly, built from the extra denominator). This poly is constructed from a different code path than the first 4. Verify subrelation 4 catches it.

Definition at line 431 of file relation_failure.test.cpp.

◆ TEST_F() [9/20]

TEST_F ( TranslatorRelationFailureTests  ,
DeltaRangeFailsOnFirstSortedValueTooLarge   
)

Corrupt position 1 in an ordered poly (the first real sorted value after virtual zero at pos 0). If ordered[1] > 3, the delta from 0 to ordered[1] violates the step constraint.

Definition at line 408 of file relation_failure.test.cpp.

◆ TEST_F() [10/20]

TEST_F ( TranslatorRelationFailureTests  ,
DeltaRangeFailsOnMaxValueCorruption   
)

Corrupt the value at lagrange_real_last position (circuit_size - MAX_RANDOM - 1) in an ordered poly. Subrelations 5-9 check that ordered[real_last] == 2^14 - 1; this is the only position they are active.

Definition at line 222 of file relation_failure.test.cpp.

◆ TEST_F() [11/20]

TEST_F ( TranslatorRelationFailureTests  ,
DeltaRangeFailsOnNegativeDelta   
)

Swap two adjacent sorted values to create a negative delta (descending pair). In the field, ordered[i+1] - ordered[i] becomes a huge element, not in {0,1,2,3}.

Definition at line 359 of file relation_failure.test.cpp.

◆ TEST_F() [12/20]

TEST_F ( TranslatorRelationFailureTests  ,
DeltaRangeFailsOnOrderedMaskingBoundary   
)

Corrupt ordered poly at position circuit_size - MAX_RANDOM - 2, the last row where the delta constraint is enforced. This is right before lagrange_real_last + lagrange_ordered_masking kicks in.

At this position: lagrange_real_last = 0, lagrange_ordered_masking = 0. The delta to the next row (real_last, which holds 2^14-1) must be in {0,1,2,3}. Setting a value of 0 here creates a gap of 2^14 - 1 to the next row.

Definition at line 333 of file relation_failure.test.cpp.

◆ TEST_F() [13/20]

TEST_F ( TranslatorRelationFailureTests  ,
InRangeValueInMaskingFlowsToOrderedTail   
)

Place a small in-range value (42) at a wire masking position and verify it flows correctly through concatenation into the ordered polynomial's contiguous masking tail.

The value 42 is unique among random FF masking values. We trace it: wire masking pos → concatenated poly (scattered) → ordered poly tail (contiguous). After the full pipeline, all relations should still pass.

Definition at line 481 of file relation_failure.test.cpp.

◆ TEST_F() [14/20]

TEST_F ( TranslatorRelationFailureTests  ,
NonNativeFieldRejectsAccumulatorAlias   
)

Regression for AztecProtocol/barretenberg#2492: verify that the accumulator alias attack (current_acc += q, quotient -= 1) is caught by the higher carry check.

The Fq accumulation formula holds in integers: prev * x + stuff - quotient * p - current_acc = 0 Replacing current_acc with current_acc + p and quotient with quotient - 1 preserves this equation, plus its mod-2^272 and mod-r projections. However, the limb-level carry witnesses (relation_wide_limbs) become stale: the new intermediate sums at limbs 2-3 no longer match the old high carry value, and subrelation 1 (higher mod 2^136 check) detects the mismatch.

Definition at line 785 of file relation_failure.test.cpp.

◆ TEST_F() [15/20]

TEST_F ( TranslatorRelationFailureTests  ,
PermutationFailsOnConcatenatedBlockBoundaryCorruption   
)

Place a non-zero value at position j*MINI (block boundary, below start_index) in a concatenated poly. This position is normally zero because wire data starts at start_index=1 within each block. Changing it alters the permutation numerator without updating ordered polys.

Definition at line 746 of file relation_failure.test.cpp.

◆ TEST_F() [16/20]

TEST_F ( TranslatorRelationFailureTests  ,
PermutationFailsOnConcatenatedCorruption   
)

Corrupt a non-masking value in concatenated_range_constraints_0, creating a multiset mismatch (numerator changes but ordered/denominator is not updated).

Definition at line 195 of file relation_failure.test.cpp.

◆ TEST_F() [17/20]

TEST_F ( TranslatorRelationFailureTests  ,
PermutationFailsOnExtraNumeratorCorruption   
)

Corrupt ordered_extra_range_constraints_numerator (the 5th factor in the permutation numerator), creating a multiset mismatch without updating z_perm.

Definition at line 570 of file relation_failure.test.cpp.

◆ TEST_F() [18/20]

TEST_F ( TranslatorRelationFailureTests  ,
PermutationFailsOnOrderedCorruption   
)

Corrupt a value in ordered_range_constraints_0 (denominator side of the permutation), creating a multiset mismatch without updating z_perm.

Definition at line 454 of file relation_failure.test.cpp.

◆ TEST_F() [19/20]

TEST_F ( TranslatorRelationFailureTests  ,
PermutationFailsOnZPermCorruption   
)

Corrupt z_perm at a mid position, breaking the running product consistency.

Definition at line 246 of file relation_failure.test.cpp.

◆ TEST_F() [20/20]

TEST_F ( TranslatorRelationFailureTests  ,
PermutationFailsOnZPermNonZeroAtFirstRow   
)

Test that z_perm must be zero at the lagrange_first row.

The permutation grand product relies on z_perm[0] = 0 so that (z_perm + lagrange_first) evaluates to 1 at the first row. Sub-relation 2 (lagrange_first * z_perm = 0) enforces this.

We cross-check the lagrange_first position two ways:

  1. Structurally: z_perm.start_index() - 1 (the zero row before the shiftable region)
  2. By scanning the lagrange_first polynomial for its non-zero entry

Definition at line 277 of file relation_failure.test.cpp.