-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Capacity Overflow During Invariant Testing #6666
Comments
I am also experiencing this issue with an invariant test. Update: FYI I changed ComponentForge Have you ensured that all of these are up to date?
What version of Foundry are you on?forge 0.2.0 (nightly-67ab8704476d55e47545cf6217e236553c427a80) What command(s) is the bug in?forge test Operating SystemmacOS (Apple Silicon) Describe the bug
|
I'm on an M1 macOS (Apple Silicon). If I change my assertion from Getting this error as well:
If I move a specific invariant test it goes away. This invariant test is being inherited from an abstract contract into two different test contracts. One of the test contracts works. The other does not. |
Versions:
I am also experiencing a similar error, when I am trying to play with the variables in
I am using below command Below are my code files Invariant_2.t.sol pragma solidity ^0.8.22;
import "forge-std/Test.sol";
import {Handler} from "../src/InvariantHandler.sol";
import {WETH} from "../src/WETH.sol";
contract InvariantHandlerTest is Test {
WETH private weth;
Handler private handler;
function setUp() public {
weth = new WETH();
handler = new Handler(weth);
deal(address(handler), 100 ether);
targetContract(address(handler));
}
function invariant_WETH_ETH_balance_should_be_greater_than_or_equal_to_eth_deposited_by_Hanlder() public {
assertGe(address(weth).balance, weth.balanceOf(address(handler)) + 5);
}
} When I add InvariantHandler.sol pragma solidity ^0.8.22;
import {WETH} from "./WETH.sol";
import {CommonBase} from "forge-std/Base.sol";
import {StdCheats} from "forge-std/StdCheats.sol";
import {StdUtils} from "forge-std/StdUtils.sol";
contract Handler is CommonBase, StdCheats, StdUtils {
WETH private weth;
constructor(WETH _weth) {
weth = _weth;
}
receive() external payable {}
function deposit(uint256 _amount) public {
_amount = bound(_amount, 0, address(this).balance);
weth.deposit{value: _amount}();
}
function withdraw(uint256 _amount) public {
_amount = bound(_amount, 0, weth.balanceOf(address(this)));
weth.withdraw(_amount);
}
function sendToFallback(uint256 _amount) public {
_amount = bound(_amount, 0, address(this).balance);
(bool success,) = address(weth).call{value: _amount}("");
require(success, "ETH send to fallback failed");
}
} WETH.sol pragma solidity ^0.8.22;
contract WETH {
string public name = "Wrapped Ether";
string public symbol = "WETH";
uint8 public decimals = 18;
event Approval(address indexed src, address indexed guy, uint256 wad);
event Transfer(address indexed src, address indexed dst, uint256 wad);
event Deposit(address indexed dst, uint256 wad);
event Withdrawal(address indexed src, uint256 wad);
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
receive() external payable {
deposit();
}
function deposit() public payable {
balanceOf[msg.sender] += msg.value;
emit Deposit(msg.sender, msg.value);
}
function withdraw(uint256 wad) public {
balanceOf[msg.sender] -= wad;
payable(msg.sender).transfer(wad);
emit Withdrawal(msg.sender, wad);
}
function totalSupply() public view returns (uint256) {
return address(this).balance;
}
function approve(address guy, uint256 wad) public returns (bool) {
allowance[msg.sender][guy] = wad;
emit Approval(msg.sender, guy, wad);
return true;
}
function transfer(address dst, uint256 wad) public returns (bool) {
return transferFrom(msg.sender, dst, wad);
}
function transferFrom(address src, address dst, uint256 wad)
public
returns (bool)
{
if (
src != msg.sender && allowance[src][msg.sender] != type(uint256).max
) {
allowance[src][msg.sender] -= wad;
}
balanceOf[src] -= wad;
balanceOf[dst] += wad;
emit Transfer(src, dst, wad);
return true;
}
} |
tysm for the repro @m-waqas88 ! with that I was able to track this down #6819 of course #6666 is a very cursed issue -.- |
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (67ab870 2023-12-25T00:25:37.702950000Z)
What command(s) is the bug in?
forge test
Operating System
macOS (Apple Silicon)
Describe the bug
During invariant testing (with a fork), if I were to add a console log or an extra operation such as a simple
balanceOf
the errorcapacity overflow
would show up. I would then have to play with removing/rearranging certain lines or modifying runs/depth to get the invariant test to run.The text was updated successfully, but these errors were encountered: