From 476b84d2a87d5ce8f8f64d1433657b5f37856338 Mon Sep 17 00:00:00 2001 From: Potuz Date: Fri, 22 Sep 2023 15:38:29 -0300 Subject: [PATCH] Apply proposer boost to first block in equivocation --- .../forkchoice/doubly-linked-tree/proposer_boost_test.go | 8 ++++++++ beacon-chain/forkchoice/doubly-linked-tree/store.go | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/beacon-chain/forkchoice/doubly-linked-tree/proposer_boost_test.go b/beacon-chain/forkchoice/doubly-linked-tree/proposer_boost_test.go index c132f227155b..5eb001ae9d78 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/proposer_boost_test.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/proposer_boost_test.go @@ -49,6 +49,7 @@ func TestForkChoice_BoostProposerRoot_PreventsExAnteAttack(t *testing.T) { slot := primitives.Slot(1) driftGenesisTime(f, slot, 0) newRoot := indexToHash(1) + f.store.proposerBoostRoot = [32]byte{} state, blkRoot, err := prepareForkchoiceState( ctx, slot, @@ -74,6 +75,7 @@ func TestForkChoice_BoostProposerRoot_PreventsExAnteAttack(t *testing.T) { slot = primitives.Slot(2) driftGenesisTime(f, slot, 0) newRoot = indexToHash(2) + f.store.proposerBoostRoot = [32]byte{} state, blkRoot, err = prepareForkchoiceState( ctx, slot, @@ -101,6 +103,7 @@ func TestForkChoice_BoostProposerRoot_PreventsExAnteAttack(t *testing.T) { slot = primitives.Slot(3) driftGenesisTime(f, slot, 0) newRoot = indexToHash(3) + f.store.proposerBoostRoot = [32]byte{} state, blkRoot, err = prepareForkchoiceState( ctx, slot, @@ -129,6 +132,7 @@ func TestForkChoice_BoostProposerRoot_PreventsExAnteAttack(t *testing.T) { slot = primitives.Slot(4) driftGenesisTime(f, slot, 0) newRoot = indexToHash(4) + f.store.proposerBoostRoot = [32]byte{} state, blkRoot, err = prepareForkchoiceState( ctx, slot, @@ -335,6 +339,7 @@ func TestForkChoice_BoostProposerRoot_PreventsExAnteAttack(t *testing.T) { cSlot := primitives.Slot(2) driftGenesisTime(f, cSlot, 0) c := indexToHash(2) + f.store.proposerBoostRoot = [32]byte{} state, blkRoot, err := prepareForkchoiceState( ctx, cSlot, @@ -354,6 +359,7 @@ func TestForkChoice_BoostProposerRoot_PreventsExAnteAttack(t *testing.T) { bSlot := primitives.Slot(1) b := indexToHash(1) + f.store.proposerBoostRoot = [32]byte{} state, blkRoot, err = prepareForkchoiceState( ctx, bSlot, @@ -378,6 +384,7 @@ func TestForkChoice_BoostProposerRoot_PreventsExAnteAttack(t *testing.T) { // A block D, building on B, is received at slot N+3. It should not be able to win without boosting. dSlot := primitives.Slot(3) d := indexToHash(3) + f.store.proposerBoostRoot = [32]byte{} state, blkRoot, err = prepareForkchoiceState( ctx, dSlot, @@ -398,6 +405,7 @@ func TestForkChoice_BoostProposerRoot_PreventsExAnteAttack(t *testing.T) { // If the same block arrives with boosting then it becomes head: driftGenesisTime(f, dSlot, 0) d2 := indexToHash(30) + f.store.proposerBoostRoot = [32]byte{} state, blkRoot, err = prepareForkchoiceState( ctx, dSlot, diff --git a/beacon-chain/forkchoice/doubly-linked-tree/store.go b/beacon-chain/forkchoice/doubly-linked-tree/store.go index dbf89590f375..1fbb28076637 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/store.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/store.go @@ -109,7 +109,8 @@ func (s *Store) insert(ctx context.Context, secondsIntoSlot := (timeNow - s.genesisTime) % params.BeaconConfig().SecondsPerSlot currentSlot := slots.CurrentSlot(s.genesisTime) boostThreshold := params.BeaconConfig().SecondsPerSlot / params.BeaconConfig().IntervalsPerSlot - if currentSlot == slot && secondsIntoSlot < boostThreshold { + isFirstBlock := s.proposerBoostRoot == [32]byte{} + if currentSlot == slot && secondsIntoSlot < boostThreshold && isFirstBlock { s.proposerBoostRoot = root }