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

Fix lc execution header bug #14468

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add test for attested header exectution fields
Inspector-Butters committed Sep 20, 2024
commit 5ed715048a94a906709d1addc05137b91266d19d
2 changes: 0 additions & 2 deletions beacon-chain/core/light-client/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -12,12 +12,10 @@ go_library(
"//consensus-types:go_default_library",
"//consensus-types/blocks:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//encoding/bytesutil:go_default_library",
"//encoding/ssz:go_default_library",
"//proto/engine/v1:go_default_library",
"//proto/eth/v1:go_default_library",
"//proto/eth/v2:go_default_library",
"//proto/migration:go_default_library",
"//runtime/version:go_default_library",
"//time/slots:go_default_library",
"@com_github_pkg_errors//:go_default_library",
4 changes: 0 additions & 4 deletions beacon-chain/core/light-client/lightclient_test.go
Original file line number Diff line number Diff line change
@@ -18,8 +18,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/testing/util"
)

// TODO: check for attested block in tests

// NewLightClientOptimisticUpdateFromBeaconState tests

func TestLightClient_NewLightClientOptimisticUpdateFromBeaconStateAltair(t *testing.T) {
@@ -78,7 +76,6 @@ func TestLightClient_NewLightClientFinalityUpdateFromBeaconStateAltair(t *testin
finalizedBlockHeader, err := l.FinalizedBlock.Header()
require.NoError(t, err)

//zeroHash := params.BeaconConfig().ZeroHash[:]
require.NotNil(t, update.FinalizedHeader, "Finalized header is nil")
updateFinalizedHeaderBeacon, err := update.FinalizedHeader.GetBeacon()
require.NoError(t, err)
@@ -179,7 +176,6 @@ func TestLightClient_NewLightClientFinalityUpdateFromBeaconStateDeneb(t *testing
l.CheckSyncAggregate(update.SyncAggregate)
l.CheckAttestedHeader(update.AttestedHeader)

//zeroHash := params.BeaconConfig().ZeroHash[:]
finalizedBlockHeader, err := l.FinalizedBlock.Header()
require.NoError(t, err)
require.NotNil(t, update.FinalizedHeader, "Finalized header is nil")
2 changes: 2 additions & 0 deletions testing/util/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ go_library(
"//beacon-chain/state/stateutil:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//consensus-types:go_default_library",
"//consensus-types/blocks:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
@@ -51,6 +52,7 @@ go_library(
"//crypto/hash:go_default_library",
"//crypto/rand:go_default_library",
"//encoding/bytesutil:go_default_library",
"//encoding/ssz:go_default_library",
"//network/forks:go_default_library",
"//proto/engine/v1:go_default_library",
"//proto/eth/v1:go_default_library",
114 changes: 114 additions & 0 deletions testing/util/lightclient.go
Original file line number Diff line number Diff line change
@@ -4,14 +4,20 @@ import (
"context"
"testing"

"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
"github.com/prysmaticlabs/prysm/v5/config/params"
consensus_types "github.com/prysmaticlabs/prysm/v5/consensus-types"
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/encoding/ssz"
v11 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1"
ethpbv1 "github.com/prysmaticlabs/prysm/v5/proto/eth/v1"
ethpbv2 "github.com/prysmaticlabs/prysm/v5/proto/eth/v2"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
"github.com/prysmaticlabs/prysm/v5/testing/require"
)

@@ -575,6 +581,114 @@ func (l *TestLightClient) CheckAttestedHeader(container *ethpbv2.LightClientHead
attestedStateRoot, err := l.AttestedState.HashTreeRoot(l.Ctx)
require.NoError(l.T, err)
require.DeepSSZEqual(l.T, attestedStateRoot[:], updateAttestedHeaderBeacon.StateRoot, "Attested block state root is not equal")

if l.AttestedBlock.Version() == version.Capella {
payloadInterface, err := l.AttestedBlock.Block().Body().Execution()
require.NoError(l.T, err)
transactionsRoot, err := payloadInterface.TransactionsRoot()
if errors.Is(err, consensus_types.ErrUnsupportedField) {
transactions, err := payloadInterface.Transactions()
require.NoError(l.T, err)
transactionsRootArray, err := ssz.TransactionsRoot(transactions)
require.NoError(l.T, err)
transactionsRoot = transactionsRootArray[:]
} else {
require.NoError(l.T, err)
}
withdrawalsRoot, err := payloadInterface.WithdrawalsRoot()
if errors.Is(err, consensus_types.ErrUnsupportedField) {
withdrawals, err := payloadInterface.Withdrawals()
require.NoError(l.T, err)
withdrawalsRootArray, err := ssz.WithdrawalSliceRoot(withdrawals, fieldparams.MaxWithdrawalsPerPayload)
require.NoError(l.T, err)
withdrawalsRoot = withdrawalsRootArray[:]
} else {
require.NoError(l.T, err)
}
execution := &v11.ExecutionPayloadHeaderCapella{
ParentHash: payloadInterface.ParentHash(),
FeeRecipient: payloadInterface.FeeRecipient(),
StateRoot: payloadInterface.StateRoot(),
ReceiptsRoot: payloadInterface.ReceiptsRoot(),
LogsBloom: payloadInterface.LogsBloom(),
PrevRandao: payloadInterface.PrevRandao(),
BlockNumber: payloadInterface.BlockNumber(),
GasLimit: payloadInterface.GasLimit(),
GasUsed: payloadInterface.GasUsed(),
Timestamp: payloadInterface.Timestamp(),
ExtraData: payloadInterface.ExtraData(),
BaseFeePerGas: payloadInterface.BaseFeePerGas(),
BlockHash: payloadInterface.BlockHash(),
TransactionsRoot: transactionsRoot,
WithdrawalsRoot: withdrawalsRoot,
}

updateAttestedHeaderExecution, err := container.GetExecutionHeaderCapella()
require.NoError(l.T, err)
require.DeepSSZEqual(l.T, execution, updateAttestedHeaderExecution, "Attested Block Execution is not equal")

executionPayloadProof, err := blocks.PayloadProof(l.Ctx, l.AttestedBlock.Block())
require.NoError(l.T, err)
updateAttestedHeaderExecutionBranch, err := container.GetExecutionBranch()
require.NoError(l.T, err)
for i, leaf := range updateAttestedHeaderExecutionBranch {
require.DeepSSZEqual(l.T, executionPayloadProof[i], leaf, "Leaf is not equal")
}
}

if l.AttestedBlock.Version() == version.Deneb {
payloadInterface, err := l.AttestedBlock.Block().Body().Execution()
require.NoError(l.T, err)
transactionsRoot, err := payloadInterface.TransactionsRoot()
if errors.Is(err, consensus_types.ErrUnsupportedField) {
transactions, err := payloadInterface.Transactions()
require.NoError(l.T, err)
transactionsRootArray, err := ssz.TransactionsRoot(transactions)
require.NoError(l.T, err)
transactionsRoot = transactionsRootArray[:]
} else {
require.NoError(l.T, err)
}
withdrawalsRoot, err := payloadInterface.WithdrawalsRoot()
if errors.Is(err, consensus_types.ErrUnsupportedField) {
withdrawals, err := payloadInterface.Withdrawals()
require.NoError(l.T, err)
withdrawalsRootArray, err := ssz.WithdrawalSliceRoot(withdrawals, fieldparams.MaxWithdrawalsPerPayload)
require.NoError(l.T, err)
withdrawalsRoot = withdrawalsRootArray[:]
} else {
require.NoError(l.T, err)
}
execution := &v11.ExecutionPayloadHeaderDeneb{
ParentHash: payloadInterface.ParentHash(),
FeeRecipient: payloadInterface.FeeRecipient(),
StateRoot: payloadInterface.StateRoot(),
ReceiptsRoot: payloadInterface.ReceiptsRoot(),
LogsBloom: payloadInterface.LogsBloom(),
PrevRandao: payloadInterface.PrevRandao(),
BlockNumber: payloadInterface.BlockNumber(),
GasLimit: payloadInterface.GasLimit(),
GasUsed: payloadInterface.GasUsed(),
Timestamp: payloadInterface.Timestamp(),
ExtraData: payloadInterface.ExtraData(),
BaseFeePerGas: payloadInterface.BaseFeePerGas(),
BlockHash: payloadInterface.BlockHash(),
TransactionsRoot: transactionsRoot,
WithdrawalsRoot: withdrawalsRoot,
}

updateAttestedHeaderExecution, err := container.GetExecutionHeaderDeneb()
require.NoError(l.T, err)
require.DeepSSZEqual(l.T, execution, updateAttestedHeaderExecution, "Attested Block Execution is not equal")

executionPayloadProof, err := blocks.PayloadProof(l.Ctx, l.AttestedBlock.Block())
require.NoError(l.T, err)
updateAttestedHeaderExecutionBranch, err := container.GetExecutionBranch()
require.NoError(l.T, err)
for i, leaf := range updateAttestedHeaderExecutionBranch {
require.DeepSSZEqual(l.T, executionPayloadProof[i], leaf, "Leaf is not equal")
}
}
}

func (l *TestLightClient) CheckSyncAggregate(sa *ethpbv1.SyncAggregate) {

Unchanged files with check annotations Beta

}
}
func getExecutionPayloadHeaderCapella(block interfaces.ReadOnlySignedBeaconBlock) (*enginev1.ExecutionPayloadHeaderCapella, error) {

Check failure on line 424 in beacon-chain/core/light-client/lightclient.go

GitHub Actions / Lint

func `getExecutionPayloadHeaderCapella` is unused (unused)
payloadInterface, err := block.Block().Body().Execution()
if err != nil {
return nil, errors.Wrap(err, "could not get execution data")
return execution, nil
}
func getExecutionPayloadHeaderDeneb(block interfaces.ReadOnlySignedBeaconBlock) (*enginev1.ExecutionPayloadHeaderDeneb, error) {

Check failure on line 479 in beacon-chain/core/light-client/lightclient.go

GitHub Actions / Lint

func `getExecutionPayloadHeaderDeneb` is unused (unused)
payloadInterface, err := block.Block().Body().Execution()
if err != nil {
return nil, errors.Wrap(err, "could not get execution data")