foundry
foundry copied to clipboard
SEVERE: --via-r in combination with vm.warp break solidity execution and overrides stack variables
Component
Forge
Have you ensured that all of these are up to date?
- [X] Foundry
- [X] Foundryup
What version of Foundry are you on?
forge 0.2.0 (503792a 2024-05-11T00:16:33.765886985Z)
What command(s) is the bug in?
forge test -vvv --via-r
Operating System
Linux
Describe the bug
I created a simple test to show the issue clearly:
event WarpTime(uint256 time);
function testWTF() public {
uint256 waitStep = 10000;
address user1 = vm.addr(1);
uint256 count = 6;
vm.startPrank(user1);
uint256 timestamp = block.timestamp;
for (uint256 i = 0; i < count; i++) {
uint256 step = i+1;
uint256 releaseTime = timestamp + (waitStep * step);
emit WarpTime(releaseTime);
}
//Validate that the iterations are not causing the bug
for (uint256 i = 0; i < count; i++) {
uint256 step = i+1;
uint256 releaseTime = timestamp + (waitStep * step);
emit WarpTime(releaseTime);
}
// Validate that warp time breaks the --via-r compilations
for (uint256 i = 0; i < count; i++) {
uint256 step = i+1;
uint256 releaseTime = timestamp + (waitStep * step);
vm.warp(releaseTime);
emit WarpTime(releaseTime);
}
//Intentionally fail to show the logs above
assertTrue(false);
vm.stopPrank();
}
Here are the logs from the test ran:
Traces:
[37530] AssetManagerTest::testWTF()
├─ [0] VM::addr(
As you can see from execution:
- vm.warp when executing under --via-r is cumulatively adding the previous block time to the warp after the first warp vm.warp(10001) = 10001 // sets the warp block + 10000 vm.warp(20001) = 30001 // sets the warp block + 10000 + 20000
- vm.warp is overriding the internal stack variable for releaseTime, as the Event is emitting the same value as the warp time.