sherlock-audit / 2023-02-surge-judging

4 stars 1 forks source link

gryphon - Risk of market prices manipulation #264

Closed github-actions[bot] closed 1 year ago

github-actions[bot] commented 1 year ago

gryphon

medium

Risk of market prices manipulation

Summary

The pool uses the LOAN_TOKEN.balanceOf(address(this)) to get the balance of LOAN_TOKENS on the pool. But the Loan tokens are supposed to be deposited or withdrawn from the pool. But Loan Token is an external token, then there is other means of depositing tokens on the pool, like simple calling transfer on the external token itself pointing the to address to the pool. The balance then will decrease the amount of user shares on the pool.

Vulnerability Detail

1 - one user transfer external Loan Tokens to the pool. 2 - when another user calls deposit of withdraw the amount of _shares will be decreased.

Impact

Wrong computation of _shares due to misleading balance of Loan Tokens.

Code Snippet

Pool.sol#L348

    function withdraw(uint amount) external {
        uint _loanTokenBalance = LOAN_TOKEN.balanceOf(address(this)); 
        ...
   }

Pool.sol#L307

    function deposit(uint amount) external {
        uint _loanTokenBalance = LOAN_TOKEN.balanceOf(address(this)); 
        ...
    }

Tool used

Manual Review

Recommendation

Keeping track of the balance of Loan Tokens of the pool by using an state variable, i.e.: uint256 externalTokenBalance; and increases the balance on deposit and decrease the balance on withdrawals.

Duplicate of #125