Create2 when broadcasting deployed and computed addresses don't match

I'm seeing an issue where I get different computed and deployed address when I run the forge script below. It works when I remove the broadcast. Am I misunderstanding the usage of the library or perhaps my understanding of broadcasting is incorrect?

:1234: Code to reproduce

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
import "forge-std/Script.sol";

contract Foo {
  constructor() {}
}

contract Create2Debug is Script {
  function run() public {
    vm.startBroadcast(); // removing causes require to pass

    bytes memory creationCode = type(Foo).creationCode;
    address computed = Create2.computeAddress(keccak256("a salt!"), keccak256(creationCode));
    address deployed = Create2.deploy(0, keccak256("a salt!"), creationCode);
    console.log("deployed", deployed);
    console.log("computed", computed);
    require(computed == deployed, "address mismatch");

    vm.stopBroadcast(); // removing causes require to pass
  }
}

:computer: Environment

Running on forge version 0.2.0

forge --version
forge 0.2.0 (721eb94 2024-05-01T00:23:13.213668000Z)
1 Like