MCPcopy Create free account
hub / github.com/ciphermodelabs/ciphercore / main

Function main

ciphercore-base/src/bin/ciphercore_split_parties.rs:89–146  ·  view source on GitHub ↗

This binary reads the inputs from the file and splits them (+ possibly secret-shares) between the parties according to a command line parameter. # Arguments `inputs_path` - path to file that contains the inputs `input_parties` - string comprising of either a comma separated list of input parties' IDs, valid ID values include `0`, `1`, `2` OR `public` OR `secret-shared` `inputs_path_0` - path to

()

Source from the content-addressed store, hash-verified

87///
88/// < this_binary > <context_path> <inline_mode> <input_parties> <output_parties>
89fn main() {
90 env_logger::init();
91 execute_main(|| -> Result<()> {
92 let args = Args::parse();
93 let json_inputs = fs::read_to_string(&args.inputs_path)?;
94 let inputs = serde_json::from_str::<Vec<TypedValue>>(&json_inputs)?;
95 let input_parties = get_tokens(args.input_parties)?;
96 let mut split_inputs = vec![vec![], vec![], vec![]];
97 if inputs.len() != input_parties.len() {
98 return Err(runtime_error!(
99 "Invalid number of inputs parties: {} expected, but {} found",
100 inputs.len(),
101 input_parties.len()
102 ));
103 }
104 let mut prng = PRNG::new(None)?;
105 for i in 0..inputs.len() {
106 match input_parties[i] {
107 IOStatus::Party(p) => {
108 for (j, result_item) in split_inputs.iter_mut().enumerate() {
109 if j as u64 == p {
110 result_item.push(inputs[i].clone());
111 } else {
112 result_item.push(TypedValue::new(
113 inputs[i].t.clone(),
114 Value::zero_of_type(inputs[i].t.clone()),
115 )?);
116 }
117 }
118 }
119 IOStatus::Public => {
120 for result_item in split_inputs.iter_mut() {
121 result_item.push(inputs[i].clone());
122 }
123 }
124 IOStatus::Shared => {
125 let parties_shares = inputs[i].get_local_shares_for_each_party(&mut prng)?;
126 for j in 0..3 {
127 split_inputs[j].push(parties_shares[j].clone());
128 }
129 }
130 }
131 }
132 fs::write(
133 args.parties_inputs_0,
134 serde_json::to_string(&split_inputs[0])?,
135 )?;
136 fs::write(
137 args.parties_inputs_1,
138 serde_json::to_string(&split_inputs[1])?,
139 )?;
140 fs::write(
141 args.parties_inputs_2,
142 serde_json::to_string(&split_inputs[2])?,
143 )?;
144 Ok(())
145 });
146}

Callers

nothing calls this directly

Calls 5

execute_mainFunction · 0.85
cloneMethod · 0.80
get_tokensFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected