-
Notifications
You must be signed in to change notification settings - Fork 36
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
feat: Implement RLC for iterators #223
Comments
* refactor: Simplify NIFS struct and remove PhantomData usage - Simplified the NIFS struct in `nifs.rs` file by removing extraneous elements. * refactor: Refactor ipa_pc.rs to use InnerProductArgument directly - Removed `EvaluationArgument` struct from `ipa_pc.rs` file, replacing it with direct usage of `InnerProductArgument`. - Updated `EvaluationEngineTrait` type declarations to accommodate the change. - Reworked `prove` and `verify` methods to work directly with `InnerProductArgument`. - Made `InnerProductArgument` visibility public. * refactor: Refactor PoseidonROCircuit struct trait bound - Trait bound changed from `PrimeField + PrimeFieldBits` to `PrimeField` in `poseidon.rs`. * refactor: mutualize macro for secp/bn256 cycles * Optimize generator creation in provider module - Refactored the `from_label` function in pasta.rs removing redundant collect, flatten operations and Vec<usize> creation, * refactor: Optimize circuit methods and enhance trait compatibility - Optimized performance by refactoring the use of iterator `into_iter()` to the iterator itself in `gadgets/r1cs.rs`. - removed a clone in ppsnark.
I believe this can be done straightforwardly with the num traits. Just to clarify: what justifies the adjective |
Looking at the num_traits now, but it's not clear how it would interact with the existing arithmetic ops traits in Arecibo. Regarding the name, the difference with an actual linear combination is that we would only pass a single challenge as input, rather than a vector of powers. The function can either compute these powers and call a linear combination, or use Horners method. If we are combining group elements for example, we may want to use Horner since we are only performing scalar multiplications with 128-bit challenge. Now you mention it though, an extension for linear combinations would also be a nice semantic addition to the code. |
I was using the "num" traits informally due to obscure associations of this name with abstractions that paper over numeric type differences, that was cryptic - sorry. In precise terms, what you want is just a generic function on completely standard traits that groups and fields (and presumably the collections you have in mind) already implement: fn rlc<T, F>(i: impl DoubleEndedIterator<Item = T>, coefficient: F) -> T
where T: MulAssign<F> + AddAssign<T>, F: Copy,
{
i.rev().reduce(|mut acc, item| {
acc *= coefficient;
acc += item;
acc
}).expect("input iterator should not be empty!")
} If we want to do something else than Horner, for parallelism, it can become quite a bit more complicated. |
See #260 |
For ordered collections of a type
T
whereT
is homomorphic with regards to a fieldF
, we can implement the traitA default implementation for
IntoIterator<Item = T>
(orIntoIterator<Item = &T>
) would remove a lot of boiler-plate code we currently have. In particular, we would not have to to compute powers of a challenge before zipping it with the iterator.The random linear combination of items can be computed efficiently using Horner's method. More specifically, we need to iterate in reverse, then fold over the "last" element in the list.
Getting the type right here is slightly non-trivial, especially since we want to use it over
The text was updated successfully, but these errors were encountered: