Skip to content
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): Add type defs #1664

Merged
merged 17 commits into from
Jul 1, 2024
Merged

feat(ssz): Add type defs #1664

merged 17 commits into from
Jul 1, 2024

Conversation

itsdevbear
Copy link
Contributor

@itsdevbear itsdevbear commented Jun 30, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new type definitions (U8, U16, U32, U64, Byte) with enhanced serialization capabilities.
    • Added VectorMerkleizer and ListMerkleizer interfaces for improved Merkleization operations.
  • Refactor

    • Refactored interfaces to use external types for better modularity and code organization.
    • Restructured ListBasic and ListComposite types for better type handling.
  • Chores

    • Updated CHAIN_SPEC in the entrypoint script from "devnet" to "testnet".

@itsdevbear itsdevbear requested a review from ocnc as a code owner June 30, 2024 23:57
Copy link
Contributor

coderabbitai bot commented Jun 30, 2024

Warning

Rate limit exceeded

@itsdevbear has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 56 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

Commits

Files that changed from the base of the PR and between 4b6038d and 8dff760.

Walkthrough

The changes enhance the type system and functionality for serialization in the ssz package by introducing new type definitions (U8, U16, U32, U64, Byte) and updating interfaces to use these types. The updates also include modifications in the Vector and List types, the Container struct, and the BaseMerkleizer and new VectorMerkleizer and ListMerkleizer interfaces. An entry script was updated to change the chain specification from "devnet" to "testnet."

Changes

Files Change Summary
mod/primitives/pkg/ssz/basic.go Added type definitions (U8, U16, U32, U64, Byte) with methods for size, fixed check, and type return.
mod/primitives/pkg/ssz/constraints.go Refactored interfaces to use types from types package, simplifying Base and Basic interfaces.
mod/primitives/pkg/ssz/interfaces.go Updated BaseMerkleizer type constraint to types.SSZType[T], added VectorMerkleizer and ListMerkleizer interfaces.
mod/primitives/pkg/ssz/list.go Added ListBasic, ListComposite type definitions and functions for element handling and removed duplicate declarations.
mod/primitives/pkg/ssz/container.go Updated methods for Container struct to fit new type definitions and refactored existing methods.
mod/primitives/pkg/ssz/types/types.go Introduced new interfaces and types for SSZ serialization and enumeration (BaseSSZType, SSZType, SSZEnumerable).
mod/.../pkg/engine-primitives/withdrawal.go Added a Type() method to Withdrawal struct to return SSZ type.
testing/files/entrypoint.sh Updated CHAIN_SPEC from "devnet" to "testnet".
mod/primitives/pkg/ssz/vector.go Redefined Vector type, added/updated methods for type checks, serialization, and merkleization.
mod/primitives/pkg/ssz/vector_test.go Renamed test functions to reflect the operations on vector sizes, hash roots, and marshaling/unmarshaling.

Sequence Diagram(s)

(Changes are too varied and specific to include sequence diagrams.)

Poem

Amid the code, where bytes do spread,
We redefine, on vectors tread. 📏
From U8 to U64's might,
Serialization shines so bright. ✨
Testnet chains now come to play,
In fields where data bunnies sway. 🐇💻🌟


Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jun 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.45%. Comparing base (02f5473) to head (8dff760).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #1664       +/-   ##
===========================================
+ Coverage   22.38%   70.45%   +48.07%     
===========================================
  Files         270        8      -262     
  Lines       11888       88    -11800     
  Branches       18       18               
===========================================
- Hits         2661       62     -2599     
+ Misses       9107       22     -9085     
+ Partials      120        4      -116     

see 262 files with indirect coverage changes

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Outside diff range comments (2)
mod/primitives/pkg/ssz/vector.go (2)

Line range hint 50-52: Reminder: Deprecate the function.

The TODO comment indicates that the VectorCompositeFromElements function is to be deprecated.

Do you want me to deprecate the function or open a GitHub issue to track this task?


Line range hint 98-100: Avoid using panic for error handling.

The MarshalSSZToBytes and NewFromSSZ methods use panic for error handling, which is not recommended.

-	if !c.IsFixed() {
-		panic("not implemented yet")
-	}
+	if !c.IsFixed() {
+		return nil, errors.New("not implemented yet")
+	}

Also applies to: 113-115

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 02f5473 and 43c5d00.

