-
Notifications
You must be signed in to change notification settings - Fork 285
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
Optimize EVMMAX montgomery multiplication #777
Comments
@chfast Could I help here? I am good with algorithms, also it will help if I can get a bit more context. Thanks |
Hi @triggeredcode, The two important references are already in the description. You should check out our existing code implementing Montgomery multiplication using CIOS algorithm. https://github.com/ethereum/evmone/blob/v0.11.0/lib/evmmax/evmmax.cpp#L55-L83. We want to know if swapping this algorithm with any other would bring performance improvements. The good overview of the algorithms is https://www.microsoft.com/en-us/research/wp-content/uploads/1998/06/97Acar.pdf. But you can also do your research. This code is well tested and we have benchmarks so it should be relatively easy to get feedback. |
Possibly generate the algorithms with https://github.com/mit-plv/fiat-crypto. |
Hey @chfast, I just saw this issue and I would like to give it a try. However, I am a beginner and this is my first time working with a benchmark, if I understand correctly, the goal is to improve the performance of the benchmark. Running this command
So if I understand well, the purpose is to try different implementations of the CIOS version of the Montgomery algorithm such as the FIPS version, Barrett Reduction, or Karatsuba Multiplication and see which one is the most efficient according to the benchmark. The point I’m wondering about is whether the existing unit tests will be sufficient to ensure the quality of the tested algorithm Thank you in advance for your response. I am not committing to completing this issue, but I find the problem very interesting and I would like to be able to contribute. |
Hello @chfast, I have made progress since the message and implemented the Separated Operand Scanning (SOS) version of the Montgomery algorithm to compare it with the current version. I’m leaving the benchmark traces below, but could you give me some guidance on how to achieve a quality benchmark? CIOS Implementation
SOS Implementation
There are differences that seem to suggest that the SOS version could be more efficient on certain benchmarks, but how can I be sure of the accuracy of the results? Plus, the code compiles, and the unit tests pass, but is that enough to prove the correct implementation of my algorithm? Could you share the methodology you used or some resources that will help me move forward in line with the project expectations? |
There are interesting results. Also because people usually suggest to use CIOS. If you can share your code I can also benchmark it. You can also take a look at #869. |
My apologies as I realized after posting that message that my algorithm did not pass all the unit tests. I am actively working on it to propose a correct implementation and run new benchmarks. |
This is fine. You may still want to take a loot at #869 as a smaller optimization step. |
Now that we have benchmarks for EVMMAX precompiles we can experiment with different Montgomery multiplication algorithms. Currently we use CIOS.
The reference paper we used have a summary of the complexity of each algorithm. However, these may not be directly applicable to small numbers like 256-bit. Check also what other projects are doing.
Also study https://www.amazon.science/blog/better-performing-25519-elliptic-curve-cryptography.
The text was updated successfully, but these errors were encountered: