Skip to content
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

Audit-fix: Replaced EOA check from code length to tx origin comparison #61

Merged
merged 2 commits into from
Aug 30, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/timetravel/CallBreaker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ contract CallBreaker is CallBreakerStorage {
bytes calldata associatedData,
bytes calldata hintdices
) external payable onlyPortalClosed {
if (msg.sender.code.length != 0) {
if (msg.sender != tx.origin) {
revert MustBeEOA();
}
_setPortalOpen();
Expand Down
6 changes: 3 additions & 3 deletions test/CronCounter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract CronTest is Test, CronCounterLib {
function testrun1Cron() external {
uint256 laminatorSequenceNumber;

vm.startPrank(pusher);
vm.startPrank(pusher, pusher);
laminatorSequenceNumber = userLand();
vm.stopPrank();

Expand All @@ -45,15 +45,15 @@ contract CronTest is Test, CronCounterLib {
// go forward in time
vm.roll(block.number + 1);

vm.startPrank(filler);
vm.startPrank(filler, filler);

solverLand(laminatorSequenceNumber, filler, true);

vm.stopPrank();

vm.roll(block.number + 8000);

vm.startPrank(filler);
vm.startPrank(filler, filler);
solverLand(laminatorSequenceNumber, filler, false);
vm.stopPrank();

Expand Down
8 changes: 4 additions & 4 deletions test/FlashLiquidity.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ contract FlashLiquidityTest is Test, FlashLiquidityLib {
function testFlashLiquidity() external {
uint256 laminatorSequenceNumber;

vm.startPrank(pusher);
vm.startPrank(pusher, pusher);
laminatorSequenceNumber = userLand(100000000000000000000, 10, 1);
vm.stopPrank();

// go forward in time
vm.roll(block.number + 1);

vm.startPrank(filler);
vm.startPrank(filler, filler);
solverLand(1000, laminatorSequenceNumber, 1, filler);
vm.stopPrank();

Expand All @@ -54,14 +54,14 @@ contract FlashLiquidityTest is Test, FlashLiquidityLib {
function testFlashLiquiditySlippage() public {
uint256 laminatorSequenceNumber;

vm.startPrank(pusher);
vm.startPrank(pusher, pusher);
laminatorSequenceNumber = userLand(100000000000000000000, 80, 1);
vm.stopPrank();

// go forward in time
vm.roll(block.number + 1);

vm.startPrank(filler);
vm.startPrank(filler, filler);
vm.expectRevert();
solverLand(0, laminatorSequenceNumber, 1, filler); // No liquidity provided
vm.stopPrank();
Expand Down
46 changes: 23 additions & 23 deletions test/Laminator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ contract LaminatorTest is Test {
vm.expectEmit(true, true, true, true);
emit CallPulled(callObj1, 0);
emit DummyEvent(val1);
vm.prank(address(callBreaker));
vm.prank(address(callBreaker), address(callBreaker));
proxy.pull(0);

vm.expectEmit(true, true, true, true);
emit CallPulled(callObj2, 1);
emit DummyEvent(val2);
vm.prank(address(callBreaker));
vm.prank(address(callBreaker), address(callBreaker));
proxy.pull(1);
}

Expand All @@ -129,7 +129,7 @@ contract LaminatorTest is Test {
uint256 sequenceNumber = laminator.pushToProxy(cData, 0);
assertEq(sequenceNumber, 0);

vm.prank(address(callBreaker));
vm.prank(address(callBreaker), address(callBreaker));
// try pulls as a random address, make sure the events were emitted
vm.expectEmit(true, true, true, true);
emit CallPulled(callObj, 0);
Expand All @@ -151,7 +151,7 @@ contract LaminatorTest is Test {
assertEq(sequenceNumber, 0);

// try pulls, make sure it reverts
vm.prank(address(callBreaker));
vm.prank(address(callBreaker), address(callBreaker));
vm.expectRevert(LaminatedProxy.TooEarly.selector);
proxy.pull(0);
}
Expand All @@ -173,7 +173,7 @@ contract LaminatorTest is Test {
vm.roll(block.number + 1);

// try pulls, make sure it reverts
vm.prank(address(callBreaker));
vm.prank(address(callBreaker), address(callBreaker));
vm.expectRevert(LaminatedProxy.TooEarly.selector);
proxy.pull(0);
}
Expand All @@ -190,7 +190,7 @@ contract LaminatorTest is Test {
callvalue: abi.encodeWithSignature("emitArg(uint256)", val)
});
bytes memory cData = abi.encode(callObj);
vm.prank(randomFriendAddress);
vm.prank(randomFriendAddress, randomFriendAddress);
vm.expectRevert(LaminatedProxy.NotLaminatorOrProxy.selector);
proxy.push(cData, 0);
}
Expand All @@ -208,7 +208,7 @@ contract LaminatorTest is Test {
callvalue: abi.encodeWithSignature("emitArg(uint256)", val)
});
bytes memory cData = abi.encode(callObj);
vm.prank(address(laminator));
vm.prank(address(laminator), address(laminator));
vm.expectEmit(true, true, true, true);
emit CallPushed(callObj, 0);
proxy.push(cData, 1);
Expand All @@ -230,7 +230,7 @@ contract LaminatorTest is Test {
assertEq(sequenceNumber, 0);

// pull once
vm.prank(address(randomFriendAddress));
vm.prank(address(randomFriendAddress), address(randomFriendAddress));
vm.expectRevert(LaminatedProxy.NotCallBreaker.selector);
proxy.pull(0);
}
Expand Down Expand Up @@ -261,11 +261,11 @@ contract LaminatorTest is Test {

proxy.cancelAllPending();

vm.prank(address(callBreaker));
vm.prank(address(callBreaker), address(callBreaker));
vm.expectRevert(LaminatedProxy.AlreadyExecuted.selector);
proxy.pull(0);

vm.prank(address(callBreaker));
vm.prank(address(callBreaker), address(callBreaker));
vm.expectRevert(LaminatedProxy.AlreadyExecuted.selector);
proxy.pull(1);
}
Expand All @@ -286,7 +286,7 @@ contract LaminatorTest is Test {
assertEq(sequenceNumber, 0);

// pull once
vm.prank(address(randomFriendAddress));
vm.prank(address(randomFriendAddress), address(randomFriendAddress));
vm.expectRevert(LaminatedProxy.NotCallBreaker.selector);
proxy.pull(0);
}
Expand All @@ -307,11 +307,11 @@ contract LaminatorTest is Test {
assertEq(sequenceNumber, 0);

// pull once
vm.prank(address(callBreaker));
vm.prank(address(callBreaker), address(callBreaker));
proxy.pull(0);

// and try to pull again
vm.prank(address(callBreaker));
vm.prank(address(callBreaker), address(callBreaker));
vm.expectRevert(LaminatedProxy.AlreadyExecuted.selector);
proxy.pull(0);
}
Expand All @@ -337,7 +337,7 @@ contract LaminatorTest is Test {
assertEq(sequenceNumber, 0);

// try to pull out of order
vm.prank(address(callBreaker));
vm.prank(address(callBreaker), address(callBreaker));
vm.expectRevert(LaminatedProxy.Uninitialized.selector);
proxy.pull(1);
}
Expand All @@ -359,7 +359,7 @@ contract LaminatorTest is Test {

vm.roll(block.number + 1);

vm.prank(address(callBreaker));
vm.prank(address(callBreaker), address(callBreaker));
vm.expectRevert(LaminatedProxy.CallFailed.selector);
proxy.pull(0);
}
Expand All @@ -376,7 +376,7 @@ contract LaminatorTest is Test {
bytes memory cData = abi.encode(callObj);

// pretend to be a random address and call directly, should fail
vm.prank(randomFriendAddress);
vm.prank(randomFriendAddress, randomFriendAddress);
vm.expectRevert(LaminatedProxy.NotLaminator.selector);
proxy.execute(cData);
}
Expand All @@ -394,7 +394,7 @@ contract LaminatorTest is Test {
bytes memory cData = abi.encode(callObjs);

// pretend to be the laminator and call directly, should work
vm.prank(address(laminator));
vm.prank(address(laminator), address(laminator));
vm.expectEmit(true, true, true, true);
emit CallExecuted(callObjs[0]);
proxy.execute(cData);
Expand All @@ -412,7 +412,7 @@ contract LaminatorTest is Test {
});
bytes memory cData = abi.encode(callObj);

vm.prank(me);
vm.prank(me, me);
vm.expectRevert(LaminatedProxy.NotLaminator.selector);
proxy.execute(cData);
}
Expand Down Expand Up @@ -448,7 +448,7 @@ contract LaminatorTest is Test {
bytes memory cData = abi.encode(callObj);

// pretend to be a random address and call directly, should fail
vm.prank(randomFriendAddress);
vm.prank(randomFriendAddress, randomFriendAddress);
vm.expectRevert(LaminatedProxy.NotLaminator.selector);
proxy.execute(cData);
}
Expand All @@ -465,7 +465,7 @@ contract LaminatorTest is Test {
bytes memory cData = abi.encode(callObj);

// pretend to be laminator and call directly, should succeed
vm.prank(address(laminator));
vm.prank(address(laminator), address(laminator));
proxy.execute(cData);
}

Expand All @@ -481,7 +481,7 @@ contract LaminatorTest is Test {
bytes memory cData = abi.encode(callObj);
laminator.pushToProxy(cData, 0);

vm.prank(address(callBreaker));
vm.prank(address(callBreaker), address(callBreaker));
bytes memory returnValue = proxy.pull(0);
ReturnObject[] memory returnObj = abi.decode(returnValue, (ReturnObject[]));
CallObject memory returnCallObject = abi.decode(returnObj[0].returnvalue, (CallObject));
Expand All @@ -500,7 +500,7 @@ contract LaminatorTest is Test {
bytes memory cData = abi.encode(callObj);
laminator.pushToProxy(cData, 0);

vm.prank(address(callBreaker));
vm.prank(address(callBreaker), address(callBreaker));
bytes memory returnValue = proxy.pull(0);
ReturnObject[] memory returnObj = abi.decode(returnValue, (ReturnObject[]));
CallObjectHolder memory returnCallObjectHolder = abi.decode(returnObj[0].returnvalue, (CallObjectHolder));
Expand Down Expand Up @@ -528,7 +528,7 @@ contract LaminatorTest is Test {
assertEq(holder.callObjs.length, callObj1.length);

// pull one
vm.prank(address(callBreaker));
vm.prank(address(callBreaker), address(callBreaker));
proxy.pull(0);

// clean after pull clears executed call objects
Expand Down
4 changes: 2 additions & 2 deletions test/MEVTimeCompute.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ contract MEVTimeComputeTest is Test, MEVTimeComputeLib {
function testMEVTimeCompute() external {
uint256 laminatorSequenceNumber;

vm.startPrank(pusher);
vm.startPrank(pusher, pusher);
laminatorSequenceNumber = userLand();
vm.stopPrank();

// go forward in time
vm.roll(block.number + 1);

vm.startPrank(filler);
vm.startPrank(filler, filler);
solverLand(laminatorSequenceNumber, filler);
vm.stopPrank();

Expand Down
2 changes: 1 addition & 1 deletion test/NoopTurnerTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract NoopTurnerTest is Test {
bytes memory hintindices = abi.encode(hintdicesKeys, hintindicesVals);

// call verify
vm.prank(address(0xdeadbeef));
vm.prank(address(0xdeadbeef), address(0xdeadbeef));
callbreaker.verify(callObjsBytes, returnObjsBytes, encodedData, hintindices);
}
}
4 changes: 2 additions & 2 deletions test/PnP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ contract PnPTest is Test, PnPLib {
function testPnP() external {
uint256 laminatorSequenceNumber;

vm.startPrank(pusher);
vm.startPrank(pusher, pusher);
laminatorSequenceNumber = userLand();
vm.stopPrank();

// go forward in time
vm.roll(block.number + 1);

vm.startPrank(filler);
vm.startPrank(filler, filler);
solverLand(laminatorSequenceNumber, filler);
vm.stopPrank();

Expand Down
6 changes: 3 additions & 3 deletions test/Sandwich.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract CronTest is Test, CronCounterLib {
function testrun1Cron() external {
uint256 laminatorSequenceNumber;

vm.startPrank(pusher);
vm.startPrank(pusher, pusher);
laminatorSequenceNumber = userLand();
vm.stopPrank();

Expand All @@ -45,15 +45,15 @@ contract CronTest is Test, CronCounterLib {
// go forward in time
vm.roll(block.number + 1);

vm.startPrank(filler);
vm.startPrank(filler, filler);

solverLand(laminatorSequenceNumber, filler, true);

vm.stopPrank();

vm.roll(block.number + 8000);

vm.startPrank(filler);
vm.startPrank(filler, filler);
solverLand(laminatorSequenceNumber, filler, false);
vm.stopPrank();

Expand Down
4 changes: 2 additions & 2 deletions test/SelfCheckout.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ contract SelfCheckoutTest is Test, SelfCheckoutLib {
function test_selfCheckout() external {
uint256 laminatorSequenceNumber;

vm.startPrank(pusher);
vm.startPrank(pusher, pusher);
laminatorSequenceNumber = userLand();
vm.stopPrank();

// go forward in time
vm.roll(block.number + 1);

vm.startPrank(filler);
vm.startPrank(filler, filler);
solverLand(laminatorSequenceNumber, filler, 20);
vm.stopPrank();

Expand Down
8 changes: 4 additions & 4 deletions test/SlippageProtection.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ contract SlippageProtectionTest is Test, SlippageProtectionLib {
uint256 laminatorSequenceNumber;
uint256 maxSlippage = 10;

vm.startPrank(pusher);
vm.startPrank(pusher, pusher);
laminatorSequenceNumber = userLand(maxSlippage);
vm.stopPrank();

// go forward in time
vm.roll(block.number + 1);

vm.startPrank(filler);
vm.startPrank(filler, filler);
solverLand(laminatorSequenceNumber, filler, maxSlippage);
vm.stopPrank();

Expand All @@ -57,14 +57,14 @@ contract SlippageProtectionTest is Test, SlippageProtectionLib {
uint256 laminatorSequenceNumber;
uint256 maxSlippage = 1;

vm.startPrank(pusher);
vm.startPrank(pusher, pusher);
laminatorSequenceNumber = userLand(maxSlippage);
vm.stopPrank();

// go forward in time
vm.roll(block.number + 1);

vm.startPrank(filler);
vm.startPrank(filler, filler);
vm.expectRevert();
solverLand(laminatorSequenceNumber, filler, maxSlippage);
vm.stopPrank();
Expand Down
Loading