Files selected for processing (6)
  • mod/primitives/pkg/ssz/basic.go (12 hunks)
  • mod/primitives/pkg/ssz/constraints.go (1 hunks)
  • mod/primitives/pkg/ssz/interfaces.go (1 hunks)
  • mod/primitives/pkg/ssz/list.go (2 hunks)
  • mod/primitives/pkg/ssz/types/types.go (1 hunks)
  • mod/primitives/pkg/ssz/vector.go (2 hunks)
Additional comments not posted (22)
mod/primitives/pkg/ssz/types/types.go (3)

3-8: LGTM!

The Type definition and constants for Basic and Composite are clear and straightforward.


10-28: LGTM!

The SSZType interface is well-defined and comprehensive.


30-40: LGTM!

The SSZEnumerable interface is well-defined and extends SSZType.

mod/primitives/pkg/ssz/constraints.go (2)

26-29: LGTM!

The Basic interface now extends types.SSZType and the type constraint is clear.


33-35: LGTM!

The Composite interface now extends types.SSZType and the type constraint is clear.

mod/primitives/pkg/ssz/interfaces.go (3)

23-28: LGTM!

The BaseMerkleizer interface now uses types.SSZType and the type constraint is clear.


Line range hint 29-34: LGTM!

The BasicMerkleizer interface provides clear merkleization operations for basic SSZ types.


Line range hint 35-41: LGTM!

The CompositeMerkleizer interface provides clear merkleization operations for composite SSZ types.

mod/primitives/pkg/ssz/vector.go (2)

34-39: LGTM!

The VectorBasic type definition and its methods are clear and well-implemented.


38-39: LGTM!

The VectorComposite type definition and its methods are clear and well-implemented.

mod/primitives/pkg/ssz/list.go (5)

34-46: LGTM!

The new type definitions for ListBasic and ListComposite are clear and align with the existing code structure.


Line range hint 48-55: LGTM!

The function ListCompositeFromElements is straightforward. Ensure to address the TODO comment for deprecation.


Line range hint 56-60: LGTM!

The function IsFixed correctly follows the SSZ specification.


Line range hint 61-65: LGTM!

The function N correctly returns the limit of the list.


Line range hint 66-70: LGTM!

The function ChunkCount correctly calculates the number of chunks in the list.

mod/primitives/pkg/ssz/basic.go (7)

35-43: LGTM!

The new type definitions for Bool, U8, U16, U32, U64, and Byte are clear and align with the existing code structure.


Line range hint 45-100: LGTM!

The functions for Bool are well-implemented and follow the SSZ specification.


Line range hint 101-149: LGTM!

The functions for U8 are well-implemented and follow the SSZ specification.


Line range hint 150-198: LGTM!

The functions for U16 are well-implemented and follow the SSZ specification.


Line range hint 199-247: LGTM!

The functions for U32 are well-implemented and follow the SSZ specification.


Line range hint 248-296: LGTM!

The functions for U64 are well-implemented and follow the SSZ specification.


Line range hint 297-343: LGTM!

The functions for Byte are well-implemented and follow the SSZ specification.

Comment on lines 22 to 27
// TODO: Enable these
//
// ChunkCount returns the number of chunks required to store the type.
// ChunkCount() uint64
// Type returns the type of the SSZ object.
// Type() Type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder: Enable the commented methods.

The TODO comment indicates that some methods are not yet enabled.

Do you want me to implement the commented methods or open a GitHub issue to track this task?

Comment on lines 44 to 46

// VectorBasicFromElements creates a new ListComposite from elements.
// TODO: Deprecate once off of Fastssz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder: Deprecate the function.

The TODO comment indicates that the VectorBasicFromElements function is to be deprecated.

Do you want me to deprecate the function or open a GitHub issue to track this task?

itsdevbear added 2 commits June 30, 2024 20:01
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 43c5d00 and e5a07ae.

Files selected for processing (4)
  • mod/engine-primitives/pkg/engine-primitives/withdrawal.go (2 hunks)
  • mod/primitives/pkg/ssz/basic.go (12 hunks)
  • mod/primitives/pkg/ssz/container.go (1 hunks)
  • mod/primitives/pkg/ssz/types/types.go (1 hunks)
Additional comments not posted (14)
mod/primitives/pkg/ssz/types/types.go (4)

1-21: LGTM!

The license header and package declaration are correctly defined.


23-28: LGTM!

The type Type and constants Basic and Composite are correctly defined.


30-41: LGTM!

The BaseSSZType interface is well-defined and follows Go interface design principles.


