code-423n4 / 2022-05-backd-findings

0 stars 0 forks source link

Attacker can get drain ETH for `targetLpToken_` #119

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Lines of code

https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/FeeBurner.sol#L56-L65

Vulnerability details

Impact

Attacker can drain all ETH from FeeBurner.sol. (Technically msg.value gets sent to swapperRouter_, but since this contract is out of scope FeeBurner.sol will be treated as the victim)

Proof of Concept

FeeBurner.sol#L56-L65

...
for (uint256 i; i < tokens_.length; i = i.uncheckedInc()) {
    IERC20 token_ = IERC20(tokens_[i]);

    // Handling ETH
    if (address(token_) == address(0)) {
        if (msg.value == 0) continue;
        burningEth_ = true;
        swapperRouter_.swapAll{value: msg.value}(address(token_), _WETH);
        continue;
    } 
...

Attacker can pass an address[] memory tokens_ array containing multiple address(0). The same msg.value will be reused for every iteration, leading to the contract having to use its own balance to fulfil the swapAll transactions.

Example:

Attacker can make the token input array as big as necessary to drain all ether from contract.

Tools Used

Manual Review

Recommended Mitigation Steps

Implement a separate function for processing ether (or any other native token) and make sure the msg.value is not reused under a for loop.

chase-manning commented 2 years ago

The FeeBurner doesn't hold any ETH as part of normal use. If someone randomly transfers ETH to the contract, it's fine if some random gets it.

GalloDaSballo commented 2 years ago

The second call will fail as there will be no ETH to send to the SwapperRouter, for that reason I believe the finding to be invalid