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): convert forkdata to peters lib #1763

Merged
merged 5 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions mod/consensus-types/pkg/types/fork_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/berachain/beacon-kit/mod/errors"
"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
"github.com/karalabe/ssz"
)

// ForkData as defined in the Ethereum 2.0 specification:
Expand Down Expand Up @@ -55,6 +56,40 @@ func (fd *ForkData) New(
return NewForkData(currentVersion, genesisValidatorsRoot)
}

// SizeSSZ returns the size of the SigningData object in SSZ encoding.
func (*ForkData) SizeSSZ() uint32 {
//nolint:mnd // 32+4 = 36.
return 36
}

// DefineSSZ defines the SSZ encoding for the ForkData object.
func (fd *ForkData) DefineSSZ(codec *ssz.Codec) {
ssz.DefineStaticBytes(codec, &fd.CurrentVersion)
ssz.DefineStaticBytes(codec, &fd.GenesisValidatorsRoot)
}

// HashTreeRoot computes the SSZ hash tree root of the ForkData object.
func (fd *ForkData) HashTreeRoot() ([32]byte, error) {
return ssz.HashSequential(fd), nil
}

// MarshalSSZTo marshals the ForkData object to SSZ format into the provided
// buffer.
func (fd *ForkData) MarshalSSZTo(buf []byte) ([]byte, error) {
return buf, ssz.EncodeToBytes(buf, fd)
}

// MarshalSSZ marshals the ForkData object to SSZ format.
func (fd *ForkData) MarshalSSZ() ([]byte, error) {
buf := make([]byte, fd.SizeSSZ())
return fd.MarshalSSZTo(buf)
}

// UnmarshalSSZ unmarshals the ForkData object from SSZ format.
func (fd *ForkData) UnmarshalSSZ(buf []byte) error {
return ssz.DecodeFromBytes(buf, fd)
}

// ComputeDomain as defined in the Ethereum 2.0 specification.
// https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#compute_domain
//
Expand Down
73 changes: 0 additions & 73 deletions mod/consensus-types/pkg/types/fork_data.ssz.go

This file was deleted.

12 changes: 0 additions & 12 deletions mod/consensus-types/pkg/types/fork_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,6 @@ func TestForkData_HashTreeRoot(t *testing.T) {
require.NoError(t, err)
}

func TestForkData_GetTree(t *testing.T) {
forkData := &types.ForkData{
CurrentVersion: common.Version{},
GenesisValidatorsRoot: common.Root{},
}

tree, err := forkData.GetTree()

require.NoError(t, err)
require.NotNil(t, tree)
}

func TestForkData_ComputeDomain(t *testing.T) {
forkData := &types.ForkData{
CurrentVersion: common.Version{},
Expand Down
Loading