feat: Add dynamic crypto provider#2706
Conversation
| pub fn install_provider<P: CryptoProvider>(provider: P) -> bool { | ||
| PROVIDER.set(Box::new(Box::new(provider))).is_ok() | ||
| } |
There was a problem hiding this comment.
We can remove this global installation of the crypto backend by having the run method for precompiles take a CryptoProvider parameter and it can be installed like:
new_evm().with_crypto_provider(Box::new(CustomCryptoProvider))?And if with_crypto_provider is missing then it uses the default
There was a problem hiding this comment.
Did this way initially so it doesn't change the API
CodSpeed Performance ReportMerging #2706 will not alter performanceComparing Summary
|
| use crate::crypto_provider::bn128::{ | ||
| G1_LENGTH as G1_LEN, G2_LENGTH as G2_LEN, SCALAR_LENGTH as SCALAR_LEN, | ||
| }; |
There was a problem hiding this comment.
Doing this type alias to reduce the diff
Co-authored-by: rakita <rakita@users.noreply.github.com>
Co-authored-by: rakita <rakita@users.noreply.github.com>
Co-authored-by: rakita <rakita@users.noreply.github.com>
| /// * `pk` - The uncompressed public key (secp256r1::PUBKEY_LENGTH bytes: 0x04 || x || y) | ||
| /// | ||
| /// # Returns | ||
| /// `true` if the signature is valid, `false` otherwise. | ||
| fn secp256r1_verify( | ||
| &self, | ||
| msg: &[u8; secp256r1::MESSAGE_HASH_LENGTH], | ||
| sig: &[u8; secp256r1::SIGNATURE_LENGTH], | ||
| pk: &[u8; secp256r1::PUBKEY_LENGTH], | ||
| ) -> bool; |
| &self, | ||
| fp2_x: &[u8; bls12_381::FP_LENGTH], | ||
| fp2_y: &[u8; bls12_381::FP_LENGTH], | ||
| ) -> Result<[u8; bls12_381::G2_LENGTH], PrecompileError>; |
There was a problem hiding this comment.
Technically speaking, putting PrecompileError here and in the APIs for the cryptography code is leaking an abstraction, but I think it can be cleaned up after
|
Superceded by #2786 |
Based off of #2705
This PR includes all of the changes including code restructuring now, to show what the end goal would be. If this looks okay, then I can split this into smaller PRs.
Changes:
get_crypto_providerto returnDefaultCryptoProvider