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

forge script deploys libraries used outside of vm.start/stopBroadcast #3924

Closed
2 tasks
Skelectric opened this issue Dec 21, 2022 · 6 comments
Closed
2 tasks
Labels
C-forge Command: forge Cmd-forge-script Command: forge script T-bug Type: bug

Comments

@Skelectric
Copy link

Skelectric commented Dec 21, 2022

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

No response

What command(s) is the bug in?

forge script

Operating System

Windows

Describe the bug

I have some libraries with convenience functions that I like to use in my scripts.

For example, a readableNum library that lets me log numbers in decimal format (for easier debugging), or a stdJsonDB library that lets me serialize/write data to a file in a single call. Despite me using these utilities outside the the bounds of vm.startBroadcast(privKey)and vm.stopBroadcast(), forge script still manages to include their deployments among the broadcasted transactions.

For an example:

        // squeeth contract payoff provider
        try stdJsonDB.getAddr("ContractPayoffProvider_Squeeth", deployments) returns (address deployedAddr) {
                 // some code
        } catch {
                 // some code
            vm.startBroadcast(deployerPrivateKey);

            squeeth = new Squeeth();                                      // THIS

            vm.stopBroadcast();
                 // some code
        }
        try stdJsonDB.getAddr(deploymentName, deployments) returns (address productAddress) {
                 // some code
        } catch {
                 // some code
            vm.startBroadcast(deployerPrivateKey);

            (bool success, bytes memory data) = address(controller).call(                                 
                abi.encodeCall(IController.createProduct, (coordinatorID, productInfo))
            );                                                            // AND THIS

            vm.stopBroadcast();
                  // some code
        }

I expect this script to broadcast only the operations I marked but forge script also cues up and deploys the stdJsonDB library.

@Skelectric Skelectric added the T-bug Type: bug label Dec 21, 2022
@Skelectric
Copy link
Author

Here's a simpler example. When i run this script it deploys SomeLibrary - why?

// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.17;

import "forge-std/Script.sol";

contract ExtraBroadcastTest is Script {
    function run() external {
        SomeLibrary.reflect(5);

        vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
        (bool success,) = address(0).call{value: 0 ether}("");
        vm.stopBroadcast();

        require(success, "Call failed.");

    }
}

library SomeLibrary {
    function reflect(uint number) external pure returns (uint) {
        return number;
    }
}

@Skelectric Skelectric changed the title forge script deploys convenience utilities used outside of vm.start/stopBroadcast forge script deploys libraries used outside of vm.start/stopBroadcast Dec 21, 2022
@Skelectric
Copy link
Author

Skelectric commented Dec 21, 2022

If i change SomeLibrary into an abstract contract and make the script inherit from it, this doesn't happen.

So libraries and forge script don't mix?

This is unfortunate as there are things I can't do with abstract contracts that I can do with libraries. For example, the try-catch pattern.

@PatrickAlphaC
Copy link

I am getting the same issue! Thanks for reporting this.

@simplyoptimistic
Copy link

I have also gotten this issue recently. It looks like it only affects external libraries, as internal libraries are inlined.

@Evalir
Copy link
Member

Evalir commented Jun 26, 2023

Ref #5194

@Evalir
Copy link
Member

Evalir commented Aug 15, 2023

Closing—fixed with several linker fixes

@Evalir Evalir closed this as completed Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-script Command: forge script T-bug Type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants