zkcrypto / bellman

zk-SNARK library.
Other
989 stars 534 forks source link

Add a TypedVariable trait #14

Closed str4d closed 6 years ago

str4d commented 6 years ago

This enables bellman users to implement structs that wrap Variables, and can interact with LinearCombination as if they were Variables.

str4d commented 6 years ago

Before this PR, structs would need to make their internal Variable public, and users of the structs would write:

LinearCombination::zero() + CS::one() - (j.d, tau.var)

After this PR, structs expose their internal Variable via the trait, and users instead write:

LinearCombination::zero() + CS::one() - (j.d, &tau)

I looked into making this more of a DSL:

LinearCombination::zero() + CS::one() - j.d * &tau

This can only be implemented by the struct author, not generically by bellman. Additionally, it only works if the struct takes E: Engine as a specialisation (so e.g. for Num<E> but not Bit).

daira commented 6 years ago

This seems to provide for wrapped variables in general, with typed variables only being one possible application. Perhaps the trait name should be WrappedVariable.

bmerge commented 6 years ago

:umbrella: The latest upstream changes (presumably 6d55a4052a70b058f5b9b4762e023e6234e778dc) made this pull request unmergeable. Please resolve the merge conflicts.

ebfull commented 6 years ago

I'm closing this because it appears bellman doesn't really need to provide any of this stuff, AFAIK. If you see a use case for it that can't be achieved with other abstractions, let me know.