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

Solidity stack traces aren't displayed in v3 #5980

Closed
kanej opened this issue Nov 25, 2024 · 1 comment
Closed

Solidity stack traces aren't displayed in v3 #5980

kanej opened this issue Nov 25, 2024 · 1 comment
Labels
status:ready This issue is ready to be worked on v-next A Hardhat v3 development task
Milestone

Comments

@kanej
Copy link
Member

kanej commented Nov 25, 2024

Solidity stack traces aren’t displaying, because the native node.js support for source maps doesn’t work like the one we used in Hardhat 2.

Our next steps are to explore the API and perhaps do the formatting ourselves, copying what the source-map-support used to do. We want to leverage node's native, but that means changing our output format.

@kanej kanej added the v-next A Hardhat v3 development task label Nov 25, 2024
@kanej kanej added this to the Private Alpha Follow-up milestone Nov 25, 2024
@kanej kanej added this to Hardhat Nov 25, 2024
@github-project-automation github-project-automation bot moved this to Backlog in Hardhat Nov 25, 2024
@kanej kanej moved this from Backlog to To-do in Hardhat Nov 25, 2024
@github-actions github-actions bot added the status:ready This issue is ready to be worked on label Nov 25, 2024
@ChristopherDedominici
Copy link
Contributor

ChristopherDedominici commented Dec 17, 2024

I synced with @fvictorio to gather more information and provide a more precise overview of the problem. Here are the additional details:

The issue is that when an error is thrown in Hardhat V3, the stack trace does not provide detailed information about where the error occurred, either in the TypeScript code or the Solidity code. It's important to note that the Solidity stack trace is not yet supported by EDR. However, as a workaround during the investigation, a fake stack trace can be created.

Code snippets to repro the error:

Smart contract code for both Hardhat v2 and Hardhat v3

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.27;

contract Foo {
    function f() public pure {
        g();
    }

    function g() public pure {
        require(false, "some reason");
    }
}

JS code for Hardhat v2 - this will work as expected, showing the error stack trace for both Solidity and JS.

(async () => {
  await ethers.getSigners();

  const contract = await ethers.deployContract("Foo");

  await contract.f();
})();

TS code for Hardhat v3 - this is where the error occurs: the stack trace for both Solidity and JS is not shown.

import { network } from "@ignored/hardhat-vnext";

const { viem, provider } = await network.connect();

const foo = await viem.deployContract("Foo");

const [a]: any = await provider.send("eth_accounts");

await provider.send("eth_sendTransaction", [
  {
    from: a,
    to: foo.address,
    data: "0x26121ff0",
  },
]);

Screenshot of the Hardhat v2 stack trace - all info are shown:
image

Screenshot of the Hardhat v3 stack trace - info are not shown:
image

The investigation into why this is happening should begin with this V2 code to understand how the logic works.
The function to check is encodeSolidityStackTrace. It is supposed to enhance the JavaScript error with information from the Solidity stack trace.
As mentioned above, EDR does not yet provide Solidity stack traces, but they can be faked during this investigation. The variable that will contain the EDR Solidity stack traces is stackTrace: SolidityStackTrace in the encodeSolidityStackTrace function.

@kanej kanej moved this from To-do to Blocked in Hardhat Jan 22, 2025
@kanej kanej closed this as completed Feb 10, 2025
@github-project-automation github-project-automation bot moved this from Blocked to Done in Hardhat Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready This issue is ready to be worked on v-next A Hardhat v3 development task
Projects
Status: Done
Development

No branches or pull requests

2 participants