diff --git a/Makefile b/Makefile index 722d4e6a..bb59f8fd 100644 --- a/Makefile +++ b/Makefile @@ -46,14 +46,8 @@ fmt: ## Format all Go code cd xmss/rust && cargo fmt sszgen: ## Regenerate SSZ encoding files from struct tags - @rm -f types/*_encoding.go - sszgen --path pkg/types --objs ChainConfig --output types/config_encoding.go - sszgen --path pkg/types --objs Checkpoint --output types/checkpoint_encoding.go - sszgen --path pkg/types --objs Validator --output types/validator_encoding.go - sszgen --path pkg/types --objs AttestationData,Attestation,SignedAttestation,AggregatedAttestation,SignedAggregatedAttestation --exclude-objs Checkpoint --output types/attestation_encoding.go - sszgen --path pkg/types --objs BlockHeader,BlockBody,Block,AggregatedSignatureProof,BlockSignatures,SignedBlock --exclude-objs Checkpoint,AttestationData,Attestation,AggregatedAttestation,AggregatedSignatureProof --output types/block_encoding.go - sszgen --path pkg/types --objs State --exclude-objs ChainConfig,Checkpoint,Validator,BlockHeader --output types/state_encoding.go - sszgen --path types --objs BlocksByRangeRequest --output types/blocks_by_range_encoding.go + @rm -f types/*_encoding.go types/encoding_gen.go + sszgen --path types --objs AttestationData,Attestation,SignedAttestation,AggregatedAttestation,SignedAggregatedAttestation,BlockHeader,BlockBody,Block,AggregatedSignatureProof,BlockSignatures,SignedBlock,BlocksByRangeRequest,Checkpoint,ChainConfig,State,Validator --output types/encoding_gen.go clean: ## Remove build artifacts and generated files rm -rf bin data @@ -132,4 +126,3 @@ run-devnet: docker-build lean-quickstart ## Run local multi-client devnet @echo "Starting local devnet with gean client (\"$(DOCKER_TAG)\" tag)." @cd lean-quickstart \ && NETWORK_DIR=local-devnet ./spin-node.sh --node all --generateGenesis --metrics > ../devnet.log 2>&1 - diff --git a/checkpoint/checkpoint.go b/checkpoint/checkpoint.go index d683dccc..f8066a5e 100644 --- a/checkpoint/checkpoint.go +++ b/checkpoint/checkpoint.go @@ -10,7 +10,7 @@ import ( "github.com/geanlabs/gean/types" ) -// Timeouts rs L9-13. +// HTTP timeouts for checkpoint sync requests. const ( CheckpointConnectTimeout = 15 * time.Second CheckpointReadTimeout = 15 * time.Second diff --git a/forkchoice/protoarray.go b/forkchoice/protoarray.go index 06b9f964..8ff675a8 100644 --- a/forkchoice/protoarray.go +++ b/forkchoice/protoarray.go @@ -146,12 +146,6 @@ func (pa *ProtoArray) FindHead(justifiedRoot [32]byte) [32]byte { return pa.nodes[bestDesc].Root } -// FindHeadWithThreshold is like FindHead but with a minimum weight cutoff. -// Used for safe target computation (2/3 threshold). -func (pa *ProtoArray) FindHeadWithThreshold(justifiedRoot [32]byte, minScore int64) [32]byte { - return pa.FindHead(justifiedRoot) // cutoff applied during ApplyScoreChanges -} - // Prune removes all nodes below the finalized root. func (pa *ProtoArray) Prune(finalizedRoot [32]byte) { finalizedIdx, ok := pa.indices[finalizedRoot] diff --git a/go.mod b/go.mod index 7be2c70a..e09054af 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.25.7 require ( github.com/cockroachdb/pebble v1.1.5 github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1 - github.com/ethereum/go-ethereum v1.17.2 github.com/ferranbt/fastssz v1.0.0 github.com/golang/snappy v1.0.0 github.com/libp2p/go-libp2p v0.48.0 @@ -37,7 +36,6 @@ require ( github.com/google/uuid v1.6.0 // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect - github.com/holiman/uint256 v1.3.2 // indirect github.com/huin/goupnp v1.3.0 // indirect github.com/ipfs/go-cid v0.5.0 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect diff --git a/go.sum b/go.sum index a8bf23e4..4bc10674 100644 --- a/go.sum +++ b/go.sum @@ -39,8 +39,6 @@ github.com/dunglas/httpsfv v1.1.0 h1:Jw76nAyKWKZKFrpMMcL76y35tOpYHqQPzHQiwDvpe54 github.com/dunglas/httpsfv v1.1.0/go.mod h1:zID2mqw9mFsnt7YC3vYQ9/cjq30q41W+1AnDwH8TiMg= github.com/emicklei/dot v1.6.2 h1:08GN+DD79cy/tzN6uLCT84+2Wk9u+wvqP+Hkx/dIR8A= github.com/emicklei/dot v1.6.2/go.mod h1:DeV7GvQtIw4h2u73RKBkkFdvVAz0D9fzeJrgPW6gy/s= -github.com/ethereum/go-ethereum v1.17.2 h1:ag6geu0kn8Hv5FLKTpH+Hm2DHD+iuFtuqKxEuwUsDOI= -github.com/ethereum/go-ethereum v1.17.2/go.mod h1:KHcRXfGOUfUmKg51IhQ0IowiqZ6PqZf08CMtk0g5K1o= github.com/ferranbt/fastssz v1.0.0 h1:9EXXYsracSqQRBQiHeaVsG/KQeYblPf40hsQPb9Dzk8= github.com/ferranbt/fastssz v1.0.0/go.mod h1:Ea3+oeoRGGLGm5shYAeDgu6PGUlcvQhE2fILyD9+tGg= github.com/flynn/noise v1.1.0 h1:KjPQoQCEFdZDiP03phOvGi11+SVVhBG2wOWAorLsstg= @@ -61,8 +59,6 @@ github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aN github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= -github.com/holiman/uint256 v1.3.2 h1:a9EgMPSC1AAaj1SZL5zIQD3WbwTuHrMGOerLjGmM/TA= -github.com/holiman/uint256 v1.3.2/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc= github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= github.com/ipfs/go-cid v0.5.0 h1:goEKKhaGm0ul11IHA7I6p1GmKz8kEYniqFopaB5Otwg= diff --git a/internal/rlp/rlp.go b/internal/rlp/rlp.go new file mode 100644 index 00000000..6df3f3cf --- /dev/null +++ b/internal/rlp/rlp.go @@ -0,0 +1,233 @@ +package rlp + +import ( + "encoding/binary" + "fmt" +) + +type valueKind byte + +const ( + stringKind valueKind = iota + listKind +) + +// SplitList decodes a top-level RLP list and returns each element as its raw +// encoded RLP value. +func SplitList(input []byte) ([][]byte, error) { + kind, payload, rest, err := split(input) + if err != nil { + return nil, err + } + if kind != listKind { + return nil, fmt.Errorf("rlp: expected list") + } + if len(rest) != 0 { + return nil, fmt.Errorf("rlp: trailing data") + } + + items := make([][]byte, 0) + for len(payload) > 0 { + _, _, next, err := split(payload) + if err != nil { + return nil, err + } + rawLen := len(payload) - len(next) + items = append(items, payload[:rawLen]) + payload = next + } + return items, nil +} + +// Bytes decodes one RLP string value. +func Bytes(input []byte) ([]byte, error) { + kind, payload, rest, err := split(input) + if err != nil { + return nil, err + } + if kind != stringKind { + return nil, fmt.Errorf("rlp: expected string") + } + if len(rest) != 0 { + return nil, fmt.Errorf("rlp: trailing data") + } + return payload, nil +} + +// String decodes one RLP string value as a Go string. +func String(input []byte) (string, error) { + b, err := Bytes(input) + if err != nil { + return "", err + } + return string(b), nil +} + +// Uint64 decodes one RLP unsigned integer. +func Uint64(input []byte) (uint64, error) { + b, err := Bytes(input) + if err != nil { + return 0, err + } + if len(b) == 0 { + return 0, nil + } + if len(b) > 8 { + return 0, fmt.Errorf("rlp: uint64 overflow") + } + if len(b) > 1 && b[0] == 0 { + return 0, fmt.Errorf("rlp: non-minimal integer") + } + var buf [8]byte + copy(buf[8-len(b):], b) + return binary.BigEndian.Uint64(buf[:]), nil +} + +// Uint16 decodes one RLP unsigned integer and verifies it fits in 16 bits. +func Uint16(input []byte) (uint16, error) { + v, err := Uint64(input) + if err != nil { + return 0, err + } + if v > uint64(^uint16(0)) { + return 0, fmt.Errorf("rlp: uint16 overflow") + } + return uint16(v), nil +} + +// EncodeBytes encodes a byte string as RLP. +func EncodeBytes(payload []byte) []byte { + if len(payload) == 1 && payload[0] < 0x80 { + return []byte{payload[0]} + } + return encodePayload(0x80, 0xb7, payload) +} + +// EncodeUint64 encodes an unsigned integer as RLP. +func EncodeUint64(v uint64) []byte { + if v == 0 { + return []byte{0x80} + } + var buf [8]byte + binary.BigEndian.PutUint64(buf[:], v) + i := 0 + for i < len(buf) && buf[i] == 0 { + i++ + } + return EncodeBytes(buf[i:]) +} + +// EncodeUint16 encodes a uint16 as RLP. +func EncodeUint16(v uint16) []byte { + return EncodeUint64(uint64(v)) +} + +// EncodeList encodes already-encoded RLP values as an RLP list. +func EncodeList(items ...[]byte) []byte { + payloadLen := 0 + for _, item := range items { + payloadLen += len(item) + } + payload := make([]byte, 0, payloadLen) + for _, item := range items { + payload = append(payload, item...) + } + return encodePayload(0xc0, 0xf7, payload) +} + +func split(input []byte) (valueKind, []byte, []byte, error) { + if len(input) == 0 { + return 0, nil, nil, fmt.Errorf("rlp: empty input") + } + + prefix := input[0] + switch { + case prefix < 0x80: + return stringKind, input[:1], input[1:], nil + case prefix <= 0xb7: + size := int(prefix - 0x80) + if len(input) < 1+size { + return 0, nil, nil, fmt.Errorf("rlp: short string") + } + if size == 1 && input[1] < 0x80 { + return 0, nil, nil, fmt.Errorf("rlp: non-minimal string") + } + return stringKind, input[1 : 1+size], input[1+size:], nil + case prefix <= 0xbf: + sizeOfSize := int(prefix - 0xb7) + size, err := readSize(input[1:], sizeOfSize) + if err != nil { + return 0, nil, nil, err + } + if size <= 55 { + return 0, nil, nil, fmt.Errorf("rlp: non-minimal long string") + } + offset := 1 + sizeOfSize + if len(input) < offset+size { + return 0, nil, nil, fmt.Errorf("rlp: short long string") + } + return stringKind, input[offset : offset+size], input[offset+size:], nil + case prefix <= 0xf7: + size := int(prefix - 0xc0) + if len(input) < 1+size { + return 0, nil, nil, fmt.Errorf("rlp: short list") + } + return listKind, input[1 : 1+size], input[1+size:], nil + default: + sizeOfSize := int(prefix - 0xf7) + size, err := readSize(input[1:], sizeOfSize) + if err != nil { + return 0, nil, nil, err + } + if size <= 55 { + return 0, nil, nil, fmt.Errorf("rlp: non-minimal long list") + } + offset := 1 + sizeOfSize + if len(input) < offset+size { + return 0, nil, nil, fmt.Errorf("rlp: short long list") + } + return listKind, input[offset : offset+size], input[offset+size:], nil + } +} + +func readSize(input []byte, sizeOfSize int) (int, error) { + if sizeOfSize == 0 || sizeOfSize > 8 { + return 0, fmt.Errorf("rlp: invalid length size") + } + if len(input) < sizeOfSize { + return 0, fmt.Errorf("rlp: short length") + } + if input[0] == 0 { + return 0, fmt.Errorf("rlp: non-minimal length") + } + var size uint64 + for _, b := range input[:sizeOfSize] { + size = size<<8 | uint64(b) + } + if size > uint64(int(^uint(0)>>1)) { + return 0, fmt.Errorf("rlp: length overflow") + } + return int(size), nil +} + +func encodePayload(shortBase, longBase byte, payload []byte) []byte { + if len(payload) <= 55 { + out := make([]byte, 1+len(payload)) + out[0] = shortBase + byte(len(payload)) + copy(out[1:], payload) + return out + } + + var lenBuf [8]byte + binary.BigEndian.PutUint64(lenBuf[:], uint64(len(payload))) + i := 0 + for i < len(lenBuf) && lenBuf[i] == 0 { + i++ + } + sizeBytes := lenBuf[i:] + out := make([]byte, 1+len(sizeBytes)+len(payload)) + out[0] = longBase + byte(len(sizeBytes)) + copy(out[1:], sizeBytes) + copy(out[1+len(sizeBytes):], payload) + return out +} diff --git a/internal/rlp/rlp_test.go b/internal/rlp/rlp_test.go new file mode 100644 index 00000000..e3e675b8 --- /dev/null +++ b/internal/rlp/rlp_test.go @@ -0,0 +1,79 @@ +package rlp + +import ( + "bytes" + "encoding/hex" + "testing" +) + +func TestEncodeExamples(t *testing.T) { + tests := []struct { + name string + got []byte + want string + }{ + {name: "empty bytes", got: EncodeBytes(nil), want: "80"}, + {name: "single byte", got: EncodeBytes([]byte{0x7f}), want: "7f"}, + {name: "dog", got: EncodeBytes([]byte("dog")), want: "83646f67"}, + {name: "small uint", got: EncodeUint64(15), want: "0f"}, + {name: "larger uint", got: EncodeUint64(1024), want: "820400"}, + {name: "list", got: EncodeList(EncodeBytes([]byte("cat")), EncodeBytes([]byte("dog"))), want: "c88363617483646f67"}, + } + + for _, tt := range tests { + if hex.EncodeToString(tt.got) != tt.want { + t.Fatalf("%s: got %x, want %s", tt.name, tt.got, tt.want) + } + } +} + +func TestSplitListDecode(t *testing.T) { + encoded := EncodeList(EncodeBytes([]byte("udp")), EncodeUint16(30303)) + items, err := SplitList(encoded) + if err != nil { + t.Fatalf("SplitList: %v", err) + } + if len(items) != 2 { + t.Fatalf("got %d items, want 2", len(items)) + } + key, err := String(items[0]) + if err != nil { + t.Fatalf("String: %v", err) + } + port, err := Uint16(items[1]) + if err != nil { + t.Fatalf("Uint16: %v", err) + } + if key != "udp" || port != 30303 { + t.Fatalf("got (%q, %d), want (udp, 30303)", key, port) + } +} + +func TestEncodeLongString(t *testing.T) { + payload := bytes.Repeat([]byte{'a'}, 56) + got := EncodeBytes(payload) + if len(got) != 58 || got[0] != 0xb8 || got[1] != 56 { + t.Fatalf("got long string prefix %x, want b838", got[:2]) + } + if !bytes.Equal(got[2:], payload) { + t.Fatalf("long string payload mismatch") + } +} + +func TestRejectNonCanonicalForms(t *testing.T) { + tests := []struct { + name string + fn func() error + }{ + {name: "non-minimal string", fn: func() error { _, err := Bytes([]byte{0x81, 0x7f}); return err }}, + {name: "non-minimal integer", fn: func() error { _, err := Uint64([]byte{0x82, 0x00, 0x01}); return err }}, + {name: "non-minimal long string", fn: func() error { _, err := Bytes([]byte{0xb8, 0x01, 0x00}); return err }}, + {name: "non-minimal length", fn: func() error { _, err := Bytes([]byte{0xb9, 0x00, 0x38}); return err }}, + } + + for _, tt := range tests { + if err := tt.fn(); err == nil { + t.Fatalf("%s: expected error", tt.name) + } + } +} diff --git a/node/consensus_store.go b/node/consensus_store.go index 3f986074..f14da37c 100644 --- a/node/consensus_store.go +++ b/node/consensus_store.go @@ -10,16 +10,14 @@ import ( ) const ( - // Buffer capacities rs L87-91. aggregatedPayloadCap = 0 // unbounded, pruned on finalization only newPayloadCap = 0 // unbounded ) // ConsensusStore holds all state required for fork choice and block processing. // -// Note: ForkChoice does NOT live here — it lives in Engine (Phase 7), -// Engine calls ForkChoice with store data as parameters. -// with store data as parameters. +// ForkChoice lives in Engine. Engine passes store data into fork-choice updates +// rather than storing fork-choice state here. type ConsensusStore struct { Backend storage.Backend NewPayloads *PayloadBuffer diff --git a/node/node.go b/node/node.go index 666d98c6..4f6a5c08 100644 --- a/node/node.go +++ b/node/node.go @@ -16,9 +16,6 @@ import ( // from Makefile / Dockerfile, surfaced through the lean_node_info Prometheus gauge. var gitCommit = "unknown" -// Engine is the consensus coordination loop. -// It owns Store, ForkChoice, and KeyManager as siblings, -// rs L78-95). // Pending block limits to prevent stuck-forever scenarios. const ( MaxBlockFetchDepth = 512 // Max ancestor chain depth before discarding @@ -34,6 +31,8 @@ const ( PendingAttestationsTotalCap = 512 ) +// Engine is the consensus coordination loop. +// It owns Store, ForkChoice, and KeyManager as siblings. type Engine struct { Store *ConsensusStore FC *forkchoice.ForkChoice @@ -77,17 +76,17 @@ func New( committeeCount uint64, ) *Engine { return &Engine{ - Store: s, - FC: fc, - P2P: p2pHost, - Keys: keys, - AggCtl: aggCtl, - DutyGate: NewDutyGate(), - CommitteeCount: committeeCount, - PendingBlocks: make(map[[32]byte]map[[32]byte]bool), - PendingBlockParents: make(map[[32]byte][32]byte), - PendingBlockDepths: make(map[[32]byte]int), - PendingAttestations: NewPendingAttestationBuffer(PendingAttestationsPerRootCap, PendingAttestationsTotalCap), + Store: s, + FC: fc, + P2P: p2pHost, + Keys: keys, + AggCtl: aggCtl, + DutyGate: NewDutyGate(), + CommitteeCount: committeeCount, + PendingBlocks: make(map[[32]byte]map[[32]byte]bool), + PendingBlockParents: make(map[[32]byte][32]byte), + PendingBlockDepths: make(map[[32]byte]int), + PendingAttestations: NewPendingAttestationBuffer(PendingAttestationsPerRootCap, PendingAttestationsTotalCap), BlockCh: make(chan *types.SignedBlock, 64), AttestationCh: make(chan *types.SignedAttestation, 256), AggregationCh: make(chan *types.SignedAggregatedAttestation, 64), diff --git a/node/store_build.go b/node/store_build.go index 7bdab854..3abc6586 100644 --- a/node/store_build.go +++ b/node/store_build.go @@ -122,7 +122,7 @@ func buildBlock( if sorted[i].entry.Data.Target.Slot != sorted[j].entry.Data.Target.Slot { return sorted[i].entry.Data.Target.Slot < sorted[j].entry.Data.Target.Slot } - return compareRoots(sorted[i].dataRoot, sorted[j].dataRoot) < 0 + return bytes.Compare(sorted[i].dataRoot[:], sorted[j].dataRoot[:]) < 0 }) processedAttData := make(map[[32]byte]bool) @@ -461,15 +461,3 @@ func attestationDataMatchesChain(state *types.State, data *types.AttestationData } return true } - -func compareRoots(a, b [32]byte) int { - for i := 0; i < 32; i++ { - if a[i] != b[i] { - if a[i] < b[i] { - return -1 - } - return 1 - } - } - return 0 -} diff --git a/p2p/encoding.go b/p2p/encoding.go index 93994aab..d9eef3f7 100644 --- a/p2p/encoding.go +++ b/p2p/encoding.go @@ -9,7 +9,7 @@ import ( "github.com/golang/snappy" ) -// Max payload sizes rs L6-9. +// Maximum wire payload sizes. const ( MaxPayloadSize = 10 * 1024 * 1024 // 10 MiB uncompressed MaxCompressedPayloadSize = 32 + MaxPayloadSize + MaxPayloadSize/6 + 1024 // ~12 MiB @@ -93,7 +93,7 @@ func DecodeReqRespPayload(buf []byte) ([]byte, error) { return decoded, nil } -// Response codes rs. +// Response codes for req/resp chunks. const ( RespSuccess byte = 0x00 RespInvalidRequest byte = 0x01 diff --git a/p2p/enr.go b/p2p/enr.go index 140bac93..67a8507e 100644 --- a/p2p/enr.go +++ b/p2p/enr.go @@ -7,10 +7,11 @@ import ( "strings" "github.com/decred/dcrd/dcrec/secp256k1/v4" - "github.com/ethereum/go-ethereum/rlp" "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/peer" "github.com/multiformats/go-multiaddr" + + leanrlp "github.com/geanlabs/gean/internal/rlp" ) // ENRFields is the spec-compliant decoded view of an ENR per EIP-778. @@ -28,10 +29,38 @@ type ENRFields struct { Multiaddr string } +type decodedENR struct { + seq uint64 + peerID peer.ID + ip4 net.IP + ip6 net.IP + udpPort uint16 + quicPort uint16 + udp6Port uint16 + quic6Port uint16 +} + +func (d *decodedENR) transportMultiaddr() string { + return buildTransportMultiaddr(d.ip4, d.ip6, d.udpPort, d.quicPort, d.udp6Port, d.quic6Port) +} + // DecodeENR decodes an ENR to structured fields per EIP-778. // Unlike ParseENR, this tolerates ENRs without an ip field (returns empty // Multiaddr) and emits a transport-only multiaddr without /p2p/. func DecodeENR(enrStr string) (*ENRFields, error) { + decoded, err := decodeENR(enrStr) + if err != nil { + return nil, err + } + + return &ENRFields{ + Seq: decoded.seq, + PeerID: decoded.peerID, + Multiaddr: decoded.transportMultiaddr(), + }, nil +} + +func decodeENR(enrStr string) (*decodedENR, error) { enrStr = strings.TrimSpace(enrStr) if !strings.HasPrefix(enrStr, "enr:") { return nil, fmt.Errorf("not an ENR: %q", enrStr) @@ -42,63 +71,54 @@ func DecodeENR(enrStr string) (*ENRFields, error) { return nil, fmt.Errorf("decode ENR base64: %w", err) } - var items []rlp.RawValue - if err := rlp.DecodeBytes(data, &items); err != nil { + items, err := leanrlp.SplitList(data) + if err != nil { return nil, fmt.Errorf("decode ENR RLP: %w", err) } if len(items) < 4 { return nil, fmt.Errorf("ENR has too few items: %d", len(items)) } - var seq uint64 - if err := rlp.DecodeBytes(items[1], &seq); err != nil { + seq, err := leanrlp.Uint64(items[1]) + if err != nil { return nil, fmt.Errorf("decode ENR seq: %w", err) } - var ip4, ip6 net.IP - var udpPort, quicPort uint16 - var udp6Port, quic6Port uint16 + decoded := &decodedENR{seq: seq} var pubkeyBytes []byte for i := 2; i+1 < len(items); i += 2 { - var key string - if err := rlp.DecodeBytes(items[i], &key); err != nil { + key, err := leanrlp.String(items[i]) + if err != nil { continue } switch key { case "ip": - var ipBytes []byte - if err := rlp.DecodeBytes(items[i+1], &ipBytes); err == nil && len(ipBytes) == 4 { - ip4 = net.IP(ipBytes) + if ipBytes, err := leanrlp.Bytes(items[i+1]); err == nil && len(ipBytes) == 4 { + decoded.ip4 = net.IP(ipBytes) } case "ip6": - var ipBytes []byte - if err := rlp.DecodeBytes(items[i+1], &ipBytes); err == nil && len(ipBytes) == 16 { - ip6 = net.IP(ipBytes) + if ipBytes, err := leanrlp.Bytes(items[i+1]); err == nil && len(ipBytes) == 16 { + decoded.ip6 = net.IP(ipBytes) } case "udp": - var port uint16 - if err := rlp.DecodeBytes(items[i+1], &port); err == nil { - udpPort = port + if port, err := leanrlp.Uint16(items[i+1]); err == nil { + decoded.udpPort = port } case "udp6": - var port uint16 - if err := rlp.DecodeBytes(items[i+1], &port); err == nil { - udp6Port = port + if port, err := leanrlp.Uint16(items[i+1]); err == nil { + decoded.udp6Port = port } case "quic": - var port uint16 - if err := rlp.DecodeBytes(items[i+1], &port); err == nil { - quicPort = port + if port, err := leanrlp.Uint16(items[i+1]); err == nil { + decoded.quicPort = port } case "quic6": - var port uint16 - if err := rlp.DecodeBytes(items[i+1], &port); err == nil { - quic6Port = port + if port, err := leanrlp.Uint16(items[i+1]); err == nil { + decoded.quic6Port = port } case "secp256k1": - var raw []byte - if err := rlp.DecodeBytes(items[i+1], &raw); err == nil { + if raw, err := leanrlp.Bytes(items[i+1]); err == nil { pubkeyBytes = raw } } @@ -120,12 +140,9 @@ func DecodeENR(enrStr string) (*ENRFields, error) { if err != nil { return nil, fmt.Errorf("derive peer ID: %w", err) } + decoded.peerID = peerID - // Build transport-only multiaddr when possible. No /p2p/ suffix. - // Prefer IPv4 when both are present (standard devp2p convention); fall back to IPv6. - maStr := buildTransportMultiaddr(ip4, ip6, udpPort, quicPort, udp6Port, quic6Port) - - return &ENRFields{Seq: seq, PeerID: peerID, Multiaddr: maStr}, nil + return decoded, nil } // ParseENR decodes an ENR string and returns a dial-ready multiaddr. @@ -133,108 +150,21 @@ func DecodeENR(enrStr string) (*ENRFields, error) { // Prefers IPv4 when both ip and ip6 are present; falls back to IPv6. // Emits /ip4//udp//quic-v1/p2p/ or /ip6/... depending on the address family. func ParseENR(enrStr string) (multiaddr.Multiaddr, error) { - enrStr = strings.TrimSpace(enrStr) - if !strings.HasPrefix(enrStr, "enr:") { - return nil, fmt.Errorf("not an ENR: %q", enrStr) - } - - b64 := enrStr[4:] - data, err := base64.RawURLEncoding.DecodeString(b64) + decoded, err := decodeENR(enrStr) if err != nil { - return nil, fmt.Errorf("decode ENR base64: %w", err) - } - - // Decode RLP list: [signature, seq, k1, v1, k2, v2, ...] - var items []rlp.RawValue - if err := rlp.DecodeBytes(data, &items); err != nil { - return nil, fmt.Errorf("decode ENR RLP: %w", err) - } - - if len(items) < 4 { - return nil, fmt.Errorf("ENR has too few items: %d", len(items)) - } - - // Parse key-value pairs (skip signature at index 0, seq at index 1). - var ip4, ip6 net.IP - var udpPort, quicPort uint16 - var udp6Port, quic6Port uint16 - var pubkeyBytes []byte - - for i := 2; i+1 < len(items); i += 2 { - var key string - if err := rlp.DecodeBytes(items[i], &key); err != nil { - continue - } - - switch key { - case "ip": - var ipBytes []byte - if err := rlp.DecodeBytes(items[i+1], &ipBytes); err == nil && len(ipBytes) == 4 { - ip4 = net.IP(ipBytes) - } - case "ip6": - var ipBytes []byte - if err := rlp.DecodeBytes(items[i+1], &ipBytes); err == nil && len(ipBytes) == 16 { - ip6 = net.IP(ipBytes) - } - case "udp": - var port uint16 - if err := rlp.DecodeBytes(items[i+1], &port); err == nil { - udpPort = port - } - case "udp6": - var port uint16 - if err := rlp.DecodeBytes(items[i+1], &port); err == nil { - udp6Port = port - } - case "quic": - var port uint16 - if err := rlp.DecodeBytes(items[i+1], &port); err == nil { - quicPort = port - } - case "quic6": - var port uint16 - if err := rlp.DecodeBytes(items[i+1], &port); err == nil { - quic6Port = port - } - case "secp256k1": - var raw []byte - if err := rlp.DecodeBytes(items[i+1], &raw); err == nil { - pubkeyBytes = raw - } - } + return nil, err } - - if ip4 == nil && ip6 == nil { + if decoded.ip4 == nil && decoded.ip6 == nil { return nil, fmt.Errorf("ENR missing ip/ip6 field") } - if len(pubkeyBytes) == 0 { - return nil, fmt.Errorf("ENR missing secp256k1 key") - } - - // Derive libp2p peer ID from secp256k1 compressed pubkey. - secpKey, err := secp256k1.ParsePubKey(pubkeyBytes) - if err != nil { - return nil, fmt.Errorf("parse secp256k1 key: %w", err) - } - - libp2pKey, err := crypto.UnmarshalSecp256k1PublicKey(secpKey.SerializeCompressed()) - if err != nil { - return nil, fmt.Errorf("convert to libp2p key: %w", err) - } - - peerID, err := peer.IDFromPublicKey(libp2pKey) - if err != nil { - return nil, fmt.Errorf("derive peer ID: %w", err) - } // Build transport multiaddr, then append /p2p/ for dialing. // Prefer IPv4 when both are present; fall back to IPv6. - transport := buildTransportMultiaddr(ip4, ip6, udpPort, quicPort, udp6Port, quic6Port) + transport := decoded.transportMultiaddr() if transport == "" { return nil, fmt.Errorf("ENR missing udp/quic port") } - ma, err := multiaddr.NewMultiaddr(fmt.Sprintf("%s/p2p/%s", transport, peerID)) + ma, err := multiaddr.NewMultiaddr(fmt.Sprintf("%s/p2p/%s", transport, decoded.peerID)) if err != nil { return nil, fmt.Errorf("build multiaddr: %w", err) } diff --git a/p2p/host.go b/p2p/host.go index 9a3dd4e8..57dcc9bb 100644 --- a/p2p/host.go +++ b/p2p/host.go @@ -21,7 +21,7 @@ import ( "github.com/geanlabs/gean/logger" ) -// GossipSub parameters rs L96-119. +// GossipSub mesh and cache parameters. const ( GossipMeshN = 8 GossipMeshNLow = 6 diff --git a/p2p/msgid.go b/p2p/msgid.go index 25dd098d..88046726 100644 --- a/p2p/msgid.go +++ b/p2p/msgid.go @@ -5,7 +5,7 @@ import ( "encoding/binary" ) -// Message ID domains rs L619-638. +// Gossipsub message ID domains for valid and invalid snappy payloads. var ( domainValidSnappy = [4]byte{0x01, 0x00, 0x00, 0x00} domainInvalidSnappy = [4]byte{0x00, 0x00, 0x00, 0x00} diff --git a/p2p/peers.go b/p2p/peers.go index 77d884c7..78bb244d 100644 --- a/p2p/peers.go +++ b/p2p/peers.go @@ -15,7 +15,7 @@ import ( "github.com/geanlabs/gean/types" ) -// Retry parameters rs L56-59. +// Peer retry and sync request parameters. const ( MaxFetchRetries = 10 InitialBackoffMs = 5 diff --git a/spectests/networking_test.go b/spectests/networking_test.go index 39976737..c0e51236 100644 --- a/spectests/networking_test.go +++ b/spectests/networking_test.go @@ -13,8 +13,7 @@ import ( "strings" "testing" - "github.com/ethereum/go-ethereum/rlp" - + leanrlp "github.com/geanlabs/gean/internal/rlp" "github.com/geanlabs/gean/p2p" ) @@ -286,43 +285,38 @@ func testDiscv5Message(t *testing.T, fx netFixture) string { return "skip" } - var fields []interface{} + var fields [][]byte reqIDHex, _ := fx.Input["requestId"].(string) reqID, _ := decodeHex(reqIDHex) // Strip leading zeros per discv5 minimal encoding. for len(reqID) > 1 && reqID[0] == 0 { reqID = reqID[1:] } - fields = append(fields, reqID) + fields = append(fields, leanrlp.EncodeBytes(reqID)) switch msgType { case "ping": enrSeq := uint64(fx.Input["enrSeq"].(float64)) - fields = append(fields, enrSeq) + fields = append(fields, leanrlp.EncodeUint64(enrSeq)) case "pong": enrSeq := uint64(fx.Input["enrSeq"].(float64)) ipHex, _ := fx.Input["recipientIp"].(string) ip, _ := decodeHex(ipHex) port := uint16(fx.Input["recipientPort"].(float64)) - fields = append(fields, enrSeq, ip, port) + fields = append(fields, leanrlp.EncodeUint64(enrSeq), leanrlp.EncodeBytes(ip), leanrlp.EncodeUint16(port)) case "findnode": dists, _ := fx.Input["distances"].([]interface{}) - var ds []uint64 + encodedDistances := make([][]byte, 0, len(dists)) for _, d := range dists { - ds = append(ds, uint64(d.(float64))) + encodedDistances = append(encodedDistances, leanrlp.EncodeUint64(uint64(d.(float64)))) } - fields = append(fields, ds) + fields = append(fields, leanrlp.EncodeList(encodedDistances...)) default: t.Skipf("discv5 message type %q encoding not yet implemented", msgType) return "skip" } - encoded, err := rlp.EncodeToBytes(fields) - if err != nil { - t.Errorf("rlp encode: %v", err) - return "fail" - } - + encoded := leanrlp.EncodeList(fields...) got := append([]byte{typeByte}, encoded...) if fmt.Sprintf("%x", got) != fmt.Sprintf("%x", want) { t.Errorf("type=%s: got %x, want %x", msgType, got, want) diff --git a/storage/keys.go b/storage/keys.go index 3b55c9ef..2117d135 100644 --- a/storage/keys.go +++ b/storage/keys.go @@ -2,7 +2,7 @@ package storage import "encoding/binary" -// Metadata keys rs L62-72. +// Metadata keys stored in the consensus backend. var ( KeyTime = []byte("time") KeyConfig = []byte("config") @@ -12,7 +12,7 @@ var ( KeyLatestFinalized = []byte("latest_finalized") ) -// Retention constants rs L75-78. +// Retention limits for prunable block and state history. const ( BlocksToKeep = 21_600 // ~1 day at 4s slots StatesToKeep = 3_000 // ~3.3 hours at 4s slots diff --git a/types/attestation_encoding.go b/types/attestation_encoding.go deleted file mode 100644 index a51c7c1f..00000000 --- a/types/attestation_encoding.go +++ /dev/null @@ -1,670 +0,0 @@ -// Code generated by fastssz. DO NOT EDIT. -// Hash: 52b67ea3b7cb79482579d5c3ff659d3473b41bec2511e9c0fd826505bb9f9f72 -// Version: 0.1.3 -package types - -import ( - ssz "github.com/ferranbt/fastssz" -) - -// MarshalSSZ ssz marshals the AttestationData object -func (a *AttestationData) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(a) -} - -// MarshalSSZTo ssz marshals the AttestationData object to a target array -func (a *AttestationData) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'Slot' - dst = ssz.MarshalUint64(dst, a.Slot) - - // Field (1) 'Head' - if a.Head == nil { - a.Head = new(Checkpoint) - } - if dst, err = a.Head.MarshalSSZTo(dst); err != nil { - return - } - - // Field (2) 'Target' - if a.Target == nil { - a.Target = new(Checkpoint) - } - if dst, err = a.Target.MarshalSSZTo(dst); err != nil { - return - } - - // Field (3) 'Source' - if a.Source == nil { - a.Source = new(Checkpoint) - } - if dst, err = a.Source.MarshalSSZTo(dst); err != nil { - return - } - - return -} - -// UnmarshalSSZ ssz unmarshals the AttestationData object -func (a *AttestationData) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 128 { - return ssz.ErrSize - } - - // Field (0) 'Slot' - a.Slot = ssz.UnmarshallUint64(buf[0:8]) - - // Field (1) 'Head' - if a.Head == nil { - a.Head = new(Checkpoint) - } - if err = a.Head.UnmarshalSSZ(buf[8:48]); err != nil { - return err - } - - // Field (2) 'Target' - if a.Target == nil { - a.Target = new(Checkpoint) - } - if err = a.Target.UnmarshalSSZ(buf[48:88]); err != nil { - return err - } - - // Field (3) 'Source' - if a.Source == nil { - a.Source = new(Checkpoint) - } - if err = a.Source.UnmarshalSSZ(buf[88:128]); err != nil { - return err - } - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the AttestationData object -func (a *AttestationData) SizeSSZ() (size int) { - size = 128 - return -} - -// HashTreeRoot ssz hashes the AttestationData object -func (a *AttestationData) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(a) -} - -// HashTreeRootWith ssz hashes the AttestationData object with a hasher -func (a *AttestationData) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Slot' - hh.PutUint64(a.Slot) - - // Field (1) 'Head' - if a.Head == nil { - a.Head = new(Checkpoint) - } - if err = a.Head.HashTreeRootWith(hh); err != nil { - return - } - - // Field (2) 'Target' - if a.Target == nil { - a.Target = new(Checkpoint) - } - if err = a.Target.HashTreeRootWith(hh); err != nil { - return - } - - // Field (3) 'Source' - if a.Source == nil { - a.Source = new(Checkpoint) - } - if err = a.Source.HashTreeRootWith(hh); err != nil { - return - } - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the AttestationData object -func (a *AttestationData) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(a) -} - -// MarshalSSZ ssz marshals the Attestation object -func (a *Attestation) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(a) -} - -// MarshalSSZTo ssz marshals the Attestation object to a target array -func (a *Attestation) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'ValidatorID' - dst = ssz.MarshalUint64(dst, a.ValidatorID) - - // Field (1) 'Data' - if a.Data == nil { - a.Data = new(AttestationData) - } - if dst, err = a.Data.MarshalSSZTo(dst); err != nil { - return - } - - return -} - -// UnmarshalSSZ ssz unmarshals the Attestation object -func (a *Attestation) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 136 { - return ssz.ErrSize - } - - // Field (0) 'ValidatorID' - a.ValidatorID = ssz.UnmarshallUint64(buf[0:8]) - - // Field (1) 'Data' - if a.Data == nil { - a.Data = new(AttestationData) - } - if err = a.Data.UnmarshalSSZ(buf[8:136]); err != nil { - return err - } - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the Attestation object -func (a *Attestation) SizeSSZ() (size int) { - size = 136 - return -} - -// HashTreeRoot ssz hashes the Attestation object -func (a *Attestation) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(a) -} - -// HashTreeRootWith ssz hashes the Attestation object with a hasher -func (a *Attestation) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'ValidatorID' - hh.PutUint64(a.ValidatorID) - - // Field (1) 'Data' - if a.Data == nil { - a.Data = new(AttestationData) - } - if err = a.Data.HashTreeRootWith(hh); err != nil { - return - } - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the Attestation object -func (a *Attestation) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(a) -} - -// MarshalSSZ ssz marshals the SignedAttestation object -func (s *SignedAttestation) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(s) -} - -// MarshalSSZTo ssz marshals the SignedAttestation object to a target array -func (s *SignedAttestation) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'ValidatorID' - dst = ssz.MarshalUint64(dst, s.ValidatorID) - - // Field (1) 'Data' - if s.Data == nil { - s.Data = new(AttestationData) - } - if dst, err = s.Data.MarshalSSZTo(dst); err != nil { - return - } - - // Field (2) 'Signature' - dst = append(dst, s.Signature[:]...) - - return -} - -// UnmarshalSSZ ssz unmarshals the SignedAttestation object -func (s *SignedAttestation) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 2672 { - return ssz.ErrSize - } - - // Field (0) 'ValidatorID' - s.ValidatorID = ssz.UnmarshallUint64(buf[0:8]) - - // Field (1) 'Data' - if s.Data == nil { - s.Data = new(AttestationData) - } - if err = s.Data.UnmarshalSSZ(buf[8:136]); err != nil { - return err - } - - // Field (2) 'Signature' - copy(s.Signature[:], buf[136:2672]) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the SignedAttestation object -func (s *SignedAttestation) SizeSSZ() (size int) { - size = 2672 - return -} - -// HashTreeRoot ssz hashes the SignedAttestation object -func (s *SignedAttestation) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(s) -} - -// HashTreeRootWith ssz hashes the SignedAttestation object with a hasher -func (s *SignedAttestation) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'ValidatorID' - hh.PutUint64(s.ValidatorID) - - // Field (1) 'Data' - if s.Data == nil { - s.Data = new(AttestationData) - } - if err = s.Data.HashTreeRootWith(hh); err != nil { - return - } - - // Field (2) 'Signature' - hh.PutBytes(s.Signature[:]) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the SignedAttestation object -func (s *SignedAttestation) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(s) -} - -// MarshalSSZ ssz marshals the AggregatedAttestation object -func (a *AggregatedAttestation) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(a) -} - -// MarshalSSZTo ssz marshals the AggregatedAttestation object to a target array -func (a *AggregatedAttestation) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - offset := int(132) - - // Offset (0) 'AggregationBits' - dst = ssz.WriteOffset(dst, offset) - - // Field (1) 'Data' - if a.Data == nil { - a.Data = new(AttestationData) - } - if dst, err = a.Data.MarshalSSZTo(dst); err != nil { - return - } - - // Field (0) 'AggregationBits' - if size := len(a.AggregationBits); size > 4096 { - err = ssz.ErrBytesLengthFn("AggregatedAttestation.AggregationBits", size, 4096) - return - } - dst = append(dst, a.AggregationBits...) - - return -} - -// UnmarshalSSZ ssz unmarshals the AggregatedAttestation object -func (a *AggregatedAttestation) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size < 132 { - return ssz.ErrSize - } - - tail := buf - var o0 uint64 - - // Offset (0) 'AggregationBits' - if o0 = ssz.ReadOffset(buf[0:4]); o0 > size { - return ssz.ErrOffset - } - - if o0 != 132 { - return ssz.ErrInvalidVariableOffset - } - - // Field (1) 'Data' - if a.Data == nil { - a.Data = new(AttestationData) - } - if err = a.Data.UnmarshalSSZ(buf[4:132]); err != nil { - return err - } - - // Field (0) 'AggregationBits' - { - buf = tail[o0:] - if err = ssz.ValidateBitlist(buf, 4096); err != nil { - return err - } - if cap(a.AggregationBits) == 0 { - a.AggregationBits = make([]byte, 0, len(buf)) - } - a.AggregationBits = append(a.AggregationBits, buf...) - } - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the AggregatedAttestation object -func (a *AggregatedAttestation) SizeSSZ() (size int) { - size = 132 - - // Field (0) 'AggregationBits' - size += len(a.AggregationBits) - - return -} - -// HashTreeRoot ssz hashes the AggregatedAttestation object -func (a *AggregatedAttestation) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(a) -} - -// HashTreeRootWith ssz hashes the AggregatedAttestation object with a hasher -func (a *AggregatedAttestation) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'AggregationBits' - if len(a.AggregationBits) == 0 { - err = ssz.ErrEmptyBitlist - return - } - hh.PutBitlist(a.AggregationBits, 4096) - - // Field (1) 'Data' - if a.Data == nil { - a.Data = new(AttestationData) - } - if err = a.Data.HashTreeRootWith(hh); err != nil { - return - } - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the AggregatedAttestation object -func (a *AggregatedAttestation) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(a) -} - -// MarshalSSZ ssz marshals the SignedAggregatedAttestation object -func (s *SignedAggregatedAttestation) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(s) -} - -// MarshalSSZTo ssz marshals the SignedAggregatedAttestation object to a target array -func (s *SignedAggregatedAttestation) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - offset := int(132) - - // Field (0) 'Data' - if s.Data == nil { - s.Data = new(AttestationData) - } - if dst, err = s.Data.MarshalSSZTo(dst); err != nil { - return - } - - // Offset (1) 'Proof' - dst = ssz.WriteOffset(dst, offset) - - // Field (1) 'Proof' - if dst, err = s.Proof.MarshalSSZTo(dst); err != nil { - return - } - - return -} - -// UnmarshalSSZ ssz unmarshals the SignedAggregatedAttestation object -func (s *SignedAggregatedAttestation) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size < 132 { - return ssz.ErrSize - } - - tail := buf - var o1 uint64 - - // Field (0) 'Data' - if s.Data == nil { - s.Data = new(AttestationData) - } - if err = s.Data.UnmarshalSSZ(buf[0:128]); err != nil { - return err - } - - // Offset (1) 'Proof' - if o1 = ssz.ReadOffset(buf[128:132]); o1 > size { - return ssz.ErrOffset - } - - if o1 != 132 { - return ssz.ErrInvalidVariableOffset - } - - // Field (1) 'Proof' - { - buf = tail[o1:] - if s.Proof == nil { - s.Proof = new(AggregatedSignatureProof) - } - if err = s.Proof.UnmarshalSSZ(buf); err != nil { - return err - } - } - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the SignedAggregatedAttestation object -func (s *SignedAggregatedAttestation) SizeSSZ() (size int) { - size = 132 - - // Field (1) 'Proof' - if s.Proof == nil { - s.Proof = new(AggregatedSignatureProof) - } - size += s.Proof.SizeSSZ() - - return -} - -// HashTreeRoot ssz hashes the SignedAggregatedAttestation object -func (s *SignedAggregatedAttestation) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(s) -} - -// HashTreeRootWith ssz hashes the SignedAggregatedAttestation object with a hasher -func (s *SignedAggregatedAttestation) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Data' - if s.Data == nil { - s.Data = new(AttestationData) - } - if err = s.Data.HashTreeRootWith(hh); err != nil { - return - } - - // Field (1) 'Proof' - if err = s.Proof.HashTreeRootWith(hh); err != nil { - return - } - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the SignedAggregatedAttestation object -func (s *SignedAggregatedAttestation) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(s) -} - -// MarshalSSZ ssz marshals the AggregatedSignatureProof object -func (a *AggregatedSignatureProof) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(a) -} - -// MarshalSSZTo ssz marshals the AggregatedSignatureProof object to a target array -func (a *AggregatedSignatureProof) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - offset := int(8) - - // Offset (0) 'Participants' - dst = ssz.WriteOffset(dst, offset) - offset += len(a.Participants) - - // Offset (1) 'ProofData' - dst = ssz.WriteOffset(dst, offset) - - // Field (0) 'Participants' - if size := len(a.Participants); size > 4096 { - err = ssz.ErrBytesLengthFn("AggregatedSignatureProof.Participants", size, 4096) - return - } - dst = append(dst, a.Participants...) - - // Field (1) 'ProofData' - if size := len(a.ProofData); size > 1048576 { - err = ssz.ErrBytesLengthFn("AggregatedSignatureProof.ProofData", size, 1048576) - return - } - dst = append(dst, a.ProofData...) - - return -} - -// UnmarshalSSZ ssz unmarshals the AggregatedSignatureProof object -func (a *AggregatedSignatureProof) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size < 8 { - return ssz.ErrSize - } - - tail := buf - var o0, o1 uint64 - - // Offset (0) 'Participants' - if o0 = ssz.ReadOffset(buf[0:4]); o0 > size { - return ssz.ErrOffset - } - - if o0 != 8 { - return ssz.ErrInvalidVariableOffset - } - - // Offset (1) 'ProofData' - if o1 = ssz.ReadOffset(buf[4:8]); o1 > size || o0 > o1 { - return ssz.ErrOffset - } - - // Field (0) 'Participants' - { - buf = tail[o0:o1] - if err = ssz.ValidateBitlist(buf, 4096); err != nil { - return err - } - if cap(a.Participants) == 0 { - a.Participants = make([]byte, 0, len(buf)) - } - a.Participants = append(a.Participants, buf...) - } - - // Field (1) 'ProofData' - { - buf = tail[o1:] - if len(buf) > 1048576 { - return ssz.ErrBytesLength - } - if cap(a.ProofData) == 0 { - a.ProofData = make([]byte, 0, len(buf)) - } - a.ProofData = append(a.ProofData, buf...) - } - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the AggregatedSignatureProof object -func (a *AggregatedSignatureProof) SizeSSZ() (size int) { - size = 8 - - // Field (0) 'Participants' - size += len(a.Participants) - - // Field (1) 'ProofData' - size += len(a.ProofData) - - return -} - -// HashTreeRoot ssz hashes the AggregatedSignatureProof object -func (a *AggregatedSignatureProof) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(a) -} - -// HashTreeRootWith ssz hashes the AggregatedSignatureProof object with a hasher -func (a *AggregatedSignatureProof) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Participants' - if len(a.Participants) == 0 { - err = ssz.ErrEmptyBitlist - return - } - hh.PutBitlist(a.Participants, 4096) - - // Field (1) 'ProofData' - { - elemIndx := hh.Index() - byteLen := uint64(len(a.ProofData)) - if byteLen > 1048576 { - err = ssz.ErrIncorrectListSize - return - } - hh.Append(a.ProofData) - hh.MerkleizeWithMixin(elemIndx, byteLen, (1048576+31)/32) - } - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the AggregatedSignatureProof object -func (a *AggregatedSignatureProof) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(a) -} diff --git a/types/block_encoding.go b/types/block_encoding.go deleted file mode 100644 index 41dc7dae..00000000 --- a/types/block_encoding.go +++ /dev/null @@ -1,614 +0,0 @@ -// Code generated by fastssz. DO NOT EDIT. -// Hash: 52b67ea3b7cb79482579d5c3ff659d3473b41bec2511e9c0fd826505bb9f9f72 -// Version: 0.1.3 -package types - -import ( - ssz "github.com/ferranbt/fastssz" -) - -// MarshalSSZ ssz marshals the BlockHeader object -func (b *BlockHeader) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(b) -} - -// MarshalSSZTo ssz marshals the BlockHeader object to a target array -func (b *BlockHeader) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'Slot' - dst = ssz.MarshalUint64(dst, b.Slot) - - // Field (1) 'ProposerIndex' - dst = ssz.MarshalUint64(dst, b.ProposerIndex) - - // Field (2) 'ParentRoot' - dst = append(dst, b.ParentRoot[:]...) - - // Field (3) 'StateRoot' - dst = append(dst, b.StateRoot[:]...) - - // Field (4) 'BodyRoot' - dst = append(dst, b.BodyRoot[:]...) - - return -} - -// UnmarshalSSZ ssz unmarshals the BlockHeader object -func (b *BlockHeader) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 112 { - return ssz.ErrSize - } - - // Field (0) 'Slot' - b.Slot = ssz.UnmarshallUint64(buf[0:8]) - - // Field (1) 'ProposerIndex' - b.ProposerIndex = ssz.UnmarshallUint64(buf[8:16]) - - // Field (2) 'ParentRoot' - copy(b.ParentRoot[:], buf[16:48]) - - // Field (3) 'StateRoot' - copy(b.StateRoot[:], buf[48:80]) - - // Field (4) 'BodyRoot' - copy(b.BodyRoot[:], buf[80:112]) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the BlockHeader object -func (b *BlockHeader) SizeSSZ() (size int) { - size = 112 - return -} - -// HashTreeRoot ssz hashes the BlockHeader object -func (b *BlockHeader) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(b) -} - -// HashTreeRootWith ssz hashes the BlockHeader object with a hasher -func (b *BlockHeader) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Slot' - hh.PutUint64(b.Slot) - - // Field (1) 'ProposerIndex' - hh.PutUint64(b.ProposerIndex) - - // Field (2) 'ParentRoot' - hh.PutBytes(b.ParentRoot[:]) - - // Field (3) 'StateRoot' - hh.PutBytes(b.StateRoot[:]) - - // Field (4) 'BodyRoot' - hh.PutBytes(b.BodyRoot[:]) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the BlockHeader object -func (b *BlockHeader) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(b) -} - -// MarshalSSZ ssz marshals the BlockBody object -func (b *BlockBody) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(b) -} - -// MarshalSSZTo ssz marshals the BlockBody object to a target array -func (b *BlockBody) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - offset := int(4) - - // Offset (0) 'Attestations' - dst = ssz.WriteOffset(dst, offset) - - // Field (0) 'Attestations' - if size := len(b.Attestations); size > 4096 { - err = ssz.ErrListTooBigFn("BlockBody.Attestations", size, 4096) - return - } - { - offset = 4 * len(b.Attestations) - for ii := 0; ii < len(b.Attestations); ii++ { - dst = ssz.WriteOffset(dst, offset) - offset += b.Attestations[ii].SizeSSZ() - } - } - for ii := 0; ii < len(b.Attestations); ii++ { - if dst, err = b.Attestations[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - return -} - -// UnmarshalSSZ ssz unmarshals the BlockBody object -func (b *BlockBody) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size < 4 { - return ssz.ErrSize - } - - tail := buf - var o0 uint64 - - // Offset (0) 'Attestations' - if o0 = ssz.ReadOffset(buf[0:4]); o0 > size { - return ssz.ErrOffset - } - - if o0 != 4 { - return ssz.ErrInvalidVariableOffset - } - - // Field (0) 'Attestations' - { - buf = tail[o0:] - num, err := ssz.DecodeDynamicLength(buf, 4096) - if err != nil { - return err - } - b.Attestations = make([]*AggregatedAttestation, num) - err = ssz.UnmarshalDynamic(buf, num, func(indx int, buf []byte) (err error) { - if b.Attestations[indx] == nil { - b.Attestations[indx] = new(AggregatedAttestation) - } - if err = b.Attestations[indx].UnmarshalSSZ(buf); err != nil { - return err - } - return nil - }) - if err != nil { - return err - } - } - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the BlockBody object -func (b *BlockBody) SizeSSZ() (size int) { - size = 4 - - // Field (0) 'Attestations' - for ii := 0; ii < len(b.Attestations); ii++ { - size += 4 - size += b.Attestations[ii].SizeSSZ() - } - - return -} - -// HashTreeRoot ssz hashes the BlockBody object -func (b *BlockBody) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(b) -} - -// HashTreeRootWith ssz hashes the BlockBody object with a hasher -func (b *BlockBody) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Attestations' - { - subIndx := hh.Index() - num := uint64(len(b.Attestations)) - if num > 4096 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.Attestations { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 4096) - } - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the BlockBody object -func (b *BlockBody) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(b) -} - -// MarshalSSZ ssz marshals the Block object -func (b *Block) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(b) -} - -// MarshalSSZTo ssz marshals the Block object to a target array -func (b *Block) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - offset := int(84) - - // Field (0) 'Slot' - dst = ssz.MarshalUint64(dst, b.Slot) - - // Field (1) 'ProposerIndex' - dst = ssz.MarshalUint64(dst, b.ProposerIndex) - - // Field (2) 'ParentRoot' - dst = append(dst, b.ParentRoot[:]...) - - // Field (3) 'StateRoot' - dst = append(dst, b.StateRoot[:]...) - - // Offset (4) 'Body' - dst = ssz.WriteOffset(dst, offset) - - // Field (4) 'Body' - if dst, err = b.Body.MarshalSSZTo(dst); err != nil { - return - } - - return -} - -// UnmarshalSSZ ssz unmarshals the Block object -func (b *Block) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size < 84 { - return ssz.ErrSize - } - - tail := buf - var o4 uint64 - - // Field (0) 'Slot' - b.Slot = ssz.UnmarshallUint64(buf[0:8]) - - // Field (1) 'ProposerIndex' - b.ProposerIndex = ssz.UnmarshallUint64(buf[8:16]) - - // Field (2) 'ParentRoot' - copy(b.ParentRoot[:], buf[16:48]) - - // Field (3) 'StateRoot' - copy(b.StateRoot[:], buf[48:80]) - - // Offset (4) 'Body' - if o4 = ssz.ReadOffset(buf[80:84]); o4 > size { - return ssz.ErrOffset - } - - if o4 != 84 { - return ssz.ErrInvalidVariableOffset - } - - // Field (4) 'Body' - { - buf = tail[o4:] - if b.Body == nil { - b.Body = new(BlockBody) - } - if err = b.Body.UnmarshalSSZ(buf); err != nil { - return err - } - } - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the Block object -func (b *Block) SizeSSZ() (size int) { - size = 84 - - // Field (4) 'Body' - if b.Body == nil { - b.Body = new(BlockBody) - } - size += b.Body.SizeSSZ() - - return -} - -// HashTreeRoot ssz hashes the Block object -func (b *Block) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(b) -} - -// HashTreeRootWith ssz hashes the Block object with a hasher -func (b *Block) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Slot' - hh.PutUint64(b.Slot) - - // Field (1) 'ProposerIndex' - hh.PutUint64(b.ProposerIndex) - - // Field (2) 'ParentRoot' - hh.PutBytes(b.ParentRoot[:]) - - // Field (3) 'StateRoot' - hh.PutBytes(b.StateRoot[:]) - - // Field (4) 'Body' - if err = b.Body.HashTreeRootWith(hh); err != nil { - return - } - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the Block object -func (b *Block) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(b) -} - -// MarshalSSZ ssz marshals the BlockSignatures object -func (b *BlockSignatures) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(b) -} - -// MarshalSSZTo ssz marshals the BlockSignatures object to a target array -func (b *BlockSignatures) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - offset := int(2540) - - // Offset (0) 'AttestationSignatures' - dst = ssz.WriteOffset(dst, offset) - - // Field (1) 'ProposerSignature' - dst = append(dst, b.ProposerSignature[:]...) - - // Field (0) 'AttestationSignatures' - if size := len(b.AttestationSignatures); size > 4096 { - err = ssz.ErrListTooBigFn("BlockSignatures.AttestationSignatures", size, 4096) - return - } - { - offset = 4 * len(b.AttestationSignatures) - for ii := 0; ii < len(b.AttestationSignatures); ii++ { - dst = ssz.WriteOffset(dst, offset) - offset += b.AttestationSignatures[ii].SizeSSZ() - } - } - for ii := 0; ii < len(b.AttestationSignatures); ii++ { - if dst, err = b.AttestationSignatures[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - return -} - -// UnmarshalSSZ ssz unmarshals the BlockSignatures object -func (b *BlockSignatures) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size < 2540 { - return ssz.ErrSize - } - - tail := buf - var o0 uint64 - - // Offset (0) 'AttestationSignatures' - if o0 = ssz.ReadOffset(buf[0:4]); o0 > size { - return ssz.ErrOffset - } - - if o0 != 2540 { - return ssz.ErrInvalidVariableOffset - } - - // Field (1) 'ProposerSignature' - copy(b.ProposerSignature[:], buf[4:2540]) - - // Field (0) 'AttestationSignatures' - { - buf = tail[o0:] - num, err := ssz.DecodeDynamicLength(buf, 4096) - if err != nil { - return err - } - b.AttestationSignatures = make([]*AggregatedSignatureProof, num) - err = ssz.UnmarshalDynamic(buf, num, func(indx int, buf []byte) (err error) { - if b.AttestationSignatures[indx] == nil { - b.AttestationSignatures[indx] = new(AggregatedSignatureProof) - } - if err = b.AttestationSignatures[indx].UnmarshalSSZ(buf); err != nil { - return err - } - return nil - }) - if err != nil { - return err - } - } - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the BlockSignatures object -func (b *BlockSignatures) SizeSSZ() (size int) { - size = 2540 - - // Field (0) 'AttestationSignatures' - for ii := 0; ii < len(b.AttestationSignatures); ii++ { - size += 4 - size += b.AttestationSignatures[ii].SizeSSZ() - } - - return -} - -// HashTreeRoot ssz hashes the BlockSignatures object -func (b *BlockSignatures) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(b) -} - -// HashTreeRootWith ssz hashes the BlockSignatures object with a hasher -func (b *BlockSignatures) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'AttestationSignatures' - { - subIndx := hh.Index() - num := uint64(len(b.AttestationSignatures)) - if num > 4096 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.AttestationSignatures { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 4096) - } - - // Field (1) 'ProposerSignature' - hh.PutBytes(b.ProposerSignature[:]) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the BlockSignatures object -func (b *BlockSignatures) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(b) -} - -// MarshalSSZ ssz marshals the SignedBlock object -func (s *SignedBlock) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(s) -} - -// MarshalSSZTo ssz marshals the SignedBlock object to a target array -func (s *SignedBlock) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - offset := int(8) - - // Offset (0) 'Block' - dst = ssz.WriteOffset(dst, offset) - if s.Block == nil { - s.Block = new(Block) - } - offset += s.Block.SizeSSZ() - - // Offset (1) 'Signature' - dst = ssz.WriteOffset(dst, offset) - - // Field (0) 'Block' - if dst, err = s.Block.MarshalSSZTo(dst); err != nil { - return - } - - // Field (1) 'Signature' - if dst, err = s.Signature.MarshalSSZTo(dst); err != nil { - return - } - - return -} - -// UnmarshalSSZ ssz unmarshals the SignedBlock object -func (s *SignedBlock) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size < 8 { - return ssz.ErrSize - } - - tail := buf - var o0, o1 uint64 - - // Offset (0) 'Block' - if o0 = ssz.ReadOffset(buf[0:4]); o0 > size { - return ssz.ErrOffset - } - - if o0 != 8 { - return ssz.ErrInvalidVariableOffset - } - - // Offset (1) 'Signature' - if o1 = ssz.ReadOffset(buf[4:8]); o1 > size || o0 > o1 { - return ssz.ErrOffset - } - - // Field (0) 'Block' - { - buf = tail[o0:o1] - if s.Block == nil { - s.Block = new(Block) - } - if err = s.Block.UnmarshalSSZ(buf); err != nil { - return err - } - } - - // Field (1) 'Signature' - { - buf = tail[o1:] - if s.Signature == nil { - s.Signature = new(BlockSignatures) - } - if err = s.Signature.UnmarshalSSZ(buf); err != nil { - return err - } - } - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the SignedBlock object -func (s *SignedBlock) SizeSSZ() (size int) { - size = 8 - - // Field (0) 'Block' - if s.Block == nil { - s.Block = new(Block) - } - size += s.Block.SizeSSZ() - - // Field (1) 'Signature' - if s.Signature == nil { - s.Signature = new(BlockSignatures) - } - size += s.Signature.SizeSSZ() - - return -} - -// HashTreeRoot ssz hashes the SignedBlock object -func (s *SignedBlock) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(s) -} - -// HashTreeRootWith ssz hashes the SignedBlock object with a hasher -func (s *SignedBlock) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Block' - if err = s.Block.HashTreeRootWith(hh); err != nil { - return - } - - // Field (1) 'Signature' - if err = s.Signature.HashTreeRootWith(hh); err != nil { - return - } - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the SignedBlock object -func (s *SignedBlock) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(s) -} diff --git a/types/blocks_by_range_encoding.go b/types/blocks_by_range_encoding.go deleted file mode 100644 index 9825c3f6..00000000 --- a/types/blocks_by_range_encoding.go +++ /dev/null @@ -1,73 +0,0 @@ -// Code generated by fastssz. DO NOT EDIT. -// Hash: c54bd1c3d5920d66b8eeda25c1a65e2554897d50b1f9115abb415234952004c0 -// Version: 0.1.3 -package types - -import ( - ssz "github.com/ferranbt/fastssz" -) - -// MarshalSSZ ssz marshals the BlocksByRangeRequest object -func (b *BlocksByRangeRequest) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(b) -} - -// MarshalSSZTo ssz marshals the BlocksByRangeRequest object to a target array -func (b *BlocksByRangeRequest) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'StartSlot' - dst = ssz.MarshalUint64(dst, b.StartSlot) - - // Field (1) 'Count' - dst = ssz.MarshalUint64(dst, b.Count) - - return -} - -// UnmarshalSSZ ssz unmarshals the BlocksByRangeRequest object -func (b *BlocksByRangeRequest) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 16 { - return ssz.ErrSize - } - - // Field (0) 'StartSlot' - b.StartSlot = ssz.UnmarshallUint64(buf[0:8]) - - // Field (1) 'Count' - b.Count = ssz.UnmarshallUint64(buf[8:16]) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the BlocksByRangeRequest object -func (b *BlocksByRangeRequest) SizeSSZ() (size int) { - size = 16 - return -} - -// HashTreeRoot ssz hashes the BlocksByRangeRequest object -func (b *BlocksByRangeRequest) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(b) -} - -// HashTreeRootWith ssz hashes the BlocksByRangeRequest object with a hasher -func (b *BlocksByRangeRequest) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'StartSlot' - hh.PutUint64(b.StartSlot) - - // Field (1) 'Count' - hh.PutUint64(b.Count) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the BlocksByRangeRequest object -func (b *BlocksByRangeRequest) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(b) -} diff --git a/types/checkpoint_encoding.go b/types/checkpoint_encoding.go deleted file mode 100644 index 802ff5e1..00000000 --- a/types/checkpoint_encoding.go +++ /dev/null @@ -1,73 +0,0 @@ -// Code generated by fastssz. DO NOT EDIT. -// Hash: 52b67ea3b7cb79482579d5c3ff659d3473b41bec2511e9c0fd826505bb9f9f72 -// Version: 0.1.3 -package types - -import ( - ssz "github.com/ferranbt/fastssz" -) - -// MarshalSSZ ssz marshals the Checkpoint object -func (c *Checkpoint) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(c) -} - -// MarshalSSZTo ssz marshals the Checkpoint object to a target array -func (c *Checkpoint) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'Root' - dst = append(dst, c.Root[:]...) - - // Field (1) 'Slot' - dst = ssz.MarshalUint64(dst, c.Slot) - - return -} - -// UnmarshalSSZ ssz unmarshals the Checkpoint object -func (c *Checkpoint) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 40 { - return ssz.ErrSize - } - - // Field (0) 'Root' - copy(c.Root[:], buf[0:32]) - - // Field (1) 'Slot' - c.Slot = ssz.UnmarshallUint64(buf[32:40]) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the Checkpoint object -func (c *Checkpoint) SizeSSZ() (size int) { - size = 40 - return -} - -// HashTreeRoot ssz hashes the Checkpoint object -func (c *Checkpoint) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(c) -} - -// HashTreeRootWith ssz hashes the Checkpoint object with a hasher -func (c *Checkpoint) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Root' - hh.PutBytes(c.Root[:]) - - // Field (1) 'Slot' - hh.PutUint64(c.Slot) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the Checkpoint object -func (c *Checkpoint) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(c) -} diff --git a/types/config_encoding.go b/types/config_encoding.go deleted file mode 100644 index 15dfa0de..00000000 --- a/types/config_encoding.go +++ /dev/null @@ -1,64 +0,0 @@ -// Code generated by fastssz. DO NOT EDIT. -// Hash: 52b67ea3b7cb79482579d5c3ff659d3473b41bec2511e9c0fd826505bb9f9f72 -// Version: 0.1.3 -package types - -import ( - ssz "github.com/ferranbt/fastssz" -) - -// MarshalSSZ ssz marshals the ChainConfig object -func (c *ChainConfig) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(c) -} - -// MarshalSSZTo ssz marshals the ChainConfig object to a target array -func (c *ChainConfig) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'GenesisTime' - dst = ssz.MarshalUint64(dst, c.GenesisTime) - - return -} - -// UnmarshalSSZ ssz unmarshals the ChainConfig object -func (c *ChainConfig) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 8 { - return ssz.ErrSize - } - - // Field (0) 'GenesisTime' - c.GenesisTime = ssz.UnmarshallUint64(buf[0:8]) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the ChainConfig object -func (c *ChainConfig) SizeSSZ() (size int) { - size = 8 - return -} - -// HashTreeRoot ssz hashes the ChainConfig object -func (c *ChainConfig) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(c) -} - -// HashTreeRootWith ssz hashes the ChainConfig object with a hasher -func (c *ChainConfig) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'GenesisTime' - hh.PutUint64(c.GenesisTime) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the ChainConfig object -func (c *ChainConfig) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(c) -} diff --git a/types/encoding_gen.go b/types/encoding_gen.go new file mode 100644 index 00000000..4bac67e8 --- /dev/null +++ b/types/encoding_gen.go @@ -0,0 +1,1946 @@ +// Code generated by fastssz. DO NOT EDIT. +// Hash: b60ca7a3fc63a099494c4e77b86c5327b9f84725eff50f9f1c817f521f630326 +// Version: 0.1.3 +package types + +import ( + ssz "github.com/ferranbt/fastssz" +) + +// MarshalSSZ ssz marshals the AttestationData object +func (a *AttestationData) MarshalSSZ() ([]byte, error) { + return ssz.MarshalSSZ(a) +} + +// MarshalSSZTo ssz marshals the AttestationData object to a target array +func (a *AttestationData) MarshalSSZTo(buf []byte) (dst []byte, err error) { + dst = buf + + // Field (0) 'Slot' + dst = ssz.MarshalUint64(dst, a.Slot) + + // Field (1) 'Head' + if a.Head == nil { + a.Head = new(Checkpoint) + } + if dst, err = a.Head.MarshalSSZTo(dst); err != nil { + return + } + + // Field (2) 'Target' + if a.Target == nil { + a.Target = new(Checkpoint) + } + if dst, err = a.Target.MarshalSSZTo(dst); err != nil { + return + } + + // Field (3) 'Source' + if a.Source == nil { + a.Source = new(Checkpoint) + } + if dst, err = a.Source.MarshalSSZTo(dst); err != nil { + return + } + + return +} + +// UnmarshalSSZ ssz unmarshals the AttestationData object +func (a *AttestationData) UnmarshalSSZ(buf []byte) error { + var err error + size := uint64(len(buf)) + if size != 128 { + return ssz.ErrSize + } + + // Field (0) 'Slot' + a.Slot = ssz.UnmarshallUint64(buf[0:8]) + + // Field (1) 'Head' + if a.Head == nil { + a.Head = new(Checkpoint) + } + if err = a.Head.UnmarshalSSZ(buf[8:48]); err != nil { + return err + } + + // Field (2) 'Target' + if a.Target == nil { + a.Target = new(Checkpoint) + } + if err = a.Target.UnmarshalSSZ(buf[48:88]); err != nil { + return err + } + + // Field (3) 'Source' + if a.Source == nil { + a.Source = new(Checkpoint) + } + if err = a.Source.UnmarshalSSZ(buf[88:128]); err != nil { + return err + } + + return err +} + +// SizeSSZ returns the ssz encoded size in bytes for the AttestationData object +func (a *AttestationData) SizeSSZ() (size int) { + size = 128 + return +} + +// HashTreeRoot ssz hashes the AttestationData object +func (a *AttestationData) HashTreeRoot() ([32]byte, error) { + return ssz.HashWithDefaultHasher(a) +} + +// HashTreeRootWith ssz hashes the AttestationData object with a hasher +func (a *AttestationData) HashTreeRootWith(hh ssz.HashWalker) (err error) { + indx := hh.Index() + + // Field (0) 'Slot' + hh.PutUint64(a.Slot) + + // Field (1) 'Head' + if a.Head == nil { + a.Head = new(Checkpoint) + } + if err = a.Head.HashTreeRootWith(hh); err != nil { + return + } + + // Field (2) 'Target' + if a.Target == nil { + a.Target = new(Checkpoint) + } + if err = a.Target.HashTreeRootWith(hh); err != nil { + return + } + + // Field (3) 'Source' + if a.Source == nil { + a.Source = new(Checkpoint) + } + if err = a.Source.HashTreeRootWith(hh); err != nil { + return + } + + hh.Merkleize(indx) + return +} + +// GetTree ssz hashes the AttestationData object +func (a *AttestationData) GetTree() (*ssz.Node, error) { + return ssz.ProofTree(a) +} + +// MarshalSSZ ssz marshals the Attestation object +func (a *Attestation) MarshalSSZ() ([]byte, error) { + return ssz.MarshalSSZ(a) +} + +// MarshalSSZTo ssz marshals the Attestation object to a target array +func (a *Attestation) MarshalSSZTo(buf []byte) (dst []byte, err error) { + dst = buf + + // Field (0) 'ValidatorID' + dst = ssz.MarshalUint64(dst, a.ValidatorID) + + // Field (1) 'Data' + if a.Data == nil { + a.Data = new(AttestationData) + } + if dst, err = a.Data.MarshalSSZTo(dst); err != nil { + return + } + + return +} + +// UnmarshalSSZ ssz unmarshals the Attestation object +func (a *Attestation) UnmarshalSSZ(buf []byte) error { + var err error + size := uint64(len(buf)) + if size != 136 { + return ssz.ErrSize + } + + // Field (0) 'ValidatorID' + a.ValidatorID = ssz.UnmarshallUint64(buf[0:8]) + + // Field (1) 'Data' + if a.Data == nil { + a.Data = new(AttestationData) + } + if err = a.Data.UnmarshalSSZ(buf[8:136]); err != nil { + return err + } + + return err +} + +// SizeSSZ returns the ssz encoded size in bytes for the Attestation object +func (a *Attestation) SizeSSZ() (size int) { + size = 136 + return +} + +// HashTreeRoot ssz hashes the Attestation object +func (a *Attestation) HashTreeRoot() ([32]byte, error) { + return ssz.HashWithDefaultHasher(a) +} + +// HashTreeRootWith ssz hashes the Attestation object with a hasher +func (a *Attestation) HashTreeRootWith(hh ssz.HashWalker) (err error) { + indx := hh.Index() + + // Field (0) 'ValidatorID' + hh.PutUint64(a.ValidatorID) + + // Field (1) 'Data' + if a.Data == nil { + a.Data = new(AttestationData) + } + if err = a.Data.HashTreeRootWith(hh); err != nil { + return + } + + hh.Merkleize(indx) + return +} + +// GetTree ssz hashes the Attestation object +func (a *Attestation) GetTree() (*ssz.Node, error) { + return ssz.ProofTree(a) +} + +// MarshalSSZ ssz marshals the SignedAttestation object +func (s *SignedAttestation) MarshalSSZ() ([]byte, error) { + return ssz.MarshalSSZ(s) +} + +// MarshalSSZTo ssz marshals the SignedAttestation object to a target array +func (s *SignedAttestation) MarshalSSZTo(buf []byte) (dst []byte, err error) { + dst = buf + + // Field (0) 'ValidatorID' + dst = ssz.MarshalUint64(dst, s.ValidatorID) + + // Field (1) 'Data' + if s.Data == nil { + s.Data = new(AttestationData) + } + if dst, err = s.Data.MarshalSSZTo(dst); err != nil { + return + } + + // Field (2) 'Signature' + dst = append(dst, s.Signature[:]...) + + return +} + +// UnmarshalSSZ ssz unmarshals the SignedAttestation object +func (s *SignedAttestation) UnmarshalSSZ(buf []byte) error { + var err error + size := uint64(len(buf)) + if size != 2672 { + return ssz.ErrSize + } + + // Field (0) 'ValidatorID' + s.ValidatorID = ssz.UnmarshallUint64(buf[0:8]) + + // Field (1) 'Data' + if s.Data == nil { + s.Data = new(AttestationData) + } + if err = s.Data.UnmarshalSSZ(buf[8:136]); err != nil { + return err + } + + // Field (2) 'Signature' + copy(s.Signature[:], buf[136:2672]) + + return err +} + +// SizeSSZ returns the ssz encoded size in bytes for the SignedAttestation object +func (s *SignedAttestation) SizeSSZ() (size int) { + size = 2672 + return +} + +// HashTreeRoot ssz hashes the SignedAttestation object +func (s *SignedAttestation) HashTreeRoot() ([32]byte, error) { + return ssz.HashWithDefaultHasher(s) +} + +// HashTreeRootWith ssz hashes the SignedAttestation object with a hasher +func (s *SignedAttestation) HashTreeRootWith(hh ssz.HashWalker) (err error) { + indx := hh.Index() + + // Field (0) 'ValidatorID' + hh.PutUint64(s.ValidatorID) + + // Field (1) 'Data' + if s.Data == nil { + s.Data = new(AttestationData) + } + if err = s.Data.HashTreeRootWith(hh); err != nil { + return + } + + // Field (2) 'Signature' + hh.PutBytes(s.Signature[:]) + + hh.Merkleize(indx) + return +} + +// GetTree ssz hashes the SignedAttestation object +func (s *SignedAttestation) GetTree() (*ssz.Node, error) { + return ssz.ProofTree(s) +} + +// MarshalSSZ ssz marshals the AggregatedAttestation object +func (a *AggregatedAttestation) MarshalSSZ() ([]byte, error) { + return ssz.MarshalSSZ(a) +} + +// MarshalSSZTo ssz marshals the AggregatedAttestation object to a target array +func (a *AggregatedAttestation) MarshalSSZTo(buf []byte) (dst []byte, err error) { + dst = buf + offset := int(132) + + // Offset (0) 'AggregationBits' + dst = ssz.WriteOffset(dst, offset) + + // Field (1) 'Data' + if a.Data == nil { + a.Data = new(AttestationData) + } + if dst, err = a.Data.MarshalSSZTo(dst); err != nil { + return + } + + // Field (0) 'AggregationBits' + if size := len(a.AggregationBits); size > 4096 { + err = ssz.ErrBytesLengthFn("AggregatedAttestation.AggregationBits", size, 4096) + return + } + dst = append(dst, a.AggregationBits...) + + return +} + +// UnmarshalSSZ ssz unmarshals the AggregatedAttestation object +func (a *AggregatedAttestation) UnmarshalSSZ(buf []byte) error { + var err error + size := uint64(len(buf)) + if size < 132 { + return ssz.ErrSize + } + + tail := buf + var o0 uint64 + + // Offset (0) 'AggregationBits' + if o0 = ssz.ReadOffset(buf[0:4]); o0 > size { + return ssz.ErrOffset + } + + if o0 != 132 { + return ssz.ErrInvalidVariableOffset + } + + // Field (1) 'Data' + if a.Data == nil { + a.Data = new(AttestationData) + } + if err = a.Data.UnmarshalSSZ(buf[4:132]); err != nil { + return err + } + + // Field (0) 'AggregationBits' + { + buf = tail[o0:] + if err = ssz.ValidateBitlist(buf, 4096); err != nil { + return err + } + if cap(a.AggregationBits) == 0 { + a.AggregationBits = make([]byte, 0, len(buf)) + } + a.AggregationBits = append(a.AggregationBits, buf...) + } + return err +} + +// SizeSSZ returns the ssz encoded size in bytes for the AggregatedAttestation object +func (a *AggregatedAttestation) SizeSSZ() (size int) { + size = 132 + + // Field (0) 'AggregationBits' + size += len(a.AggregationBits) + + return +} + +// HashTreeRoot ssz hashes the AggregatedAttestation object +func (a *AggregatedAttestation) HashTreeRoot() ([32]byte, error) { + return ssz.HashWithDefaultHasher(a) +} + +// HashTreeRootWith ssz hashes the AggregatedAttestation object with a hasher +func (a *AggregatedAttestation) HashTreeRootWith(hh ssz.HashWalker) (err error) { + indx := hh.Index() + + // Field (0) 'AggregationBits' + if len(a.AggregationBits) == 0 { + err = ssz.ErrEmptyBitlist + return + } + hh.PutBitlist(a.AggregationBits, 4096) + + // Field (1) 'Data' + if a.Data == nil { + a.Data = new(AttestationData) + } + if err = a.Data.HashTreeRootWith(hh); err != nil { + return + } + + hh.Merkleize(indx) + return +} + +// GetTree ssz hashes the AggregatedAttestation object +func (a *AggregatedAttestation) GetTree() (*ssz.Node, error) { + return ssz.ProofTree(a) +} + +// MarshalSSZ ssz marshals the SignedAggregatedAttestation object +func (s *SignedAggregatedAttestation) MarshalSSZ() ([]byte, error) { + return ssz.MarshalSSZ(s) +} + +// MarshalSSZTo ssz marshals the SignedAggregatedAttestation object to a target array +func (s *SignedAggregatedAttestation) MarshalSSZTo(buf []byte) (dst []byte, err error) { + dst = buf + offset := int(132) + + // Field (0) 'Data' + if s.Data == nil { + s.Data = new(AttestationData) + } + if dst, err = s.Data.MarshalSSZTo(dst); err != nil { + return + } + + // Offset (1) 'Proof' + dst = ssz.WriteOffset(dst, offset) + + // Field (1) 'Proof' + if dst, err = s.Proof.MarshalSSZTo(dst); err != nil { + return + } + + return +} + +// UnmarshalSSZ ssz unmarshals the SignedAggregatedAttestation object +func (s *SignedAggregatedAttestation) UnmarshalSSZ(buf []byte) error { + var err error + size := uint64(len(buf)) + if size < 132 { + return ssz.ErrSize + } + + tail := buf + var o1 uint64 + + // Field (0) 'Data' + if s.Data == nil { + s.Data = new(AttestationData) + } + if err = s.Data.UnmarshalSSZ(buf[0:128]); err != nil { + return err + } + + // Offset (1) 'Proof' + if o1 = ssz.ReadOffset(buf[128:132]); o1 > size { + return ssz.ErrOffset + } + + if o1 != 132 { + return ssz.ErrInvalidVariableOffset + } + + // Field (1) 'Proof' + { + buf = tail[o1:] + if s.Proof == nil { + s.Proof = new(AggregatedSignatureProof) + } + if err = s.Proof.UnmarshalSSZ(buf); err != nil { + return err + } + } + return err +} + +// SizeSSZ returns the ssz encoded size in bytes for the SignedAggregatedAttestation object +func (s *SignedAggregatedAttestation) SizeSSZ() (size int) { + size = 132 + + // Field (1) 'Proof' + if s.Proof == nil { + s.Proof = new(AggregatedSignatureProof) + } + size += s.Proof.SizeSSZ() + + return +} + +// HashTreeRoot ssz hashes the SignedAggregatedAttestation object +func (s *SignedAggregatedAttestation) HashTreeRoot() ([32]byte, error) { + return ssz.HashWithDefaultHasher(s) +} + +// HashTreeRootWith ssz hashes the SignedAggregatedAttestation object with a hasher +func (s *SignedAggregatedAttestation) HashTreeRootWith(hh ssz.HashWalker) (err error) { + indx := hh.Index() + + // Field (0) 'Data' + if s.Data == nil { + s.Data = new(AttestationData) + } + if err = s.Data.HashTreeRootWith(hh); err != nil { + return + } + + // Field (1) 'Proof' + if err = s.Proof.HashTreeRootWith(hh); err != nil { + return + } + + hh.Merkleize(indx) + return +} + +// GetTree ssz hashes the SignedAggregatedAttestation object +func (s *SignedAggregatedAttestation) GetTree() (*ssz.Node, error) { + return ssz.ProofTree(s) +} + +// MarshalSSZ ssz marshals the BlockHeader object +func (b *BlockHeader) MarshalSSZ() ([]byte, error) { + return ssz.MarshalSSZ(b) +} + +// MarshalSSZTo ssz marshals the BlockHeader object to a target array +func (b *BlockHeader) MarshalSSZTo(buf []byte) (dst []byte, err error) { + dst = buf + + // Field (0) 'Slot' + dst = ssz.MarshalUint64(dst, b.Slot) + + // Field (1) 'ProposerIndex' + dst = ssz.MarshalUint64(dst, b.ProposerIndex) + + // Field (2) 'ParentRoot' + dst = append(dst, b.ParentRoot[:]...) + + // Field (3) 'StateRoot' + dst = append(dst, b.StateRoot[:]...) + + // Field (4) 'BodyRoot' + dst = append(dst, b.BodyRoot[:]...) + + return +} + +// UnmarshalSSZ ssz unmarshals the BlockHeader object +func (b *BlockHeader) UnmarshalSSZ(buf []byte) error { + var err error + size := uint64(len(buf)) + if size != 112 { + return ssz.ErrSize + } + + // Field (0) 'Slot' + b.Slot = ssz.UnmarshallUint64(buf[0:8]) + + // Field (1) 'ProposerIndex' + b.ProposerIndex = ssz.UnmarshallUint64(buf[8:16]) + + // Field (2) 'ParentRoot' + copy(b.ParentRoot[:], buf[16:48]) + + // Field (3) 'StateRoot' + copy(b.StateRoot[:], buf[48:80]) + + // Field (4) 'BodyRoot' + copy(b.BodyRoot[:], buf[80:112]) + + return err +} + +// SizeSSZ returns the ssz encoded size in bytes for the BlockHeader object +func (b *BlockHeader) SizeSSZ() (size int) { + size = 112 + return +} + +// HashTreeRoot ssz hashes the BlockHeader object +func (b *BlockHeader) HashTreeRoot() ([32]byte, error) { + return ssz.HashWithDefaultHasher(b) +} + +// HashTreeRootWith ssz hashes the BlockHeader object with a hasher +func (b *BlockHeader) HashTreeRootWith(hh ssz.HashWalker) (err error) { + indx := hh.Index() + + // Field (0) 'Slot' + hh.PutUint64(b.Slot) + + // Field (1) 'ProposerIndex' + hh.PutUint64(b.ProposerIndex) + + // Field (2) 'ParentRoot' + hh.PutBytes(b.ParentRoot[:]) + + // Field (3) 'StateRoot' + hh.PutBytes(b.StateRoot[:]) + + // Field (4) 'BodyRoot' + hh.PutBytes(b.BodyRoot[:]) + + hh.Merkleize(indx) + return +} + +// GetTree ssz hashes the BlockHeader object +func (b *BlockHeader) GetTree() (*ssz.Node, error) { + return ssz.ProofTree(b) +} + +// MarshalSSZ ssz marshals the BlockBody object +func (b *BlockBody) MarshalSSZ() ([]byte, error) { + return ssz.MarshalSSZ(b) +} + +// MarshalSSZTo ssz marshals the BlockBody object to a target array +func (b *BlockBody) MarshalSSZTo(buf []byte) (dst []byte, err error) { + dst = buf + offset := int(4) + + // Offset (0) 'Attestations' + dst = ssz.WriteOffset(dst, offset) + + // Field (0) 'Attestations' + if size := len(b.Attestations); size > 4096 { + err = ssz.ErrListTooBigFn("BlockBody.Attestations", size, 4096) + return + } + { + offset = 4 * len(b.Attestations) + for ii := 0; ii < len(b.Attestations); ii++ { + dst = ssz.WriteOffset(dst, offset) + offset += b.Attestations[ii].SizeSSZ() + } + } + for ii := 0; ii < len(b.Attestations); ii++ { + if dst, err = b.Attestations[ii].MarshalSSZTo(dst); err != nil { + return + } + } + + return +} + +// UnmarshalSSZ ssz unmarshals the BlockBody object +func (b *BlockBody) UnmarshalSSZ(buf []byte) error { + var err error + size := uint64(len(buf)) + if size < 4 { + return ssz.ErrSize + } + + tail := buf + var o0 uint64 + + // Offset (0) 'Attestations' + if o0 = ssz.ReadOffset(buf[0:4]); o0 > size { + return ssz.ErrOffset + } + + if o0 != 4 { + return ssz.ErrInvalidVariableOffset + } + + // Field (0) 'Attestations' + { + buf = tail[o0:] + num, err := ssz.DecodeDynamicLength(buf, 4096) + if err != nil { + return err + } + b.Attestations = make([]*AggregatedAttestation, num) + err = ssz.UnmarshalDynamic(buf, num, func(indx int, buf []byte) (err error) { + if b.Attestations[indx] == nil { + b.Attestations[indx] = new(AggregatedAttestation) + } + if err = b.Attestations[indx].UnmarshalSSZ(buf); err != nil { + return err + } + return nil + }) + if err != nil { + return err + } + } + return err +} + +// SizeSSZ returns the ssz encoded size in bytes for the BlockBody object +func (b *BlockBody) SizeSSZ() (size int) { + size = 4 + + // Field (0) 'Attestations' + for ii := 0; ii < len(b.Attestations); ii++ { + size += 4 + size += b.Attestations[ii].SizeSSZ() + } + + return +} + +// HashTreeRoot ssz hashes the BlockBody object +func (b *BlockBody) HashTreeRoot() ([32]byte, error) { + return ssz.HashWithDefaultHasher(b) +} + +// HashTreeRootWith ssz hashes the BlockBody object with a hasher +func (b *BlockBody) HashTreeRootWith(hh ssz.HashWalker) (err error) { + indx := hh.Index() + + // Field (0) 'Attestations' + { + subIndx := hh.Index() + num := uint64(len(b.Attestations)) + if num > 4096 { + err = ssz.ErrIncorrectListSize + return + } + for _, elem := range b.Attestations { + if err = elem.HashTreeRootWith(hh); err != nil { + return + } + } + hh.MerkleizeWithMixin(subIndx, num, 4096) + } + + hh.Merkleize(indx) + return +} + +// GetTree ssz hashes the BlockBody object +func (b *BlockBody) GetTree() (*ssz.Node, error) { + return ssz.ProofTree(b) +} + +// MarshalSSZ ssz marshals the Block object +func (b *Block) MarshalSSZ() ([]byte, error) { + return ssz.MarshalSSZ(b) +} + +// MarshalSSZTo ssz marshals the Block object to a target array +func (b *Block) MarshalSSZTo(buf []byte) (dst []byte, err error) { + dst = buf + offset := int(84) + + // Field (0) 'Slot' + dst = ssz.MarshalUint64(dst, b.Slot) + + // Field (1) 'ProposerIndex' + dst = ssz.MarshalUint64(dst, b.ProposerIndex) + + // Field (2) 'ParentRoot' + dst = append(dst, b.ParentRoot[:]...) + + // Field (3) 'StateRoot' + dst = append(dst, b.StateRoot[:]...) + + // Offset (4) 'Body' + dst = ssz.WriteOffset(dst, offset) + + // Field (4) 'Body' + if dst, err = b.Body.MarshalSSZTo(dst); err != nil { + return + } + + return +} + +// UnmarshalSSZ ssz unmarshals the Block object +func (b *Block) UnmarshalSSZ(buf []byte) error { + var err error + size := uint64(len(buf)) + if size < 84 { + return ssz.ErrSize + } + + tail := buf + var o4 uint64 + + // Field (0) 'Slot' + b.Slot = ssz.UnmarshallUint64(buf[0:8]) + + // Field (1) 'ProposerIndex' + b.ProposerIndex = ssz.UnmarshallUint64(buf[8:16]) + + // Field (2) 'ParentRoot' + copy(b.ParentRoot[:], buf[16:48]) + + // Field (3) 'StateRoot' + copy(b.StateRoot[:], buf[48:80]) + + // Offset (4) 'Body' + if o4 = ssz.ReadOffset(buf[80:84]); o4 > size { + return ssz.ErrOffset + } + + if o4 != 84 { + return ssz.ErrInvalidVariableOffset + } + + // Field (4) 'Body' + { + buf = tail[o4:] + if b.Body == nil { + b.Body = new(BlockBody) + } + if err = b.Body.UnmarshalSSZ(buf); err != nil { + return err + } + } + return err +} + +// SizeSSZ returns the ssz encoded size in bytes for the Block object +func (b *Block) SizeSSZ() (size int) { + size = 84 + + // Field (4) 'Body' + if b.Body == nil { + b.Body = new(BlockBody) + } + size += b.Body.SizeSSZ() + + return +} + +// HashTreeRoot ssz hashes the Block object +func (b *Block) HashTreeRoot() ([32]byte, error) { + return ssz.HashWithDefaultHasher(b) +} + +// HashTreeRootWith ssz hashes the Block object with a hasher +func (b *Block) HashTreeRootWith(hh ssz.HashWalker) (err error) { + indx := hh.Index() + + // Field (0) 'Slot' + hh.PutUint64(b.Slot) + + // Field (1) 'ProposerIndex' + hh.PutUint64(b.ProposerIndex) + + // Field (2) 'ParentRoot' + hh.PutBytes(b.ParentRoot[:]) + + // Field (3) 'StateRoot' + hh.PutBytes(b.StateRoot[:]) + + // Field (4) 'Body' + if err = b.Body.HashTreeRootWith(hh); err != nil { + return + } + + hh.Merkleize(indx) + return +} + +// GetTree ssz hashes the Block object +func (b *Block) GetTree() (*ssz.Node, error) { + return ssz.ProofTree(b) +} + +// MarshalSSZ ssz marshals the AggregatedSignatureProof object +func (a *AggregatedSignatureProof) MarshalSSZ() ([]byte, error) { + return ssz.MarshalSSZ(a) +} + +// MarshalSSZTo ssz marshals the AggregatedSignatureProof object to a target array +func (a *AggregatedSignatureProof) MarshalSSZTo(buf []byte) (dst []byte, err error) { + dst = buf + offset := int(8) + + // Offset (0) 'Participants' + dst = ssz.WriteOffset(dst, offset) + offset += len(a.Participants) + + // Offset (1) 'ProofData' + dst = ssz.WriteOffset(dst, offset) + + // Field (0) 'Participants' + if size := len(a.Participants); size > 4096 { + err = ssz.ErrBytesLengthFn("AggregatedSignatureProof.Participants", size, 4096) + return + } + dst = append(dst, a.Participants...) + + // Field (1) 'ProofData' + if size := len(a.ProofData); size > 1048576 { + err = ssz.ErrBytesLengthFn("AggregatedSignatureProof.ProofData", size, 1048576) + return + } + dst = append(dst, a.ProofData...) + + return +} + +// UnmarshalSSZ ssz unmarshals the AggregatedSignatureProof object +func (a *AggregatedSignatureProof) UnmarshalSSZ(buf []byte) error { + var err error + size := uint64(len(buf)) + if size < 8 { + return ssz.ErrSize + } + + tail := buf + var o0, o1 uint64 + + // Offset (0) 'Participants' + if o0 = ssz.ReadOffset(buf[0:4]); o0 > size { + return ssz.ErrOffset + } + + if o0 != 8 { + return ssz.ErrInvalidVariableOffset + } + + // Offset (1) 'ProofData' + if o1 = ssz.ReadOffset(buf[4:8]); o1 > size || o0 > o1 { + return ssz.ErrOffset + } + + // Field (0) 'Participants' + { + buf = tail[o0:o1] + if err = ssz.ValidateBitlist(buf, 4096); err != nil { + return err + } + if cap(a.Participants) == 0 { + a.Participants = make([]byte, 0, len(buf)) + } + a.Participants = append(a.Participants, buf...) + } + + // Field (1) 'ProofData' + { + buf = tail[o1:] + if len(buf) > 1048576 { + return ssz.ErrBytesLength + } + if cap(a.ProofData) == 0 { + a.ProofData = make([]byte, 0, len(buf)) + } + a.ProofData = append(a.ProofData, buf...) + } + return err +} + +// SizeSSZ returns the ssz encoded size in bytes for the AggregatedSignatureProof object +func (a *AggregatedSignatureProof) SizeSSZ() (size int) { + size = 8 + + // Field (0) 'Participants' + size += len(a.Participants) + + // Field (1) 'ProofData' + size += len(a.ProofData) + + return +} + +// HashTreeRoot ssz hashes the AggregatedSignatureProof object +func (a *AggregatedSignatureProof) HashTreeRoot() ([32]byte, error) { + return ssz.HashWithDefaultHasher(a) +} + +// HashTreeRootWith ssz hashes the AggregatedSignatureProof object with a hasher +func (a *AggregatedSignatureProof) HashTreeRootWith(hh ssz.HashWalker) (err error) { + indx := hh.Index() + + // Field (0) 'Participants' + if len(a.Participants) == 0 { + err = ssz.ErrEmptyBitlist + return + } + hh.PutBitlist(a.Participants, 4096) + + // Field (1) 'ProofData' + { + elemIndx := hh.Index() + byteLen := uint64(len(a.ProofData)) + if byteLen > 1048576 { + err = ssz.ErrIncorrectListSize + return + } + hh.Append(a.ProofData) + hh.MerkleizeWithMixin(elemIndx, byteLen, (1048576+31)/32) + } + + hh.Merkleize(indx) + return +} + +// GetTree ssz hashes the AggregatedSignatureProof object +func (a *AggregatedSignatureProof) GetTree() (*ssz.Node, error) { + return ssz.ProofTree(a) +} + +// MarshalSSZ ssz marshals the BlockSignatures object +func (b *BlockSignatures) MarshalSSZ() ([]byte, error) { + return ssz.MarshalSSZ(b) +} + +// MarshalSSZTo ssz marshals the BlockSignatures object to a target array +func (b *BlockSignatures) MarshalSSZTo(buf []byte) (dst []byte, err error) { + dst = buf + offset := int(2540) + + // Offset (0) 'AttestationSignatures' + dst = ssz.WriteOffset(dst, offset) + + // Field (1) 'ProposerSignature' + dst = append(dst, b.ProposerSignature[:]...) + + // Field (0) 'AttestationSignatures' + if size := len(b.AttestationSignatures); size > 4096 { + err = ssz.ErrListTooBigFn("BlockSignatures.AttestationSignatures", size, 4096) + return + } + { + offset = 4 * len(b.AttestationSignatures) + for ii := 0; ii < len(b.AttestationSignatures); ii++ { + dst = ssz.WriteOffset(dst, offset) + offset += b.AttestationSignatures[ii].SizeSSZ() + } + } + for ii := 0; ii < len(b.AttestationSignatures); ii++ { + if dst, err = b.AttestationSignatures[ii].MarshalSSZTo(dst); err != nil { + return + } + } + + return +} + +// UnmarshalSSZ ssz unmarshals the BlockSignatures object +func (b *BlockSignatures) UnmarshalSSZ(buf []byte) error { + var err error + size := uint64(len(buf)) + if size < 2540 { + return ssz.ErrSize + } + + tail := buf + var o0 uint64 + + // Offset (0) 'AttestationSignatures' + if o0 = ssz.ReadOffset(buf[0:4]); o0 > size { + return ssz.ErrOffset + } + + if o0 != 2540 { + return ssz.ErrInvalidVariableOffset + } + + // Field (1) 'ProposerSignature' + copy(b.ProposerSignature[:], buf[4:2540]) + + // Field (0) 'AttestationSignatures' + { + buf = tail[o0:] + num, err := ssz.DecodeDynamicLength(buf, 4096) + if err != nil { + return err + } + b.AttestationSignatures = make([]*AggregatedSignatureProof, num) + err = ssz.UnmarshalDynamic(buf, num, func(indx int, buf []byte) (err error) { + if b.AttestationSignatures[indx] == nil { + b.AttestationSignatures[indx] = new(AggregatedSignatureProof) + } + if err = b.AttestationSignatures[indx].UnmarshalSSZ(buf); err != nil { + return err + } + return nil + }) + if err != nil { + return err + } + } + return err +} + +// SizeSSZ returns the ssz encoded size in bytes for the BlockSignatures object +func (b *BlockSignatures) SizeSSZ() (size int) { + size = 2540 + + // Field (0) 'AttestationSignatures' + for ii := 0; ii < len(b.AttestationSignatures); ii++ { + size += 4 + size += b.AttestationSignatures[ii].SizeSSZ() + } + + return +} + +// HashTreeRoot ssz hashes the BlockSignatures object +func (b *BlockSignatures) HashTreeRoot() ([32]byte, error) { + return ssz.HashWithDefaultHasher(b) +} + +// HashTreeRootWith ssz hashes the BlockSignatures object with a hasher +func (b *BlockSignatures) HashTreeRootWith(hh ssz.HashWalker) (err error) { + indx := hh.Index() + + // Field (0) 'AttestationSignatures' + { + subIndx := hh.Index() + num := uint64(len(b.AttestationSignatures)) + if num > 4096 { + err = ssz.ErrIncorrectListSize + return + } + for _, elem := range b.AttestationSignatures { + if err = elem.HashTreeRootWith(hh); err != nil { + return + } + } + hh.MerkleizeWithMixin(subIndx, num, 4096) + } + + // Field (1) 'ProposerSignature' + hh.PutBytes(b.ProposerSignature[:]) + + hh.Merkleize(indx) + return +} + +// GetTree ssz hashes the BlockSignatures object +func (b *BlockSignatures) GetTree() (*ssz.Node, error) { + return ssz.ProofTree(b) +} + +// MarshalSSZ ssz marshals the SignedBlock object +func (s *SignedBlock) MarshalSSZ() ([]byte, error) { + return ssz.MarshalSSZ(s) +} + +// MarshalSSZTo ssz marshals the SignedBlock object to a target array +func (s *SignedBlock) MarshalSSZTo(buf []byte) (dst []byte, err error) { + dst = buf + offset := int(8) + + // Offset (0) 'Block' + dst = ssz.WriteOffset(dst, offset) + if s.Block == nil { + s.Block = new(Block) + } + offset += s.Block.SizeSSZ() + + // Offset (1) 'Signature' + dst = ssz.WriteOffset(dst, offset) + + // Field (0) 'Block' + if dst, err = s.Block.MarshalSSZTo(dst); err != nil { + return + } + + // Field (1) 'Signature' + if dst, err = s.Signature.MarshalSSZTo(dst); err != nil { + return + } + + return +} + +// UnmarshalSSZ ssz unmarshals the SignedBlock object +func (s *SignedBlock) UnmarshalSSZ(buf []byte) error { + var err error + size := uint64(len(buf)) + if size < 8 { + return ssz.ErrSize + } + + tail := buf + var o0, o1 uint64 + + // Offset (0) 'Block' + if o0 = ssz.ReadOffset(buf[0:4]); o0 > size { + return ssz.ErrOffset + } + + if o0 != 8 { + return ssz.ErrInvalidVariableOffset + } + + // Offset (1) 'Signature' + if o1 = ssz.ReadOffset(buf[4:8]); o1 > size || o0 > o1 { + return ssz.ErrOffset + } + + // Field (0) 'Block' + { + buf = tail[o0:o1] + if s.Block == nil { + s.Block = new(Block) + } + if err = s.Block.UnmarshalSSZ(buf); err != nil { + return err + } + } + + // Field (1) 'Signature' + { + buf = tail[o1:] + if s.Signature == nil { + s.Signature = new(BlockSignatures) + } + if err = s.Signature.UnmarshalSSZ(buf); err != nil { + return err + } + } + return err +} + +// SizeSSZ returns the ssz encoded size in bytes for the SignedBlock object +func (s *SignedBlock) SizeSSZ() (size int) { + size = 8 + + // Field (0) 'Block' + if s.Block == nil { + s.Block = new(Block) + } + size += s.Block.SizeSSZ() + + // Field (1) 'Signature' + if s.Signature == nil { + s.Signature = new(BlockSignatures) + } + size += s.Signature.SizeSSZ() + + return +} + +// HashTreeRoot ssz hashes the SignedBlock object +func (s *SignedBlock) HashTreeRoot() ([32]byte, error) { + return ssz.HashWithDefaultHasher(s) +} + +// HashTreeRootWith ssz hashes the SignedBlock object with a hasher +func (s *SignedBlock) HashTreeRootWith(hh ssz.HashWalker) (err error) { + indx := hh.Index() + + // Field (0) 'Block' + if err = s.Block.HashTreeRootWith(hh); err != nil { + return + } + + // Field (1) 'Signature' + if err = s.Signature.HashTreeRootWith(hh); err != nil { + return + } + + hh.Merkleize(indx) + return +} + +// GetTree ssz hashes the SignedBlock object +func (s *SignedBlock) GetTree() (*ssz.Node, error) { + return ssz.ProofTree(s) +} + +// MarshalSSZ ssz marshals the BlocksByRangeRequest object +func (b *BlocksByRangeRequest) MarshalSSZ() ([]byte, error) { + return ssz.MarshalSSZ(b) +} + +// MarshalSSZTo ssz marshals the BlocksByRangeRequest object to a target array +func (b *BlocksByRangeRequest) MarshalSSZTo(buf []byte) (dst []byte, err error) { + dst = buf + + // Field (0) 'StartSlot' + dst = ssz.MarshalUint64(dst, b.StartSlot) + + // Field (1) 'Count' + dst = ssz.MarshalUint64(dst, b.Count) + + return +} + +// UnmarshalSSZ ssz unmarshals the BlocksByRangeRequest object +func (b *BlocksByRangeRequest) UnmarshalSSZ(buf []byte) error { + var err error + size := uint64(len(buf)) + if size != 16 { + return ssz.ErrSize + } + + // Field (0) 'StartSlot' + b.StartSlot = ssz.UnmarshallUint64(buf[0:8]) + + // Field (1) 'Count' + b.Count = ssz.UnmarshallUint64(buf[8:16]) + + return err +} + +// SizeSSZ returns the ssz encoded size in bytes for the BlocksByRangeRequest object +func (b *BlocksByRangeRequest) SizeSSZ() (size int) { + size = 16 + return +} + +// HashTreeRoot ssz hashes the BlocksByRangeRequest object +func (b *BlocksByRangeRequest) HashTreeRoot() ([32]byte, error) { + return ssz.HashWithDefaultHasher(b) +} + +// HashTreeRootWith ssz hashes the BlocksByRangeRequest object with a hasher +func (b *BlocksByRangeRequest) HashTreeRootWith(hh ssz.HashWalker) (err error) { + indx := hh.Index() + + // Field (0) 'StartSlot' + hh.PutUint64(b.StartSlot) + + // Field (1) 'Count' + hh.PutUint64(b.Count) + + hh.Merkleize(indx) + return +} + +// GetTree ssz hashes the BlocksByRangeRequest object +func (b *BlocksByRangeRequest) GetTree() (*ssz.Node, error) { + return ssz.ProofTree(b) +} + +// MarshalSSZ ssz marshals the Checkpoint object +func (c *Checkpoint) MarshalSSZ() ([]byte, error) { + return ssz.MarshalSSZ(c) +} + +// MarshalSSZTo ssz marshals the Checkpoint object to a target array +func (c *Checkpoint) MarshalSSZTo(buf []byte) (dst []byte, err error) { + dst = buf + + // Field (0) 'Root' + dst = append(dst, c.Root[:]...) + + // Field (1) 'Slot' + dst = ssz.MarshalUint64(dst, c.Slot) + + return +} + +// UnmarshalSSZ ssz unmarshals the Checkpoint object +func (c *Checkpoint) UnmarshalSSZ(buf []byte) error { + var err error + size := uint64(len(buf)) + if size != 40 { + return ssz.ErrSize + } + + // Field (0) 'Root' + copy(c.Root[:], buf[0:32]) + + // Field (1) 'Slot' + c.Slot = ssz.UnmarshallUint64(buf[32:40]) + + return err +} + +// SizeSSZ returns the ssz encoded size in bytes for the Checkpoint object +func (c *Checkpoint) SizeSSZ() (size int) { + size = 40 + return +} + +// HashTreeRoot ssz hashes the Checkpoint object +func (c *Checkpoint) HashTreeRoot() ([32]byte, error) { + return ssz.HashWithDefaultHasher(c) +} + +// HashTreeRootWith ssz hashes the Checkpoint object with a hasher +func (c *Checkpoint) HashTreeRootWith(hh ssz.HashWalker) (err error) { + indx := hh.Index() + + // Field (0) 'Root' + hh.PutBytes(c.Root[:]) + + // Field (1) 'Slot' + hh.PutUint64(c.Slot) + + hh.Merkleize(indx) + return +} + +// GetTree ssz hashes the Checkpoint object +func (c *Checkpoint) GetTree() (*ssz.Node, error) { + return ssz.ProofTree(c) +} + +// MarshalSSZ ssz marshals the ChainConfig object +func (c *ChainConfig) MarshalSSZ() ([]byte, error) { + return ssz.MarshalSSZ(c) +} + +// MarshalSSZTo ssz marshals the ChainConfig object to a target array +func (c *ChainConfig) MarshalSSZTo(buf []byte) (dst []byte, err error) { + dst = buf + + // Field (0) 'GenesisTime' + dst = ssz.MarshalUint64(dst, c.GenesisTime) + + return +} + +// UnmarshalSSZ ssz unmarshals the ChainConfig object +func (c *ChainConfig) UnmarshalSSZ(buf []byte) error { + var err error + size := uint64(len(buf)) + if size != 8 { + return ssz.ErrSize + } + + // Field (0) 'GenesisTime' + c.GenesisTime = ssz.UnmarshallUint64(buf[0:8]) + + return err +} + +// SizeSSZ returns the ssz encoded size in bytes for the ChainConfig object +func (c *ChainConfig) SizeSSZ() (size int) { + size = 8 + return +} + +// HashTreeRoot ssz hashes the ChainConfig object +func (c *ChainConfig) HashTreeRoot() ([32]byte, error) { + return ssz.HashWithDefaultHasher(c) +} + +// HashTreeRootWith ssz hashes the ChainConfig object with a hasher +func (c *ChainConfig) HashTreeRootWith(hh ssz.HashWalker) (err error) { + indx := hh.Index() + + // Field (0) 'GenesisTime' + hh.PutUint64(c.GenesisTime) + + hh.Merkleize(indx) + return +} + +// GetTree ssz hashes the ChainConfig object +func (c *ChainConfig) GetTree() (*ssz.Node, error) { + return ssz.ProofTree(c) +} + +// MarshalSSZ ssz marshals the State object +func (s *State) MarshalSSZ() ([]byte, error) { + return ssz.MarshalSSZ(s) +} + +// MarshalSSZTo ssz marshals the State object to a target array +func (s *State) MarshalSSZTo(buf []byte) (dst []byte, err error) { + dst = buf + offset := int(228) + + // Field (0) 'Config' + if s.Config == nil { + s.Config = new(ChainConfig) + } + if dst, err = s.Config.MarshalSSZTo(dst); err != nil { + return + } + + // Field (1) 'Slot' + dst = ssz.MarshalUint64(dst, s.Slot) + + // Field (2) 'LatestBlockHeader' + if s.LatestBlockHeader == nil { + s.LatestBlockHeader = new(BlockHeader) + } + if dst, err = s.LatestBlockHeader.MarshalSSZTo(dst); err != nil { + return + } + + // Field (3) 'LatestJustified' + if s.LatestJustified == nil { + s.LatestJustified = new(Checkpoint) + } + if dst, err = s.LatestJustified.MarshalSSZTo(dst); err != nil { + return + } + + // Field (4) 'LatestFinalized' + if s.LatestFinalized == nil { + s.LatestFinalized = new(Checkpoint) + } + if dst, err = s.LatestFinalized.MarshalSSZTo(dst); err != nil { + return + } + + // Offset (5) 'HistoricalBlockHashes' + dst = ssz.WriteOffset(dst, offset) + offset += len(s.HistoricalBlockHashes) * 32 + + // Offset (6) 'JustifiedSlots' + dst = ssz.WriteOffset(dst, offset) + offset += len(s.JustifiedSlots) + + // Offset (7) 'Validators' + dst = ssz.WriteOffset(dst, offset) + offset += len(s.Validators) * 112 + + // Offset (8) 'JustificationsRoots' + dst = ssz.WriteOffset(dst, offset) + offset += len(s.JustificationsRoots) * 32 + + // Offset (9) 'JustificationsValidators' + dst = ssz.WriteOffset(dst, offset) + + // Field (5) 'HistoricalBlockHashes' + if size := len(s.HistoricalBlockHashes); size > 262144 { + err = ssz.ErrListTooBigFn("State.HistoricalBlockHashes", size, 262144) + return + } + for ii := 0; ii < len(s.HistoricalBlockHashes); ii++ { + if size := len(s.HistoricalBlockHashes[ii]); size != 32 { + err = ssz.ErrBytesLengthFn("State.HistoricalBlockHashes[ii]", size, 32) + return + } + dst = append(dst, s.HistoricalBlockHashes[ii]...) + } + + // Field (6) 'JustifiedSlots' + if size := len(s.JustifiedSlots); size > 262144 { + err = ssz.ErrBytesLengthFn("State.JustifiedSlots", size, 262144) + return + } + dst = append(dst, s.JustifiedSlots...) + + // Field (7) 'Validators' + if size := len(s.Validators); size > 4096 { + err = ssz.ErrListTooBigFn("State.Validators", size, 4096) + return + } + for ii := 0; ii < len(s.Validators); ii++ { + if dst, err = s.Validators[ii].MarshalSSZTo(dst); err != nil { + return + } + } + + // Field (8) 'JustificationsRoots' + if size := len(s.JustificationsRoots); size > 262144 { + err = ssz.ErrListTooBigFn("State.JustificationsRoots", size, 262144) + return + } + for ii := 0; ii < len(s.JustificationsRoots); ii++ { + if size := len(s.JustificationsRoots[ii]); size != 32 { + err = ssz.ErrBytesLengthFn("State.JustificationsRoots[ii]", size, 32) + return + } + dst = append(dst, s.JustificationsRoots[ii]...) + } + + // Field (9) 'JustificationsValidators' + if size := len(s.JustificationsValidators); size > 1073741824 { + err = ssz.ErrBytesLengthFn("State.JustificationsValidators", size, 1073741824) + return + } + dst = append(dst, s.JustificationsValidators...) + + return +} + +// UnmarshalSSZ ssz unmarshals the State object +func (s *State) UnmarshalSSZ(buf []byte) error { + var err error + size := uint64(len(buf)) + if size < 228 { + return ssz.ErrSize + } + + tail := buf + var o5, o6, o7, o8, o9 uint64 + + // Field (0) 'Config' + if s.Config == nil { + s.Config = new(ChainConfig) + } + if err = s.Config.UnmarshalSSZ(buf[0:8]); err != nil { + return err + } + + // Field (1) 'Slot' + s.Slot = ssz.UnmarshallUint64(buf[8:16]) + + // Field (2) 'LatestBlockHeader' + if s.LatestBlockHeader == nil { + s.LatestBlockHeader = new(BlockHeader) + } + if err = s.LatestBlockHeader.UnmarshalSSZ(buf[16:128]); err != nil { + return err + } + + // Field (3) 'LatestJustified' + if s.LatestJustified == nil { + s.LatestJustified = new(Checkpoint) + } + if err = s.LatestJustified.UnmarshalSSZ(buf[128:168]); err != nil { + return err + } + + // Field (4) 'LatestFinalized' + if s.LatestFinalized == nil { + s.LatestFinalized = new(Checkpoint) + } + if err = s.LatestFinalized.UnmarshalSSZ(buf[168:208]); err != nil { + return err + } + + // Offset (5) 'HistoricalBlockHashes' + if o5 = ssz.ReadOffset(buf[208:212]); o5 > size { + return ssz.ErrOffset + } + + if o5 != 228 { + return ssz.ErrInvalidVariableOffset + } + + // Offset (6) 'JustifiedSlots' + if o6 = ssz.ReadOffset(buf[212:216]); o6 > size || o5 > o6 { + return ssz.ErrOffset + } + + // Offset (7) 'Validators' + if o7 = ssz.ReadOffset(buf[216:220]); o7 > size || o6 > o7 { + return ssz.ErrOffset + } + + // Offset (8) 'JustificationsRoots' + if o8 = ssz.ReadOffset(buf[220:224]); o8 > size || o7 > o8 { + return ssz.ErrOffset + } + + // Offset (9) 'JustificationsValidators' + if o9 = ssz.ReadOffset(buf[224:228]); o9 > size || o8 > o9 { + return ssz.ErrOffset + } + + // Field (5) 'HistoricalBlockHashes' + { + buf = tail[o5:o6] + num, err := ssz.DivideInt2(len(buf), 32, 262144) + if err != nil { + return err + } + s.HistoricalBlockHashes = make([][]byte, num) + for ii := 0; ii < num; ii++ { + if cap(s.HistoricalBlockHashes[ii]) == 0 { + s.HistoricalBlockHashes[ii] = make([]byte, 0, len(buf[ii*32:(ii+1)*32])) + } + s.HistoricalBlockHashes[ii] = append(s.HistoricalBlockHashes[ii], buf[ii*32:(ii+1)*32]...) + } + } + + // Field (6) 'JustifiedSlots' + { + buf = tail[o6:o7] + if err = ssz.ValidateBitlist(buf, 262144); err != nil { + return err + } + if cap(s.JustifiedSlots) == 0 { + s.JustifiedSlots = make([]byte, 0, len(buf)) + } + s.JustifiedSlots = append(s.JustifiedSlots, buf...) + } + + // Field (7) 'Validators' + { + buf = tail[o7:o8] + num, err := ssz.DivideInt2(len(buf), 112, 4096) + if err != nil { + return err + } + s.Validators = make([]*Validator, num) + for ii := 0; ii < num; ii++ { + if s.Validators[ii] == nil { + s.Validators[ii] = new(Validator) + } + if err = s.Validators[ii].UnmarshalSSZ(buf[ii*112 : (ii+1)*112]); err != nil { + return err + } + } + } + + // Field (8) 'JustificationsRoots' + { + buf = tail[o8:o9] + num, err := ssz.DivideInt2(len(buf), 32, 262144) + if err != nil { + return err + } + s.JustificationsRoots = make([][]byte, num) + for ii := 0; ii < num; ii++ { + if cap(s.JustificationsRoots[ii]) == 0 { + s.JustificationsRoots[ii] = make([]byte, 0, len(buf[ii*32:(ii+1)*32])) + } + s.JustificationsRoots[ii] = append(s.JustificationsRoots[ii], buf[ii*32:(ii+1)*32]...) + } + } + + // Field (9) 'JustificationsValidators' + { + buf = tail[o9:] + if err = ssz.ValidateBitlist(buf, 1073741824); err != nil { + return err + } + if cap(s.JustificationsValidators) == 0 { + s.JustificationsValidators = make([]byte, 0, len(buf)) + } + s.JustificationsValidators = append(s.JustificationsValidators, buf...) + } + return err +} + +// SizeSSZ returns the ssz encoded size in bytes for the State object +func (s *State) SizeSSZ() (size int) { + size = 228 + + // Field (5) 'HistoricalBlockHashes' + size += len(s.HistoricalBlockHashes) * 32 + + // Field (6) 'JustifiedSlots' + size += len(s.JustifiedSlots) + + // Field (7) 'Validators' + size += len(s.Validators) * 112 + + // Field (8) 'JustificationsRoots' + size += len(s.JustificationsRoots) * 32 + + // Field (9) 'JustificationsValidators' + size += len(s.JustificationsValidators) + + return +} + +// HashTreeRoot ssz hashes the State object +func (s *State) HashTreeRoot() ([32]byte, error) { + return ssz.HashWithDefaultHasher(s) +} + +// HashTreeRootWith ssz hashes the State object with a hasher +func (s *State) HashTreeRootWith(hh ssz.HashWalker) (err error) { + indx := hh.Index() + + // Field (0) 'Config' + if s.Config == nil { + s.Config = new(ChainConfig) + } + if err = s.Config.HashTreeRootWith(hh); err != nil { + return + } + + // Field (1) 'Slot' + hh.PutUint64(s.Slot) + + // Field (2) 'LatestBlockHeader' + if s.LatestBlockHeader == nil { + s.LatestBlockHeader = new(BlockHeader) + } + if err = s.LatestBlockHeader.HashTreeRootWith(hh); err != nil { + return + } + + // Field (3) 'LatestJustified' + if s.LatestJustified == nil { + s.LatestJustified = new(Checkpoint) + } + if err = s.LatestJustified.HashTreeRootWith(hh); err != nil { + return + } + + // Field (4) 'LatestFinalized' + if s.LatestFinalized == nil { + s.LatestFinalized = new(Checkpoint) + } + if err = s.LatestFinalized.HashTreeRootWith(hh); err != nil { + return + } + + // Field (5) 'HistoricalBlockHashes' + { + if size := len(s.HistoricalBlockHashes); size > 262144 { + err = ssz.ErrListTooBigFn("State.HistoricalBlockHashes", size, 262144) + return + } + subIndx := hh.Index() + for _, i := range s.HistoricalBlockHashes { + if len(i) != 32 { + err = ssz.ErrBytesLength + return + } + hh.Append(i) + } + numItems := uint64(len(s.HistoricalBlockHashes)) + hh.MerkleizeWithMixin(subIndx, numItems, 262144) + } + + // Field (6) 'JustifiedSlots' + if len(s.JustifiedSlots) == 0 { + err = ssz.ErrEmptyBitlist + return + } + hh.PutBitlist(s.JustifiedSlots, 262144) + + // Field (7) 'Validators' + { + subIndx := hh.Index() + num := uint64(len(s.Validators)) + if num > 4096 { + err = ssz.ErrIncorrectListSize + return + } + for _, elem := range s.Validators { + if err = elem.HashTreeRootWith(hh); err != nil { + return + } + } + hh.MerkleizeWithMixin(subIndx, num, 4096) + } + + // Field (8) 'JustificationsRoots' + { + if size := len(s.JustificationsRoots); size > 262144 { + err = ssz.ErrListTooBigFn("State.JustificationsRoots", size, 262144) + return + } + subIndx := hh.Index() + for _, i := range s.JustificationsRoots { + if len(i) != 32 { + err = ssz.ErrBytesLength + return + } + hh.Append(i) + } + numItems := uint64(len(s.JustificationsRoots)) + hh.MerkleizeWithMixin(subIndx, numItems, 262144) + } + + // Field (9) 'JustificationsValidators' + if len(s.JustificationsValidators) == 0 { + err = ssz.ErrEmptyBitlist + return + } + hh.PutBitlist(s.JustificationsValidators, 1073741824) + + hh.Merkleize(indx) + return +} + +// GetTree ssz hashes the State object +func (s *State) GetTree() (*ssz.Node, error) { + return ssz.ProofTree(s) +} + +// MarshalSSZ ssz marshals the Validator object +func (v *Validator) MarshalSSZ() ([]byte, error) { + return ssz.MarshalSSZ(v) +} + +// MarshalSSZTo ssz marshals the Validator object to a target array +func (v *Validator) MarshalSSZTo(buf []byte) (dst []byte, err error) { + dst = buf + + // Field (0) 'AttestationPubkey' + dst = append(dst, v.AttestationPubkey[:]...) + + // Field (1) 'ProposalPubkey' + dst = append(dst, v.ProposalPubkey[:]...) + + // Field (2) 'Index' + dst = ssz.MarshalUint64(dst, v.Index) + + return +} + +// UnmarshalSSZ ssz unmarshals the Validator object +func (v *Validator) UnmarshalSSZ(buf []byte) error { + var err error + size := uint64(len(buf)) + if size != 112 { + return ssz.ErrSize + } + + // Field (0) 'AttestationPubkey' + copy(v.AttestationPubkey[:], buf[0:52]) + + // Field (1) 'ProposalPubkey' + copy(v.ProposalPubkey[:], buf[52:104]) + + // Field (2) 'Index' + v.Index = ssz.UnmarshallUint64(buf[104:112]) + + return err +} + +// SizeSSZ returns the ssz encoded size in bytes for the Validator object +func (v *Validator) SizeSSZ() (size int) { + size = 112 + return +} + +// HashTreeRoot ssz hashes the Validator object +func (v *Validator) HashTreeRoot() ([32]byte, error) { + return ssz.HashWithDefaultHasher(v) +} + +// HashTreeRootWith ssz hashes the Validator object with a hasher +func (v *Validator) HashTreeRootWith(hh ssz.HashWalker) (err error) { + indx := hh.Index() + + // Field (0) 'AttestationPubkey' + hh.PutBytes(v.AttestationPubkey[:]) + + // Field (1) 'ProposalPubkey' + hh.PutBytes(v.ProposalPubkey[:]) + + // Field (2) 'Index' + hh.PutUint64(v.Index) + + hh.Merkleize(indx) + return +} + +// GetTree ssz hashes the Validator object +func (v *Validator) GetTree() (*ssz.Node, error) { + return ssz.ProofTree(v) +} diff --git a/types/state_encoding.go b/types/state_encoding.go deleted file mode 100644 index f1010e35..00000000 --- a/types/state_encoding.go +++ /dev/null @@ -1,418 +0,0 @@ -// Code generated by fastssz. DO NOT EDIT. -// Hash: 52b67ea3b7cb79482579d5c3ff659d3473b41bec2511e9c0fd826505bb9f9f72 -// Version: 0.1.3 -package types - -import ( - ssz "github.com/ferranbt/fastssz" -) - -// MarshalSSZ ssz marshals the State object -func (s *State) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(s) -} - -// MarshalSSZTo ssz marshals the State object to a target array -func (s *State) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - offset := int(228) - - // Field (0) 'Config' - if s.Config == nil { - s.Config = new(ChainConfig) - } - if dst, err = s.Config.MarshalSSZTo(dst); err != nil { - return - } - - // Field (1) 'Slot' - dst = ssz.MarshalUint64(dst, s.Slot) - - // Field (2) 'LatestBlockHeader' - if s.LatestBlockHeader == nil { - s.LatestBlockHeader = new(BlockHeader) - } - if dst, err = s.LatestBlockHeader.MarshalSSZTo(dst); err != nil { - return - } - - // Field (3) 'LatestJustified' - if s.LatestJustified == nil { - s.LatestJustified = new(Checkpoint) - } - if dst, err = s.LatestJustified.MarshalSSZTo(dst); err != nil { - return - } - - // Field (4) 'LatestFinalized' - if s.LatestFinalized == nil { - s.LatestFinalized = new(Checkpoint) - } - if dst, err = s.LatestFinalized.MarshalSSZTo(dst); err != nil { - return - } - - // Offset (5) 'HistoricalBlockHashes' - dst = ssz.WriteOffset(dst, offset) - offset += len(s.HistoricalBlockHashes) * 32 - - // Offset (6) 'JustifiedSlots' - dst = ssz.WriteOffset(dst, offset) - offset += len(s.JustifiedSlots) - - // Offset (7) 'Validators' - dst = ssz.WriteOffset(dst, offset) - offset += len(s.Validators) * 112 - - // Offset (8) 'JustificationsRoots' - dst = ssz.WriteOffset(dst, offset) - offset += len(s.JustificationsRoots) * 32 - - // Offset (9) 'JustificationsValidators' - dst = ssz.WriteOffset(dst, offset) - - // Field (5) 'HistoricalBlockHashes' - if size := len(s.HistoricalBlockHashes); size > 262144 { - err = ssz.ErrListTooBigFn("State.HistoricalBlockHashes", size, 262144) - return - } - for ii := 0; ii < len(s.HistoricalBlockHashes); ii++ { - if size := len(s.HistoricalBlockHashes[ii]); size != 32 { - err = ssz.ErrBytesLengthFn("State.HistoricalBlockHashes[ii]", size, 32) - return - } - dst = append(dst, s.HistoricalBlockHashes[ii]...) - } - - // Field (6) 'JustifiedSlots' - if size := len(s.JustifiedSlots); size > 262144 { - err = ssz.ErrBytesLengthFn("State.JustifiedSlots", size, 262144) - return - } - dst = append(dst, s.JustifiedSlots...) - - // Field (7) 'Validators' - if size := len(s.Validators); size > 4096 { - err = ssz.ErrListTooBigFn("State.Validators", size, 4096) - return - } - for ii := 0; ii < len(s.Validators); ii++ { - if dst, err = s.Validators[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - // Field (8) 'JustificationsRoots' - if size := len(s.JustificationsRoots); size > 262144 { - err = ssz.ErrListTooBigFn("State.JustificationsRoots", size, 262144) - return - } - for ii := 0; ii < len(s.JustificationsRoots); ii++ { - if size := len(s.JustificationsRoots[ii]); size != 32 { - err = ssz.ErrBytesLengthFn("State.JustificationsRoots[ii]", size, 32) - return - } - dst = append(dst, s.JustificationsRoots[ii]...) - } - - // Field (9) 'JustificationsValidators' - if size := len(s.JustificationsValidators); size > 1073741824 { - err = ssz.ErrBytesLengthFn("State.JustificationsValidators", size, 1073741824) - return - } - dst = append(dst, s.JustificationsValidators...) - - return -} - -// UnmarshalSSZ ssz unmarshals the State object -func (s *State) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size < 228 { - return ssz.ErrSize - } - - tail := buf - var o5, o6, o7, o8, o9 uint64 - - // Field (0) 'Config' - if s.Config == nil { - s.Config = new(ChainConfig) - } - if err = s.Config.UnmarshalSSZ(buf[0:8]); err != nil { - return err - } - - // Field (1) 'Slot' - s.Slot = ssz.UnmarshallUint64(buf[8:16]) - - // Field (2) 'LatestBlockHeader' - if s.LatestBlockHeader == nil { - s.LatestBlockHeader = new(BlockHeader) - } - if err = s.LatestBlockHeader.UnmarshalSSZ(buf[16:128]); err != nil { - return err - } - - // Field (3) 'LatestJustified' - if s.LatestJustified == nil { - s.LatestJustified = new(Checkpoint) - } - if err = s.LatestJustified.UnmarshalSSZ(buf[128:168]); err != nil { - return err - } - - // Field (4) 'LatestFinalized' - if s.LatestFinalized == nil { - s.LatestFinalized = new(Checkpoint) - } - if err = s.LatestFinalized.UnmarshalSSZ(buf[168:208]); err != nil { - return err - } - - // Offset (5) 'HistoricalBlockHashes' - if o5 = ssz.ReadOffset(buf[208:212]); o5 > size { - return ssz.ErrOffset - } - - if o5 != 228 { - return ssz.ErrInvalidVariableOffset - } - - // Offset (6) 'JustifiedSlots' - if o6 = ssz.ReadOffset(buf[212:216]); o6 > size || o5 > o6 { - return ssz.ErrOffset - } - - // Offset (7) 'Validators' - if o7 = ssz.ReadOffset(buf[216:220]); o7 > size || o6 > o7 { - return ssz.ErrOffset - } - - // Offset (8) 'JustificationsRoots' - if o8 = ssz.ReadOffset(buf[220:224]); o8 > size || o7 > o8 { - return ssz.ErrOffset - } - - // Offset (9) 'JustificationsValidators' - if o9 = ssz.ReadOffset(buf[224:228]); o9 > size || o8 > o9 { - return ssz.ErrOffset - } - - // Field (5) 'HistoricalBlockHashes' - { - buf = tail[o5:o6] - num, err := ssz.DivideInt2(len(buf), 32, 262144) - if err != nil { - return err - } - s.HistoricalBlockHashes = make([][]byte, num) - for ii := 0; ii < num; ii++ { - if cap(s.HistoricalBlockHashes[ii]) == 0 { - s.HistoricalBlockHashes[ii] = make([]byte, 0, len(buf[ii*32:(ii+1)*32])) - } - s.HistoricalBlockHashes[ii] = append(s.HistoricalBlockHashes[ii], buf[ii*32:(ii+1)*32]...) - } - } - - // Field (6) 'JustifiedSlots' - { - buf = tail[o6:o7] - if err = ssz.ValidateBitlist(buf, 262144); err != nil { - return err - } - if cap(s.JustifiedSlots) == 0 { - s.JustifiedSlots = make([]byte, 0, len(buf)) - } - s.JustifiedSlots = append(s.JustifiedSlots, buf...) - } - - // Field (7) 'Validators' - { - buf = tail[o7:o8] - num, err := ssz.DivideInt2(len(buf), 112, 4096) - if err != nil { - return err - } - s.Validators = make([]*Validator, num) - for ii := 0; ii < num; ii++ { - if s.Validators[ii] == nil { - s.Validators[ii] = new(Validator) - } - if err = s.Validators[ii].UnmarshalSSZ(buf[ii*112 : (ii+1)*112]); err != nil { - return err - } - } - } - - // Field (8) 'JustificationsRoots' - { - buf = tail[o8:o9] - num, err := ssz.DivideInt2(len(buf), 32, 262144) - if err != nil { - return err - } - s.JustificationsRoots = make([][]byte, num) - for ii := 0; ii < num; ii++ { - if cap(s.JustificationsRoots[ii]) == 0 { - s.JustificationsRoots[ii] = make([]byte, 0, len(buf[ii*32:(ii+1)*32])) - } - s.JustificationsRoots[ii] = append(s.JustificationsRoots[ii], buf[ii*32:(ii+1)*32]...) - } - } - - // Field (9) 'JustificationsValidators' - { - buf = tail[o9:] - if err = ssz.ValidateBitlist(buf, 1073741824); err != nil { - return err - } - if cap(s.JustificationsValidators) == 0 { - s.JustificationsValidators = make([]byte, 0, len(buf)) - } - s.JustificationsValidators = append(s.JustificationsValidators, buf...) - } - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the State object -func (s *State) SizeSSZ() (size int) { - size = 228 - - // Field (5) 'HistoricalBlockHashes' - size += len(s.HistoricalBlockHashes) * 32 - - // Field (6) 'JustifiedSlots' - size += len(s.JustifiedSlots) - - // Field (7) 'Validators' - size += len(s.Validators) * 112 - - // Field (8) 'JustificationsRoots' - size += len(s.JustificationsRoots) * 32 - - // Field (9) 'JustificationsValidators' - size += len(s.JustificationsValidators) - - return -} - -// HashTreeRoot ssz hashes the State object -func (s *State) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(s) -} - -// HashTreeRootWith ssz hashes the State object with a hasher -func (s *State) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Config' - if s.Config == nil { - s.Config = new(ChainConfig) - } - if err = s.Config.HashTreeRootWith(hh); err != nil { - return - } - - // Field (1) 'Slot' - hh.PutUint64(s.Slot) - - // Field (2) 'LatestBlockHeader' - if s.LatestBlockHeader == nil { - s.LatestBlockHeader = new(BlockHeader) - } - if err = s.LatestBlockHeader.HashTreeRootWith(hh); err != nil { - return - } - - // Field (3) 'LatestJustified' - if s.LatestJustified == nil { - s.LatestJustified = new(Checkpoint) - } - if err = s.LatestJustified.HashTreeRootWith(hh); err != nil { - return - } - - // Field (4) 'LatestFinalized' - if s.LatestFinalized == nil { - s.LatestFinalized = new(Checkpoint) - } - if err = s.LatestFinalized.HashTreeRootWith(hh); err != nil { - return - } - - // Field (5) 'HistoricalBlockHashes' - { - if size := len(s.HistoricalBlockHashes); size > 262144 { - err = ssz.ErrListTooBigFn("State.HistoricalBlockHashes", size, 262144) - return - } - subIndx := hh.Index() - for _, i := range s.HistoricalBlockHashes { - if len(i) != 32 { - err = ssz.ErrBytesLength - return - } - hh.Append(i) - } - numItems := uint64(len(s.HistoricalBlockHashes)) - hh.MerkleizeWithMixin(subIndx, numItems, 262144) - } - - // Field (6) 'JustifiedSlots' - if len(s.JustifiedSlots) == 0 { - err = ssz.ErrEmptyBitlist - return - } - hh.PutBitlist(s.JustifiedSlots, 262144) - - // Field (7) 'Validators' - { - subIndx := hh.Index() - num := uint64(len(s.Validators)) - if num > 4096 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range s.Validators { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 4096) - } - - // Field (8) 'JustificationsRoots' - { - if size := len(s.JustificationsRoots); size > 262144 { - err = ssz.ErrListTooBigFn("State.JustificationsRoots", size, 262144) - return - } - subIndx := hh.Index() - for _, i := range s.JustificationsRoots { - if len(i) != 32 { - err = ssz.ErrBytesLength - return - } - hh.Append(i) - } - numItems := uint64(len(s.JustificationsRoots)) - hh.MerkleizeWithMixin(subIndx, numItems, 262144) - } - - // Field (9) 'JustificationsValidators' - if len(s.JustificationsValidators) == 0 { - err = ssz.ErrEmptyBitlist - return - } - hh.PutBitlist(s.JustificationsValidators, 1073741824) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the State object -func (s *State) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(s) -} diff --git a/types/validator_encoding.go b/types/validator_encoding.go deleted file mode 100644 index c31e905e..00000000 --- a/types/validator_encoding.go +++ /dev/null @@ -1,82 +0,0 @@ -// Code generated by fastssz. DO NOT EDIT. -// Hash: dual-key-devnet4 -// Version: 0.1.3 -package types - -import ( - ssz "github.com/ferranbt/fastssz" -) - -// MarshalSSZ ssz marshals the Validator object -func (v *Validator) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(v) -} - -// MarshalSSZTo ssz marshals the Validator object to a target array -func (v *Validator) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'AttestationPubkey' - dst = append(dst, v.AttestationPubkey[:]...) - - // Field (1) 'ProposalPubkey' - dst = append(dst, v.ProposalPubkey[:]...) - - // Field (2) 'Index' - dst = ssz.MarshalUint64(dst, v.Index) - - return -} - -// UnmarshalSSZ ssz unmarshals the Validator object -func (v *Validator) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 112 { - return ssz.ErrSize - } - - // Field (0) 'AttestationPubkey' - copy(v.AttestationPubkey[:], buf[0:52]) - - // Field (1) 'ProposalPubkey' - copy(v.ProposalPubkey[:], buf[52:104]) - - // Field (2) 'Index' - v.Index = ssz.UnmarshallUint64(buf[104:112]) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the Validator object -func (v *Validator) SizeSSZ() (size int) { - size = 112 - return -} - -// HashTreeRoot ssz hashes the Validator object -func (v *Validator) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(v) -} - -// HashTreeRootWith ssz hashes the Validator object with a hasher -func (v *Validator) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'AttestationPubkey' - hh.PutBytes(v.AttestationPubkey[:]) - - // Field (1) 'ProposalPubkey' - hh.PutBytes(v.ProposalPubkey[:]) - - // Field (2) 'Index' - hh.PutUint64(v.Index) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the Validator object -func (v *Validator) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(v) -}