zemse/hardhat-tracer

Custom ABIs

Opened this issue · 3 comments

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

zemse commented

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.

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

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.