Merge pull request #63 from depools/feat/prysm-compatibility-checker

Feat/prysm compatibility checker
This commit is contained in:
Andrew Zavgorodny 2020-10-22 11:44:04 +03:00 committed by GitHub
commit dc7c2b2aab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 108 additions and 10 deletions

View File

@ -17,6 +17,8 @@ build-darwin:
GOOS=darwin GOARCH=amd64 go build -o dc4bc_cli_darwin ./cmd/dc4bc_cli/
@echo "Building dc4bc_airgapped..."
GOOS=darwin GOARCH=amd64 go build -o dc4bc_airgapped_darwin ./cmd/airgapped/
@echo "Building dc4bc_prysm_compatibility_checker..."
GOOS=darwin GOARCH=amd64 go build -o dc4bc_prysm_compatibility_checker_darwin ./cmd/prysm_compatibility_checker/
build-linux:
@echo "Building dc4bc_d..."
@ -25,5 +27,7 @@ build-linux:
GOOS=linux GOARCH=amd64 go build -o dc4bc_cli_linux ./cmd/dc4bc_cli/
@echo "Building dc4bc_airgapped..."
GOOS=linux GOARCH=amd64 go build -o dc4bc_airgapped_linux ./cmd/airgapped/
@echo "Building dc4bc_prysm_compatibility_checker..."
GOOS=linux GOARCH=amd64 go build -o dc4bc_prysm_compatibility_checker_linux ./cmd/prysm_compatibility_checker/
.PHONY: mocks

View File

@ -4,7 +4,7 @@ import (
"bytes"
"context"
"crypto/md5"
"crypto/rand"
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
@ -15,7 +15,6 @@ import (
"testing"
"time"
bls12381 "github.com/corestario/kyber/pairing/bls12381"
"github.com/depools/dc4bc/airgapped"
"github.com/depools/dc4bc/client/types"
"github.com/depools/dc4bc/fsm/state_machines/dkg_proposal_fsm"
@ -111,14 +110,8 @@ func (n *node) run(t *testing.T) {
if err = json.Unmarshal(msg.Data, &pubKeyReq); err != nil {
t.Fatalf("failed to unmarshal pubKey request: %v", err)
}
seed := make([]byte, 32)
_, _ = rand.Read(seed)
pubKey := bls12381.NewBLS12381Suite(seed).Point()
if err = pubKey.UnmarshalBinary(pubKeyReq.MasterKey); err != nil {
t.Fatalf("failed to unmarshal pubkey: %v", err)
}
if err = ioutil.WriteFile(fmt.Sprintf("/tmp/participant_%d.pubkey",
pubKeyReq.ParticipantId), []byte(pubKey.String()), 0666); err != nil {
pubKeyReq.ParticipantId), []byte(hex.EncodeToString(pubKeyReq.MasterKey)), 0666); err != nil {
t.Fatalf("failed to write pubkey to temp file: %v", err)
}
}

View File

@ -116,7 +116,12 @@ func (t *terminal) showFinishedDKGCommand() error {
}
for dkgID, keyring := range keyrings {
fmt.Printf("DKG identifier: %s\n", dkgID)
fmt.Printf("PubKey: %s\n", keyring.PubPoly.Commit().String())
pubkeyBz, err := keyring.PubPoly.Commit().MarshalBinary()
if err != nil {
fmt.Println("failed to marshal pubkey: %w", err)
continue
}
fmt.Printf("PubKey: %s\n", base64.StdEncoding.EncodeToString(pubkeyBz))
fmt.Println("-----------------------------------------------------")
}
return nil

View File

@ -0,0 +1,96 @@
package main
import (
"encoding/base64"
"fmt"
prysmBLS "github.com/prysmaticlabs/prysm/shared/bls"
"github.com/spf13/cobra"
"io/ioutil"
"log"
)
func checkSignature() *cobra.Command {
return &cobra.Command{
Use: "check_signature [signature]",
Short: "checks a signature on prysm compatibility",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
sig, err := base64.StdEncoding.DecodeString(args[0])
if err != nil {
log.Fatalf("failed to decode signature bytes from string: %v", err)
}
if _, err = prysmBLS.SignatureFromBytes(sig); err != nil {
log.Fatalf("failed to get prysm sig from bytes: %v", err)
}
fmt.Println("Signature is correct")
},
}
}
func checkPubKey() *cobra.Command {
return &cobra.Command{
Use: "check_pubkey [pubkey]",
Short: "checks a pubkey on prysm compatibility",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
pubkey, err := base64.StdEncoding.DecodeString(args[0])
if err != nil {
log.Fatalf("failed to decode pubkey bytes from string: %v", err)
}
if _, err = prysmBLS.PublicKeyFromBytes(pubkey); err != nil {
log.Fatalf("failed to get prysm pubkey from bytes: %v", err)
}
fmt.Println("Public key is correct")
},
}
}
func verify() *cobra.Command {
return &cobra.Command{
Use: "verify [signature] [pubkey] [file]",
Short: "verify signature with Prysm",
Args: cobra.ExactArgs(3),
Run: func(cmd *cobra.Command, args []string) {
sig, err := base64.StdEncoding.DecodeString(args[0])
if err != nil {
log.Fatalf("failed to decode signature bytes from string: %v", err)
}
prysmSig, err := prysmBLS.SignatureFromBytes(sig)
if err != nil {
log.Fatalf("failed to get prysm sig from bytes: %v", err)
}
pubkey, err := base64.StdEncoding.DecodeString(args[1])
if err != nil {
log.Fatalf("failed to decode pubkey bytes from string: %v", err)
}
prysmPubKey, err := prysmBLS.PublicKeyFromBytes(pubkey)
if err != nil {
log.Fatalf("failed to get prysm pubkey from bytes: %v", err)
}
msg, err := ioutil.ReadFile(args[2])
if err != nil {
log.Fatalf("failed to read file: %v", err)
}
if !prysmSig.Verify(prysmPubKey, msg) {
log.Fatalf("failed to verify prysm signature")
}
fmt.Println("Signature is correct")
},
}
}
var rootCmd = &cobra.Command{
Use: "./prysmCompatibilityChecker",
Short: "util to check signatures and pubkeys compatibility with Prysm",
}
func main() {
rootCmd.AddCommand(
checkPubKey(),
checkSignature(),
verify(),
)
if err := rootCmd.Execute(); err != nil {
log.Fatalf("Failed to execute root command: %v", err)
}
}