Skip to content

Commit edc966a

Browse files
committed
improve precompile failure logging
This gets rid of the clippy warning, and will make actor debug logs a bit more readable.
1 parent 649f09a commit edc966a

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actors/evm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ fil_actors_evm_shared = { workspace = true }
3232
hex = { workspace = true }
3333
hex-literal = { workspace = true }
3434
substrate-bn = { workspace = true }
35+
thiserror = { workspace = true }
3536

3637
[dev-dependencies]
3738
hex = { workspace = true, features = ["serde"] }

actors/evm/shared/src/address.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@ impl From<U256> for EthAddress {
1919
}
2020
}
2121

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

29+
impl std::fmt::Debug for EthAddress {
30+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31+
write!(f, "{}", self)
32+
}
33+
}
34+
2835
impl From<EthAddress> for Address {
2936
fn from(addr: EthAddress) -> Self {
3037
From::from(&addr)

actors/evm/src/interpreter/instructions/call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub fn call_generic<RT: Runtime>(
191191
match precompiles::Precompiles::call_precompile(system, &dst, input_data, context) {
192192
Ok(return_data) => (1, return_data),
193193
Err(err) => {
194-
log::warn!(target: "evm", "Precompile failed: error {:?}", err);
194+
log::warn!(target: "evm", "call to precompile {} failed: {}", &dst, err);
195195
// precompile failed, exit with reverted and no output
196196
(0, vec![])
197197
}

actors/evm/src/interpreter/precompiles/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use fil_actors_evm_shared::{address::EthAddress, uints::U256};
44
use fil_actors_runtime::{runtime::Runtime, ActorError};
55
use fvm_shared::{address::Address, econ::TokenAmount};
66
use substrate_bn::{CurveError, FieldError, GroupError};
7+
use thiserror::Error;
78

89
use crate::reader::OverflowError;
910

@@ -111,15 +112,21 @@ impl<RT: Runtime> Precompiles<RT> {
111112
}
112113
}
113114

114-
#[derive(Debug)]
115+
#[derive(Debug, Error)]
115116
pub enum PrecompileError {
116117
// EVM precompile errors
118+
#[error("EC curve error in data passed to precompile: {0:?}")]
117119
EcErr(CurveError),
120+
#[error("incorrect input size to precompile")]
118121
IncorrectInputSize,
119122
// FVM precompile errors
123+
#[error("invalid input to precompile")]
120124
InvalidInput,
125+
#[error("calling convention forbidden for precompile")]
121126
CallForbidden,
127+
#[error("transfering funds to precompile failed")]
122128
TransferFailed,
129+
#[error("internal evm error when calling precompile: {0}")]
123130
VMError(ActorError),
124131
}
125132

0 commit comments

Comments
 (0)