Exemplo 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;
            }
        }
Exemplo n.º 2
0
        public void SetupInputDistribution()
        {
            int         myPosition      = Quorum.GetPositionOf(PartyIds, Me.Id);
            GateAddress myInputGateAddr = SortNetwork.FirstGateForWire[myPosition];
            Quorum      myInputQuorum   = GateQuorumMapping[myInputGateAddr.Gate];

            Protocol sortValueDistribution = new SharingProtocol(Me, Me.Id, myInputQuorum, SortValue, Prime,
                                                                 ProtocolIdGenerator.GateInputSharingIdentifier(myInputGateAddr.Gate.TopologicalRank, 2 * myInputGateAddr.Port));

            Protocol secretDistribution = new SharingProtocol(Me, Me.Id, myInputQuorum, Secret, Prime,
                                                              ProtocolIdGenerator.GateInputSharingIdentifier(myInputGateAddr.Gate.TopologicalRank, 2 * myInputGateAddr.Port + 1));

            List <Protocol> inputProtocols = new List <Protocol>();

            inputProtocols.Add(sortValueDistribution);
            inputProtocols.Add(secretDistribution);

            InputProtocolMapping = new Dictionary <InputGateAddress, Tuple <ulong, ulong> >();

            for (int i = 0; i < PartyIds.Count; i++)
            {
                var gateAddr = SortNetwork.FirstGateForWire[i];
                foreach (Quorum q in MyQuorums)
                {
                    if (GateQuorumMapping[gateAddr.Gate] == q)
                    {
                        if (i == myPosition)
                        {
                            InputProtocolMapping[gateAddr] = new Tuple <ulong, ulong>(sortValueDistribution.ProtocolId, secretDistribution.ProtocolId);
                        }
                        else
                        {
                            ulong sortRecvId  = ProtocolIdGenerator.GateInputSharingIdentifier(gateAddr.Gate.TopologicalRank, 2 * gateAddr.Port);
                            ulong shareRecvId = ProtocolIdGenerator.GateInputSharingIdentifier(gateAddr.Gate.TopologicalRank, 2 * gateAddr.Port + 1);
                            InputProtocolMapping[gateAddr] = new Tuple <ulong, ulong>(sortRecvId, shareRecvId);
                            // I need to receive for this gate
                            inputProtocols.Add(new SharingProtocol(Me, PartyIds.ElementAt(i), q, null, Prime, sortRecvId));
                            inputProtocols.Add(new SharingProtocol(Me, PartyIds.ElementAt(i), q, null, Prime, shareRecvId));
                        }
                    }
                }
            }

            ExecuteSubProtocols(inputProtocols);
        }
Exemplo n.º 3
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;
            }
        }