Skip to content

Commit

Permalink
improve precompile failure logging
Browse files Browse the repository at this point in the history
This gets rid of the clippy warning, and will make actor debug logs a
bit more readable.
  • Loading branch information
Stebalien committed Dec 5, 2024
1 parent 649f09a commit edc966a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions actors/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fil_actors_evm_shared = { workspace = true }
hex = { workspace = true }
hex-literal = { workspace = true }
substrate-bn = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
hex = { workspace = true, features = ["serde"] }
Expand Down
9 changes: 8 additions & 1 deletion actors/evm/shared/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ impl From<U256> for EthAddress {
}
}

impl std::fmt::Debug for EthAddress {
impl std::fmt::Display for EthAddress {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("0x")?;
f.write_str(&hex::encode(self.0))
}
}

impl std::fmt::Debug for EthAddress {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self)
}
}

impl From<EthAddress> for Address {
fn from(addr: EthAddress) -> Self {
From::from(&addr)
Expand Down
2 changes: 1 addition & 1 deletion actors/evm/src/interpreter/instructions/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub fn call_generic<RT: Runtime>(
match precompiles::Precompiles::call_precompile(system, &dst, input_data, context) {
Ok(return_data) => (1, return_data),
Err(err) => {
log::warn!(target: "evm", "Precompile failed: error {:?}", err);
log::warn!(target: "evm", "call to precompile {} failed: {}", &dst, err);
// precompile failed, exit with reverted and no output
(0, vec![])
}
Expand Down
9 changes: 8 additions & 1 deletion actors/evm/src/interpreter/precompiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use fil_actors_evm_shared::{address::EthAddress, uints::U256};
use fil_actors_runtime::{runtime::Runtime, ActorError};
use fvm_shared::{address::Address, econ::TokenAmount};
use substrate_bn::{CurveError, FieldError, GroupError};
use thiserror::Error;

use crate::reader::OverflowError;

Expand Down Expand Up @@ -111,15 +112,21 @@ impl<RT: Runtime> Precompiles<RT> {
}
}

#[derive(Debug)]
#[derive(Debug, Error)]
pub enum PrecompileError {
// EVM precompile errors
#[error("EC curve error in data passed to precompile: {0:?}")]
EcErr(CurveError),
#[error("incorrect input size to precompile")]
IncorrectInputSize,
// FVM precompile errors
#[error("invalid input to precompile")]
InvalidInput,
#[error("calling convention forbidden for precompile")]
CallForbidden,
#[error("transfering funds to precompile failed")]
TransferFailed,
#[error("internal evm error when calling precompile: {0}")]
VMError(ActorError),
}

Expand Down

0 comments on commit edc966a

Please sign in to comment.