Categorygithub.com/prysmaticlabs/fastssz
modulepackage
0.0.0-20240620202422-a981b8ef89d3
Repository: https://github.com/prysmaticlabs/fastssz.git
Documentation: pkg.go.dev

# README

FastSSZ

Clone:

$ git clone [email protected]:prysmaticlabs/fastssz.git

Download the eth2.0 spec tests

$ make get-spec-tests

Regenerate the test spec encodings:

$ make build-spec-tests

Generate encodings for a specific package:

$ go run sszgen/*.go --path ./ethereumapis/eth/v1alpha1 [--objs BeaconBlock,Eth1Data]

Optionally, you can specify the objs you want to generate. Otherwise, it will generate encodings for all structs in the package. Note that if a struct does not have 'ssz' tags when required (i.e size of arrays), the generator will fail.

By default, it generates a file with the prefix '_encoding.go' for each file that contains a generated struct. Optionally, you can combine all the outputs in a single file with the 'output' flag.

$ go run sszgen/*.go --path ./ethereumapis/eth/v1alpha1 --output ./ethereumapis/eth/v1alpha1/encoding.go

Test the spectests:

$ go test -v ./spectests/... -run TestSpec

Run the fuzzer:

$ FUZZ_TESTS=True go test -v ./spectests/... -run TestFuzz

To install the generator run:

$ go get github.com/prysmaticlabs/fastssz/sszgen

Benchmark (BeaconBlock):

$ go test -v ./spectests/... -run=XXX -bench=.
goos: linux
goarch: amd64
pkg: github.com/prysmaticlabs/fastssz/spectests
BenchmarkMarshalGoSSZ-4       	    1366	    753160 ns/op	  115112 B/op	    8780 allocs/op
BenchmarkMarshalFast-4        	  240765	      5093 ns/op	   18432 B/op	       1 allocs/op
BenchmarkMarshalSuperFast-4   	  377835	      3041 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnMarshalGoSSZ-4     	     847	   1395097 ns/op	  144608 B/op	    8890 allocs/op
BenchmarkUnMarshalFast-4      	   43824	     27190 ns/op	   31024 B/op	     577 allocs/op
PASS
ok  	github.com/prysmaticlabs/fastssz/spectests	6.608s

Package reference

To reference a struct from another package use the '--include' flag to point to that package.

Example:

$ go run sszgen/*.go --path ./example2
$ go run sszgen/*.go --path ./example 
[ERR]: could not find struct with name 'Checkpoint'
$ go run sszgen/*.go --path ./example --include ./example2

There are some caveats required to use this functionality.

  • If multiple input paths import the same package, all of them need to import it with the same alias if any.
  • If the folder of the package is not the same as the name of the package, any input file that imports this package needs to do it with an alias.

# Packages

No description provided by the author
Code generated by fastssz.
No description provided by the author
Code generated by fastssz.

# Functions

No description provided by the author
DecodeDynamicLength decodes the length from the dynamic input.
DivideInt divides the int fully.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ExtendUint16 extends a uint16 buffer to a given size.
ExtendUint64 extends a uint64 buffer to a given size.
ExtendUint8 extends a uint16 buffer to a given size.
HashWithDefaultHasher hashes a HashRoot object with a Hasher from the default HasherPool.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
MarshalBool marshals a boolean to dst.
MarshalSSZ marshals an object.
MarshalUint16 marshals a little endian uint16 to dst.
MarshalUint32 marshals a little endian uint32 to dst.
MarshalUint64 marshals a little endian uint64 to dst.
MarshalUint8 marshals a little endian uint8 to dst.
NewHasher creates a new Hasher object.
NewHasher creates a new Hasher object with a custom hash function.
NewNodeWithLR initializes a branch node.
NewNodeWithValue initializes a leaf node.
ReadOffset reads an offset from buf.
TreeFromChunks constructs a tree from leaf values.
TreeFromNodes constructs a tree from leaf nodes.
No description provided by the author
UnmarshalBool unmarshals a boolean from the src input.
UnmarshalDynamic unmarshals the dynamic items from the input.
UnmarshallUint16 unmarshals a little endian uint16 from the src input.
UnmarshallUint32 unmarshals a little endian uint32 from the src input.
UnmarshallUint64 unmarshals a little endian uint64 from the src input.
UnmarshallUint8 unmarshals a little endian uint8 from the src input.
No description provided by the author
ValidateBitlist validates that the bitlist is correct.
VerifyMultiproof verifies a proof for multiple leaves against the given root.
VerifyProof verifies a single merkle branch.
WriteOffset writes an offset to dst.

# Variables

DefaultHasherPool is a default hasher pool.
No description provided by the author
No description provided by the author
ErrIncorrectByteSize means that the byte size is incorrect.
ErrIncorrectListSize means that the size of the list is incorrect.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

CompressedMultiproof represents a compressed merkle proof of several leaves.
Hasher is a utility tool to hash SSZ structs.
HasherPool may be used for pooling Hashers for similarly typed SSZs.
Multiproof represents a merkle proof of several leaves.
Node represents a node in the tree backing of a SSZ object.
Proof represents a merkle proof against a general index.
No description provided by the author

# Interfaces

No description provided by the author
Marshaler is the interface implemented by types that can marshal themselves into valid SZZ.
Unmarshaler is the interface implemented by types that can unmarshal a SSZ description of themselves.