1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use std::ops;

use tracing_subscriber::EnvFilter;

use seec::circuit::builder::CircuitBuilder;
use seec::circuit::dyn_layers::CircuitLayerIter;
use seec::circuit::DefaultIdx;
use seec::secret::{inputs, low_depth_reduce, Secret};
use seec::{sub_circuit, BooleanGate, Circuit};

#[sub_circuit]
fn and_sc(input: &[Secret]) -> Secret {
    low_depth_reduce(input.iter().cloned(), ops::BitAnd::bitand).expect("Empty input")
}

#[sub_circuit]
fn or_sc(input: &[Secret]) -> Secret {
    low_depth_reduce(input.iter().cloned(), ops::BitOr::bitor).expect("Empty input")
}

fn main() {
    tracing_subscriber::fmt()
        .with_env_filter(EnvFilter::from_default_env())
        .init();

    let input_shares = inputs(8);

    let and_outputs = input_shares
        .chunks_exact(4)
        .fold(vec![], |mut acc, input_chunk| {
            let output = and_sc(input_chunk);
            acc.push(output);
            acc
        });

    let or_out = or_sc(&and_outputs);

    (or_out ^ false).output();

    let circuit: Circuit<bool, BooleanGate, DefaultIdx> = CircuitBuilder::global_into_circuit();
    let layer_iter = CircuitLayerIter::new(&circuit);
    for layer in layer_iter {
        dbg!(layer);
    }

    // let circuit = circuit.into_base_circuit();
    // eprintln!("into base");
    // circuit.save_dot("sub_circuits.dot").unwrap();
}