Skip to content

Warping not compatible with --optimize true and --via-ir #10683

@bernard-wagner

Description

@bernard-wagner

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge Version: 1.2.2-stable
Commit SHA: 73ac79f
Build Timestamp: 2025-06-01T14:56:45.336809000Z (1748789805)
Build Profile: maxperf

What version of Foundryup are you on?

foundryup: 1.0.1

What command(s) is the bug in?

forge test

Operating System

macOS (Apple Silicon)

Describe the bug

When compiling with --via-ir and --optimize true instances of vm.warp() yield unexpected results:

    function test_warping() public {
        uint256 startTime = block.timestamp;

        uint256[8] memory timestamps = [
            uint256(0),
            uint256(86400),
            uint256(604800),
            uint256(2678400),
            uint256(5184000),
            uint256(15811200),
            uint256(31536000),
            uint256(63072000)
        ];

        for (uint256 i = 0; i < timestamps.length; i++) {
            console2.log("Warping to: ", startTime + timestamps[i]);
            vm.warp(startTime + timestamps[i]);
            assertEq(block.timestamp, startTime + timestamps[i], "Warping failed");
        }
    }

When running with forge test -vv --via-ir --optimize false --match-test test_warping it succeeds. The tests fail with forge test -vv --via-ir --optimize true --match-test test_warping:

[FAIL: Warping failed: 86401 != 172801] test_warping() (gas: 10223)
Logs:
  Warping to:  1
  Warping to:  86401

Even when removing the assertEq, startTime + timestamps[i] yields an incorrect result. However, removing vm.warp() as well results in the correct logs. So it's something strange that is happening when using the vm.warp cheatcode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-bugType: bugT-needs-triageType: this issue needs to be labelled

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions