@@ -8,7 +8,7 @@ use core::time::Duration;
8
8
use alloy_eips:: BlockId ;
9
9
use alloy_primitives:: { Address , Bytes , U256 } ;
10
10
use alloy_rpc_types_eth:: { error:: EthRpcErrorCode , request:: TransactionInputError , BlockError } ;
11
- use alloy_sol_types:: decode_revert_reason ;
11
+ use alloy_sol_types:: { ContractError , RevertReason } ;
12
12
use reth_errors:: RethError ;
13
13
use reth_primitives_traits:: transaction:: signed:: RecoveryError ;
14
14
use reth_rpc_server_types:: result:: {
@@ -615,8 +615,14 @@ impl RevertError {
615
615
impl std:: fmt:: Display for RevertError {
616
616
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
617
617
f. write_str ( "execution reverted" ) ?;
618
- if let Some ( reason) = self . output . as_ref ( ) . and_then ( |bytes| decode_revert_reason ( bytes) ) {
619
- write ! ( f, ": {reason}" ) ?;
618
+ if let Some ( reason) = self . output . as_ref ( ) . and_then ( |out| RevertReason :: decode ( out) ) {
619
+ let error = reason. to_string ( ) ;
620
+ let mut error = error. as_str ( ) ;
621
+ if matches ! ( reason, RevertReason :: ContractError ( ContractError :: Revert ( _) ) ) {
622
+ // we strip redundant `revert: ` prefix from the revert reason
623
+ error = error. trim_start_matches ( "revert: " ) ;
624
+ }
625
+ write ! ( f, ": {error}" ) ?;
620
626
}
621
627
Ok ( ( ) )
622
628
}
@@ -768,9 +774,9 @@ pub fn ensure_success(result: ExecutionResult) -> EthResult<Bytes> {
768
774
769
775
#[ cfg( test) ]
770
776
mod tests {
771
- use revm_primitives:: b256;
772
-
773
777
use super :: * ;
778
+ use alloy_sol_types:: { Revert , SolError } ;
779
+ use revm_primitives:: b256;
774
780
775
781
#[ test]
776
782
fn timed_out_error ( ) {
@@ -805,4 +811,12 @@ mod tests {
805
811
EthApiError :: HeaderNotFound ( BlockId :: finalized ( ) ) . into ( ) ;
806
812
assert_eq ! ( err. message( ) , "block not found: finalized" ) ;
807
813
}
814
+
815
+ #[ test]
816
+ fn revert_err_display ( ) {
817
+ let revert = Revert :: from ( "test_revert_reason" ) ;
818
+ let err = RevertError :: new ( revert. abi_encode ( ) . into ( ) ) ;
819
+ let msg = err. to_string ( ) ;
820
+ assert_eq ! ( msg, "execution reverted: test_revert_reason" ) ;
821
+ }
808
822
}
0 commit comments