foundry icon indicating copy to clipboard operation
foundry copied to clipboard

`forge scripts` seem to deploy libraries that are used in a deployment even if their use isn't within a `start/stopBroadcast`

Open JasoonS opened this issue 3 years ago • 1 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 (6974541 2022-09-20T00:08:48.480626755Z)

What command(s) is the bug in?

forge script

Operating System

No response

Describe the bug

The contract seemed to always deploy the library regardless.

JasoonS avatar Sep 20 '22 18:09 JasoonS

Also, worth mentioning that I had some errors about unlinked libraries that prevented me from deploying.

I went through a bit of a deployment setup hell, and now things are mostly working - so I'm not sure what changed. But at the time I had to delete the library to get it to work.

JasoonS avatar Sep 21 '22 07:09 JasoonS

Here is a basic repro of the issue.

import 'forge-std/Script.sol';

library ABCD {
    function increment(uint256 num) public pure returns (uint256) {
        return num+1;
    }
}

contract SimpleRepro is Script {
    using ABCD for uint256;

    function run() public {
        uint256(1).increment();

        vm.startBroadcast();
        address(0x01).call("");
        vm.stopBroadcast();
    }
}
Script ran successfully.
==========================
Simulated On-chain Traces:

  [92887] → new <Unknown>@0xdA8d497A39Ad2F2A27bF546dbeCdE3ace42beEC6
    └─ ← 183 bytes of code

  [25500] PRECOMPILE::ecrecover()
    └─ ←

And the Transactions json file will contain a CREATE and a CALL.

[
  {
    "hash": null,
    "transactionType": "CREATE",
    "contractName": null,
    "contractAddress": "0xdA8d497A39Ad2F2A27bF546dbeCdE3ace42beEC6",
    "function": null,
    "arguments": null,
    "transaction": {
      "type": "0x02",
      "from": "0x00a329c0648769a73afac7f9381e08fb43dbea72",
      "gas": "0x1d7b1",
      "data": "0x60b7610025600b82828239805160001a60731461001857fe5b30600052607381538281f3fe730000000000000000000000000000000000000000301460806040526004361060335760003560e01c80637cf5dab0146038575b600080fd5b604760433660046061565b605b565b604051605291906078565b60405180910390f35b60010190565b6000602082840312156071578081fd5b5035919050565b9081526020019056fea26469706673582212206dc82c1d65dccde4fb636aeca7770646ba655917c54c1bcab18deab52fa7971464736f6c634300060c0033",
      "nonce": "0x7163",
      "accessList": []
    },
    "additionalContracts": []
  },
  {
    "hash": null,
    "transactionType": "CALL",
    "contractName": null,
    "contractAddress": null,
    "function": null,
    "arguments": null,
    "transaction": {
      "type": "0x02",
      "from": "0x00a329c0648769a73afac7f9381e08fb43dbea72",
      "to": "0x0000000000000000000000000000000000000001",
      "gas": "0x817e",
      "value": "0x0",
      "data": "0x",
      "nonce": "0x7164",
      "accessList": []
    },
    "additionalContracts": []
  }
]

dekz avatar Oct 21 '22 01:10 dekz

not sure if that helps you, but i think when making library methods internal the behavior changes.

sakulstra avatar Feb 13 '23 09:02 sakulstra

Just stumbled upon the same issue, ended up deploying [Strings2](https://github.com/dmfxyz/murky/blob/main/differential_testing/test/utils/Strings2.sol) by accident whilst borrowing some of the foundry book examples for ffi as for some reason its method is public...

ultrasecreth avatar Aug 19 '23 15:08 ultrasecreth