Manta-Network / manta-rs

Rust Crates for the Manta Network Ecosystem

Home Page:https://github.com/Manta-Network

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Derive Macro for `Variable` and `Constant`

bhgomes opened this issue · comments

For Constant there is a canonical implementation for structs (each of its fields are constants). For Variable it will depend on the explicit allocation modes we want to add to each field, so maybe something like

#[derive(Variable)]
struct Thing<T> {
    #[secret]
    input: T,

    #[public]
    output: T
}

which would compile to something like:

impl<T> Variable<Derived, COM> for Thing<T>
where
    T: Variable<Public, COM> + Variable<Secret, COM>,
{
    type Type = Thing<T::Type>;
    
    #[inline]
    fn new_unknown(compiler: &mut COM) -> Self {
        Self {
            input: $crate::eclair::alloc::Allocator::allocate_unknown::<Secret, _>(compiler),
            output: $crate::eclair::alloc::Allocator::allocate_unknown::<Public, _>(compiler),
        }
    }
    
    #[inline]
    fn new_known(this: &Self::Type, compiler: &mut COM) -> Self {
        Self {
            input: $crate::eclair::alloc::Allocator::allocate_known::<Secret, _>(compiler, this.input),
            output: $crate::eclair::alloc::Allocator::allocate_unknown::<Public, _>(compiler, this.output),
        }
    }
}