alloy-rs / core

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

[Bug] Function created with sol! macro does not perform correct abi_encode() for function selector #631

Closed mesozoic-technology closed 3 months ago

mesozoic-technology commented 4 months ago

Component

sol-types, sol! macro

What version of Alloy are you on?

No response

Operating System

macOS (Apple Silicon)

Describe the bug

I reproduced the issue below. This is for version 0.7.4.

The abi encoded hex bytes produced by replicateCall{...}.abi_encode() does not result in the correct encoding of the function's selector, which was derived from a forge script and printed out afterwards.

https://github.com/mesozoic-technology/rust-sketches/blob/main/src/main.rs

DaniPopes commented 3 months ago

The signature in the Rust code you provided is replicate(bytes,bytes,bytes,address), which is correct for the given sol! function. What signature are you expecting?

prestwich commented 3 months ago

independently verifying the 4-byte with cast gives the same result as sol!

Screenshot 2024-05-22 at 09 38 15

which we can see matches the sol! output of the rust-sketch bin

Screenshot 2024-05-22 at 09 38 44

Can you say what function definition gave 0x6fc310f8 and how it was printed from the forge script?

mesozoic-technology commented 3 months ago

Sorry, you're right, I'm wrong. Had a huge cold yesterday and put the similarly named but incorrect contract into forge to derive that "expected selector".

I was trying to encode a call to Multicall3 and it was working when I did not include any calls, but when including this call, failed. Combined with my head pounding, jumped to a false conclusion