Compare commits

...

3 Commits

Author SHA1 Message Date
terence tsao
14446eb3c3 Devnet2 state bug 2024-09-01 21:09:32 -07:00
rkapka
e67c16a36e electra ssz 2024-08-26 20:20:09 +02:00
rkapka
88d45f98ea Revert "Update spec tests to v1.5.0-alpha.4 (#14340)"
This reverts commit 22f6f787e1.
2024-08-20 13:01:30 +02:00
8 changed files with 82 additions and 48 deletions

View File

@@ -227,7 +227,7 @@ filegroup(
url = "https://github.com/ethereum/EIPs/archive/5480440fe51742ed23342b68cf106cefd427e39d.tar.gz",
)
consensus_spec_version = "v1.5.0-alpha.4"
consensus_spec_version = "v1.5.0-alpha.3"
bls_test_version = "v0.1.1"
@@ -243,7 +243,7 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
integrity = "sha256-sSw6c9IR/ZiWjyk1cbfVGC/aUkId4r7+eSl3haWsq0E=",
integrity = "sha256-+byv+GUOQytex5GgtjBGVoNDseJZbiBdAjEtlgCbjEo=",
url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/general.tar.gz" % consensus_spec_version,
)
@@ -259,7 +259,7 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
integrity = "sha256-OGlKhbA6TjTP0p1ojXVCJPzLEHJzewKkhAa+PQggoiU=",
integrity = "sha256-JJUy/jT1h3kGQkinTuzL7gMOA1+qgmPgJXVrYuH63Cg=",
url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/minimal.tar.gz" % consensus_spec_version,
)
@@ -275,7 +275,7 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
integrity = "sha256-ah2Gj4ci5hw5vQgpUWkNjEQutoBCepg5jcpTi0DKVB0=",
integrity = "sha256-T2VM4Qd0SwgGnTjWxjOX297DqEsovO9Ueij1UEJy48Y=",
url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/mainnet.tar.gz" % consensus_spec_version,
)
@@ -290,7 +290,7 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
integrity = "sha256-I+llAsIF6lPP8RUtZ2DFsJqtCs4UPh+st3hFs12FWpY=",
integrity = "sha256-OP9BCBcQ7i+93bwj7ktY8pZ5uWsGjgTe4XTp7BDhX+I=",
strip_prefix = "consensus-specs-" + consensus_spec_version[1:],
url = "https://github.com/ethereum/consensus-specs/archive/refs/tags/%s.tar.gz" % consensus_spec_version,
)

View File

