Skip to content

Commit

Permalink
add changes (#13657)
Browse files Browse the repository at this point in the history
  • Loading branch information
nisdas authored Feb 23, 2024
1 parent 0b261cb commit 789c3f8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions beacon-chain/core/blocks/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion beacon-chain/core/blocks/signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
4 changes: 2 additions & 2 deletions beacon-chain/sync/validate_beacon_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 789c3f8

Please sign in to comment.