From 789c3f80789288cc4b9ceb780df5064d1629e67e Mon Sep 17 00:00:00 2001 From: Nishant Das Date: Fri, 23 Feb 2024 18:51:46 +0800 Subject: [PATCH] add changes (#13657) --- beacon-chain/core/blocks/signature.go | 6 ++++-- beacon-chain/core/blocks/signature_test.go | 4 +++- beacon-chain/sync/validate_beacon_blocks.go | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/beacon-chain/core/blocks/signature.go b/beacon-chain/core/blocks/signature.go index fd879fe2e..508de5f1a 100644 --- a/beacon-chain/core/blocks/signature.go +++ b/beacon-chain/core/blocks/signature.go @@ -99,7 +99,7 @@ func VerifyBlockHeaderSignature(beaconState state.BeaconState, header *ethpb.Sig // VerifyBlockSignatureUsingCurrentFork verifies the proposer signature of a beacon block. This differs // from the above method by not using fork data from the state and instead retrieving it // via the respective epoch. -func VerifyBlockSignatureUsingCurrentFork(beaconState state.ReadOnlyBeaconState, blk interfaces.ReadOnlySignedBeaconBlock) error { +func VerifyBlockSignatureUsingCurrentFork(beaconState state.ReadOnlyBeaconState, blk interfaces.ReadOnlySignedBeaconBlock, blkRoot [32]byte) error { currentEpoch := slots.ToEpoch(blk.Block().Slot()) fork, err := forks.Fork(currentEpoch) if err != nil { @@ -115,7 +115,9 @@ func VerifyBlockSignatureUsingCurrentFork(beaconState state.ReadOnlyBeaconState, } proposerPubKey := proposer.PublicKey sig := blk.Signature() - return signing.VerifyBlockSigningRoot(proposerPubKey, sig[:], domain, blk.Block().HashTreeRoot) + return signing.VerifyBlockSigningRoot(proposerPubKey, sig[:], domain, func() ([32]byte, error) { + return blkRoot, nil + }) } // BlockSignatureBatch retrieves the block signature batch from the provided block and its corresponding state. diff --git a/beacon-chain/core/blocks/signature_test.go b/beacon-chain/core/blocks/signature_test.go index 41ecbb7b0..aea33fac2 100644 --- a/beacon-chain/core/blocks/signature_test.go +++ b/beacon-chain/core/blocks/signature_test.go @@ -79,11 +79,13 @@ func TestVerifyBlockSignatureUsingCurrentFork(t *testing.T) { } domain, err := signing.Domain(fData, 100, params.BeaconConfig().DomainBeaconProposer, bState.GenesisValidatorsRoot()) assert.NoError(t, err) + blkRoot, err := altairBlk.Block.HashTreeRoot() + assert.NoError(t, err) rt, err := signing.ComputeSigningRoot(altairBlk.Block, domain) assert.NoError(t, err) sig := keys[0].Sign(rt[:]).Marshal() altairBlk.Signature = sig wsb, err := consensusblocks.NewSignedBeaconBlock(altairBlk) require.NoError(t, err) - assert.NoError(t, blocks.VerifyBlockSignatureUsingCurrentFork(bState, wsb)) + assert.NoError(t, blocks.VerifyBlockSignatureUsingCurrentFork(bState, wsb, blkRoot)) } diff --git a/beacon-chain/sync/validate_beacon_blocks.go b/beacon-chain/sync/validate_beacon_blocks.go index 0a975f4f8..37699e189 100644 --- a/beacon-chain/sync/validate_beacon_blocks.go +++ b/beacon-chain/sync/validate_beacon_blocks.go @@ -272,7 +272,7 @@ func (s *Service) validatePhase0Block(ctx context.Context, blk interfaces.ReadOn return nil, err } - if err := blocks.VerifyBlockSignatureUsingCurrentFork(parentState, blk); err != nil { + if err := blocks.VerifyBlockSignatureUsingCurrentFork(parentState, blk, blockRoot); err != nil { return nil, err } // In the event the block is more than an epoch ahead from its @@ -373,7 +373,7 @@ func (s *Service) verifyPendingBlockSignature(ctx context.Context, blk interface if err != nil { return pubsub.ValidationIgnore, err } - if err := blocks.VerifyBlockSignatureUsingCurrentFork(roState, blk); err != nil { + if err := blocks.VerifyBlockSignatureUsingCurrentFork(roState, blk, blkRoot); err != nil { s.setBadBlock(ctx, blkRoot) return pubsub.ValidationReject, err }