Closed sherlock-admin closed 2 years ago
I think that it's a medium vulnerability (user funds are not affected by this and fees are harvested from time to time anyway in the normal flow of operation). But, regardless -- this issue has a valid point.
berndartmueller
high
Collected fees can be used by anyone to top-up
Summary
Anyone can use collected fees by the
ExchangeProxy
contract to top-up by providing arbitrary call data to the swap contract.Vulnerability Detail
The
ExchangeProxy
contract collects swap fees and keeps them in escrow for later withdrawal by the yield distributor. However, an attacker is able to provide arbitrary_convertData
in theHardenedTopupProxy.CardTopupPermit
function. This parameter is used and passed on to theExchangeProxy.executeSwapDirect
function without validation. Then it is used to call theexecutorAddress
to do the token swap. Hence, it's possible to instruct the swap contract to swap the collected fees from theExchangeProxy
contract instead of only swapping the tokens provided by the user (the spending allowance is set to the maximum allowance before in line 156)Impact
An attacker can use the residual token balances (i.e. collected fees) from the
ExchangeProxy
contract as the amount for the top-up.Code Snippet
To demonstrate this issue, use the provided test case
can use fees from exchange proxy for topup
in https://gist.github.com/berndartmueller/5cfa9d784a32ecba92eb6abaf4d464d9. Copy the test file intotest/ExploitTopup.test.js
and runtruffle test
. It demonstrates how an attacker can use 10 DAI to receive a top-up worth 900e6 USDC (collected fees).ExchangeProxy.sol#L174
Tool Used
Manual Review
Recommendation
Consider validating the spent amount of the ERC-20 token
_tokenFrom
to equal the desired swap_amount
in theExchangeProxy.executeSwapDirect
function. This prevents swapping more than the provided_amount
function parameter.Duplicate of #112