Skip to content

Commit 9398ced

Browse files
committed
Merge branch 'master' into feat/memory-fixed-size-stack
2 parents 1c5a684 + f9f7db0 commit 9398ced

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

contracts/utils/FixedSizeMemoryStack.sol

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ library FixedSizeMemoryStack {
4949
uint256 t = stack._top;
5050
if (t >= stack._data.length) revert StackOverflow(stack._data.length);
5151
stack._data[t] = value;
52-
unchecked {
53-
stack._top = t + 1;
54-
}
52+
stack._top = t + 1;
5553
}
5654

5755
/// @notice Pop the top value from the stack.
@@ -60,9 +58,7 @@ library FixedSizeMemoryStack {
6058
function pop(Stack memory stack) internal pure returns (bytes32 value) {
6159
uint256 t = stack._top;
6260
if (t == 0) revert StackUnderflow();
63-
unchecked {
64-
t -= 1;
65-
}
61+
t -= 1;
6662
value = stack._data[t];
6763
stack._top = t;
6864
}

test/utils/Blockhash.t.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ contract BlockhashTest is Test {
6767
function testFuzzFutureBlocks(uint256 offset, uint256 currentBlock) public {
6868
// Future blocks
6969
offset = bound(offset, 1, type(uint256).max);
70+
currentBlock = bound(currentBlock, 0, type(uint256).max - offset);
7071
vm.roll(currentBlock);
7172

7273
unchecked {

test/utils/FixedSizeMemoryStack.t.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ contract FixedSizeMemoryStackTest is Test, SymTest {
3636
}
3737

3838
/// forge-config: default.allow_internal_expect_revert = true
39-
function testPeek() public {
39+
function testPeekStackUnderflow() public {
4040
FixedSizeMemoryStack.Stack memory stack = FixedSizeMemoryStack.init(10);
4141

4242
vm.expectRevert(abi.encodeWithSelector(FixedSizeMemoryStack.StackUnderflow.selector));
4343
stack.peek();
4444
assertEq(stack._top, 0);
45+
}
46+
47+
function testPeek() public {
48+
FixedSizeMemoryStack.Stack memory stack = FixedSizeMemoryStack.init(10);
4549

4650
stack.push(bytes32(uint256(1)));
4751
stack.push(bytes32(uint256(2)));

0 commit comments

Comments
 (0)