Skip to content

Commit

Permalink
Merge pull request #11 from lca1/service_keypair
Browse files Browse the repository at this point in the history
Service keypair
  • Loading branch information
JoaoAndreSa committed Apr 3, 2019
2 parents 784b73c + f3c2553 commit 322a71a
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 39 deletions.
4 changes: 2 additions & 2 deletions go.mod
Expand Up @@ -21,10 +21,10 @@ require (
go.dedis.ch/onet/v3 v3.0.4
go.dedis.ch/protobuf v1.0.6
go.etcd.io/bbolt v1.3.2 // indirect
golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect
golang.org/x/net v0.0.0-20190324223953-e3b2ff56ed87 // indirect
golang.org/x/tools v0.0.0-20190322203728-c1a832b0ad89 // indirect
golang.org/x/tools v0.0.0-20190325223049-1d95b17f1b04 // indirect
gonum.org/v1/gonum v0.0.0-20190321072728-ca4d35bc590a
gopkg.in/satori/go.uuid.v1 v1.2.0
)
4 changes: 4 additions & 0 deletions go.sum
Expand Up @@ -258,6 +258,8 @@ golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a h1:YX8ljsm6wXlHZO+aRz9Exq
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576 h1:aUX/1G2gFSs4AsJJg2cL3HuoRhCSCz733FE5GUSuaT4=
golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c h1:Vj5n4GlwjmQteupaxJ9+0FNOmBrHfq7vN4btdGoDZgI=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -339,6 +341,8 @@ golang.org/x/tools v0.0.0-20190321232350-e250d351ecad h1:tYrC3aF7wTeS1noni7wCGu9
golang.org/x/tools v0.0.0-20190321232350-e250d351ecad/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190322203728-c1a832b0ad89 h1:iWXXYN3edZ3Nd/7I6Rt1sXrWVmhF9bgVtlEJ7BbH124=
golang.org/x/tools v0.0.0-20190322203728-c1a832b0ad89/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190325223049-1d95b17f1b04 h1:SRYGE+BqJRgY8JH4p2NmwTPeuREKqKYw5IuEmthTHKQ=
golang.org/x/tools v0.0.0-20190325223049-1d95b17f1b04/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
gonum.org/v1/gonum v0.0.0-20190312022028-60a68a3a7f2c h1:vkUG1VH//F1/AT8sZfBgWZdtBeUa8/Vh/lQx/P0JIcQ=
gonum.org/v1/gonum v0.0.0-20190312022028-60a68a3a7f2c/go.mod h1:jevfED4GnIEnJrWW55YmY9DMhajHcnkqVnEXmEtMyNI=
gonum.org/v1/gonum v0.0.0-20190321072728-ca4d35bc590a h1:XffIu/i+IJIC+M8WoBEmJm8N/YYbA8Pvh748YgzU7kI=
Expand Down
2 changes: 1 addition & 1 deletion lib/shuffling_proof.go
Expand Up @@ -135,7 +135,7 @@ func checkShuffleProof(g, h kyber.Point, Xhat, Yhat, XhatBar, YhatBar []kyber.Po
err := proof.HashVerify(libunlynx.SuiTe, "PairShuffle", verifier, prf)
if err != nil {
log.Lvl1(err)
log.Lvl1("-----------verify failed (with XharBar)")
log.Lvl1("-----------verify failed (with XhatBar)")
return false
}

Expand Down
15 changes: 13 additions & 2 deletions lib/structs_proofs.go
Expand Up @@ -129,12 +129,18 @@ func (rpr *RangeProofRequest) VerifyProof(source network.ServerIdentity, sq Surv
wg := libunlynx.StartParallelize(1)
go func() {
defer wg.Done()
var err error
err = VerifyProofSignature(sq.IDtoPublic[rpr.SenderID], rpr.Data, rpr.Signature)
if err != nil {
verifSign = proofFalseSign
}
}()
verif := verifyRangeProofList(rpr.Data, sq.Threshold, sq.Query.Ranges, sq.Query.IVSigs.InputValidationSigs, sq.RosterServers.Aggregate, sq.RangeProofThreshold)
agg, err := sq.RosterServers.ServiceAggregate("drynx")
if err != nil {
// It's in protocol-test mode only, so the aggregate point of all conodes will do
agg = sq.RosterServers.Aggregate
}
verif := verifyRangeProofList(rpr.Data, sq.Threshold, sq.Query.Ranges, sq.Query.IVSigs.InputValidationSigs, agg, sq.RangeProofThreshold)
log.Lvl2("VN", source.String(), " verified range proof:", verif)
libunlynx.EndParallelize(wg)
//libunlynx.EndTimer(time)
Expand Down Expand Up @@ -387,7 +393,12 @@ func verifyShuffle(data []byte, sample float64, roster onet.Roster) int64 {

toVerify := &PublishedShufflingProof{}
toVerify.FromBytes(*proofs.(*PublishedShufflingProofBytes))
result := ShufflingProofVerification(*toVerify, roster.Aggregate)
agg, err := roster.ServiceAggregate("drynx")
if err != nil {
// It's in protocol-test mode only, so the aggregate point of all conodes will do
agg = roster.Aggregate
}
result := ShufflingProofVerification(*toVerify, agg)

if result {
bmInt = ProofTrue
Expand Down
2 changes: 0 additions & 2 deletions lib/suite.go
Expand Up @@ -2,11 +2,9 @@ package libdrynx

import (
"github.com/lca1/unlynx/lib"
"go.dedis.ch/cothority/v3"
"go.dedis.ch/kyber/v3/pairing/bn256"
)

func init() {
cothority.Suite = bn256.NewSuiteG1()
libunlynx.SuiTe = bn256.NewSuiteG1()
}
4 changes: 2 additions & 2 deletions protocols/shuffling_protocol.go
Expand Up @@ -142,7 +142,7 @@ func (p *ShufflingProtocol) Start() error {
shuffleTarget = append(shuffleTarget, pr)
}

collectiveKey := p.Roster().Aggregate
collectiveKey := p.Aggregate()
if p.CollectiveKey != nil {
//test
collectiveKey = p.CollectiveKey
Expand Down Expand Up @@ -209,7 +209,7 @@ func (p *ShufflingProtocol) Dispatch() error {
startT := time.Now()
roundTotalComputation := libunlynx.StartTimer(p.Name() + "_Shuffling(DISPATCH)")

collectiveKey := p.Roster().Aggregate //shuffling is by default done with collective authority key
collectiveKey := p.Aggregate() //shuffling is by default done with collective authority key

if p.CollectiveKey != nil {
//test
Expand Down
2 changes: 1 addition & 1 deletion protocols/shufflinglocal_protocol.go
Expand Up @@ -113,7 +113,7 @@ func (p *ShufflingLocalProtocol) Dispatch() error {
startT := time.Now()
roundTotalComputation := libunlynx.StartTimer(p.Name() + "_Shuffling(DISPATCH)")

collectiveKey := p.Roster().Aggregate //shuffling is by default done with collective authority key
collectiveKey := p.Aggregate() //shuffling is by default done with collective authority key

if p.CollectiveKey != nil {
//test
Expand Down
3 changes: 2 additions & 1 deletion services/api.go
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/lca1/drynx/lib"
"github.com/lca1/drynx/lib/encoding"
"github.com/lca1/unlynx/lib"
"go.dedis.ch/cothority/v3"
"go.dedis.ch/kyber/v3"
"go.dedis.ch/kyber/v3/util/key"
"go.dedis.ch/onet/v3"
Expand Down Expand Up @@ -34,7 +35,7 @@ func init() {
func NewDrynxClient(entryPoint *network.ServerIdentity, clientID string) *API {
keys := key.NewKeyPair(libunlynx.SuiTe)
newClient := &API{
Client: onet.NewClient(libunlynx.SuiTe, ServiceName),
Client: onet.NewClient(cothority.Suite, ServiceName),
clientID: clientID,
entryPoint: entryPoint,
public: keys.Public,
Expand Down
29 changes: 19 additions & 10 deletions services/service.go
@@ -1,24 +1,24 @@
package services

import (
"github.com/lca1/drynx/lib"
"github.com/lca1/unlynx/lib"
"github.com/lca1/unlynx/lib/shuffle"
"github.com/lca1/unlynx/lib/tools"
"go.dedis.ch/onet/v3"
"go.dedis.ch/onet/v3/log"
"go.dedis.ch/onet/v3/network"
"time"

"sync"

"github.com/btcsuite/goleveldb/leveldb/errors"
"github.com/coreos/bbolt"
"github.com/fanliao/go-concurrentMap"
"github.com/lca1/drynx/lib"
concurrent "github.com/fanliao/go-concurrentMap"
"github.com/lca1/drynx/protocols"
"github.com/lca1/unlynx/lib"
"github.com/lca1/unlynx/protocols"
"go.dedis.ch/cothority/v3/skipchain"
"go.dedis.ch/kyber/v3/util/random"
"go.dedis.ch/onet/v3"
"go.dedis.ch/onet/v3/log"
"go.dedis.ch/onet/v3/network"
)

// ServiceName is the registered name for the drynx service.
Expand Down Expand Up @@ -103,7 +103,7 @@ type MsgTypes struct {
var msgTypes = MsgTypes{}

func init() {
onet.RegisterNewService(ServiceName, NewService)
onet.RegisterNewServiceWithSuite(ServiceName, libunlynx.SuiTe, NewService)

msgTypes.msgSurveyQuery = network.RegisterMessage(&libdrynx.SurveyQuery{})
msgTypes.msgSurveyQueryToDP = network.RegisterMessage(&libdrynx.SurveyQueryToDP{})
Expand Down Expand Up @@ -295,7 +295,11 @@ func (s *ServiceDrynx) HandleSurveyQuery(recq *libdrynx.SurveyQuery) (network.Me

// prepares the precomputation for shuffling
lineSize := 100 // + 1 is for the possible count attribute
survey.ShufflePrecompute = libunlynxshuffle.PrecomputationWritingForShuffling(false, gobFile, s.ServerIdentity().String(), libunlynx.SuiTe.Scalar().Pick(random.New()), recq.RosterServers.Aggregate, lineSize)
agg, err := recq.RosterServers.ServiceAggregate("drynx")
if err != nil {
log.Fatal("Didn't find appropriate aggregate key")
}
survey.ShufflePrecompute = libunlynxshuffle.PrecomputationWritingForShuffling(false, gobFile, s.ServerIdentity().String(), libunlynx.SuiTe.Scalar().Pick(random.New()), agg, lineSize)

// if is the root server: send query to all other servers and its data providers
if recq.IntraMessage == false {
Expand Down Expand Up @@ -344,7 +348,7 @@ func (s *ServiceDrynx) HandleSurveyQuery(recq *libdrynx.SurveyQuery) (network.Me
// TODO: we can remove this waiting after the test
// -----------------------------------------------------------------------------------------------------------------
// signal other nodes that the data provider(s) already sent their data (response)
err := libunlynxtools.SendISMOthers(s.ServiceProcessor, &recq.RosterServers, &SyncDCP{recq.SurveyID})
err = libunlynxtools.SendISMOthers(s.ServiceProcessor, &recq.RosterServers, &SyncDCP{recq.SurveyID})
if err != nil {
log.Error("[SERVICE] <drynx> Server, broadcasting [syncDCPChannel] error ", err)
}
Expand Down Expand Up @@ -422,9 +426,14 @@ func (s *ServiceDrynx) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.Generic
survey := castToSurvey(s.Survey.Get(target))
dataCollectionProtocol := pi.(*protocols.DataCollectionProtocol)

agg, err := survey.SurveyQuery.RosterServers.ServiceAggregate("drynx")
if err != nil {
log.Fatal("Didn't find appropriate aggregate key")
}

queryStatement := protocols.SurveyToDP{
SurveyID: survey.SurveyQuery.SurveyID,
Aggregate: survey.SurveyQuery.RosterServers.Aggregate,
Aggregate: agg,
Query: survey.SurveyQuery.Query,
}
dataCollectionProtocol.Survey = queryStatement
Expand Down
29 changes: 15 additions & 14 deletions services/service_test.go
Expand Up @@ -2,6 +2,7 @@ package services

import (
"fmt"
"go.dedis.ch/cothority/v3"

"github.com/lca1/drynx/lib/encoding"
"github.com/lca1/unlynx/lib"
Expand Down Expand Up @@ -100,7 +101,7 @@ func TestServiceDrynx(t *testing.T) {
thresholdEntityProofsVerif = []float64{0.0, 0.0, 0.0, 0.0}
}

local := onet.NewLocalTest(libunlynx.SuiTe)
local := onet.NewLocalTest(cothority.Suite)
elServers, elDPs, elVNs := generateNodes(local, nbrServers, nbrDPs, nbrVNs)

if proofs == 0 {
Expand Down Expand Up @@ -222,15 +223,15 @@ func TestServiceDrynx(t *testing.T) {

idToPublic := make(map[string]kyber.Point)
for _, v := range elServers.List {
idToPublic[v.String()] = v.Public
idToPublic[v.String()] = v.ServicePublic(ServiceName)
}
for _, v := range elDPs.List {
idToPublic[v.String()] = v.Public
idToPublic[v.String()] = v.ServicePublic(ServiceName)
}

if proofs != 0 {
for _, v := range elVNs.List {
idToPublic[v.String()] = v.Public
idToPublic[v.String()] = v.ServicePublic(ServiceName)
}
}

Expand Down Expand Up @@ -428,7 +429,7 @@ func TestServiceDrynxLogisticRegressionForSPECTF(t *testing.T) {
thresholdEntityProofsVerif = []float64{0.0, 0.0, 0.0, 0.0}
}

local := onet.NewLocalTest(libunlynx.SuiTe)
local := onet.NewLocalTest(cothority.Suite)
elServers, elDPs, elVNs := generateNodes(local, nbrServers, nbrDPs, nbrVNs)

if proofs == 0 {
Expand Down Expand Up @@ -550,15 +551,15 @@ func TestServiceDrynxLogisticRegressionForSPECTF(t *testing.T) {

idToPublic := make(map[string]kyber.Point)
for _, v := range elServers.List {
idToPublic[v.String()] = v.Public
idToPublic[v.String()] = v.ServicePublic(ServiceName)
}
for _, v := range elDPs.List {
idToPublic[v.String()] = v.Public
idToPublic[v.String()] = v.ServicePublic(ServiceName)
}

if proofs != 0 {
for _, v := range elVNs.List {
idToPublic[v.String()] = v.Public
idToPublic[v.String()] = v.ServicePublic(ServiceName)
}
}

Expand Down Expand Up @@ -708,9 +709,9 @@ func TestServiceDrynxLogisticRegression(t *testing.T) {
os.Remove("pre_compute_multiplications.gob")

// these nodes act as both servers and data providers
local := onet.NewLocalTest(libunlynx.SuiTe)
local1 := onet.NewLocalTest(libunlynx.SuiTe)
local2 := onet.NewLocalTest(libunlynx.SuiTe)
local := onet.NewLocalTest(cothority.Suite)
local1 := onet.NewLocalTest(cothority.Suite)
local2 := onet.NewLocalTest(cothority.Suite)

// create servers and data providers
_, el, _ := local.GenTree(10, true)
Expand Down Expand Up @@ -907,13 +908,13 @@ func TestServiceDrynxLogisticRegression(t *testing.T) {

idToPublic := make(map[string]kyber.Point)
for _, v := range el.List {
idToPublic[v.String()] = v.Public
idToPublic[v.String()] = v.ServicePublic(ServiceName)
}
for _, v := range el1.List {
idToPublic[v.String()] = v.Public
idToPublic[v.String()] = v.ServicePublic(ServiceName)
}
for _, v := range elVNs.List {
idToPublic[v.String()] = v.Public
idToPublic[v.String()] = v.ServicePublic(ServiceName)
}

thresholdEntityProofsVerif := []float64{1.0, 1.0, 1.0, 1.0} // 1: threshold general, 2: threshold range, 3: obfuscation, 4: threshold key switch
Expand Down
6 changes: 3 additions & 3 deletions simul/drynx_simul.go
Expand Up @@ -329,13 +329,13 @@ func (sim *SimulationDrynx) Run(config *onet.SimulationConfig) error {

idToPublic := make(map[string]kyber.Point)
for _, v := range rosterServers.List {
idToPublic[v.String()] = v.Public
idToPublic[v.String()] = v.ServicePublic(services.ServiceName)
}
for _, v := range rosterVNs.List {
idToPublic[v.String()] = v.Public
idToPublic[v.String()] = v.ServicePublic(services.ServiceName)
}
for _, v := range elDPs {
idToPublic[v.String()] = v.Public
idToPublic[v.String()] = v.ServicePublic(services.ServiceName)
}

// Create a client (querier) for the service)
Expand Down
2 changes: 1 addition & 1 deletion simul/runfiles/drynx.toml
@@ -1,7 +1,7 @@
Simulation = "ServiceDrynx"
Servers = 6
Bf = 2
Suite = "bn256.G1"
Suite = "Ed25519"
Rounds = 1
Bandwidth = 100
Delay = 20
Expand Down

0 comments on commit 322a71a

Please sign in to comment.