53-62: LGTM!

The SSZEnumerable interface is well-defined and follows Go interface design principles.

mod/primitives/pkg/ssz/container.go (3)

1-8: LGTM!

The package declaration and imports are correctly defined.


10-47: LGTM!

The Container struct and its methods are well-defined and follow Go struct and method design principles.


49-107: LGTM!

The methods for SSZ serialization are well-defined and follow Go method design principles.

mod/engine-primitives/pkg/engine-primitives/withdrawal.go (3)

Line range hint 1-26: LGTM!

The license header and package declaration are correctly defined.


Line range hint 28-86: LGTM!

The Withdrawal struct and its methods are well-defined and follow Go struct and method design principles.


87-90: LGTM!

The Type method for the Withdrawal struct is well-defined and follows Go method design principles.

mod/primitives/pkg/ssz/basic.go (4)

Line range hint 1-11: LGTM!

The license header and package declaration are correctly defined.


27-52: LGTM!

The imports and type definitions are correctly defined.


Line range hint 54-103: LGTM!

The Bool type and its methods are well-defined and follow Go method design principles.


Line range hint 105-343: LGTM!

The types U8, U16, U32, U64, and Byte and their methods are well-defined and follow Go method design principles.

mod/primitives/pkg/ssz/container.go Outdated Show resolved Hide resolved
itsdevbear added 3 commits June 30, 2024 20:42
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Outside diff range comments (3)
testing/files/entrypoint.sh (3)

Line range hint 46-47: Unused Variables

The variables GENESIS and TMP_GENESIS are defined but not used. Verify their usage or remove them if unnecessary.

- GENESIS=$HOMEDIR/config/genesis.json
- TMP_GENESIS=$HOMEDIR/config/tmp_genesis.json

Line range hint 81-81: Unquoted Variable

The surrounding quotes unquote the variable. Remove or escape the quotes.

- BEACON_START_CMD="./build/bin/beacond start --pruning=nothing "$TRACE" \
+ BEACON_START_CMD="./build/bin/beacond start --pruning=nothing \"$TRACE\" \

Line range hint 95-95: Double Quote to Prevent Globbing and Word Splitting

Double quote the variable to prevent globbing and word splitting.

- RPC_DIAL_URL=$(resolve_path "$RPC_DIAL_URL")
+ RPC_DIAL_URL="$(resolve_path "$RPC_DIAL_URL")"
Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between e5a07ae and 9ede992.

Files selected for processing (7)
  • mod/primitives/pkg/ssz/container.go (1 hunks)
  • mod/primitives/pkg/ssz/interfaces.go (2 hunks)
  • mod/primitives/pkg/ssz/list.go (3 hunks)
  • mod/primitives/pkg/ssz/types/types.go (1 hunks)
  • mod/primitives/pkg/ssz/vector.go (1 hunks)
  • mod/primitives/pkg/ssz/vector_test.go (5 hunks)
  • testing/files/entrypoint.sh (1 hunks)
Additional context used
Shellcheck
testing/files/entrypoint.sh

[warning] 46-46: GENESIS appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 47-47: TMP_GENESIS appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 81-81: The surrounding quotes actually unquote this. Remove or escape them.

(SC2027)


[info] 95-95: Double quote to prevent globbing and word splitting.

(SC2086)

Additional comments not posted (51)
mod/primitives/pkg/ssz/types/types.go (4)

1-19: License and Copyright Notice

The license and copyright notice are correctly included and formatted.


21-28: New Type Definitions

The Type enum and its constants Basic and Composite are well-defined and clear.


30-41: BaseSSZType Interface

The BaseSSZType interface defines essential methods for SSZ types, including HashTreeRoot, IsFixed, SizeSSZ, Type, and MarshalSSZ. These methods are crucial for SSZ serialization and type handling.


53-63: New SSZEnumerable Interface

The SSZEnumerable interface extends SSZType and adds methods N and Elements for SSZ enumerable types. This extension is logical and aligns with SSZ specifications.

mod/primitives/pkg/ssz/interfaces.go (7)

Line range hint 1-22: License and Copyright Notice

The license and copyright notice are correctly included and formatted.


23-23: Import Statement

The import statement correctly imports the types package from the specified path.


Line range hint 27-31: BaseMerkleizer Interface

The BaseMerkleizer interface defines basic merkleization operations for SSZ types. The method signatures are clear and appropriate.


Line range hint 33-43: BasicMerkleizer Interface

