From 52c7199694b7f86f64cb37c91c5a17c72088f0cc Mon Sep 17 00:00:00 2001 From: ZhAnGeek Date: Wed, 6 Nov 2024 16:04:30 +0800 Subject: [PATCH 1/5] feat: makes revm sp1 compatible through feature controlling --- Cargo.lock | 32 +++++---------------------- crates/precompile/Cargo.toml | 12 +++++----- crates/precompile/src/bls.rs | 2 +- crates/precompile/src/cometbft.rs | 2 +- crates/precompile/src/iavl.rs | 15 +++++++++++++ crates/precompile/src/lib.rs | 10 ++++++--- crates/precompile/src/tendermint.rs | 6 +++++ crates/precompile/src/tm_secp256k1.rs | 6 +++++ 8 files changed, 48 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d0d004c2..0a70a6e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1104,7 +1104,7 @@ checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" [[package]] name = "cometbft" version = "0.1.0-alpha.2" -source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=1282547#12825470f8b2df8e960e39a84ad4c9921492f512" +source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=5582327#558232788fca6ade6ae2e16a7557af1982105c4f" dependencies = [ "bytes 1.7.1", "cometbft-proto", @@ -1112,7 +1112,6 @@ dependencies = [ "ed25519 2.2.3", "ed25519-consensus", "flex-error", - "futures", "num-traits", "once_cell", "prost 0.12.6", @@ -1132,7 +1131,7 @@ dependencies = [ [[package]] name = "cometbft-config" version = "0.1.0-alpha.2" -source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=1282547#12825470f8b2df8e960e39a84ad4c9921492f512" +source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=5582327#558232788fca6ade6ae2e16a7557af1982105c4f" dependencies = [ "cometbft", "flex-error", @@ -1145,7 +1144,7 @@ dependencies = [ [[package]] name = "cometbft-light-client" version = "0.1.0-alpha.2" -source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=1282547#12825470f8b2df8e960e39a84ad4c9921492f512" +source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=5582327#558232788fca6ade6ae2e16a7557af1982105c4f" dependencies = [ "cometbft", "cometbft-light-client-verifier", @@ -1154,7 +1153,6 @@ dependencies = [ "crossbeam-channel", "derive_more 0.99.18", "flex-error", - "futures", "regex", "serde", "serde_cbor", @@ -1162,14 +1160,13 @@ dependencies = [ "serde_json", "static_assertions", "time", - "tokio", "tracing", ] [[package]] name = "cometbft-light-client-verifier" version = "0.1.0-alpha.2" -source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=1282547#12825470f8b2df8e960e39a84ad4c9921492f512" +source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=5582327#558232788fca6ade6ae2e16a7557af1982105c4f" dependencies = [ "cometbft", "derive_more 0.99.18", @@ -1181,7 +1178,7 @@ dependencies = [ [[package]] name = "cometbft-proto" version = "0.1.0-alpha.2" -source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=1282547#12825470f8b2df8e960e39a84ad4c9921492f512" +source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=5582327#558232788fca6ade6ae2e16a7557af1982105c4f" dependencies = [ "bytes 1.7.1", "flex-error", @@ -1198,7 +1195,7 @@ dependencies = [ [[package]] name = "cometbft-rpc" version = "0.1.0-alpha.2" -source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=1282547#12825470f8b2df8e960e39a84ad4c9921492f512" +source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=5582327#558232788fca6ade6ae2e16a7557af1982105c4f" dependencies = [ "async-trait", "bytes 1.7.1", @@ -1206,12 +1203,10 @@ dependencies = [ "cometbft-config", "cometbft-proto", "flex-error", - "futures", "getrandom 0.2.15", "peg", "pin-project", "rand 0.8.5", - "reqwest 0.11.27", "semver 1.0.23", "serde", "serde_bytes", @@ -1220,8 +1215,6 @@ dependencies = [ "subtle-encoding", "thiserror", "time", - "tokio", - "tracing", "url", "uuid", "walkdir", @@ -3812,7 +3805,6 @@ dependencies = [ "percent-encoding", "pin-project-lite", "rustls 0.21.12", - "rustls-native-certs", "rustls-pemfile 1.0.4", "serde", "serde_json", @@ -4232,18 +4224,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "rustls-native-certs" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" -dependencies = [ - "openssl-probe", - "rustls-pemfile 1.0.4", - "schannel", - "security-framework", -] - [[package]] name = "rustls-pemfile" version = "1.0.4" diff --git a/crates/precompile/Cargo.toml b/crates/precompile/Cargo.toml index 1b89d4f3..ed455c04 100644 --- a/crates/precompile/Cargo.toml +++ b/crates/precompile/Cargo.toml @@ -38,13 +38,13 @@ secp256k1 = { version = ">=0.28, <=0.29", default-features = false, features = [ "rand", "global-context", ], optional = true } -cometbft = { git = "https://github.com/bnb-chain/greenfield-cometbft-rs.git", rev = "1282547" } -cometbft-light-client-verifier = { git = "https://github.com/bnb-chain/greenfield-cometbft-rs.git", rev = "1282547" } -cometbft-proto = { git = "https://github.com/bnb-chain/greenfield-cometbft-rs.git", rev = "1282547" } -cometbft-light-client = { git = "https://github.com/bnb-chain/greenfield-cometbft-rs.git", rev = "1282547" } +cometbft = { git = "https://github.com/bnb-chain/greenfield-cometbft-rs.git", rev = "5582327" } +cometbft-light-client-verifier = { git = "https://github.com/bnb-chain/greenfield-cometbft-rs.git", rev = "5582327" } +cometbft-proto = { git = "https://github.com/bnb-chain/greenfield-cometbft-rs.git", rev = "5582327" } +cometbft-light-client = { git = "https://github.com/bnb-chain/greenfield-cometbft-rs.git", rev = "5582327", default-features = false } prost = { version = "0.12.6" } bls_on_arkworks = "0.3.0" -tendermint = { git = "https://github.com/bnb-chain/tendermint-rs-parlia", rev = "8c21ccbd58a174e07eed2c9343e63ccd00f0fbd5", features = ["secp256k1"] } +tendermint = { git = "https://github.com/bnb-chain/tendermint-rs-parlia", rev = "8c21ccbd58a174e07eed2c9343e63ccd00f0fbd5", optional = true, features = ["secp256k1"] } parity-bytes = { version = "0.1.2", default-features = false } # SHA2-256 and RIPEMD-160 @@ -99,7 +99,7 @@ std = [ hashbrown = ["revm-primitives/hashbrown"] asm-keccak = ["revm-primitives/asm-keccak"] -bsc = ["revm-primitives/bsc", "secp256k1", "secp256r1"] +bsc = ["revm-primitives/bsc", "secp256k1", "secp256r1", "tendermint"] optimism = ["revm-primitives/optimism", "secp256r1"] # Optimism default handler enabled Optimism handler register by default in EvmBuilder. diff --git a/crates/precompile/src/bls.rs b/crates/precompile/src/bls.rs index 6e5bebba..b68d5699 100644 --- a/crates/precompile/src/bls.rs +++ b/crates/precompile/src/bls.rs @@ -3,7 +3,7 @@ use bls_on_arkworks as bls; use revm_primitives::{Bytes, PrecompileOutput}; use std::vec::Vec; -pub(crate) const BLS_SIGNATURE_VALIDATION: PrecompileWithAddress = PrecompileWithAddress( +pub const BLS_SIGNATURE_VALIDATION: PrecompileWithAddress = PrecompileWithAddress( crate::u64_to_address(102), Precompile::Standard(bls_signature_validation_run), ); diff --git a/crates/precompile/src/cometbft.rs b/crates/precompile/src/cometbft.rs index 52f3f6ad..a76187e3 100644 --- a/crates/precompile/src/cometbft.rs +++ b/crates/precompile/src/cometbft.rs @@ -14,7 +14,7 @@ use prost::Message; use revm_primitives::{Bytes, PrecompileOutput}; use std::{borrow::ToOwned, string::String, vec::Vec}; -pub(crate) const COMETBFT_LIGHT_BLOCK_VALIDATION: PrecompileWithAddress = PrecompileWithAddress( +pub const COMETBFT_LIGHT_BLOCK_VALIDATION: PrecompileWithAddress = PrecompileWithAddress( crate::u64_to_address(103), Precompile::Standard(cometbft_light_block_validation_run), ); diff --git a/crates/precompile/src/iavl.rs b/crates/precompile/src/iavl.rs index 47593ab5..c9056414 100644 --- a/crates/precompile/src/iavl.rs +++ b/crates/precompile/src/iavl.rs @@ -1,8 +1,10 @@ #![allow(dead_code)] +#![allow(unused_imports)] use crate::{Bytes, Error, Precompile, PrecompileError, PrecompileResult, PrecompileWithAddress}; use parity_bytes::BytesRef; use revm_primitives::PrecompileOutput; +#[cfg(feature = "bsc")] use tendermint::lite::iavl_proof; /// Iavl proof validation precompile for BSC. @@ -61,6 +63,7 @@ fn iavl_proof_validation_run_plato(input: &Bytes, gas_limit: u64) -> PrecompileR } /// Run Iavl proof validation with given hardfork toggles. +#[cfg(feature = "bsc")] fn iavl_proof_validation_run_inner( input: &Bytes, gas_limit: u64, @@ -86,7 +89,19 @@ fn iavl_proof_validation_run_inner( } } +#[cfg(not(feature = "bsc"))] +fn iavl_proof_validation_run_inner( + _input: &Bytes, + _gas_limit: u64, + _is_moran: bool, + _is_planck: bool, + _is_plato: bool, +) -> PrecompileResult { + Err(PrecompileError::other("suspended").into()) +} + #[cfg(test)] +#[cfg(feature = "bsc")] mod tests { use super::*; use revm_primitives::hex; diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index ec297fdd..5cd4234a 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -3,6 +3,7 @@ //! Implementations of EVM precompiled contracts. #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(not(feature = "std"), no_std)] +#![allow(unused_mut)] #[macro_use] #[cfg(not(feature = "std"))] @@ -23,8 +24,8 @@ pub mod secp256k1; pub mod secp256r1; pub mod utilities; -mod bls; -mod cometbft; +pub mod bls; +pub mod cometbft; mod double_sign; mod iavl; mod tendermint; @@ -182,6 +183,7 @@ impl Precompiles { static INSTANCE: OnceBox = OnceBox::new(); INSTANCE.get_or_init(|| { let mut precompiles = Self::istanbul().clone(); + #[cfg(feature = "bsc")] precompiles.extend([ tendermint::TENDERMINT_HEADER_VALIDATION_NANO, iavl::IAVL_PROOF_VALIDATION_NANO, @@ -196,6 +198,7 @@ impl Precompiles { static INSTANCE: OnceBox = OnceBox::new(); INSTANCE.get_or_init(|| { let mut precompiles = Self::istanbul().clone(); + #[cfg(feature = "bsc")] precompiles.extend([ tendermint::TENDERMINT_HEADER_VALIDATION, iavl::IAVL_PROOF_VALIDATION_MORAN, @@ -210,6 +213,7 @@ impl Precompiles { static INSTANCE: OnceBox = OnceBox::new(); INSTANCE.get_or_init(|| { let mut precompiles = Self::istanbul().clone(); + #[cfg(feature = "bsc")] precompiles.extend([ tendermint::TENDERMINT_HEADER_VALIDATION, iavl::IAVL_PROOF_VALIDATION_PLANCK, @@ -263,7 +267,7 @@ impl Precompiles { precompiles.extend([double_sign::DOUBLE_SIGN_EVIDENCE_VALIDATION]); // this feature is enabled with bsc - #[cfg(feature = "secp256k1")] + #[cfg(all(feature = "secp256k1", feature = "bsc"))] precompiles.extend([tm_secp256k1::TM_SECP256K1_SIGNATURE_RECOVER]); Box::new(precompiles) diff --git a/crates/precompile/src/tendermint.rs b/crates/precompile/src/tendermint.rs index 01289472..e8075ddf 100644 --- a/crates/precompile/src/tendermint.rs +++ b/crates/precompile/src/tendermint.rs @@ -1,9 +1,13 @@ +#![allow(unused_imports)] +#![allow(dead_code)] use crate::{Bytes, Error, Precompile, PrecompileError, PrecompileResult, PrecompileWithAddress}; use parity_bytes::BytesRef; use revm_primitives::PrecompileOutput; +#[cfg(feature = "bsc")] use tendermint::lite::light_client; /// Tendermint precompile for BSC. +#[cfg(feature = "bsc")] pub(crate) const TENDERMINT_HEADER_VALIDATION: PrecompileWithAddress = PrecompileWithAddress( crate::u64_to_address(100), Precompile::Standard(crate::tendermint::tendermint_header_validation_run), @@ -21,6 +25,7 @@ fn tendermint_header_validation_run_nano(_input: &Bytes, _gas_limit: u64) -> Pre } /// Run the Tendermint header validation precompile. +#[cfg(feature = "bsc")] fn tendermint_header_validation_run(input: &Bytes, gas_limit: u64) -> PrecompileResult { const TENDERMINT_HEADER_VALIDATION_BASE: u64 = 3_000; @@ -41,6 +46,7 @@ fn tendermint_header_validation_run(input: &Bytes, gas_limit: u64) -> Precompile } #[cfg(test)] +#[cfg(feature = "bsc")] mod tests { use super::*; use revm_primitives::hex; diff --git a/crates/precompile/src/tm_secp256k1.rs b/crates/precompile/src/tm_secp256k1.rs index e06cfa9b..3874b184 100644 --- a/crates/precompile/src/tm_secp256k1.rs +++ b/crates/precompile/src/tm_secp256k1.rs @@ -1,9 +1,13 @@ +#![allow(unused_imports)] +#![allow(dead_code)] use crate::{Bytes, Error, Precompile, PrecompileError, PrecompileResult, PrecompileWithAddress}; use revm_primitives::PrecompileOutput; use secp256k1::{ecdsa, Message, PublicKey}; +#[cfg(feature = "bsc")] use tendermint::{account, public_key}; /// Tendermint SECP256K1 signature recover precompile for BSC. +#[cfg(feature = "bsc")] pub(crate) const TM_SECP256K1_SIGNATURE_RECOVER: PrecompileWithAddress = PrecompileWithAddress( crate::u64_to_address(105), Precompile::Standard(tm_secp256k1_signature_recover_run), @@ -20,6 +24,7 @@ const SECP256K1_SIGNATURE_MSGHASH_LENGTH: usize = 32; /// | PubKey | Signature | SignatureMsgHash | /// /// | 33 bytes | 64 bytes | 32 bytes | +#[cfg(feature = "bsc")] fn tm_secp256k1_signature_recover_run(input: &Bytes, gas_limit: u64) -> PrecompileResult { const TM_SECP256K1_SIGNATURE_RECOVER_BASE: u64 = 3_000; @@ -71,6 +76,7 @@ fn tm_secp256k1_signature_recover_run(input: &Bytes, gas_limit: u64) -> Precompi } #[cfg(test)] +#[cfg(feature = "bsc")] mod tests { use super::*; use revm_primitives::hex; From 96c8eeecfc2d30a0df77452af2e5720c75815be5 Mon Sep 17 00:00:00 2001 From: Roshan Date: Wed, 6 Nov 2024 19:40:30 +0800 Subject: [PATCH 2/5] test: update feature control --- crates/precompile/src/iavl.rs | 15 --------------- crates/precompile/src/lib.rs | 3 ++- crates/precompile/src/tendermint.rs | 10 ++-------- 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/crates/precompile/src/iavl.rs b/crates/precompile/src/iavl.rs index c9056414..47593ab5 100644 --- a/crates/precompile/src/iavl.rs +++ b/crates/precompile/src/iavl.rs @@ -1,10 +1,8 @@ #![allow(dead_code)] -#![allow(unused_imports)] use crate::{Bytes, Error, Precompile, PrecompileError, PrecompileResult, PrecompileWithAddress}; use parity_bytes::BytesRef; use revm_primitives::PrecompileOutput; -#[cfg(feature = "bsc")] use tendermint::lite::iavl_proof; /// Iavl proof validation precompile for BSC. @@ -63,7 +61,6 @@ fn iavl_proof_validation_run_plato(input: &Bytes, gas_limit: u64) -> PrecompileR } /// Run Iavl proof validation with given hardfork toggles. -#[cfg(feature = "bsc")] fn iavl_proof_validation_run_inner( input: &Bytes, gas_limit: u64, @@ -89,19 +86,7 @@ fn iavl_proof_validation_run_inner( } } -#[cfg(not(feature = "bsc"))] -fn iavl_proof_validation_run_inner( - _input: &Bytes, - _gas_limit: u64, - _is_moran: bool, - _is_planck: bool, - _is_plato: bool, -) -> PrecompileResult { - Err(PrecompileError::other("suspended").into()) -} - #[cfg(test)] -#[cfg(feature = "bsc")] mod tests { use super::*; use revm_primitives::hex; diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index 5cd4234a..7d56bcbb 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -3,7 +3,6 @@ //! Implementations of EVM precompiled contracts. #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(not(feature = "std"), no_std)] -#![allow(unused_mut)] #[macro_use] #[cfg(not(feature = "std"))] @@ -27,7 +26,9 @@ pub mod utilities; pub mod bls; pub mod cometbft; mod double_sign; +#[cfg(feature = "bsc")] mod iavl; +#[cfg(feature = "bsc")] mod tendermint; #[cfg(feature = "secp256k1")] mod tm_secp256k1; diff --git a/crates/precompile/src/tendermint.rs b/crates/precompile/src/tendermint.rs index e8075ddf..9e46e8c0 100644 --- a/crates/precompile/src/tendermint.rs +++ b/crates/precompile/src/tendermint.rs @@ -1,22 +1,18 @@ -#![allow(unused_imports)] -#![allow(dead_code)] use crate::{Bytes, Error, Precompile, PrecompileError, PrecompileResult, PrecompileWithAddress}; use parity_bytes::BytesRef; use revm_primitives::PrecompileOutput; -#[cfg(feature = "bsc")] use tendermint::lite::light_client; /// Tendermint precompile for BSC. -#[cfg(feature = "bsc")] pub(crate) const TENDERMINT_HEADER_VALIDATION: PrecompileWithAddress = PrecompileWithAddress( crate::u64_to_address(100), - Precompile::Standard(crate::tendermint::tendermint_header_validation_run), + Precompile::Standard(tendermint_header_validation_run), ); /// Tendermint precompile for BSC after Nano hardfork. pub(crate) const TENDERMINT_HEADER_VALIDATION_NANO: PrecompileWithAddress = PrecompileWithAddress( crate::u64_to_address(100), - Precompile::Standard(crate::tendermint::tendermint_header_validation_run_nano), + Precompile::Standard(tendermint_header_validation_run_nano), ); /// Run the Tendermint header validation precompile after Nano hardfork. @@ -25,7 +21,6 @@ fn tendermint_header_validation_run_nano(_input: &Bytes, _gas_limit: u64) -> Pre } /// Run the Tendermint header validation precompile. -#[cfg(feature = "bsc")] fn tendermint_header_validation_run(input: &Bytes, gas_limit: u64) -> PrecompileResult { const TENDERMINT_HEADER_VALIDATION_BASE: u64 = 3_000; @@ -46,7 +41,6 @@ fn tendermint_header_validation_run(input: &Bytes, gas_limit: u64) -> Precompile } #[cfg(test)] -#[cfg(feature = "bsc")] mod tests { use super::*; use revm_primitives::hex; From 4197e855127b8d155fa87ae7a37633ac63481772 Mon Sep 17 00:00:00 2001 From: ZhAnGeek Date: Fri, 8 Nov 2024 09:21:14 +0800 Subject: [PATCH 3/5] fix: precompile issue for risv32 bytes len array --- crates/precompile/src/cometbft.rs | 2 +- crates/precompile/src/lib.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/precompile/src/cometbft.rs b/crates/precompile/src/cometbft.rs index a76187e3..98db6a72 100644 --- a/crates/precompile/src/cometbft.rs +++ b/crates/precompile/src/cometbft.rs @@ -408,7 +408,7 @@ fn encode_light_block_validation_result( let mut output = vec![0; (VALIDATE_RESULT_METADATA_LENGTH + consensus_state_bytes.len() as u64) as usize]; output[0] = if validator_set_changed { 1 } else { 0 }; - output[24..32].copy_from_slice(consensus_state_bytes.len().to_be_bytes().as_ref()); + output[24..32].copy_from_slice((consensus_state_bytes.len() as u64).to_be_bytes().as_ref()); output[32..].copy_from_slice(consensus_state_bytes.as_ref()); Bytes::from(output) } diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index 7d56bcbb..cf61f3db 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -243,6 +243,7 @@ impl Precompiles { static INSTANCE: OnceBox = OnceBox::new(); INSTANCE.get_or_init(|| { let mut precompiles = Self::luban().clone(); + #[cfg(feature = "bsc")] precompiles.extend([iavl::IAVL_PROOF_VALIDATION_PLATO]); Box::new(precompiles) From b8d59fa899701a233131c183423c649b22874dbe Mon Sep 17 00:00:00 2001 From: ZhAnGeek Date: Mon, 11 Nov 2024 15:44:52 +0800 Subject: [PATCH 4/5] feat: optimize dep --- crates/precompile/Cargo.toml | 2 +- crates/precompile/src/lib.rs | 2 ++ crates/precompile/src/tm_secp256k1.rs | 4 ---- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/precompile/Cargo.toml b/crates/precompile/Cargo.toml index ed455c04..d1ab327c 100644 --- a/crates/precompile/Cargo.toml +++ b/crates/precompile/Cargo.toml @@ -126,7 +126,7 @@ portable = ["revm-primitives/portable", "c-kzg?/portable"] # Use `secp256k1` as a faster alternative to `k256`. # The problem that `secp256k1` has is it fails to build for `wasm` target on Windows and Mac as it is c lib. # In Linux it passes. If you don't require to build wasm on win/mac, it is safe to use it and it is enabled by default. -secp256k1 = ["dep:secp256k1"] +secp256k1 = ["dep:secp256k1", "tendermint"] # Enables the BLS12-381 precompiles. blst = ["dep:blst"] diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index cf61f3db..bd4d3354 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -3,6 +3,8 @@ //! Implementations of EVM precompiled contracts. #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(not(feature = "std"), no_std)] +#![allow(unused_mut)] +#![allow(unused_crate_dependencies)] #[macro_use] #[cfg(not(feature = "std"))] diff --git a/crates/precompile/src/tm_secp256k1.rs b/crates/precompile/src/tm_secp256k1.rs index 3874b184..955d825b 100644 --- a/crates/precompile/src/tm_secp256k1.rs +++ b/crates/precompile/src/tm_secp256k1.rs @@ -3,11 +3,9 @@ use crate::{Bytes, Error, Precompile, PrecompileError, PrecompileResult, PrecompileWithAddress}; use revm_primitives::PrecompileOutput; use secp256k1::{ecdsa, Message, PublicKey}; -#[cfg(feature = "bsc")] use tendermint::{account, public_key}; /// Tendermint SECP256K1 signature recover precompile for BSC. -#[cfg(feature = "bsc")] pub(crate) const TM_SECP256K1_SIGNATURE_RECOVER: PrecompileWithAddress = PrecompileWithAddress( crate::u64_to_address(105), Precompile::Standard(tm_secp256k1_signature_recover_run), @@ -24,7 +22,6 @@ const SECP256K1_SIGNATURE_MSGHASH_LENGTH: usize = 32; /// | PubKey | Signature | SignatureMsgHash | /// /// | 33 bytes | 64 bytes | 32 bytes | -#[cfg(feature = "bsc")] fn tm_secp256k1_signature_recover_run(input: &Bytes, gas_limit: u64) -> PrecompileResult { const TM_SECP256K1_SIGNATURE_RECOVER_BASE: u64 = 3_000; @@ -76,7 +73,6 @@ fn tm_secp256k1_signature_recover_run(input: &Bytes, gas_limit: u64) -> Precompi } #[cfg(test)] -#[cfg(feature = "bsc")] mod tests { use super::*; use revm_primitives::hex; From 3dff0d37f05e9caffff5b805906c2675ec0060e2 Mon Sep 17 00:00:00 2001 From: ZhAnGeek Date: Tue, 12 Nov 2024 19:23:57 +0800 Subject: [PATCH 5/5] fix: removed unneccesary global mark --- Cargo.lock | 12 +++--- crates/precompile/Cargo.toml | 12 +++--- crates/precompile/src/lib.rs | 55 ++++++++++++++++++--------- crates/precompile/src/tm_secp256k1.rs | 3 +- 4 files changed, 50 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0a70a6e9..15280c2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1104,7 +1104,7 @@ checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" [[package]] name = "cometbft" version = "0.1.0-alpha.2" -source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=5582327#558232788fca6ade6ae2e16a7557af1982105c4f" +source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=ccf58da#ccf58dabac222c7950aa52d8b700fc61beb9ae7f" dependencies = [ "bytes 1.7.1", "cometbft-proto", @@ -1131,7 +1131,7 @@ dependencies = [ [[package]] name = "cometbft-config" version = "0.1.0-alpha.2" -source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=5582327#558232788fca6ade6ae2e16a7557af1982105c4f" +source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=ccf58da#ccf58dabac222c7950aa52d8b700fc61beb9ae7f" dependencies = [ "cometbft", "flex-error", @@ -1144,7 +1144,7 @@ dependencies = [ [[package]] name = "cometbft-light-client" version = "0.1.0-alpha.2" -source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=5582327#558232788fca6ade6ae2e16a7557af1982105c4f" +source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=ccf58da#ccf58dabac222c7950aa52d8b700fc61beb9ae7f" dependencies = [ "cometbft", "cometbft-light-client-verifier", @@ -1166,7 +1166,7 @@ dependencies = [ [[package]] name = "cometbft-light-client-verifier" version = "0.1.0-alpha.2" -source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=5582327#558232788fca6ade6ae2e16a7557af1982105c4f" +source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=ccf58da#ccf58dabac222c7950aa52d8b700fc61beb9ae7f" dependencies = [ "cometbft", "derive_more 0.99.18", @@ -1178,7 +1178,7 @@ dependencies = [ [[package]] name = "cometbft-proto" version = "0.1.0-alpha.2" -source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=5582327#558232788fca6ade6ae2e16a7557af1982105c4f" +source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=ccf58da#ccf58dabac222c7950aa52d8b700fc61beb9ae7f" dependencies = [ "bytes 1.7.1", "flex-error", @@ -1195,7 +1195,7 @@ dependencies = [ [[package]] name = "cometbft-rpc" version = "0.1.0-alpha.2" -source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=5582327#558232788fca6ade6ae2e16a7557af1982105c4f" +source = "git+https://github.com/bnb-chain/greenfield-cometbft-rs.git?rev=ccf58da#ccf58dabac222c7950aa52d8b700fc61beb9ae7f" dependencies = [ "async-trait", "bytes 1.7.1", diff --git a/crates/precompile/Cargo.toml b/crates/precompile/Cargo.toml index d1ab327c..27b5078f 100644 --- a/crates/precompile/Cargo.toml +++ b/crates/precompile/Cargo.toml @@ -38,14 +38,14 @@ secp256k1 = { version = ">=0.28, <=0.29", default-features = false, features = [ "rand", "global-context", ], optional = true } -cometbft = { git = "https://github.com/bnb-chain/greenfield-cometbft-rs.git", rev = "5582327" } -cometbft-light-client-verifier = { git = "https://github.com/bnb-chain/greenfield-cometbft-rs.git", rev = "5582327" } -cometbft-proto = { git = "https://github.com/bnb-chain/greenfield-cometbft-rs.git", rev = "5582327" } -cometbft-light-client = { git = "https://github.com/bnb-chain/greenfield-cometbft-rs.git", rev = "5582327", default-features = false } +cometbft = { git = "https://github.com/bnb-chain/greenfield-cometbft-rs.git", rev = "ccf58da" } +cometbft-light-client-verifier = { git = "https://github.com/bnb-chain/greenfield-cometbft-rs.git", rev = "ccf58da" } +cometbft-proto = { git = "https://github.com/bnb-chain/greenfield-cometbft-rs.git", rev = "ccf58da" } +cometbft-light-client = { git = "https://github.com/bnb-chain/greenfield-cometbft-rs.git", rev = "ccf58da", default-features = false } prost = { version = "0.12.6" } bls_on_arkworks = "0.3.0" tendermint = { git = "https://github.com/bnb-chain/tendermint-rs-parlia", rev = "8c21ccbd58a174e07eed2c9343e63ccd00f0fbd5", optional = true, features = ["secp256k1"] } -parity-bytes = { version = "0.1.2", default-features = false } +parity-bytes = { version = "0.1.2", default-features = false, optional = true } # SHA2-256 and RIPEMD-160 sha2 = { version = "0.10", default-features = false } @@ -99,7 +99,7 @@ std = [ hashbrown = ["revm-primitives/hashbrown"] asm-keccak = ["revm-primitives/asm-keccak"] -bsc = ["revm-primitives/bsc", "secp256k1", "secp256r1", "tendermint"] +bsc = ["revm-primitives/bsc", "secp256k1", "secp256r1", "tendermint", "parity-bytes"] optimism = ["revm-primitives/optimism", "secp256r1"] # Optimism default handler enabled Optimism handler register by default in EvmBuilder. diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index bd4d3354..ab2a605e 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -3,8 +3,6 @@ //! Implementations of EVM precompiled contracts. #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(not(feature = "std"), no_std)] -#![allow(unused_mut)] -#![allow(unused_crate_dependencies)] #[macro_use] #[cfg(not(feature = "std"))] @@ -185,12 +183,17 @@ impl Precompiles { pub fn nano() -> &'static Self { static INSTANCE: OnceBox = OnceBox::new(); INSTANCE.get_or_init(|| { - let mut precompiles = Self::istanbul().clone(); + let precompiles = Self::istanbul().clone(); + #[cfg(feature = "bsc")] - precompiles.extend([ - tendermint::TENDERMINT_HEADER_VALIDATION_NANO, - iavl::IAVL_PROOF_VALIDATION_NANO, - ]); + let precompiles = { + let mut precompiles = precompiles; + precompiles.extend([ + tendermint::TENDERMINT_HEADER_VALIDATION_NANO, + iavl::IAVL_PROOF_VALIDATION_NANO, + ]); + precompiles + }; Box::new(precompiles) }) @@ -200,12 +203,17 @@ impl Precompiles { pub fn moran() -> &'static Self { static INSTANCE: OnceBox = OnceBox::new(); INSTANCE.get_or_init(|| { - let mut precompiles = Self::istanbul().clone(); + let precompiles = Self::istanbul().clone(); + #[cfg(feature = "bsc")] - precompiles.extend([ - tendermint::TENDERMINT_HEADER_VALIDATION, - iavl::IAVL_PROOF_VALIDATION_MORAN, - ]); + let precompiles = { + let mut precompiles = precompiles; + precompiles.extend([ + tendermint::TENDERMINT_HEADER_VALIDATION, + iavl::IAVL_PROOF_VALIDATION_MORAN, + ]); + precompiles + }; Box::new(precompiles) }) @@ -215,12 +223,17 @@ impl Precompiles { pub fn planck() -> &'static Self { static INSTANCE: OnceBox = OnceBox::new(); INSTANCE.get_or_init(|| { - let mut precompiles = Self::istanbul().clone(); + let precompiles = Self::istanbul().clone(); + #[cfg(feature = "bsc")] - precompiles.extend([ - tendermint::TENDERMINT_HEADER_VALIDATION, - iavl::IAVL_PROOF_VALIDATION_PLANCK, - ]); + let precompiles = { + let mut precompiles = precompiles; + precompiles.extend([ + tendermint::TENDERMINT_HEADER_VALIDATION, + iavl::IAVL_PROOF_VALIDATION_PLANCK, + ]); + precompiles + }; Box::new(precompiles) }) @@ -244,9 +257,13 @@ impl Precompiles { pub fn plato() -> &'static Self { static INSTANCE: OnceBox = OnceBox::new(); INSTANCE.get_or_init(|| { - let mut precompiles = Self::luban().clone(); + let precompiles = Self::luban().clone(); #[cfg(feature = "bsc")] - precompiles.extend([iavl::IAVL_PROOF_VALIDATION_PLATO]); + let precompiles = { + let mut precompiles = precompiles; + precompiles.extend([iavl::IAVL_PROOF_VALIDATION_PLATO]); + precompiles + }; Box::new(precompiles) }) diff --git a/crates/precompile/src/tm_secp256k1.rs b/crates/precompile/src/tm_secp256k1.rs index 955d825b..11db1b88 100644 --- a/crates/precompile/src/tm_secp256k1.rs +++ b/crates/precompile/src/tm_secp256k1.rs @@ -1,5 +1,6 @@ -#![allow(unused_imports)] #![allow(dead_code)] +#![cfg_attr(feature = "bsc", warn(dead_code))] + use crate::{Bytes, Error, Precompile, PrecompileError, PrecompileResult, PrecompileWithAddress}; use revm_primitives::PrecompileOutput; use secp256k1::{ecdsa, Message, PublicKey};