@@ -49,7 +49,7 @@ func ProcessPendingConsolidations(ctx context.Context, st state.BeaconState) err
return errors.New("nil state")
}
nextEpoch := slots.ToEpoch(st.Slot()) + 1
currentEpoch := slots.ToEpoch(st.Slot())
var nextPendingConsolidation uint64
pendingConsolidations, err := st.PendingConsolidations()
@@ -66,7 +66,7 @@ func ProcessPendingConsolidations(ctx context.Context, st state.BeaconState) err
nextPendingConsolidation++
continue
}
if sourceValidator.WithdrawableEpoch > nextEpoch {
if sourceValidator.WithdrawableEpoch > currentEpoch {
break
}

View File

@@ -248,7 +248,7 @@ func ProcessPendingBalanceDeposits(ctx context.Context, st state.BeaconState, ac
// constants
ffe := params.BeaconConfig().FarFutureEpoch
nextEpoch := slots.ToEpoch(st.Slot()) + 1
curEpoch := slots.ToEpoch(st.Slot())
for _, balanceDeposit := range deposits {
v, err := st.ValidatorAtIndexReadOnly(balanceDeposit.Index)
@@ -259,7 +259,7 @@ func ProcessPendingBalanceDeposits(ctx context.Context, st state.BeaconState, ac
// If the validator is currently exiting, postpone the deposit until after the withdrawable
// epoch.
if v.ExitEpoch() < ffe {
if nextEpoch <= v.WithdrawableEpoch() {
if curEpoch <= v.WithdrawableEpoch() {
depositsToPostpone = append(depositsToPostpone, balanceDeposit)
} else {
// The deposited balance will never become active. Therefore, we increase the balance but do

View File

@@ -53,6 +53,17 @@ func (*State) replayBlocks(
if err != nil {
return nil, err
}
htr, err := state.HashTreeRoot(ctx)
if err != nil {
return nil, err
}
if htr != signed[i].Block().StateRoot() {
log.WithFields(logrus.Fields{
"stateRoot": fmt.Sprintf("%x", htr),
"blockRoot": fmt.Sprintf("%x", signed[i].Block().StateRoot()),
"slot": signed[i].Block().Slot(),
}).Fatal("state root mismatch")
}
}
}

View File

@@ -233,6 +233,8 @@ func ConfigToYaml(cfg *BeaconChainConfig) []byte {
fmt.Sprintf("MESSAGE_DOMAIN_INVALID_SNAPPY: %#x", cfg.MessageDomainInvalidSnappy),
fmt.Sprintf("MESSAGE_DOMAIN_VALID_SNAPPY: %#x", cfg.MessageDomainValidSnappy),
fmt.Sprintf("MIN_EPOCHS_FOR_BLOCK_REQUESTS: %d", int(cfg.MinEpochsForBlockRequests)),
fmt.Sprintf("ELECTRA_FORK_EPOCH: %d", cfg.ElectraForkEpoch),
fmt.Sprintf("ELECTRA_FORK_VERSION: %#x", cfg.ElectraForkVersion),
}
yamlFile := []byte(strings.Join(lines, "\n"))

View File

@@ -32,8 +32,6 @@ var placeholderFields = []string{
"EIP7002_FORK_VERSION",
"EIP7594_FORK_EPOCH",
"EIP7594_FORK_VERSION",
"EIP7732_FORK_EPOCH",
"EIP7732_FORK_VERSION",
"FIELD_ELEMENTS_PER_BLOB", // Compile time constant.
"KZG_COMMITMENT_INCLUSION_PROOF_DEPTH", // Compile time constant on BlobSidecar.commitment_inclusion_proof.
"MAX_BLOBS_PER_BLOCK",

View File

@@ -1,5 +1,5 @@
// Code generated by fastssz. DO NOT EDIT.
// Hash: 84572d8fa233c45a41477bced891ee355cc1745ae0fad290f110b7f6b5ed12e1
// Hash: ecf364fe5acf3bed144e2e2d74edecf4b9bb2a8433927332e95d28a80b5f733a
package eth
import (
@@ -30,20 +30,20 @@ func (a *AttestationElectra) MarshalSSZTo(buf []byte) (dst []byte, err error) {
return
}
// Field (2) 'CommitteeBits'
if size := len(a.CommitteeBits); size != 8 {
err = ssz.ErrBytesLengthFn("--.CommitteeBits", size, 8)
return
}
dst = append(dst, a.CommitteeBits...)
// Field (3) 'Signature'
// Field (2) 'Signature'
if size := len(a.Signature); size != 96 {
err = ssz.ErrBytesLengthFn("--.Signature", size, 96)
return
}
dst = append(dst, a.Signature...)
// Field (3) 'CommitteeBits'
if size := len(a.CommitteeBits); size != 8 {
err = ssz.ErrBytesLengthFn("--.CommitteeBits", size, 8)
return
}
dst = append(dst, a.CommitteeBits...)
// Field (0) 'AggregationBits'
if size := len(a.AggregationBits); size > 131072 {
err = ssz.ErrBytesLengthFn("--.AggregationBits", size, 131072)
@@ -82,17 +82,17 @@ func (a *AttestationElectra) UnmarshalSSZ(buf []byte) error {
return err
}
// Field (2) 'CommitteeBits'
if cap(a.CommitteeBits) == 0 {
a.CommitteeBits = make([]byte, 0, len(buf[132:140]))
}
a.CommitteeBits = append(a.CommitteeBits, buf[132:140]...)
// Field (3) 'Signature'
// Field (2) 'Signature'
if cap(a.Signature) == 0 {
a.Signature = make([]byte, 0, len(buf[140:236]))
a.Signature = make([]byte, 0, len(buf[132:228]))
}
a.Signature = append(a.Signature, buf[140:236]...)
a.Signature = append(a.Signature, buf[132:228]...)
// Field (3) 'CommitteeBits'
if cap(a.CommitteeBits) == 0 {
a.CommitteeBits = make([]byte, 0, len(buf[228:236]))
}
a.CommitteeBits = append(a.CommitteeBits, buf[228:236]...)
// Field (0) 'AggregationBits'
{
@@ -139,20 +139,20 @@ func (a *AttestationElectra) HashTreeRootWith(hh *ssz.Hasher) (err error) {
return
}
// Field (2) 'CommitteeBits'
if size := len(a.CommitteeBits); size != 8 {
err = ssz.ErrBytesLengthFn("--.CommitteeBits", size, 8)
return
}
hh.PutBytes(a.CommitteeBits)
// Field (3) 'Signature'
// Field (2) 'Signature'
if size := len(a.Signature); size != 96 {
err = ssz.ErrBytesLengthFn("--.Signature", size, 96)
return
}
hh.PutBytes(a.Signature)
// Field (3) 'CommitteeBits'
if size := len(a.CommitteeBits); size != 8 {
err = ssz.ErrBytesLengthFn("--.CommitteeBits", size, 8)
return
}
hh.PutBytes(a.CommitteeBits)
hh.Merkleize(indx)
return
}

View File

@@ -2,20 +2,20 @@ package main
import (
"context"
"encoding/hex"
"flag"
"fmt"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/transition/interop"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/db/kv"
doublylinkedtree "github.com/prysmaticlabs/prysm/v5/beacon-chain/forkchoice/doubly-linked-tree"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/v5/config/features"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/config/params"
)
var (
// Required fields
datadir = flag.String("datadir", "", "Path to data directory.")
state = flag.Uint("state", 0, "Extract state at this slot.")
)
func main() {
@@ -27,20 +27,43 @@ func main() {
if err != nil {
panic(err)
}
cfg := params.BeaconConfig()
cfg.ChurnLimitQuotient = 128 // Devnet uses this config. Without it, state transition will fail when processing epoch
params.OverrideBeaconConfig(cfg)
ctx := context.Background()
slot := primitives.Slot(*state)
_, roots, err := d.BlockRootsBySlot(ctx, slot)
fc := doublylinkedtree.New()
s := stategen.New(d, fc)
hexString := "04caf4ff7fc7ab2b294ae83ea7a4c1f1763a3e552a08735a6a5d5755b4fd4933" // This is the finalized root, which we'll first replay to and save it as finalized root for state transition
root, err := hex.DecodeString(hexString)
if err != nil {
panic(err)
}
if len(roots) != 1 {
fmt.Printf("Expected 1 block root for slot %d, got %d roots", *state, len(roots))
st, err := s.StateByRoot(ctx, [32]byte(root))
if err != nil {
panic(err)
}
s, err := d.State(ctx, roots[0])
_, err = s.Resume(ctx, st) // Resume saves the caches of the finalized state for state gen
if err != nil {
panic(err)
}
interop.WriteStateToDisk(s)
fmt.Println("done")
hexString = "ce3665faa64345557b47afa03ef7b81e48c24c6a712e4c3c90303cef64e88af8" // This is the target root
root, err = hex.DecodeString(hexString)
if err != nil {
panic(err)
}
st, err = s.StateByRoot(ctx, [32]byte(root))
if err != nil {
panic(err)
}
st, err = s.StateByRoot(ctx, [32]byte(root)) // Replay twice fails because start state caches are incorrect
if err != nil {
// Error: panic: state root 0xd21dac2ac7a03561f17c550bcaa7d5d5be8b9f5cbd2e23ae808fc8306e290be9
// does not match the block state root 0x3952f2c8a6eebc7ff96f05ca54fca81363a0fb720238722e00197a7c1e3c7149
panic(err)
}
}