foundry
foundry copied to clipboard
Anvil + Cast does not show failed tx
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 properlyHowever, 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
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)
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