types

package
v0.0.0-...-35a8ded Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsByteArrSlice

func AsByteArrSlice[T ~[32]byte](s []T) [][32]byte

Converts a slice of Bytes32 or FullBytes32 into a slice of [32]byte

func Bytes32Cmp

func Bytes32Cmp(a, b Bytes32) int

Cmp two Bytes32s. The Bytes32 are interpreted as big-endians big integers and then are compared. Returns:

  • a < b : -1
  • a == b : 0
  • a > b : 1

func DecodeQuotedHexString

func DecodeQuotedHexString(b []byte) ([]byte, error)

func MarshalHexBytesJSON

func MarshalHexBytesJSON(b []byte) []byte

func ReadBigIntOn32Bytes

func ReadBigIntOn32Bytes(r io.Reader) (*big.Int, error)

Read a bigint from a reader assuming it takes 32 bytes

func ReadInt64On32Bytes

func ReadInt64On32Bytes(r io.Reader) (x, n_ int64, err error)

func WriteBigIntOn32Bytes

func WriteBigIntOn32Bytes(w io.Writer, b *big.Int) (int64, error)

Big int are assumed to fit on 32 bytes and are written as a single block of 32 bytes in bigendian form (i.e, zero-padded on the left)

func WriteInt64On32Bytes

func WriteInt64On32Bytes(w io.Writer, x int64) (int64, error)

Types

type Account

type Account struct {
	// Implicitly we assume that the nonce fits into
	// a int64 but the obtained encoding is consistent
	// with how it would be if it was a big.Int
	Nonce          int64
	Balance        *big.Int
	StorageRoot    Bytes32
	MimcCodeHash   Bytes32
	KeccakCodeHash FullBytes32
	CodeSize       int64
}

An Ethereum account represented with the zkTrie representation

func (Account) MarshalJSON

func (a Account) MarshalJSON() ([]byte, error)

func (*Account) ReadFrom

func (a *Account) ReadFrom(r io.Reader) (int64, error)

func (*Account) UnmarshalJSON

func (a *Account) UnmarshalJSON(data []byte) error

func (Account) WriteTo

func (a Account) WriteTo(w io.Writer) (int64, error)

type Bytes32

type Bytes32 [32]byte

Bytes32 represents an arbtrary bytes string of 32 bytes. It is used to represent the output of non-field based hash function such as keccak256 or sha256.

func AsBytes32

func AsBytes32(b []byte) (d Bytes32)

Create a bytes32 from a slice

func Bytes32FromHex

func Bytes32FromHex(s string) Bytes32

Creates a bytes32 from an hexstring. Panic if it fails. Mostly useful for testing. the string s is left padded with zeroes if less than 64 characters are provided if more than 64 characters are provided, the function will panic function expects an even number of chars Ox prefix is optional

func DummyBytes32

func DummyBytes32(i int) (d Bytes32)

Constructs a dummy Bytes32 from an integer

func DummyDigest

func DummyDigest(i int) (d Bytes32)

Returns a dummy digest

func LeftPadToBytes32

func LeftPadToBytes32(b []byte) Bytes32

LeftPadToBytes32 pads a bytes32 element into a Bytes32 by adding zeroes to the left until the slice has 32 bytes

func (Bytes32) Hex

func (d Bytes32) Hex() string

Returns an hexstring representation of the Bytes32

func (*Bytes32) IsBn254Fr

func (f *Bytes32) IsBn254Fr() bool

Returns true if the receiver is a valid field element

func (Bytes32) MarshalJSON

func (f Bytes32) MarshalJSON() ([]byte, error)

Marshal "e" into JSON format

func (*Bytes32) ReadFrom

func (b *Bytes32) ReadFrom(r io.Reader) (int64, error)

Reads a bytes32 from the given reader

func (*Bytes32) UnmarshalJSON

func (f *Bytes32) UnmarshalJSON(b []byte) error

Unmarshal an ethereum address from JSON format. The expected format is an hex string.

func (Bytes32) WriteTo

func (b Bytes32) WriteTo(w io.Writer) (int64, error)

Writes the bytes32 into the given write.

type EthAddress

type EthAddress [20]byte

EthAddress represents an ethereum address. It consists of 20bytes and is the obtained by hashing the corresponding ECDSA-secp256k1 public key and keeping the 20 first bytes.

func AddressFromHex

func AddressFromHex(h string) (EthAddress, error)

func DummyAddress

func DummyAddress(i int) (a EthAddress)

Construct a dummy address from an integer

func (EthAddress) Hex

func (e EthAddress) Hex() string

func (EthAddress) MarshalJSON

func (e EthAddress) MarshalJSON() ([]byte, error)

Marshal "e" into JSON format

func (*EthAddress) ReadFrom

func (e *EthAddress) ReadFrom(r io.Reader) (int64, error)

Reads a bytes32 from the given reader

func (*EthAddress) ReadFrom32BytesLeftZeroPadded

func (e *EthAddress) ReadFrom32BytesLeftZeroPadded(r io.Reader) (int64, error)

Reads an Ethereum address that is left zero-padded to 32 bytes. Example: 0x000000000000000000000000deadbeefdeadbeefdeadbeefdeadbeefdeadbeef

func (*EthAddress) UnmarshalJSON

func (e *EthAddress) UnmarshalJSON(b []byte) error

Unmarshal an ethereum address from JSON format. The expected format is an hex string of 20 bytes. If the input string is larger than 20 bytes, truncate the leftmost bytes of the input address. If it is too small zero pad it on the left.

func (*EthAddress) WriteOn32Bytes

func (e *EthAddress) WriteOn32Bytes(w io.Writer) (int64, error)

Writes an Ethereum address on 32 using left-zero padding.

func (EthAddress) WriteTo

func (e EthAddress) WriteTo(w io.Writer) (int64, error)

Writes the bytes32 into the given write.

type FullBytes32

type FullBytes32 Bytes32

Full bytes32 is a wrapper around bytes32 used to specifically represent a bytes32 that may not fit on a single field element and require 2 words to be hashed with MiMC.

func AsFullBytes32

func AsFullBytes32(b []byte) FullBytes32

func DummyFullByte

func DummyFullByte(i int) (f FullBytes32)

Constructs a dummy full bytes from an integer

func FullBytes32FromHex

func FullBytes32FromHex(s string) FullBytes32

Creates a bytes32 from an hexstring. Panic if it fails. Mostly useful for testing.

func (FullBytes32) Hex

func (f FullBytes32) Hex() string

func (FullBytes32) MarshalJSON

func (f FullBytes32) MarshalJSON() ([]byte, error)

Marshal "e" into JSON format

func (*FullBytes32) ReadFrom

func (f *FullBytes32) ReadFrom(r io.Reader) (n int64, err error)

func (*FullBytes32) ReadPacked

func (f *FullBytes32) ReadPacked(r io.Reader) (n int64, err error)

func (*FullBytes32) UnmarshalJSON

func (f *FullBytes32) UnmarshalJSON(b []byte) error

Unmarshal an ethereum address from JSON format. The expected format is an hex string.

func (FullBytes32) Write1Word

func (f FullBytes32) Write1Word(w io.Writer) (n int64, err error)

func (FullBytes32) WriteTo

func (f FullBytes32) WriteTo(w io.Writer) (n int64, err error)

Jump to

Keyboard shortcuts

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