Tapioca DAO - 0xrugpull_detector's results

The first ever Omnichain money market, powered by LayerZero.

General Information

Platform: Code4rena

Start Date: 05/07/2023

Pot Size: $390,000 USDC

Total HM: 136

Participants: 132

Period: about 1 month

Judge: LSDan

Total Solo HM: 56

Id: 261

League: ETH

Tapioca DAO

Findings Distribution

Researcher Performance

Rank: 57/132

Findings: 5

Award: $559.88

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

Labels

bug
3 (High Risk)
satisfactory
duplicate-1083

Awards

56.1709 USDC - $56.17

External Links

Lines of code

https://github.com/Tapioca-DAO/tapiocaz-audit/blob/master/contracts/tOFT/modules/BaseTOFTStrategyModule.sol#L152-L162 https://github.com/Tapioca-DAO/tapiocaz-audit/blob/master/contracts/tOFT/modules/BaseTOFTMarketModule.sol#L160-L169 https://github.com/Tapioca-DAO/tapiocaz-audit/blob/master/contracts/tOFT/modules/BaseTOFTOptionsModule.sol#L189-L200 https://github.com/Tapioca-DAO/tapiocaz-audit/blob/master/contracts/tOFT/modules/BaseTOFTLeverageModule.sol#L184-L194 https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/master/contracts/usd0/modules/USDOLeverageModule.sol#L169-L179 https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/master/contracts/usd0/modules/USDOMarketModule.sol#L168-L177 https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/master/contracts/usd0/modules/USDOOptionsModule.sol#L174-L185

Vulnerability details

Proof of Concept

All these contracts are module contracts for omni-chain operations like leverage, strategy, market, options.

Vulnerabiilies come from 2 reasons.

  • These module contracts has no access control mechanism in place for important omni-chain related functions.
  • These functions delegatecall to any address supplied as modules parameter.

For example, a hacker can call BaseTOFTStrategyModule.strategyDeposit() passing modules as malicious contract with SELFDESTRUCT.

contract MaliciousModule Is Ownable {
    function depositToYieldbox() {
        selfdestruct(owner());
    }
}
contract MaliciousAttacker Is Ownable {
    function attack() {
        BaseTOFTStrategyModule(strategyModule).strategyDeposit(new MaliciousModule(), ...);
    }
}

