protected static void CreateGateTree(MpcProtocols.Dkms.Gate root, int numLeaves, Zp quorumIndex, bool topToBottom) { if (numLeaves > 1) { var left = new MpcProtocols.Dkms.Gate(root.Type, quorumIndex++, root.MpcCircuit); var right = new MpcProtocols.Dkms.Gate(root.Type, quorumIndex++, root.MpcCircuit); if (topToBottom) { root.AddEdgeTo(left); root.AddEdgeTo(right); } else { left.AddEdgeTo(root); right.AddEdgeTo(root); } if (numLeaves >= 4) { CreateGateTree(left, numLeaves / 2, quorumIndex, topToBottom); CreateGateTree(right, numLeaves / 2, quorumIndex, topToBottom); } } }
protected static MpcProtocols.Dkms.Circuit CreateByzantineCircuit(int numPlayers, int numQuorums, int numSlots, int quorumSize, int prime) { var inputGates = new List<Gate>(); var internalGates = new List<Gate>(); var quorumIndex = new Zp(numQuorums); // TODO: THE NUMBER OF INPUTS OF ALL GATES MUST BE IN ORDER OF THE QUORUM SIZE NOT JUST ONE OR TWO. // WE HAVE TO ADD A RECOMBINE CIRCUIT (DISCUSSED IN A PAPER) TO REDUCE THE NUMBER OF INPUTS TO ONE OR TWO. //var G1_parser = new Parser("Inputs=X \n Outputs=Y \n Y0=(X/X) \n Y=(1-Y0)", prime); //G1_parser.Parse(); //var G2_parser = new Parser("Inputs=X1,X2 \n Outputs=Y \n S=(X1+X2) \n X0=(S==0) \n Y0=(X0/X0) \n Y1=(1-Y0) \n W0=(S==1) \n Z0=(W0/W0) \n Z1=(1-Z0) \n Z2=(2*Z1) \n Z=(Z0+Z2) \n Y=(Y1*Z)", prime); //G2_parser.Parse(); //var G3_parser = new Parser("Inputs=X \n Outputs=Y \n E1=(X==0) \n E2=(X==1) \n X0=(E1+E2) \n Y0=(X0/X0) \n Y=(1-Y0)", prime); //G3_parser.Parse(); //var G4_parser = new Parser("Inputs=X1,X2 \n Outputs=Y \n X=(X1==0) \n Y0=(X/X) \n Y1=(1-Y0) \n Y=(Y0*X2)", prime); //G4_parser.Parse(); //////////////////////////////////// FOR 8/22 SUBMISSION ONLY var G1_parser = new Common.FiniteField.Circuits.Parser(Common.FiniteField.FunctionType.Sum, 2 * quorumSize, prime); var G2_parser = new Common.FiniteField.Circuits.Parser(Common.FiniteField.FunctionType.Sum, 3 * quorumSize, prime); G1_parser.Parse(); G2_parser.Parse(); var G3_parser = G1_parser; var G4_parser = G2_parser; //////////////////////////////////// FOR 8/22 SUBMISSION ONLY var G4_gatesList = new List<Gate[]>(numPlayers); for (int i = 0; i < numPlayers; i++) { var inputs = new Gate[numSlots]; var G1_gates = new Gate[numSlots]; var G4_gates = new Gate[numSlots]; for (int j = 0; j < numSlots; j++) { inputs[j] = new Gate(quorumIndex++); // input gates // create G1's and connect input gates to them G1_gates[j] = new Gate(GateType.Internal, quorumIndex++, G1_parser.Circuit); inputs[j].AddEdgeTo(G1_gates[j]); // create G4's and connect input gates to them G4_gates[j] = new Gate(GateType.Internal, quorumIndex++, G4_parser.Circuit); inputs[j].AddEdgeTo(G4_gates[j]); inputGates.Add(inputs[j]); internalGates.Add(G1_gates[j]); internalGates.Add(G4_gates[j]); } // create G2's var G2_root = new Gate(GateType.Internal, quorumIndex++, G2_parser.Circuit); CreateGateTree(G2_root, numSlots / 2, quorumIndex, false); // connect leaf G2's to G1's var G2_leaves = GetGatesAndLeaves(G2_root, false, internalGates).ToList(); Debug.Assert(G2_leaves.Count() == numSlots / 2); for (int j = 0, k = 0; j < numSlots; j++, k = j / 2) G1_gates[j].AddEdgeTo(G2_leaves[k]); // create G3's var G3_root = new Gate(GateType.Internal, quorumIndex++, G3_parser.Circuit); CreateGateTree(G3_root, numSlots / 2, quorumIndex, true); // connect root G3 to root G2 G2_root.AddEdgeTo(G3_root); // connect leaf G3's to G4's var G3_leaves = GetGatesAndLeaves(G3_root, true, internalGates).ToList(); Debug.Assert(G3_leaves.Count() == numSlots / 2); for (int j = 0, k = 0; j < numSlots; j++, k = j / 2) G3_leaves[k].AddEdgeTo(G4_gates[j]); G4_gatesList.Add(G4_gates); } // create anonymous broadcaster // the broadcaster consists of t binary trees each of which has n leaves. var sum_parser = new Common.FiniteField.Circuits.Parser("Inputs=X1,X2 \n Outputs=Y \n Y=(X1+X2)", prime); sum_parser.Parse(); // create t binary trees with n leaves var adder_roots = new MpcProtocols.Dkms.Gate[numSlots]; var adder_leaves = new List<MpcProtocols.Dkms.Gate[]>(numSlots); for (int i = 0; i < numSlots; i++) { adder_roots[i] = new Gate(GateType.Internal, quorumIndex++, sum_parser.Circuit); CreateGateTree(adder_roots[i], numPlayers / 2, quorumIndex, false); var leaves = GetGatesAndLeaves(adder_roots[i], false, internalGates).ToArray(); Debug.Assert(leaves.Length == numPlayers / 2); adder_leaves.Add(leaves); } // connect G4's to the broadcaster leaves // note: i-th G4's of two adjacent players must be connected to the same leaf for (int i = 0; i < numSlots; i++) { for (int j = 0, k = 0; j < numPlayers; j++, k = j / 2) G4_gatesList[j][i].AddEdgeTo(adder_leaves[i][k]); } return new MpcProtocols.Dkms.Circuit(inputGates.AsReadOnly(), internalGates); }
protected static MpcProtocols.Dkms.Circuit CreateByzantineCircuit(int numPlayers, int numQuorums, int numSlots, int quorumSize, int prime) { var inputGates = new List <Gate>(); var internalGates = new List <Gate>(); var quorumIndex = new Zp(numQuorums); // TODO: THE NUMBER OF INPUTS OF ALL GATES MUST BE IN ORDER OF THE QUORUM SIZE NOT JUST ONE OR TWO. // WE HAVE TO ADD A RECOMBINE CIRCUIT (DISCUSSED IN A PAPER) TO REDUCE THE NUMBER OF INPUTS TO ONE OR TWO. //var G1_parser = new Parser("Inputs=X \n Outputs=Y \n Y0=(X/X) \n Y=(1-Y0)", prime); //G1_parser.Parse(); //var G2_parser = new Parser("Inputs=X1,X2 \n Outputs=Y \n S=(X1+X2) \n X0=(S==0) \n Y0=(X0/X0) \n Y1=(1-Y0) \n W0=(S==1) \n Z0=(W0/W0) \n Z1=(1-Z0) \n Z2=(2*Z1) \n Z=(Z0+Z2) \n Y=(Y1*Z)", prime); //G2_parser.Parse(); //var G3_parser = new Parser("Inputs=X \n Outputs=Y \n E1=(X==0) \n E2=(X==1) \n X0=(E1+E2) \n Y0=(X0/X0) \n Y=(1-Y0)", prime); //G3_parser.Parse(); //var G4_parser = new Parser("Inputs=X1,X2 \n Outputs=Y \n X=(X1==0) \n Y0=(X/X) \n Y1=(1-Y0) \n Y=(Y0*X2)", prime); //G4_parser.Parse(); //////////////////////////////////// FOR 8/22 SUBMISSION ONLY var G1_parser = new Common.FiniteField.Circuits.Parser(Common.FiniteField.FunctionType.Sum, 2 * quorumSize, prime); var G2_parser = new Common.FiniteField.Circuits.Parser(Common.FiniteField.FunctionType.Sum, 3 * quorumSize, prime); G1_parser.Parse(); G2_parser.Parse(); var G3_parser = G1_parser; var G4_parser = G2_parser; //////////////////////////////////// FOR 8/22 SUBMISSION ONLY var G4_gatesList = new List <Gate[]>(numPlayers); for (int i = 0; i < numPlayers; i++) { var inputs = new Gate[numSlots]; var G1_gates = new Gate[numSlots]; var G4_gates = new Gate[numSlots]; for (int j = 0; j < numSlots; j++) { inputs[j] = new Gate(quorumIndex++); // input gates // create G1's and connect input gates to them G1_gates[j] = new Gate(GateType.Internal, quorumIndex++, G1_parser.Circuit); inputs[j].AddEdgeTo(G1_gates[j]); // create G4's and connect input gates to them G4_gates[j] = new Gate(GateType.Internal, quorumIndex++, G4_parser.Circuit); inputs[j].AddEdgeTo(G4_gates[j]); inputGates.Add(inputs[j]); internalGates.Add(G1_gates[j]); internalGates.Add(G4_gates[j]); } // create G2's var G2_root = new Gate(GateType.Internal, quorumIndex++, G2_parser.Circuit); CreateGateTree(G2_root, numSlots / 2, quorumIndex, false); // connect leaf G2's to G1's var G2_leaves = GetGatesAndLeaves(G2_root, false, internalGates).ToList(); Debug.Assert(G2_leaves.Count() == numSlots / 2); for (int j = 0, k = 0; j < numSlots; j++, k = j / 2) { G1_gates[j].AddEdgeTo(G2_leaves[k]); } // create G3's var G3_root = new Gate(GateType.Internal, quorumIndex++, G3_parser.Circuit); CreateGateTree(G3_root, numSlots / 2, quorumIndex, true); // connect root G3 to root G2 G2_root.AddEdgeTo(G3_root); // connect leaf G3's to G4's var G3_leaves = GetGatesAndLeaves(G3_root, true, internalGates).ToList(); Debug.Assert(G3_leaves.Count() == numSlots / 2); for (int j = 0, k = 0; j < numSlots; j++, k = j / 2) { G3_leaves[k].AddEdgeTo(G4_gates[j]); } G4_gatesList.Add(G4_gates); } // create anonymous broadcaster // the broadcaster consists of t binary trees each of which has n leaves. var sum_parser = new Common.FiniteField.Circuits.Parser("Inputs=X1,X2 \n Outputs=Y \n Y=(X1+X2)", prime); sum_parser.Parse(); // create t binary trees with n leaves var adder_roots = new MpcProtocols.Dkms.Gate[numSlots]; var adder_leaves = new List <MpcProtocols.Dkms.Gate[]>(numSlots); for (int i = 0; i < numSlots; i++) { adder_roots[i] = new Gate(GateType.Internal, quorumIndex++, sum_parser.Circuit); CreateGateTree(adder_roots[i], numPlayers / 2, quorumIndex, false); var leaves = GetGatesAndLeaves(adder_roots[i], false, internalGates).ToArray(); Debug.Assert(leaves.Length == numPlayers / 2); adder_leaves.Add(leaves); } // connect G4's to the broadcaster leaves // note: i-th G4's of two adjacent players must be connected to the same leaf for (int i = 0; i < numSlots; i++) { for (int j = 0, k = 0; j < numPlayers; j++, k = j / 2) { G4_gatesList[j][i].AddEdgeTo(adder_leaves[i][k]); } } return(new MpcProtocols.Dkms.Circuit(inputGates.AsReadOnly(), internalGates)); }
protected static void CreateGateTree(MpcProtocols.Dkms.Gate root, int numLeaves, Zp quorumIndex, bool topToBottom) { if (numLeaves > 1) { var left = new MpcProtocols.Dkms.Gate(root.Type, quorumIndex++, root.MpcCircuit); var right = new MpcProtocols.Dkms.Gate(root.Type, quorumIndex++, root.MpcCircuit); if (topToBottom) { root.AddEdgeTo(left); root.AddEdgeTo(right); } else { left.AddEdgeTo(root); right.AddEdgeTo(root); } if (numLeaves >= 4) { CreateGateTree(left, numLeaves / 2, quorumIndex, topToBottom); CreateGateTree(right, numLeaves / 2, quorumIndex, topToBottom); } } }