Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(compute): testing chained operation calls with output labels #42

Merged
merged 32 commits into from
Oct 27, 2024

Conversation

10d9e
Copy link
Collaborator

@10d9e 10d9e commented Oct 21, 2024

Changes include:

  • refactored CircuitBuilder that includes design for operations accepting circuit based inputs
  • refactored mux gate
  • created a circuit macro helper that maps operators and if/then/else to appropriate builder ops... available in both execute and compile modes
#[test]
fn test_macro_if_else3() {
    #[circuit(execute)]
    fn mux_circuit(a: &T, b: &T) -> T {
        let first_two = a - b;
        if first_two {
            a * b
        } else {
            a + b
        }
    }

    let a = 4_u8;
    let b = 4_u8;

    let result = mux_circuit(&a, &b);
    assert_eq!(result, a + b);

    let a = 5_u8;
    let result = mux_circuit(&a, &b);
    assert_eq!(result, a * b);
}

#[test]
fn test_macro_arithmetic_compiler() {
    #[circuit(compile)]
    fn multi_arithmetic(a: &T, b: &T, c: &T, d: &T) -> (Circuit, Vec<bool>) {
        let res = a * b;
        let res = res + c;
        res - d
    }

    let a = 2_u8;
    let b = 5_u8;
    let c = 3_u8;
    let d = 4_u8;

    let (circuit, inputs) = multi_arithmetic(&a, &b, &c, &d);
    let result = get_executor().execute(&circuit, &inputs, &[]).unwrap();
    let result: GarbledUint<8> = GarbledUint::new(result);
    let result: u8 = result.into();
    assert_eq!(result, a * b + c - d);
}

closes #31
closes #3
closes #2

@10d9e 10d9e self-assigned this Oct 21, 2024
@10d9e 10d9e force-pushed the 10d9e/feat/multi-input-circuit-compiler branch from c74eada to 8942e5e Compare October 25, 2024 16:31
10d9e added 8 commits October 25, 2024 13:34
Simplified the circuit builder macros by combining the boolean and arithmetic operations into a single macro. This improves code readability and maintainability.
Refactor the circuit builder macros in the compute module to include a new macro for multiplication. This macro is used to build and execute a multiplication circuit. The code changes include adding the `build_and_execute_multiplication` macro and its implementation.
- Modified the circuit macro to improve input generation.
- Replaced unnecessary cloning with references for better performance.
@10d9e 10d9e requested a review from NMCarv October 25, 2024 19:26
@10d9e 10d9e marked this pull request as ready for review October 25, 2024 19:26
@10d9e 10d9e requested review from rafagomes and sbnair October 25, 2024 19:28
@10d9e 10d9e added this to the Compute SDK beta milestone Oct 25, 2024
10d9e added 9 commits October 27, 2024 03:53
This commit adds clippy lints to the circuit_macro crate. Specifically, it allows non_camel_case_types, non_snake_case, clippy::builtin_type_shadow, and clippy::too_many_arguments. This change improves the code quality and ensures that the code adheres to the recommended coding conventions.
@10d9e 10d9e merged commit cd5a926 into main Oct 27, 2024
4 checks passed
@10d9e 10d9e deleted the 10d9e/feat/multi-input-circuit-compiler branch October 27, 2024 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant