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

Go to the source code of this file.

Classes

class  SafeUintTest< Builder >
 

Macros

#define STDLIB_TYPE_ALIASES
 

Typedefs

using CircuitTypes = ::testing::Types< bb::UltraCircuitBuilder >
 

Functions

template<class T >
void ignore_unused (T &)
 
 TYPED_TEST_SUITE (SafeUintTest, CircuitTypes)
 
STANDARD_TESTING_TAGS TYPED_TEST (SafeUintTest, TestConstructorWithValueOutOfRangeFails)
 
 TYPED_TEST (SafeUintTest, TestConstructorWithValueInRange)
 
 TYPED_TEST (SafeUintTest, TestMultiply)
 Test that we can multiply successfully and tags are merged on multiplication.
 
 TYPED_TEST (SafeUintTest, TestMultiplyOperationOutOfRangeFails)
 Test that we overflow correctly on the border of 3**160 and 3**161.
 
 TYPED_TEST (SafeUintTest, TestMultiplyOperationOnConstantsOutOfRangeFails)
 Test that we correctly overflow multiplying by a constant on the border of 2**253 and 2**254.
 
 TYPED_TEST (SafeUintTest, TestAdd)
 Test that we can add without overflow successfully.
 
 TYPED_TEST (SafeUintTest, TestAddOperationOutOfRangeFails)
 Test that we correctly overflow on addition on the border of 3**160 and 2 * 3**160.
 
 TYPED_TEST (SafeUintTest, TestSubtract)
 Test that we can subtract without underflow successfully.
 
 TYPED_TEST (SafeUintTest, TestSubtractResultOutOfRange)
 Test that range constraint fails if the value exceeds the bit limit.
 
 TYPED_TEST (SafeUintTest, TestSubtractUnderflowGeneral)
 Test that underflow is caught in general case.
 
 TYPED_TEST (SafeUintTest, TestSubtractUnderflowSpecial)
 Test that underflow is caught in the special case.
 
 TYPED_TEST (SafeUintTest, TestMinusOperator)
 Test that valid minus operation works.
 
 TYPED_TEST (SafeUintTest, TestMinusOperatorValidOnZero)
 Test that valid minus operation works on 0.
 
 TYPED_TEST (SafeUintTest, TestMinusUnderflowGeneral1)
 Test that checks that minus operator underflow is caught in the general case.
 
 TYPED_TEST (SafeUintTest, TestMinusUnderflowGeneral2)
 Test that checks that minus operator underflow is caught in the general case.
 
 TYPED_TEST (SafeUintTest, TestMinusUnderflowSpecial1)
 Test that checks that minus operator underflow is caught from special case.
 
 TYPED_TEST (SafeUintTest, TestMinusUnderflowSpecial2)
 Test that checks that minus operator underflow is caught from special case.
 
 TYPED_TEST (SafeUintTest, TestDivideMethod)
 
 TYPED_TEST (SafeUintTest, TestDivideMethodQuotientRangeTooSmallFails)
 
 TYPED_TEST (SafeUintTest, TestDivideRemainderTooLarge)
 
 TYPED_TEST (SafeUintTest, TestDivideMethodQuotientRemainderIncorrectFails)
 
 TYPED_TEST (SafeUintTest, TestDivideMethodQuotientRemainderModRFails)
 
 TYPED_TEST (SafeUintTest, TestDivOperator)
 
 TYPED_TEST (SafeUintTest, TestDivideOperator)
 
 TYPED_TEST (SafeUintTest, TestSlice)
 
 TYPED_TEST (SafeUintTest, TestSliceEqualMsbLsb)
 
 TYPED_TEST (SafeUintTest, TestSliceRandom)
 
 TYPED_TEST (SafeUintTest, TestOperatorDivRemainderConstraint)
 Make sure we prevent proving v / v = 0 by setting the divison remainder to be v.
 
 TYPED_TEST (SafeUintTest, TestDivRemainderConstraint)
 Make sure we prevent proving v / v = 0 with remainder set to v.
 
 TYPED_TEST (SafeUintTest, TestByteArrayConversion)
 

