Use starkware/crypto-cpp for starknet verify/pedersen #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Same idea as #2 but using https://github.com/starkware-libs/crypto-cpp which is audited and has existing JS bindings.
Problem
sign/verify/pedersenfunctions are CPU intensive and the current implementation uses https://github.com/indutny/elliptic which is very slow in JS.Solution
Use crypto-cpp for
pedersenandverifyfunctions that are called most of the time in our backend.signis mostly called by client browsers and akvariable has to be computed which isn't trivial (https://github.com/starkware-libs/crypto-cpp/blob/master/src/starkware/crypto/ffi/js/crypto.js#L64-L65) so we decided to skip using it for now.crypto-cpp is audited and hasn't changed since Dec 2021 so I copy/pasted the C++ code directly in this repo. I've made a few changes in CMakeLists.txt and removed presubmit.sh and Go bindings as we don't use them. To review this MR I suggest pulling the code and running
git diff origin/master ':!src/crypto-cpp'to hide crypto-cpp additions.The idea is to keep this library full JS compatible (for browsers especially) but set
USE_STARKWARE_CRYPTO_CPP=trueto make crypto functions use the C++ dynamic library and speed things up.Results ⚡
(on my machine, without C++
sign)Before:
After: