uints

package
v0.1.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHints

func GetHints() []solver.Hint

Types

type BinaryField

type BinaryField[T U32 | U64] struct {
	// contains filtered or unexported fields
}

func New

func New[T Long](api frontend.API) (*BinaryField[T], error)

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

type Long

type Long interface{ U32 | U64 }

type U32

type U32 [4]U8

func NewU32

func NewU32(v uint32) U32

func NewU32Array

func NewU32Array(v []uint32) []U32

type U64

type U64 [8]U8

func NewU64

func NewU64(v uint64) U64

func NewU64Array

func NewU64Array(v []uint64) []U64

type U8

type U8 struct {
	Val frontend.Variable
	// contains filtered or unexported fields
}

func NewU8

func NewU8(v uint8) U8

func NewU8Array

func NewU8Array(v []uint8) []U8

func (*U8) GnarkInitHook

func (e *U8) GnarkInitHook()

GnarkInitHook describes how to initialise the element.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL