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

Function prepare_input

ciphercore-base/src/mpc/mpc_conversion.rs:444–514  ·  view source on GitHub ↗
(
        op: Operation,
        input: Vec<u128>,
        input_status: IOStatus,
        t: Type,
    )

Source from the content-addressed store, hash-verified

442 }
443
444 fn prepare_input(
445 op: Operation,
446 input: Vec<u128>,
447 input_status: IOStatus,
448 t: Type,
449 ) -> Result<Vec<Value>> {
450 let mut res = vec![];
451 if input_status == IOStatus::Public {
452 match t {
453 Type::Scalar(st) => {
454 res.push(Value::from_scalar(input[0], st)?);
455 }
456 Type::Array(_, st) => {
457 res.push(Value::from_flattened_array(&input, st)?);
458 }
459 _ => {
460 panic!("Shouldn't be here");
461 }
462 }
463 return Ok(res);
464 }
465
466 let mut data_input = vec![];
467 match t {
468 Type::Array(_, st) => {
469 if matches!(input_status, IOStatus::Party(_)) {
470 res.push(Value::from_flattened_array(&input, st)?);
471 return Ok(res);
472 }
473 if let Operation::B2A(_) = op {
474 // shares of input = (input^3, 2, 1)
475 let first_share: Vec<u128> = input.iter().map(|x| (*x) ^ 3).collect();
476 data_input.push(Value::from_flattened_array(&first_share, st)?);
477 } else {
478 // shares of input = (input-3, 1, 2)
479 let threes = vec![3; input.len()];
480 let first_share = subtract_vectors_u128(&input, &threes, st.get_modulus())?;
481 data_input.push(Value::from_flattened_array(&first_share, st)?);
482 }
483 for i in 1..PARTIES {
484 let share = vec![i; input.len()];
485 data_input.push(Value::from_flattened_array(&share, st)?);
486 }
487 }
488 Type::Scalar(st) => {
489 if matches!(input_status, IOStatus::Party(_)) {
490 res.push(Value::from_scalar(input[0], st)?);
491 return Ok(res);
492 }
493 if let Operation::B2A(_) = op {
494 // shares of input = (input^3, 2, 1)
495 let first_share = input[0] ^ 3;
496 data_input.push(Value::from_scalar(first_share, st)?);
497 } else {
498 // shares of input = (input-3, 1, 1)
499 let first_share = subtract_vectors_u128(&input, &vec![3], st.get_modulus())?;
500 data_input.push(Value::from_scalar(first_share[0], st)?);
501 }

Callers 1

conversion_testFunction · 0.70

Calls 3

subtract_vectors_u128Function · 0.85
get_modulusMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected