foundry: Revert messages are missing

Component

Anvil

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (3fc1491 2022-06-06T00:14:30.023454Z)

What command(s) is the bug in?

anvil

Operating System

macOS (Intel)

Describe the bug

Transactions will revert messages are missing revert messages.

I have a method and modifier like:

    modifier onlyOwner() {
        require(msg.sender == owner, "!authorized");
        _;
    }
    function getSecret() public onlyOwner view returns(uint256 secret) {
        return 123;
    }

The response data I am getting looks like:

{'jsonrpc': '2.0', 'id': 23, 'error': {'code': -32003, 'message': 'execution reverted: ', 'data': '0x'}}

which is maybe what I would expect had I not included a revert message.

!unathorized is missing from the response.

I believe this is a regression, as this was working a month or so ago.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (7 by maintainers)

Most upvoted comments

Ok I am working on a more bare-bones reproduction script to try and debug stuff. I got this:

from solcx import compile_source
from web3 import HTTPProvider, Web3
from web3.exceptions import ContractLogicError

# Mnemonic       : "test test test test test test test test test test test junk"
# Derivation path: "m/44'/60'/0'/{acct-index}"
ACCOUNT = "0x1e59ce931B4CFea3fe4B875411e280e173cB7A9C"
PKEY = "0xdd23ca549a97cb330b011aebb674730df8b14acaee42d211ab45692699ab8ba5"

SOURCE_CODE = """
pragma solidity ^0.8.2;

contract NumberStorage {
    uint256 public number;

    function setNumber(uint256 num) public {
        require(num != 0, "RevertStringFooBar");
        number = num;
    }
}
""".strip()


def main():
    # Connect to node (either Hardhat node or Anvil)
    web3 = Web3(HTTPProvider("http://127.0.0.1:8545/"))
    web3.eth.default_account = ACCOUNT

    # Compile simple contract
    compiled_sol = compile_source(SOURCE_CODE, output_values=["abi", "bin"])
    _, contract_interface = compiled_sol.popitem()
    bytecode = contract_interface["bin"]
    abi = contract_interface["abi"]
    contract =  web3.eth.contract(abi=abi, bytecode=bytecode)

    # Deploy contract and create instance
    params = {"maxFeePerGas": 3242352352352, "maxPriorityFeePerGas": 2000000000}
    tx_hash = contract.constructor().transact(params)
    tx_receipt = web3.eth.wait_for_transaction_receipt(tx_hash)
    instance = web3.eth.contract(address=tx_receipt.contractAddress, abi=abi)

    # Transact in a way that should succeed
    tx_hash = instance.functions.setNumber(5).transact(params)
    tx_receipt = web3.eth.wait_for_transaction_receipt(tx_hash)
    print("Success")

    # Transact in a way that should fail
    try:
        tx_hash = instance.functions.setNumber(0).transact(params)
    except ContractLogicError as err:
        print(f"Failed: {err}")



if __name__ == "__main__":
    main()

When I use Hardhat, this is the output of the script:

Success
Failed: execution reverted: Error: VM Exception while processing transaction: reverted with reason string 'RevertStringFooBar'

When I connect to Anvil however, this is the output:

Success
Failed: execution reverted: 

For some reason, the revert message is not there!

@mattsse let me know if my reproduction script is at all helpful! I can also reach out to the people at web3.py.