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

Function helper_create_ops

ciphercore-base/src/mpc/mpc_compiler.rs:1727–1807  ·  view source on GitHub ↗
(
        input_types: Vec<Type>,
        op: Operation,
        input_party_map: Vec<IOStatus>,
        output_parties: Vec<IOStatus>,
        include_constant: bool,
    )

Source from the content-addressed store, hash-verified

1725 }
1726
1727 fn helper_create_ops(
1728 input_types: Vec<Type>,
1729 op: Operation,
1730 input_party_map: Vec<IOStatus>,
1731 output_parties: Vec<IOStatus>,
1732 include_constant: bool,
1733 ) -> Result<()> {
1734 let c = create_context()?;
1735 let g = c.create_graph()?;
1736 let mut input_nodes = vec![];
1737 for i in 0..input_types.len() {
1738 let input_node = g.input(input_types[i].clone())?;
1739 input_node.set_name(&format!("Input {}", i))?;
1740 input_nodes.push(input_node);
1741 }
1742 let resolved_op = if include_constant {
1743 input_nodes.push(g.constant(
1744 input_types[0].clone(),
1745 Value::zero_of_type(input_types[0].clone()),
1746 )?);
1747 match op {
1748 Operation::CreateNamedTuple(mut names) => {
1749 names.push("const".to_owned());
1750 Operation::CreateNamedTuple(names)
1751 }
1752 Operation::Stack(outer_shape) => {
1753 let mut pr = 1;
1754 for x in &outer_shape {
1755 pr *= *x;
1756 }
1757 Operation::Stack(vec![pr + 1])
1758 }
1759 _ => op,
1760 }
1761 } else {
1762 op
1763 };
1764 let o = g.add_node(input_nodes, vec![], resolved_op)?;
1765 o.set_name("Plaintext operation")?;
1766 let output_type = o.get_type()?;
1767 g.set_output_node(o.clone())?;
1768 g.finalize()?;
1769 c.set_main_graph(g.clone())?;
1770 c.finalize()?;
1771
1772 let inline_config = InlineConfig {
1773 default_mode: InlineMode::Simple,
1774 ..Default::default()
1775 };
1776 let mpc_c = prepare_for_mpc_evaluation(
1777 c.clone(),
1778 vec![input_party_map.clone()],
1779 vec![output_parties.clone()],
1780 inline_config,
1781 )?;
1782 let mpc_graph = mpc_c.get_main_graph()?;
1783 // Check names
1784 let mpc_node_result = mpc_c.retrieve_node(mpc_graph.clone(), "Plaintext operation");

Callers 1

test_helper_create_opsFunction · 0.85

Calls 15

cloneMethod · 0.80
add_nodeMethod · 0.80
prepare_inputFunction · 0.70
check_outputFunction · 0.70
create_contextFunction · 0.50
create_graphMethod · 0.45
inputMethod · 0.45
set_nameMethod · 0.45
pushMethod · 0.45
constantMethod · 0.45
get_typeMethod · 0.45

Tested by 1

test_helper_create_opsFunction · 0.68