-
Notifications
You must be signed in to change notification settings - Fork 253
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
Allow to overwrite the default implementation of msm
#528
Conversation
It would be great if we could pass a custom It looks like this is not the way to go, since it is producing some recursive compile time loop problem? |
I suppose Are there methods besides |
Another idea would be to have a global "registry" that contains function pointers for MSMs and FFTs. Something like the following, perhaps: pub struct Registry {
msm: /* type signature for MSM method */
fft: /* type signature for FFT methods */
}
lazy_static! { REGISTRY: Registry = /* init */ }; // or use OnceCell
// In MSM impl
fn msm(...) {
REGISTRY.msm(...);
} We will provide default impls for |
The foregoing design is basically the idea in #470 |
Actually, it would be nice to have a design that's a hybrid between ark_ec::with_msm(msm_fn1, || { /* scoped code that uses `msm_fn1` */});
ark_ec::with_msm(msm_fn2, || { /* scoped code that uses `msm_fn2` */}); and global replacement ark_ec::set_global_msm(msm_fn1);
/* all subsequent code uses `msm_fn1` */ |
A registry incurs some global cost, unless some default feature disables it, but if your talking about ASICs or FPGA then maybe you'd want it for some curves but not others. Another part of the story would be what/how gadget code depends upon the models? ala your comments in arkworks-rs/curves#76 Assuming "not really" then.. We could override I kinda wish there was some co-git tool that helped maintain branch-like repository differences across repositories, given we're seemingly talking about such a small delta: https://github.com/arkworks-rs/algebra/blob/master/ec/src/models/short_weierstrass/group.rs#L637 Anyways.. We could do this specialization manually if we really like the specialization solution here, no?
|
In practice I suspect the overhead of the registry will be negligible compared to the cost of the MSM.
Yes, the "hook"/"registry" idea is compatible with this PR, but I think this PR would be redundant if we implemented the former. A further advantage of the registry idea is that only the default (current) MSM impl needs to live in |
Yes of course, but what I mean is: What would need hooks? It's clear Miller looks and final exps are costly enough to justify hooks this way, but they can be patched without hooks without much code duplication. I suppose
Yes, this sounds more relevant, and I guess answers my question above. Are the trade offs in MSMs mostly just size? Rust has no polymorphic |
I adopted my implementation to what @burdges suggested. This way tests are passing, the recursive compile time loop is gone. If we want to implement this solution, the PR would be ready for review. It would definitely drastically cut down the amount of code that we have to fork for our implementation. |
…o pass-msm-bigint
…o pass-msm-bigint
I changed the design a bit, now we are re-implementing the |
msm
* upstream/master: (29 commits) Fix some clippy lints (arkworks-rs#570) Correct tag name & complete command suggestion (arkworks-rs#569) Open a "release-PR" against a `releases` branch (arkworks-rs#566) Allow to overwrite default impl of `msm` in TwistedEdwards form (arkworks-rs#567) Remove poly-benches. (arkworks-rs#558) DO NOT MERGE YET. Release 0.4 (arkworks-rs#512) otherwise downstream users that have not migrated will not see warning (arkworks-rs#563) use `into_bigint()` in `Debug` for `Fp<P, N>` (arkworks-rs#562) Add `frobenius_map_in_place` (arkworks-rs#557) Fix test_sw_properties for some cofactor groups (arkworks-rs#555) Move h2c tests to test-templates (arkworks-rs#554) impl `CanonicalSerialize/Deserialize` for `BigUint` (arkworks-rs#551) Fix MontFp issue in fields with 64 * k bits (arkworks-rs#550) Fix tests for Modulus plus one div four (arkworks-rs#552) fix (arkworks-rs#547) Rename all `*Parameters` to `*Config` (arkworks-rs#545) Fix doc-comment on `SWUMap` and CamelCase `(CO)DOMAIN` Small cleanups in hash-to-curve (arkworks-rs#544) Allow to overwrite the default implementation of `msm` (arkworks-rs#528) Move `multi_miller_loop` and `final_exponentiation` into `BW6Config` (arkworks-rs#542) ...
Description
Multi scalar multiplication is usually an expensive operation on different platforms. It is slow in WebAssembly runtimes and can usually get speed up by special hardware. This makes it interesting to define a custom
msm
function in the model which overwrites the default implementation. This custom function could compute the msm by calling into host functions from a WebAssembly runtime or by delegating it to customized hardware.This PR:
msm
from theVariableBaseMSM
trait in theSWCurveConfig
trait, refers there tomsm_unchecked
from theVariableBaseMSM
trait. This function ois calledmodel_msm
model_msm
implementation provided by theSWCurveConfig
trait in theVariableBaseMSM
implementation forProjective<P>
model_msm
bigint function can get overwritten by curves which are implementing theSWCurveConfig
trait.Similar motivation and technique then the already merged PR #534 . As discussed in issue #537.
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
- [ ] Wrote unit testsnon-breaking change, all existing tests are still passing.Pending
section inCHANGELOG.md
Files changed
in the GitHub PR explorer