Documentation ¶
Index ¶
- func AsByteArrSlice[T ~[32]byte](s []T) [][32]byte
- func Bytes32Cmp(a, b Bytes32) int
- func DecodeQuotedHexString(b []byte) ([]byte, error)
- func MarshalHexBytesJSON(b []byte) []byte
- func ReadBigIntOn32Bytes(r io.Reader) (*big.Int, error)
- func ReadInt64On32Bytes(r io.Reader) (x, n_ int64, err error)
- func WriteBigIntOn32Bytes(w io.Writer, b *big.Int) (int64, error)
- func WriteInt64On32Bytes(w io.Writer, x int64) (int64, error)
- type Account
- type Bytes32
- type EthAddress
- func (e EthAddress) Hex() string
- func (e EthAddress) MarshalJSON() ([]byte, error)
- func (e *EthAddress) ReadFrom(r io.Reader) (int64, error)
- func (e *EthAddress) ReadFrom32BytesLeftZeroPadded(r io.Reader) (int64, error)
- func (e *EthAddress) UnmarshalJSON(b []byte) error
- func (e *EthAddress) WriteOn32Bytes(w io.Writer) (int64, error)
- func (e EthAddress) WriteTo(w io.Writer) (int64, error)
- type FullBytes32
- func (f FullBytes32) Hex() string
- func (f FullBytes32) MarshalJSON() ([]byte, error)
- func (f *FullBytes32) ReadFrom(r io.Reader) (n int64, err error)
- func (f *FullBytes32) ReadPacked(r io.Reader) (n int64, err error)
- func (f *FullBytes32) UnmarshalJSON(b []byte) error
- func (f FullBytes32) Write1Word(w io.Writer) (n int64, err error)
- func (f FullBytes32) WriteTo(w io.Writer) (n int64, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsByteArrSlice ¶
Converts a slice of Bytes32 or FullBytes32 into a slice of [32]byte
func Bytes32Cmp ¶
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 MarshalHexBytesJSON ¶
func ReadBigIntOn32Bytes ¶
Read a bigint from a reader assuming it takes 32 bytes
func WriteBigIntOn32Bytes ¶
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)
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 (*Account) UnmarshalJSON ¶
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 Bytes32FromHex ¶
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 LeftPadToBytes32 ¶
LeftPadToBytes32 pads a bytes32 element into a Bytes32 by adding zeroes to the left until the slice has 32 bytes
func (Bytes32) MarshalJSON ¶
Marshal "e" into JSON format
func (*Bytes32) UnmarshalJSON ¶
Unmarshal an ethereum address from JSON format. The expected format is an hex string.
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.
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) 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)