-
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
Improve zkey load time #25
Comments
I confirm that this is a problem on iOS device too. My hunch is this will be improved using dylib. Still seems weird to me this is so slow though. |
Same basic behavior. With this we isolate this to initializing of library. https://github.com/oskarth/mopro/blob/main/mopro-core/src/middleware/circom/mod.rs#L87 for timing Gonna leave this for now but two approaches:
|
We should be able to preprocess zkey and then quickly load proving key and matrices from disk:
|
I tried out some things here #26 and it seems like the slow part is the ProvingKey. I think this is because it is doing a bunch of EC operations etc, so there might be a more efficient way to do serialization field by field.
|
More complete log for
|
Improvements using custom serialization for arkworks proving key and matrices, and using This is about x10 better (Result: 18s vs 158s for keccak256) but can't help but to think this can be improved quite a lot more. |
This is the library we want to try https://github.com/rkyv/rkyv |
For checking perf: https://github.com/mstange/samply |
Think we do this already but might be worth sanity checking arkworks-rs/circom-compat#46 (comment) |
Suggestions from @vimwitch For #25 the problem isn't loading the file into memory, this happens in < 1 ms. The problem is parsing the bytes into usable data. In this file the zkey is being parsed: https://github.com/arkworks-rs/circom-compat/blob/master/src/zkey.rs The process is simple, it iterates over the bytes and extracts certain sections as bigint (32, 64, 256 bit) numbers. The problem is on line 347 and 358. These lines call into this function: https://github.com/arkworks-rs/algebra/blob/master/ec/src/models/short_weierstrass/affine.rs#L72 This function asserts that the point is on the curve and in the correct subgroup. These checks have to be performed for thousands of points and take 99% of the time in the profiler. I forked
You can test this by switching the I think using |
Oh awesome! I thought we used new_unchecked already. Yes indeed, the problem are those EC checks. Out of curiosity, how exactly did you profile to find those exact lines being the problem? I didn't spend enough time to get a good profile setup but that makes sense. Easier than doing the zero-copy serialization probably. As for as I know it should be OK to use My suggestion would be that we merge it, and we can create an issue to understand security assumptions better. In any case, for serious production use, we'd want to audit code and libraries more. Right now most of the stack (including dependencies like ark-groth16 afaik) are unaudited. So in the grand scheme of things I don't think this is especially unsafe (famous last words) compared to general attack surface. |
I use samply for profiling rust stuff. I took the test that loads the zkey and copied it into an example executable then let it run for a few seconds with the profiler. I don't know how to run the tests with samply attached, i think it might not be possible. This is the profile: https://share.firefox.dev/3UohBEa |
fixed by #129 |
Problem
It is slow to load zkey.
cargo test --release test_generate_proof2 -- --nocapture
shows it takes ~70-80s to load in zkey for a ~80mb file (Keccak256).Zkey is ~80mb but would expect this to be much faster.
This seems to be the case regardless of if we are using dylib or not.
Approaches
Two ideas:
Acceptance criteria
Much faster loading of zkey, or other way to improve this type of load up time
The text was updated successfully, but these errors were encountered: