Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/StdStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ library stdStorageSafe {

Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
uint256 constant UINT256_MAX = 115792089237316195423570985008687907853269984665640564039457584007913129639935;
uint256 constant MAX_SLOT_READS = 256;

function sigs(string memory sigStr) internal pure returns (bytes4) {
return bytes4(keccak256(bytes(sigStr)));
Expand Down Expand Up @@ -123,7 +124,8 @@ library stdStorageSafe {
if (reads.length == 0) {
revert("stdStorage find(StdStorage): No storage use detected for target.");
} else {
for (uint256 i = reads.length; i > 0;) {
uint256 start = reads.length > MAX_SLOT_READS ? reads.length - MAX_SLOT_READS : 0;
for (uint256 i = reads.length; i > start;) {
--i;
bytes32 prev = vm.load(who, reads[i]);
if (prev == bytes32(0)) {
Expand Down
9 changes: 9 additions & 0 deletions test/StdStorage.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,15 @@ contract StdStorageTest is Test {
vm.expectRevert("stdStorage find(StdStorage): Slot(s) not found.");
target.findBalanceOf(address(this));
}

// Fork regression test for https://github.com/foundry-rs/forge-std/issues/740
// BabyDoge on BSC is a reflection token whose `balanceOf` reads many slots.
// Before the fix, `deal()` would hang indefinitely.
function test_RevertDealReflectionTokenFork() public {
vm.createSelectFork("https://bsc-rpc.publicnode.com");
vm.expectRevert("stdStorage find(StdStorage): Slot(s) not found.");
deal(0xc748673057861a797275CD8A068AbB95A902e8de, address(this), 1 ether);
}
}

contract StorageTestTarget {
Expand Down
Loading