felt

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 16 Imported by: 48 modules, 152 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	Base16 = 16
	Base10 = 10
)
View Source
const (
	Limbs = fp.Limbs // number of 64 bits words needed to represent a Element
	Bits  = fp.Bits  // number of bits needed to represent a Element
	Bytes = fp.Bytes // number of bytes needed to represent a Element

	// Max number of chars to represent a Felt as Hex.
	// 0x at the start + 2 chars per byte.
	MaxFeltAsHexSize = len("0x") + Bytes*2
)
View Source
const CompactWrites = false

CompactWrites reports whether this build writes felts in the compact forms.

Variables

This section is empty.

Functions

func CastPointerSlice added in v0.17.1

func CastPointerSlice[To, From FeltLike](s []*From) []*To

CastPointerSlice reinterprets s as pointers to another felt type, sharing its backing array.

func CastSlice added in v0.17.1

func CastSlice[To, From FeltLike](s []From) []To

CastSlice reinterprets s as another felt type, sharing its backing array.

func Equal added in v0.15.15

func Equal[F FeltLike](a, b *F) bool

Equal reports whether a and b are equal; limb equality is the field element's own definition.

func FromBytes added in v0.14.3

func FromBytes[F FeltLike](value []byte) F

FromBytes crates a new Felt based type given a byte array

func FromMinimalBytes added in v0.17.1

func FromMinimalBytes[F FeltLike](value []byte) (F, error)

FromMinimalBytes creates a new Felt based type from 1 to 32 big-endian bytes below the modulus.

func FromString added in v0.15.7

func FromString[F FeltLike](value string) (F, error)

FromString crates a new Felt based type given a any string

func FromUint64 added in v0.14.3

func FromUint64[F FeltLike](num uint64) F

FromUint64 creates a new Felt based type given an uint64

func ImplOf added in v0.17.1

func ImplOf[F FeltLike](f *F) *fp.Element

ImplOf returns the field element behind any felt type without copying it.

func IsZero added in v0.15.15

func IsZero[F FeltLike](v *F) bool

IsZero reports whether v is zero; limb equality is the field element's own definition.

func NewFromBytes added in v0.15.7

func NewFromBytes[F FeltLike](val []byte) *F

NewFromBytes crates a new Felt based type given a byte array. Use this function with care since it forces a heap allocation. For efficient code use `FromBytes`

func NewFromString added in v0.15.7

func NewFromString[F FeltLike](val string) (*F, error)

NewFromString crates a new Felt based type given a string. Use this function with care since it forces a heap allocation. For efficient code use `FromString`

func NewFromUint64 added in v0.15.7

func NewFromUint64[F FeltLike](num uint64) *F

NewFromUint64 crates a new Felt based type given a uint64. Use this function with care since it forces a heap allocation. For efficient code use `FromUint64`

func NewRandom added in v0.15.7

func NewRandom[F FeltLike]() *F

NewRandom creates a new random Felt based type. It also forces a heap allocation. For efficient code use `Random`

func NewUnsafeFromString added in v0.15.8

func NewUnsafeFromString[F FeltLike](val string) *F

NewUnsafeFromString is similar to `NewFromString` but it panics instead of returning an error.

func One added in v0.14.3

func One[F FeltLike]() F

One returns the multiplicative identity of F.

func Random added in v0.15.8

func Random[F FeltLike]() F

Creates a new random Felt based type

func UnsafeFromString added in v0.15.7

func UnsafeFromString[F FeltLike](value string) F

UnsafeFromString crates a new Felt based type given a any string. It panics if the string is not valid.

func Zero

func Zero[F FeltLike]() F

Zero returns the zero value of F.

Types

type Address added in v0.15.7

type Address = Typed[addressKind]

type CasmClassHash added in v0.15.10

type CasmClassHash = Typed[casmClassHashKind]

type ClassHash added in v0.15.7

type ClassHash = Typed[classHashKind]

type Felt

type Felt = Typed[feltKind]

Felt is the untyped field element.

type FeltLike added in v0.15.7

type FeltLike interface {
	~[4]uint64
}

FeltLike is the constraint for generic code over felts: every Typed[K] satisfies it, as does any type declared over one. It exists because a generic type such as Slice cannot infer K.

type Hash added in v0.15.7

type Hash = Typed[hashKind]

type SierraClassHash added in v0.15.10

