H-1: WBTC18 swap uses wrong amount variable
Summary:
An incorrect variable is used in the final swap operation of the _swap_to function in wbtc18.vy, causing the swap to use the original input amount instead of the intermediate swap result.
Description:
In wbtc18.vy, the _swap_to function uses the variable amount instead of amount_out in the final swap operation:
File: wbtc18.vy
177: amount_out = curve_tricrypto.swap(
178: TBTC_INDEX_TRICRYPTO,
179: CRVUSD_INDEX_TRICRYPTO,
180: amount,
181: TRICRYPTO_POOL,
182: msg.sender,
183: )
The swap chain should be: WBTC18 → WBTC → tBTC → crvUSD, where each step uses the output from the previous step as input.
Impact:
High.
- Transaction failure: If the tBTC amount received from the WBTC→tBTC swap is less than the original WBTC18 input amount, the final tBTC→crvUSD swap will attempt to use more tBTC than available, causing the transaction to revert.
- Funds stuck on contract: If the tBTC amount received is greater than the original WBTC18 input amount, only a portion of the tBTC will be swapped, leaving the remainder trapped on the contract and resulting in a loss for the user.
Recommendation:
Change line 180 in src/exchanges/wbtc18.vy
- 180 amount,
+ 180 amount_out
Developer Response:
Fixed in: 2224877.