Skip to content

Commit

Permalink
add check for bsc precompile
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonberg1997 committed Jun 11, 2024
1 parent 54cb759 commit 29a08a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/precompile/src/bls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn bls_signature_validation_run(input: &Bytes, gas_limit: u64) -> PrecompileResu
let pub_keys_data = &input[msg_and_sig_length as usize..].to_vec();

// check signature format
if let Err(_) = bls::signature_to_point(&signature.to_vec()) {
if bls::signature_to_point(&signature.to_vec()).is_err() {
return Ok((cost, Bytes::default()));
}

Expand Down
11 changes: 10 additions & 1 deletion crates/revm/src/context/evm_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use core::{
fmt,
ops::{Deref, DerefMut},
};
use revm_precompile::u64_to_address;
use std::boxed::Box;

/// EVM context that contains the inner EVM context and precompiles.
Expand Down Expand Up @@ -123,7 +124,7 @@ impl<DB: Database> EvmContext<DB> {
if result.gas.record_cost(gas_used) {
// to keep align with bsc, revert if data is empty.
// revert will not cost all gas
if data.is_empty() {
if is_bsc_precompile(address) && data.is_empty() {
result.result = InstructionResult::Revert;
} else {
result.result = InstructionResult::Return;
Expand Down Expand Up @@ -226,6 +227,14 @@ impl<DB: Database> EvmContext<DB> {
}
}

// Helper to check if the address is some specific bsc precompile address.
fn is_bsc_precompile(address: Address) -> bool {
let bls_sig_validation = u64_to_address(102);
let double_sign_evidence_validation = u64_to_address(104);

address == bls_sig_validation || address == double_sign_evidence_validation
}

/// Test utilities for the [`EvmContext`].
#[cfg(any(test, feature = "test-utils"))]
pub(crate) mod test_utils {
Expand Down

0 comments on commit 29a08a3

Please sign in to comment.