mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-07 22:54:17 -05:00
SSZ-QL: Handle List type & Populate the actual value dynamically (#15637)
* Add VariableTestContainer in ssz_query.proto * Add listInfo * Use errors.New for making an error with a static string literal * Add listInfo field when analyzing the List type * Persist the field order in the container * Add actualOffset and goFieldName at fieldInfo * Add PopulateFromValue function & update test runner * Handle slice of ssz object for marshalling * Add CalculateOffsetAndLength test * Add comments for better doc * Changelog :) * Apply reviews from Radek * Remove actualOffset and update offset field instead * Add Nested container of variable-sized for testing nested path * Fix offset adding logics: for variable-sized field, always add 4 instead of its fixed size * Fix multiple import issue --------- Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
@@ -39,6 +39,7 @@ ssz_gen_marshal(
|
||||
objs = [
|
||||
"FixedTestContainer",
|
||||
"FixedNestedContainer",
|
||||
"VariableTestContainer",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
216
proto/ssz_query/ssz_query.pb.go
generated
216
proto/ssz_query/ssz_query.pb.go
generated
@@ -172,6 +172,140 @@ func (x *FixedTestContainer) GetTrailingField() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
type VariableNestedContainer struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Value1 uint64 `protobuf:"varint,1,opt,name=value1,proto3" json:"value1,omitempty"`
|
||||
FieldListUint64 []uint64 `protobuf:"varint,2,rep,packed,name=field_list_uint64,json=fieldListUint64,proto3" json:"field_list_uint64,omitempty" ssz-max:"100"`
|
||||
}
|
||||
|
||||
func (x *VariableNestedContainer) Reset() {
|
||||
*x = VariableNestedContainer{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_ssz_query_ssz_query_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *VariableNestedContainer) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*VariableNestedContainer) ProtoMessage() {}
|
||||
|
||||
func (x *VariableNestedContainer) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_ssz_query_ssz_query_proto_msgTypes[2]
|
||||
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 VariableNestedContainer.ProtoReflect.Descriptor instead.
|
||||
func (*VariableNestedContainer) Descriptor() ([]byte, []int) {
|
||||
return file_proto_ssz_query_ssz_query_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *VariableNestedContainer) GetValue1() uint64 {
|
||||
if x != nil {
|
||||
return x.Value1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *VariableNestedContainer) GetFieldListUint64() []uint64 {
|
||||
if x != nil {
|
||||
return x.FieldListUint64
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type VariableTestContainer struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
LeadingField []byte `protobuf:"bytes,1,opt,name=leading_field,json=leadingField,proto3" json:"leading_field,omitempty" ssz-size:"32"`
|
||||
FieldListUint64 []uint64 `protobuf:"varint,2,rep,packed,name=field_list_uint64,json=fieldListUint64,proto3" json:"field_list_uint64,omitempty" ssz-max:"2048"`
|
||||
FieldListContainer []*FixedNestedContainer `protobuf:"bytes,3,rep,name=field_list_container,json=fieldListContainer,proto3" json:"field_list_container,omitempty" ssz-max:"128"`
|
||||
Nested *VariableNestedContainer `protobuf:"bytes,4,opt,name=nested,proto3" json:"nested,omitempty"`
|
||||
TrailingField []byte `protobuf:"bytes,5,opt,name=trailing_field,json=trailingField,proto3" json:"trailing_field,omitempty" ssz-size:"56"`
|
||||
}
|
||||
|
||||
func (x *VariableTestContainer) Reset() {
|
||||
*x = VariableTestContainer{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_ssz_query_ssz_query_proto_msgTypes[3]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *VariableTestContainer) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*VariableTestContainer) ProtoMessage() {}
|
||||
|
||||
func (x *VariableTestContainer) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_ssz_query_ssz_query_proto_msgTypes[3]
|
||||
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 VariableTestContainer.ProtoReflect.Descriptor instead.
|
||||
func (*VariableTestContainer) Descriptor() ([]byte, []int) {
|
||||
return file_proto_ssz_query_ssz_query_proto_rawDescGZIP(), []int{3}
|
||||
}
|
||||
|
||||
func (x *VariableTestContainer) GetLeadingField() []byte {
|
||||
if x != nil {
|
||||
return x.LeadingField
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *VariableTestContainer) GetFieldListUint64() []uint64 {
|
||||
if x != nil {
|
||||
return x.FieldListUint64
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *VariableTestContainer) GetFieldListContainer() []*FixedNestedContainer {
|
||||
if x != nil {
|
||||
return x.FieldListContainer
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *VariableTestContainer) GetNested() *VariableNestedContainer {
|
||||
if x != nil {
|
||||
return x.Nested
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *VariableTestContainer) 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{
|
||||
@@ -204,11 +338,37 @@ var file_proto_ssz_query_ssz_query_proto_rawDesc = []byte{
|
||||
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,
|
||||
0x46, 0x69, 0x65, 0x6c, 0x64, 0x22, 0x66, 0x0a, 0x17, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c,
|
||||
0x65, 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, 0x33, 0x0a, 0x11, 0x66, 0x69, 0x65, 0x6c,
|
||||
0x64, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x5f, 0x75, 0x69, 0x6e, 0x74, 0x36, 0x34, 0x18, 0x02, 0x20,
|
||||
0x03, 0x28, 0x04, 0x42, 0x07, 0x92, 0xb5, 0x18, 0x03, 0x31, 0x30, 0x30, 0x52, 0x0f, 0x66, 0x69,
|
||||
0x65, 0x6c, 0x64, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x69, 0x6e, 0x74, 0x36, 0x34, 0x22, 0xc1, 0x02,
|
||||
0x0a, 0x15, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x54, 0x65, 0x73, 0x74, 0x43, 0x6f,
|
||||
0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x12, 0x2b, 0x0a, 0x0d, 0x6c, 0x65, 0x61, 0x64, 0x69,
|
||||
0x6e, 0x67, 0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x06,
|
||||
0x8a, 0xb5, 0x18, 0x02, 0x33, 0x32, 0x52, 0x0c, 0x6c, 0x65, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x46,
|
||||
0x69, 0x65, 0x6c, 0x64, 0x12, 0x34, 0x0a, 0x11, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x5f, 0x6c, 0x69,
|
||||
0x73, 0x74, 0x5f, 0x75, 0x69, 0x6e, 0x74, 0x36, 0x34, 0x18, 0x02, 0x20, 0x03, 0x28, 0x04, 0x42,
|
||||
0x08, 0x92, 0xb5, 0x18, 0x04, 0x32, 0x30, 0x34, 0x38, 0x52, 0x0f, 0x66, 0x69, 0x65, 0x6c, 0x64,
|
||||
0x4c, 0x69, 0x73, 0x74, 0x55, 0x69, 0x6e, 0x74, 0x36, 0x34, 0x12, 0x5a, 0x0a, 0x14, 0x66, 0x69,
|
||||
0x65, 0x6c, 0x64, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e,
|
||||
0x65, 0x72, 0x18, 0x03, 0x20, 0x03, 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, 0x42, 0x07, 0x92, 0xb5, 0x18, 0x03, 0x31,
|
||||
0x32, 0x38, 0x52, 0x12, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6e,
|
||||
0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x12, 0x3a, 0x0a, 0x06, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64,
|
||||
0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x73, 0x73, 0x7a, 0x5f, 0x71, 0x75, 0x65,
|
||||
0x72, 0x79, 0x2e, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x4e, 0x65, 0x73, 0x74, 0x65,
|
||||
0x64, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x52, 0x06, 0x6e, 0x65, 0x73, 0x74,
|
||||
0x65, 0x64, 0x12, 0x2d, 0x0a, 0x0e, 0x74, 0x72, 0x61, 0x69, 0x6c, 0x69, 0x6e, 0x67, 0x5f, 0x66,
|
||||
0x69, 0x65, 0x6c, 0x64, 0x18, 0x05, 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 (
|
||||
@@ -223,18 +383,22 @@ func file_proto_ssz_query_ssz_query_proto_rawDescGZIP() []byte {
|
||||
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_msgTypes = make([]protoimpl.MessageInfo, 4)
|
||||
var file_proto_ssz_query_ssz_query_proto_goTypes = []interface{}{
|
||||
(*FixedNestedContainer)(nil), // 0: ssz_query.FixedNestedContainer
|
||||
(*FixedTestContainer)(nil), // 1: ssz_query.FixedTestContainer
|
||||
(*FixedNestedContainer)(nil), // 0: ssz_query.FixedNestedContainer
|
||||
(*FixedTestContainer)(nil), // 1: ssz_query.FixedTestContainer
|
||||
(*VariableNestedContainer)(nil), // 2: ssz_query.VariableNestedContainer
|
||||
(*VariableTestContainer)(nil), // 3: ssz_query.VariableTestContainer
|
||||
}
|
||||
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
|
||||
0, // 1: ssz_query.VariableTestContainer.field_list_container:type_name -> ssz_query.FixedNestedContainer
|
||||
2, // 2: ssz_query.VariableTestContainer.nested:type_name -> ssz_query.VariableNestedContainer
|
||||
3, // [3:3] is the sub-list for method output_type
|
||||
3, // [3:3] is the sub-list for method input_type
|
||||
3, // [3:3] is the sub-list for extension type_name
|
||||
3, // [3:3] is the sub-list for extension extendee
|
||||
0, // [0:3] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_proto_ssz_query_ssz_query_proto_init() }
|
||||
@@ -267,6 +431,30 @@ func file_proto_ssz_query_ssz_query_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_proto_ssz_query_ssz_query_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*VariableNestedContainer); 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[3].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*VariableTestContainer); 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{
|
||||
@@ -274,7 +462,7 @@ func file_proto_ssz_query_ssz_query_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_proto_ssz_query_ssz_query_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 2,
|
||||
NumMessages: 4,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
|
||||
@@ -41,3 +41,35 @@ message FixedTestContainer {
|
||||
// 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
|
||||
}
|
||||
|
||||
// ===== VARIABLE-SIZE TEST CONTAINERS =====
|
||||
|
||||
// VariableNestedContainer - nested container for testing nested field access
|
||||
// Tests: nested container navigation, field offset calculations within nested structures
|
||||
message VariableNestedContainer {
|
||||
uint64 value1 = 1;
|
||||
repeated uint64 field_list_uint64 = 2 [ (ethereum.eth.ext.ssz_max) = "100" ];
|
||||
}
|
||||
|
||||
// VariableTestContainer - comprehensive variable-size container for SSZ query testing
|
||||
// Tests: Variable-size lists, offsets in variable containers, mixed fixed/variable fields
|
||||
message VariableTestContainer {
|
||||
// Fixed-size leading field - test fixed field before variable fields
|
||||
// Acts as a baseline to verify offset calculations start correctly
|
||||
bytes leading_field = 1 [ (ethereum.eth.ext.ssz_size) = "32" ]; // Test: fixed 32-byte field at start, offset: 0
|
||||
|
||||
// Variable-size list of basic type - test list with primitive elements
|
||||
// SSZ uses 4-byte offset pointer, actual data stored after all fixed fields
|
||||
repeated uint64 field_list_uint64 = 2 [ (ethereum.eth.ext.ssz_max) = "2048" ]; // Test: List[uint64, 2048] (max 2048 elements)
|
||||
|
||||
// Variable-size list of containers - test list with composite elements
|
||||
// Each container is fixed-size (40 bytes), but list itself is variable
|
||||
repeated FixedNestedContainer field_list_container = 3 [ (ethereum.eth.ext.ssz_max) = "128" ]; // Test: List[FixedNestedContainer, 128]
|
||||
|
||||
// Variable nested container - test nested container access within variable container
|
||||
VariableNestedContainer nested = 4;
|
||||
|
||||
// Fixed-size trailing field - test fixed field after variable fields
|
||||
// Verifies correct offset calculation after variable-size fields
|
||||
bytes trailing_field = 5 [ (ethereum.eth.ext.ssz_size) = "56" ]; // Test: fixed 56-byte field at end, offset: 32 + 4 + 4 + 4 = 44
|
||||
}
|
||||
|
||||
@@ -236,3 +236,348 @@ func (f *FixedTestContainer) HashTreeRootWith(hh *ssz.Hasher) (err error) {
|
||||
hh.Merkleize(indx)
|
||||
return
|
||||
}
|
||||
|
||||
// MarshalSSZ ssz marshals the VariableNestedContainer object
|
||||
func (v *VariableNestedContainer) MarshalSSZ() ([]byte, error) {
|
||||
return ssz.MarshalSSZ(v)
|
||||
}
|
||||
|
||||
// MarshalSSZTo ssz marshals the VariableNestedContainer object to a target array
|
||||
func (v *VariableNestedContainer) MarshalSSZTo(buf []byte) (dst []byte, err error) {
|
||||
dst = buf
|
||||
offset := int(12)
|
||||
|
||||
// Field (0) 'Value1'
|
||||
dst = ssz.MarshalUint64(dst, v.Value1)
|
||||
|
||||
// Offset (1) 'FieldListUint64'
|
||||
dst = ssz.WriteOffset(dst, offset)
|
||||
offset += len(v.FieldListUint64) * 8
|
||||
|
||||
// Field (1) 'FieldListUint64'
|
||||
if size := len(v.FieldListUint64); size > 100 {
|
||||
err = ssz.ErrListTooBigFn("--.FieldListUint64", size, 100)
|
||||
return
|
||||
}
|
||||
for ii := 0; ii < len(v.FieldListUint64); ii++ {
|
||||
dst = ssz.MarshalUint64(dst, v.FieldListUint64[ii])
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// UnmarshalSSZ ssz unmarshals the VariableNestedContainer object
|
||||
func (v *VariableNestedContainer) UnmarshalSSZ(buf []byte) error {
|
||||
var err error
|
||||
size := uint64(len(buf))
|
||||
if size < 12 {
|
||||
return ssz.ErrSize
|
||||
}
|
||||
|
||||
tail := buf
|
||||
var o1 uint64
|
||||
|
||||
// Field (0) 'Value1'
|
||||
v.Value1 = ssz.UnmarshallUint64(buf[0:8])
|
||||
|
||||
// Offset (1) 'FieldListUint64'
|
||||
if o1 = ssz.ReadOffset(buf[8:12]); o1 > size {
|
||||
return ssz.ErrOffset
|
||||
}
|
||||
|
||||
if o1 != 12 {
|
||||
return ssz.ErrInvalidVariableOffset
|
||||
}
|
||||
|
||||
// Field (1) 'FieldListUint64'
|
||||
{
|
||||
buf = tail[o1:]
|
||||
num, err := ssz.DivideInt2(len(buf), 8, 100)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.FieldListUint64 = ssz.ExtendUint64(v.FieldListUint64, num)
|
||||
for ii := 0; ii < num; ii++ {
|
||||
v.FieldListUint64[ii] = ssz.UnmarshallUint64(buf[ii*8 : (ii+1)*8])
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// SizeSSZ returns the ssz encoded size in bytes for the VariableNestedContainer object
|
||||
func (v *VariableNestedContainer) SizeSSZ() (size int) {
|
||||
size = 12
|
||||
|
||||
// Field (1) 'FieldListUint64'
|
||||
size += len(v.FieldListUint64) * 8
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// HashTreeRoot ssz hashes the VariableNestedContainer object
|
||||
func (v *VariableNestedContainer) HashTreeRoot() ([32]byte, error) {
|
||||
return ssz.HashWithDefaultHasher(v)
|
||||
}
|
||||
|
||||
// HashTreeRootWith ssz hashes the VariableNestedContainer object with a hasher
|
||||
func (v *VariableNestedContainer) HashTreeRootWith(hh *ssz.Hasher) (err error) {
|
||||
indx := hh.Index()
|
||||
|
||||
// Field (0) 'Value1'
|
||||
hh.PutUint64(v.Value1)
|
||||
|
||||
// Field (1) 'FieldListUint64'
|
||||
{
|
||||
if size := len(v.FieldListUint64); size > 100 {
|
||||
err = ssz.ErrListTooBigFn("--.FieldListUint64", size, 100)
|
||||
return
|
||||
}
|
||||
subIndx := hh.Index()
|
||||
for _, i := range v.FieldListUint64 {
|
||||
hh.AppendUint64(i)
|
||||
}
|
||||
hh.FillUpTo32()
|
||||
|
||||
numItems := uint64(len(v.FieldListUint64))
|
||||
hh.MerkleizeWithMixin(subIndx, numItems, ssz.CalculateLimit(100, numItems, 8))
|
||||
}
|
||||
|
||||
hh.Merkleize(indx)
|
||||
return
|
||||
}
|
||||
|
||||
// MarshalSSZ ssz marshals the VariableTestContainer object
|
||||
func (v *VariableTestContainer) MarshalSSZ() ([]byte, error) {
|
||||
return ssz.MarshalSSZ(v)
|
||||
}
|
||||
|
||||
// MarshalSSZTo ssz marshals the VariableTestContainer object to a target array
|
||||
func (v *VariableTestContainer) MarshalSSZTo(buf []byte) (dst []byte, err error) {
|
||||
dst = buf
|
||||
offset := int(100)
|
||||
|
||||
// Field (0) 'LeadingField'
|
||||
if size := len(v.LeadingField); size != 32 {
|
||||
err = ssz.ErrBytesLengthFn("--.LeadingField", size, 32)
|
||||
return
|
||||
}
|
||||
dst = append(dst, v.LeadingField...)
|
||||
|
||||
// Offset (1) 'FieldListUint64'
|
||||
dst = ssz.WriteOffset(dst, offset)
|
||||
offset += len(v.FieldListUint64) * 8
|
||||
|
||||
// Offset (2) 'FieldListContainer'
|
||||
dst = ssz.WriteOffset(dst, offset)
|
||||
offset += len(v.FieldListContainer) * 40
|
||||
|
||||
// Offset (3) 'Nested'
|
||||
dst = ssz.WriteOffset(dst, offset)
|
||||
if v.Nested == nil {
|
||||
v.Nested = new(VariableNestedContainer)
|
||||
}
|
||||
offset += v.Nested.SizeSSZ()
|
||||
|
||||
// Field (4) 'TrailingField'
|
||||
if size := len(v.TrailingField); size != 56 {
|
||||
err = ssz.ErrBytesLengthFn("--.TrailingField", size, 56)
|
||||
return
|
||||
}
|
||||
dst = append(dst, v.TrailingField...)
|
||||
|
||||
// Field (1) 'FieldListUint64'
|
||||
if size := len(v.FieldListUint64); size > 2048 {
|
||||
err = ssz.ErrListTooBigFn("--.FieldListUint64", size, 2048)
|
||||
return
|
||||
}
|
||||
for ii := 0; ii < len(v.FieldListUint64); ii++ {
|
||||
dst = ssz.MarshalUint64(dst, v.FieldListUint64[ii])
|
||||
}
|
||||
|
||||
// Field (2) 'FieldListContainer'
|
||||
if size := len(v.FieldListContainer); size > 128 {
|
||||
err = ssz.ErrListTooBigFn("--.FieldListContainer", size, 128)
|
||||
return
|
||||
}
|
||||
for ii := 0; ii < len(v.FieldListContainer); ii++ {
|
||||
if dst, err = v.FieldListContainer[ii].MarshalSSZTo(dst); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Field (3) 'Nested'
|
||||
if dst, err = v.Nested.MarshalSSZTo(dst); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// UnmarshalSSZ ssz unmarshals the VariableTestContainer object
|
||||
func (v *VariableTestContainer) UnmarshalSSZ(buf []byte) error {
|
||||
var err error
|
||||
size := uint64(len(buf))
|
||||
if size < 100 {
|
||||
return ssz.ErrSize
|
||||
}
|
||||
|
||||
tail := buf
|
||||
var o1, o2, o3 uint64
|
||||
|
||||
// Field (0) 'LeadingField'
|
||||
if cap(v.LeadingField) == 0 {
|
||||
v.LeadingField = make([]byte, 0, len(buf[0:32]))
|
||||
}
|
||||
v.LeadingField = append(v.LeadingField, buf[0:32]...)
|
||||
|
||||
// Offset (1) 'FieldListUint64'
|
||||
if o1 = ssz.ReadOffset(buf[32:36]); o1 > size {
|
||||
return ssz.ErrOffset
|
||||
}
|
||||
|
||||
if o1 != 100 {
|
||||
return ssz.ErrInvalidVariableOffset
|
||||
}
|
||||
|
||||
// Offset (2) 'FieldListContainer'
|
||||
if o2 = ssz.ReadOffset(buf[36:40]); o2 > size || o1 > o2 {
|
||||
return ssz.ErrOffset
|
||||
}
|
||||
|
||||
// Offset (3) 'Nested'
|
||||
if o3 = ssz.ReadOffset(buf[40:44]); o3 > size || o2 > o3 {
|
||||
return ssz.ErrOffset
|
||||
}
|
||||
|
||||
// Field (4) 'TrailingField'
|
||||
if cap(v.TrailingField) == 0 {
|
||||
v.TrailingField = make([]byte, 0, len(buf[44:100]))
|
||||
}
|
||||
v.TrailingField = append(v.TrailingField, buf[44:100]...)
|
||||
|
||||
// Field (1) 'FieldListUint64'
|
||||
{
|
||||
buf = tail[o1:o2]
|
||||
num, err := ssz.DivideInt2(len(buf), 8, 2048)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.FieldListUint64 = ssz.ExtendUint64(v.FieldListUint64, num)
|
||||
for ii := 0; ii < num; ii++ {
|
||||
v.FieldListUint64[ii] = ssz.UnmarshallUint64(buf[ii*8 : (ii+1)*8])
|
||||
}
|
||||
}
|
||||
|
||||
// Field (2) 'FieldListContainer'
|
||||
{
|
||||
buf = tail[o2:o3]
|
||||
num, err := ssz.DivideInt2(len(buf), 40, 128)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.FieldListContainer = make([]*FixedNestedContainer, num)
|
||||
for ii := 0; ii < num; ii++ {
|
||||
if v.FieldListContainer[ii] == nil {
|
||||
v.FieldListContainer[ii] = new(FixedNestedContainer)
|
||||
}
|
||||
if err = v.FieldListContainer[ii].UnmarshalSSZ(buf[ii*40 : (ii+1)*40]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Field (3) 'Nested'
|
||||
{
|
||||
buf = tail[o3:]
|
||||
if v.Nested == nil {
|
||||
v.Nested = new(VariableNestedContainer)
|
||||
}
|
||||
if err = v.Nested.UnmarshalSSZ(buf); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// SizeSSZ returns the ssz encoded size in bytes for the VariableTestContainer object
|
||||
func (v *VariableTestContainer) SizeSSZ() (size int) {
|
||||
size = 100
|
||||
|
||||
// Field (1) 'FieldListUint64'
|
||||
size += len(v.FieldListUint64) * 8
|
||||
|
||||
// Field (2) 'FieldListContainer'
|
||||
size += len(v.FieldListContainer) * 40
|
||||
|
||||
// Field (3) 'Nested'
|
||||
if v.Nested == nil {
|
||||
v.Nested = new(VariableNestedContainer)
|
||||
}
|
||||
size += v.Nested.SizeSSZ()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// HashTreeRoot ssz hashes the VariableTestContainer object
|
||||
func (v *VariableTestContainer) HashTreeRoot() ([32]byte, error) {
|
||||
return ssz.HashWithDefaultHasher(v)
|
||||
}
|
||||
|
||||
// HashTreeRootWith ssz hashes the VariableTestContainer object with a hasher
|
||||
func (v *VariableTestContainer) HashTreeRootWith(hh *ssz.Hasher) (err error) {
|
||||
indx := hh.Index()
|
||||
|
||||
// Field (0) 'LeadingField'
|
||||
if size := len(v.LeadingField); size != 32 {
|
||||
err = ssz.ErrBytesLengthFn("--.LeadingField", size, 32)
|
||||
return
|
||||
}
|
||||
hh.PutBytes(v.LeadingField)
|
||||
|
||||
// Field (1) 'FieldListUint64'
|
||||
{
|
||||
if size := len(v.FieldListUint64); size > 2048 {
|
||||
err = ssz.ErrListTooBigFn("--.FieldListUint64", size, 2048)
|
||||
return
|
||||
}
|
||||
subIndx := hh.Index()
|
||||
for _, i := range v.FieldListUint64 {
|
||||
hh.AppendUint64(i)
|
||||
}
|
||||
hh.FillUpTo32()
|
||||
|
||||
numItems := uint64(len(v.FieldListUint64))
|
||||
hh.MerkleizeWithMixin(subIndx, numItems, ssz.CalculateLimit(2048, numItems, 8))
|
||||
}
|
||||
|
||||
// Field (2) 'FieldListContainer'
|
||||
{
|
||||
subIndx := hh.Index()
|
||||
num := uint64(len(v.FieldListContainer))
|
||||
if num > 128 {
|
||||
err = ssz.ErrIncorrectListSize
|
||||
return
|
||||
}
|
||||
for _, elem := range v.FieldListContainer {
|
||||
if err = elem.HashTreeRootWith(hh); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
hh.MerkleizeWithMixin(subIndx, num, 128)
|
||||
}
|
||||
|
||||
// Field (3) 'Nested'
|
||||
if err = v.Nested.HashTreeRootWith(hh); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Field (4) 'TrailingField'
|
||||
if size := len(v.TrailingField); size != 56 {
|
||||
err = ssz.ErrBytesLengthFn("--.TrailingField", size, 56)
|
||||
return
|
||||
}
|
||||
hh.PutBytes(v.TrailingField)
|
||||
|
||||
hh.Merkleize(indx)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user