Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't validate when decoding revert reason #511

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading