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

Avoid zero value transfers #1014

Merged
merged 31 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6c5069c
feat: block zero transfers for pool tokens (simulate tokens that don'…
EndymionJkb Sep 19, 2024
90ff425
refactor: check amount > 0 in _sendTo, to prevent zero transfers
EndymionJkb Sep 19, 2024
f0cf956
Merge branch 'main' into zero-xfer-v2
EndymionJkb Sep 23, 2024
d5d0010
Merge branch 'main' into zero-xfer-v2
EndymionJkb Sep 26, 2024
6f69649
feat: protect router against zero transfers
EndymionJkb Sep 26, 2024
29b0de2
test: protect hooks against zero transfers
EndymionJkb Sep 26, 2024
ed9c989
chore: update bytecode
EndymionJkb Sep 26, 2024
175b654
chore: update gas
EndymionJkb Sep 26, 2024
68b527a
feat: also prevent 0 ETH transfers
EndymionJkb Sep 26, 2024
a148d76
chore: update bytecode
EndymionJkb Sep 26, 2024
7858591
chore: update gas
EndymionJkb Sep 26, 2024
1d89cfc
Merge branch 'main' into zero-xfer-v2
EndymionJkb Sep 26, 2024
08427db
Merge branch 'main' into zero-xfer-v2
EndymionJkb Sep 27, 2024
4e25851
Merge branch 'main' into zero-xfer-v2
EndymionJkb Sep 27, 2024
5a1199c
Merge branch 'main' into zero-xfer-v2
EndymionJkb Sep 28, 2024
87b44a3
refactor: revert change to main Vault - don't check in `sendTo` - try…
EndymionJkb Sep 29, 2024
106a93f
refactor: Router changes to avoid calling Vault functions that would …
EndymionJkb Sep 29, 2024
d85dcfd
chore: update bytecode
EndymionJkb Sep 29, 2024
8e148ac
refactor: avoid making Vault calls in the test framework that do zero…
EndymionJkb Sep 29, 2024
f70d306
test: update tests to avoid zero transfers
EndymionJkb Sep 29, 2024
b562bac
chore: update gas
EndymionJkb Sep 29, 2024
78a2808
lint
EndymionJkb Sep 29, 2024
51ec01c
refactor: don't need to check for zero transfer of weth
EndymionJkb Sep 29, 2024
976b94f
chore: update bytecode
EndymionJkb Sep 29, 2024
cd2c1b5
Merge branch 'main' into zero-xfer-v2
EndymionJkb Oct 1, 2024
40f6b35
refactor: don't call settle with 0
EndymionJkb Oct 1, 2024
99f8951
test: update settle in test
EndymionJkb Oct 1, 2024
0c3947b
chore: update bytecode
EndymionJkb Oct 1, 2024
4ed09f9
chore: update gas
EndymionJkb Oct 1, 2024
2ff038b
Merge branch 'main' into zero-xfer-v2
EndymionJkb Oct 1, 2024
1809aef
refactor: remove unnecessary checks
EndymionJkb Oct 1, 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
2 changes: 2 additions & 0 deletions pkg/interfaces/contracts/test/IVaultMainMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ interface IVaultMainMock {

function manualSetBufferTotalShares(IERC4626 wrappedToken, uint256 shares) external;

function manualSetBufferBalances(IERC4626 wrappedToken, uint256 underlyingAmount, uint256 wrappedAmount) external;

function manualSettleReentrancy(IERC20 token) external returns (uint256 paid);

function manualSendToReentrancy(IERC20 token, address to, uint256 amount) external;
Expand Down
18 changes: 11 additions & 7 deletions pkg/pool-hooks/contracts/MinimalRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ abstract contract MinimalRouter is RouterCommon, ReentrancyGuardTransient {
IERC20 token = tokens[i];
uint256 amountIn = amountsIn[i];

if (amountIn == 0) {
continue;
}

// There can be only one WETH token in the pool.
if (params.wethIsEth && address(token) == address(_weth)) {
if (address(this).balance < amountIn) {
Expand Down Expand Up @@ -222,26 +226,26 @@ abstract contract MinimalRouter is RouterCommon, ReentrancyGuardTransient {
// minAmountsOut length is checked against tokens length at the Vault.
IERC20[] memory tokens = _vault.getPoolTokens(params.pool);

uint256 ethAmountOut = 0;
for (uint256 i = 0; i < tokens.length; ++i) {
uint256 amountOut = amountsOut[i];

if (amountOut == 0) {
continue;
}

IERC20 token = tokens[i];

// There can be only one WETH token in the pool.
if (params.wethIsEth && address(token) == address(_weth)) {
// Send WETH here and unwrap to native ETH.
_vault.sendTo(_weth, address(this), amountOut);
_weth.withdraw(amountOut);
ethAmountOut = amountOut;
// Send ETH to receiver.
payable(params.receiver).sendValue(amountOut);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 good idea.

} else {
// Transfer the token to the receiver (amountOut).
_vault.sendTo(token, params.receiver, amountOut);
}
}

if (ethAmountOut > 0) {
// Send ETH to receiver.
payable(params.receiver).sendValue(ethAmountOut);
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
301.9k
302.1k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
245.5k
245.6k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
340.7k
333.0k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
266.9k
259.2k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
214.6k
196.4k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
199.2k
181.0k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
214.1k
194.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
233.5k
213.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
195.3k
195.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
181.4k
181.6k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
179.6k
179.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
192.6k
172.1k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
214.4k
214.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
168.0k
167.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
181.9k
166.9k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
191.7k
176.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
179.4k
179.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
165.5k
165.6k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
236.3k
218.2k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
220.9k
202.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
235.6k
216.0k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
255.0k
235.3k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
228.6k
228.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
198.2k
198.4k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
235.0k
235.1k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
211.8k
193.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
223.2k
222.9k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
200.9k
188.4k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
210.6k
198.2k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
212.7k
212.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
182.3k
182.4k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
178.4k
178.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
347.6k
347.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
335.1k
335.2k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
296.8k
297.0k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
232.0k
232.1k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
327.2k
319.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
253.5k
245.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
208.3k
190.2k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
185.9k
167.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
200.9k
181.3k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
233.6k
213.9k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
185.0k
185.1k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
167.9k
168.0k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
179.6k
179.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
179.3k
158.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
168.0k
167.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
168.6k
153.6k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
191.7k
176.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
169.1k
169.2k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
152.0k
152.1k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
230.1k
212.0k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
207.7k
189.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
222.4k
202.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
255.1k
235.4k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
218.3k
218.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
184.1k
184.3k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
235.0k
235.1k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
198.6k
180.6k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
229.7k
229.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
223.2k
222.9k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
187.6k
175.1k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
210.7k
198.3k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
202.4k
202.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
168.2k
168.3k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
178.4k
178.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
348.9k
349.0k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
336.4k
336.5k
Loading
Loading