The BasicMerkleizer interface extends BaseMerkleizer and adds methods for merkleizing basic SSZ types. The method signatures are clear and appropriate.


Line range hint 45-51: CompositeMerkleizer Interface

The CompositeMerkleizer interface extends BaseMerkleizer and adds methods for merkleizing composite SSZ types. The method signatures are clear and appropriate.


53-56: VectorMerkelizer Interface

The VectorMerkelizer interface defines methods for merkleizing vectors of SSZ types. The method signatures are clear and appropriate.


58-61: ListMerkliezer Interface

The ListMerkliezer interface defines methods for merkleizing lists of SSZ types. The method signatures are clear and appropriate.

testing/files/entrypoint.sh (2)

Line range hint 1-43: License and Function Definition

The license and permission notice are correctly included and formatted. The function resolve_path is well-defined and handles both URLs and file paths.


65-65: CHAIN_SPEC Variable Update

The CHAIN_SPEC variable is updated to testnet. Ensure this change is intentional and aligns with the environment requirements.

mod/primitives/pkg/ssz/container.go (13)

1-19: License and Copyright Notice

The license and copyright notice are correctly included and formatted.


21-28: Import Statements

The import statements correctly import necessary packages and modules.


30-30: Interface Implementation Assertion

The assertion ensures that Container implements the types.SSZEnumerable interface. This is a good practice to catch interface implementation issues at compile time.


32-35: Container Struct Definition

The Container struct is defined with a single field elements which is a slice of types.BaseSSZType. This is clear and straightforward.


37-54: NewContainer Function

The NewContainer function uses reflection to create a new Container from a struct. It includes checks to ensure the input is a struct and handles pointers correctly. The TODO comment indicates that struct tags need to be checked to exclude fields.


56-65: Field Iteration and Type Checking

The loop iterates over the fields of the struct and checks if they implement the types.BaseSSZType interface. If a field does not implement the interface, an error is returned. This is a robust way to ensure all fields are valid SSZ types.


67-67: Return Statement

The function returns a new Container with the collected elements. This is clear and straightforward.


70-72: N Method

The N method returns the number of elements in the container. This is clear and straightforward.


74-76: Elements Method

The Elements method returns the elements of the container. This is clear and straightforward.


78-92: MarshalSSZ Method

The MarshalSSZ method marshals the container into SSZ format by iterating over the elements and calling their MarshalSSZ method. This is a clear and efficient implementation.


94-103: SizeSSZ Method

The SizeSSZ method returns the size of the container in bytes by summing the sizes of its elements. This is a clear and efficient implementation.


105-113: IsFixed Method

The IsFixed method returns true if all elements in the container are of fixed size. This is a clear and efficient implementation.


120-123: Type Method

The Type method returns the type of the container as types.Composite. This is clear and straightforward.

mod/primitives/pkg/ssz/vector_test.go (3)

30-61: LGTM!

The test cases for TestVectorSizeSSZ cover various vector types and are correctly implemented.


Line range hint 62-93: LGTM!

The test cases for TestVectorHashTreeRoot cover various vector types and are correctly implemented.


Line range hint 95-149: LGTM!

The test cases for TestVectorMarshalUnmarshal cover various vector types and are correctly implemented.

mod/primitives/pkg/ssz/vector.go (12)

35-37: LGTM!

The type definition for Vector with the type constraint is appropriate and ensures type safety.


50-54: LGTM!

The method SizeSSZ correctly calculates the size of the vector in bytes using the SizeSSZ method of the element type.


56-59: LGTM!

The method IsFixed correctly determines if the vector is of fixed size using the IsFixed method of the element type.


62-65: LGTM!

The method Type correctly returns the type of the vector using the Type method of the element type.


68-75: LGTM!

The method ChunkCount correctly calculates the number of chunks in the vector and handles both basic and composite types appropriately.


79-81: LGTM!

The method N correctly returns the length of the vector.


86-88: LGTM!

The method Elements correctly returns the elements of the vector.


96-102: LGTM!

The method HashTreeRootWith correctly calculates the Merkle root of the vector with a given merkleizer and handles both basic and composite types appropriately.


107-110: LGTM!

The method HashTreeRoot correctly calculates the Merkle root of the vector using the HashTreeRootWith method with a new merkleizer.


117-123: LGTM!

The method MarshalSSZTo correctly marshals the vector into SSZ format using the appropriate serializer method based on whether the vector is fixed size.


126-128: LGTM!