Macro Definition Documentation

◆ STDLIB_TYPE_ALIASES

Typedef Documentation

◆ CircuitTypes

using CircuitTypes = ::testing::Types<bb::UltraCircuitBuilder>

Definition at line 36 of file safe_uint.test.cpp.

Function Documentation

◆ ignore_unused()

template<class T >
void ignore_unused ( T &  )

Definition at line 32 of file safe_uint.test.cpp.

◆ TYPED_TEST() [1/30]

TYPED_TEST ( SafeUintTest  ,
TestAdd   
)

Test that we can add without overflow successfully.

Definition at line 158 of file safe_uint.test.cpp.

◆ TYPED_TEST() [2/30]

TYPED_TEST ( SafeUintTest  ,
TestAddOperationOutOfRangeFails   
)

Test that we correctly overflow on addition on the border of 3**160 and 2 * 3**160.

Definition at line 177 of file safe_uint.test.cpp.

◆ TYPED_TEST() [3/30]

TYPED_TEST ( SafeUintTest  ,
TestByteArrayConversion   
)

Definition at line 763 of file safe_uint.test.cpp.

◆ TYPED_TEST() [4/30]

TYPED_TEST ( SafeUintTest  ,
TestConstructorWithValueInRange   
)

Definition at line 59 of file safe_uint.test.cpp.

◆ TYPED_TEST() [5/30]

STANDARD_TESTING_TAGS TYPED_TEST ( SafeUintTest  ,
TestConstructorWithValueOutOfRangeFails   
)

Definition at line 42 of file safe_uint.test.cpp.

◆ TYPED_TEST() [6/30]

TYPED_TEST ( SafeUintTest  ,
TestDivideMethod   
)

Definition at line 433 of file safe_uint.test.cpp.

◆ TYPED_TEST() [7/30]

TYPED_TEST ( SafeUintTest  ,
TestDivideMethodQuotientRangeTooSmallFails   
)

Definition at line 460 of file safe_uint.test.cpp.

◆ TYPED_TEST() [8/30]

TYPED_TEST ( SafeUintTest  ,
TestDivideMethodQuotientRemainderIncorrectFails   
)

Definition at line 489 of file safe_uint.test.cpp.

◆ TYPED_TEST() [9/30]

TYPED_TEST ( SafeUintTest  ,
TestDivideMethodQuotientRemainderModRFails   
)

Definition at line 504 of file safe_uint.test.cpp.

◆ TYPED_TEST() [10/30]

TYPED_TEST ( SafeUintTest  ,
TestDivideOperator   
)

Definition at line 540 of file safe_uint.test.cpp.

◆ TYPED_TEST() [11/30]

TYPED_TEST ( SafeUintTest  ,
TestDivideRemainderTooLarge   
)

Definition at line 475 of file safe_uint.test.cpp.

◆ TYPED_TEST() [12/30]

TYPED_TEST ( SafeUintTest  ,
TestDivOperator   
)

Definition at line 521 of file safe_uint.test.cpp.

◆ TYPED_TEST() [13/30]

TYPED_TEST ( SafeUintTest  ,
TestDivRemainderConstraint   
)

Make sure we prevent proving v / v = 0 with remainder set to v.

Definition at line 742 of file safe_uint.test.cpp.

◆ TYPED_TEST() [14/30]

TYPED_TEST ( SafeUintTest  ,
TestMinusOperator   
)

Test that valid minus operation works.

Definition at line 296 of file safe_uint.test.cpp.

◆ TYPED_TEST() [15/30]

TYPED_TEST ( SafeUintTest  ,
TestMinusOperatorValidOnZero   
)

Test that valid minus operation works on 0.

Definition at line 318 of file safe_uint.test.cpp.

◆ TYPED_TEST() [16/30]

TYPED_TEST ( SafeUintTest  ,
TestMinusUnderflowGeneral1   
)

Test that checks that minus operator underflow is caught in the general case.

General case means that the special case does not happen.

Definition at line 337 of file safe_uint.test.cpp.

◆ TYPED_TEST() [17/30]

TYPED_TEST ( SafeUintTest  ,
TestMinusUnderflowGeneral2   
)

