-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ssz): More updates #1654
feat(ssz): More updates #1654
Conversation
Warning Rate limit exceeded@itsdevbear has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 8 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe recent updates refactor and optimize the SSZ merkleization process, adding systematic vector and list handling while enhancing the SSZObject interface to include SSZ marshalling. Key functions are renamed for consistency, improving readability and usability within the merkleizer framework. Changes
Poem
Tip Early access features
Note:
TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1654 +/- ##
==========================================
- Coverage 22.99% 22.38% -0.61%
==========================================
Files 268 270 +2
Lines 11840 11885 +45
Branches 18 18
==========================================
- Hits 2723 2661 -62
- Misses 8989 9104 +115
+ Partials 128 120 -8
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (8)
- mod/primitives/pkg/bytes/b32.go (1 hunks)
- mod/primitives/pkg/ssz/interfaces.go (2 hunks)
- mod/primitives/pkg/ssz/merkleizer/interfaces.go (1 hunks)
- mod/primitives/pkg/ssz/merkleizer/merkleizer.go (4 hunks)
- mod/primitives/pkg/ssz/merkleizer/merkleizer_test.go (2 hunks)
- mod/primitives/pkg/ssz/merkleizer/merkleizer_vector.go (1 hunks)
- mod/primitives/pkg/ssz/merkleizer/types.go (1 hunks)
- mod/primitives/pkg/ssz/vector.go (2 hunks)
Additional comments not posted (11)
mod/primitives/pkg/ssz/merkleizer/types.go (1)
31-32
: LGTM!The addition of the
MarshalSSZ
method to theSSZObject
interface is consistent with the objective of enhancing SSZ marshaling functionalities.mod/primitives/pkg/ssz/merkleizer/interfaces.go (1)
28-30
: LGTM!The renaming of the methods
MerkleizeVecBasic
toMerkleizeVectorBasic
andMerkleizeVecComposite
toMerkleizeVectorComposite
improves consistency in method naming.mod/primitives/pkg/ssz/interfaces.go (1)
37-37
: LGTM!The renaming of the methods
MerkleizeVecBasic
toMerkleizeVectorBasic
andMerkleizeVecComposite
toMerkleizeVectorComposite
improves consistency in method naming.Also applies to: 47-47
mod/primitives/pkg/ssz/merkleizer/merkleizer_vector.go (2)
23-33
: LGTM!The function
MerkleizeVectorBasic
correctly packs the input vector and calls theMerkleize
function.However, ensure that the
Merkleize
function is correctly implemented.
35-53
: LGTM!The function
MerkleizeVectorComposite
correctly computes the hash tree root for each element in the input vector and calls theMerkleize
function.However, ensure that the
Merkleize
function is correctly implemented.Verification successful
LGTM!
The function
MerkleizeVectorComposite
correctly computes the hash tree root for each element in the input vector and calls theMerkleize
function. TheMerkleize
function itself is correctly implemented, handling different cases for padding chunks and returning the appropriate root hash.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementation of the `Merkleize` function. # Test: Search for the `Merkleize` function implementation. Expect: Correct implementation. rg --type go --pcre2 --multiline 'func \(m \*merkleizer\[RootT, T\]\) Merkleize\('Length of output: 174
Script:
#!/bin/bash # Description: Extract the full implementation of the `Merkleize` function. # Extract the `Merkleize` function implementation from the identified file. ast-grep --lang go --pattern $'func (m *merkleizer[RootT, T]) Merkleize($$_) ($$_) { $$$ }' mod/primitives/pkg/ssz/merkleizer/merkleizer.goLength of output: 142
Script:
#!/bin/bash # Description: Extract the `Merkleize` function implementation with surrounding context for better accuracy. # Search for the `Merkleize` function definition and extract surrounding lines to capture the full implementation. rg --type go --context 20 'func (m *merkleizer[RootT, T]) Merkleize(' mod/primitives/pkg/ssz/merkleizer/merkleizer.goLength of output: 252
Script:
#!/bin/bash # Description: Extract the `Merkleize` function implementation with surrounding context for better accuracy. # Search for the `Merkleize` function definition and extract surrounding lines to capture the full implementation. rg --type go --context 20 'func \(m \*merkleizer\[RootT, T\]\) Merkleize\(' mod/primitives/pkg/ssz/merkleizer/merkleizer.goLength of output: 1369
Script:
#!/bin/bash # Description: Extract the complete `Merkleize` function implementation with more surrounding context. # Search for the `Merkleize` function definition and extract more surrounding lines to capture the full implementation. rg --type go --context 40 'func \(m \*merkleizer\[RootT, T\]\) Merkleize\(' mod/primitives/pkg/ssz/merkleizer/merkleizer.goLength of output: 2285
Script:
#!/bin/bash # Description: Extract the complete `Merkleize` function implementation with more surrounding context. # Search for the `Merkleize` function definition and extract more surrounding lines to capture the full implementation. rg --type go --context 60 'func \(m \*merkleizer\[RootT, T\]\) Merkleize\(' mod/primitives/pkg/ssz/merkleizer/merkleizer.goLength of output: 3404
mod/primitives/pkg/bytes/b32.go (1)
68-71
: LGTM!The function
MarshalSSZ
correctly implements SSZ marshaling for theB32
type.mod/primitives/pkg/ssz/merkleizer/merkleizer_test.go (1)
51-89
: Remove commented-out code.The commented-out code segments related to the
BasicContainer
type should be removed for cleanliness.- // BasicContainer represents a container of two basic items. - // type BasicContainer[SpecT any] struct { - // Item1 BasicItem - // Item2 BasicItem - // } - // SizeSSZ returns the size of the container in bytes. - // func (c *BasicContainer[SpecT]) SizeSSZ() int { - // return c.Item1.SizeSSZ() + c.Item2.SizeSSZ() - // } - // HashTreeRoot computes the Merkle root of the container using SSZ hashing - // rules. - // func (c *BasicContainer[SpecT]) HashTreeRoot() ([32]byte, error) { - // merkleizer := merkleizer.New[[32]byte, common.Root]() - // return merkleizer.MerkleizeContainer(c) - // } - // TestBasicItemMerkleization tests the Merkleization of a basic item. - // func TestBasicContainerMerkleization(t *testing.T) { - // container := BasicContainer[any]{ - // Item1: BasicItem(1), - // Item2: BasicItem(2), - // } - // // Merkleize the container. - // actualRoot, err := container.HashTreeRoot() - // require.NoError(t, err) - // // Manually compute our own root, using our merkle tree knowledge. - // htr1, err := container.Item1.HashTreeRoot() - // require.NoError(t, err) - // htr2, err := container.Item2.HashTreeRoot() - // require.NoError(t, err) - // expectedRoot := sha256.Sum256(append(htr1[:], htr2[:]...)) - // // Should match - // require.Equal(t, expectedRoot, actualRoot) - // }mod/primitives/pkg/ssz/vector.go (2)
53-53
: LGTM!The change to call
MerkleizeVectorBasic
aligns with the renaming for consistency.
108-108
: LGTM!The change to call
MerkleizeVectorComposite
aligns with the renaming for consistency.mod/primitives/pkg/ssz/merkleizer/merkleizer.go (2)
48-48
: LGTM!The simplification of
NewRootHasher
initialization improves readability.
60-60
: LGTM!The change to call
MerkleizeVectorBasic
aligns with the renaming for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (5)
- mod/primitives/pkg/ssz/merkleizer/merkelizer_list.go (1 hunks)
- mod/primitives/pkg/ssz/merkleizer/merkleizer.go (5 hunks)
- mod/primitives/pkg/ssz/merkleizer/merkleizer_vector.go (1 hunks)
- mod/primitives/pkg/ssz/merkleizer/pack.go (1 hunks)
- mod/primitives/pkg/ssz/vector.go (3 hunks)
Additional comments not posted (14)
mod/primitives/pkg/ssz/merkleizer/merkleizer_vector.go (2)
23-35
: LGTM!The
MerkleizeVectorBasic
function correctly implements the SSZ merkleization algorithm for a vector of basic types.
37-55
: LGTM!The
MerkleizeVectorComposite
function correctly implements the SSZ merkleization algorithm for a vector of composite types.mod/primitives/pkg/ssz/merkleizer/merkelizer_list.go (2)
29-35
: LGTM!The
MerkleizeListBasic
function correctly implements the SSZ merkleization algorithm for a list of basic types. The changes improve the usage of thepack
function and handle the effective limit correctly.
Line range hint
37-67
: LGTM!The
MerkleizeListComposite
function correctly implements the SSZ merkleization algorithm for a list of composite types.mod/primitives/pkg/ssz/merkleizer/pack.go (2)
25-50
: LGTM!The
pack
function correctly implements the SSZ packing algorithm for a list of SSZ-marshallable elements.
52-65
: LGTM!The
chunkifyBytes
function correctly implements the SSZ chunking algorithm for a byte slice.mod/primitives/pkg/ssz/merkleizer/merkleizer.go (4)
47-47
: LGTM!The simplification of
rootHasher
initialization improves readability and maintainability.
59-59
: LGTM!The change promotes code reuse and simplifies the function.
108-108
: LGTM!The change improves error handling and the function's robustness.
108-108
: LGTM!The refactoring improves the performance of the function.
mod/primitives/pkg/ssz/vector.go (4)
53-58
: LGTM!The function reuses the
ChunkCountBasicList
function for lists and passes the length of the vector as the max capacity.
65-65
: LGTM!The change improves consistency in naming and promotes code reuse.
115-115
: LGTM!The change improves consistency in naming and promotes code reuse.
115-115
: LGTM!The function correctly checks if the vector is of fixed size by calling
IsFixed
on the element type.
// packBits packs a list of SSZ-marshallable bitlists into a single byte slice. | ||
func packBits[ | ||
RootT ~[32]byte, | ||
T interface { | ||
MarshalSSZ() ([]byte, error) | ||
}, | ||
](values []T) ([]RootT, error) { | ||
// pack_bits(bits): Given the bits of bitlist or bitvector, get | ||
// bitfield_bytes by packing them in bytes and aligning to the start. | ||
// The length-delimiting bit for bitlists is excluded. Then return pack | ||
// (bitfield_bytes). | ||
panic("not yet implemented") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unimplemented function: packBits
.
The packBits
function is not yet implemented and contains a panic statement. The comments provide a detailed description of the intended functionality.
Do you want me to implement this function or open a GitHub issue to track this task?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (2)
- mod/primitives/pkg/ssz/list.go (4 hunks)
- mod/primitives/pkg/ssz/vector.go (5 hunks)
Additional comments not posted (39)
mod/primitives/pkg/ssz/vector.go (21)
35-37
: Use of Generic TypeB
for VectorBasicThe change from
T
toB
for basic types inVectorBasic
improves clarity and consistency in naming conventions. This aligns with the SSZ specification and enhances readability.
39-41
: Deprecation Notice forVectorBasicFromElements
The TODO comment indicates that this function will be deprecated once the transition from Fastssz is complete. Ensure that this deprecation is tracked and handled appropriately.
44-47
: Efficient Calculation of Size inSizeSSZ
The method correctly calculates the size of the vector in bytes by multiplying the size of a single element by the length of the vector. This approach is efficient and straightforward.
50-52
: Fixed Size Check inIsFixed
The method correctly returns
true
indicating thatVectorBasic
is of fixed size. This is consistent with SSZ specifications for basic vectors.
55-58
: Correct Calculation of Chunk Count inChunkCount
The method correctly calculates the number of chunks by dividing the total size by the root length and rounding up. This ensures accurate chunking for merkleization.
61-62
: Accurate Length Calculation inN
The method correctly returns the length of the vector, which is essential for SSZ operations.
67-70
: Merkle Root Calculation with Custom Merkleizer inHashTreeRootWith
The method correctly delegates the merkle root calculation to the provided merkleizer, ensuring flexibility and reusability.
74-76
: Simplified Merkle Root Calculation inHashTreeRoot
The method correctly creates a new merkleizer and calculates the merkle root, simplifying the process for the user.
80-82
: Efficient SSZ Marshaling inMarshalSSZTo
The method correctly uses the serializer to marshal the vector into SSZ format, ensuring efficient serialization.
85-87
: Efficient SSZ Marshaling inMarshalSSZ
The method correctly delegates to
MarshalSSZTo
, ensuring consistent and efficient SSZ serialization.
90-91
: SSZ Unmarshaling inNewFromSSZ
The method correctly uses the serializer to unmarshal the vector from SSZ format, ensuring accurate deserialization.
109-113
: Fixed Size Check inIsFixed
The method correctly checks if the composite type is fixed size by delegating to the
IsFixed
method of the element type. This ensures accurate size determination.
116-118
: Accurate Length Calculation inN
The method correctly returns the length of the composite vector, which is essential for SSZ operations.
131-133
: Merkle Root Calculation with Custom Merkleizer inHashTreeRootWith
The method correctly delegates the merkle root calculation to the provided merkleizer, ensuring flexibility and reusability.
Line range hint
139-142
: Accurate Length Calculation inN
The method correctly returns the length of the composite vector, which is essential for SSZ operations.
Line range hint
145-147
: Efficient Size Calculation inSizeSSZ
The method correctly calculates the size of the composite vector in bytes by multiplying the size of a single element by the length of the vector. This approach is efficient and straightforward.
Line range hint
150-153
: Merkle Root Calculation with Custom Merkleizer inHashTreeRootWith
The method correctly delegates the merkle root calculation to the provided merkleizer, ensuring flexibility and reusability.
Line range hint
156-158
: Simplified Merkle Root Calculation inHashTreeRoot
The method correctly creates a new merkleizer and calculates the merkle root, simplifying the process for the user.
Line range hint
161-167
: Efficient SSZ Marshaling inMarshalSSZTo
The method correctly uses the serializer to marshal the vector into SSZ format. However, the panic for non-fixed types indicates incomplete implementation. Ensure this is tracked.
Line range hint
170-172
: Efficient SSZ Marshaling inMarshalSSZ
The method correctly delegates to
MarshalSSZTo
, ensuring consistent and efficient SSZ serialization.
Line range hint
175-184
: SSZ Unmarshaling inNewFromSSZ
The method correctly uses the serializer to unmarshal the vector from SSZ format. However, the panic for non-fixed types indicates incomplete implementation. Ensure this is tracked.
mod/primitives/pkg/ssz/list.go (18)
35-37
: Use of Generic TypeB
for ListBasicThe change from
T
toB
for basic types inListBasic
improves clarity and consistency in naming conventions. This aligns with the SSZ specification and enhances readability.
42-49
: Deprecation Notice forListBasicFromElements
The TODO comment indicates that this function will be deprecated once the transition from Fastssz is complete. Ensure that this deprecation is tracked and handled appropriately.
52-55
: Correct Fixed Size Check inIsFixed
The method correctly returns
false
indicating thatListBasic
is not of fixed size. This is consistent with SSZ specifications for basic lists.
58-60
: Accurate Limit Calculation inN
The method correctly returns the limit of the list, which is essential for SSZ operations.
63-66
: Correct Calculation of Chunk Count inChunkCount
The method correctly calculates the number of chunks by dividing the total size by the root length and rounding up. This ensures accurate chunking for merkleization.
69-71
: Efficient Size Calculation inSizeSSZ
The method correctly delegates the size calculation to the
VectorBasic
type, ensuring consistency and reusability.
76-79
: Merkle Root Calculation with Custom Merkleizer inHashTreeRootWith
The method correctly delegates the merkle root calculation to the provided merkleizer, ensuring flexibility and reusability.
83-85
: Simplified Merkle Root Calculation inHashTreeRoot
The method correctly creates a new merkleizer and calculates the merkle root, simplifying the process for the user.
89-90
: Efficient SSZ Marshaling inMarshalSSZTo
The method correctly delegates the marshaling to the
VectorBasic
type, ensuring consistency and reusability.
94-96
: Efficient SSZ Marshaling inMarshalSSZ
The method correctly delegates to
MarshalSSZTo
, ensuring consistent and efficient SSZ serialization.
134-137
: Correct Fixed Size Check inIsFixed
The method correctly returns
false
indicating thatListComposite
is not of fixed size. This is consistent with SSZ specifications for composite lists.
139-142
: Accurate Limit Calculation inN
The method correctly returns the limit of the list, which is essential for SSZ operations.
Line range hint
145-147
: Efficient Size Calculation inSizeSSZ
The method correctly delegates the size calculation to the
VectorComposite
type, ensuring consistency and reusability.
Line range hint
150-153
: Merkle Root Calculation with Custom Merkleizer inHashTreeRootWith
The method correctly delegates the merkle root calculation to the provided merkleizer, ensuring flexibility and reusability.
Line range hint
156-158
: Simplified Merkle Root Calculation inHashTreeRoot
The method correctly creates a new merkleizer and calculates the merkle root, simplifying the process for the user.
Line range hint
161-167
: Efficient SSZ Marshaling inMarshalSSZTo
The method correctly uses the serializer to marshal the list into SSZ format. However, the panic for non-fixed types indicates incomplete implementation. Ensure this is tracked.
Line range hint
170-172
: Efficient SSZ Marshaling inMarshalSSZ
The method correctly delegates to
MarshalSSZTo
, ensuring consistent and efficient SSZ serialization.
Line range hint
175-184
: SSZ Unmarshaling inNewFromSSZ
The method correctly uses the serializer to unmarshal the list from SSZ format. However, the panic for non-fixed types indicates incomplete implementation. Ensure this is tracked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (4)
- mod/primitives/pkg/ssz/list.go (4 hunks)
- mod/primitives/pkg/ssz/merkleizer/merkleizer.go (5 hunks)
- mod/primitives/pkg/ssz/merkleizer/pack.go (1 hunks)
- mod/primitives/pkg/ssz/vector.go (4 hunks)
Additional comments not posted (32)
mod/primitives/pkg/ssz/merkleizer/pack.go (1)
53-66
: Address the TODO and ensure implementation correctness.The function implementation looks good, but the TODO comment indicates that there might be some uncertainty around the implementation. Ensure that the chunking logic is correct and safe.
// chunkifyBytes partitions a byte slice into chunks of a given length. func chunkifyBytes[RootT ~[32]byte](input []byte) ( []RootT, uint64, ) { //nolint:mnd // we add 31 in order to round up the division. numChunks := max((len(input)+31)/constants.RootLength, 1) // TODO: figure out how to safely chunk these bytes. chunks := make([]RootT, numChunks) for i := range chunks { copy(chunks[i][:], input[32*i:]) } //#nosec:G701 // numChunks is always >= 1. return chunks, uint64(numChunks) }mod/primitives/pkg/ssz/merkleizer/merkleizer.go (5)
Line range hint
47-52
: LGTM!The simplification of
rootHasher
initialization looks good.
59-61
: LGTM!The refactoring to use
MerkleizeVectorBasic
looks good.
Line range hint
67-97
: Address the TODOs and ensure implementation correctness.The function implementation looks good, but the TODO comments indicate potential improvements. Ensure that the handling of different types and the separation of merkleizers are addressed.
// TODO: MerkleizeBitlist // MerkleizeContainer implements the SSZ merkleization algorithm for a // container. // // TODO: Make a separate merkleizer for container and list of containers. func (m *merkleizer[RootT, T]) MerkleizeContainer( value SSZObject[RootT], ) (RootT, error) { rValue := reflect.ValueOf(value) if rValue.Kind() == reflect.Ptr { rValue = rValue.Elem() } numFields := rValue.NumField() htrs := make([]RootT, numFields) var err error for i := range numFields { fieldValue := rValue.Field(i) if !fieldValue.CanInterface() { return RootT{}, errors.Newf( "cannot interface with field %v", fieldValue, ) } // TODO: handle different types. field, ok := fieldValue.Interface().(SSZObject[RootT]) if !ok { return RootT{}, errors.Newf( "field %d does not implement Hashable", i, ) } htrs[i], err = field.HashTreeRoot( /*args...*/ ) if err != nil { return RootT{}, err } } return m.Merkleize(htrs) }
108-110
: LGTM!The implementation of
MerkleizeByteSlice
looks good.
Line range hint
112-157
: LGTM!The implementation of
Merkleize
looks good.mod/primitives/pkg/ssz/vector.go (13)
39-41
: LGTM!The implementation of
VectorBasicFromElements
looks good.
44-47
: LGTM!The implementation of
SizeSSZ
looks good.
49-52
: LGTM!The implementation of
IsFixed
looks good.
55-61
: LGTM!The implementation of
ChunkCount
looks good.
63-67
: LGTM!The implementation of
N
looks good.
72-75
: LGTM!The implementation of
HashTreeRootWith
looks good.
79-81
: LGTM!The implementation of
HashTreeRoot
looks good.
85-87
: LGTM!The implementation of
MarshalSSZTo
looks good.
90-92
: LGTM!The implementation of
MarshalSSZ
looks good.
95-97
: LGTM!The implementation of
NewFromSSZ
looks good.
Line range hint
109-112
: LGTM!The implementation of
VectorCompositeFromElements
looks good.
114-117
: LGTM!The implementation of
IsFixed
looks good.
120-124
: LGTM!The implementation of
N
looks good.mod/primitives/pkg/ssz/list.go (13)
35-37
: LGTM!The update to use a generic parameter
B
instead ofT
improves type consistency.
42-48
: LGTM!The update to use the generic parameter
B
inListBasicFromElements
is consistent with the refactoring efforts.
52-55
: LGTM!The
IsFixed
function correctly indicates thatListBasic
is not of fixed size.
57-62
: LGTM!The
N
function correctly returns the limit of theListBasic
as defined in the SSZ specification.
64-71
: LGTM!The
ChunkCount
function correctly calculates the number of chunks in theListBasic
based on the SSZ specification.
74-76
: LGTM!The
SizeSSZ
function correctly returns the size of the list in bytes by delegating to theVectorBasic
type.
81-84
: LGTM!The
HashTreeRootWith
function correctly returns the Merkle root of theListBasic
with a given merkleizer.
88-90
: LGTM!The
HashTreeRoot
function correctly returns the Merkle root of theListBasic
by creating a new merkleizer.
94-95
: LGTM!The
MarshalSSZTo
function correctly marshals theListBasic
into SSZ format by delegating to theVectorBasic
type.
99-101
: LGTM!The
MarshalSSZ
function correctly marshals theListBasic
into SSZ format by delegating to theVectorBasic
type.
139-142
: LGTM!The
IsFixed
function correctly indicates thatListComposite
is not of fixed size.
144-147
: LGTM!The
N
function correctly returns the limit of theListComposite
as defined in the SSZ specification.
149-153
: LGTM!The
ChunkCount
function correctly calculates the number of chunks in theListComposite
based on the SSZ specification.
func (l ListBasic[B]) NewFromSSZ(buf []byte) (*ListBasic[B], error) { | ||
// The same for ListBasic as for VectorBasic | ||
var ( | ||
t = make(VectorBasic[T], 0) | ||
err error | ||
elements = make(VectorBasic[B], 0) | ||
err error | ||
) | ||
|
||
t, err = t.NewFromSSZ(buf) | ||
return &ListBasic[T]{ | ||
t: t, | ||
elements, err = elements.NewFromSSZ(buf) | ||
return &ListBasic[B]{ | ||
elements: elements, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SSZ Unmarshaling in NewFromSSZ
The method correctly uses the serializer to unmarshal the list from SSZ format. However, the comment suggests that this is similar to VectorBasic
, indicating potential code duplication. Consider refactoring to avoid redundancy.
- func (l ListBasic[B]) NewFromSSZ(buf []byte) (*ListBasic[B], error) {
- // The same for ListBasic as for VectorBasic
- var (
- elements = make(VectorBasic[B], 0)
- err error
- )
- elements, err = elements.NewFromSSZ(buf)
- return &ListBasic[B]{
- elements: elements,
- }, err
+ func NewListBasicFromSSZ[B Basic[B]](buf []byte) (*ListBasic[B], error) {
+ elements, err := VectorBasic[B]{}.NewFromSSZ(buf)
+ if err != nil {
+ return nil, err
+ }
+ return &ListBasic[B]{
+ elements: elements,
+ }, nil
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
func (l ListBasic[B]) NewFromSSZ(buf []byte) (*ListBasic[B], error) { | |
// The same for ListBasic as for VectorBasic | |
var ( | |
t = make(VectorBasic[T], 0) | |
err error | |
elements = make(VectorBasic[B], 0) | |
err error | |
) | |
t, err = t.NewFromSSZ(buf) | |
return &ListBasic[T]{ | |
t: t, | |
elements, err = elements.NewFromSSZ(buf) | |
return &ListBasic[B]{ | |
elements: elements, | |
func NewListBasicFromSSZ[B Basic[B]](buf []byte) (*ListBasic[B], error) { | |
elements, err := VectorBasic[B]{}.NewFromSSZ(buf) | |
if err != nil { | |
return nil, err | |
} | |
return &ListBasic[B]{ | |
elements: elements, | |
}, nil | |
} |
Summary by CodeRabbit
New Features
Refactor
Enhancements
SSZObject
interface for marshaling data into SSZ format.