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

[Bug] abi_decode panic when using sol types of fixed bytes #433

Closed
fjchen7 opened this issue Nov 23, 2023 · 2 comments · Fixed by #434
Closed

[Bug] abi_decode panic when using sol types of fixed bytes #433

fjchen7 opened this issue Nov 23, 2023 · 2 comments · Fixed by #434
Labels
bug Something isn't working

Comments

@fjchen7
Copy link

fjchen7 commented Nov 23, 2023

Component

sol-types

What version of Alloy are you on?

No response

Operating System

macOS (Apple Silicon)

Describe the bug

Reproduction

use alloy_primitives::fixed_bytes;
use alloy_sol_types::{sol, SolType};
sol! {
    #[derive(Debug, Default)]
    struct FullReport {
        bytes32[3] report_context;
        bytes      report_blob;
        bytes32[]  raw_rs;
        bytes32[]  raw_ss;
        bytes32    raw_vs;
    }
}
let full_report = FullReport {
    report_context: [
        fixed_bytes!("0006015a2de20abc8c880eb052a09c069e4edf697529d12eeae88b7b6867fc81"),
        fixed_bytes!("00000000000000000000000000000000000000000000000000000000080f7906"),
        fixed_bytes!("0000000000000000000000000000000000000000000000000000000000000000"),
    ],
    report_blob: hex::decode("0002191c50b7bdaf2cb8672453141946eea123f8baeaa8d2afa4194b6955e68300000000000000000000000000000000000000000000000000000000655ac7af00000000000000000000000000000000000000000000000000000000655ac7af000000000000000000000000000000000000000000000000000000000000138800000000000000000000000000000000000000000000000000000000000a1f6800000000000000000000000000000000000000000000000000000000655c192f000000000000000000000000000000000000000000000000d130d9ecefeaae30").unwrap().into(),
    raw_rs: vec!(
        fixed_bytes!("d1e3d8b8c581a7ed9cfc41316f1bb8598d98237fc8278a01a9c6a323c4b5c331"),
        fixed_bytes!("38ef50778560ec2bb08b23960e3d74f1ffe83b9240a39555c6eb817e3f68302c"),
    ),
    raw_ss: vec!(
        fixed_bytes!("7fb9c59cc499a4672f1481a526d01aa8c01380dcfa0ea855041254d3bcf45536"),
        fixed_bytes!("2ce612a86846a7cbb640ddcd3abdecf56618c7b24cf96242643d5c355dee5f0e"),
    ),
    raw_vs: fixed_bytes!("0001000000000000000000000000000000000000000000000000000000000000"),
};
// let full_report: FullReport = Default::default();
// let encoded = full_report.abi_encode();
let encoded = FullReport::abi_encode(&full_report);
println!("encoded: {:?}", hex::encode(&encoded));
let full_report = FullReport::abi_decode(&encoded, true).unwrap();
println!("full_report: {:?}", full_report);

Panic message

called `Result::unwrap()` on an `Err` value: TypeCheckFail { expected_type: "Solidity pointer (uint32)", data: "0006015a2de20abc8c880eb052a09c069e4edf697529d12eeae88b7b6867fc81" }

When I remove bytes32[3] report_context; then it works.

@fjchen7 fjchen7 added the bug Something isn't working label Nov 23, 2023
@fjchen7
Copy link
Author

fjchen7 commented Nov 24, 2023

Hi @DaniPopes I wonder why the encoding bytes is different from other tools?

I encode a variable of same type with same data by ethabi, the abi-encode result is 0006015a2de20abc8c880eb052a09c069e4edf697529d12eeae88b7b6867fc8100000000000000000000000000000000000000000000000000000000080f7906000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000240000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e00002191c50b7bdaf2cb8672453141946eea123f8baeaa8d2afa4194b6955e68300000000000000000000000000000000000000000000000000000000655ac7af00000000000000000000000000000000000000000000000000000000655ac7af000000000000000000000000000000000000000000000000000000000000138800000000000000000000000000000000000000000000000000000000000a1f6800000000000000000000000000000000000000000000000000000000655c192f000000000000000000000000000000000000000000000000d130d9ecefeaae300000000000000000000000000000000000000000000000000000000000000002d1e3d8b8c581a7ed9cfc41316f1bb8598d98237fc8278a01a9c6a323c4b5c33138ef50778560ec2bb08b23960e3d74f1ffe83b9240a39555c6eb817e3f68302c00000000000000000000000000000000000000000000000000000000000000027fb9c59cc499a4672f1481a526d01aa8c01380dcfa0ea855041254d3bcf455362ce612a86846a7cbb640ddcd3abdecf56618c7b24cf96242643d5c355dee5f0e

However in the above snippet, result of abi_encode is 00000000000000000000000000000000000000000000000000000000000000200006015a2de20abc8c880eb052a09c069e4edf697529d12eeae88b7b6867fc8100000000000000000000000000000000000000000000000000000000080f7906000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000240000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e00002191c50b7bdaf2cb8672453141946eea123f8baeaa8d2afa4194b6955e68300000000000000000000000000000000000000000000000000000000655ac7af00000000000000000000000000000000000000000000000000000000655ac7af000000000000000000000000000000000000000000000000000000000000138800000000000000000000000000000000000000000000000000000000000a1f6800000000000000000000000000000000000000000000000000000000655c192f000000000000000000000000000000000000000000000000d130d9ecefeaae300000000000000000000000000000000000000000000000000000000000000002d1e3d8b8c581a7ed9cfc41316f1bb8598d98237fc8278a01a9c6a323c4b5c33138ef50778560ec2bb08b23960e3d74f1ffe83b9240a39555c6eb817e3f68302c00000000000000000000000000000000000000000000000000000000000000027fb9c59cc499a4672f1481a526d01aa8c01380dcfa0ea855041254d3bcf455362ce612a86846a7cbb640ddcd3abdecf56618c7b24cf96242643d5c355dee5f0e, which has extra leading bytes 0000000000000000000000000000000000000000000000000000000000000020.

@DaniPopes
Copy link
Member

The equivalent to ethabi would be abi_encode_params.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants