From 4b68572058d00f82d15a8b015930af7d340e35d5 Mon Sep 17 00:00:00 2001 From: Dusan Stanivukovic Date: Thu, 14 Sep 2023 09:04:00 +0200 Subject: [PATCH] Fix error handling for signature validator (#1871) Context: https://cowservices.slack.com/archives/C0361CDD1FZ/p1694595411953299 We need to convert web3 error first to `ExecutionError` so the reverts are properly classified so that our error conversion method properly classify revert as `SignatureValidationError::Invalid` --- crates/shared/src/signature_validator.rs | 12 +++++++++++- crates/shared/src/signature_validator/simulation.rs | 9 +++++++-- crates/shared/src/signature_validator/web3.rs | 9 --------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/crates/shared/src/signature_validator.rs b/crates/shared/src/signature_validator.rs index 912eccc971..035fdfe568 100644 --- a/crates/shared/src/signature_validator.rs +++ b/crates/shared/src/signature_validator.rs @@ -1,5 +1,6 @@ use { - ethcontract::Bytes, + crate::ethcontract_error::EthcontractErrorType, + ethcontract::{errors::ExecutionError, Bytes}, ethrpc::Web3, hex_literal::hex, model::interaction::InteractionData, @@ -73,3 +74,12 @@ pub fn validator(contracts: Contracts, web3: Web3) -> Arc for SignatureValidationError { + fn from(err: ExecutionError) -> Self { + match EthcontractErrorType::classify(&err) { + EthcontractErrorType::Contract => Self::Invalid, + _ => Self::Other(err.into()), + } + } +} diff --git a/crates/shared/src/signature_validator/simulation.rs b/crates/shared/src/signature_validator/simulation.rs index dbe4bbb521..938dc80f28 100644 --- a/crates/shared/src/signature_validator/simulation.rs +++ b/crates/shared/src/signature_validator/simulation.rs @@ -6,7 +6,7 @@ use { super::{SignatureCheck, SignatureValidating, SignatureValidationError}, anyhow::{Context, Result}, - ethcontract::{common::abi::Token, tokens::Tokenize, Bytes}, + ethcontract::{common::abi::Token, errors::ExecutionError, tokens::Tokenize, Bytes}, ethrpc::Web3, futures::future, primitive_types::{H160, U256}, @@ -59,7 +59,12 @@ impl Validator { tx.data.unwrap(), ); - let output = self.web3.eth().call(call, None).await?; + let output = self + .web3 + .eth() + .call(call, None) + .await + .map_err(ExecutionError::from)?; let simulation = Simulation::decode(&output.0)?; tracing::trace!(?check, ?simulation, "simulated signatures"); diff --git a/crates/shared/src/signature_validator/web3.rs b/crates/shared/src/signature_validator/web3.rs index ff9e90824b..b328fcf34e 100644 --- a/crates/shared/src/signature_validator/web3.rs +++ b/crates/shared/src/signature_validator/web3.rs @@ -106,12 +106,3 @@ impl From for SignatureValidationError { } } } - -impl From for SignatureValidationError { - fn from(err: ExecutionError) -> Self { - match EthcontractErrorType::classify(&err) { - EthcontractErrorType::Contract => Self::Invalid, - _ => Self::Other(err.into()), - } - } -}