hashgraph / hedera-mirror-node-explorer

Hedera Mirror Node Explorer for the Hedera Hashgraph DLT.
Apache License 2.0
31 stars 15 forks source link

Enhancing Error Message Readability on Hashscan for Reverted Smart Contract Calls #904

Open quiet-node opened 8 months ago

quiet-node commented 8 months ago

Problem

Description: Currently, when a smart contract call is reverted, the error message displayed on Hashscan is well-readable if the error message is either Error(string) or Panic(uint256). However, for custom errors, the display lacks human readability, as it doesn't decode the custom data into a readable format.

Example:

function buy(uint amount) public payable {
    if (amount > msg.value / 2 ether)
        revert("Not enough Ether provided.");
}

In this example, the error generates an Error(string) data, which Hashscan displays nicely.

image

link to example transaction: https://hashscan.io/testnet/transaction/1708618373.183662003

Proposal: Enhance the error message display for custom errors such as:

error Unauthorized(address);
function withdraw() public {
    if (msg.sender != owner)
        revert Unauthorized(msg.sender);
}

Currently, Hashscan decodes custom error data into a non-human-readable format.

image

link to example transaction: https://hashscan.io/testnet/transaction/1708620069.753947441

This issue proposes improving this to make custom error messages more easily understandable to developers.

Expected Outcome: With this enhancement, developers will benefit from better readability of error messages, especially for custom errors, leading to improved debugging and development experiences when interacting with smart contracts on Hashscan.

Solution

Alternatives

No response

quiet-node commented 8 months ago

Update: Hashscan does decode the error message using the contract interface when the contract is verified.

error Unauthorized(address account, string message, uint256 ID, bool status);
    function withdraw() public {
        if (msg.sender != owner)
            revert Unauthorized(msg.sender, "Unauthorized!!", 369, false);

        payable(msg.sender).transfer(address(this).balance);
}
image

link to example transaction: https://hashscan.io/testnet/transaction/1708635063.837440003

This will leave the solution left with If the contract is not verified and the error is caused by a custom error, display the data hash

mshakeg commented 2 months ago

Below is an example of a redirectForToken function call that reverts with the following error that isn't plainly human readable.

0x494e56414c49445f4f5045524154494f4e

https://hashscan.io/mainnet/transaction/1723125786.080226003