mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 13:28:01 -05:00
Prevent parent block with same slot (#5842)
* Block must have a higher slot than parent state * New tests and existing test * Typo * Fixed more existing test.... * Merge branch 'master' into sec0 * Merge branch 'master' into sec0 * Merge branch 'master' of github.com:prysmaticlabs/prysm into sec0 * Update spec tests to v0.11.3 * Merge branch 'sec0' of github.com:prysmaticlabs/prysm into sec0 * Update badge to v0.11.3 * Update badge to v0.11.3 * Merge refs/heads/master into sec0
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
[](https://buildkite.com/prysmatic-labs/prysm)
|
[](https://buildkite.com/prysmatic-labs/prysm)
|
||||||
[](https://app.fuzzit.dev/orgs/prysmaticlabs-gh/dashboard)
|
[](https://app.fuzzit.dev/orgs/prysmaticlabs-gh/dashboard)
|
||||||
[](https://github.com/ethereum/eth2.0-specs/tree/v0.11.2)
|
[](https://github.com/ethereum/eth2.0-specs/tree/v0.11.3)
|
||||||
[](https://discord.gg/KSA7rPr)
|
[](https://discord.gg/KSA7rPr)
|
||||||
[](https://gitter.im/prysmaticlabs/geth-sharding?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
[](https://gitter.im/prysmaticlabs/geth-sharding?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||||
|
|
||||||
|
|||||||
12
WORKSPACE
12
WORKSPACE
@@ -214,8 +214,8 @@ filegroup(
|
|||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
)
|
)
|
||||||
""",
|
""",
|
||||||
sha256 = "e31f491682a7b5bcf48250efefd150e6dcf0b2d7658d0ec5407c053fb84cbad0",
|
sha256 = "489f85d7c17a901b9069c95f656154fdf1385db00f3aeb3e0319aed8745f9453",
|
||||||
url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v0.11.2/general.tar.gz",
|
url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v0.11.3/general.tar.gz",
|
||||||
)
|
)
|
||||||
|
|
||||||
http_archive(
|
http_archive(
|
||||||
@@ -230,8 +230,8 @@ filegroup(
|
|||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
)
|
)
|
||||||
""",
|
""",
|
||||||
sha256 = "1d978d482cd680f99dfc808ccfd59c88e33089450ffc1e283041cbf6dc8982db",
|
sha256 = "b83000fbcb60b7a5b8c0e805f3fee6953b17bfe0fe6658416e7d99e6d261f284",
|
||||||
url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v0.11.2/minimal.tar.gz",
|
url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v0.11.3/minimal.tar.gz",
|
||||||
)
|
)
|
||||||
|
|
||||||
http_archive(
|
http_archive(
|
||||||
@@ -246,8 +246,8 @@ filegroup(
|
|||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
)
|
)
|
||||||
""",
|
""",
|
||||||
sha256 = "ac68dcd5c3a78a7a51e86b61131f71683d844c81b79547029cc6dfa259c3c6dd",
|
sha256 = "ae0c09ab49afa69085c91f9e2f2f4de6526d43b927609839b1597c674b4dccde",
|
||||||
url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v0.11.2/mainnet.tar.gz",
|
url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v0.11.3/mainnet.tar.gz",
|
||||||
)
|
)
|
||||||
|
|
||||||
http_archive(
|
http_archive(
|
||||||
|
|||||||
@@ -257,16 +257,13 @@ func ProcessSlots(ctx context.Context, state *stateTrie.BeaconState, slot uint64
|
|||||||
}
|
}
|
||||||
span.AddAttributes(trace.Int64Attribute("slots", int64(slot)-int64(state.Slot())))
|
span.AddAttributes(trace.Int64Attribute("slots", int64(slot)-int64(state.Slot())))
|
||||||
|
|
||||||
if state.Slot() > slot {
|
// The block must have a higher slot than parent state.
|
||||||
|
if state.Slot() >= slot {
|
||||||
err := fmt.Errorf("expected state.slot %d < slot %d", state.Slot(), slot)
|
err := fmt.Errorf("expected state.slot %d < slot %d", state.Slot(), slot)
|
||||||
traceutil.AnnotateError(span, err)
|
traceutil.AnnotateError(span, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if state.Slot() == slot {
|
|
||||||
return state, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
highestSlot := state.Slot()
|
highestSlot := state.Slot()
|
||||||
key := state.Slot()
|
key := state.Slot()
|
||||||
|
|
||||||
|
|||||||
@@ -481,7 +481,7 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) {
|
|||||||
aggBits.SetBitAt(0, true)
|
aggBits.SetBitAt(0, true)
|
||||||
blockAtt := ðpb.Attestation{
|
blockAtt := ðpb.Attestation{
|
||||||
Data: ðpb.AttestationData{
|
Data: ðpb.AttestationData{
|
||||||
Slot: beaconState.Slot() - 1,
|
Slot: beaconState.Slot(),
|
||||||
Target: ðpb.Checkpoint{Epoch: helpers.CurrentEpoch(beaconState)},
|
Target: ðpb.Checkpoint{Epoch: helpers.CurrentEpoch(beaconState)},
|
||||||
Source: ðpb.Checkpoint{
|
Source: ðpb.Checkpoint{
|
||||||
Epoch: 0,
|
Epoch: 0,
|
||||||
@@ -525,20 +525,32 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) {
|
|||||||
}
|
}
|
||||||
exit.Signature = privKeys[exit.Exit.ValidatorIndex].Sign(signingRoot[:]).Marshal()[:]
|
exit.Signature = privKeys[exit.Exit.ValidatorIndex].Sign(signingRoot[:]).Marshal()[:]
|
||||||
|
|
||||||
|
header := beaconState.LatestBlockHeader()
|
||||||
|
prevStateRoot, err := beaconState.HashTreeRoot(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
header.StateRoot = prevStateRoot[:]
|
||||||
|
if err := beaconState.SetLatestBlockHeader(header); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
parentRoot, err := stateutil.BlockHeaderRoot(beaconState.LatestBlockHeader())
|
parentRoot, err := stateutil.BlockHeaderRoot(beaconState.LatestBlockHeader())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
copied := beaconState.Copy()
|
||||||
randaoReveal, err := testutil.RandaoReveal(beaconState, currentEpoch, privKeys)
|
if err := copied.SetSlot(beaconState.Slot() + 1); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
randaoReveal, err := testutil.RandaoReveal(copied, currentEpoch, privKeys)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
block := ðpb.SignedBeaconBlock{
|
block := ðpb.SignedBeaconBlock{
|
||||||
Block: ðpb.BeaconBlock{
|
Block: ðpb.BeaconBlock{
|
||||||
ParentRoot: parentRoot[:],
|
ParentRoot: parentRoot[:],
|
||||||
Slot: beaconState.Slot(),
|
Slot: beaconState.Slot() + 1,
|
||||||
ProposerIndex: 17,
|
ProposerIndex: 13,
|
||||||
Body: ðpb.BeaconBlockBody{
|
Body: ðpb.BeaconBlockBody{
|
||||||
RandaoReveal: randaoReveal,
|
RandaoReveal: randaoReveal,
|
||||||
ProposerSlashings: proposerSlashings,
|
ProposerSlashings: proposerSlashings,
|
||||||
@@ -559,6 +571,9 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) {
|
|||||||
}
|
}
|
||||||
block.Signature = sig.Marshal()
|
block.Signature = sig.Marshal()
|
||||||
|
|
||||||
|
if beaconState.SetSlot(block.Block.Slot) != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
beaconState, err = state.ProcessBlock(context.Background(), beaconState, block)
|
beaconState, err = state.ProcessBlock(context.Background(), beaconState, block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Expected block to pass processing conditions: %v", err)
|
t.Fatalf("Expected block to pass processing conditions: %v", err)
|
||||||
@@ -829,6 +844,7 @@ func TestProcessBlk_AttsBasedOnValidatorCount(t *testing.T) {
|
|||||||
for i := 0; i < len(atts); i++ {
|
for i := 0; i < len(atts); i++ {
|
||||||
att := ðpb.Attestation{
|
att := ðpb.Attestation{
|
||||||
Data: ðpb.AttestationData{
|
Data: ðpb.AttestationData{
|
||||||
|
Slot: 1,
|
||||||
Source: ðpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]},
|
Source: ðpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]},
|
||||||
Target: ðpb.Checkpoint{Epoch: 0}},
|
Target: ðpb.Checkpoint{Epoch: 0}},
|
||||||
AggregationBits: aggBits,
|
AggregationBits: aggBits,
|
||||||
@@ -859,18 +875,33 @@ func TestProcessBlk_AttsBasedOnValidatorCount(t *testing.T) {
|
|||||||
atts[i] = att
|
atts[i] = att
|
||||||
}
|
}
|
||||||
|
|
||||||
epochSignature, err := testutil.RandaoReveal(s, helpers.CurrentEpoch(s), privKeys)
|
copied := s.Copy()
|
||||||
|
if err := copied.SetSlot(s.Slot() + 1); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
epochSignature, err := testutil.RandaoReveal(copied, helpers.CurrentEpoch(copied), privKeys)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
header := s.LatestBlockHeader()
|
||||||
|
prevStateRoot, err := s.HashTreeRoot(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
header.StateRoot = prevStateRoot[:]
|
||||||
|
if err := s.SetLatestBlockHeader(header); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
parentRoot, err := stateutil.BlockHeaderRoot(s.LatestBlockHeader())
|
parentRoot, err := stateutil.BlockHeaderRoot(s.LatestBlockHeader())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
blk := ðpb.SignedBeaconBlock{
|
blk := ðpb.SignedBeaconBlock{
|
||||||
Block: ðpb.BeaconBlock{
|
Block: ðpb.BeaconBlock{
|
||||||
ProposerIndex: 72,
|
ProposerIndex: 156,
|
||||||
Slot: s.Slot(),
|
Slot: s.Slot() + 1,
|
||||||
ParentRoot: parentRoot[:],
|
ParentRoot: parentRoot[:],
|
||||||
Body: ðpb.BeaconBlockBody{
|
Body: ðpb.BeaconBlockBody{
|
||||||
Eth1Data: ðpb.Eth1Data{},
|
Eth1Data: ðpb.Eth1Data{},
|
||||||
@@ -890,6 +921,9 @@ func TestProcessBlk_AttsBasedOnValidatorCount(t *testing.T) {
|
|||||||
config.MinAttestationInclusionDelay = 0
|
config.MinAttestationInclusionDelay = 0
|
||||||
params.OverrideBeaconConfig(config)
|
params.OverrideBeaconConfig(config)
|
||||||
|
|
||||||
|
if s.SetSlot(s.Slot()+1) != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
if _, err := state.ProcessBlock(context.Background(), s, blk); err != nil {
|
if _, err := state.ProcessBlock(context.Background(), s, blk); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -1036,3 +1070,29 @@ func TestProcessOperations_IncorrectDeposits(t *testing.T) {
|
|||||||
t.Errorf("Expected %s, received %v", want, err)
|
t.Errorf("Expected %s, received %v", want, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProcessSlots_SameSlotAsParentState(t *testing.T) {
|
||||||
|
slot := uint64(2)
|
||||||
|
parentState, err := beaconstate.InitializeFromProto(&pb.BeaconState{Slot: slot})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
wanted := "expected state.slot 2 < slot 2"
|
||||||
|
if _, err := state.ProcessSlots(context.Background(), parentState, slot); err.Error() != wanted {
|
||||||
|
t.Error("Did not get wanted error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProcessSlots_LowerSlotAsParentState(t *testing.T) {
|
||||||
|
slot := uint64(2)
|
||||||
|
parentState, err := beaconstate.InitializeFromProto(&pb.BeaconState{Slot: slot})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
wanted := "expected state.slot 2 < slot 1"
|
||||||
|
if _, err := state.ProcessSlots(context.Background(), parentState, slot-1); err.Error() != wanted {
|
||||||
|
t.Error("Did not get wanted error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user