mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-04 00:44:27 +00:00
b7175b3482
* Revert "Revert "Update fastssz" (#7100)"
This reverts commit b954db9704
.
* Preston's patch
* Merge branch 'master' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* Update fssz, add regression test case
* more HTR with fssz
* fix some tests
* only one test left
* Make it so that HTR will work
* gofmt, imports
* gofmt, imports
* fix
* Merge branch 'master' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* fix
* Merge branch 'master' into revert-7100-revert-6760-update-fssz
* Merge refs/heads/master into revert-7100-revert-6760-update-fssz
* gaz
* Merge branch 'revert-7100-revert-6760-update-fssz' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* Merge refs/heads/master into revert-7100-revert-6760-update-fssz
* fix test
* Merge branch 'revert-7100-revert-6760-update-fssz' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* Merge refs/heads/master into revert-7100-revert-6760-update-fssz
70 lines
2.2 KiB
Go
70 lines
2.2 KiB
Go
package depositutil_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/go-ssz"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
"github.com/prysmaticlabs/prysm/shared/bls"
|
|
"github.com/prysmaticlabs/prysm/shared/depositutil"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func TestDepositInput_GeneratesPb(t *testing.T) {
|
|
k1 := bls.RandKey()
|
|
k2 := bls.RandKey()
|
|
|
|
result, _, err := depositutil.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)
|
|
sr, err := ssz.SigningRoot(result)
|
|
require.NoError(t, err)
|
|
domain, err := helpers.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 := testutil.DeterministicDepositsAndKeys(1)
|
|
require.NoError(t, err)
|
|
deposit := deposits[0]
|
|
domain, err := helpers.ComputeDomain(
|
|
params.BeaconConfig().DomainDeposit,
|
|
params.BeaconConfig().GenesisForkVersion,
|
|
params.BeaconConfig().ZeroHash[:],
|
|
)
|
|
require.NoError(t, err)
|
|
err = depositutil.VerifyDepositSignature(deposit.Data, domain)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
func TestVerifyDepositSignature_InvalidSig(t *testing.T) {
|
|
deposits, _, err := testutil.DeterministicDepositsAndKeys(1)
|
|
require.NoError(t, err)
|
|
deposit := deposits[0]
|
|
domain, err := helpers.ComputeDomain(
|
|
params.BeaconConfig().DomainDeposit,
|
|
params.BeaconConfig().GenesisForkVersion,
|
|
params.BeaconConfig().ZeroHash[:],
|
|
)
|
|
require.NoError(t, err)
|
|
deposit.Data.Signature = deposit.Data.Signature[1:]
|
|
err = depositutil.VerifyDepositSignature(deposit.Data, domain)
|
|
if err == nil {
|
|
t.Fatal("Deposit Verification succeeds with a invalid signature")
|
|
}
|
|
}
|