foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Wrong number of bytes of runtime code reported in traces

Open duncancmt opened this issue 1 year ago • 0 comments

Component

Forge

Have you ensured that all of these are up to date?

  • [X] Foundry
  • [X] Foundryup

What version of Foundry are you on?

forge 0.2.0 (2cf84d9 2024-02-07T00:16:06.769732275Z)

What command(s) is the bug in?

forge test

Operating System

Linux

Describe the bug

forge test -vvvv reports the number of bytes of initcode as the number of bytes of runtime code.

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "forge-std/Test.sol";

contract WrongTraceTest is Test {
    function testTrace() public {
        assembly ("memory-safe") {
            mstore(0x00, 0x60015ff3) // PUSH1 1 PUSH0 RETURN
            pop(create(0x00, 0x1c, 0x04))
        }
    }
}
$ forge test --evm-version shanghai --mc WrongTraceTest --mt testTrace -vvvv
[⠆] Compiling...
No files changed, compilation skipped

Running 1 test for test/WrongTrace.t.sol:WrongTraceTest
[PASS] testTrace() (gas: 32437)
Traces:
  [32437] WrongTraceTest::testTrace()
    ├─ [208] → new <unknown>@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
    │   └─ ← 4 bytes of code
    └─ ← ()

Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 298.59µs
 
Ran 1 test suites: 1 tests passed, 0 failed, 0 skipped (1 total tests)

This should show 1 byte of code, not 4. The amount of gas consumed correctly counts the 8 gas for initcode execution plus the 200 gas for the code deposit.

duncancmt avatar Feb 07 '24 22:02 duncancmt