Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
domiwei committed Nov 27, 2024
1 parent 792fccd commit d991db7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 80 deletions.
4 changes: 2 additions & 2 deletions cl/cltypes/solid/bitvector.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ func (b *BitVector) EncodeSSZ(dst []byte) ([]byte, error) {
if len(dst) < b.EncodingSizeSSZ() {
dst = make([]byte, b.EncodingSizeSSZ())
}
copy(dst[:], b.container)
copy(dst, b.container)
return dst, nil
}

func (b *BitVector) HashSSZ() ([32]byte, error) {
// zero padding
buf := make([]byte, b.EncodingSizeSSZ())
copy(buf[:], b.container)
copy(buf, b.container)
return merkle_tree.BitvectorRootWithLimit(buf, uint64(b.bitCap))
}

Expand Down
11 changes: 5 additions & 6 deletions cl/spectest/consensus_tests/appendix.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ func init() {
func addSszTests() {
TestFormats.Add("ssz_static").
With("AggregateAndProof", getSSZStaticConsensusTest(&cltypes.AggregateAndProof{})).
//With("Attestation", getSSZStaticConsensusTest(&solid.Attestation{})).
With("AttestationData", getSSZStaticConsensusTest(&solid.AttestationData{})).
//With("BeaconBlockBody", getSSZStaticConsensusTest(cltypes.NewBeaconBody(&clparams.MainnetBeaconConfig, clparams.DenebVersion))).
With("BeaconBlockHeader", getSSZStaticConsensusTest(&cltypes.BeaconBlockHeader{})).
With("BeaconState", getSSZStaticConsensusTest(state.New(&clparams.MainnetBeaconConfig))).
With("BlobIdentifier", getSSZStaticConsensusTest(&cltypes.BlobIdentifier{})).
Expand All @@ -121,8 +119,6 @@ func addSszTests() {
// With("DepositMessage", getSSZStaticConsensusTest(&cltypes.DepositMessage{})).
// With("Eth1Block", getSSZStaticConsensusTest(&cltypes.Eth1Block{})).
With("Eth1Data", getSSZStaticConsensusTest(&cltypes.Eth1Data{})).
//With("ExecutionPayload", getSSZStaticConsensusTest(cltypes.NewEth1Block(clparams.Phase0Version, &clparams.MainnetBeaconConfig))).
//With("ExecutionPayloadHeader", getSSZStaticConsensusTest(&cltypes.Eth1Header{})).
With("Fork", getSSZStaticConsensusTest(&cltypes.Fork{})).
//With("ForkData", getSSZStaticConsensusTest(&cltypes.ForkData{})).
//With("HistoricalBatch", getSSZStaticConsensusTest(&cltypes.HistoricalBatch{})).
Expand All @@ -144,10 +140,13 @@ func addSszTests() {
With("SyncAggregate", getSSZStaticConsensusTest(&cltypes.SyncAggregate{})).
With("SyncAggregatorSelectionData", getSSZStaticConsensusTest(&cltypes.SyncAggregatorSelectionData{})).
With("SyncCommittee", getSSZStaticConsensusTest(&solid.SyncCommittee{})).
// With("SyncCommitteeContribution", getSSZStaticConsensusTest(&cltypes.SyncCommitteeContribution{})).
// With("SyncCommitteeMessage", getSSZStaticConsensusTest(&cltypes.SyncCommitteeMessage{})).
With("Validator", getSSZStaticConsensusTest(solid.NewValidator())).
With("WithdrawalRequest", getSSZStaticConsensusTest(&solid.WithdrawalRequest{})).
With("ExecutionPayloadHeader", sszStaticTestNewObjectByFunc(
func(v clparams.StateVersion) *cltypes.Eth1Header {
return cltypes.NewEth1Header(v)
}, withTestJson())).
With("SyncCommitteeContribution", sszStaticTestByEmptyObject(&cltypes.Contribution{})).
With("Withdrawal", sszStaticTestByEmptyObject(&cltypes.Withdrawal{}, withTestJson())).
With("LightClientHeader", sszStaticTestNewObjectByFunc(
func(v clparams.StateVersion) *cltypes.LightClientHeader {
Expand Down
72 changes: 0 additions & 72 deletions cl/spectest/consensus_tests/forks.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,75 +66,3 @@ var ForksFork = spectest.HandlerFunc(func(t *testing.T, root fs.FS, c spectest.T

return nil
})

/*
func print2(pre, post *state.CachingBeaconState) string {
preHash, err := pre.ValidatorSet().HashSSZ()
if err != nil {
return fmt.Sprintf("pre hash err %v", err)
}
postHash, err := post.ValidatorSet().HashSSZ()
if err != nil {
return fmt.Sprintf("post hash err %v", err)
}
if preHash != postHash {
return fmt.Sprintf("vs pre hash %v != post hash %v", preHash, postHash)
}
if pre.GetEarlistExitEpoch() != post.GetEarlistExitEpoch() {
return fmt.Sprintf("earlistExitEpoch pre %d != post %d", pre.GetEarlistExitEpoch(), post.GetEarlistExitEpoch())
}
if pre.GetEarlistConsolidationEpoch() != post.GetEarlistConsolidationEpoch() {
return fmt.Sprintf("earlistConsEpoch pre %d != post %d", pre.GetEarlistConsolidationEpoch(), post.GetEarlistConsolidationEpoch())
}
if pre.GetExitBalanceToConsume() != post.GetExitBalanceToConsume() {
return fmt.Sprintf("exitBalance pre %d != post %d", pre.GetExitBalanceToConsume(), post.GetExitBalanceToConsume())
}
if pre.GetConsolidationBalanceToConsume() != post.GetConsolidationBalanceToConsume() {
return fmt.Sprintf("consolidationBalance pre %d != post %d", pre.GetConsolidationBalanceToConsume(), post.GetConsolidationBalanceToConsume())
}
hash1, err := pre.GetPendingDeposits().HashSSZ()
if err != nil {
return fmt.Sprintf("pre hash err %v", err)
}
hash2, err := post.GetPendingDeposits().HashSSZ()
if err != nil {
return fmt.Sprintf("post hash err %v", err)
}
if hash1 != hash2 {
return fmt.Sprintf("pre hash %v != post hash %v", hash1, hash2)
}
return "ok"
}
func print(pre, post *state.CachingBeaconState) string {
d1 := []solid.PendingDeposit{}
deposits := pre.GetPendingDeposits()
deposits.Range(func(index int, value *solid.PendingDeposit, length int) bool {
d1 = append(d1, *value)
return true
})
//fmt.Println("pre", d)
d2 := []solid.PendingDeposit{}
deposits = post.GetPendingDeposits()
deposits.Range(func(index int, value *solid.PendingDeposit, length int) bool {
d2 = append(d2, *value)
return true
})
//fmt.Println("post", d)
if len(d1) != len(d2) {
return fmt.Sprintf("pre len %d != post len %d", len(d1), len(d2))
}
for i := range d1 {
if d1[i] != d2[i] {
return fmt.Sprintf("pre %v != post %v", d1[i], d2[i])
}
}
return "ok"
}
*/

0 comments on commit d991db7

Please sign in to comment.