foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Anvil + Cast does not show failed tx

Open Pongch opened this issue 2 years ago • 2 comments

I have deployed a contract through low level calls via cast send, the transaction gets mined successfully on Anvil with 'Deployed Contract:

' log and 'cast tx' shows the transaction receipt properly

However, the contract does not exist, due to the transaction gas estimate being underpriced

How to replicate

  • make a transaction that requires N amount of gas
  • underprice transaction with gasEstimate at N-1

expected behavior

  • show transaction failure and reason on Anvil log or via Cast tx

Pongch avatar Aug 29 '22 06:08 Pongch

would appreciate it if you could provide a minimal example.

does cast tx list the transaction as successful or failed?

anvil does log failed transactions and the reason string if available: (require(.., reason)

mattsse avatar Aug 29 '22 12:08 mattsse

This issue is old, but we actually just reproduced this today. Unfortunately I can't provide our exact case to reproduce, but it was very similar to what @Pongch said. We were simulating a Gnosis Safe transaction and provided all the signatures in calldata (which is why I can't share a repro). Details:

First we used anvil

  • It estimated a gas limit of ~117k, but this was insufficient because ~138k gas is is needed
  • The transaction receipt showed success, but the full transaction did not actually execute (the expected storage variable change did not occur)
  • We looked at the trace with cast run. This indicated a top-level revert because of a wrong ecrecover (the recovered address was not a signer on the safe). Only one ecrecover was shown, i.e. it failed on the first signature, and it recovered an unexpected address (the address was not a signer, but all sigs were valid)
  • When we lowered the gas limit to ~110k, the results were as expected: failed status, longer trace showing more ecrecovers occuring.
  • When specifying a high enough gas limit, everything works as expected

Then we tried hardhat (via jackhammer):

  • It chose a better default gas limit so worked out of the box
  • We hardcoded the ~117k gas limit anvil used, and saw multiple ecrecovers for all signers before the out of gas (as expected)
  • We hardcoded the same ~110k test gas limit, and similarly saw multiple ecrecovers for all signers before the out of gas

To summarize, there were three issues with anvil:

  • Bad gas estimate
  • Wrong success value reported
  • Wrong trace reported with the 117k gas case

mds1 avatar Jun 28 '24 17:06 mds1