Compiles all the graphs of an already inlined context into graphs for secure computation. Namely, every plaintext operation is replaced by a related MPC protocol from the ABY3 framework. The given input-party map describes what statuses of inputs (public, shared or owned by a party). The `output_parties` argument contains ids of the parties (from 0..PARTIES) that obtain the revealed result of MPC
(
context: Context,
input_party_map: Vec<Vec<IOStatus>>,
output_parties: Vec<Vec<IOStatus>>,
)
| 1051 | /// If private, the output of the main graph is always a tuple of 3 elements where the first element is known to the first party, |
| 1052 | /// the second to the second one etc. Thus, the first tuple element can be either a share or a revealed value known to the first party. |
| 1053 | fn compile_to_mpc( |
| 1054 | context: Context, |
| 1055 | input_party_map: Vec<Vec<IOStatus>>, |
| 1056 | output_parties: Vec<Vec<IOStatus>>, |
| 1057 | ) -> Result<MappedContext> { |
| 1058 | for sub_map in &input_party_map { |
| 1059 | for status in sub_map { |
| 1060 | if let IOStatus::Party(id) = *status { |
| 1061 | if id >= PARTIES as u64 { |
| 1062 | return Err(runtime_error!("Input party should have a valid party ID")); |
| 1063 | } |
| 1064 | } |
| 1065 | } |
| 1066 | } |
| 1067 | for sub_parties in &output_parties { |
| 1068 | for status in sub_parties { |
| 1069 | if let IOStatus::Party(id) = *status { |
| 1070 | if id >= PARTIES as u64 { |
| 1071 | return Err(runtime_error!("Output party should have a valid party ID")); |
| 1072 | } |
| 1073 | } else { |
| 1074 | return Err(runtime_error!( |
| 1075 | "Output status should be a party id or shared" |
| 1076 | )); |
| 1077 | } |
| 1078 | } |
| 1079 | } |
| 1080 | let new_context = create_context()?; |
| 1081 | let mut context_map = ContextMappings::default(); |
| 1082 | compile_to_mpc_context( |
| 1083 | context.clone(), |
| 1084 | input_party_map, |
| 1085 | output_parties, |
| 1086 | new_context.clone(), |
| 1087 | &mut context_map, |
| 1088 | )?; |
| 1089 | let old_main_graph = context.get_main_graph()?; |
| 1090 | let main_graph = context_map.get_graph(old_main_graph); |
| 1091 | new_context.set_main_graph(main_graph)?; |
| 1092 | new_context.finalize()?; |
| 1093 | let mut mapped_context = MappedContext::new(new_context); |
| 1094 | mapped_context.mappings = context_map; |
| 1095 | Ok(mapped_context) |
| 1096 | } |
| 1097 | |
| 1098 | /// Creates a new copy of an input context with PRF nodes containing globally unique inputs (iv's). |
| 1099 | /// These global inputs are taken from the set {1,2,...,n} where n is the total number of PRF nodes. |