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

Function test_input

ciphercore-base/src/mpc/mpc_compiler.rs:1335–1428  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1333
1334 #[test]
1335 fn test_input() {
1336 let seed = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F";
1337 let mut prng = PRNG::new(Some(*seed)).unwrap();
1338 let mut helper =
1339 |t: Type, input_status: IOStatus, output_parties: Vec<IOStatus>| -> Result<()> {
1340 let c = simple_context(|g| g.input(t.clone()))?;
1341 let mpc_mapped_context = compile_to_mpc(
1342 c,
1343 vec![vec![input_status.clone()]],
1344 vec![output_parties.clone()],
1345 )?;
1346 let mpc_context = mpc_mapped_context.get_context();
1347 let mpc_graph = mpc_context.get_main_graph()?;
1348 let mut inputs = vec![];
1349 if input_status == IOStatus::Shared {
1350 let tuple_t = tuple_type(vec![t.clone(); PARTIES]);
1351 inputs.push(prng.get_random_value(tuple_t.clone())?);
1352 } else {
1353 inputs.push(prng.get_random_value(t.clone())?);
1354 }
1355 let output = random_evaluate(mpc_graph.clone(), inputs.clone())?;
1356
1357 let mpc_computation_graph = mpc_context.get_graphs()[0].clone();
1358
1359 let computation_output_node = mpc_computation_graph.get_output_node()?;
1360 let computation_output_annotations = computation_output_node.get_annotations()?;
1361 if input_status != IOStatus::Public {
1362 let expected = if input_status == IOStatus::Shared {
1363 reveal_private_value(inputs[0].clone(), t.clone())?
1364 } else {
1365 inputs[0].clone()
1366 };
1367 // check that output is a sharing of expected
1368 if output_parties.is_empty() {
1369 let revealed_output = reveal_private_value(output.clone(), t.clone())?;
1370 assert!(output.check_type(tuple_type(vec![t.clone(); PARTIES]))?);
1371 assert_eq!(revealed_output, expected);
1372 } else {
1373 // check that output is of the right type
1374 assert!(output.check_type(t.clone())?);
1375 assert_eq!(output, expected.clone());
1376 }
1377 assert!(computation_output_annotations.contains(&NodeAnnotation::Private));
1378 } else {
1379 // public input must be shared
1380 if output_parties.is_empty() {
1381 let revealed_output = reveal_private_value(output.clone(), t.clone())?;
1382 assert!(output.check_type(tuple_type(vec![t.clone(); PARTIES]))?);
1383 assert_eq!(revealed_output, inputs[0]);
1384 // check that the final output is private (since it's shared)
1385 let output_annotations = mpc_graph.get_output_node()?.get_annotations()?;
1386 assert!(output_annotations.contains(&NodeAnnotation::Private));
1387 } else {
1388 assert_eq!(output, inputs[0]);
1389 }
1390 // computation output should be public on public inputs
1391 assert!(!computation_output_annotations.contains(&NodeAnnotation::Private));
1392 }

Callers

nothing calls this directly

Calls 15

simple_contextFunction · 0.85
compile_to_mpcFunction · 0.85
random_evaluateFunction · 0.85
reveal_private_valueFunction · 0.85
cloneMethod · 0.80
get_random_valueMethod · 0.80
get_annotationsMethod · 0.80
is_emptyMethod · 0.80
tuple_typeFunction · 0.50
array_typeFunction · 0.50
scalar_typeFunction · 0.50
inputMethod · 0.45

Tested by

no test coverage detected