type SierraClassHash = Typed[sierraClassHashKind]

type Slice added in v0.16.6

type Slice[F FeltLike] []F

func (Slice[F]) MarshalCBOR added in v0.16.6

func (s Slice[F]) MarshalCBOR() ([]byte, error)

func (Slice[F]) MarshalJSONTo added in v0.16.6

func (s Slice[F]) MarshalJSONTo(enc *jsontext.Encoder) error

func (*Slice[F]) UnmarshalCBOR added in v0.16.6

func (s *Slice[F]) UnmarshalCBOR(data []byte) error

func (*Slice[F]) UnmarshalJSONFrom added in v0.16.6

func (s *Slice[F]) UnmarshalJSONFrom(dec *jsontext.Decoder) error

UnmarshalJSONFrom reads a JSON array of 0x-hex strings into the slice.

type StateRootHash added in v0.15.17

type StateRootHash = Typed[stateRootHashKind]

type TransactionHash added in v0.15.7

type TransactionHash = Typed[transactionHashKind]

type Typed added in v0.17.0

type Typed[K any] fp.Element

Typed is a field element told apart at compile time by a phantom kind. Every Typed[K] shares one implementation, so all felt types behave and encode the same and converting between them is free.

func (*Typed[K]) Add added in v0.17.0

func (z *Typed[K]) Add(x, y *Typed[K]) *Typed[K]

Add forwards the call to underlying field element implementation

func (Typed[K]) AppendText added in v0.17.0

func (z Typed[K]) AppendText(data []byte) ([]byte, error)

AppendText appends the felt's 0x hex representation to data. The quotes are placed at the encoding/json level. It is a json/v2 interface and enforces appending.

func (*Typed[K]) BigInt added in v0.17.0

func (z *Typed[K]) BigInt(res *big.Int) *big.Int

BigInt forwards the call to underlying field element implementation

func (*Typed[K]) Bits added in v0.17.0

func (z *Typed[K]) Bits() [4]uint64

Bits forwards the call to underlying field element implementation. Provides access to z by returning its value as a little-endian [4]uint64 array.

func (*Typed[K]) Bytes added in v0.17.0

func (z *Typed[K]) Bytes() [32]byte

Bytes forwards the call to underlying field element implementation. Returns the value of z as a big-endian byte array

func (*Typed[K]) Cmp added in v0.17.0

func (z *Typed[K]) Cmp(x *Typed[K]) int

Cmp forwards the call to underlying field element implementation. Returns:

-1 if z <  x
 0 if z == x
+1 if z >  x

func (*Typed[K]) Div added in v0.17.0

func (z *Typed[K]) Div(x, y *Typed[K]) *Typed[K]

Div forwards the call to underlying field element implementation

func (*Typed[K]) Double added in v0.17.0

func (z *Typed[K]) Double(x *Typed[K]) *Typed[K]

Double forwards the call to underlying field element implementation

func (*Typed[K]) Equal added in v0.17.0

func (z *Typed[K]) Equal(x *Typed[K]) bool

Equal forwards the call to underlying field element implementation

func (*Typed[K]) Exp added in v0.17.0

func (z *Typed[K]) Exp(x *Typed[K], y *big.Int) *Typed[K]

Exp forwards the call to underlying field element implementation

func (*Typed[K]) Halve added in v0.17.0

func (z *Typed[K]) Halve()

Halve forwards the call to underlying field element implementation

func (*Typed[K]) Impl added in v0.17.0

func (z *Typed[K]) Impl() *fp.Element

Impl returns the underlying field element type

func (*Typed[K]) IsOne added in v0.17.0

func (z *Typed[K]) IsOne() bool

IsOne forwards the call to underlying field element implementation

func (*Typed[K]) IsZero added in v0.17.0

func (z *Typed[K]) IsZero() bool

IsZero forwards the call to underlying field element implementation

func (*Typed[K]) Marshal added in v0.17.0

func (z *Typed[K]) Marshal() []byte

Marshal forwards the call to underlying field element implementation

func (*Typed[K]) MarshalCBOR added in v0.17.0

func (z *Typed[K]) MarshalCBOR() ([]byte, error)

Fast, felt-specialized CBOR marshaling.

func (Typed[K]) MarshalText added in v0.17.0

func (z Typed[K]) MarshalText() ([]byte, error)

