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

vm.stopAndReturnStateDiff() results do not include call to create2 factory #6634

Closed
2 tasks done
RPate97 opened this issue Dec 20, 2023 · 2 comments
Closed
2 tasks done
Labels
T-bug Type: bug

Comments

@RPate97
Copy link
Contributor

RPate97 commented Dec 20, 2023

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (73fb616 2023-12-19T00:17:51.579325000Z)

What command(s) is the bug in?

forge script

Operating System

macOS (Apple Silicon)

Describe the bug

Deploying a contract using create2 shows up as a single create AccountAccess in the results returned by vm.stopAndReturnStateDiff() even though the call to the create2 factory itself is also a state-changing action. This makes it difficult to determine if a contract was deployed using create or create2 based on the recorded results. The call to the create2 factory should be included in the results returned by this cheat code.

It's unclear to me if the current behavior was intended or not. If it was intended, then this issue should probably be converted into a feature request. Please let me know if you think I should do that.

Replication

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

import { Script, console } from "forge-std/Script.sol";
import { VmSafe, Vm } from "forge-std/Vm.sol";

contract Counter {
    uint256 public number;

    constructor (uint _number) {
      number = _number;
    }

    function increment() public {
      number += 1;
    }
}

contract CounterScript is Script {
    function run() public {
        vm.startStateDiffRecording();
        Counter counter = new Counter{ salt: 0 }(0);

        Vm.AccountAccess[] memory accountAccesses = vm.stopAndReturnStateDiff();
        for (uint i = 0; i < accountAccesses.length; i++) {
            console.log(uint(accountAccesses[i].kind));
            console.log('account', accountAccesses[i].account);
            console.log('accessor', accountAccesses[i].accessor);
        }
    }
}

forge script ./script/Counter.s.sol --tc CounterScript

@RPate97 RPate97 added the T-bug Type: bug label Dec 20, 2023
@gakonst gakonst added this to Foundry Dec 20, 2023
@github-project-automation github-project-automation bot moved this to Todo in Foundry Dec 20, 2023
@maurelian
Copy link

This looks to me like a legitimate issue. I notice that the trace from your PoC also excludes any reference to the factory contract and makes it appear like a direct creation.

[146870] CounterScript::run()
    ├─ [0] VM::startStateDiffRecording()
    │   └─ ← ()
    ├─ [74744] → new Counter@0xa5a60F25eae05d45f90d25469954703CC5334527
    │   └─ ← 371 bytes of code
    ├─ [0] VM::stopAndReturnStateDiff()

@klkvr
Copy link
Member

klkvr commented Apr 17, 2024

Fixed by #7653 and #7207

@klkvr klkvr closed this as completed Apr 17, 2024
@jenpaff jenpaff moved this from Todo to Completed in Foundry Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants