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

deal(address token, address who, uint256 give) fails with No storage use detected for target #337

Open
2 tasks done
webthethird opened this issue Apr 23, 2024 · 3 comments
Labels
cheatcode Issue with a cheat code against zksync

Comments

@webthethird
Copy link

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.0.2 (532ef5e 2024-04-22T00:21:35.201114596Z)

What command(s) is the bug in?

forge test

Operating System

Linux

Describe the bug

When I attempt to deal ERC20 tokens to an address using deal(address token, address who, uint256 give) after forking zkSync Era mainnet, I get the following error and trace (where 0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4 is USDC deployed on zkSync Era):

  [163415] LimitOrderTest::test_DealUSDC()
    ├─ [0] 0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4::balanceOf(LimitOrderTest: [0x7FA9385bE102ac3EAc297483Dd6233D62b3e1496]) [staticcall]
    │   └─ ← 0
    ├─ [0] VM::record()
    │   └─ ← ()
    ├─ [0] 0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4::balanceOf(LimitOrderTest: [0x7FA9385bE102ac3EAc297483Dd6233D62b3e1496]) [staticcall]
    │   └─ ← 0
    ├─ [0] VM::accesses(0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4)
    │   └─ ← [], []
    └─ ← revert: stdStorage find(StdStorage): No storage use detected for target.

The Solidity code is as follows (note: I get the same error no matter which token I use):

contract ForkTest is Test {
    /* fork */
    uint256 public eraFork;

    /* fork addresses */
    address constant USDC = 0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4;

    /* contracts */
    IERC20Metadata public usdc;

    function setUp() public virtual {
        /* initialize fork */
        eraFork = vm.createFork("https://mainnet.era.zksync.io");
        vm.selectFork(eraFork);

        /* get existing deployments */
        usdc = IERC20Metadata(USDC);
    }

    function test_DealUSDC() public {
        deal(address(usdc), address(this), 1 ether);
        ...
    }
}

I am using the forge-std library v1.8.0, where deal is defined in StdCheats.sol as:

    // Set the balance of an account for any ERC20 token
    // Use the alternative signature to update `totalSupply`
    function deal(address token, address to, uint256 give) internal virtual {
        deal(token, to, give, false);
    }

    function deal(address token, address to, uint256 give, bool adjust) internal virtual {
        // get current balance
        (, bytes memory balData) = token.staticcall(abi.encodeWithSelector(0x70a08231, to));
        uint256 prevBal = abi.decode(balData, (uint256));

        // update balance
        stdstore.target(token).sig(0x70a08231).with_key(to).checked_write(give);

        // update total supply
        if (adjust) {
            (, bytes memory totSupData) = token.staticcall(abi.encodeWithSelector(0x18160ddd));
            uint256 totSup = abi.decode(totSupData, (uint256));
            if (give < prevBal) {
                totSup -= (prevBal - give);
            } else {
                totSup += (give - prevBal);
            }
            stdstore.target(token).sig(0x18160ddd).checked_write(totSup);
        }
    }
@dutterbutter
Copy link
Collaborator

dutterbutter commented Apr 23, 2024

@webthethird really appreciate the bug report. We will investigate the issue, to speed up our investigation do you happen to have a repo link or a minimal reproducible example that we can quickly run to reproduce?

To confirm you ran with the --zksync flag?

@dutterbutter dutterbutter added cheatcode Issue with a cheat code against zksync and removed T-bug labels Apr 23, 2024
@webthethird
Copy link
Author

To confirm you ran with the --zksync flag?

Indeed, I did.

do you happen to have a repo link or a minimal reproducible example that we can quickly run to reproduce?

The repo I'm working on is private for now, but I will put together a minimal example to share here by EOD.

@webthethird
Copy link
Author

@dutterbutter
https://github.com/webthethird/min-reproducible-deal-token-bug-zksync-foundry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cheatcode Issue with a cheat code against zksync
Projects
None yet
Development

No branches or pull requests

2 participants