Skip to content

Commit

Permalink
Fix error handling for signature validator (#1871)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
sunce86 authored Sep 14, 2023
1 parent 1f913fd commit 4b68572
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
12 changes: 11 additions & 1 deletion crates/shared/src/signature_validator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use {
ethcontract::Bytes,
crate::ethcontract_error::EthcontractErrorType,
ethcontract::{errors::ExecutionError, Bytes},
ethrpc::Web3,
hex_literal::hex,
model::interaction::InteractionData,
Expand Down Expand Up @@ -73,3 +74,12 @@ pub fn validator(contracts: Contracts, web3: Web3) -> Arc<dyn SignatureValidatin
contracts.vault_relayer,
))
}

impl From<ExecutionError> for SignatureValidationError {
fn from(err: ExecutionError) -> Self {
match EthcontractErrorType::classify(&err) {
EthcontractErrorType::Contract => Self::Invalid,
_ => Self::Other(err.into()),
}
}
}
9 changes: 7 additions & 2 deletions crates/shared/src/signature_validator/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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");
Expand Down
9 changes: 0 additions & 9 deletions crates/shared/src/signature_validator/web3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,3 @@ impl From<MethodError> for SignatureValidationError {
}
}
}

impl From<ExecutionError> for SignatureValidationError {
fn from(err: ExecutionError) -> Self {
match EthcontractErrorType::classify(&err) {
EthcontractErrorType::Contract => Self::Invalid,
_ => Self::Other(err.into()),
}
}
}

0 comments on commit 4b68572

Please sign in to comment.