code4rena-2021-06-pooltogether-m03

[M-03] SafeMath not completely used in yield source contracts

보고서

Summary

solidity 0.8 이전 버전을 이용하면서 SafeMath를 사용하지 않아 오버/언더플로우의 위험이 있다.

Keyword

overflow/underflow, safemath

Vulnerability

solidity 0.8 이전 버전을 이용하며 연산에 SafeMath를 적용하지 않은 연산이 있어 지적했다.

SushiYieldSource 컨트랙트에서 share 연산시 SafeMath가 아닌 + 로 직접 사용하여 연산했다.

  function redeemToken(uint256 amount) public override returns (uint256) {
    ...
    uint256 requiredShares = ((amount.mul(totalShares) + totalShares)).div(barSushiBalance);
  }

BadgerYieldSource 컨트랙트도 마찬가지로 share 연산시 SafeMath를 사용하지 않았다.

  function redeemToken(uint256 amount) public override returns (uint256) {
    ...
    uint256 requiredShares =
      ((amount.mul(totalShares) + totalShares)).div(
        badgerSettBadgerBalance
      );
  }

IdleYieldSource 컨트랙트에서도 share 연산시 SafeMath를 사용하지 않았다. (다만 보고서에서는 이 컨트랙트를 지적했지만 이 컨트랙트는 solidity 0.8 이상이므로 취약하지 않을것이다.)

  function _tokenToShares(uint256 tokens) internal view returns (uint256 shares) {
    shares = (tokens * ONE_IDLE_TOKEN) / _price();
  }
 
  function _sharesToToken(uint256 shares) internal view returns (uint256 tokens) { 
    tokens = (shares * _price()) / ONE_IDLE_TOKEN;
  }

Impact

오버플로우나 언더플로우가 발생해도 revert 되지 않아 프로토콜이 망가질 수 있다.

Mitigation

SafeMath 라이브러리를 사용한다.

Memo

이 취약점은 원래 Low 심각도로 제출되었다. 오버플로우가 발생할 상한선은 높지만, 오버플로우가 발생하면 크게 망가질 수 있으므로 Medium으로 심각도가 올라갔다.


tags: bughunting, pooltogether, smart contract, solidity, integer overflow underflow, solidity safemath, severity medium