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

The 'forge --via-ir' compilation option leads to a contract running state that is inconsistent with expectations #6430

Closed
2 tasks done
fpChan opened this issue Nov 26, 2023 · 2 comments
Labels
T-bug Type: bug

Comments

@fpChan
Copy link

fpChan commented Nov 26, 2023

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

0.2.0 (3e12d88 2023-11-17T00:33:21.440760000Z)

What command(s) is the bug in?

--via-ir

Operating System

macOS (Apple Silicon)

Describe the bug

source code

        uint256 startAt = block.timestamp;
        console2.log("startAt %d now %d", startAt, block.timestamp);
        vm.warp(startAt + 1 days);
        console2.log("startAt %d now %d", startAt, block.timestamp);

run without --via-ir

forge test --match-contract CounterTest -vv
The result meets expectations.

Logs:
  startAt 1 now 1
  startAt 1 now 86401

run with --via-ir

forge test --match-contract CounterTest -vv --via-ir
The result does not meet expectations.

Logs:
  startAt 1 now 1
  startAt 86401 now 86401
image
@fpChan fpChan added the T-bug Type: bug label Nov 26, 2023
@gakonst gakonst added this to Foundry Nov 26, 2023
@github-project-automation github-project-automation bot moved this to Todo in Foundry Nov 26, 2023
@Evalir
Copy link
Member

Evalir commented Nov 27, 2023

--via-ir introduces quite a few optimizations which can make a lot of things, including sourcemaps, innacurate. What you're seeing is your code being optimized in the logs. You can disable certain optimizations for IR compilation, but in general we recommend running tests without ir. See ethereum/solidity#12533

@Evalir Evalir closed this as completed Nov 27, 2023
@github-project-automation github-project-automation bot moved this from Todo to Done in Foundry Nov 27, 2023
@mds1
Copy link
Collaborator

mds1 commented Nov 27, 2023

For workarounds, see the convo + linked items at #4934 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
Archived in project
Development

No branches or pull requests

3 participants