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

Fix cases where trace.step is empty #4799

Closed
wants to merge 1 commit into from
Closed

Conversation

Amxx
Copy link
Contributor

@Amxx Amxx commented Jan 29, 2024

  • Because this PR includes a bug fix,
    • relevant tests have been included.

This unit test in the OpenZeppelin Contracts repository triggers an issue

  hardhat:core:hardhat-network:node Could not generate stack trace. Please report this to help us improve Hardhat.
  hardhat:core:hardhat-network:node  TypeError: Cannot use 'in' operator to search for 'pc' in undefined
    at isEvmStep (/home/amxx/Work/OZ/openzeppelin-contracts/node_modules/hardhat/src/internal/hardhat-network/stack-traces/message-trace.ts:88:14)
    at ErrorInferrer._isConstructorInvalidArgumentsError (/home/amxx/Work/OZ/openzeppelin-contracts/node_modules/hardhat/src/internal/hardhat-network/stack-traces/error-inferrer.ts:1003:19)
    at ErrorInferrer.inferBeforeTracingCreateMessage (/home/amxx/Work/OZ/openzeppelin-contracts/node_modules/hardhat/src/internal/hardhat-network/stack-traces/error-inferrer.ts:144:14)
    at SolidityTracer._getCreateMessageStackTrace (/home/amxx/Work/OZ/openzeppelin-contracts/node_modules/hardhat/src/internal/hardhat-network/stack-traces/solidityTracer.ts:136:27)
    at SolidityTracer.getStackTrace (/home/amxx/Work/OZ/openzeppelin-contracts/node_modules/hardhat/src/internal/hardhat-network/stack-traces/solidityTracer.ts:50:19)
    at SolidityTracer._rawTraceEvmExecution (/home/amxx/Work/OZ/openzeppelin-contracts/node_modules/hardhat/src/internal/hardhat-network/stack-traces/solidityTracer.ts:217:38)
    at SolidityTracer._traceEvmExecution (/home/amxx/Work/OZ/openzeppelin-contracts/node_modules/hardhat/src/internal/hardhat-network/stack-traces/solidityTracer.ts:159:29)
    at SolidityTracer._getCallMessageStackTrace (/home/amxx/Work/OZ/openzeppelin-contracts/node_modules/hardhat/src/internal/hardhat-network/stack-traces/solidityTracer.ts:70:17)
    at SolidityTracer.getStackTrace (/home/amxx/Work/OZ/openzeppelin-contracts/node_modules/hardhat/src/internal/hardhat-network/stack-traces/solidityTracer.ts:54:19)
    at HardhatNode._manageErrors (/home/amxx/Work/OZ/openzeppelin-contracts/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:1989:41) +0ms

The reason for this error is that trace.steps is empty, and thus

const lastStep = trace.steps[trace.steps.length - 1];

is undefined

Copy link

changeset-bot bot commented Jan 29, 2024

⚠️ No Changeset found

Latest commit: c76382e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Jan 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 29, 2024 8:17am

@Amxx
Copy link
Contributor Author

Amxx commented Jan 29, 2024

More details

When running _rawTraceEvmExecution, that step is causing the error:

{
  code: <Buffer 60 c0 60 40 52 60 40 51 62 00 14 9f 38 03 80 62 00 14 9f 83 39 81 81 01 60 40 52 81 01 90 62 00 00 29 91 90 62 00 02 65 56 5b 82 60 00 73 ff ff ff ff ... 5325 more bytes>,
  steps: [],
  value: 0n,
  returnData: <Buffer >,
  numberOfSubtraces: 0,
  depth: 1,
  deployedContract: <Buffer 97 c3 18 90 00 c1 6b 45 32 2f 45 1a df ff c7 76 bd 20 d3 ff>,
  gasUsed: 29397644n,
  error: EvmError { error: 'create collision', errorType: 'EvmError' },
  bytecode: Bytecode {
    contract: [Contract],
    isDeployment: true,
    normalizedCode: <Buffer 60 c0 60 40 52 60 40 51 62 00 14 9f 38 03 80 62 00 14 9f 83 39 81 81 01 60 40 52 81 01 90 62 00 00 29 91 90 62 00 02 65 56 5b 82 60 00 73 ff ff ff ff ... 5229 more bytes>,
    instructions: [Array],
    libraryAddressPositions: [],
    immutableReferences: [],
    compilerVersion: '0.8.20',
    _pcToInstruction: [Map]
  }
}

for this step, isEvmStep returns false, but the absence because steps: [],, calling getStrackTrace on that step leads to the issue.

Maybe there is a better fix than the one I propose.

@Amxx
Copy link
Contributor Author

Amxx commented Jan 29, 2024

Can't figure out how to fix that on my own. Closing PR and reopening as issue.

@Amxx Amxx closed this Jan 29, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

1 participant