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

recurse_link infinite recursion for external library circular dependency crashes forge #5014

Closed
2 tasks done
daltyboy11 opened this issue May 23, 2023 · 0 comments · Fixed by #7027
Closed
2 tasks done
Labels
T-bug Type: bug

Comments

@daltyboy11
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.2.0 (59f026f 2023-05-23T17:21:42.593814000Z)

What command(s) is the bug in?

forge test

Operating System

macOS (Apple Silicon)

Describe the bug

If two libs have external functions that call each other then recurse_link enters an infinite loop. It attempts to link Lib A to Lib B, then B to A, then A to B..., until a stack overflow. Below is a minimal repro demonstrating the issue

  1. Create a starter project via forge init
  2. Append the following code to Counter.sol
library Foo {
  function foo() external {
    Bar.bar();
  }

  function flum() external {}
}

library Bar {
  function bar() external {
    Foo.flum();
  }
}
  1. Run RUST_LOG=forge forge test
  2. Observe crash output (duplicate lines omitted for brevity):
2023-05-23T20:21:53.130321Z TRACE forge::link: linking contract target="Foo.json:Foo"
2023-05-23T20:21:53.130325Z TRACE forge::link: get dependency dependency="Bar.json:Bar" file="src/Counter.sol" key="Bar" version=Version { major: 0, minor: 8, patch: 20, build: BuildMetadata("commit.a1b79de6.Darwin.appleclang") }
2023-05-23T20:21:53.130333Z TRACE forge::link: linking contract target="Bar.json:Bar"
2023-05-23T20:21:53.130362Z TRACE forge::link: get dependency dependency="Foo.json:Foo" file="src/Counter.sol" key="Foo" version=Version { major: 0, minor: 8, patch: 20, build: BuildMetadata("commit.a1b79de6.Darwin.appleclang") }
2023-05-23T20:21:53.130376Z TRACE forge::link: linking contract target="Foo.json:Foo"
2023-05-23T20:21:53.130380Z TRACE forge::link: get dependency dependency="Bar.json:Bar" file="src/Counter.sol" key="Bar" version=Version { major: 0, minor: 8, patch: 20, build: BuildMetadata("commit.a1b79de6.Darwin.appleclang") }
2023-05-23T20:21:53.130388Z TRACE forge::link: linking contract target="Bar.json:Bar"
2023-05-23T20:21:53.130392Z TRACE forge::link: get dependency dependency="Foo.json:Foo" file="src/Counter.sol" key="Foo" version=Version { major: 0, minor: 8, patch: 20, build: BuildMetadata("commit.a1b79de6.Darwin.appleclang") }

thread 'main' has overflowed its stack
fatal runtime error: stack overflow

The trace logs narrowed the issue down to recurse_link. Note this only happens when the lib's functions are external.

@daltyboy11 daltyboy11 added the T-bug Type: bug label May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

1 participant