hats-finance / SafeStaking-by-HOPR-0x607386df18b663cf5ee9b879fbc1f32466ad5a85

HOPR is an open incentivized mixnet which enables privacy-preserving point-to-point data exchange. HOPR is similar to Tor but actually private, decentralized and economically sustainable.
https://hoprnet.org
GNU General Public License v3.0
0 stars 1 forks source link

`reclaimErc20Tokens()` can take out REWARD_TOKEN #13

Open hats-bug-reporter[bot] opened 12 months ago

hats-bug-reporter[bot] commented 12 months ago

Github username: @9olidity Submission hash (on-chain): 0x952e8f7eda8b4491a1d2d95c89e1659a595541d8f82c9462e3cc2fa3ccf483d4 Severity: high

Description: Description\ The function of HoprStake::reclaimErc20Tokens() function is

Reclaim any ERC20 token being accidentally sent to the contract.

However, the function only determines whether the token is LOCK_TOKEN, and does not determine whether the token is REWARD_TOKEN. If the administrator takes out the REWARD_TOKEN in the contract, the _claim() function will not be able to execute normally due to the insufficient number of REWARD_TOKEN in the contract.

This situation is possible. After all, the function considers the situation when tokenaddress is LOCK_TOKEN.

Attack Scenario\

When the administrator executes the reclaimErc20Tokens() function and the input tokenAddress is the REWARD_TOKENaddress

Attachments

  1. Proof of Concept (PoC) File

When the administrator executes the reclaimErc20Tokens() function and the input tokenAddress is the REWARD_TOKENaddress

  1. Revised Code File (Optional)
    // File: HoprStake.sol
    function reclaimErc20Tokens(address tokenAddress) external onlyOwner nonReentrant {
    uint256 difference;
    +   require(tokenAddress != REWARD_TOKEN);
    if (tokenAddress == LOCK_TOKEN) {
      difference = IERC20(LOCK_TOKEN).balanceOf(address(this)) - totalLocked;
    } else {
      difference = IERC20(tokenAddress).balanceOf(address(this)); 
    }
    IERC20(tokenAddress).safeTransfer(owner(), difference);
    }
QYuQianchen commented 11 months ago

This is expected as the owner can take out excessive unclaimed reward tokens to adjust error in calculation.