Skip to content
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

feat: makes revm sp1 compatible through feature controlling #84

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 6 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions crates/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion crates/precompile/src/bls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
Expand Down
4 changes: 2 additions & 2 deletions crates/precompile/src/cometbft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
Expand Down Expand Up @@ -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());
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compatibility for 32-bit system, risv32 running panic for this line due to mismatch len

output[32..].copy_from_slice(consensus_state_bytes.as_ref());
Bytes::from(output)
}
Expand Down
14 changes: 11 additions & 3 deletions crates/precompile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd better remove this to keep deps clean


#[macro_use]
#[cfg(not(feature = "std"))]
Expand All @@ -23,10 +25,12 @@ pub mod secp256k1;
pub mod secp256r1;
pub mod utilities;

mod bls;
mod cometbft;
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;
Expand Down Expand Up @@ -182,6 +186,7 @@ impl Precompiles {
static INSTANCE: OnceBox<Precompiles> = 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,
Expand All @@ -196,6 +201,7 @@ impl Precompiles {
static INSTANCE: OnceBox<Precompiles> = 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,
Expand All @@ -210,6 +216,7 @@ impl Precompiles {
static INSTANCE: OnceBox<Precompiles> = 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,
Expand Down Expand Up @@ -238,6 +245,7 @@ impl Precompiles {
static INSTANCE: OnceBox<Precompiles> = 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)
Expand All @@ -263,7 +271,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)
Expand Down
4 changes: 2 additions & 2 deletions crates/precompile/src/tendermint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use tendermint::lite::light_client;
/// Tendermint precompile for 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.
Expand Down
2 changes: 2 additions & 0 deletions crates/precompile/src/tm_secp256k1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused_imports)]
#![allow(dead_code)]
use crate::{Bytes, Error, Precompile, PrecompileError, PrecompileResult, PrecompileWithAddress};
use revm_primitives::PrecompileOutput;
use secp256k1::{ecdsa, Message, PublicKey};
Expand Down
Loading