Merge pull request #57 from depools/feat/prysm-kyber-compatibility

Test prysm kyber compatibility
This commit is contained in:
Andrew Zavgorodny 2020-10-14 18:32:29 +03:00 committed by GitHub
commit 62c1f0d510
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 19 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
prysmBLS "github.com/prysmaticlabs/prysm/shared/bls"
"os"
"sync"
"testing"
@ -28,14 +29,15 @@ const (
)
type Node struct {
ParticipantID int
Participant string
Machine *Machine
commits []requests.DKGProposalCommitConfirmationRequest
deals []requests.DKGProposalDealConfirmationRequest
responses []requests.DKGProposalResponseConfirmationRequest
masterKeys []requests.DKGProposalMasterKeyConfirmationRequest
partialSigns []requests.SigningProposalPartialSignRequest
ParticipantID int
Participant string
Machine *Machine
commits []requests.DKGProposalCommitConfirmationRequest
deals []requests.DKGProposalDealConfirmationRequest
responses []requests.DKGProposalResponseConfirmationRequest
masterKeys []requests.DKGProposalMasterKeyConfirmationRequest
partialSigns []requests.SigningProposalPartialSignRequest
reconstructedSignatures []client.ReconstructedSignature
}
func (n *Node) storeOperation(t *testing.T, msg storage.Message) {
@ -71,7 +73,11 @@ func (n *Node) storeOperation(t *testing.T, msg storage.Message) {
}
n.partialSigns = append(n.partialSigns, req)
case client.SignatureReconstructed:
return
var req client.ReconstructedSignature
if err := json.Unmarshal(msg.Data, &req); err != nil {
t.Fatalf("failed to unmarshal fsm req: %v", err)
}
n.reconstructedSignatures = append(n.reconstructedSignatures, req)
default:
t.Fatalf("invalid event: %s", msg.Event)
}
@ -311,7 +317,22 @@ func TestAirgappedAllSteps(t *testing.T) {
}
})
fmt.Println("DKG succeeded, signature recovered")
//verify signatures
for _, n := range tr.nodes {
for i := 0; i < len(n.reconstructedSignatures); i++ {
if !bytes.Equal(n.reconstructedSignatures[0].Signature, n.reconstructedSignatures[i].Signature) {
t.Fatalf("signatures are not equal!")
}
if err := n.Machine.VerifySign(msgToSign, n.reconstructedSignatures[i].Signature, DKGIdentifier); err != nil {
t.Fatal("signature is not verified!")
}
}
}
//keys and signatures are equal, so let's test it on prysm compatibility
testKyberPrysm(t, tr.nodes[0].masterKeys[0].MasterKey, tr.nodes[0].reconstructedSignatures[0].Signature, msgToSign)
fmt.Println("DKG succeeded, signature recovered and verified")
}
func TestAirgappedMachine_Replay(t *testing.T) {
@ -558,7 +579,36 @@ func TestAirgappedMachine_Replay(t *testing.T) {
}
})
fmt.Println("DKG succeeded, signature recovered")
//verify signatures
for _, n := range tr.nodes {
for i := 0; i < len(n.reconstructedSignatures); i++ {
if !bytes.Equal(n.reconstructedSignatures[0].Signature, n.reconstructedSignatures[i].Signature) {
t.Fatalf("signatures are not equal!")
}
if err := n.Machine.VerifySign(msgToSign, n.reconstructedSignatures[i].Signature, DKGIdentifier); err != nil {
t.Fatal("signature is not verified!")
}
}
}
//keys and signatures are equal, so let's test it on prysm compatibility
testKyberPrysm(t, tr.nodes[0].masterKeys[0].MasterKey, tr.nodes[0].reconstructedSignatures[0].Signature, msgToSign)
fmt.Println("DKG succeeded, signature recovered and verified")
}
func testKyberPrysm(t *testing.T, pubkey, signature, msg []byte) {
prysmSig, err := prysmBLS.SignatureFromBytes(signature)
if err != nil {
t.Fatalf("failed to get prysm sig from bytes: %v", err)
}
prysmPubKey, err := prysmBLS.PublicKeyFromBytes(pubkey)
if err != nil {
t.Fatalf("failed to get prysm pubkey from bytes: %v", err)
}
if !prysmSig.Verify(prysmPubKey, msg) {
t.Fatalf("failed to verify prysm signature")
}
}
func runStep(transport *Transport, cb func(n *Node, wg *sync.WaitGroup)) {

View File

@ -5,7 +5,7 @@ import (
"encoding/json"
"fmt"
bls "github.com/depools/kyber-bls12381"
bls "github.com/corestario/kyber/pairing/bls12381"
"github.com/corestario/kyber"
dkgPedersen "github.com/corestario/kyber/share/dkg/pedersen"

View File

@ -7,7 +7,7 @@ import (
"fmt"
"log"
bls12381 "github.com/depools/kyber-bls12381"
bls12381 "github.com/corestario/kyber/pairing/bls12381"
client "github.com/depools/dc4bc/client/types"
"github.com/syndtr/goleveldb/leveldb"

View File

@ -15,13 +15,13 @@ 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"
"github.com/depools/dc4bc/fsm/types/requests"
"github.com/depools/dc4bc/qr"
"github.com/depools/dc4bc/storage"
bls12381 "github.com/depools/kyber-bls12381"
)
type node struct {

10
go.mod
View File

@ -4,23 +4,23 @@ go 1.13
require (
github.com/corestario/kyber v1.6.0
github.com/depools/kyber-bls12381 v0.0.0-20200929134032-c24859b7d890
github.com/golang/mock v1.4.4
github.com/google/go-cmp v0.2.0
github.com/google/go-cmp v0.5.0
github.com/google/uuid v1.1.1
github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b
github.com/looplab/fsm v0.1.0
github.com/makiuchi-d/gozxing v0.0.0-20190830103442-eaff64b1ceb7
github.com/prysmaticlabs/prysm v1.0.0-alpha.29.0.20201014075528-022b6667e5d0
github.com/segmentio/kafka-go v0.4.2
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/spf13/cobra v1.0.0
github.com/stretchr/testify v1.6.1
github.com/syndtr/goleveldb v1.0.0
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca
gocv.io/x/gocv v0.24.0
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
golang.org/x/text v0.3.3 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
lukechampine.com/frand v1.3.0
)
replace golang.org/x/crypto => github.com/tendermint/crypto v0.0.0-20180820045704-3764759f34a5
replace github.com/ethereum/go-ethereum => github.com/ethereum/go-ethereum v1.9.22