diff --git a/beacon-chain/blockchain/execution_engine.go b/beacon-chain/blockchain/execution_engine.go index b68f80b199..661cd5290c 100644 --- a/beacon-chain/blockchain/execution_engine.go +++ b/beacon-chain/blockchain/execution_engine.go @@ -94,7 +94,7 @@ func (s *Service) notifyForkchoiceUpdate(ctx context.Context, arg *notifyForkcho if len(lastValidHash) == 0 { lastValidHash = defaultLatestValidHash } - invalidRoots, err := s.ForkChoicer().SetOptimisticToInvalid(ctx, headRoot, bytesutil.ToBytes32(headBlk.ParentRoot()), bytesutil.ToBytes32(lastValidHash)) + invalidRoots, err := s.ForkChoicer().SetOptimisticToInvalid(ctx, headRoot, headBlk.ParentRoot(), bytesutil.ToBytes32(lastValidHash)) if err != nil { log.WithError(err).Error("Could not set head root to invalid") return nil, nil @@ -229,7 +229,7 @@ func (s *Service) notifyNewPayload(ctx context.Context, postStateVersion int, if err != nil { return false, err } - invalidRoots, err := s.ForkChoicer().SetOptimisticToInvalid(ctx, root, bytesutil.ToBytes32(blk.Block().ParentRoot()), bytesutil.ToBytes32(lastValidHash)) + invalidRoots, err := s.ForkChoicer().SetOptimisticToInvalid(ctx, root, blk.Block().ParentRoot(), bytesutil.ToBytes32(lastValidHash)) if err != nil { return false, err } @@ -269,7 +269,7 @@ func (s *Service) optimisticCandidateBlock(ctx context.Context, blk interfaces.B if blk.Slot()+params.BeaconConfig().SafeSlotsToImportOptimistically <= s.CurrentSlot() { return nil } - parent, err := s.getBlock(ctx, bytesutil.ToBytes32(blk.ParentRoot())) + parent, err := s.getBlock(ctx, blk.ParentRoot()) if err != nil { return err } diff --git a/beacon-chain/blockchain/head.go b/beacon-chain/blockchain/head.go index a4485ab22a..f7a7cb27cf 100644 --- a/beacon-chain/blockchain/head.go +++ b/beacon-chain/blockchain/head.go @@ -100,7 +100,7 @@ func (s *Service) saveHead(ctx context.Context, newHeadRoot [32]byte, headBlock newStateRoot := headBlock.Block().StateRoot() // A chain re-org occurred, so we fire an event notifying the rest of the services. - if bytesutil.ToBytes32(headBlock.Block().ParentRoot()) != oldHeadRoot { + if headBlock.Block().ParentRoot() != oldHeadRoot { commonRoot, forkSlot, err := s.ForkChoicer().CommonAncestor(ctx, oldHeadRoot, newHeadRoot) if err != nil { log.WithError(err).Error("Could not find common ancestor root") @@ -126,8 +126,8 @@ func (s *Service) saveHead(ctx context.Context, newHeadRoot [32]byte, headBlock Depth: math.Max(uint64(headSlot-forkSlot), uint64(newHeadSlot-forkSlot)), OldHeadBlock: oldHeadRoot[:], NewHeadBlock: newHeadRoot[:], - OldHeadState: oldStateRoot, - NewHeadState: newStateRoot, + OldHeadState: oldStateRoot[:], + NewHeadState: newStateRoot[:], Epoch: slots.ToEpoch(newHeadSlot), ExecutionOptimistic: isOptimistic, }, @@ -152,7 +152,7 @@ func (s *Service) saveHead(ctx context.Context, newHeadRoot [32]byte, headBlock // Forward an event capturing a new chain head over a common event feed // done in a goroutine to avoid blocking the critical runtime main routine. go func() { - if err := s.notifyNewHeadEvent(ctx, newHeadSlot, headState, newStateRoot, newHeadRoot[:]); err != nil { + if err := s.notifyNewHeadEvent(ctx, newHeadSlot, headState, newStateRoot[:], newHeadRoot[:]); err != nil { log.WithError(err).Error("Could not notify event feed of new chain head") } }() @@ -382,7 +382,8 @@ func (s *Service) saveOrphanedAtts(ctx context.Context, orphanedRoot [32]byte, n } saveOrphanedAttCount.Inc() } - orphanedRoot = bytesutil.ToBytes32(orphanedBlk.Block().ParentRoot()) + parentRoot := orphanedBlk.Block().ParentRoot() + orphanedRoot = bytesutil.ToBytes32(parentRoot[:]) } return nil } diff --git a/beacon-chain/blockchain/head_test.go b/beacon-chain/blockchain/head_test.go index e2bc96dffe..638331729b 100644 --- a/beacon-chain/blockchain/head_test.go +++ b/beacon-chain/blockchain/head_test.go @@ -50,7 +50,7 @@ func TestSaveHead_Different(t *testing.T) { require.NoError(t, err) ojc := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]} ofc := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]} - state, blkRoot, err := prepareForkchoiceState(ctx, oldBlock.Block().Slot(), oldRoot, bytesutil.ToBytes32(oldBlock.Block().ParentRoot()), [32]byte{}, ojc, ofc) + state, blkRoot, err := prepareForkchoiceState(ctx, oldBlock.Block().Slot(), oldRoot, oldBlock.Block().ParentRoot(), [32]byte{}, ojc, ofc) require.NoError(t, err) require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot)) service.head = &head{ @@ -66,11 +66,11 @@ func TestSaveHead_Different(t *testing.T) { wsb := util.SaveBlock(t, context.Background(), service.cfg.BeaconDB, newHeadSignedBlock) newRoot, err := newHeadBlock.HashTreeRoot() require.NoError(t, err) - state, blkRoot, err = prepareForkchoiceState(ctx, wsb.Block().Slot()-1, bytesutil.ToBytes32(wsb.Block().ParentRoot()), service.cfg.ForkChoiceStore.CachedHeadRoot(), [32]byte{}, ojc, ofc) + state, blkRoot, err = prepareForkchoiceState(ctx, wsb.Block().Slot()-1, wsb.Block().ParentRoot(), service.cfg.ForkChoiceStore.CachedHeadRoot(), [32]byte{}, ojc, ofc) require.NoError(t, err) require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot)) - state, blkRoot, err = prepareForkchoiceState(ctx, wsb.Block().Slot(), newRoot, bytesutil.ToBytes32(wsb.Block().ParentRoot()), [32]byte{}, ojc, ofc) + state, blkRoot, err = prepareForkchoiceState(ctx, wsb.Block().Slot(), newRoot, wsb.Block().ParentRoot(), [32]byte{}, ojc, ofc) require.NoError(t, err) require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot)) headState, err := util.NewBeaconState() @@ -104,7 +104,7 @@ func TestSaveHead_Different_Reorg(t *testing.T) { require.NoError(t, err) ojc := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]} ofc := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]} - state, blkRoot, err := prepareForkchoiceState(ctx, oldBlock.Block().Slot(), oldRoot, bytesutil.ToBytes32(oldBlock.Block().ParentRoot()), [32]byte{}, ojc, ofc) + state, blkRoot, err := prepareForkchoiceState(ctx, oldBlock.Block().Slot(), oldRoot, oldBlock.Block().ParentRoot(), [32]byte{}, ojc, ofc) require.NoError(t, err) require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot)) service.head = &head{ @@ -114,7 +114,7 @@ func TestSaveHead_Different_Reorg(t *testing.T) { } reorgChainParent := [32]byte{'B'} - state, blkRoot, err = prepareForkchoiceState(ctx, 0, reorgChainParent, oldRoot, bytesutil.ToBytes32(oldBlock.Block().ParentRoot()), ojc, ofc) + state, blkRoot, err = prepareForkchoiceState(ctx, 0, reorgChainParent, oldRoot, oldBlock.Block().ParentRoot(), ojc, ofc) require.NoError(t, err) require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot)) @@ -126,7 +126,7 @@ func TestSaveHead_Different_Reorg(t *testing.T) { wsb := util.SaveBlock(t, context.Background(), service.cfg.BeaconDB, newHeadSignedBlock) newRoot, err := newHeadBlock.HashTreeRoot() require.NoError(t, err) - state, blkRoot, err = prepareForkchoiceState(ctx, wsb.Block().Slot(), newRoot, bytesutil.ToBytes32(wsb.Block().ParentRoot()), [32]byte{}, ojc, ofc) + state, blkRoot, err = prepareForkchoiceState(ctx, wsb.Block().Slot(), newRoot, wsb.Block().ParentRoot(), [32]byte{}, ojc, ofc) require.NoError(t, err) require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot)) headState, err := util.NewBeaconState() diff --git a/beacon-chain/blockchain/log.go b/beacon-chain/blockchain/log.go index 5ea346e673..afe7e4728e 100644 --- a/beacon-chain/blockchain/log.go +++ b/beacon-chain/blockchain/log.go @@ -73,6 +73,7 @@ func logBlockSyncStatus(block interfaces.BeaconBlock, blockRoot [32]byte, justif } level := log.Logger.GetLevel() if level >= logrus.DebugLevel { + parentRoot := block.ParentRoot() log.WithFields(logrus.Fields{ "slot": block.Slot(), "slotInEpoch": block.Slot() % params.BeaconConfig().SlotsPerEpoch, @@ -82,7 +83,7 @@ func logBlockSyncStatus(block interfaces.BeaconBlock, blockRoot [32]byte, justif "justifiedRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(justified.Root)[:8]), "finalizedEpoch": finalized.Epoch, "finalizedRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(finalized.Root)[:8]), - "parentRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(block.ParentRoot())[:8]), + "parentRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(parentRoot[:])[:8]), "version": version.String(block.Version()), "sinceSlotStartTime": prysmTime.Now().Sub(startTime), "chainServiceProcessedTime": prysmTime.Now().Sub(receivedTime), diff --git a/beacon-chain/blockchain/process_block.go b/beacon-chain/blockchain/process_block.go index c81360abcb..e68c0f2ef9 100644 --- a/beacon-chain/blockchain/process_block.go +++ b/beacon-chain/blockchain/process_block.go @@ -248,12 +248,13 @@ func (s *Service) onBlock(ctx context.Context, signed interfaces.SignedBeaconBlo } go func() { // Send an event regarding the new finalized checkpoint over a common event feed. + stateRoot := signed.Block().StateRoot() s.cfg.StateNotifier.StateFeed().Send(&feed.Event{ Type: statefeed.FinalizedCheckpoint, Data: ðpbv1.EventFinalizedCheckpoint{ Epoch: postState.FinalizedCheckpoint().Epoch, Block: postState.FinalizedCheckpoint().Root, - State: signed.Block().StateRoot(), + State: stateRoot[:], ExecutionOptimistic: isOptimistic, }, }) @@ -317,7 +318,7 @@ func (s *Service) onBlockBatch(ctx context.Context, blks []interfaces.SignedBeac if err := s.verifyBlkPreState(ctx, b); err != nil { return err } - preState, err := s.cfg.StateGen.StateByRootInitialSync(ctx, bytesutil.ToBytes32(b.ParentRoot())) + preState, err := s.cfg.StateGen.StateByRootInitialSync(ctx, b.ParentRoot()) if err != nil { return err } @@ -516,7 +517,7 @@ func (s *Service) insertBlockToForkchoiceStore(ctx context.Context, blk interfac ctx, span := trace.StartSpan(ctx, "blockChain.insertBlockToForkchoiceStore") defer span.End() - if !s.cfg.ForkChoiceStore.HasNode(bytesutil.ToBytes32(blk.ParentRoot())) { + if !s.cfg.ForkChoiceStore.HasNode(blk.ParentRoot()) { fCheckpoint := st.FinalizedCheckpoint() jCheckpoint := st.CurrentJustifiedCheckpoint() if err := s.fillInForkChoiceMissingBlocks(ctx, blk, fCheckpoint, jCheckpoint); err != nil { diff --git a/beacon-chain/blockchain/process_block_helpers.go b/beacon-chain/blockchain/process_block_helpers.go index fb1d935d12..980bb3eaed 100644 --- a/beacon-chain/blockchain/process_block_helpers.go +++ b/beacon-chain/blockchain/process_block_helpers.go @@ -39,7 +39,7 @@ func (s *Service) getBlockPreState(ctx context.Context, b interfaces.BeaconBlock return nil, err } - preState, err := s.cfg.StateGen.StateByRoot(ctx, bytesutil.ToBytes32(b.ParentRoot())) + preState, err := s.cfg.StateGen.StateByRoot(ctx, b.ParentRoot()) if err != nil { return nil, errors.Wrapf(err, "could not get pre state for slot %d", b.Slot()) } @@ -65,7 +65,7 @@ func (s *Service) verifyBlkPreState(ctx context.Context, b interfaces.BeaconBloc ctx, span := trace.StartSpan(ctx, "blockChain.verifyBlkPreState") defer span.End() - parentRoot := bytesutil.ToBytes32(b.ParentRoot()) + parentRoot := b.ParentRoot() // Loosen the check to HasBlock because state summary gets saved in batches // during initial syncing. There's no risk given a state summary object is just a // a subset of the block object. @@ -73,7 +73,7 @@ func (s *Service) verifyBlkPreState(ctx context.Context, b interfaces.BeaconBloc return errors.New("could not reconstruct parent state") } - if err := s.VerifyFinalizedBlkDescendant(ctx, bytesutil.ToBytes32(b.ParentRoot())); err != nil { + if err := s.VerifyFinalizedBlkDescendant(ctx, parentRoot); err != nil { return err } @@ -241,7 +241,7 @@ func (s *Service) ancestorByDB(ctx context.Context, r [32]byte, slot types.Slot) return r[:], nil } - return s.ancestorByDB(ctx, bytesutil.ToBytes32(b.ParentRoot()), slot) + return s.ancestorByDB(ctx, b.ParentRoot(), slot) } // This retrieves missing blocks from DB (ie. the blocks that couldn't be received over sync) and inserts them to fork choice store. @@ -259,7 +259,7 @@ func (s *Service) fillInForkChoiceMissingBlocks(ctx context.Context, blk interfa pendingNodes = append(pendingNodes, &forkchoicetypes.BlockAndCheckpoints{Block: blk, JustifiedCheckpoint: jCheckpoint, FinalizedCheckpoint: fCheckpoint}) // As long as parent node is not in fork choice store, and parent node is in DB. - root := bytesutil.ToBytes32(blk.ParentRoot()) + root := blk.ParentRoot() for !s.cfg.ForkChoiceStore.HasNode(root) && s.cfg.BeaconDB.HasBlock(ctx, root) { b, err := s.getBlock(ctx, root) if err != nil { @@ -268,7 +268,7 @@ func (s *Service) fillInForkChoiceMissingBlocks(ctx context.Context, blk interfa if b.Block().Slot() <= fSlot { break } - root = bytesutil.ToBytes32(b.Block().ParentRoot()) + root = b.Block().ParentRoot() args := &forkchoicetypes.BlockAndCheckpoints{Block: b.Block(), JustifiedCheckpoint: jCheckpoint, FinalizedCheckpoint: fCheckpoint} diff --git a/beacon-chain/blockchain/process_block_test.go b/beacon-chain/blockchain/process_block_test.go index 6853eca7c9..49ab24f5bd 100644 --- a/beacon-chain/blockchain/process_block_test.go +++ b/beacon-chain/blockchain/process_block_test.go @@ -1756,7 +1756,7 @@ func TestOnBlock_ProcessBlocksParallel(t *testing.T) { logHook := logTest.NewGlobal() for i := 0; i < 10; i++ { fc := ðpb.Checkpoint{} - st, blkRoot, err := prepareForkchoiceState(ctx, 0, bytesutil.ToBytes32(wsb1.Block().ParentRoot()), [32]byte{}, [32]byte{}, fc, fc) + st, blkRoot, err := prepareForkchoiceState(ctx, 0, wsb1.Block().ParentRoot(), [32]byte{}, [32]byte{}, fc, fc) require.NoError(t, err) require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot)) var wg sync.WaitGroup diff --git a/beacon-chain/blockchain/testing/mock.go b/beacon-chain/blockchain/testing/mock.go index 7ff3bf250d..13d2746b25 100644 --- a/beacon-chain/blockchain/testing/mock.go +++ b/beacon-chain/blockchain/testing/mock.go @@ -174,7 +174,8 @@ func (s *ChainService) ReceiveBlockInitialSync(ctx context.Context, block interf if s.State == nil { return ErrNilState } - if !bytes.Equal(s.Root, block.Block().ParentRoot()) { + parentRoot := block.Block().ParentRoot() + if !bytes.Equal(s.Root, parentRoot[:]) { return errors.Errorf("wanted %#x but got %#x", s.Root, block.Block().ParentRoot()) } if err := s.State.SetSlot(block.Block().Slot()); err != nil { @@ -202,7 +203,8 @@ func (s *ChainService) ReceiveBlockBatch(ctx context.Context, blks []interfaces. return ErrNilState } for _, b := range blks { - if !bytes.Equal(s.Root, b.Block().ParentRoot()) { + parentRoot := b.Block().ParentRoot() + if !bytes.Equal(s.Root, parentRoot[:]) { return errors.Errorf("wanted %#x but got %#x", s.Root, b.Block().ParentRoot()) } if err := s.State.SetSlot(b.Block().Slot()); err != nil { @@ -233,7 +235,8 @@ func (s *ChainService) ReceiveBlock(ctx context.Context, block interfaces.Signed if s.State == nil { return ErrNilState } - if !bytes.Equal(s.Root, block.Block().ParentRoot()) { + parentRoot := block.Block().ParentRoot() + if !bytes.Equal(s.Root, parentRoot[:]) { return errors.Errorf("wanted %#x but got %#x", s.Root, block.Block().ParentRoot()) } if err := s.State.SetSlot(block.Block().Slot()); err != nil { diff --git a/beacon-chain/core/blocks/block_operations_fuzz_test.go b/beacon-chain/core/blocks/block_operations_fuzz_test.go index f289d90bc0..cb2ecd1e96 100644 --- a/beacon-chain/core/blocks/block_operations_fuzz_test.go +++ b/beacon-chain/core/blocks/block_operations_fuzz_test.go @@ -42,7 +42,7 @@ func TestFuzzProcessBlockHeader_10000(t *testing.T) { s, err := v1.InitializeFromProtoUnsafe(state) require.NoError(t, err) - if block.Block == nil || block.Block.Body == nil { + if block.Block == nil || block.Block.Body == nil || block.Block.Body.Eth1Data == nil { continue } wsb, err := blocks.NewSignedBeaconBlock(block) diff --git a/beacon-chain/core/blocks/header.go b/beacon-chain/core/blocks/header.go index 789d9d0a51..9c391cb3a7 100644 --- a/beacon-chain/core/blocks/header.go +++ b/beacon-chain/core/blocks/header.go @@ -51,13 +51,15 @@ func ProcessBlockHeader( if err != nil { return nil, err } - beaconState, err = ProcessBlockHeaderNoVerify(ctx, beaconState, block.Block().Slot(), block.Block().ProposerIndex(), block.Block().ParentRoot(), bodyRoot[:]) + parentRoot := block.Block().ParentRoot() + beaconState, err = ProcessBlockHeaderNoVerify(ctx, beaconState, block.Block().Slot(), block.Block().ProposerIndex(), parentRoot[:], bodyRoot[:]) if err != nil { return nil, err } // Verify proposer signature. - if err := VerifyBlockSignature(beaconState, block.Block().ProposerIndex(), block.Signature(), block.Block().HashTreeRoot); err != nil { + sig := block.Signature() + if err := VerifyBlockSignature(beaconState, block.Block().ProposerIndex(), sig[:], block.Block().HashTreeRoot); err != nil { return nil, err } diff --git a/beacon-chain/core/blocks/randao.go b/beacon-chain/core/blocks/randao.go index 1095ed4019..8323b563a0 100644 --- a/beacon-chain/core/blocks/randao.go +++ b/beacon-chain/core/blocks/randao.go @@ -39,11 +39,13 @@ func ProcessRandao( if err != nil { return nil, err } - if err := verifySignature(buf, proposerPub, body.RandaoReveal(), domain); err != nil { + + randaoReveal := body.RandaoReveal() + if err := verifySignature(buf, proposerPub, randaoReveal[:], domain); err != nil { return nil, errors.Wrap(err, "could not verify block randao") } - beaconState, err = ProcessRandaoNoVerify(beaconState, body.RandaoReveal()) + beaconState, err = ProcessRandaoNoVerify(beaconState, randaoReveal[:]) if err != nil { return nil, errors.Wrap(err, "could not process randao") } diff --git a/beacon-chain/core/blocks/signature.go b/beacon-chain/core/blocks/signature.go index 439f028150..9ba4afd716 100644 --- a/beacon-chain/core/blocks/signature.go +++ b/beacon-chain/core/blocks/signature.go @@ -113,7 +113,8 @@ func VerifyBlockSignatureUsingCurrentFork(beaconState state.ReadOnlyBeaconState, return err } proposerPubKey := proposer.PublicKey - return signing.VerifyBlockSigningRoot(proposerPubKey, blk.Signature(), domain, blk.Block().HashTreeRoot) + sig := blk.Signature() + return signing.VerifyBlockSigningRoot(proposerPubKey, sig[:], domain, blk.Block().HashTreeRoot) } // BlockSignatureBatch retrieves the block signature batch from the provided block and its corresponding state. diff --git a/beacon-chain/core/transition/transition_fuzz_test.go b/beacon-chain/core/transition/transition_fuzz_test.go index c84f0f8c19..91ef016487 100644 --- a/beacon-chain/core/transition/transition_fuzz_test.go +++ b/beacon-chain/core/transition/transition_fuzz_test.go @@ -184,7 +184,7 @@ func TestFuzzProcessBlockForStateRoot_1000(t *testing.T) { for i := 0; i < 1000; i++ { fuzzer.Fuzz(state) fuzzer.Fuzz(sb) - if sb.Block == nil || sb.Block.Body == nil { + if sb.Block == nil || sb.Block.Body == nil || sb.Block.Body.Eth1Data == nil { continue } wsb, err := blocks.NewSignedBeaconBlock(sb) diff --git a/beacon-chain/core/transition/transition_no_verify_sig.go b/beacon-chain/core/transition/transition_no_verify_sig.go index 38ebee00d8..4fb8ba5074 100644 --- a/beacon-chain/core/transition/transition_no_verify_sig.go +++ b/beacon-chain/core/transition/transition_no_verify_sig.go @@ -59,7 +59,8 @@ func ExecuteStateTransitionNoVerifyAnySig( interop.WriteBlockToDisk(signed, false /* Has the block failed */) interop.WriteStateToDisk(st) - st, err = ProcessSlotsUsingNextSlotCache(ctx, st, signed.Block().ParentRoot(), signed.Block().Slot()) + parentRoot := signed.Block().ParentRoot() + st, err = ProcessSlotsUsingNextSlotCache(ctx, st, parentRoot[:], signed.Block().Slot()) if err != nil { return nil, nil, errors.Wrap(err, "could not process slots") } @@ -75,7 +76,8 @@ func ExecuteStateTransitionNoVerifyAnySig( if err != nil { return nil, nil, err } - if !bytes.Equal(postStateRoot[:], signed.Block().StateRoot()) { + stateRoot := signed.Block().StateRoot() + if !bytes.Equal(postStateRoot[:], stateRoot[:]) { return nil, nil, fmt.Errorf("could not validate state root, wanted: %#x, received: %#x", postStateRoot[:], signed.Block().StateRoot()) } @@ -127,7 +129,8 @@ func CalculateStateRoot( // Execute per slots transition. var err error - state, err = ProcessSlotsUsingNextSlotCache(ctx, state, signed.Block().ParentRoot(), signed.Block().Slot()) + parentRoot := signed.Block().ParentRoot() + state, err = ProcessSlotsUsingNextSlotCache(ctx, state, parentRoot[:], signed.Block().Slot()) if err != nil { return [32]byte{}, errors.Wrap(err, "could not process slots") } @@ -174,12 +177,14 @@ func ProcessBlockNoVerifyAnySig( return nil, nil, err } - bSet, err := b.BlockSignatureBatch(st, blk.ProposerIndex(), signed.Signature(), blk.HashTreeRoot) + sig := signed.Signature() + bSet, err := b.BlockSignatureBatch(st, blk.ProposerIndex(), sig[:], blk.HashTreeRoot) if err != nil { tracing.AnnotateError(span, err) return nil, nil, errors.Wrap(err, "could not retrieve block signature set") } - rSet, err := b.RandaoSignatureBatch(ctx, st, signed.Block().Body().RandaoReveal()) + randaoReveal := signed.Block().Body().RandaoReveal() + rSet, err := b.RandaoSignatureBatch(ctx, st, randaoReveal[:]) if err != nil { tracing.AnnotateError(span, err) return nil, nil, errors.Wrap(err, "could not retrieve randao signature set") @@ -279,7 +284,8 @@ func ProcessBlockForStateRoot( if err != nil { return nil, errors.Wrap(err, "could not hash tree root beacon block body") } - state, err = b.ProcessBlockHeaderNoVerify(ctx, state, blk.Slot(), blk.ProposerIndex(), blk.ParentRoot(), bodyRoot[:]) + parentRoot := blk.ParentRoot() + state, err = b.ProcessBlockHeaderNoVerify(ctx, state, blk.Slot(), blk.ProposerIndex(), parentRoot[:], bodyRoot[:]) if err != nil { tracing.AnnotateError(span, err) return nil, errors.Wrap(err, "could not process block header") @@ -304,7 +310,8 @@ func ProcessBlockForStateRoot( } } - state, err = b.ProcessRandaoNoVerify(state, signed.Block().Body().RandaoReveal()) + randaoReveal := signed.Block().Body().RandaoReveal() + state, err = b.ProcessRandaoNoVerify(state, randaoReveal[:]) if err != nil { tracing.AnnotateError(span, err) return nil, errors.Wrap(err, "could not verify and process randao") diff --git a/beacon-chain/db/kv/blocks.go b/beacon-chain/db/kv/blocks.go index fcbdba229b..9e07c423d0 100644 --- a/beacon-chain/db/kv/blocks.go +++ b/beacon-chain/db/kv/blocks.go @@ -722,10 +722,10 @@ func createBlockIndicesFromBlock(ctx context.Context, block interfaces.BeaconBlo indices := [][]byte{ bytesutil.SlotToBytesBigEndian(block.Slot()), } - if block.ParentRoot() != nil && len(block.ParentRoot()) > 0 { - buckets = append(buckets, blockParentRootIndicesBucket) - indices = append(indices, block.ParentRoot()) - } + buckets = append(buckets, blockParentRootIndicesBucket) + parentRoot := block.ParentRoot() + indices = append(indices, parentRoot[:]) + for i := 0; i < len(buckets); i++ { indicesByBucket[string(buckets[i])] = indices[i] } diff --git a/beacon-chain/db/kv/finalized_block_roots.go b/beacon-chain/db/kv/finalized_block_roots.go index 01faa59adc..11babf77fc 100644 --- a/beacon-chain/db/kv/finalized_block_roots.go +++ b/beacon-chain/db/kv/finalized_block_roots.go @@ -90,8 +90,9 @@ func (s *Store) updateFinalizedBlockRoots(ctx context.Context, tx *bolt.Tx, chec } block := signedBlock.Block() + parentRoot := block.ParentRoot() container := ðpb.FinalizedBlockRootContainer{ - ParentRoot: block.ParentRoot(), + ParentRoot: parentRoot[:], ChildRoot: previousRoot, } @@ -112,7 +113,8 @@ func (s *Store) updateFinalizedBlockRoots(ctx context.Context, tx *bolt.Tx, chec } // Found parent, loop exit condition. - if parentBytes := bkt.Get(block.ParentRoot()); parentBytes != nil { + pr := block.ParentRoot() + if parentBytes := bkt.Get(pr[:]); parentBytes != nil { parent := ðpb.FinalizedBlockRootContainer{} if err := decode(ctx, parentBytes, parent); err != nil { tracing.AnnotateError(span, err) @@ -124,14 +126,14 @@ func (s *Store) updateFinalizedBlockRoots(ctx context.Context, tx *bolt.Tx, chec tracing.AnnotateError(span, err) return err } - if err := bkt.Put(block.ParentRoot(), enc); err != nil { + if err := bkt.Put(pr[:], enc); err != nil { tracing.AnnotateError(span, err) return err } break } previousRoot = root - root = block.ParentRoot() + root = pr[:] } // Upsert blocks from the current finalized epoch. diff --git a/beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go b/beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go index 1b785cf123..917c8b015b 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go @@ -552,8 +552,8 @@ func (f *ForkChoice) InsertOptimisticChain(ctx context.Context, chain []*forkcho } for i := len(chain) - 1; i > 0; i-- { b := chain[i].Block - r := bytesutil.ToBytes32(chain[i-1].Block.ParentRoot()) - parentRoot := bytesutil.ToBytes32(b.ParentRoot()) + r := chain[i-1].Block.ParentRoot() + parentRoot := b.ParentRoot() payloadHash, err := blocks.GetBlockPayloadHash(b) if err != nil { return err diff --git a/beacon-chain/forkchoice/protoarray/store.go b/beacon-chain/forkchoice/protoarray/store.go index c6ba356958..b47564e965 100644 --- a/beacon-chain/forkchoice/protoarray/store.go +++ b/beacon-chain/forkchoice/protoarray/store.go @@ -1003,8 +1003,8 @@ func (f *ForkChoice) InsertOptimisticChain(ctx context.Context, chain []*forkcho } for i := len(chain) - 1; i > 0; i-- { b := chain[i].Block - r := bytesutil.ToBytes32(chain[i-1].Block.ParentRoot()) - parentRoot := bytesutil.ToBytes32(b.ParentRoot()) + r := chain[i-1].Block.ParentRoot() + parentRoot := b.ParentRoot() payloadHash, err := blocks.GetBlockPayloadHash(b) if err != nil { return err diff --git a/beacon-chain/monitor/process_block.go b/beacon-chain/monitor/process_block.go index 72d2a90640..e15dd50321 100644 --- a/beacon-chain/monitor/process_block.go +++ b/beacon-chain/monitor/process_block.go @@ -88,11 +88,12 @@ func (s *Service) processProposedBlock(state state.BeaconState, root [32]byte, b aggPerf.totalProposedCount++ s.aggregatedPerformance[blk.ProposerIndex()] = aggPerf + parentRoot := blk.ParentRoot() log.WithFields(logrus.Fields{ "ProposerIndex": blk.ProposerIndex(), "Slot": blk.Slot(), "Version": blk.Version(), - "ParentRoot": fmt.Sprintf("%#x", bytesutil.Trunc(blk.ParentRoot())), + "ParentRoot": fmt.Sprintf("%#x", bytesutil.Trunc(parentRoot[:])), "BlockRoot": fmt.Sprintf("%#x", bytesutil.Trunc(root[:])), "NewBalance": balance, "BalanceChange": balanceChg, diff --git a/beacon-chain/rpc/eth/beacon/blocks.go b/beacon-chain/rpc/eth/beacon/blocks.go index c47ce92a28..8a9e82b71b 100644 --- a/beacon-chain/rpc/eth/beacon/blocks.go +++ b/beacon-chain/rpc/eth/beacon/blocks.go @@ -78,7 +78,7 @@ func (bs *Server) GetWeakSubjectivity(ctx context.Context, _ *empty.Empty) (*eth if err != nil { return nil, status.Errorf(codes.Internal, fmt.Sprintf("block with root %#x from slot index %d not found in db", cbr, wsSlot)) } - stateRoot := bytesutil.ToBytes32(cb.Block().StateRoot()) + stateRoot := cb.Block().StateRoot() log.Printf("weak subjectivity checkpoint reported as epoch=%d, block root=%#x, state root=%#x", wsEpoch, cbr, stateRoot) return ðpbv1.WeakSubjectivityResponse{ Data: ðpbv1.WeakSubjectivityData{ @@ -434,11 +434,12 @@ func (bs *Server) GetBlockV2(ctx context.Context, req *ethpbv2.BlockRequestV2) ( if err != nil { return nil, status.Errorf(codes.Internal, "Could not get signed beacon block: %v", err) } + sig := blk.Signature() return ðpbv2.BlockResponseV2{ Version: ethpbv2.Version_ALTAIR, Data: ðpbv2.SignedBeaconBlockContainer{ Message: ðpbv2.SignedBeaconBlockContainer_AltairBlock{AltairBlock: v2Blk}, - Signature: blk.Signature(), + Signature: sig[:], }, ExecutionOptimistic: false, }, nil @@ -465,11 +466,12 @@ func (bs *Server) GetBlockV2(ctx context.Context, req *ethpbv2.BlockRequestV2) ( if err != nil { return nil, status.Errorf(codes.Internal, "Could not check if block is optimistic: %v", err) } + sig := blk.Signature() return ðpbv2.BlockResponseV2{ Version: ethpbv2.Version_BELLATRIX, Data: ðpbv2.SignedBeaconBlockContainer{ Message: ðpbv2.SignedBeaconBlockContainer_BellatrixBlock{BellatrixBlock: v2Blk}, - Signature: blk.Signature(), + Signature: sig[:], }, ExecutionOptimistic: isOptimistic, }, nil @@ -499,11 +501,12 @@ func (bs *Server) GetBlockV2(ctx context.Context, req *ethpbv2.BlockRequestV2) ( if err != nil { return nil, status.Errorf(codes.Internal, "Could not check if block is optimistic: %v", err) } + sig := blk.Signature() return ðpbv2.BlockResponseV2{ Version: ethpbv2.Version_BELLATRIX, Data: ðpbv2.SignedBeaconBlockContainer{ Message: ðpbv2.SignedBeaconBlockContainer_BellatrixBlock{BellatrixBlock: v2Blk}, - Signature: blk.Signature(), + Signature: sig[:], }, ExecutionOptimistic: isOptimistic, }, nil @@ -553,9 +556,10 @@ func (bs *Server) GetBlockSSZV2(ctx context.Context, req *ethpbv2.BlockRequestV2 if err != nil { return nil, status.Errorf(codes.Internal, "Could not get signed beacon block: %v", err) } + sig := blk.Signature() data := ðpbv2.SignedBeaconBlockAltair{ Message: v2Blk, - Signature: blk.Signature(), + Signature: sig[:], } sszData, err := data.MarshalSSZ() if err != nil { @@ -577,9 +581,10 @@ func (bs *Server) GetBlockSSZV2(ctx context.Context, req *ethpbv2.BlockRequestV2 if err != nil { return nil, status.Errorf(codes.Internal, "Could not get signed beacon block: %v", err) } + sig := blk.Signature() data := ðpbv2.SignedBeaconBlockBellatrix{ Message: v2Blk, - Signature: blk.Signature(), + Signature: sig[:], } sszData, err := data.MarshalSSZ() if err != nil { @@ -605,9 +610,10 @@ func (bs *Server) GetBlockSSZV2(ctx context.Context, req *ethpbv2.BlockRequestV2 if err != nil { return nil, status.Errorf(codes.Internal, "Could not get signed beacon block: %v", err) } + sig := blk.Signature() data := ðpbv2.SignedBeaconBlockBellatrix{ Message: v2Blk, - Signature: blk.Signature(), + Signature: sig[:], } sszData, err := data.MarshalSSZ() if err != nil { diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks.go index 6d8d52817b..7689f95b01 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks.go @@ -302,7 +302,8 @@ func (bs *Server) StreamBlocks(req *ethpb.StreamBlocksRequest, stream ethpb.Beac continue } signed := data.SignedBlock - if err := blocks.VerifyBlockSignature(headState, signed.Block().ProposerIndex(), signed.Signature(), signed.Block().HashTreeRoot); err != nil { + sig := signed.Signature() + if err := blocks.VerifyBlockSignature(headState, signed.Block().ProposerIndex(), sig[:], signed.Block().HashTreeRoot); err != nil { log.WithError(err).WithField("blockSlot", data.SignedBlock.Block().Slot()).Error("Could not verify block signature") continue } diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/blocks.go b/beacon-chain/rpc/prysm/v1alpha1/validator/blocks.go index e2f2d1d336..9cd2dadfeb 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/blocks.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/blocks.go @@ -119,7 +119,8 @@ func (vs *Server) sendBlocks(stream ethpb.BeaconNodeValidator_StreamBlocksAltair return nil } signed := data.SignedBlock - if err := blocks.VerifyBlockSignature(headState, signed.Block().ProposerIndex(), signed.Signature(), signed.Block().HashTreeRoot); err != nil { + sig := signed.Signature() + if err := blocks.VerifyBlockSignature(headState, signed.Block().ProposerIndex(), sig[:], signed.Block().HashTreeRoot); err != nil { log.WithError(err).Error("Could not verify block signature") return nil } diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go index 4efd2f5ccc..a33454e314 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go @@ -165,7 +165,7 @@ func (vs *Server) proposeGenericBeaconBlock(ctx context.Context, blk interfaces. // computeStateRoot computes the state root after a block has been processed through a state transition and // returns it to the validator client. func (vs *Server) computeStateRoot(ctx context.Context, block interfaces.SignedBeaconBlock) ([]byte, error) { - beaconState, err := vs.StateGen.StateByRoot(ctx, bytesutil.ToBytes32(block.Block().ParentRoot())) + beaconState, err := vs.StateGen.StateByRoot(ctx, block.Block().ParentRoot()) if err != nil { return nil, errors.Wrap(err, "could not retrieve beacon state") } diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix.go index dfc27f4760..d4b01bc5e4 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix.go @@ -235,16 +235,21 @@ func (vs *Server) unblindBuilderBlock(ctx context.Context, b interfaces.SignedBe if !ok { return nil, errors.New("execution data must be execution payload header") } + parentRoot := b.Block().ParentRoot() + stateRoot := b.Block().StateRoot() + randaoReveal := b.Block().Body().RandaoReveal() + graffiti := b.Block().Body().Graffiti() + sig := b.Signature() sb := ðpb.SignedBlindedBeaconBlockBellatrix{ Block: ðpb.BlindedBeaconBlockBellatrix{ Slot: b.Block().Slot(), ProposerIndex: b.Block().ProposerIndex(), - ParentRoot: b.Block().ParentRoot(), - StateRoot: b.Block().StateRoot(), + ParentRoot: parentRoot[:], + StateRoot: stateRoot[:], Body: ðpb.BlindedBeaconBlockBodyBellatrix{ - RandaoReveal: b.Block().Body().RandaoReveal(), + RandaoReveal: randaoReveal[:], Eth1Data: b.Block().Body().Eth1Data(), - Graffiti: b.Block().Body().Graffiti(), + Graffiti: graffiti[:], ProposerSlashings: b.Block().Body().ProposerSlashings(), AttesterSlashings: b.Block().Body().AttesterSlashings(), Attestations: b.Block().Body().Attestations(), @@ -254,7 +259,7 @@ func (vs *Server) unblindBuilderBlock(ctx context.Context, b interfaces.SignedBe ExecutionPayloadHeader: header, }, }, - Signature: b.Signature(), + Signature: sig[:], } payload, err := vs.BlockBuilder.SubmitBlindedBlock(ctx, sb) diff --git a/beacon-chain/rpc/statefetcher/fetcher.go b/beacon-chain/rpc/statefetcher/fetcher.go index e33117677b..a13cffc1d7 100644 --- a/beacon-chain/rpc/statefetcher/fetcher.go +++ b/beacon-chain/rpc/statefetcher/fetcher.go @@ -223,7 +223,8 @@ func (p *StateProvider) headStateRoot(ctx context.Context) ([]byte, error) { if err = blocks.BeaconBlockIsNil(b); err != nil { return nil, err } - return b.Block().StateRoot(), nil + stateRoot := b.Block().StateRoot() + return stateRoot[:], nil } func (p *StateProvider) genesisStateRoot(ctx context.Context) ([]byte, error) { @@ -234,7 +235,8 @@ func (p *StateProvider) genesisStateRoot(ctx context.Context) ([]byte, error) { if err := blocks.BeaconBlockIsNil(b); err != nil { return nil, err } - return b.Block().StateRoot(), nil + stateRoot := b.Block().StateRoot() + return stateRoot[:], nil } func (p *StateProvider) finalizedStateRoot(ctx context.Context) ([]byte, error) { @@ -249,7 +251,8 @@ func (p *StateProvider) finalizedStateRoot(ctx context.Context) ([]byte, error) if err := blocks.BeaconBlockIsNil(b); err != nil { return nil, err } - return b.Block().StateRoot(), nil + stateRoot := b.Block().StateRoot() + return stateRoot[:], nil } func (p *StateProvider) justifiedStateRoot(ctx context.Context) ([]byte, error) { @@ -264,7 +267,8 @@ func (p *StateProvider) justifiedStateRoot(ctx context.Context) ([]byte, error) if err := blocks.BeaconBlockIsNil(b); err != nil { return nil, err } - return b.Block().StateRoot(), nil + stateRoot := b.Block().StateRoot() + return stateRoot[:], nil } func (p *StateProvider) stateRootByRoot(ctx context.Context, stateRoot []byte) ([]byte, error) { @@ -302,5 +306,6 @@ func (p *StateProvider) stateRootBySlot(ctx context.Context, slot types.Slot) ([ if blks[0] == nil || blks[0].Block() == nil { return nil, errors.New("nil block") } - return blks[0].Block().StateRoot(), nil + stateRoot := blks[0].Block().StateRoot() + return stateRoot[:], nil } diff --git a/beacon-chain/rpc/statefetcher/fetcher_test.go b/beacon-chain/rpc/statefetcher/fetcher_test.go index 5487f98ebf..deba4b5571 100644 --- a/beacon-chain/rpc/statefetcher/fetcher_test.go +++ b/beacon-chain/rpc/statefetcher/fetcher_test.go @@ -241,7 +241,8 @@ func TestGetStateRoot(t *testing.T) { require.NoError(t, err) genesisBlock, err := db.GenesisBlock(ctx) require.NoError(t, err) - assert.DeepEqual(t, genesisBlock.Block().StateRoot(), s) + sr := genesisBlock.Block().StateRoot() + assert.DeepEqual(t, sr[:], s) }) t.Run("finalized", func(t *testing.T) { diff --git a/beacon-chain/state/stategen/getter.go b/beacon-chain/state/stategen/getter.go index 50969209d5..508db1be21 100644 --- a/beacon-chain/state/stategen/getter.go +++ b/beacon-chain/state/stategen/getter.go @@ -237,7 +237,7 @@ func (s *State) latestAncestor(ctx context.Context, blockRoot [32]byte) (state.B } // Is the state the genesis state. - parentRoot := bytesutil.ToBytes32(b.Block().ParentRoot()) + parentRoot := b.Block().ParentRoot() if parentRoot == params.BeaconConfig().ZeroHash { s, err := s.beaconDB.GenesisState(ctx) return s, errors.Wrap(err, "could not get genesis state") diff --git a/beacon-chain/state/stategen/history.go b/beacon-chain/state/stategen/history.go index f6e45cf4c3..e08a62324c 100644 --- a/beacon-chain/state/stategen/history.go +++ b/beacon-chain/state/stategen/history.go @@ -11,7 +11,6 @@ import ( "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" "go.opencensus.io/trace" ) @@ -172,7 +171,7 @@ func (c *CanonicalHistory) ancestorChain(ctx context.Context, tail interfaces.Si if err != nil && !errors.Is(err, db.ErrNotFoundState) { return nil, nil, errors.Wrap(err, fmt.Sprintf("error querying database for state w/ block root = %#x", root)) } - parent, err := c.h.Block(ctx, bytesutil.ToBytes32(b.ParentRoot())) + parent, err := c.h.Block(ctx, b.ParentRoot()) if err != nil { msg := fmt.Sprintf("db error when retrieving parent of block at slot=%d by root=%#x", b.Slot(), b.ParentRoot()) return nil, nil, errors.Wrap(err, msg) diff --git a/beacon-chain/state/stategen/mock_test.go b/beacon-chain/state/stategen/mock_test.go index 55ab4ba27e..00b6594daf 100644 --- a/beacon-chain/state/stategen/mock_test.go +++ b/beacon-chain/state/stategen/mock_test.go @@ -16,7 +16,6 @@ import ( blocktest "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks/testing" "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" "github.com/prysmaticlabs/prysm/v3/testing/require" "github.com/prysmaticlabs/prysm/v3/testing/util" ) @@ -65,7 +64,7 @@ func TestMockHistoryParentRoot(t *testing.T) { endBlock, err := hist.Block(ctx, endRoot) require.NoError(t, err) // middle should be the parent of end, compare the middle root to endBlock's parent root - require.Equal(t, hist.slotMap[middle], bytesutil.ToBytes32(endBlock.Block().ParentRoot())) + require.Equal(t, hist.slotMap[middle], endBlock.Block().ParentRoot()) } type mockHistorySpec struct { diff --git a/beacon-chain/state/stategen/replay.go b/beacon-chain/state/stategen/replay.go index 5de04e377d..2373260e84 100644 --- a/beacon-chain/state/stategen/replay.go +++ b/beacon-chain/state/stategen/replay.go @@ -15,7 +15,6 @@ import ( "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" "github.com/prysmaticlabs/prysm/v3/monitoring/tracing" "github.com/prysmaticlabs/prysm/v3/runtime/version" "github.com/sirupsen/logrus" @@ -124,7 +123,7 @@ func (s *State) loadBlocks(ctx context.Context, startSlot, endSlot types.Slot, e return nil, ctx.Err() } b := filteredBlocks[len(filteredBlocks)-1] - if bytesutil.ToBytes32(b.Block().ParentRoot()) != blockRoots[i] { + if b.Block().ParentRoot() != blockRoots[i] { continue } filteredBlocks = append(filteredBlocks, blocks[i]) diff --git a/beacon-chain/state/stategen/replayer_test.go b/beacon-chain/state/stategen/replayer_test.go index 52073ce969..c2565c4f91 100644 --- a/beacon-chain/state/stategen/replayer_test.go +++ b/beacon-chain/state/stategen/replayer_test.go @@ -16,12 +16,14 @@ func headerFromBlock(b interfaces.SignedBeaconBlock) (*ethpb.BeaconBlockHeader, if err != nil { return nil, err } + stateRoot := b.Block().StateRoot() + parentRoot := b.Block().ParentRoot() return ðpb.BeaconBlockHeader{ Slot: b.Block().Slot(), - StateRoot: b.Block().StateRoot(), + StateRoot: stateRoot[:], ProposerIndex: b.Block().ProposerIndex(), BodyRoot: bodyRoot[:], - ParentRoot: b.Block().ParentRoot(), + ParentRoot: parentRoot[:], }, nil } diff --git a/beacon-chain/sync/initial-sync/BUILD.bazel b/beacon-chain/sync/initial-sync/BUILD.bazel index bda429acd4..aef520e277 100644 --- a/beacon-chain/sync/initial-sync/BUILD.bazel +++ b/beacon-chain/sync/initial-sync/BUILD.bazel @@ -32,7 +32,6 @@ go_library( "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//crypto/rand:go_default_library", - "//encoding/bytesutil:go_default_library", "//math:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//runtime:go_default_library", diff --git a/beacon-chain/sync/initial-sync/blocks_fetcher_utils.go b/beacon-chain/sync/initial-sync/blocks_fetcher_utils.go index 6b98cb23ff..31f937d24b 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher_utils.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher_utils.go @@ -12,7 +12,6 @@ import ( "github.com/prysmaticlabs/prysm/v3/config/params" "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" p2ppb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/time/slots" "github.com/sirupsen/logrus" @@ -237,7 +236,7 @@ func (f *blocksFetcher) findForkWithPeer(ctx context.Context, pid peer.ID, slot // Traverse blocks, and if we've got one that doesn't have parent in DB, backtrack on it. for i, block := range blocks { - parentRoot := bytesutil.ToBytes32(block.Block().ParentRoot()) + parentRoot := block.Block().ParentRoot() if !f.chain.HasBlock(ctx, parentRoot) { log.WithFields(logrus.Fields{ "peer": pid, @@ -264,7 +263,7 @@ func (f *blocksFetcher) findForkWithPeer(ctx context.Context, pid peer.ID, slot func (f *blocksFetcher) findAncestor(ctx context.Context, pid peer.ID, b interfaces.SignedBeaconBlock) (*forkData, error) { outBlocks := []interfaces.SignedBeaconBlock{b} for i := uint64(0); i < backtrackingMaxHops; i++ { - parentRoot := bytesutil.ToBytes32(outBlocks[len(outBlocks)-1].Block().ParentRoot()) + parentRoot := outBlocks[len(outBlocks)-1].Block().ParentRoot() if f.chain.HasBlock(ctx, parentRoot) { // Common ancestor found, forward blocks back to processor. sort.Slice(outBlocks, func(i, j int) bool { diff --git a/beacon-chain/sync/initial-sync/blocks_queue_test.go b/beacon-chain/sync/initial-sync/blocks_queue_test.go index 111fcf1547..2dc65dd8af 100644 --- a/beacon-chain/sync/initial-sync/blocks_queue_test.go +++ b/beacon-chain/sync/initial-sync/blocks_queue_test.go @@ -255,7 +255,7 @@ func TestBlocksQueue_Loop(t *testing.T) { }) assert.NoError(t, queue.start()) processBlock := func(block interfaces.SignedBeaconBlock) error { - if !beaconDB.HasBlock(ctx, bytesutil.ToBytes32(block.Block().ParentRoot())) { + if !beaconDB.HasBlock(ctx, block.Block().ParentRoot()) { return fmt.Errorf("%w: %#x", errParentDoesNotExist, block.Block().ParentRoot()) } root, err := block.Block().HashTreeRoot() @@ -1336,7 +1336,7 @@ func TestBlocksQueue_stuckWhenHeadIsSetToOrphanedBlock(t *testing.T) { continue } - parentRoot := bytesutil.ToBytes32(blk.Block().ParentRoot()) + parentRoot := blk.Block().ParentRoot() if !beaconDB.HasBlock(ctx, parentRoot) && !mc.HasBlock(ctx, parentRoot) { log.Errorf("%v: %#x", errParentDoesNotExist, blk.Block().ParentRoot()) continue diff --git a/beacon-chain/sync/initial-sync/round_robin.go b/beacon-chain/sync/initial-sync/round_robin.go index 1bc00ce2ea..7ad0366d24 100644 --- a/beacon-chain/sync/initial-sync/round_robin.go +++ b/beacon-chain/sync/initial-sync/round_robin.go @@ -1,7 +1,6 @@ package initialsync import ( - "bytes" "context" "encoding/hex" "errors" @@ -13,7 +12,6 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" "github.com/prysmaticlabs/prysm/v3/time/slots" "github.com/sirupsen/logrus" ) @@ -240,8 +238,7 @@ func (s *Service) processBlock( } s.logSyncStatus(genesis, blk.Block(), blkRoot) - parentRoot := bytesutil.ToBytes32(blk.Block().ParentRoot()) - if !s.cfg.Chain.HasBlock(ctx, parentRoot) { + if !s.cfg.Chain.HasBlock(ctx, blk.Block().ParentRoot()) { return fmt.Errorf("%w: (in processBlock, slot=%d) %#x", errParentDoesNotExist, blk.Block().Slot(), blk.Block().ParentRoot()) } return blockReceiver(ctx, blk, blkRoot) @@ -270,7 +267,7 @@ func (s *Service) processBatchedBlocks(ctx context.Context, genesis time.Time, } } s.logBatchSyncStatus(genesis, blks, blkRoot) - parentRoot := bytesutil.ToBytes32(firstBlock.Block().ParentRoot()) + parentRoot := firstBlock.Block().ParentRoot() if !s.cfg.Chain.HasBlock(ctx, parentRoot) { return fmt.Errorf("%w: %#x (in processBatchedBlocks, slot=%d)", errParentDoesNotExist, firstBlock.Block().ParentRoot(), firstBlock.Block().Slot()) } @@ -278,7 +275,7 @@ func (s *Service) processBatchedBlocks(ctx context.Context, genesis time.Time, blockRoots[0] = blkRoot for i := 1; i < len(blks); i++ { b := blks[i] - if !bytes.Equal(b.Block().ParentRoot(), blockRoots[i-1][:]) { + if b.Block().ParentRoot() != blockRoots[i-1] { return fmt.Errorf("expected linear block list with parent root of %#x but received %#x", blockRoots[i-1][:], b.Block().ParentRoot()) } diff --git a/beacon-chain/sync/pending_blocks_queue.go b/beacon-chain/sync/pending_blocks_queue.go index 42a0db5efd..655dd8390b 100644 --- a/beacon-chain/sync/pending_blocks_queue.go +++ b/beacon-chain/sync/pending_blocks_queue.go @@ -114,7 +114,7 @@ func (s *Service) processPendingBlocks(ctx context.Context) error { } s.pendingQueueLock.RLock() - inPendingQueue := s.seenPendingBlocks[bytesutil.ToBytes32(b.Block().ParentRoot())] + inPendingQueue := s.seenPendingBlocks[b.Block().ParentRoot()] s.pendingQueueLock.RUnlock() keepProcessing, err := s.checkIfBlockIsBad(ctx, span, slot, b, blkRoot) @@ -125,17 +125,18 @@ func (s *Service) processPendingBlocks(ctx context.Context) error { continue } - parentInDb := s.cfg.beaconDB.HasBlock(ctx, bytesutil.ToBytes32(b.Block().ParentRoot())) + parentInDb := s.cfg.beaconDB.HasBlock(ctx, b.Block().ParentRoot()) hasPeer := len(pids) != 0 // Only request for missing parent block if it's not in beaconDB, not in pending cache // and has peer in the peer list. + parentRoot := b.Block().ParentRoot() if !inPendingQueue && !parentInDb && hasPeer { log.WithFields(logrus.Fields{ "currentSlot": b.Block().Slot(), - "parentRoot": hex.EncodeToString(bytesutil.Trunc(b.Block().ParentRoot())), + "parentRoot": hex.EncodeToString(bytesutil.Trunc(parentRoot[:])), }).Debug("Requesting parent block") - parentRoots = append(parentRoots, bytesutil.ToBytes32(b.Block().ParentRoot())) + parentRoots = append(parentRoots, b.Block().ParentRoot()) span.End() continue @@ -213,7 +214,7 @@ func (s *Service) checkIfBlockIsBad( b interfaces.SignedBeaconBlock, blkRoot [32]byte, ) (keepProcessing bool, err error) { - parentIsBad := s.hasBadBlock(bytesutil.ToBytes32(b.Block().ParentRoot())) + parentIsBad := s.hasBadBlock(b.Block().ParentRoot()) blockIsBad := s.hasBadBlock(blkRoot) // Check if parent is a bad block. if parentIsBad || blockIsBad { @@ -316,7 +317,7 @@ func (s *Service) validatePendingSlots() error { for _, b := range blks { epoch := slots.ToEpoch(slot) // remove all descendant blocks of old blocks - if oldBlockRoots[bytesutil.ToBytes32(b.Block().ParentRoot())] { + if oldBlockRoots[b.Block().ParentRoot()] { root, err := b.Block().HashTreeRoot() if err != nil { return err diff --git a/beacon-chain/sync/rpc_beacon_blocks_by_range.go b/beacon-chain/sync/rpc_beacon_blocks_by_range.go index 7452a1a288..364f41d2b9 100644 --- a/beacon-chain/sync/rpc_beacon_blocks_by_range.go +++ b/beacon-chain/sync/rpc_beacon_blocks_by_range.go @@ -13,7 +13,6 @@ import ( "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" "github.com/prysmaticlabs/prysm/v3/monitoring/tracing" pb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "go.opencensus.io/trace" @@ -247,7 +246,7 @@ func (s *Service) filterBlocks(ctx context.Context, blks []interfaces.SignedBeac return nil, err } parentValid := *prevRoot != [32]byte{} - isLinear := *prevRoot == bytesutil.ToBytes32(b.Block().ParentRoot()) + isLinear := *prevRoot == b.Block().ParentRoot() isSingular := step == 1 slotDiff, err := b.Block().Slot().SafeSubSlot(startSlot) if err != nil { diff --git a/beacon-chain/sync/validate_beacon_blocks.go b/beacon-chain/sync/validate_beacon_blocks.go index 7120b4f0d6..88e622a9d5 100644 --- a/beacon-chain/sync/validate_beacon_blocks.go +++ b/beacon-chain/sync/validate_beacon_blocks.go @@ -104,7 +104,7 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms return pubsub.ValidationIgnore, nil } // Check if parent is a bad block and then reject the block. - if s.hasBadBlock(bytesutil.ToBytes32(blk.Block().ParentRoot())) { + if s.hasBadBlock(blk.Block().ParentRoot()) { s.setBadBlock(ctx, blockRoot) err := fmt.Errorf("received block with root %#x that has an invalid parent %#x", blockRoot, blk.Block().ParentRoot()) log.WithError(err).WithFields(getBlockFields(blk)).Debug("Received block with an invalid parent") @@ -161,7 +161,7 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms } // Handle block when the parent is unknown. - if !s.cfg.chain.HasBlock(ctx, bytesutil.ToBytes32(blk.Block().ParentRoot())) { + if !s.cfg.chain.HasBlock(ctx, blk.Block().ParentRoot()) { s.pendingQueueLock.Lock() if err := s.insertBlockToPendingQueue(blk.Block().Slot(), blk, blockRoot); err != nil { s.pendingQueueLock.Unlock() @@ -198,11 +198,12 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms if err != nil { return pubsub.ValidationIgnore, err } + graffiti := blk.Block().Body().Graffiti() log.WithFields(logrus.Fields{ "blockSlot": blk.Block().Slot(), "sinceSlotStartTime": receivedTime.Sub(startTime), "proposerIndex": blk.Block().ProposerIndex(), - "graffiti": string(blk.Block().Body().Graffiti()), + "graffiti": string(graffiti[:]), }).Debug("Received block") blockVerificationGossipSummary.Observe(float64(prysmTime.Since(receivedTime).Milliseconds())) @@ -213,12 +214,12 @@ func (s *Service) validateBeaconBlock(ctx context.Context, blk interfaces.Signed ctx, span := trace.StartSpan(ctx, "sync.validateBeaconBlock") defer span.End() - if err := s.cfg.chain.VerifyFinalizedBlkDescendant(ctx, bytesutil.ToBytes32(blk.Block().ParentRoot())); err != nil { + if err := s.cfg.chain.VerifyFinalizedBlkDescendant(ctx, blk.Block().ParentRoot()); err != nil { s.setBadBlock(ctx, blockRoot) return err } - parentState, err := s.cfg.stateGen.StateByRoot(ctx, bytesutil.ToBytes32(blk.Block().ParentRoot())) + parentState, err := s.cfg.stateGen.StateByRoot(ctx, blk.Block().ParentRoot()) if err != nil { return err } @@ -229,7 +230,8 @@ func (s *Service) validateBeaconBlock(ctx context.Context, blk interfaces.Signed } // In the event the block is more than an epoch ahead from its // parent state, we have to advance the state forward. - parentState, err = transition.ProcessSlotsUsingNextSlotCache(ctx, parentState, blk.Block().ParentRoot(), blk.Block().Slot()) + parentRoot := blk.Block().ParentRoot() + parentState, err = transition.ProcessSlotsUsingNextSlotCache(ctx, parentState, parentRoot[:], blk.Block().Slot()) if err != nil { return err } @@ -296,8 +298,7 @@ func (s *Service) validateBellatrixBeaconBlock(ctx context.Context, parentState return errors.New("incorrect timestamp") } - parentRoot := bytesutil.ToBytes32(blk.ParentRoot()) - isParentOptimistic, err := s.cfg.chain.IsOptimisticForRoot(ctx, parentRoot) + isParentOptimistic, err := s.cfg.chain.IsOptimisticForRoot(ctx, blk.ParentRoot()) if err != nil { return err } @@ -373,10 +374,11 @@ func getBlockFields(b interfaces.SignedBeaconBlock) logrus.Fields { if consensusblocks.BeaconBlockIsNil(b) != nil { return logrus.Fields{} } + graffiti := b.Block().Body().Graffiti() return logrus.Fields{ "slot": b.Block().Slot(), "proposerIndex": b.Block().ProposerIndex(), - "graffiti": string(b.Block().Body().Graffiti()), + "graffiti": string(graffiti[:]), "version": b.Block().Version(), } } diff --git a/consensus-types/blocks/factory.go b/consensus-types/blocks/factory.go index c262c9676a..5f76a4cec6 100644 --- a/consensus-types/blocks/factory.go +++ b/consensus-types/blocks/factory.go @@ -182,16 +182,21 @@ func BuildSignedBeaconBlockFromExecutionPayload( if err != nil { return nil, errors.Wrap(err, "could not get sync aggregate from block body") } + parentRoot := b.ParentRoot() + stateRoot := b.StateRoot() + randaoReveal := b.Body().RandaoReveal() + graffiti := b.Body().Graffiti() + sig := blk.Signature() bellatrixFullBlock := ð.SignedBeaconBlockBellatrix{ Block: ð.BeaconBlockBellatrix{ Slot: b.Slot(), ProposerIndex: b.ProposerIndex(), - ParentRoot: b.ParentRoot(), - StateRoot: b.StateRoot(), + ParentRoot: parentRoot[:], + StateRoot: stateRoot[:], Body: ð.BeaconBlockBodyBellatrix{ - RandaoReveal: b.Body().RandaoReveal(), + RandaoReveal: randaoReveal[:], Eth1Data: b.Body().Eth1Data(), - Graffiti: b.Body().Graffiti(), + Graffiti: graffiti[:], ProposerSlashings: b.Body().ProposerSlashings(), AttesterSlashings: b.Body().AttesterSlashings(), Attestations: b.Body().Attestations(), @@ -201,7 +206,7 @@ func BuildSignedBeaconBlockFromExecutionPayload( ExecutionPayload: payload, }, }, - Signature: blk.Signature(), + Signature: sig[:], } return NewSignedBeaconBlock(bellatrixFullBlock) } diff --git a/consensus-types/blocks/factory_test.go b/consensus-types/blocks/factory_test.go index b2c9b51914..d41400f6f6 100644 --- a/consensus-types/blocks/factory_test.go +++ b/consensus-types/blocks/factory_test.go @@ -201,31 +201,31 @@ func Test_NewBeaconBlockBody(t *testing.T) { } func Test_BuildSignedBeaconBlock(t *testing.T) { - sig := []byte("signature") + sig := bytesutil.ToBytes96([]byte("signature")) t.Run("Phase0", func(t *testing.T) { b := &BeaconBlock{version: version.Phase0, body: &BeaconBlockBody{version: version.Phase0}} - sb, err := BuildSignedBeaconBlock(b, sig) + sb, err := BuildSignedBeaconBlock(b, sig[:]) require.NoError(t, err) assert.DeepEqual(t, sig, sb.Signature()) assert.Equal(t, version.Phase0, sb.Version()) }) t.Run("Altair", func(t *testing.T) { b := &BeaconBlock{version: version.Altair, body: &BeaconBlockBody{version: version.Altair}} - sb, err := BuildSignedBeaconBlock(b, sig) + sb, err := BuildSignedBeaconBlock(b, sig[:]) require.NoError(t, err) assert.DeepEqual(t, sig, sb.Signature()) assert.Equal(t, version.Altair, sb.Version()) }) t.Run("Bellatrix", func(t *testing.T) { b := &BeaconBlock{version: version.Bellatrix, body: &BeaconBlockBody{version: version.Bellatrix}} - sb, err := BuildSignedBeaconBlock(b, sig) + sb, err := BuildSignedBeaconBlock(b, sig[:]) require.NoError(t, err) assert.DeepEqual(t, sig, sb.Signature()) assert.Equal(t, version.Bellatrix, sb.Version()) }) t.Run("BellatrixBlind", func(t *testing.T) { b := &BeaconBlock{version: version.Bellatrix, body: &BeaconBlockBody{version: version.Bellatrix, isBlinded: true}} - sb, err := BuildSignedBeaconBlock(b, sig) + sb, err := BuildSignedBeaconBlock(b, sig[:]) require.NoError(t, err) assert.DeepEqual(t, sig, sb.Signature()) assert.Equal(t, version.Bellatrix, sb.Version()) diff --git a/consensus-types/blocks/getters.go b/consensus-types/blocks/getters.go index 00c1b5af3b..86f19da115 100644 --- a/consensus-types/blocks/getters.go +++ b/consensus-types/blocks/getters.go @@ -3,6 +3,7 @@ package blocks import ( "github.com/pkg/errors" ssz "github.com/prysmaticlabs/fastssz" + field_params "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" @@ -21,7 +22,7 @@ func BeaconBlockIsNil(b interfaces.SignedBeaconBlock) error { } // Signature returns the respective block signature. -func (b *SignedBeaconBlock) Signature() []byte { +func (b *SignedBeaconBlock) Signature() [field_params.BLSSignatureLength]byte { return b.signature } @@ -166,12 +167,12 @@ func (b *SignedBeaconBlock) ToBlinded() (interfaces.SignedBeaconBlock, error) { Block: ð.BlindedBeaconBlockBellatrix{ Slot: b.block.slot, ProposerIndex: b.block.proposerIndex, - ParentRoot: b.block.parentRoot, - StateRoot: b.block.stateRoot, + ParentRoot: b.block.parentRoot[:], + StateRoot: b.block.stateRoot[:], Body: ð.BlindedBeaconBlockBodyBellatrix{ - RandaoReveal: b.block.body.randaoReveal, + RandaoReveal: b.block.body.randaoReveal[:], Eth1Data: b.block.body.eth1Data, - Graffiti: b.block.body.graffiti, + Graffiti: b.block.body.graffiti[:], ProposerSlashings: b.block.body.proposerSlashings, AttesterSlashings: b.block.body.attesterSlashings, Attestations: b.block.body.attestations, @@ -181,7 +182,7 @@ func (b *SignedBeaconBlock) ToBlinded() (interfaces.SignedBeaconBlock, error) { ExecutionPayloadHeader: header, }, }, - Signature: b.signature, + Signature: b.signature[:], }) } @@ -208,11 +209,11 @@ func (b *SignedBeaconBlock) Header() (*eth.SignedBeaconBlockHeader, error) { Header: ð.BeaconBlockHeader{ Slot: b.block.slot, ProposerIndex: b.block.proposerIndex, - ParentRoot: b.block.parentRoot, - StateRoot: b.block.stateRoot, + ParentRoot: b.block.parentRoot[:], + StateRoot: b.block.stateRoot[:], BodyRoot: root[:], }, - Signature: b.signature, + Signature: b.signature[:], }, nil } @@ -349,12 +350,12 @@ func (b *BeaconBlock) ProposerIndex() types.ValidatorIndex { } // ParentRoot returns the parent root of beacon block. -func (b *BeaconBlock) ParentRoot() []byte { +func (b *BeaconBlock) ParentRoot() [field_params.RootLength]byte { return b.parentRoot } // StateRoot returns the state root of the beacon block. -func (b *BeaconBlock) StateRoot() []byte { +func (b *BeaconBlock) StateRoot() [field_params.RootLength]byte { return b.stateRoot } @@ -379,10 +380,10 @@ func (b *BeaconBlock) Version() int { } // HashTreeRoot returns the ssz root of the block. -func (b *BeaconBlock) HashTreeRoot() ([32]byte, error) { +func (b *BeaconBlock) HashTreeRoot() ([field_params.RootLength]byte, error) { pb, err := b.Proto() if err != nil { - return [32]byte{}, err + return [field_params.RootLength]byte{}, err } switch b.version { case version.Phase0: @@ -395,7 +396,7 @@ func (b *BeaconBlock) HashTreeRoot() ([32]byte, error) { } return pb.(*eth.BeaconBlockBellatrix).HashTreeRoot() default: - return [32]byte{}, errIncorrectBlockVersion + return [field_params.RootLength]byte{}, errIncorrectBlockVersion } } @@ -570,7 +571,7 @@ func (b *BeaconBlockBody) IsNil() bool { } // RandaoReveal returns the randao reveal from the block body. -func (b *BeaconBlockBody) RandaoReveal() []byte { +func (b *BeaconBlockBody) RandaoReveal() [field_params.BLSSignatureLength]byte { return b.randaoReveal } @@ -580,7 +581,7 @@ func (b *BeaconBlockBody) Eth1Data() *eth.Eth1Data { } // Graffiti returns the graffiti in the block. -func (b *BeaconBlockBody) Graffiti() []byte { +func (b *BeaconBlockBody) Graffiti() [field_params.RootLength]byte { return b.graffiti } @@ -633,10 +634,10 @@ func (b *BeaconBlockBody) Execution() (interfaces.ExecutionData, error) { } // HashTreeRoot returns the ssz root of the block body. -func (b *BeaconBlockBody) HashTreeRoot() ([32]byte, error) { +func (b *BeaconBlockBody) HashTreeRoot() ([field_params.RootLength]byte, error) { pb, err := b.Proto() if err != nil { - return [32]byte{}, err + return [field_params.RootLength]byte{}, err } switch b.version { case version.Phase0: @@ -649,6 +650,6 @@ func (b *BeaconBlockBody) HashTreeRoot() ([32]byte, error) { } return pb.(*eth.BeaconBlockBodyBellatrix).HashTreeRoot() default: - return [32]byte{}, errIncorrectBodyVersion + return [field_params.RootLength]byte{}, errIncorrectBodyVersion } } diff --git a/consensus-types/blocks/getters_test.go b/consensus-types/blocks/getters_test.go index 833dd62379..9df7c7886c 100644 --- a/consensus-types/blocks/getters_test.go +++ b/consensus-types/blocks/getters_test.go @@ -7,6 +7,7 @@ import ( fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" + "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" validatorpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/validator-client" "github.com/prysmaticlabs/prysm/v3/runtime/version" @@ -40,8 +41,8 @@ func Test_BeaconBlockIsNil(t *testing.T) { } func Test_SignedBeaconBlock_Signature(t *testing.T) { - sb := &SignedBeaconBlock{signature: []byte("signature")} - assert.DeepEqual(t, []byte("signature"), sb.Signature()) + sb := &SignedBeaconBlock{signature: bytesutil.ToBytes96([]byte("signature"))} + assert.DeepEqual(t, bytesutil.ToBytes96([]byte("signature")), sb.Signature()) } func Test_SignedBeaconBlock_Block(t *testing.T) { @@ -88,12 +89,12 @@ func Test_SignedBeaconBlock_Version(t *testing.T) { func Test_SignedBeaconBlock_Header(t *testing.T) { bb := &BeaconBlockBody{ version: version.Phase0, - randaoReveal: make([]byte, 96), + randaoReveal: [96]byte{}, eth1Data: ð.Eth1Data{ DepositRoot: make([]byte, 32), BlockHash: make([]byte, 32), }, - graffiti: make([]byte, 32), + graffiti: [32]byte{}, } sb := &SignedBeaconBlock{ version: version.Phase0, @@ -101,19 +102,19 @@ func Test_SignedBeaconBlock_Header(t *testing.T) { version: version.Phase0, slot: 128, proposerIndex: 128, - parentRoot: []byte("parentroot"), - stateRoot: []byte("stateroot"), + parentRoot: bytesutil.ToBytes32([]byte("parentroot")), + stateRoot: bytesutil.ToBytes32([]byte("stateroot")), body: bb, }, - signature: []byte("signature"), + signature: bytesutil.ToBytes96([]byte("signature")), } h, err := sb.Header() require.NoError(t, err) - assert.DeepEqual(t, sb.signature, h.Signature) + assert.DeepEqual(t, sb.signature[:], h.Signature) assert.Equal(t, sb.block.slot, h.Header.Slot) assert.Equal(t, sb.block.proposerIndex, h.Header.ProposerIndex) - assert.DeepEqual(t, sb.block.parentRoot, h.Header.ParentRoot) - assert.DeepEqual(t, sb.block.stateRoot, h.Header.StateRoot) + assert.DeepEqual(t, sb.block.parentRoot[:], h.Header.ParentRoot) + assert.DeepEqual(t, sb.block.stateRoot[:], h.Header.StateRoot) expectedHTR, err := bb.HashTreeRoot() require.NoError(t, err) assert.DeepEqual(t, expectedHTR[:], h.Header.BodyRoot) @@ -147,13 +148,13 @@ func Test_BeaconBlock_ProposerIndex(t *testing.T) { } func Test_BeaconBlock_ParentRoot(t *testing.T) { - b := &BeaconBlock{parentRoot: []byte("parentroot")} - assert.DeepEqual(t, []byte("parentroot"), b.ParentRoot()) + b := &BeaconBlock{parentRoot: bytesutil.ToBytes32([]byte("parentroot"))} + assert.DeepEqual(t, bytesutil.ToBytes32([]byte("parentroot")), b.ParentRoot()) } func Test_BeaconBlock_StateRoot(t *testing.T) { - b := &BeaconBlock{stateRoot: []byte("stateroot")} - assert.DeepEqual(t, []byte("stateroot"), b.StateRoot()) + b := &BeaconBlock{stateRoot: bytesutil.ToBytes32([]byte("stateroot"))} + assert.DeepEqual(t, bytesutil.ToBytes32([]byte("stateroot")), b.StateRoot()) } func Test_BeaconBlock_Body(t *testing.T) { @@ -255,8 +256,8 @@ func Test_BeaconBlockBody_IsNil(t *testing.T) { } func Test_BeaconBlockBody_RandaoReveal(t *testing.T) { - bb := &BeaconBlockBody{randaoReveal: []byte("randaoreveal")} - assert.DeepEqual(t, []byte("randaoreveal"), bb.RandaoReveal()) + bb := &BeaconBlockBody{randaoReveal: bytesutil.ToBytes96([]byte("randaoreveal"))} + assert.DeepEqual(t, bytesutil.ToBytes96([]byte("randaoreveal")), bb.RandaoReveal()) } func Test_BeaconBlockBody_Eth1Data(t *testing.T) { @@ -266,8 +267,8 @@ func Test_BeaconBlockBody_Eth1Data(t *testing.T) { } func Test_BeaconBlockBody_Graffiti(t *testing.T) { - bb := &BeaconBlockBody{graffiti: []byte("graffiti")} - assert.DeepEqual(t, []byte("graffiti"), bb.Graffiti()) + bb := &BeaconBlockBody{graffiti: bytesutil.ToBytes32([]byte("graffiti"))} + assert.DeepEqual(t, bytesutil.ToBytes32([]byte("graffiti")), bb.Graffiti()) } func Test_BeaconBlockBody_ProposerSlashings(t *testing.T) { diff --git a/consensus-types/blocks/proto.go b/consensus-types/blocks/proto.go index c0b669ccd0..c50598c4b0 100644 --- a/consensus-types/blocks/proto.go +++ b/consensus-types/blocks/proto.go @@ -2,6 +2,7 @@ package blocks import ( "github.com/pkg/errors" + "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/runtime/version" "google.golang.org/protobuf/proto" @@ -30,7 +31,7 @@ func (b *SignedBeaconBlock) Proto() (proto.Message, error) { } return ð.SignedBeaconBlock{ Block: block, - Signature: b.signature, + Signature: b.signature[:], }, nil case version.Altair: var block *eth.BeaconBlockAltair @@ -43,7 +44,7 @@ func (b *SignedBeaconBlock) Proto() (proto.Message, error) { } return ð.SignedBeaconBlockAltair{ Block: block, - Signature: b.signature, + Signature: b.signature[:], }, nil case version.Bellatrix: if b.IsBlinded() { @@ -57,7 +58,7 @@ func (b *SignedBeaconBlock) Proto() (proto.Message, error) { } return ð.SignedBlindedBeaconBlockBellatrix{ Block: block, - Signature: b.signature, + Signature: b.signature[:], }, nil } var block *eth.BeaconBlockBellatrix @@ -70,7 +71,7 @@ func (b *SignedBeaconBlock) Proto() (proto.Message, error) { } return ð.SignedBeaconBlockBellatrix{ Block: block, - Signature: b.signature, + Signature: b.signature[:], }, nil default: return nil, errors.New("unsupported signed beacon block version") @@ -101,8 +102,8 @@ func (b *BeaconBlock) Proto() (proto.Message, error) { return ð.BeaconBlock{ Slot: b.slot, ProposerIndex: b.proposerIndex, - ParentRoot: b.parentRoot, - StateRoot: b.stateRoot, + ParentRoot: b.parentRoot[:], + StateRoot: b.stateRoot[:], Body: body, }, nil case version.Altair: @@ -117,8 +118,8 @@ func (b *BeaconBlock) Proto() (proto.Message, error) { return ð.BeaconBlockAltair{ Slot: b.slot, ProposerIndex: b.proposerIndex, - ParentRoot: b.parentRoot, - StateRoot: b.stateRoot, + ParentRoot: b.parentRoot[:], + StateRoot: b.stateRoot[:], Body: body, }, nil case version.Bellatrix: @@ -134,8 +135,8 @@ func (b *BeaconBlock) Proto() (proto.Message, error) { return ð.BlindedBeaconBlockBellatrix{ Slot: b.slot, ProposerIndex: b.proposerIndex, - ParentRoot: b.parentRoot, - StateRoot: b.stateRoot, + ParentRoot: b.parentRoot[:], + StateRoot: b.stateRoot[:], Body: body, }, nil } @@ -150,8 +151,8 @@ func (b *BeaconBlock) Proto() (proto.Message, error) { return ð.BeaconBlockBellatrix{ Slot: b.slot, ProposerIndex: b.proposerIndex, - ParentRoot: b.parentRoot, - StateRoot: b.stateRoot, + ParentRoot: b.parentRoot[:], + StateRoot: b.stateRoot[:], Body: body, }, nil default: @@ -168,9 +169,9 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) { switch b.version { case version.Phase0: return ð.BeaconBlockBody{ - RandaoReveal: b.randaoReveal, + RandaoReveal: b.randaoReveal[:], Eth1Data: b.eth1Data, - Graffiti: b.graffiti, + Graffiti: b.graffiti[:], ProposerSlashings: b.proposerSlashings, AttesterSlashings: b.attesterSlashings, Attestations: b.attestations, @@ -179,9 +180,9 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) { }, nil case version.Altair: return ð.BeaconBlockBodyAltair{ - RandaoReveal: b.randaoReveal, + RandaoReveal: b.randaoReveal[:], Eth1Data: b.eth1Data, - Graffiti: b.graffiti, + Graffiti: b.graffiti[:], ProposerSlashings: b.proposerSlashings, AttesterSlashings: b.attesterSlashings, Attestations: b.attestations, @@ -192,9 +193,9 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) { case version.Bellatrix: if b.isBlinded { return ð.BlindedBeaconBlockBodyBellatrix{ - RandaoReveal: b.randaoReveal, + RandaoReveal: b.randaoReveal[:], Eth1Data: b.eth1Data, - Graffiti: b.graffiti, + Graffiti: b.graffiti[:], ProposerSlashings: b.proposerSlashings, AttesterSlashings: b.attesterSlashings, Attestations: b.attestations, @@ -205,9 +206,9 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) { }, nil } return ð.BeaconBlockBodyBellatrix{ - RandaoReveal: b.randaoReveal, + RandaoReveal: b.randaoReveal[:], Eth1Data: b.eth1Data, - Graffiti: b.graffiti, + Graffiti: b.graffiti[:], ProposerSlashings: b.proposerSlashings, AttesterSlashings: b.attesterSlashings, Attestations: b.attestations, @@ -233,7 +234,7 @@ func initSignedBlockFromProtoPhase0(pb *eth.SignedBeaconBlock) (*SignedBeaconBlo b := &SignedBeaconBlock{ version: version.Phase0, block: block, - signature: pb.Signature, + signature: bytesutil.ToBytes96(pb.Signature), } return b, nil } @@ -250,7 +251,7 @@ func initSignedBlockFromProtoAltair(pb *eth.SignedBeaconBlockAltair) (*SignedBea b := &SignedBeaconBlock{ version: version.Altair, block: block, - signature: pb.Signature, + signature: bytesutil.ToBytes96(pb.Signature), } return b, nil } @@ -267,7 +268,7 @@ func initSignedBlockFromProtoBellatrix(pb *eth.SignedBeaconBlockBellatrix) (*Sig b := &SignedBeaconBlock{ version: version.Bellatrix, block: block, - signature: pb.Signature, + signature: bytesutil.ToBytes96(pb.Signature), } return b, nil } @@ -284,7 +285,7 @@ func initBlindedSignedBlockFromProtoBellatrix(pb *eth.SignedBlindedBeaconBlockBe b := &SignedBeaconBlock{ version: version.Bellatrix, block: block, - signature: pb.Signature, + signature: bytesutil.ToBytes96(pb.Signature), } return b, nil } @@ -302,8 +303,8 @@ func initBlockFromProtoPhase0(pb *eth.BeaconBlock) (*BeaconBlock, error) { version: version.Phase0, slot: pb.Slot, proposerIndex: pb.ProposerIndex, - parentRoot: pb.ParentRoot, - stateRoot: pb.StateRoot, + parentRoot: bytesutil.ToBytes32(pb.ParentRoot), + stateRoot: bytesutil.ToBytes32(pb.StateRoot), body: body, } return b, nil @@ -322,8 +323,8 @@ func initBlockFromProtoAltair(pb *eth.BeaconBlockAltair) (*BeaconBlock, error) { version: version.Altair, slot: pb.Slot, proposerIndex: pb.ProposerIndex, - parentRoot: pb.ParentRoot, - stateRoot: pb.StateRoot, + parentRoot: bytesutil.ToBytes32(pb.ParentRoot), + stateRoot: bytesutil.ToBytes32(pb.StateRoot), body: body, } return b, nil @@ -342,8 +343,8 @@ func initBlockFromProtoBellatrix(pb *eth.BeaconBlockBellatrix) (*BeaconBlock, er version: version.Bellatrix, slot: pb.Slot, proposerIndex: pb.ProposerIndex, - parentRoot: pb.ParentRoot, - stateRoot: pb.StateRoot, + parentRoot: bytesutil.ToBytes32(pb.ParentRoot), + stateRoot: bytesutil.ToBytes32(pb.StateRoot), body: body, } return b, nil @@ -362,8 +363,8 @@ func initBlindedBlockFromProtoBellatrix(pb *eth.BlindedBeaconBlockBellatrix) (*B version: version.Bellatrix, slot: pb.Slot, proposerIndex: pb.ProposerIndex, - parentRoot: pb.ParentRoot, - stateRoot: pb.StateRoot, + parentRoot: bytesutil.ToBytes32(pb.ParentRoot), + stateRoot: bytesutil.ToBytes32(pb.StateRoot), body: body, } return b, nil @@ -377,9 +378,9 @@ func initBlockBodyFromProtoPhase0(pb *eth.BeaconBlockBody) (*BeaconBlockBody, er b := &BeaconBlockBody{ version: version.Phase0, isBlinded: false, - randaoReveal: pb.RandaoReveal, + randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), eth1Data: pb.Eth1Data, - graffiti: pb.Graffiti, + graffiti: bytesutil.ToBytes32(pb.Graffiti), proposerSlashings: pb.ProposerSlashings, attesterSlashings: pb.AttesterSlashings, attestations: pb.Attestations, @@ -397,9 +398,9 @@ func initBlockBodyFromProtoAltair(pb *eth.BeaconBlockBodyAltair) (*BeaconBlockBo b := &BeaconBlockBody{ version: version.Altair, isBlinded: false, - randaoReveal: pb.RandaoReveal, + randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), eth1Data: pb.Eth1Data, - graffiti: pb.Graffiti, + graffiti: bytesutil.ToBytes32(pb.Graffiti), proposerSlashings: pb.ProposerSlashings, attesterSlashings: pb.AttesterSlashings, attestations: pb.Attestations, @@ -418,9 +419,9 @@ func initBlockBodyFromProtoBellatrix(pb *eth.BeaconBlockBodyBellatrix) (*BeaconB b := &BeaconBlockBody{ version: version.Bellatrix, isBlinded: false, - randaoReveal: pb.RandaoReveal, + randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), eth1Data: pb.Eth1Data, - graffiti: pb.Graffiti, + graffiti: bytesutil.ToBytes32(pb.Graffiti), proposerSlashings: pb.ProposerSlashings, attesterSlashings: pb.AttesterSlashings, attestations: pb.Attestations, @@ -440,9 +441,9 @@ func initBlindedBlockBodyFromProtoBellatrix(pb *eth.BlindedBeaconBlockBodyBellat b := &BeaconBlockBody{ version: version.Bellatrix, isBlinded: true, - randaoReveal: pb.RandaoReveal, + randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), eth1Data: pb.Eth1Data, - graffiti: pb.Graffiti, + graffiti: bytesutil.ToBytes32(pb.Graffiti), proposerSlashings: pb.ProposerSlashings, attesterSlashings: pb.AttesterSlashings, attestations: pb.Attestations, diff --git a/consensus-types/blocks/proto_test.go b/consensus-types/blocks/proto_test.go index 9cf8096de4..041f704348 100644 --- a/consensus-types/blocks/proto_test.go +++ b/consensus-types/blocks/proto_test.go @@ -12,11 +12,8 @@ import ( ) type fields struct { - b20 []byte - b32 []byte - b48 []byte - b96 []byte - b256 []byte + root [32]byte + sig [96]byte deposits []*eth.Deposit atts []*eth.Attestation proposerSlashings []*eth.ProposerSlashing @@ -35,11 +32,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) { Block: ð.BeaconBlock{ Slot: 128, ProposerIndex: 128, - ParentRoot: f.b32, - StateRoot: f.b32, + ParentRoot: f.root[:], + StateRoot: f.root[:], Body: bodyPbPhase0(), }, - Signature: f.b96, + Signature: f.sig[:], } block := &SignedBeaconBlock{ version: version.Phase0, @@ -47,11 +44,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) { version: version.Phase0, slot: 128, proposerIndex: 128, - parentRoot: f.b32, - stateRoot: f.b32, + parentRoot: f.root, + stateRoot: f.root, body: bodyPhase0(), }, - signature: f.b96, + signature: f.sig, } result, err := block.Proto() @@ -69,11 +66,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) { Block: ð.BeaconBlockAltair{ Slot: 128, ProposerIndex: 128, - ParentRoot: f.b32, - StateRoot: f.b32, + ParentRoot: f.root[:], + StateRoot: f.root[:], Body: bodyPbAltair(), }, - Signature: f.b96, + Signature: f.sig[:], } block := &SignedBeaconBlock{ version: version.Altair, @@ -81,11 +78,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) { version: version.Altair, slot: 128, proposerIndex: 128, - parentRoot: f.b32, - stateRoot: f.b32, + parentRoot: f.root, + stateRoot: f.root, body: bodyAltair(), }, - signature: f.b96, + signature: f.sig, } result, err := block.Proto() @@ -103,11 +100,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) { Block: ð.BeaconBlockBellatrix{ Slot: 128, ProposerIndex: 128, - ParentRoot: f.b32, - StateRoot: f.b32, + ParentRoot: f.root[:], + StateRoot: f.root[:], Body: bodyPbBellatrix(), }, - Signature: f.b96, + Signature: f.sig[:], } block := &SignedBeaconBlock{ version: version.Bellatrix, @@ -115,11 +112,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) { version: version.Bellatrix, slot: 128, proposerIndex: 128, - parentRoot: f.b32, - stateRoot: f.b32, + parentRoot: f.root, + stateRoot: f.root, body: bodyBellatrix(), }, - signature: f.b96, + signature: f.sig, } result, err := block.Proto() @@ -137,11 +134,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) { Block: ð.BlindedBeaconBlockBellatrix{ Slot: 128, ProposerIndex: 128, - ParentRoot: f.b32, - StateRoot: f.b32, + ParentRoot: f.root[:], + StateRoot: f.root[:], Body: bodyPbBlindedBellatrix(), }, - Signature: f.b96, + Signature: f.sig[:], } block := &SignedBeaconBlock{ version: version.Bellatrix, @@ -149,11 +146,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) { version: version.Bellatrix, slot: 128, proposerIndex: 128, - parentRoot: f.b32, - stateRoot: f.b32, + parentRoot: f.root, + stateRoot: f.root, body: bodyBlindedBellatrix(), }, - signature: f.b96, + signature: f.sig, } result, err := block.Proto() @@ -175,16 +172,16 @@ func Test_BeaconBlock_Proto(t *testing.T) { expectedBlock := ð.BeaconBlock{ Slot: 128, ProposerIndex: 128, - ParentRoot: f.b32, - StateRoot: f.b32, + ParentRoot: f.root[:], + StateRoot: f.root[:], Body: bodyPbPhase0(), } block := &BeaconBlock{ version: version.Phase0, slot: 128, proposerIndex: 128, - parentRoot: f.b32, - stateRoot: f.b32, + parentRoot: f.root, + stateRoot: f.root, body: bodyPhase0(), } @@ -202,16 +199,16 @@ func Test_BeaconBlock_Proto(t *testing.T) { expectedBlock := ð.BeaconBlockAltair{ Slot: 128, ProposerIndex: 128, - ParentRoot: f.b32, - StateRoot: f.b32, + ParentRoot: f.root[:], + StateRoot: f.root[:], Body: bodyPbAltair(), } block := &BeaconBlock{ version: version.Altair, slot: 128, proposerIndex: 128, - parentRoot: f.b32, - stateRoot: f.b32, + parentRoot: f.root, + stateRoot: f.root, body: bodyAltair(), } @@ -229,16 +226,16 @@ func Test_BeaconBlock_Proto(t *testing.T) { expectedBlock := ð.BeaconBlockBellatrix{ Slot: 128, ProposerIndex: 128, - ParentRoot: f.b32, - StateRoot: f.b32, + ParentRoot: f.root[:], + StateRoot: f.root[:], Body: bodyPbBellatrix(), } block := &BeaconBlock{ version: version.Bellatrix, slot: 128, proposerIndex: 128, - parentRoot: f.b32, - stateRoot: f.b32, + parentRoot: f.root, + stateRoot: f.root, body: bodyBellatrix(), } @@ -256,16 +253,16 @@ func Test_BeaconBlock_Proto(t *testing.T) { expectedBlock := ð.BlindedBeaconBlockBellatrix{ Slot: 128, ProposerIndex: 128, - ParentRoot: f.b32, - StateRoot: f.b32, + ParentRoot: f.root[:], + StateRoot: f.root[:], Body: bodyPbBlindedBellatrix(), } block := &BeaconBlock{ version: version.Bellatrix, slot: 128, proposerIndex: 128, - parentRoot: f.b32, - stateRoot: f.b32, + parentRoot: f.root, + stateRoot: f.root, body: bodyBlindedBellatrix(), } @@ -343,11 +340,11 @@ func Test_initSignedBlockFromProtoPhase0(t *testing.T) { Block: ð.BeaconBlock{ Slot: 128, ProposerIndex: 128, - ParentRoot: f.b32, - StateRoot: f.b32, + ParentRoot: f.root[:], + StateRoot: f.root[:], Body: bodyPbPhase0(), }, - Signature: f.b96, + Signature: f.sig[:], } resultBlock, err := initSignedBlockFromProtoPhase0(expectedBlock) require.NoError(t, err) @@ -356,7 +353,7 @@ func Test_initSignedBlockFromProtoPhase0(t *testing.T) { expectedHTR, err := expectedBlock.Block.HashTreeRoot() require.NoError(t, err) assert.DeepEqual(t, expectedHTR, resultHTR) - assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature) + assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature[:]) } func Test_initSignedBlockFromProtoAltair(t *testing.T) { @@ -365,11 +362,11 @@ func Test_initSignedBlockFromProtoAltair(t *testing.T) { Block: ð.BeaconBlockAltair{ Slot: 128, ProposerIndex: 128, - ParentRoot: f.b32, - StateRoot: f.b32, + ParentRoot: f.root[:], + StateRoot: f.root[:], Body: bodyPbAltair(), }, - Signature: f.b96, + Signature: f.sig[:], } resultBlock, err := initSignedBlockFromProtoAltair(expectedBlock) require.NoError(t, err) @@ -378,7 +375,7 @@ func Test_initSignedBlockFromProtoAltair(t *testing.T) { expectedHTR, err := expectedBlock.Block.HashTreeRoot() require.NoError(t, err) assert.DeepEqual(t, expectedHTR, resultHTR) - assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature) + assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature[:]) } func Test_initSignedBlockFromProtoBellatrix(t *testing.T) { @@ -387,11 +384,11 @@ func Test_initSignedBlockFromProtoBellatrix(t *testing.T) { Block: ð.BeaconBlockBellatrix{ Slot: 128, ProposerIndex: 128, - ParentRoot: f.b32, - StateRoot: f.b32, + ParentRoot: f.root[:], + StateRoot: f.root[:], Body: bodyPbBellatrix(), }, - Signature: f.b96, + Signature: f.sig[:], } resultBlock, err := initSignedBlockFromProtoBellatrix(expectedBlock) require.NoError(t, err) @@ -400,7 +397,7 @@ func Test_initSignedBlockFromProtoBellatrix(t *testing.T) { expectedHTR, err := expectedBlock.Block.HashTreeRoot() require.NoError(t, err) assert.DeepEqual(t, expectedHTR, resultHTR) - assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature) + assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature[:]) } func Test_initBlindedSignedBlockFromProtoBellatrix(t *testing.T) { @@ -409,11 +406,11 @@ func Test_initBlindedSignedBlockFromProtoBellatrix(t *testing.T) { Block: ð.BlindedBeaconBlockBellatrix{ Slot: 128, ProposerIndex: 128, - ParentRoot: f.b32, - StateRoot: f.b32, + ParentRoot: f.root[:], + StateRoot: f.root[:], Body: bodyPbBlindedBellatrix(), }, - Signature: f.b96, + Signature: f.sig[:], } resultBlock, err := initBlindedSignedBlockFromProtoBellatrix(expectedBlock) require.NoError(t, err) @@ -422,7 +419,7 @@ func Test_initBlindedSignedBlockFromProtoBellatrix(t *testing.T) { expectedHTR, err := expectedBlock.Block.HashTreeRoot() require.NoError(t, err) assert.DeepEqual(t, expectedHTR, resultHTR) - assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature) + assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature[:]) } func Test_initBlockFromProtoPhase0(t *testing.T) { @@ -430,8 +427,8 @@ func Test_initBlockFromProtoPhase0(t *testing.T) { expectedBlock := ð.BeaconBlock{ Slot: 128, ProposerIndex: 128, - ParentRoot: f.b32, - StateRoot: f.b32, + ParentRoot: f.root[:], + StateRoot: f.root[:], Body: bodyPbPhase0(), } resultBlock, err := initBlockFromProtoPhase0(expectedBlock) @@ -448,8 +445,8 @@ func Test_initBlockFromProtoAltair(t *testing.T) { expectedBlock := ð.BeaconBlockAltair{ Slot: 128, ProposerIndex: 128, - ParentRoot: f.b32, - StateRoot: f.b32, + ParentRoot: f.root[:], + StateRoot: f.root[:], Body: bodyPbAltair(), } resultBlock, err := initBlockFromProtoAltair(expectedBlock) @@ -466,8 +463,8 @@ func Test_initBlockFromProtoBellatrix(t *testing.T) { expectedBlock := ð.BeaconBlockBellatrix{ Slot: 128, ProposerIndex: 128, - ParentRoot: f.b32, - StateRoot: f.b32, + ParentRoot: f.root[:], + StateRoot: f.root[:], Body: bodyPbBellatrix(), } resultBlock, err := initBlockFromProtoBellatrix(expectedBlock) @@ -484,8 +481,8 @@ func Test_initBlockFromProtoBlindedBellatrix(t *testing.T) { expectedBlock := ð.BlindedBeaconBlockBellatrix{ Slot: 128, ProposerIndex: 128, - ParentRoot: f.b32, - StateRoot: f.b32, + ParentRoot: f.root[:], + StateRoot: f.root[:], Body: bodyPbBlindedBellatrix(), } resultBlock, err := initBlindedBlockFromProtoBellatrix(expectedBlock) @@ -544,13 +541,13 @@ func Test_initBlockBodyFromProtoBlindedBellatrix(t *testing.T) { func bodyPbPhase0() *eth.BeaconBlockBody { f := getFields() return ð.BeaconBlockBody{ - RandaoReveal: f.b96, + RandaoReveal: f.sig[:], Eth1Data: ð.Eth1Data{ - DepositRoot: f.b32, + DepositRoot: f.root[:], DepositCount: 128, - BlockHash: f.b32, + BlockHash: f.root[:], }, - Graffiti: f.b32, + Graffiti: f.root[:], ProposerSlashings: f.proposerSlashings, AttesterSlashings: f.attesterSlashings, Attestations: f.atts, @@ -562,13 +559,13 @@ func bodyPbPhase0() *eth.BeaconBlockBody { func bodyPbAltair() *eth.BeaconBlockBodyAltair { f := getFields() return ð.BeaconBlockBodyAltair{ - RandaoReveal: f.b96, + RandaoReveal: f.sig[:], Eth1Data: ð.Eth1Data{ - DepositRoot: f.b32, + DepositRoot: f.root[:], DepositCount: 128, - BlockHash: f.b32, + BlockHash: f.root[:], }, - Graffiti: f.b32, + Graffiti: f.root[:], ProposerSlashings: f.proposerSlashings, AttesterSlashings: f.attesterSlashings, Attestations: f.atts, @@ -581,13 +578,13 @@ func bodyPbAltair() *eth.BeaconBlockBodyAltair { func bodyPbBellatrix() *eth.BeaconBlockBodyBellatrix { f := getFields() return ð.BeaconBlockBodyBellatrix{ - RandaoReveal: f.b96, + RandaoReveal: f.sig[:], Eth1Data: ð.Eth1Data{ - DepositRoot: f.b32, + DepositRoot: f.root[:], DepositCount: 128, - BlockHash: f.b32, + BlockHash: f.root[:], }, - Graffiti: f.b32, + Graffiti: f.root[:], ProposerSlashings: f.proposerSlashings, AttesterSlashings: f.attesterSlashings, Attestations: f.atts, @@ -601,13 +598,13 @@ func bodyPbBellatrix() *eth.BeaconBlockBodyBellatrix { func bodyPbBlindedBellatrix() *eth.BlindedBeaconBlockBodyBellatrix { f := getFields() return ð.BlindedBeaconBlockBodyBellatrix{ - RandaoReveal: f.b96, + RandaoReveal: f.sig[:], Eth1Data: ð.Eth1Data{ - DepositRoot: f.b32, + DepositRoot: f.root[:], DepositCount: 128, - BlockHash: f.b32, + BlockHash: f.root[:], }, - Graffiti: f.b32, + Graffiti: f.root[:], ProposerSlashings: f.proposerSlashings, AttesterSlashings: f.attesterSlashings, Attestations: f.atts, @@ -622,13 +619,13 @@ func bodyPhase0() *BeaconBlockBody { f := getFields() return &BeaconBlockBody{ version: version.Phase0, - randaoReveal: f.b96, + randaoReveal: f.sig, eth1Data: ð.Eth1Data{ - DepositRoot: f.b32, + DepositRoot: f.root[:], DepositCount: 128, - BlockHash: f.b32, + BlockHash: f.root[:], }, - graffiti: f.b32, + graffiti: f.root, proposerSlashings: f.proposerSlashings, attesterSlashings: f.attesterSlashings, attestations: f.atts, @@ -641,13 +638,13 @@ func bodyAltair() *BeaconBlockBody { f := getFields() return &BeaconBlockBody{ version: version.Altair, - randaoReveal: f.b96, + randaoReveal: f.sig, eth1Data: ð.Eth1Data{ - DepositRoot: f.b32, + DepositRoot: f.root[:], DepositCount: 128, - BlockHash: f.b32, + BlockHash: f.root[:], }, - graffiti: f.b32, + graffiti: f.root, proposerSlashings: f.proposerSlashings, attesterSlashings: f.attesterSlashings, attestations: f.atts, @@ -661,13 +658,13 @@ func bodyBellatrix() *BeaconBlockBody { f := getFields() return &BeaconBlockBody{ version: version.Bellatrix, - randaoReveal: f.b96, + randaoReveal: f.sig, eth1Data: ð.Eth1Data{ - DepositRoot: f.b32, + DepositRoot: f.root[:], DepositCount: 128, - BlockHash: f.b32, + BlockHash: f.root[:], }, - graffiti: f.b32, + graffiti: f.root, proposerSlashings: f.proposerSlashings, attesterSlashings: f.attesterSlashings, attestations: f.atts, @@ -683,13 +680,13 @@ func bodyBlindedBellatrix() *BeaconBlockBody { return &BeaconBlockBody{ version: version.Bellatrix, isBlinded: true, - randaoReveal: f.b96, + randaoReveal: f.sig, eth1Data: ð.Eth1Data{ - DepositRoot: f.b32, + DepositRoot: f.root[:], DepositCount: 128, - BlockHash: f.b32, + BlockHash: f.root[:], }, - graffiti: f.b32, + graffiti: f.root, proposerSlashings: f.proposerSlashings, attesterSlashings: f.attesterSlashings, attestations: f.atts, @@ -702,45 +699,45 @@ func bodyBlindedBellatrix() *BeaconBlockBody { func getFields() fields { b20 := make([]byte, 20) - b32 := make([]byte, 32) b48 := make([]byte, 48) - b96 := make([]byte, 96) b256 := make([]byte, 256) + var root [32]byte + var sig [96]byte b20[0], b20[5], b20[10] = 'q', 'u', 'x' - b32[0], b32[5], b32[10] = 'f', 'o', 'o' b48[0], b48[5], b48[10] = 'b', 'a', 'r' - b96[0], b96[5], b96[10] = 'b', 'a', 'z' b256[0], b256[5], b256[10] = 'x', 'y', 'z' + root[0], root[5], root[10] = 'a', 'b', 'c' + sig[0], sig[5], sig[10] = 'd', 'e', 'f' deposits := make([]*eth.Deposit, 16) for i := range deposits { deposits[i] = ð.Deposit{} deposits[i].Proof = make([][]byte, 33) for j := range deposits[i].Proof { - deposits[i].Proof[j] = b32 + deposits[i].Proof[j] = root[:] } deposits[i].Data = ð.Deposit_Data{ PublicKey: b48, - WithdrawalCredentials: b32, + WithdrawalCredentials: root[:], Amount: 128, - Signature: b96, + Signature: sig[:], } } atts := make([]*eth.Attestation, 128) for i := range atts { atts[i] = ð.Attestation{} - atts[i].Signature = b96 + atts[i].Signature = sig[:] atts[i].AggregationBits = bitfield.NewBitlist(1) atts[i].Data = ð.AttestationData{ Slot: 128, CommitteeIndex: 128, - BeaconBlockRoot: b32, + BeaconBlockRoot: root[:], Source: ð.Checkpoint{ Epoch: 128, - Root: b32, + Root: root[:], }, Target: ð.Checkpoint{ Epoch: 128, - Root: b32, + Root: root[:], }, } } @@ -749,21 +746,21 @@ func getFields() fields { Header: ð.BeaconBlockHeader{ Slot: 128, ProposerIndex: 128, - ParentRoot: b32, - StateRoot: b32, - BodyRoot: b32, + ParentRoot: root[:], + StateRoot: root[:], + BodyRoot: root[:], }, - Signature: b96, + Signature: sig[:], }, Header_2: ð.SignedBeaconBlockHeader{ Header: ð.BeaconBlockHeader{ Slot: 128, ProposerIndex: 128, - ParentRoot: b32, - StateRoot: b32, - BodyRoot: b32, + ParentRoot: root[:], + StateRoot: root[:], + BodyRoot: root[:], }, - Signature: b96, + Signature: sig[:], }, } attesterSlashing := ð.AttesterSlashing{ @@ -772,34 +769,34 @@ func getFields() fields { Data: ð.AttestationData{ Slot: 128, CommitteeIndex: 128, - BeaconBlockRoot: b32, + BeaconBlockRoot: root[:], Source: ð.Checkpoint{ Epoch: 128, - Root: b32, + Root: root[:], }, Target: ð.Checkpoint{ Epoch: 128, - Root: b32, + Root: root[:], }, }, - Signature: b96, + Signature: sig[:], }, Attestation_2: ð.IndexedAttestation{ AttestingIndices: []uint64{1, 2, 8}, Data: ð.AttestationData{ Slot: 128, CommitteeIndex: 128, - BeaconBlockRoot: b32, + BeaconBlockRoot: root[:], Source: ð.Checkpoint{ Epoch: 128, - Root: b32, + Root: root[:], }, Target: ð.Checkpoint{ Epoch: 128, - Root: b32, + Root: root[:], }, }, - Signature: b96, + Signature: sig[:], }, } voluntaryExit := ð.SignedVoluntaryExit{ @@ -807,7 +804,7 @@ func getFields() fields { Epoch: 128, ValidatorIndex: 128, }, - Signature: b96, + Signature: sig[:], } syncCommitteeBits := bitfield.NewBitvector512() syncCommitteeBits.SetBitAt(1, true) @@ -815,22 +812,22 @@ func getFields() fields { syncCommitteeBits.SetBitAt(8, true) syncAggregate := ð.SyncAggregate{ SyncCommitteeBits: syncCommitteeBits, - SyncCommitteeSignature: b96, + SyncCommitteeSignature: sig[:], } execPayload := &enginev1.ExecutionPayload{ - ParentHash: b32, + ParentHash: root[:], FeeRecipient: b20, - StateRoot: b32, - ReceiptsRoot: b32, + StateRoot: root[:], + ReceiptsRoot: root[:], LogsBloom: b256, - PrevRandao: b32, + PrevRandao: root[:], BlockNumber: 128, GasLimit: 128, GasUsed: 128, Timestamp: 128, - ExtraData: b32, - BaseFeePerGas: b32, - BlockHash: b32, + ExtraData: root[:], + BaseFeePerGas: root[:], + BlockHash: root[:], Transactions: [][]byte{ []byte("transaction1"), []byte("transaction2"), @@ -838,28 +835,25 @@ func getFields() fields { }, } execPayloadHeader := &enginev1.ExecutionPayloadHeader{ - ParentHash: b32, + ParentHash: root[:], FeeRecipient: b20, - StateRoot: b32, - ReceiptsRoot: b32, + StateRoot: root[:], + ReceiptsRoot: root[:], LogsBloom: b256, - PrevRandao: b32, + PrevRandao: root[:], BlockNumber: 128, GasLimit: 128, GasUsed: 128, Timestamp: 128, - ExtraData: b32, - BaseFeePerGas: b32, - BlockHash: b32, - TransactionsRoot: b32, + ExtraData: root[:], + BaseFeePerGas: root[:], + BlockHash: root[:], + TransactionsRoot: root[:], } return fields{ - b20: b20, - b32: b32, - b48: b48, - b96: b96, - b256: b256, + root: root, + sig: sig, deposits: deposits, atts: atts, proposerSlashings: []*eth.ProposerSlashing{proposerSlashing}, diff --git a/consensus-types/blocks/types.go b/consensus-types/blocks/types.go index 8863a9f29e..3c7e6bd510 100644 --- a/consensus-types/blocks/types.go +++ b/consensus-types/blocks/types.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/pkg/errors" + field_params "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" engine "github.com/prysmaticlabs/prysm/v3/proto/engine/v1" @@ -39,9 +40,9 @@ var ( type BeaconBlockBody struct { version int isBlinded bool - randaoReveal []byte + randaoReveal [field_params.BLSSignatureLength]byte eth1Data *eth.Eth1Data - graffiti []byte + graffiti [field_params.RootLength]byte proposerSlashings []*eth.ProposerSlashing attesterSlashings []*eth.AttesterSlashing attestations []*eth.Attestation @@ -57,8 +58,8 @@ type BeaconBlock struct { version int slot types.Slot proposerIndex types.ValidatorIndex - parentRoot []byte - stateRoot []byte + parentRoot [field_params.RootLength]byte + stateRoot [field_params.RootLength]byte body *BeaconBlockBody } @@ -66,7 +67,7 @@ type BeaconBlock struct { type SignedBeaconBlock struct { version int block *BeaconBlock - signature []byte + signature [field_params.BLSSignatureLength]byte } func errNotSupported(funcName string, ver int) error { diff --git a/consensus-types/interfaces/BUILD.bazel b/consensus-types/interfaces/BUILD.bazel index be748c7187..f635d65a24 100644 --- a/consensus-types/interfaces/BUILD.bazel +++ b/consensus-types/interfaces/BUILD.bazel @@ -9,6 +9,7 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces", visibility = ["//visibility:public"], deps = [ + "//config/fieldparams:go_default_library", "//consensus-types/primitives:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/validator-client:go_default_library", diff --git a/consensus-types/interfaces/beacon_block.go b/consensus-types/interfaces/beacon_block.go index cd463537ae..9110ccad12 100644 --- a/consensus-types/interfaces/beacon_block.go +++ b/consensus-types/interfaces/beacon_block.go @@ -2,6 +2,7 @@ package interfaces import ( ssz "github.com/prysmaticlabs/fastssz" + field_params "github.com/prysmaticlabs/prysm/v3/config/fieldparams" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" validatorpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/validator-client" @@ -12,7 +13,7 @@ import ( // a signed beacon block. type SignedBeaconBlock interface { Block() BeaconBlock - Signature() []byte + Signature() [field_params.BLSSignatureLength]byte IsNil() bool Copy() (SignedBeaconBlock, error) Proto() (proto.Message, error) @@ -34,12 +35,12 @@ type SignedBeaconBlock interface { type BeaconBlock interface { Slot() types.Slot ProposerIndex() types.ValidatorIndex - ParentRoot() []byte - StateRoot() []byte + ParentRoot() [field_params.RootLength]byte + StateRoot() [field_params.RootLength]byte Body() BeaconBlockBody IsNil() bool IsBlinded() bool - HashTreeRoot() ([32]byte, error) + HashTreeRoot() ([field_params.RootLength]byte, error) Proto() (proto.Message, error) ssz.Marshaler ssz.Unmarshaler @@ -51,9 +52,9 @@ type BeaconBlock interface { // BeaconBlockBody describes the method set employed by an object // that is a beacon block body. type BeaconBlockBody interface { - RandaoReveal() []byte + RandaoReveal() [field_params.BLSSignatureLength]byte Eth1Data() *ethpb.Eth1Data - Graffiti() []byte + Graffiti() [field_params.RootLength]byte ProposerSlashings() []*ethpb.ProposerSlashing AttesterSlashings() []*ethpb.AttesterSlashing Attestations() []*ethpb.Attestation @@ -61,7 +62,7 @@ type BeaconBlockBody interface { VoluntaryExits() []*ethpb.SignedVoluntaryExit SyncAggregate() (*ethpb.SyncAggregate, error) IsNil() bool - HashTreeRoot() ([32]byte, error) + HashTreeRoot() ([field_params.RootLength]byte, error) Proto() (proto.Message, error) Execution() (ExecutionData, error) } diff --git a/consensus-types/interfaces/utils.go b/consensus-types/interfaces/utils.go index 731e7f8f01..3711d3e127 100644 --- a/consensus-types/interfaces/utils.go +++ b/consensus-types/interfaces/utils.go @@ -38,9 +38,10 @@ func SignedBeaconBlockHeaderFromBlockInterface(sb SignedBeaconBlock) (*ethpb.Sig if err != nil { return nil, errors.Wrap(err, "failed to get block header of block") } + sig := sb.Signature() return ðpb.SignedBeaconBlockHeader{ Header: h, - Signature: sb.Signature(), + Signature: sig[:], }, nil } @@ -73,11 +74,13 @@ func BeaconBlockHeaderFromBlockInterface(block BeaconBlock) (*ethpb.BeaconBlockH if err != nil { return nil, errors.Wrap(err, "failed to get body root of block") } + parentRoot := block.ParentRoot() + stateRoot := block.StateRoot() return ðpb.BeaconBlockHeader{ Slot: block.Slot(), ProposerIndex: block.ProposerIndex(), - ParentRoot: block.ParentRoot(), - StateRoot: block.StateRoot(), + ParentRoot: parentRoot[:], + StateRoot: stateRoot[:], BodyRoot: bodyRoot[:], }, nil } diff --git a/consensus-types/mock/BUILD.bazel b/consensus-types/mock/BUILD.bazel index f879269b52..8b4351948a 100644 --- a/consensus-types/mock/BUILD.bazel +++ b/consensus-types/mock/BUILD.bazel @@ -6,6 +6,7 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/v3/consensus-types/mock", visibility = ["//visibility:public"], deps = [ + "//config/fieldparams:go_default_library", "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/consensus-types/mock/block.go b/consensus-types/mock/block.go index ec8b9465df..f7e29f2ef3 100644 --- a/consensus-types/mock/block.go +++ b/consensus-types/mock/block.go @@ -2,6 +2,7 @@ package mock import ( ssz "github.com/prysmaticlabs/fastssz" + field_params "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" @@ -21,7 +22,7 @@ func (m SignedBeaconBlock) Block() interfaces.BeaconBlock { return m.BeaconBlock } -func (SignedBeaconBlock) Signature() []byte { +func (SignedBeaconBlock) Signature() [field_params.BLSSignatureLength]byte { panic("implement me") } @@ -86,7 +87,7 @@ func (SignedBeaconBlock) Header() (*eth.SignedBeaconBlockHeader, error) { } type BeaconBlock struct { - Htr [32]byte + Htr [field_params.RootLength]byte HtrErr error BeaconBlockBody interfaces.BeaconBlockBody BlockSlot types.Slot @@ -96,7 +97,7 @@ func (BeaconBlock) AsSignRequestObject() (validatorpb.SignRequestObject, error) panic("implement me") } -func (m BeaconBlock) HashTreeRoot() ([32]byte, error) { +func (m BeaconBlock) HashTreeRoot() ([field_params.RootLength]byte, error) { return m.Htr, m.HtrErr } @@ -108,11 +109,11 @@ func (BeaconBlock) ProposerIndex() types.ValidatorIndex { panic("implement me") } -func (BeaconBlock) ParentRoot() []byte { +func (BeaconBlock) ParentRoot() [field_params.RootLength]byte { panic("implement me") } -func (BeaconBlock) StateRoot() []byte { +func (BeaconBlock) StateRoot() [field_params.RootLength]byte { panic("implement me") } @@ -158,7 +159,7 @@ func (BeaconBlock) Version() int { type BeaconBlockBody struct{} -func (BeaconBlockBody) RandaoReveal() []byte { +func (BeaconBlockBody) RandaoReveal() [field_params.BLSSignatureLength]byte { panic("implement me") } @@ -166,7 +167,7 @@ func (BeaconBlockBody) Eth1Data() *eth.Eth1Data { panic("implement me") } -func (BeaconBlockBody) Graffiti() []byte { +func (BeaconBlockBody) Graffiti() [field_params.RootLength]byte { panic("implement me") } @@ -198,7 +199,7 @@ func (BeaconBlockBody) IsNil() bool { return false } -func (BeaconBlockBody) HashTreeRoot() ([32]byte, error) { +func (BeaconBlockBody) HashTreeRoot() ([field_params.RootLength]byte, error) { panic("implement me") } diff --git a/proto/migration/v1alpha1_to_v1.go b/proto/migration/v1alpha1_to_v1.go index f69d5ec10b..605127c677 100644 --- a/proto/migration/v1alpha1_to_v1.go +++ b/proto/migration/v1alpha1_to_v1.go @@ -16,15 +16,18 @@ func BlockIfaceToV1BlockHeader(block interfaces.SignedBeaconBlock) (*ethpbv1.Sig if err != nil { return nil, errors.Wrap(err, "failed to get body root of block") } + parentRoot := block.Block().ParentRoot() + stateRoot := block.Block().StateRoot() + sig := block.Signature() return ðpbv1.SignedBeaconBlockHeader{ Message: ðpbv1.BeaconBlockHeader{ Slot: block.Block().Slot(), ProposerIndex: block.Block().ProposerIndex(), - ParentRoot: block.Block().ParentRoot(), - StateRoot: block.Block().StateRoot(), + ParentRoot: parentRoot[:], + StateRoot: stateRoot[:], BodyRoot: bodyRoot[:], }, - Signature: block.Signature(), + Signature: sig[:], }, nil } diff --git a/testing/endtoend/evaluators/operations.go b/testing/endtoend/evaluators/operations.go index 5899ce1b71..f8b2cc1993 100644 --- a/testing/endtoend/evaluators/operations.go +++ b/testing/endtoend/evaluators/operations.go @@ -159,7 +159,7 @@ func verifyGraffitiInBlocks(conns ...*grpc.ClientConn) error { slot := blk.Block().Slot() graffitiInBlock := blk.Block().Body().Graffiti() for _, graffiti := range helpers.Graffiti { - if bytes.Equal(bytesutil.PadTo([]byte(graffiti), 32), graffitiInBlock) { + if bytes.Equal(bytesutil.PadTo([]byte(graffiti), 32), graffitiInBlock[:]) { e = true break } diff --git a/tools/blocktree/BUILD.bazel b/tools/blocktree/BUILD.bazel index fbb7add9d4..c44cc0b815 100644 --- a/tools/blocktree/BUILD.bazel +++ b/tools/blocktree/BUILD.bazel @@ -10,7 +10,6 @@ go_library( "//beacon-chain/db:go_default_library", "//beacon-chain/db/filters:go_default_library", "//consensus-types/primitives:go_default_library", - "//encoding/bytesutil:go_default_library", "@com_github_emicklei_dot//:go_default_library", ], ) diff --git a/tools/blocktree/main.go b/tools/blocktree/main.go index d155b10721..ca2724098d 100644 --- a/tools/blocktree/main.go +++ b/tools/blocktree/main.go @@ -19,7 +19,6 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/db" "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/filters" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" ) var ( @@ -86,7 +85,7 @@ func main() { dotN := graph.Node(rStr).Box().Attr("label", label) n := &node{ - parentRoot: bytesutil.ToBytes32(b.Block().ParentRoot()), + parentRoot: b.Block().ParentRoot(), dothNode: &dotN, } m[r] = n diff --git a/validator/client/propose.go b/validator/client/propose.go index 66c9bfa481..b789ba3bc2 100644 --- a/validator/client/propose.go +++ b/validator/client/propose.go @@ -169,12 +169,13 @@ func (v *validator) ProposeBlock(ctx context.Context, slot types.Slot, pubKey [f } blkRoot := fmt.Sprintf("%#x", bytesutil.Trunc(blkResp.BlockRoot)) + graffiti := blk.Block().Body().Graffiti() log.WithFields(logrus.Fields{ "slot": blk.Block().Slot(), "blockRoot": blkRoot, "numAttestations": len(blk.Block().Body().Attestations()), "numDeposits": len(blk.Block().Body().Deposits()), - "graffiti": string(blk.Block().Body().Graffiti()), + "graffiti": string(graffiti[:]), "fork": version.String(blk.Block().Version()), }).Info("Submitted new block") diff --git a/validator/client/propose_test.go b/validator/client/propose_test.go index f6d437334d..2c0928ea5b 100644 --- a/validator/client/propose_test.go +++ b/validator/client/propose_test.go @@ -606,7 +606,8 @@ func testProposeBlock(t *testing.T, graffiti []byte) { }) validator.ProposeBlock(context.Background(), 1, pubKey) - assert.Equal(t, string(validator.graffiti), string(sentBlock.Block().Body().Graffiti())) + g := sentBlock.Block().Body().Graffiti() + assert.Equal(t, string(validator.graffiti), string(g[:])) require.LogsContain(t, hook, "Submitted new block") }) }