Documentation ¶
Overview ¶
Package uints implements optimised byte and long integer operations.
Usually arithmetic in a circuit is performed in the native field, which is of prime order. However, for compatibility with native operations we rely on operating on smaller primitive types as 8-bit, 32-bit and 64-bit integer. Naively, these operations have to be implemented bitwise as there are no closed equations for boolean operations (XOR, AND, OR).
However, the bitwise approach is very inefficient and leads to several constraints per bit. Accumulating over a long integer, it leads to very inefficients circuits.
This package performs boolean operations using lookup tables on bytes. So, long integers are split into 4 or 8 bytes and we perform the operations bytewise. In the lookup tables, we store results for all possible 2^8×2^8 inputs. With this approach, every bytewise operation costs as single lookup, which depending on the backend is relatively cheap (one to three constraints).
NB! The package is still work in progress. The interfaces and implementation details most certainly changes over time. We cannot ensure the soundness of the operations.
Index ¶
- func GetHints() []solver.Hint
- type BinaryField
- func (bf *BinaryField[T]) Add(a ...T) T
- func (bf *BinaryField[T]) And(a ...T) T
- func (bf *BinaryField[T]) AssertEq(a, b T)
- func (bf *BinaryField[T]) ByteAssertEq(a, b U8)
- func (bf *BinaryField[T]) ByteValueOf(a frontend.Variable) U8
- func (bf *BinaryField[T]) Lrot(a T, c int) T
- func (bf *BinaryField[T]) Not(a T) T
- func (bf *BinaryField[T]) PackLSB(a ...U8) T
- func (bf *BinaryField[T]) PackMSB(a ...U8) T
- func (bf *BinaryField[T]) Rshift(a T, c int) T
- func (bf *BinaryField[T]) ToValue(a T) frontend.Variable
- func (bf *BinaryField[T]) UnpackLSB(a T) []U8
- func (bf *BinaryField[T]) UnpackMSB(a T) []U8
- func (bf *BinaryField[T]) ValueOf(a frontend.Variable) T
- func (bf *BinaryField[T]) Xor(a ...T) T
- type Long
- type U32
- type U64
- type U8
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BinaryField ¶
func (*BinaryField[T]) Add ¶
func (bf *BinaryField[T]) Add(a ...T) T
func (*BinaryField[T]) And ¶
func (bf *BinaryField[T]) And(a ...T) T
func (*BinaryField[T]) AssertEq ¶
func (bf *BinaryField[T]) AssertEq(a, b T)
func (*BinaryField[T]) ByteAssertEq ¶
func (bf *BinaryField[T]) ByteAssertEq(a, b U8)
func (*BinaryField[T]) ByteValueOf ¶
func (bf *BinaryField[T]) ByteValueOf(a frontend.Variable) U8
func (*BinaryField[T]) Lrot ¶
func (bf *BinaryField[T]) Lrot(a T, c int) T
func (*BinaryField[T]) Not ¶
func (bf *BinaryField[T]) Not(a T) T
func (*BinaryField[T]) PackLSB ¶
func (bf *BinaryField[T]) PackLSB(a ...U8) T
func (*BinaryField[T]) PackMSB ¶
func (bf *BinaryField[T]) PackMSB(a ...U8) T
func (*BinaryField[T]) Rshift ¶
func (bf *BinaryField[T]) Rshift(a T, c int) T
func (*BinaryField[T]) ToValue ¶
func (bf *BinaryField[T]) ToValue(a T) frontend.Variable
func (*BinaryField[T]) UnpackLSB ¶
func (bf *BinaryField[T]) UnpackLSB(a T) []U8
func (*BinaryField[T]) UnpackMSB ¶
func (bf *BinaryField[T]) UnpackMSB(a T) []U8
func (*BinaryField[T]) ValueOf ¶
func (bf *BinaryField[T]) ValueOf(a frontend.Variable) T
func (*BinaryField[T]) Xor ¶
func (bf *BinaryField[T]) Xor(a ...T) T