From fcb194bbd7f401a5a327167d23b6d8dba9d4ca68 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Thu, 2 Aug 2018 15:59:03 +0800 Subject: [PATCH] Generate real challenge in the cosi challenge phase --- consensus/consensus_leader.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/consensus/consensus_leader.go b/consensus/consensus_leader.go index 7fbc954dc..2b0226c4d 100644 --- a/consensus/consensus_leader.go +++ b/consensus/consensus_leader.go @@ -215,13 +215,14 @@ func (consensus *Consensus) constructChallengeMessage() []byte { for _, val := range consensus.commitments { commitments = append(commitments, val) } - buffer.Write(getAggregatedCommit(commitments, consensus.bitmap)) + aggCommitment, aggCommitmentBytes := getAggregatedCommit(commitments) + buffer.Write(aggCommitmentBytes) // 33 byte aggregated key buffer.Write(getAggregatedKey(consensus.bitmap)) // 32 byte challenge - buffer.Write(getChallenge()) + buffer.Write(getChallenge(aggCommitment, consensus.bitmap.AggregatePublic, buffer.Bytes()[:36])) // message contains consensus id and block hash for now. // 64 byte of signature on previous data signature := signMessage(buffer.Bytes()) @@ -230,13 +231,13 @@ func (consensus *Consensus) constructChallengeMessage() []byte { return proto_consensus.ConstructConsensusMessage(proto_consensus.CHALLENGE, buffer.Bytes()) } -func getAggregatedCommit(commitments []kyber.Point, bitmap *crypto.Mask) []byte { +func getAggregatedCommit(commitments []kyber.Point) (commitment kyber.Point, bytes []byte) { aggCommitment := crypto.AggregateCommitmentsOnly(crypto.Curve, commitments) bytes, err := aggCommitment.MarshalBinary() if err != nil { panic("Failed to deserialize the aggregated commitment") } - return append(bytes[:], byte(0)) + return aggCommitment, append(bytes[:], byte(0)) } func getAggregatedKey(bitmap *crypto.Mask) []byte { @@ -247,8 +248,8 @@ func getAggregatedKey(bitmap *crypto.Mask) []byte { return append(bytes[:], byte(0)) } -func getChallenge() []byte { - // TODO: implement actual challenge data +func getChallenge(aggCommitment, aggKey kyber.Point, message []byte) []byte { + crypto.Challenge(crypto.Curve, aggCommitment, aggKey, message) return make([]byte, 32) }