mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47: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>
76 lines
2.3 KiB
Go
76 lines
2.3 KiB
Go
package deposit_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing"
|
|
"github.com/prysmaticlabs/prysm/v3/config/params"
|
|
"github.com/prysmaticlabs/prysm/v3/contracts/deposit"
|
|
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
|
)
|
|
|
|
func TestDepositInput_GeneratesPb(t *testing.T) {
|
|
k1, err := bls.RandKey()
|
|
require.NoError(t, err)
|
|
k2, err := bls.RandKey()
|
|
require.NoError(t, err)
|
|
|
|
result, _, err := deposit.DepositInput(k1, k2, 0)
|
|
require.NoError(t, err)
|
|
assert.DeepEqual(t, k1.PublicKey().Marshal(), result.PublicKey)
|
|
|
|
sig, err := bls.SignatureFromBytes(result.Signature)
|
|
require.NoError(t, err)
|
|
testData := ðpb.DepositMessage{
|
|
PublicKey: result.PublicKey,
|
|
WithdrawalCredentials: result.WithdrawalCredentials,
|
|
Amount: result.Amount,
|
|
}
|
|
sr, err := testData.HashTreeRoot()
|
|
require.NoError(t, err)
|
|
domain, err := signing.ComputeDomain(
|
|
params.BeaconConfig().DomainDeposit,
|
|
nil, /*forkVersion*/
|
|
nil, /*genesisValidatorsRoot*/
|
|
)
|
|
require.NoError(t, err)
|
|
root, err := (ðpb.SigningData{ObjectRoot: sr[:], Domain: domain}).HashTreeRoot()
|
|
require.NoError(t, err)
|
|
assert.Equal(t, true, sig.Verify(k1.PublicKey(), root[:]))
|
|
}
|
|
|
|
func TestVerifyDepositSignature_ValidSig(t *testing.T) {
|
|
deposits, _, err := util.DeterministicDepositsAndKeys(1)
|
|
require.NoError(t, err)
|
|
dep := deposits[0]
|
|
domain, err := signing.ComputeDomain(
|
|
params.BeaconConfig().DomainDeposit,
|
|
params.BeaconConfig().GenesisForkVersion,
|
|
params.BeaconConfig().ZeroHash[:],
|
|
)
|
|
require.NoError(t, err)
|
|
err = deposit.VerifyDepositSignature(dep.Data, domain)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
func TestVerifyDepositSignature_InvalidSig(t *testing.T) {
|
|
deposits, _, err := util.DeterministicDepositsAndKeys(1)
|
|
require.NoError(t, err)
|
|
dep := deposits[0]
|
|
domain, err := signing.ComputeDomain(
|
|
params.BeaconConfig().DomainDeposit,
|
|
params.BeaconConfig().GenesisForkVersion,
|
|
params.BeaconConfig().ZeroHash[:],
|
|
)
|
|
require.NoError(t, err)
|
|
dep.Data.Signature = dep.Data.Signature[1:]
|
|
err = deposit.VerifyDepositSignature(dep.Data, domain)
|
|
if err == nil {
|
|
t.Fatal("Deposit Verification succeeds with a invalid signature")
|
|
}
|
|
}
|