The method MarshalSSZ correctly marshals the vector into SSZ format using the MarshalSSZTo method.


131-137: LGTM!

The method NewFromSSZ correctly creates a new vector from SSZ format using the appropriate deserializer method based on whether the vector is fixed size.

mod/primitives/pkg/ssz/list.go (10)

Line range hint 74-77: LGTM!

The method IsFixed correctly returns false, indicating that lists are not of fixed size.


79-82: LGTM!

The method N correctly returns the limit of the list.


Line range hint 84-89: LGTM!

The method ChunkCount correctly calculates the number of chunks in the list using the size of the element type.


79-80: LGTM!

The method SizeSSZ correctly calculates the size of the list in bytes using the SizeSSZ method of the Vector type.


Line range hint 91-94: LGTM!

The method HashTreeRootWith correctly calculates the Merkle root of the list with a given merkleizer using the MerkleizeListBasic method of the merkleizer.


96-98: LGTM!

The method HashTreeRoot correctly calculates the Merkle root of the list using the HashTreeRootWith method with a new merkleizer.


99-101: LGTM!

The method MarshalSSZTo correctly marshals the list into SSZ format using the MarshalVectorFixed method of the serializer.


104-106: LGTM!

The method MarshalSSZ correctly marshals the list into SSZ format using the MarshalSSZTo method.


110-115: LGTM!

The method NewFromSSZ correctly creates a new list from SSZ format using the NewFromSSZ method of the Vector type to deserialize the elements.


Line range hint 146-149: LGTM!

The method IsFixed correctly returns false, indicating that lists are not of fixed size.

mod/primitives/pkg/ssz/types/types.go Show resolved Hide resolved
mod/primitives/pkg/ssz/container.go Outdated Show resolved Hide resolved
mod/primitives/pkg/ssz/container.go Outdated Show resolved Hide resolved
@itsdevbear itsdevbear enabled auto-merge (squash) July 1, 2024 01:05
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits

Files that changed from the base of the PR and between 9ede992 and 4b6038d.

Files selected for processing (2)
  • mod/primitives/pkg/ssz/interfaces.go (2 hunks)
  • mod/primitives/pkg/ssz/vector.go (1 hunks)
Additional comments not posted (14)
mod/primitives/pkg/ssz/interfaces.go (3)

27-27: LGTM!

The update to use types.SSZType[T] in BaseMerkleizer is consistent with the objective of adding type definitions.


53-56: LGTM!

The addition of the VectorMerkleizer interface with methods for Merkleizing vectors of basic and composite types is consistent with the objective of adding type definitions.


58-61: LGTM!

The addition of the ListMerkleizer interface with methods for Merkleizing lists of basic and composite types is consistent with the objective of adding type definitions.

mod/primitives/pkg/ssz/vector.go (11)

52-54: LGTM!

The SizeSSZ function correctly calculates the size of the list in bytes.


58-63: LGTM!

The IsFixed function correctly determines if the vector is of fixed size.


66-67: LGTM!

The Type function correctly returns the type of the vector.


71-78: LGTM!

The ChunkCount function correctly calculates the number of chunks in the vector.


82-85: LGTM!

The N function correctly returns the N value as defined in the SSZ specification.


89-90: LGTM!

The Elements function correctly returns the elements of the vector.


99-106: LGTM!

The HashTreeRootWith function correctly returns the Merkle root of the vector with a given merkleizer, performing necessary type checks.


110-111: LGTM!

The HashTreeRoot function correctly returns the Merkle root of the vector.


119-124: LGTM!

The MarshalSSZTo function correctly marshals the vector into SSZ format, returning an error for non-fixed size vectors.


128-129: LGTM!

The MarshalSSZ function correctly marshals the vector into SSZ format.


133-138: LGTM!

The NewFromSSZ function correctly creates a new vector from SSZ format, panicking for non-fixed size vectors.

Comment on lines +43 to 45
func VectorFromElements[B Basic[B]](elements ...B) Vector[B] {
return elements
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder: Deprecate the function.

The TODO comment indicates that the VectorFromElements function is to be deprecated.

Do you want me to deprecate the function or open a GitHub issue to track this task?

@itsdevbear itsdevbear disabled auto-merge July 1, 2024 01:22
@itsdevbear itsdevbear merged commit 96033ea into main Jul 1, 2024
16 checks passed
@itsdevbear itsdevbear deleted the sssz-type-def branch July 1, 2024 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant