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

Middleware protect #152

Open
wants to merge 54 commits into
base: middleware-remove
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
128aacf
create outline
Jun1on Jul 15, 2024
6801684
add liquidity protection
Jun1on Jul 15, 2024
5e6c2ae
add quoter check in beforeswap
Jun1on Jul 15, 2024
9f6788e
increase foundry gas_limit
Jun1on Jul 16, 2024
e3ad3c7
forge fmt
Jun1on Jul 16, 2024
d3e40ff
add function to handle errors
Jun1on Jul 16, 2024
052f21d
enforce implementation address mined
Jun1on Jul 16, 2024
71962b1
fix error bug
Jun1on Jul 17, 2024
9a60e41
bring back random function
Jun1on Jul 17, 2024
daf74ce
Recipient mapping! (#246)
hensha256 Aug 2, 2024
fdf28e4
allow batching sig based approvals through p2 forwarder (#238)
snreynolds Aug 2, 2024
ebf7a4d
Take portion (#250)
hensha256 Aug 2, 2024
30863cc
Pay with balance, and use delta as amount in (#249)
hensha256 Aug 2, 2024
a9e463d
Settle pair (#242)
dianakocsis Aug 2, 2024
e764aec
posm: add staking through subscribers (#229)
snreynolds Aug 2, 2024
912536c
make msgSender public (#253)
hensha256 Aug 2, 2024
eee5a0e
posm: CLEAR_OR_TAKE (#252)
saucepoint Aug 2, 2024
6fe5428
TAKE_PAIR (#254)
dianakocsis Aug 3, 2024
1f28ac2
ERC721Permit (#210)
saucepoint Aug 3, 2024
2f15bb2
Take (#257)
snreynolds Aug 3, 2024
86b5ea3
multicall: bubble up revert reason (#236)
saucepoint Aug 4, 2024
d65f158
Optimise permit hashing (#260)
hensha256 Aug 4, 2024
0c956bf
Replace OZ EIP712 (#256)
saucepoint Aug 4, 2024
60a983e
Take command in router (#261)
hensha256 Aug 4, 2024
dfa1865
posm: Rename File Collisions (#263)
saucepoint Aug 4, 2024
2d07bd4
Align constants with UR (#267)
hensha256 Aug 4, 2024
e2d2508
One BPS library (#268)
hensha256 Aug 4, 2024
eb0cf58
slippage params routing (#264)
hensha256 Aug 4, 2024
41bbc7d
add liquidity view (#270)
snreynolds Aug 4, 2024
ea5f9ec
add bytes, clean up compiliation (#269)
snreynolds Aug 4, 2024
f402aa7
actions with no unlock (#231)
hensha256 Aug 5, 2024
d1f9005
ERC721Permit - PermitForAll (#271)
saucepoint Aug 5, 2024
3b93674
Wrap reverts thrown by subscribers (#273)
gretzke Aug 5, 2024
df47aa9
Some cleanup (#276)
snreynolds Aug 5, 2024
20718d5
Make PositionManager.transferFrom virtual (#278)
brockmiller Aug 5, 2024
cf4e2ad
Use custom revert (#277)
snreynolds Aug 5, 2024
af688af
add mint position event (#279)
snreynolds Aug 5, 2024
bf3b8ad
Provide feesAccrued to subscriber.notifyModifyLiquidity (#282)
saucepoint Aug 6, 2024
17f1a49
OZ: posm - restore permissioning on increase (#290)
saucepoint Aug 7, 2024
7cad2f6
fix: slippage checks (#285)
snreynolds Aug 8, 2024
b890da6
nit: make multicall external (#292)
snreynolds Aug 8, 2024
4d56687
OZ: Remove contract balance swap input (#286)
hensha256 Aug 8, 2024
469f856
move sub unsub (#287)
snreynolds Aug 8, 2024
5ad4439
add view quoter
Jun1on Aug 8, 2024
656afa4
Merge branch 'middleware-remove' into middleware-protect
Jun1on Aug 9, 2024
05ad967
uninheret from middleware-remove
Jun1on Aug 13, 2024
54c12c8
add gas tests with revert quoter
Jun1on Aug 13, 2024
4ad5a3f
Merge branch 'view-quoter' into middleware-protect
Jun1on Aug 13, 2024
8139431
forge test --isolate
Jun1on Aug 13, 2024
81e9692
use view quoter
Jun1on Aug 13, 2024
3f69c05
optimize quoter
Jun1on Aug 13, 2024
6632806
update docs
Jun1on Aug 14, 2024
cea56de
use tstore
Jun1on Aug 15, 2024
5eec68a
update gas snapshots
Jun1on Aug 15, 2024
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
Prev Previous commit
Next Next commit
multicall: bubble up revert reason (#236)
* wip bubble up revert

* fix formatting

* simple bubble

* test different error types on multicall

* additional testing for external contract reverts

* example core revert bubbling

* testing for different lengths

* cleanup

* cleanup unused imports

* delete stale gas

* minor nits
  • Loading branch information
saucepoint authored Aug 4, 2024
commit 86b5ea3b51ea8b6727690deb280f5a16bc887063
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_burn_empty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
47186
47184
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_burn_empty_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
47004
47001
Original file line number Diff line number Diff line change
@@ -1 +1 @@
123058
123056
Original file line number Diff line number Diff line change
@@ -1 +1 @@
122756
122754
Original file line number Diff line number Diff line change
@@ -1 +1 @@
130136
130134
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129835
129832
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
141409
141406
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
150257
150254
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_withClose.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
150257
150254
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_withTakePair.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
149868
149865
Original file line number Diff line number Diff line change
@@ -1 +1 @@
108602
108600
Original file line number Diff line number Diff line change
@@ -1 +1 @@
115800
115797
Original file line number Diff line number Diff line change
@@ -1 +1 @@
115411
115408
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_decrease_burnEmpty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134196
134193
Original file line number Diff line number Diff line change
@@ -1 +1 @@
126935
126932
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128516
128513
Original file line number Diff line number Diff line change
@@ -1 +1 @@
152363
152360
Original file line number Diff line number Diff line change
@@ -1 +1 @@
151604
151601
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134163
134160
Original file line number Diff line number Diff line change
@@ -1 +1 @@
130328
130325
Original file line number Diff line number Diff line change
@@ -1 +1 @@
171022
171019
Original file line number Diff line number Diff line change
@@ -1 +1 @@
141002
140999
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
336841
336838
Original file line number Diff line number Diff line change
@@ -1 +1 @@
345370
345367
Original file line number Diff line number Diff line change
@@ -1 +1 @@
344911
344908
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickLower.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
314823
314820
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickUpper.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
315465
315462
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
241047
241044
Original file line number Diff line number Diff line change
@@ -1 +1 @@
371193
371190
Original file line number Diff line number Diff line change
@@ -1 +1 @@
320841
320838
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_withClose.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
372141
372138
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_withSettlePair.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
371520
371517
Original file line number Diff line number Diff line change
@@ -1 +1 @@
416516
416513
12 changes: 2 additions & 10 deletions src/base/Multicall.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,10 @@ abstract contract Multicall is IMulticall {
(bool success, bytes memory result) = address(this).delegatecall(data[i]);

if (!success) {
// handle custom errors
if (result.length == 4) {
assembly {
revert(add(result, 0x20), mload(result))
}
}
// Next 5 lines from https://ethereum.stackexchange.com/a/83577
if (result.length < 68) revert();
// bubble up the revert reason
assembly {
result := add(result, 0x04)
revert(add(result, 0x20), mload(result))
}
revert(abi.decode(result, (string)));
}

results[i] = result;
Expand Down
117 changes: 113 additions & 4 deletions test/Multicall.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.20;

import "forge-std/Test.sol";
import {MockMulticall} from "./mocks/MockMulticall.sol";
import {MockMulticall, RevertContract} from "./mocks/MockMulticall.sol";

contract MulticallTest is Test {
MockMulticall multicall;
Expand Down Expand Up @@ -30,7 +30,7 @@ contract MulticallTest is Test {
function test_multicall_firstRevert() public {
bytes[] memory calls = new bytes[](2);
calls[0] =
abi.encodeWithSelector(MockMulticall(multicall).functionThatRevertsWithError.selector, "First call failed");
abi.encodeWithSelector(MockMulticall(multicall).functionThatRevertsWithString.selector, "First call failed");
calls[1] = abi.encodeWithSelector(MockMulticall(multicall).functionThatReturnsTuple.selector, 1, 2);

vm.expectRevert("First call failed");
Expand All @@ -40,8 +40,9 @@ contract MulticallTest is Test {
function test_multicall_secondRevert() public {
bytes[] memory calls = new bytes[](2);
calls[0] = abi.encodeWithSelector(MockMulticall(multicall).functionThatReturnsTuple.selector, 1, 2);
calls[1] =
abi.encodeWithSelector(MockMulticall(multicall).functionThatRevertsWithError.selector, "Second call failed");
calls[1] = abi.encodeWithSelector(
MockMulticall(multicall).functionThatRevertsWithString.selector, "Second call failed"
);

vm.expectRevert("Second call failed");
multicall.multicall(calls);
Expand Down Expand Up @@ -106,4 +107,112 @@ contract MulticallTest is Test {
assertEq(multicall.msgValue(), 100);
assertEq(multicall.msgValueDouble(), 200);
}

// revert bubbling
function test_multicall_bubbleRevert_string() public {
bytes[] memory calls = new bytes[](1);
calls[0] =
abi.encodeWithSelector(MockMulticall(multicall).functionThatRevertsWithString.selector, "errorString");

vm.expectRevert("errorString");
multicall.multicall(calls);
}

function test_multicall_bubbleRevert_4bytes() public {
bytes[] memory calls = new bytes[](1);
calls[0] = abi.encodeWithSelector(MockMulticall(multicall).revertWith4Bytes.selector);

// revert is caught
vm.expectRevert(MockMulticall.Error4Bytes.selector);
multicall.multicall(calls);

// confirm expected length of the revert
try multicall.revertWith4Bytes() {}
catch (bytes memory reason) {
assertEq(reason.length, 4);
}
}

function test_fuzz_multicall_bubbleRevert_36bytes(uint8 num) public {
bytes[] memory calls = new bytes[](1);
calls[0] = abi.encodeWithSelector(MockMulticall(multicall).revertWith36Bytes.selector, num);

// revert is caught
vm.expectRevert(abi.encodeWithSelector(MockMulticall.Error36Bytes.selector, num));
multicall.multicall(calls);

// confirm expected length of the revert
try multicall.revertWith36Bytes(num) {}
catch (bytes memory reason) {
assertEq(reason.length, 36);
}
}

function test_fuzz_multicall_bubbleRevert_68bytes(uint256 a, uint256 b) public {
bytes[] memory calls = new bytes[](1);
calls[0] = abi.encodeWithSelector(MockMulticall(multicall).revertWith68Bytes.selector, a, b);

// revert is caught
vm.expectRevert(abi.encodeWithSelector(MockMulticall.Error68Bytes.selector, a, b));
multicall.multicall(calls);

// confirm expected length of the revert
try multicall.revertWith68Bytes(a, b) {}
catch (bytes memory reason) {
assertEq(reason.length, 68);
}
}

function test_fuzz_multicall_bubbleRevert_arbitraryBytes(uint16 length) public {
length = uint16(bound(length, 0, 4096));
bytes memory data = new bytes(length);
for (uint256 i = 0; i < data.length; i++) {
data[i] = bytes1(uint8(i));
}

bytes[] memory calls = new bytes[](1);
calls[0] = abi.encodeWithSelector(MockMulticall(multicall).revertWithBytes.selector, data);

// revert is caught
vm.expectRevert(abi.encodeWithSelector(MockMulticall.ErrorBytes.selector, data));
multicall.multicall(calls);

// confirm expected length of the revert
try multicall.revertWithBytes(data) {}
catch (bytes memory reason) {
// errors with 0 bytes are by default 64 bytes of data (length & pointer?) + 4 bytes of selector
if (length == 0) {
assertEq(reason.length, 68);
} else {
uint256 expectedLength = 64 + 4; // default length + selector
// 32 bytes added to the reason for each 32 bytes of data
expectedLength += (((data.length - 1) / 32) + 1) * 32;
assertEq(reason.length, expectedLength);
}
}
}

function test_multicall_bubbleRevert_externalRevertString() public {
bytes[] memory calls = new bytes[](2);
calls[0] = abi.encodeWithSelector(MockMulticall(multicall).externalRevertString.selector, "errorString");

vm.expectRevert("errorString");
multicall.multicall(calls);
}

function test_multicall_bubbleRevert_externalRevertSimple() public {
bytes[] memory calls = new bytes[](1);
calls[0] = abi.encodeWithSelector(MockMulticall(multicall).externalRevertError1.selector);

vm.expectRevert(RevertContract.Error1.selector);
multicall.multicall(calls);
}

function test_multicall_bubbleRevert_externalRevertWithParams(uint256 a, uint256 b) public {
bytes[] memory calls = new bytes[](1);
calls[0] = abi.encodeWithSelector(MockMulticall(multicall).externalRevertError2.selector, a, b);

vm.expectRevert(abi.encodeWithSelector(RevertContract.Error2.selector, a, b));
multicall.multicall(calls);
}
}
Loading
Loading