openzklib / openzl

Zero-Knowledge Cryptography Infrastructure Stack
https://openzl.org
Other
126 stars 14 forks source link

ECLAIR Compiler Procedural Macro #8

Open bhgomes opened 1 year ago

bhgomes commented 1 year ago

To build circuits in an abstract setting we need to pass around the compiler argument. In many cases, when we want to just compose existing primitives, we don't want to have to specify it and it would be nice to just infer it at every call site. This is where the procedural macro simplifies the work of the developer. They would go from this:

fn circuit<X, Y, Z, COM>(x: X, y: Y, z: Z, compiler: &mut COM) 
where
    X: Add<Y, COM, Output = Z>,
    Z: PartialEq<Z, COM>,
{
    compiler.assert_eq(&x.add(y, compiler), &z)
}

to this:

#[eclair]
fn circuit<X, Y, Z>(x: X, y: Y, z: Z) 
where
    X: Add<Y, Output = Z>,
    Z: PartialEq,
{
    assert_eq!(x + y, z)
}