https://github.com/Tapioca-DAO/tapiocaz-audit/blob/master/contracts/tOFT/modules/BaseTOFTStrategyModule.sol#L152-L162

    function strategyDeposit(
        address module,
        uint16 _srcChainId,
        bytes memory _srcAddress,
        uint64 _nonce,
        bytes memory _payload,
        IERC20 _erc20
    ) public {
        ...

        (bool success, bytes memory reason) = module.delegatecall(// @audit - might cause self destructions, function should not be public
            abi.encodeWithSelector(
                this.depositToYieldbox.selector,
                assetId,
                amount,
                share,
                _erc20,
                address(this),
                onBehalfOf
            )
        );

Impact

Complete DoS of Omni-chain tokens by destroying leverage, strategy, option, market modules.

Tools Used

Manual Review

Recommendation

  • There should be access control mechanism for omni-chain feature functions.
  • Only trusted modules address should be used for delegatecall.

Assessed type

call/delegatecall

#0 - c4-pre-sort

2023-08-05T11:17:39Z

minhquanym marked the issue as duplicate of #146

#1 - c4-judge

2023-09-13T10:25:05Z

dmvt marked the issue as satisfactory

Findings Information

Labels

bug
3 (High Risk)
satisfactory
upgraded by judge
edited-by-warden
duplicate-1046

Awards

46.9428 USDC - $46.94

External Links

Lines of code

https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/master/contracts/markets/bigBang/BigBang.sol#L191

Vulnerability details

Proof of Concept

BigBang.init() might set non-zero big debtStartPoint value.

https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/master/contracts/markets/bigBang/BigBang.sol#L156-L162

    _isEthMarket = collateralId == penrose.wethAssetId();
    if (!_isEthMarket) {
        debtRateAgainstEthMarket = _debtRateAgainstEth;
        maxDebtRate = _debtRateMax;
        minDebtRate = _debtRateMin;
        debtStartPoint = _debtStartPoint;
    }

If debtStartPoint is greater than totalBorrow.elastic, underflow will occur.

https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/master/contracts/markets/bigBang/BigBang.sol#L180-L201

function getDebtRate() public view returns (uint256) { ... uint256 _currentDebt = totalBorrow.elastic; uint256 debtPercentage = ((_currentDebt - debtStartPoint) * DEBT_PRECISION) / (_maxDebtPoint - debtStartPoint); ... return debt; }

Impact

As getDebtRate() is called by accure() and liquidate(). it will cause these functions to be reverted as well.

https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/master/contracts/markets/bigBang/BigBang.sol#L512-L541

    function _accrue() internal override {
....
        //update debt rate
        uint256 annumDebtRate = getDebtRate();
...
    }

Recommendation

If totalBorrow.elastic < debtStartPoint, getDebtRate() should return mintDebtRate.

function getDebtRate() public view returns (uint256) { ... uint256 _currentDebt = totalBorrow.elastic; + if (_currentDebt < debtStartPoint) return minDebtRate; uint256 debtPercentage = ((_currentDebt - debtStartPoint) * DEBT_PRECISION) / (_maxDebtPoint - debtStartPoint); ... return debt; }

Assessed type

DoS

#0 - c4-pre-sort

2023-08-04T22:26:38Z

minhquanym marked the issue as duplicate of #1370

#1 - c4-pre-sort

2023-08-04T22:30:36Z

minhquanym marked the issue as duplicate of #1046

#2 - c4-judge

2023-09-18T13:13:52Z

dmvt changed the severity to 3 (High Risk)

#3 - c4-judge

2023-09-18T13:15:26Z

dmvt marked the issue as satisfactory

Findings Information

Labels

bug
2 (Med Risk)
satisfactory
edited-by-warden
duplicate-1456

Awards

76.3356 USDC - $76.34

External Links

Lines of code

https://github.com/Tapioca-DAO/tapioca-yieldbox-strategies-audit/blob/master/contracts/yearn/YearnStrategy.sol#L145

Vulnerability details

It is quite possible for some times Yearn strategy might return incurring losses.

As maxLoss parameter is set to 0, YearnStrategy._withdraw() does not tolerate any losses incurred.

It will make withdrawal from Yearn strategies blocked.

    function _withdraw(
        address to,
        uint256 amount
    ) internal override nonReentrant {
        uint256 available = _currentBalance();
        require(available >= amount, "YearnStrategy: amount not valid");

        uint256 queued = wrappedNative.balanceOf(address(this));
        if (amount > queued) {
            uint256 pricePerShare = vault.pricePerShare();
            uint256 toWithdraw = (((amount - queued) *
                (10 ** vault.decimals())) / pricePerShare);

            vault.withdraw(toWithdraw, address(this), 0); // @audit - maxLoss = 0
        }
        wrappedNative.safeTransfer(to, amount - 1); //rounding error

        emit AmountWithdrawn(to, amount);
    }

Impact

Withdrawal might be blocked in case of strategy loss.

Recommendation

It should use maxLoss parameter which is updatable by owner.

https://github.com/Tapioca-DAO/tapioca-yieldbox-strategies-audit/blob/master/contracts/yearn/YearnStrategy.sol#L145

    function _withdraw(
        address to,
        uint256 amount
    ) internal override nonReentrant {
        uint256 available = _currentBalance();
        require(available >= amount, "YearnStrategy: amount not valid");

        uint256 queued = wrappedNative.balanceOf(address(this));
        if (amount > queued) {
            uint256 pricePerShare = vault.pricePerShare();
            uint256 toWithdraw = (((amount - queued) *
                (10 ** vault.decimals())) / pricePerShare);

-           vault.withdraw(toWithdraw, address(this), 0);
+           vault.withdraw(toWithdraw, address(this), maxLoss);
        }
        wrappedNative.safeTransfer(to, amount - 1);

        emit AmountWithdrawn(to, amount);
    }

Assessed type

DoS

#0 - c4-pre-sort

2023-08-05T08:54:47Z

minhquanym marked the issue as duplicate of #96

#1 - c4-judge

2023-09-13T09:08:49Z

dmvt marked the issue as satisfactory

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter