hardhat icon indicating copy to clipboard operation
hardhat copied to clipboard

Transaction which fails due to duplicate salt fails to generate stack

Open ncjones opened this issue 1 year ago • 4 comments

Version of Hardhat

2.19.0

What happened?

I have a function which deploys beacon proxies with create2 by providing a salt like:

function createWidget(uint32 salt) external {
    BeaconProxy proxy = new BeaconProxy{ salt: bytes32(salt) }( address(_beacon), new bytes(0));
    emit WidgetCreated(address(proxy));
}

I have a test which checks the same salt cannot be used twice. It expects the transaction to be reverted. When this test runs I get a warning like:

  hardhat:core:hardhat-network:node Could not generate stack trace. Please report this to help us improve Hardhat.

Hardhat version:

⇒  yarn hardhat --version
2.19.0

Minimal reproduction steps

Call a contract which uses create2 and reverts because of non-unique salt.

Search terms

No response

ncjones avatar Nov 08 '23 01:11 ncjones

Hi @ncjones. Just to clarify: the second transaction with the same salt does revert correctly; you are just reporting the "Failed to generate 1 stack trace." message, right?

I can confirm that this is happening. The problem is here:

https://github.com/NomicFoundation/hardhat/blob/f0ca6c8ff7ec48031ffaf368212b8dbe5bf5587e/packages/hardhat-core/src/internal/hardhat-network/stack-traces/error-inferrer.ts#L581

We should return early if trace.steps is empty.

fvictorio avatar Nov 10 '23 13:11 fvictorio

@fvictorio Sorry I missed your question. Yes, the transaction was reverted correctly but because of this issue I was unable to correctly assert as such in my test.

ncjones avatar Jan 15 '24 18:01 ncjones

Got this issue, and started working on a PR (that unfortunattelly does not fix the issue) #4799

Details can be found here: https://github.com/NomicFoundation/hardhat/pull/4799#issuecomment-1914204248

Amxx avatar Jan 29 '24 08:01 Amxx

I can confirm that this is happening. The problem is here:

https://github.com/NomicFoundation/hardhat/blob/f0ca6c8ff7ec48031ffaf368212b8dbe5bf5587e/packages/hardhat-core/src/internal/hardhat-network/stack-traces/error-inferrer.ts#L581

We should return early if trace.steps is empty.

If this function returns "false" early, then the same error happens elsewhere in the execution path

This is the faillure currently

    at isEvmStep (hardhat/src/internal/hardhat-network/stack-traces/message-trace.ts:88:14)
    at ErrorInferrer._isConstructorInvalidArgumentsError (hardhat/src/internal/hardhat-network/stack-traces/error-inferrer.ts:1003:19)
    at ErrorInferrer.inferBeforeTracingCreateMessage (hardhat/src/internal/hardhat-network/stack-traces/error-inferrer.ts:144:14)
    at SolidityTracer._getCreateMessageStackTrace (hardhat/src/internal/hardhat-network/stack-traces/solidityTracer.ts:136:27)
    at SolidityTracer.getStackTrace (hardhat/src/internal/hardhat-network/stack-traces/solidityTracer.ts:50:19)

If you fix _isConstructorInvalidArgumentsError, then you get

    at isEvmStep (/hardhat/src/internal/hardhat-network/stack-traces/message-trace.ts:88:14)
    at ErrorInferrer._checkLastInstruction (/home/src/internal/hardhat-network/stack-traces/error-inferrer.ts:583:19)
    at ErrorInferrer.inferAfterTracing (/hardhat/src/internal/hardhat-network/stack-traces/error-inferrer.ts:164:12)
    at SolidityTracer._rawTraceEvmExecution (/hardhat/src/internal/hardhat-network/stack-traces/solidityTracer.ts:227:61)
    at SolidityTracer._traceEvmExecution (/hardhat/src/internal/hardhat-network/stack-traces/solidityTracer.ts:159:29)
    at SolidityTracer._getCreateMessageStackTrace (/hardhat/src/internal/hardhat-network/stack-traces/solidityTracer.ts:142:17)
    at SolidityTracer.getStackTrace (/hardhat/src/internal/hardhat-network/stack-traces/solidityTracer.ts:50:19)

Amxx avatar Jan 29 '24 08:01 Amxx