Skip to content

Commit

Permalink
fix: don't validate when decoding revert reason
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Feb 6, 2024
1 parent 04d63af commit 15fa30c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions crates/sol-types/src/types/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,22 @@ mod tests {
assert_eq!(decoded, revert.to_string());
}

#[test]
fn decode_uniswap_revert() {
// Solc 0.5.X/0.5.16 adds a random 0x80 byte which makes reserialization check fail.
// https://github.com/Uniswap/v2-core/blob/ee547b17853e71ed4e0101ccfd52e70d5acded58/contracts/UniswapV2Pair.sol#L178
// https://github.com/paradigmxyz/evm-inspectors/pull/12
let bytes = hex!("08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000024556e697377617056323a20494e53554646494349454e545f494e5055545f414d4f554e5400000000000000000000000000000000000000000000000000000080");

Revert::abi_decode(&bytes, true).unwrap_err();

let decoded = Revert::abi_decode(&bytes, false).unwrap();
assert_eq!(decoded.reason, "UniswapV2: INSUFFICIENT_INPUT_AMOUNT");

let decoded = decode_revert_reason(&bytes).unwrap();
assert_eq!(decoded, "revert: UniswapV2: INSUFFICIENT_INPUT_AMOUNT");
}

#[test]
fn decode_random_revert_reason() {
let revert_reason = String::from("test_revert_reason");
Expand Down
2 changes: 1 addition & 1 deletion crates/sol-types/src/types/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ where
/// If both attempts fail, it returns `None`.
pub fn decode(out: &[u8]) -> Option<Self> {
// Try to decode as a generic contract error.
if let Ok(error) = ContractError::<T>::abi_decode(out, true) {
if let Ok(error) = ContractError::<T>::abi_decode(out, false) {
return Some(error.into());
}

Expand Down

0 comments on commit 15fa30c

Please sign in to comment.