foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.26k stars 1.74k forks source link

bug(`cast`): `cast send` doesn't display custom errors on tx reverts #8606

Open rplusq opened 2 months ago

rplusq commented 2 months ago

Component

Cast

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

What version of Foundry are you on?

forge 0.2.0 (0b73b42 2024-08-05T00:19:50.130854000Z)

What command(s) is the bug in?

anvil; forge create SimpleStorage --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80; cast send 0x5FbDB2315678afecb367f032d93F642f64180aa3 "setValue(uint256)" 101 --private-key=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

Operating System

macOS (Apple Silicon)

Describe the bug

When running cast send, if your tx reverts with a custom error, cast only displays:

Error: 
server returned an error response: error code 3: execution reverted: 

But no custom error (nor error, nor signature), which makes it super hard to debug.

Reproducible with the anvil's default private key with this contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SimpleStorage {
    uint256 private storedValue;

    event ValueChanged(uint256 newValue);

    error ValueTooHigh(uint256 providedValue, uint256 maxValue);

    function setValue(uint256 _newValue) public {
        if (_newValue > 100) {
            revert ValueTooHigh({ providedValue: _newValue, maxValue: 100 });
        }
        storedValue = _newValue;
        emit ValueChanged(_newValue);
    }

    function getValue() public view returns (uint256) {
        return storedValue;
    }

    function incrementValue() public {
        storedValue += 1;
        emit ValueChanged(storedValue);
    }

    function divideTenBy(uint256 _divisor) public pure returns (uint256) {
        require(_divisor != 0, "Cannot divide by zero");
        return 10 / _divisor;
    }
}
  1. Run Anvil
  2. forge create SimpleStorage --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
  3. cast send 0x5FbDB2315678afecb367f032d93F642f64180aa3 "setValue(uint256)" 101 --private-key=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
rplusq commented 2 months ago

Interested in solving this one

cuiweixie commented 2 months ago

see https://github.com/foundry-rs/foundry/issues/8603