mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 11:57:18 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
65 lines
2.2 KiB
Go
65 lines
2.2 KiB
Go
package state_native_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
|
"github.com/prysmaticlabs/prysm/v3/container/trie"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
|
)
|
|
|
|
func TestBeaconStateMerkleProofs(t *testing.T) {
|
|
ctx := context.Background()
|
|
st, _ := util.DeterministicGenesisState(t, 256)
|
|
htr, err := st.HashTreeRoot(ctx)
|
|
require.NoError(t, err)
|
|
t.Run("current sync committee", func(t *testing.T) {
|
|
_, err := st.CurrentSyncCommitteeProof(ctx)
|
|
require.ErrorContains(t, "unsupported", err)
|
|
})
|
|
t.Run("next sync committee", func(t *testing.T) {
|
|
_, err := st.NextSyncCommitteeProof(ctx)
|
|
require.ErrorContains(t, "unsupported", err)
|
|
})
|
|
t.Run("finalized root", func(t *testing.T) {
|
|
finalizedRoot := st.FinalizedCheckpoint().Root
|
|
proof, err := st.FinalizedRootProof(ctx)
|
|
require.NoError(t, err)
|
|
gIndex := statenative.FinalizedRootGeneralizedIndex()
|
|
valid := trie.VerifyMerkleProof(htr[:], finalizedRoot, gIndex, proof)
|
|
require.Equal(t, true, valid)
|
|
})
|
|
t.Run("recomputes root on dirty fields", func(t *testing.T) {
|
|
currentRoot, err := st.HashTreeRoot(ctx)
|
|
require.NoError(t, err)
|
|
cpt := st.FinalizedCheckpoint()
|
|
require.NoError(t, err)
|
|
|
|
// Edit the checkpoint.
|
|
cpt.Epoch = 100
|
|
require.NoError(t, st.SetFinalizedCheckpoint(cpt))
|
|
|
|
// Produce a proof for the finalized root.
|
|
proof, err := st.FinalizedRootProof(ctx)
|
|
require.NoError(t, err)
|
|
|
|
// We expect the previous step to have triggered
|
|
// a recomputation of dirty fields in the beacon state, resulting
|
|
// in a new hash tree root as the finalized checkpoint had previously
|
|
// changed and should have been marked as a dirty state field.
|
|
// The proof validity should be false for the old root, but true for the new.
|
|
finalizedRoot := st.FinalizedCheckpoint().Root
|
|
gIndex := statenative.FinalizedRootGeneralizedIndex()
|
|
valid := trie.VerifyMerkleProof(currentRoot[:], finalizedRoot, gIndex, proof)
|
|
require.Equal(t, false, valid)
|
|
|
|
newRoot, err := st.HashTreeRoot(ctx)
|
|
require.NoError(t, err)
|
|
|
|
valid = trie.VerifyMerkleProof(newRoot[:], finalizedRoot, gIndex, proof)
|
|
require.Equal(t, true, valid)
|
|
})
|
|
}
|