mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-07 22:54:17 -05:00
Initialize SSZ-QL package with support for fixed-size types (#15588)
* Add basic PathElement * Add ssz_type.go * Add basic sszInfo * Add containerInfo * Add basic analyzer without analyzing list/vector * Add analyzer for homogeneous collection types * Add offset/length calculator * Add testutil package in encoding/ssz/query * Add first round trip test for IndexedAttestationElectra * Go mod tidy * Add Print function for debugging purpose * Add changelog * Add testonly flag for testutil package & Nit for nogo * Apply reviews from Radek * Replace fastssz with prysmaticlabs one * Add proto/ssz_query package for testing purpose * Update encoding/ssz/query tests to decouple with beacon types * Use require.* instead of assert.* * Fix import name for proto ssz_query package * Remove uint8/uint16 and some byte arrays in FixedTestContainer * Add newline for files * Fix comment about byte array in ssz_query.proto --------- Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
68
proto/ssz_query/BUILD.bazel
Normal file
68
proto/ssz_query/BUILD.bazel
Normal file
@@ -0,0 +1,68 @@
|
||||
load("@rules_proto//proto:defs.bzl", "proto_library")
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
|
||||
load("//proto:ssz_proto_library.bzl", "ssz_proto_files")
|
||||
load("//tools:ssz.bzl", "SSZ_DEPS", "ssz_gen_marshal")
|
||||
|
||||
# gazelle:ignore
|
||||
|
||||
proto_library(
|
||||
name = "proto",
|
||||
srcs = ["ssz_query.proto"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//proto/eth/ext:proto",
|
||||
],
|
||||
)
|
||||
|
||||
go_proto_library(
|
||||
name = "go_proto",
|
||||
compilers = [
|
||||
"@com_github_prysmaticlabs_protoc_gen_go_cast//:go_cast_grpc",
|
||||
],
|
||||
importpath = "github.com/OffchainLabs/prysm/v6/proto/ssz_query",
|
||||
proto = ":proto",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//proto/eth/ext:go_default_library",
|
||||
"@com_github_golang_protobuf//proto:go_default_library",
|
||||
"@org_golang_google_protobuf//reflect/protoreflect:go_default_library",
|
||||
"@org_golang_google_protobuf//runtime/protoimpl:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
# SSZ generation for test proto messages
|
||||
ssz_gen_marshal(
|
||||
name = "ssz_generated",
|
||||
out = "ssz_query.ssz.go",
|
||||
go_proto = ":go_proto",
|
||||
objs = [
|
||||
"FixedTestContainer",
|
||||
"FixedNestedContainer",
|
||||
],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
":ssz_generated", # keep
|
||||
],
|
||||
embed = [":go_proto"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v6/proto/ssz_query",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = SSZ_DEPS + [
|
||||
"//proto/eth/ext:go_default_library",
|
||||
"@com_github_golang_protobuf//proto:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
ssz_proto_files(
|
||||
name = "ssz_proto_files",
|
||||
srcs = ["ssz_query.proto"],
|
||||
config = select({
|
||||
"//conditions:default": "mainnet",
|
||||
"//proto:ssz_mainnet": "mainnet",
|
||||
"//proto:ssz_minimal": "minimal",
|
||||
}),
|
||||
)
|
||||
289
proto/ssz_query/ssz_query.pb.go
generated
Executable file
289
proto/ssz_query/ssz_query.pb.go
generated
Executable file
@@ -0,0 +1,289 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.33.0
|
||||
// protoc v3.21.7
|
||||
// source: proto/ssz_query/ssz_query.proto
|
||||
|
||||
package ssz_query
|
||||
|
||||
import (
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
|
||||
_ "github.com/OffchainLabs/prysm/v6/proto/eth/ext"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
type FixedNestedContainer struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Value1 uint64 `protobuf:"varint,1,opt,name=value1,proto3" json:"value1,omitempty"`
|
||||
Value2 []byte `protobuf:"bytes,2,opt,name=value2,proto3" json:"value2,omitempty" ssz-size:"32"`
|
||||
}
|
||||
|
||||
func (x *FixedNestedContainer) Reset() {
|
||||
*x = FixedNestedContainer{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_ssz_query_ssz_query_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *FixedNestedContainer) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*FixedNestedContainer) ProtoMessage() {}
|
||||
|
||||
func (x *FixedNestedContainer) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_ssz_query_ssz_query_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use FixedNestedContainer.ProtoReflect.Descriptor instead.
|
||||
func (*FixedNestedContainer) Descriptor() ([]byte, []int) {
|
||||
return file_proto_ssz_query_ssz_query_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *FixedNestedContainer) GetValue1() uint64 {
|
||||
if x != nil {
|
||||
return x.Value1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *FixedNestedContainer) GetValue2() []byte {
|
||||
if x != nil {
|
||||
return x.Value2
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type FixedTestContainer struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
FieldUint32 uint32 `protobuf:"varint,3,opt,name=field_uint32,json=fieldUint32,proto3" json:"field_uint32,omitempty"`
|
||||
FieldUint64 uint64 `protobuf:"varint,4,opt,name=field_uint64,json=fieldUint64,proto3" json:"field_uint64,omitempty"`
|
||||
FieldBool bool `protobuf:"varint,5,opt,name=field_bool,json=fieldBool,proto3" json:"field_bool,omitempty"`
|
||||
FieldBytes32 []byte `protobuf:"bytes,8,opt,name=field_bytes32,json=fieldBytes32,proto3" json:"field_bytes32,omitempty" ssz-size:"32"`
|
||||
Nested *FixedNestedContainer `protobuf:"bytes,9,opt,name=nested,proto3" json:"nested,omitempty"`
|
||||
VectorField []uint64 `protobuf:"varint,10,rep,packed,name=vector_field,json=vectorField,proto3" json:"vector_field,omitempty" ssz-size:"24"`
|
||||
TrailingField []byte `protobuf:"bytes,11,opt,name=trailing_field,json=trailingField,proto3" json:"trailing_field,omitempty" ssz-size:"56"`
|
||||
}
|
||||
|
||||
func (x *FixedTestContainer) Reset() {
|
||||
*x = FixedTestContainer{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_ssz_query_ssz_query_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *FixedTestContainer) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*FixedTestContainer) ProtoMessage() {}
|
||||
|
||||
func (x *FixedTestContainer) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_ssz_query_ssz_query_proto_msgTypes[1]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use FixedTestContainer.ProtoReflect.Descriptor instead.
|
||||
func (*FixedTestContainer) Descriptor() ([]byte, []int) {
|
||||
return file_proto_ssz_query_ssz_query_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *FixedTestContainer) GetFieldUint32() uint32 {
|
||||
if x != nil {
|
||||
return x.FieldUint32
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *FixedTestContainer) GetFieldUint64() uint64 {
|
||||
if x != nil {
|
||||
return x.FieldUint64
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *FixedTestContainer) GetFieldBool() bool {
|
||||
if x != nil {
|
||||
return x.FieldBool
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *FixedTestContainer) GetFieldBytes32() []byte {
|
||||
if x != nil {
|
||||
return x.FieldBytes32
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *FixedTestContainer) GetNested() *FixedNestedContainer {
|
||||
if x != nil {
|
||||
return x.Nested
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *FixedTestContainer) GetVectorField() []uint64 {
|
||||
if x != nil {
|
||||
return x.VectorField
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *FixedTestContainer) GetTrailingField() []byte {
|
||||
if x != nil {
|
||||
return x.TrailingField
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_proto_ssz_query_ssz_query_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_proto_ssz_query_ssz_query_proto_rawDesc = []byte{
|
||||
0x0a, 0x1f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x73, 0x7a, 0x5f, 0x71, 0x75, 0x65, 0x72,
|
||||
0x79, 0x2f, 0x73, 0x73, 0x7a, 0x5f, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x12, 0x09, 0x73, 0x73, 0x7a, 0x5f, 0x71, 0x75, 0x65, 0x72, 0x79, 0x1a, 0x1b, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x2f, 0x65, 0x74, 0x68, 0x2f, 0x65, 0x78, 0x74, 0x2f, 0x6f, 0x70, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x4e, 0x0a, 0x14, 0x46, 0x69, 0x78,
|
||||
0x65, 0x64, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65,
|
||||
0x72, 0x12, 0x16, 0x0a, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x04, 0x52, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x31, 0x12, 0x1e, 0x0a, 0x06, 0x76, 0x61, 0x6c,
|
||||
0x75, 0x65, 0x32, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x06, 0x8a, 0xb5, 0x18, 0x02, 0x33,
|
||||
0x32, 0x52, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x32, 0x22, 0xb9, 0x02, 0x0a, 0x12, 0x46, 0x69,
|
||||
0x78, 0x65, 0x64, 0x54, 0x65, 0x73, 0x74, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72,
|
||||
0x12, 0x21, 0x0a, 0x0c, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x5f, 0x75, 0x69, 0x6e, 0x74, 0x33, 0x32,
|
||||
0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0b, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x55, 0x69, 0x6e,
|
||||
0x74, 0x33, 0x32, 0x12, 0x21, 0x0a, 0x0c, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x5f, 0x75, 0x69, 0x6e,
|
||||
0x74, 0x36, 0x34, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x66, 0x69, 0x65, 0x6c, 0x64,
|
||||
0x55, 0x69, 0x6e, 0x74, 0x36, 0x34, 0x12, 0x1d, 0x0a, 0x0a, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x5f,
|
||||
0x62, 0x6f, 0x6f, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x66, 0x69, 0x65, 0x6c,
|
||||
0x64, 0x42, 0x6f, 0x6f, 0x6c, 0x12, 0x2b, 0x0a, 0x0d, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x5f, 0x62,
|
||||
0x79, 0x74, 0x65, 0x73, 0x33, 0x32, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x06, 0x8a, 0xb5,
|
||||
0x18, 0x02, 0x33, 0x32, 0x52, 0x0c, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x42, 0x79, 0x74, 0x65, 0x73,
|
||||
0x33, 0x32, 0x12, 0x37, 0x0a, 0x06, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x18, 0x09, 0x20, 0x01,
|
||||
0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x73, 0x73, 0x7a, 0x5f, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2e, 0x46,
|
||||
0x69, 0x78, 0x65, 0x64, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69,
|
||||
0x6e, 0x65, 0x72, 0x52, 0x06, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x12, 0x29, 0x0a, 0x0c, 0x76,
|
||||
0x65, 0x63, 0x74, 0x6f, 0x72, 0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x0a, 0x20, 0x03, 0x28,
|
||||
0x04, 0x42, 0x06, 0x8a, 0xb5, 0x18, 0x02, 0x32, 0x34, 0x52, 0x0b, 0x76, 0x65, 0x63, 0x74, 0x6f,
|
||||
0x72, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x2d, 0x0a, 0x0e, 0x74, 0x72, 0x61, 0x69, 0x6c, 0x69,
|
||||
0x6e, 0x67, 0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x06,
|
||||
0x8a, 0xb5, 0x18, 0x02, 0x35, 0x36, 0x52, 0x0d, 0x74, 0x72, 0x61, 0x69, 0x6c, 0x69, 0x6e, 0x67,
|
||||
0x46, 0x69, 0x65, 0x6c, 0x64, 0x42, 0x32, 0x5a, 0x30, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e,
|
||||
0x63, 0x6f, 0x6d, 0x2f, 0x4f, 0x66, 0x66, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x4c, 0x61, 0x62, 0x73,
|
||||
0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x2f, 0x76, 0x36, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f,
|
||||
0x73, 0x73, 0x7a, 0x5f, 0x71, 0x75, 0x65, 0x72, 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_proto_ssz_query_ssz_query_proto_rawDescOnce sync.Once
|
||||
file_proto_ssz_query_ssz_query_proto_rawDescData = file_proto_ssz_query_ssz_query_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_proto_ssz_query_ssz_query_proto_rawDescGZIP() []byte {
|
||||
file_proto_ssz_query_ssz_query_proto_rawDescOnce.Do(func() {
|
||||
file_proto_ssz_query_ssz_query_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_ssz_query_ssz_query_proto_rawDescData)
|
||||
})
|
||||
return file_proto_ssz_query_ssz_query_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_proto_ssz_query_ssz_query_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
|
||||
var file_proto_ssz_query_ssz_query_proto_goTypes = []interface{}{
|
||||
(*FixedNestedContainer)(nil), // 0: ssz_query.FixedNestedContainer
|
||||
(*FixedTestContainer)(nil), // 1: ssz_query.FixedTestContainer
|
||||
}
|
||||
var file_proto_ssz_query_ssz_query_proto_depIdxs = []int32{
|
||||
0, // 0: ssz_query.FixedTestContainer.nested:type_name -> ssz_query.FixedNestedContainer
|
||||
1, // [1:1] is the sub-list for method output_type
|
||||
1, // [1:1] is the sub-list for method input_type
|
||||
1, // [1:1] is the sub-list for extension type_name
|
||||
1, // [1:1] is the sub-list for extension extendee
|
||||
0, // [0:1] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_proto_ssz_query_ssz_query_proto_init() }
|
||||
func file_proto_ssz_query_ssz_query_proto_init() {
|
||||
if File_proto_ssz_query_ssz_query_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_proto_ssz_query_ssz_query_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*FixedNestedContainer); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_proto_ssz_query_ssz_query_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*FixedTestContainer); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_proto_ssz_query_ssz_query_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 2,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
GoTypes: file_proto_ssz_query_ssz_query_proto_goTypes,
|
||||
DependencyIndexes: file_proto_ssz_query_ssz_query_proto_depIdxs,
|
||||
MessageInfos: file_proto_ssz_query_ssz_query_proto_msgTypes,
|
||||
}.Build()
|
||||
File_proto_ssz_query_ssz_query_proto = out.File
|
||||
file_proto_ssz_query_ssz_query_proto_rawDesc = nil
|
||||
file_proto_ssz_query_ssz_query_proto_goTypes = nil
|
||||
file_proto_ssz_query_ssz_query_proto_depIdxs = nil
|
||||
}
|
||||
43
proto/ssz_query/ssz_query.proto
Normal file
43
proto/ssz_query/ssz_query.proto
Normal file
@@ -0,0 +1,43 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package ssz_query;
|
||||
|
||||
import "proto/eth/ext/options.proto";
|
||||
|
||||
option go_package = "github.com/OffchainLabs/prysm/v6/proto/ssz_query";
|
||||
|
||||
|
||||
// ===== FIXED-SIZE TEST CONTAINERS =====
|
||||
// These containers are designed to test SSZ query functionality with comprehensive coverage
|
||||
// of all fixed-size SSZ types according to the SSZ specification.
|
||||
|
||||
// FixedNestedContainer - nested container for testing nested field access
|
||||
// Tests: nested container navigation, field offset calculations within nested structures
|
||||
message FixedNestedContainer {
|
||||
uint64 value1 = 1; // Test: uint64 basic type, offset calculation in nested context
|
||||
bytes value2 = 2 [ (ethereum.eth.ext.ssz_size) = "32" ]; // Test: fixed-size bytes in nested container
|
||||
}
|
||||
|
||||
// FixedTestContainer - comprehensive fixed-size container for SSZ query testing
|
||||
// Tests: All basic fixed-size SSZ types, nested containers, vectors, offset/length calculations
|
||||
// Total size: 333 bytes (4+8+1+32+40+192+56)
|
||||
message FixedTestContainer {
|
||||
// Basic integer types - test different integer sizes and their SSZ serialization
|
||||
uint32 field_uint32 = 3; // Test: uint32 basic type, offset: 0
|
||||
uint64 field_uint64 = 4; // Test: uint64 basic type, offset: 4
|
||||
|
||||
// Boolean type - test boolean serialization (1 byte in SSZ)
|
||||
bool field_bool = 5; // Test: boolean basic type, offset: 12
|
||||
|
||||
// Fixed-size bytes - test byte array
|
||||
bytes field_bytes32 = 8 [ (ethereum.eth.ext.ssz_size) = "32" ]; // Test: 32-byte array, offset: 13
|
||||
|
||||
// Nested container - test container nesting and field access
|
||||
FixedNestedContainer nested = 9; // Test: nested container navigation (8+32=40 bytes), offset: 45
|
||||
|
||||
// Vector type - test fixed-size array of basic elements
|
||||
repeated uint64 vector_field = 10 [ (ethereum.eth.ext.ssz_size) = "24" ]; // Test: Vector[24] of uint64 (24*8=192 bytes), offset: 85
|
||||
|
||||
// Additional bytes field - test field ordering and offset calculation
|
||||
bytes trailing_field = 11 [ (ethereum.eth.ext.ssz_size) = "56" ]; // Test: trailing field after vector, offset: 277
|
||||
}
|
||||
238
proto/ssz_query/ssz_query.ssz.go
Normal file
238
proto/ssz_query/ssz_query.ssz.go
Normal file
@@ -0,0 +1,238 @@
|
||||
// Code generated by fastssz. DO NOT EDIT.
|
||||
package ssz_query
|
||||
|
||||
import (
|
||||
ssz "github.com/prysmaticlabs/fastssz"
|
||||
)
|
||||
|
||||
// MarshalSSZ ssz marshals the FixedNestedContainer object
|
||||
func (f *FixedNestedContainer) MarshalSSZ() ([]byte, error) {
|
||||
return ssz.MarshalSSZ(f)
|
||||
}
|
||||
|
||||
// MarshalSSZTo ssz marshals the FixedNestedContainer object to a target array
|
||||
func (f *FixedNestedContainer) MarshalSSZTo(buf []byte) (dst []byte, err error) {
|
||||
dst = buf
|
||||
|
||||
// Field (0) 'Value1'
|
||||
dst = ssz.MarshalUint64(dst, f.Value1)
|
||||
|
||||
// Field (1) 'Value2'
|
||||
if size := len(f.Value2); size != 32 {
|
||||
err = ssz.ErrBytesLengthFn("--.Value2", size, 32)
|
||||
return
|
||||
}
|
||||
dst = append(dst, f.Value2...)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// UnmarshalSSZ ssz unmarshals the FixedNestedContainer object
|
||||
func (f *FixedNestedContainer) UnmarshalSSZ(buf []byte) error {
|
||||
var err error
|
||||
size := uint64(len(buf))
|
||||
if size != 40 {
|
||||
return ssz.ErrSize
|
||||
}
|
||||
|
||||
// Field (0) 'Value1'
|
||||
f.Value1 = ssz.UnmarshallUint64(buf[0:8])
|
||||
|
||||
// Field (1) 'Value2'
|
||||
if cap(f.Value2) == 0 {
|
||||
f.Value2 = make([]byte, 0, len(buf[8:40]))
|
||||
}
|
||||
f.Value2 = append(f.Value2, buf[8:40]...)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// SizeSSZ returns the ssz encoded size in bytes for the FixedNestedContainer object
|
||||
func (f *FixedNestedContainer) SizeSSZ() (size int) {
|
||||
size = 40
|
||||
return
|
||||
}
|
||||
|
||||
// HashTreeRoot ssz hashes the FixedNestedContainer object
|
||||
func (f *FixedNestedContainer) HashTreeRoot() ([32]byte, error) {
|
||||
return ssz.HashWithDefaultHasher(f)
|
||||
}
|
||||
|
||||
// HashTreeRootWith ssz hashes the FixedNestedContainer object with a hasher
|
||||
func (f *FixedNestedContainer) HashTreeRootWith(hh *ssz.Hasher) (err error) {
|
||||
indx := hh.Index()
|
||||
|
||||
// Field (0) 'Value1'
|
||||
hh.PutUint64(f.Value1)
|
||||
|
||||
// Field (1) 'Value2'
|
||||
if size := len(f.Value2); size != 32 {
|
||||
err = ssz.ErrBytesLengthFn("--.Value2", size, 32)
|
||||
return
|
||||
}
|
||||
hh.PutBytes(f.Value2)
|
||||
|
||||
hh.Merkleize(indx)
|
||||
return
|
||||
}
|
||||
|
||||
// MarshalSSZ ssz marshals the FixedTestContainer object
|
||||
func (f *FixedTestContainer) MarshalSSZ() ([]byte, error) {
|
||||
return ssz.MarshalSSZ(f)
|
||||
}
|
||||
|
||||
// MarshalSSZTo ssz marshals the FixedTestContainer object to a target array
|
||||
func (f *FixedTestContainer) MarshalSSZTo(buf []byte) (dst []byte, err error) {
|
||||
dst = buf
|
||||
|
||||
// Field (0) 'FieldUint32'
|
||||
dst = ssz.MarshalUint32(dst, f.FieldUint32)
|
||||
|
||||
// Field (1) 'FieldUint64'
|
||||
dst = ssz.MarshalUint64(dst, f.FieldUint64)
|
||||
|
||||
// Field (2) 'FieldBool'
|
||||
dst = ssz.MarshalBool(dst, f.FieldBool)
|
||||
|
||||
// Field (3) 'FieldBytes32'
|
||||
if size := len(f.FieldBytes32); size != 32 {
|
||||
err = ssz.ErrBytesLengthFn("--.FieldBytes32", size, 32)
|
||||
return
|
||||
}
|
||||
dst = append(dst, f.FieldBytes32...)
|
||||
|
||||
// Field (4) 'Nested'
|
||||
if f.Nested == nil {
|
||||
f.Nested = new(FixedNestedContainer)
|
||||
}
|
||||
if dst, err = f.Nested.MarshalSSZTo(dst); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Field (5) 'VectorField'
|
||||
if size := len(f.VectorField); size != 24 {
|
||||
err = ssz.ErrVectorLengthFn("--.VectorField", size, 24)
|
||||
return
|
||||
}
|
||||
for ii := 0; ii < 24; ii++ {
|
||||
dst = ssz.MarshalUint64(dst, f.VectorField[ii])
|
||||
}
|
||||
|
||||
// Field (6) 'TrailingField'
|
||||
if size := len(f.TrailingField); size != 56 {
|
||||
err = ssz.ErrBytesLengthFn("--.TrailingField", size, 56)
|
||||
return
|
||||
}
|
||||
dst = append(dst, f.TrailingField...)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// UnmarshalSSZ ssz unmarshals the FixedTestContainer object
|
||||
func (f *FixedTestContainer) UnmarshalSSZ(buf []byte) error {
|
||||
var err error
|
||||
size := uint64(len(buf))
|
||||
if size != 333 {
|
||||
return ssz.ErrSize
|
||||
}
|
||||
|
||||
// Field (0) 'FieldUint32'
|
||||
f.FieldUint32 = ssz.UnmarshallUint32(buf[0:4])
|
||||
|
||||
// Field (1) 'FieldUint64'
|
||||
f.FieldUint64 = ssz.UnmarshallUint64(buf[4:12])
|
||||
|
||||
// Field (2) 'FieldBool'
|
||||
f.FieldBool, err = ssz.DecodeBool(buf[12:13])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Field (3) 'FieldBytes32'
|
||||
if cap(f.FieldBytes32) == 0 {
|
||||
f.FieldBytes32 = make([]byte, 0, len(buf[13:45]))
|
||||
}
|
||||
f.FieldBytes32 = append(f.FieldBytes32, buf[13:45]...)
|
||||
|
||||
// Field (4) 'Nested'
|
||||
if f.Nested == nil {
|
||||
f.Nested = new(FixedNestedContainer)
|
||||
}
|
||||
if err = f.Nested.UnmarshalSSZ(buf[45:85]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Field (5) 'VectorField'
|
||||
f.VectorField = ssz.ExtendUint64(f.VectorField, 24)
|
||||
for ii := 0; ii < 24; ii++ {
|
||||
f.VectorField[ii] = ssz.UnmarshallUint64(buf[85:277][ii*8 : (ii+1)*8])
|
||||
}
|
||||
|
||||
// Field (6) 'TrailingField'
|
||||
if cap(f.TrailingField) == 0 {
|
||||
f.TrailingField = make([]byte, 0, len(buf[277:333]))
|
||||
}
|
||||
f.TrailingField = append(f.TrailingField, buf[277:333]...)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// SizeSSZ returns the ssz encoded size in bytes for the FixedTestContainer object
|
||||
func (f *FixedTestContainer) SizeSSZ() (size int) {
|
||||
size = 333
|
||||
return
|
||||
}
|
||||
|
||||
// HashTreeRoot ssz hashes the FixedTestContainer object
|
||||
func (f *FixedTestContainer) HashTreeRoot() ([32]byte, error) {
|
||||
return ssz.HashWithDefaultHasher(f)
|
||||
}
|
||||
|
||||
// HashTreeRootWith ssz hashes the FixedTestContainer object with a hasher
|
||||
func (f *FixedTestContainer) HashTreeRootWith(hh *ssz.Hasher) (err error) {
|
||||
indx := hh.Index()
|
||||
|
||||
// Field (0) 'FieldUint32'
|
||||
hh.PutUint32(f.FieldUint32)
|
||||
|
||||
// Field (1) 'FieldUint64'
|
||||
hh.PutUint64(f.FieldUint64)
|
||||
|
||||
// Field (2) 'FieldBool'
|
||||
hh.PutBool(f.FieldBool)
|
||||
|
||||
// Field (3) 'FieldBytes32'
|
||||
if size := len(f.FieldBytes32); size != 32 {
|
||||
err = ssz.ErrBytesLengthFn("--.FieldBytes32", size, 32)
|
||||
return
|
||||
}
|
||||
hh.PutBytes(f.FieldBytes32)
|
||||
|
||||
// Field (4) 'Nested'
|
||||
if err = f.Nested.HashTreeRootWith(hh); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Field (5) 'VectorField'
|
||||
{
|
||||
if size := len(f.VectorField); size != 24 {
|
||||
err = ssz.ErrVectorLengthFn("--.VectorField", size, 24)
|
||||
return
|
||||
}
|
||||
subIndx := hh.Index()
|
||||
for _, i := range f.VectorField {
|
||||
hh.AppendUint64(i)
|
||||
}
|
||||
hh.Merkleize(subIndx)
|
||||
}
|
||||
|
||||
// Field (6) 'TrailingField'
|
||||
if size := len(f.TrailingField); size != 56 {
|
||||
err = ssz.ErrBytesLengthFn("--.TrailingField", size, 56)
|
||||
return
|
||||
}
|
||||
hh.PutBytes(f.TrailingField)
|
||||
|
||||
hh.Merkleize(indx)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user