zemse / hardhat-tracer

🕵️ allows you to see internal calls, events and storage operations in the console
MIT License
341 stars 35 forks source link

Custom ABIs #60

Open LesterLyu opened 10 months ago

LesterLyu commented 10 months ago

Is there any way to add custom ABIs via config, the ABIs from 4byte.directory may not always correct.

zemse commented 10 months ago

If you just add interfaces in your contracts folder, that should be used and given more preference than 4bytes dir. You can also turn off usage of 4bytes using this config.

LesterLyu commented 10 months ago

I have the interfaces defined in the contracts folder, but it still prefers to pick from the 4bytes dir in a special case.

Assuming the interface is function someFunction(bytes calldata data) and the data is only 10 bytes. The function call is below in yul:

let contractAddress := `some address`
// 4 bytes sighash + 32 bytes data size + 10 bytes data
// If do the function call in solidity, the insize will be 4 + 32 + 32, but including the ending zeros is not necessary and consumes more gas
let insize := 46 
pop(call(gas(), contractAddress, 0, 0, insize, 0, 0))

If insize is 4 + 32 + 32, it will pick the interfaces from the contract folder.

zemse commented 10 months ago

Hmm, interesting. I'm using ethers.js ABI decoder which expects the calldata to be adhering to the ABI spec. If you are not passing the zeros for the last value, it works in solidity because it doesn't check calldata length. Solidity also accepts more bytes in calldata than needed but ethers would throw an exception for these both cases.

Maybe it could be fine to fill missing bytes by not requiring exact calldata length to reflect the behaviour of solidity, I can try patching it on my side.