alloy-rs / core

High-performance, well-tested & documented core libraries for Ethereum, in Rust
https://alloy.rs
Apache License 2.0
758 stars 131 forks source link

[Bug] `abi_decode_returns` doesn't work with `slot0` by returning `TypeCheckFail` #691

Closed wtdcode closed 1 month ago

wtdcode commented 1 month ago

Component

dyn-abi

What version of Alloy are you on?

0.2.0

Operating System

Linux

Describe the bug

Component

contract

What version of Alloy are you on?

0.2.0

Operating System

Linux

Describe the bug

Minimum repro:

use alloy::{hex, sol, sol_types::SolCall};

sol! {
    function slot0()
        external
        view
        returns (
            uint160 sqrtPriceX96,
            int24 tick,
            uint16 observationIndex,
            uint16 observationCardinality,
            uint16 observationCardinalityNext,
            uint8 feeProtocol,
            bool unlocked
        );
}

fn main() {
    // a perfect valid slot0 returns got by
    // cast call 0xb744Abf10B85fd77D46a8B22f71Fc1E059A2e002 "slot0()"
    let bs = hex!("000000000000000000000000000000000000007c08ceadc9f453ebfb5551158400000000000000000000000000000000000000000000000000000000000178a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000c800c800000000000000000000000000000000000000000000000000000000000000001");

    // panic
    let _ = slot0Call::abi_decode_returns(&bs, true).unwrap();
}

Panic with:

thread 'main' panicked at src/main.rs:25:54:
called `Result::unwrap()` on an `Err` value: TypeCheckFail { expected_type: "(uint160,int24,uint16,uint16,uint16,uint8,bool)", data: "000000000000000000000000000000000000007c08ceadc9f453ebfb5551158400000000000000000000000000000000000000000000000000000000000178a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000c800c800000000000000000000000000000000000000000000000000000000000000001" }

I can't see why it has type mismatching.

wtdcode commented 1 month ago

Closed due to wrong abi.

Sorry =(.