ethereum / hevm

symbolic EVM evaluator
https://hevm.dev
GNU Affero General Public License v3.0
223 stars 45 forks source link

Improve known cheat code errors #497

Open arcz opened 1 month ago

arcz commented 1 month ago

We return non-helpful errors when there is a problem with a known cheat code. For instance, here we know we are inside ffi but we return BadCheatCode with sig which doesn't add much debugging value.

Ideally, in the error, we should have the method + args like ffi(string[]) and a failure reason.

msooseth commented 1 month ago

Hi @arcz,

Thanks for this! I have done some work on this, but for the life of me I can't find a way to test it :laughing: Please see PR https://github.com/ethereum/hevm/pull/503

There, the file test/contracts/pass/cheatCodeErrors.sol is what's supposed to trigger the error. However, it seems like the interpreter ignores that there are too few arguments (1 instead of 2). I can't seem to make the interpreter die. If you change the 0x24 to 0x44 there, the hevm.deal works, so indeed it is a correct call.

So I'm stuck at testing my new fix. Do you know how could I write that inline assembly such that the interpreter will die with a BadCheatcode and I could test my error code? On bad selector, it reverts, on incorrect parameters it just runs happily ever after, I'm confused how to actually trigger one of these :laughing:

Thanks,

Mate

msooseth commented 6 days ago

Blocked currently on a good test case and a follow-up review. Perhaps in September when fewer people are on vacation, this will be merged :)