Test that checks that minus operator underflow is caught in the general case.

Testing -1 is an underflow.

Definition at line 356 of file safe_uint.test.cpp.

◆ TYPED_TEST() [18/30]

TYPED_TEST ( SafeUintTest  ,
TestMinusUnderflowSpecial1   
)

Test that checks that minus operator underflow is caught from special case.

Special case refers to the check that current_max + other.current_max > MAX_VALUE, which is a potential underflow case, that escapes the general check through the range constraint. Throws an error even if it is not an underflow in some instantiations of the witness values.

Definition at line 377 of file safe_uint.test.cpp.

◆ TYPED_TEST() [19/30]

TYPED_TEST ( SafeUintTest  ,
TestMinusUnderflowSpecial2   
)

Test that checks that minus operator underflow is caught from special case.

Special case refers to the check that current_max + other.current_max > MAX_VALUE, which is a potential underflow case, that escapes the general check through the range constraint. Also, underflow can actually be detected from range constraint.

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

◆ TYPED_TEST() [20/30]

TYPED_TEST ( SafeUintTest  ,
TestMultiply   
)

Test that we can multiply successfully and tags are merged on multiplication.

Definition at line 75 of file safe_uint.test.cpp.

◆ TYPED_TEST() [21/30]

TYPED_TEST ( SafeUintTest  ,
TestMultiplyOperationOnConstantsOutOfRangeFails   
)

Test that we correctly overflow multiplying by a constant on the border of 2**253 and 2**254.

Definition at line 125 of file safe_uint.test.cpp.

◆ TYPED_TEST() [22/30]

TYPED_TEST ( SafeUintTest  ,
TestMultiplyOperationOutOfRangeFails   
)

Test that we overflow correctly on the border of 3**160 and 3**161.

Definition at line 95 of file safe_uint.test.cpp.

◆ TYPED_TEST() [23/30]

TYPED_TEST ( SafeUintTest  ,
TestOperatorDivRemainderConstraint   
)

Make sure we prevent proving v / v = 0 by setting the divison remainder to be v.

Definition at line 688 of file safe_uint.test.cpp.

◆ TYPED_TEST() [24/30]

TYPED_TEST ( SafeUintTest  ,
TestSlice   
)

Definition at line 610 of file safe_uint.test.cpp.

◆ TYPED_TEST() [25/30]

TYPED_TEST ( SafeUintTest  ,
TestSliceEqualMsbLsb   
)

Definition at line 638 of file safe_uint.test.cpp.

◆ TYPED_TEST() [26/30]

TYPED_TEST ( SafeUintTest  ,
TestSliceRandom   
)

Definition at line 660 of file safe_uint.test.cpp.

◆ TYPED_TEST() [27/30]

TYPED_TEST ( SafeUintTest  ,
TestSubtract   
)

Test that we can subtract without underflow successfully.

Definition at line 208 of file safe_uint.test.cpp.

◆ TYPED_TEST() [28/30]

TYPED_TEST ( SafeUintTest  ,
TestSubtractResultOutOfRange   
)

Test that range constraint fails if the value exceeds the bit limit.

difference is 7, which exceeds 2 bits, and causes the circuit to fail.

Definition at line 230 of file safe_uint.test.cpp.

◆ TYPED_TEST() [29/30]

TYPED_TEST ( SafeUintTest  ,
TestSubtractUnderflowGeneral   
)

Test that underflow is caught in general case.

General case refers to when difference.current_max + other.current_max does not exceed MAX_VALUE and underflow is caught by range constraint.

Definition at line 251 of file safe_uint.test.cpp.

◆ TYPED_TEST() [30/30]

TYPED_TEST ( SafeUintTest  ,
TestSubtractUnderflowSpecial   
)

Test that underflow is caught in the special case.

Should throw an error because difference.current_max + other.current_max exceeds the MAX_VALUE.

Definition at line 270 of file safe_uint.test.cpp.

◆ TYPED_TEST_SUITE()

TYPED_TEST_SUITE ( SafeUintTest  ,
CircuitTypes   
)