MarshalText returns the felt as an unquoted 0x hex string with no unnecessary leading zeros. The quotes are placed at the encoding/json level. Uses a value receiver so encoding/json can call it on non-addressable values (struct fields in `any`).

func (*Typed[K]) MinimalBytes added in v0.17.1

func (z *Typed[K]) MinimalBytes() []byte

MinimalBytes returns the big-endian value without leading zero bytes; zero is one zero byte.

func (*Typed[K]) Mul added in v0.17.0

func (z *Typed[K]) Mul(x, y *Typed[K]) *Typed[K]

Mul forwards the call to underlying field element implementation

func (*Typed[K]) Neg added in v0.17.0

func (z *Typed[K]) Neg(x *Typed[K]) *Typed[K]

func (*Typed[K]) Set added in v0.17.0

func (z *Typed[K]) Set(x *Typed[K]) *Typed[K]

Set forwards the call to underlying field element implementation

func (*Typed[K]) SetBigInt added in v0.17.0

func (z *Typed[K]) SetBigInt(v *big.Int) *Typed[K]

SetBigInt forwards the call to underlying field element implementation

func (*Typed[K]) SetBytes added in v0.17.0

func (z *Typed[K]) SetBytes(e []byte) *Typed[K]

SetBytes forwards the call to underlying field element implementation

func (*Typed[K]) SetBytesCanonical added in v0.17.0

func (z *Typed[K]) SetBytesCanonical(e []byte) error

SetBytesCanonical forwards the call to underlying field element implementation

func (*Typed[K]) SetMinimalBytes added in v0.17.1

func (z *Typed[K]) SetMinimalBytes(data []byte) error

SetMinimalBytes sets z from a big-endian value of 1 to 32 bytes below the modulus.

func (*Typed[K]) SetRandom added in v0.17.0

func (z *Typed[K]) SetRandom() *Typed[K]

SetRandom forwards the call to underlying field element implementation

func (*Typed[K]) SetString added in v0.17.0

func (z *Typed[K]) SetString(number string) (*Typed[K], error)

SetString forwards the call to underlying field element implementation

func (*Typed[K]) SetUint64 added in v0.17.0

func (z *Typed[K]) SetUint64(v uint64) *Typed[K]

SetUint64 forwards the call to underlying field element implementation

func (*Typed[K]) ShortString added in v0.17.0

func (z *Typed[K]) ShortString() string

ShortString prints the felt to a string in a shortened format

func (*Typed[K]) StoredBytes added in v0.17.1

func (z *Typed[K]) StoredBytes() []byte

StoredBytes returns the form this build stores a standalone felt value in: the full 32 bytes.

func (*Typed[K]) String added in v0.17.0

func (z *Typed[K]) String() string

String forwards the call to underlying field element implementation

func (*Typed[K]) Sub added in v0.17.0

func (z *Typed[K]) Sub(x, y *Typed[K]) *Typed[K]

Sub forwards the call to underlying field element implementation

func (*Typed[K]) Text added in v0.17.0

func (z *Typed[K]) Text(base int) string

Text forwards the call to underlying field element implementation

func (*Typed[K]) Uint64 added in v0.17.0

func (z *Typed[K]) Uint64() uint64

Uint64 forwards the call to underlying field element implementation

func (*Typed[K]) Unmarshal added in v0.17.0

func (z *Typed[K]) Unmarshal(e []byte)

Unmarshal forwards the call to underlying field element implementation

func (*Typed[K]) UnmarshalCBOR added in v0.17.0

func (z *Typed[K]) UnmarshalCBOR(data []byte) error

UnmarshalCBOR decodes a compact or legacy felt that spans all of data, writing z only on success.

func (*Typed[K]) UnmarshalJSONFrom added in v0.17.0

func (z *Typed[K]) UnmarshalJSONFrom(dec *jsontext.Decoder) error

UnmarshalJSONFrom sets z from a quoted 0x-prefixed hex JSON string; any other JSON value fails.

func (*Typed[K]) UnmarshalText added in v0.17.0

func (z *Typed[K]) UnmarshalText(text []byte) error

UnmarshalText sets z from an unquoted 0x-prefixed hex string, as map keys and text decoders pass it.

func (Typed[K]) ValidatorValue added in v0.17.1

func (z Typed[K]) ValidatorValue() any

ValidatorValue implements validator.Valuer, so every felt type is validated by its hex string.

Jump to

Keyboard shortcuts

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