Ejemplo n.º 1
0
        public override void HandleMessage(int fromId, Msg msg)
        {
            switch (msg.Type)
            {
            case MsgType.Commit:
                // collect commitments from parties
                Commitment = ((CommitMsg)msg).Commitment;
                break;

            case MsgType.Share:
                // collect shares from parties

                var swMsg = msg as ShareWitnessMsg <BigZp>;
                if (PolyCommit != null && Commitment != null &&
                    !PolyCommit.VerifyEval(Commitment, new BigZp(Prime, DstQuorum.GetPositionOf(Me.Id) + 1), swMsg.Share, swMsg.Witness))
                {
                    // broadcast an accusation against the i-th party.
                    throw new NotImplementedException();
                }
                else if (PolyCommit != null && Commitment == null)
                {
                    Console.Write("No commitment received from" + fromId);
                }

                IsCompleted = true;
                Result      = new Share <BigZp>(swMsg.Share, false);
                break;
            }
        }
Ejemplo n.º 2
0
        public override void HandleMessage(int fromId, Msg msg)
        {
            switch (msg.Type)
            {
            case MsgType.Commit:
                // collect commitments from parties
                commitsRecv[fromId] = msg as CommitMsg;
                break;

            case MsgType.Share:
                // collect shares from parties
                sharesRecv[fromId] = msg as ShareWitnessMsg <BigZp>;

                if (commitsRecv.ContainsKey(fromId))
                {
                    // verify the share
                    if (PolyCommit != null && !PolyCommit.VerifyEval(commitsRecv[fromId].Commitment, new BigZp(Prime, Quorum.GetPositionOf(Me.Id) + 1),
                                                                     sharesRecv[fromId].Share, sharesRecv[fromId].Witness))
                    {
                        // broadcast an accusation against the i-th party.
                        throw new NotImplementedException();
                    }

                    // add the share to the shares received from all parties

                    CombinedShare += sharesRecv[fromId].Share;

                    if (++numSharesRecv >= Math.Ceiling(2.0 * Quorum.Size / 3.0) && !scheduledReconst)
                    {
                        // send a loopback message to notify the end of this round. This is done to
                        // ensure we receive the inputs of "all" honest parties in this round and
                        // bad parties cannot prevent us from receiving honest input by sending bad inputs sooner.
                        Send(Me.Id, new Msg(MsgType.NextRound));
                        scheduledReconst = true;
                    }
                }
                else
                {
                    Console.WriteLine("No commitment received for party " + fromId);
                }
                break;

            case MsgType.NextRound:
                if (fromId != Me.Id)
                {
                    Console.WriteLine("Invalid next round message received. Party " + fromId + " seems to be cheating!");
                }
                IsCompleted = true;
                Result      = new Share <BigZp>(CombinedShare, false);
                break;
            }
        }
Ejemplo n.º 3
0
        public override void HandleMessage(int fromId, Msg msg)
        {
            switch (msg.Type)
            {
            case MsgType.Commit:
                commitsRecv[fromId] = msg as CommitMsg;
                numCommitsRecv[fromId]++;
                Debug.Assert(numCommitsRecv[fromId] <= StartSharesPerParty);
                break;

            case MsgType.Share:
                if (commitsRecv.ContainsKey(fromId))
                {
                    int whichOrigShare          = numCommitsRecv[fromId] - 1;
                    int whichFinalFromOrigShare = sharesRecv[fromId][whichOrigShare].Count;
                    int evalPoint = MyQuorumIndex * FinalSharesPerParty + whichFinalFromOrigShare + 1;
                    var swMessage = msg as ShareWitnessMsg <BigZp>;
                    sharesRecv[fromId][numCommitsRecv[fromId] - 1].Add(swMessage);
                    ReceivedReshareCount++;
                    if (PolyCommit != null && !PolyCommit.VerifyEval(commitsRecv[fromId].Commitment, new BigZp(Prime, evalPoint), swMessage.Share, swMessage.Witness))
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    Console.WriteLine("No commitment from " + fromId);
                }

                // send the message to start the next round when we have received all of the shares from everybody
                if (ReceivedReshareCount == StartShareCount * FinalSharesPerParty)
                {
                    Send(Me.Id, new Msg(MsgType.NextRound));
                }
                break;

            case MsgType.NextRound:
                Recombine();
                break;
            }
        }