-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validator client: add submit registration (#10785)
* Add client registration methods * Mocken * Run mockgen * Fix bad tests * Fix rest of the tests * Tests * Fix time tests Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
- Loading branch information
1 parent
7563bc0
commit 95c140b
Showing
22 changed files
with
814 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package signing | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"github.com/prysmaticlabs/prysm/config/params" | ||
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" | ||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" | ||
) | ||
|
||
var ErrNilRegistration = errors.New("nil signed registration") | ||
|
||
// VerifyRegistrationSignature verifies the signature of a validator's registration. | ||
func VerifyRegistrationSignature( | ||
e types.Epoch, | ||
f *ethpb.Fork, | ||
sr *ethpb.SignedValidatorRegistrationV1, | ||
genesisRoot []byte, | ||
) error { | ||
if sr == nil || sr.Message == nil { | ||
return ErrNilRegistration | ||
} | ||
|
||
d := params.BeaconConfig().DomainApplicationBuilder | ||
sd, err := Domain(f, e, d, genesisRoot) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := VerifySigningRoot(sr.Message, sr.Message.Pubkey, sr.Signature, sd); err != nil { | ||
return ErrSigFailedToVerify | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package signing_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing" | ||
"github.com/prysmaticlabs/prysm/config/params" | ||
"github.com/prysmaticlabs/prysm/crypto/bls" | ||
"github.com/prysmaticlabs/prysm/encoding/bytesutil" | ||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" | ||
"github.com/prysmaticlabs/prysm/testing/require" | ||
"github.com/prysmaticlabs/prysm/testing/util" | ||
"github.com/prysmaticlabs/prysm/time/slots" | ||
) | ||
|
||
func TestVerifyRegistrationSignature(t *testing.T) { | ||
sk, err := bls.RandKey() | ||
require.NoError(t, err) | ||
reg := ðpb.ValidatorRegistrationV1{ | ||
FeeRecipient: bytesutil.PadTo([]byte("fee"), 20), | ||
GasLimit: 123456, | ||
Timestamp: uint64(time.Now().Unix()), | ||
Pubkey: sk.PublicKey().Marshal(), | ||
} | ||
st, _ := util.DeterministicGenesisState(t, 1) | ||
d := params.BeaconConfig().DomainApplicationBuilder | ||
e := slots.ToEpoch(st.Slot()) | ||
sig, err := signing.ComputeDomainAndSign(st, e, reg, d, sk) | ||
require.NoError(t, err) | ||
sReg := ðpb.SignedValidatorRegistrationV1{ | ||
Message: reg, | ||
Signature: sig, | ||
} | ||
f := st.Fork() | ||
g := st.GenesisValidatorsRoot() | ||
require.NoError(t, signing.VerifyRegistrationSignature(e, f, sReg, g)) | ||
|
||
sReg.Signature = []byte("bad") | ||
require.ErrorIs(t, signing.VerifyRegistrationSignature(e, f, sReg, g), signing.ErrSigFailedToVerify) | ||
|
||
sReg.Message = nil | ||
require.ErrorIs(t, signing.VerifyRegistrationSignature(e, f, sReg, g), signing.ErrNilRegistration) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.