Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cast run): try custom error decode from openchain signature database #8632

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cuiweixie
Copy link
Contributor

@cuiweixie cuiweixie commented Aug 9, 2024

Motivation

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

contract OwnerControlled {
    address public owner;
    uint256 private value;

    event ValueChanged(uint256 newValue);
    error Unknown(string str);

    constructor() {
        owner = msg.sender;
    }

    modifier onlyOwner() {
        if(msg.sender != owner) {
            revert Unknown("only Owner");
        }
        _;
    }

    function setValue(uint256 _newValue) public onlyOwner {
        value = _newValue;
        emit ValueChanged(_newValue);
    }

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

in this contract, when tx revert by using custom error.
cast run result:

Executing previous transactions from the block.
Traces:
  [2462] 0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9::setValue(1)
    └─ ← [Revert] custom error 7c45b126: 
only Owner


Transaction failed.

Solution

I think we can make it more readable by using openchain's signature database online.
In this pr, custom err would look like:

Executing previous transactions from the block.
Traces:
  [2462] 0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9::setValue(1)
    └─ ← [Revert] Unknown("only Owner")


Transaction failed.

Comment on lines 182 to 190
// try from https://openchain.xyz
let (tx, rx) = mpsc::channel();
let encoded_selector = hex::encode(selector);

thread::spawn(move || {
let rt = tokio::runtime::Runtime::new().unwrap();
let result = rt.block_on(decode_function_selector(&encoded_selector));
tx.send(result).unwrap();
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit expensive to do per invocation.

I can see how this could be useful, but I'd like to make this configurable this behaviour on the RevertDecoder level by giving it an optional OpenChainClient and only use it if we can retrieve the a tokio handle

Copy link
Contributor Author

@cuiweixie cuiweixie Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change ok or not, I need your feedback!

@cuiweixie cuiweixie requested a review from mattsse August 9, 2024 13:55
@cuiweixie cuiweixie force-pushed the readable_custom_error branch 3 times, most recently from cae43c4 to 5d290e6 Compare August 13, 2024 12:56
@cuiweixie cuiweixie closed this Aug 13, 2024
@cuiweixie cuiweixie reopened this Aug 13, 2024
@cuiweixie cuiweixie force-pushed the readable_custom_error branch 5 times, most recently from da328f6 to 86f344a Compare August 13, 2024 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants