-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Add ecrecover syscall #17720
Add ecrecover syscall #17720
Conversation
@jackcmay Please review |
How about program space binding for both C and Rust? Tests? |
For CI it looks like not all the |
I'm not sure it should be called ecrecover, since that means something specific in ethereum. This is a general function for recovering the public key from a secp256k1 signature, which might be useful in other situations than ethereum compatibility. How about something like |
Codecov Report
@@ Coverage Diff @@
## master #17720 +/- ##
=========================================
- Coverage 82.6% 82.6% -0.1%
=========================================
Files 437 438 +1
Lines 122557 122640 +83
=========================================
+ Hits 101309 101326 +17
- Misses 21248 21314 +66 |
Looks good, we need to decide on compute cost. |
@s-medvedev are you able to provide benchmarks for the bpf and the native cases? (probably one step of what you need to estimate the compute cost) Separately, as far as I know libsecp256k1 doesn't use assembly. This could mean it's 1.2-2x slower than an optimised implementation. If this is a concern. |
We compare bpf implementation and native implementation via syscall. The both implementation use libsecp256k1 library.
@jon-chuang Yes, you are right. libsecp256k1 performs this operation very slowly. We compare alternative libraries and get next results:
Note: Core Intel i7-7700HQ used for measurements To determine the cost regardless of computer performance, we decided to compare the time to compute You can see benchmark code in neonlabsorg/Solana-EVM#73 |
sdk/program/src/secp256k1_recover.rs
Outdated
Secp256k1RecoverError::InvalidHash => 1, | ||
Secp256k1RecoverError::InvalidRecoveryId => 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't match to From<u64> for Secp256k1RecoverError
. is it intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not intentional. Fixed.
Alternatively, we can introduce another special native program like This assumes the given signature is deterministic at the time of transaction (I think so?) and there needs some way to pass the recovered public key from the |
My understanding is that in this use case |
@s-medvedev Does switching from libsecp256k1 to secp256k1 require any api changes that might prevent us from switching the underlying implementation between the two later? |
@jackcmay Yes that's right. Solidity contracts can use the ecrecover function and pass any information to it. Uniswap contracts use this functionality. |
@jackcmay These two libraries differ slightly in interface, but nothing critical. The ecrecover system call can be implemented using these libraries without changing the interface. |
@s-medvedev Want to resolve the conflicts and get us to all green for merge? |
@s-medvedev , separately, would you mind sharing with me the bpf secp crate? I'd like to get the wallclock results when |
We used the
|
I see, thanks @s-medvedev . I am guessing it was most likely run with JIT, as without JIT, for an ed25519 scalar mul, I was getting 1s and above. |
I suspect this was due to rw data in the crate |
Co-authored-by: Anton Lisanin <lisanin.anton@gmail.com> (cherry picked from commit 1f288ce) # Conflicts: # Cargo.lock # programs/bpf/Cargo.lock # programs/bpf/tests/programs.rs # programs/bpf_loader/Cargo.toml # programs/bpf_loader/src/syscalls.rs # sdk/program/Cargo.toml
Co-authored-by: Anton Lisanin <lisanin.anton@gmail.com> (cherry picked from commit 1f288ce) # Conflicts: # Cargo.lock # programs/bpf/Cargo.lock # programs/bpf/tests/programs.rs # programs/bpf_loader/Cargo.toml # programs/bpf_loader/src/syscalls.rs # sdk/program/Cargo.toml
* Add ecrecover syscall (#17720) Co-authored-by: Anton Lisanin <lisanin.anton@gmail.com> (cherry picked from commit 1f288ce) # Conflicts: # Cargo.lock # programs/bpf/Cargo.lock # programs/bpf/tests/programs.rs # programs/bpf_loader/Cargo.toml # programs/bpf_loader/src/syscalls.rs # sdk/program/Cargo.toml * resolve conflicts Co-authored-by: s-medvedev <40623263+s-medvedev@users.noreply.github.com> Co-authored-by: Jack May <jack@solana.com>
Problem
The EVM implementation requires an
ecrecover
function, but its computation in the BPF code requires too many instructions (6 million).Summary of Changes
Implement an
ecrecover
system call.Fixes #