code-423n4 / 2023-07-tapioca

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tapioca audit details

  • Total Prize Pool: $390,000 USDC
    • HM awards: $222,338 USDC
    • Analysis awards: $13,476 USDC
    • QA awards: $6,737 USDC
    • Bot Race awards: $20,212 USDC
    • Gas awards: $6,737 USDC
    • Judge awards: $26,000 USDC
    • Lookout awards: $12,000 USDC
    • Scout awards: $500 USDC
    • Mitigation Review: $82,000 USDC (Opportunity goes to top 5 certified wardens based on placement in this audit.)
  • Join C4 Discord to register
  • Submit findings using the C4 form
  • Read our guidelines for more details
  • Starts July 05, 2023 20:00 UTC
  • Ends August 04, 2023 20:00 UTC

Automated Findings / Publicly Known Issues

Automated findings output for the audit can be found here. ❗️Important: click "Raw" to view the entire report, as it is truncated in the default view.

Note for C4 wardens: Anything included in the automated findings output is considered a publicly known issue and is ineligible for awards.

We are aware of the issue with the _ld2sdRate(). Currently if isLdChain isn't set to true for the chain within the deployment of the token, the maximum amount of token that can be sent is equal to 18e18.

Prior audits can be viewed here, and the contents of these are also considered known issues and ineligible for awards. It is recommended that wardens read both Certora reports for helpful context.

In particular, note that the issue described as "First depositor can steal value of some subsequent deposits" in the Certora audit is a known issue.

Overview

The Tapioca protocol is built with a lot of different smart contracts, scattered across 5 repositories. It's an Omnichain protocol working the LayerZero messaging layer. At its core, Tapioca ERC20/ERC721 contracts uses the LayerZero OFTv2 and ONFT721 contracts.

The main repository is tapioca-bar, which contains USDO, a stablecoin. BigBang, a CDP based contract that mint and burn USDO. And Singularity, a lending and borrowing platform.

The other repos are here to support the ecosystem as well as to create a synergy between the tokenemics and the protocol features.

  • tap-token Contracts related to the tokenemics, is linked to tapioca-bar in an asymmetric way.
  • tapiocaz Contracts that contains a wrapper named TOFT, which is used to wrap gas tokens and transfer allow their usage through the LayerZero network.
  • tapioca-periph Periphery contracts. The main contract is MagnetarV2, acts as a helper that reduce the number of user taken actions/transactions.
  • YieldBox A "BentoBox v2". Acts as a vault, that allow for yield strategies to be applied on the asset.
  • yieldbox-strategies Yield strategies that will be used by a YieldBox asset.

tapioca-userflow

Notes

  • The docs provide a lot of information about the protocol and the user flow, given the size of the protocol, we encourage checking it at https://docs.tapioca.xyz/tapioca/.
  • MagnetarV2 does not have access control by design. The underlying is the one that implement those (Can be found on TOFT, Singularity, USDO, TapiocaOptionBroker).
  • Re-entrency on ownable contract should be considered as a vulnerability only if the last call leads to an external call with potential vulnerability.

Files in scope

File SLOC Description Libraries
Contracts (17)
tapioca-bar-audit/contracts/markets/singularity/SGLCollateral.sol 22 Singularity collateral module
tapioca-bar-audit/contracts/markets/singularity/SGLBorrow.sol 31 Singularity borrowing module
tapioca-bar-audit/contracts/usd0/BaseUSDOStorage.sol 🖥 💰 🧮 56 Base USDO contract tapioca-sdk/* @openzeppelin/* tapioca-periph/*
tapioca-bar-audit/contracts/usd0/USDO.sol 69 USDO stablecoin tapioca-sdk/* tapioca-periph/*
tapioca-bar-audit/contracts/markets/singularity/SGLLendingCommon.sol 📤 78 Singularity base contract
tapioca-bar-audit/contracts/markets/singularity/SGLStorage.sol 121 Singularity storage layout @boringcrypto/* tapioca-periph/* tapioca-sdk/*
tapioca-bar-audit/contracts/markets/singularity/SGLLeverage.sol 💰 📤 135 Singularity module for leverage tapioca-periph/*
tapioca-bar-audit/contracts/markets/MarketERC20.sol 🧮 181 Base contract for Market.sol @boringcrypto/* @openzeppelin/*
tapioca-bar-audit/contracts/markets/singularity/SGLCommon.sol 📤 209 Singularity base contract
tapioca-bar-audit/contracts/usd0/modules/USDOMarketModule.sol 💰 👥 ♻️ Σ 268 USDO Module for Singularity tapioca-sdk/* @boringcrypto/* tapioca-periph/*
tapioca-bar-audit/contracts/usd0/modules/USDOOptionsModule.sol 💰 👥 ♻️ Σ 269 USDO Module for TapiocaBrokerOption.sol calls tapioca-sdk/* tapioca-periph/*
tapioca-bar-audit/contracts/usd0/modules/USDOLeverageModule.sol 💰 👥 ♻️ Σ 277 USDO Module for leverage tapioca-sdk/* tapioca-periph/*
tapioca-bar-audit/contracts/markets/singularity/SGLLiquidation.sol 📤 288 Singularity module for liquidations
tapioca-bar-audit/contracts/usd0/BaseUSDO.sol 💰 👥 358 Custom LayerZero OFT logic, inherited in USDO tapioca-sdk/* @openzeppelin/* tapioca-periph/*
tapioca-bar-audit/contracts/Penrose.sol 🖥 💰 📤 🌀 Σ 377 Owner contract for USDO & BB @boringcrypto/* tapioca-sdk/* tapioca-periph/*
tapioca-bar-audit/contracts/markets/singularity/Singularity.sol 💰 👥 452 Lending & borrowing tapioca-periph/* tapioca-sdk/*
tapioca-bar-audit/contracts/markets/bigBang/BigBang.sol 📤 👥 555 Mint and burn USDO through CDP @boringcrypto/* tapioca-periph/*
Abstracts (1)
tapioca-bar-audit/contracts/markets/Market.sol 🖥 316 Base contract for BigBang & Singularity @boringcrypto/* tapioca-sdk/* tapioca-periph/*
Total (over 18 files): 4062
File SLOC Description Libraries
Contracts (10)
tapiocaz-audit/contracts/tOFT/TapiocaOFT.sol 💰 50 OFTv2 compliant wrapped token, with new custom functions
tapiocaz-audit/contracts/tOFT/BaseTOFTStorage.sol 🖥 💰 55 Base TOFT EVM storage layout tapioca-sdk/* @openzeppelin/* tapioca-periph/*
tapiocaz-audit/contracts/tOFT/mTapiocaOFT.sol 💰 94 Special TOFT implementation that can balance its supply
tapiocaz-audit/contracts/TapiocaWrapper.sol 💰 🧮 141 TOFT create2 deployer tapioca-periph/* @openzeppelin/*
tapiocaz-audit/contracts/tOFT/modules/BaseTOFTStrategyModule.sol 💰 👥 203 Base TOFT YieldBox module tapioca-sdk/* tapioca-periph/*
tapiocaz-audit/contracts/Balancer.sol 💰 223 Contract that balance out a mTapiocaOFT supply tapioca-periph/* solmate/* @openzeppelin/*
tapiocaz-audit/contracts/tOFT/modules/BaseTOFTMarketModule.sol 💰 👥 ♻️ Σ 276 Base TOFT Singularity market module tapioca-sdk/* tapioca-periph/*
tapiocaz-audit/contracts/tOFT/modules/BaseTOFTOptionsModule.sol 💰 👥 ♻️ Σ 283 Base TOFT TapiocaOptionBroker market module tapioca-sdk/* tapioca-periph/*
tapiocaz-audit/contracts/tOFT/modules/BaseTOFTLeverageModule.sol 💰 👥 ♻️ Σ 305 Base TOFT leverage module tapioca-sdk/* tapioca-periph/*
tapiocaz-audit/contracts/tOFT/BaseTOFT.sol 💰 👥 455 Base TOFT contract
Total (over 10 files): 2085
File SLOC Description Libraries
Contracts (9)
tap-token-audit/contracts/tokens/LTap.sol 📤 30 ERC20 aoTAP 1:1 redeemer @boringcrypto/* @openzeppelin/*
tap-token-audit/contracts/options/oTAP.sol 75 ERC721 Option meta contract @boringcrypto/* @openzeppelin/* tapioca-sdk/*
tap-token-audit/contracts/option-airdrop/aoTAP.sol 88 Forked version of oTAP @boringcrypto/* @openzeppelin/* tapioca-sdk/*
tap-token-audit/contracts/Vesting.sol 94 Vesting contract @openzeppelin/* @boringcrypto/*
tap-token-audit/contracts/tokens/TapOFT.sol 127 Tapioca protocol token @openzeppelin/*
tap-token-audit/contracts/options/TapiocaOptionLiquidityProvision.sol 📤 🧮 Σ 248 Singularity ERC20 receipt token vault @boringcrypto/* @openzeppelin/* tapioca-sdk/*
tap-token-audit/contracts/option-airdrop/AirdropBroker.sol 📤 🧮 Σ 338 Smaller version of TapiocaOptionBroker to mint & exercise LTAP @openzeppelin/* @boringcrypto/* tapioca-periph/*
tap-token-audit/contracts/governance/twTAP.sol 🖥 📤 Σ 341 ONFT721 governance token tapioca-sdk/* @openzeppelin/*
tap-token-audit/contracts/options/TapiocaOptionBroker.sol 📤 Σ 398 Mint & exercise oTAP @boringcrypto/* @openzeppelin/* tapioca-periph/*
Abstracts (2)
tap-token-audit/contracts/twAML.sol 🖥 94 Math library
tap-token-audit/contracts/tokens/BaseTapOFT.sol 💰 ♻️ Σ 264 Base TapOFT contract tapioca-sdk/* @openzeppelin/* tapioca-periph/*
Total (over 11 files): 2097
File SLOC Description Libraries
Contracts (12)
tapioca-periph-audit/contracts/oracle/implementations/GLPOracle.sol 38 GLP Oracle
tapioca-periph-audit/contracts/TapiocaDeployer/TapiocaDeployer.sol 🖥 💰 🌀 52 Tapioca contract deployer
tapioca-periph-audit/contracts/oracle/implementations/SGOracle.sol 57 Stargate finance oracle @chainlink/*
tapioca-periph-audit/contracts/oracle/Seer.sol 66 Oracle contract, uses best of ChainLink/UniV3 price feed
tapioca-periph-audit/contracts/Multicall/Multicall3.sol 🖥 💰 Σ 72 Multicall contract @openzeppelin/*
tapioca-periph-audit/contracts/oracle/implementations/ARBTriCryptoOracle.sol 87 TriCrypto oracle @chainlink/* @openzeppelin/* solady/*
tapioca-periph-audit/contracts/Swapper/CurveSwapper.sol 108 Curve swapper contract @openzeppelin/*
tapioca-periph-audit/contracts/Swapper/UniswapV2Swapper.sol 121 UniV2 swapper contract
tapioca-periph-audit/contracts/Swapper/UniswapV3Swapper.sol 142 UniV3 swapper contract @uniswap/* @openzeppelin/*
tapioca-periph-audit/contracts/Magnetar/MagnetarV2Storage.sol 💰 284 Magnetar storage layout @boringcrypto/* tapioca-sdk/*
tapioca-periph-audit/contracts/Magnetar/modules/MagnetarMarketModule.sol 💰 📤 ♻️ 676 Magnetar Singularity module tapioca-sdk/* @openzeppelin/*
tapioca-periph-audit/contracts/Magnetar/MagnetarV2.sol 🖥 💰 👥 Σ 866 Helper contract that interacts with Singularity, BigBang, TapiocaOptionBroker @openzeppelin/*
Abstracts (1)
tapioca-periph-audit/contracts/Swapper/BaseSwapper.sol 151 Base swapper contract for other swapper contract @openzeppelin/* tapioca-sdk/*
Total (over 13 files): 2720
File SLOC Description Libraries
Contracts (10)
tapioca-yieldbox-strategies-audit/contracts/yearn/YearnStrategy.sol 82 Yearn strat @openzeppelin/* @boringcrypto/* tapioca-sdk/*
tapioca-yieldbox-strategies-audit/contracts/compound/CompoundStrategy.sol 💰 94 Compound strat @openzeppelin/* @boringcrypto/* tapioca-sdk/*
tapioca-yieldbox-strategies-audit/contracts/lido/LidoEthStrategy.sol 💰 100 TriCrypto LP strat @openzeppelin/* @boringcrypto/* tapioca-sdk/*
tapioca-yieldbox-strategies-audit/contracts/curve/TricryptoNativeStrategy.sol 175 TriCrypto native strat @openzeppelin/* @boringcrypto/* tapioca-sdk/*
tapioca-yieldbox-strategies-audit/contracts/curve/TricryptoLPStrategy.sol 176 TriCrypto LP strat @openzeppelin/* @boringcrypto/* tapioca-sdk/*
tapioca-yieldbox-strategies-audit/contracts/stargate/StargateStrategy.sol 💰 182 Stargate strat @openzeppelin/* @boringcrypto/* tapioca-sdk/*
tapioca-yieldbox-strategies-audit/contracts/aave/AaveStrategy.sol 190 Stargate strat @openzeppelin/* @boringcrypto/* tapioca-sdk/*
tapioca-yieldbox-strategies-audit/contracts/balancer/BalancerStrategy.sol 💰 208 Balancer strat @openzeppelin/* @boringcrypto/* tapioca-sdk/*
tapioca-yieldbox-strategies-audit/contracts/glp/GlpStrategy.sol 🧪 ♻️ 240 GLP strat @boringcrypto/* @uniswap/* tapioca-sdk/*
tapioca-yieldbox-strategies-audit/contracts/convex/ConvexTricryptoStrategy.sol 🧮 289 TriCrypto strat @openzeppelin/* @boringcrypto/* tapioca-sdk/*
Total (over 10 files): 1736
File SLOC Description Libraries
Contracts (3)
YieldBox/contracts/NativeTokenFactory.sol 72 Creates ERC1155 tokens
YieldBox/contracts/YieldBoxURIBuilder.sol 123 Inherited by YieldBox @openzeppelin/* @boringcrypto/*
YieldBox/contracts/YieldBox.sol 🧪 💰 263 Main Yieldbox contract @boringcrypto/* @openzeppelin/*
Abstracts (1)
YieldBox/contracts/YieldBoxPermit.sol 🧮 67 EIP-2612 for YieldBox @openzeppelin/*
Libraries (2)
YieldBox/contracts/BoringMath.sol 26 Simple math lib
YieldBox/contracts/YieldBoxRebase.sol 🧪 40 Math lib for internal accounting @boringcrypto/*
Total (over 6 files): 591

Out of scope

Additional Context

twAML is a simple model that is used in twTAP and TapiocaOptionBroker. A detailed explanation of how it works can be found here.

Scoping Details

- If you have a public code repo, please share it here:  https://github.com/Tapioca-DAO/Tapioca-bar https://github.com/Tapioca-DAO/tap-token https://github.com/Tapioca-DAO/TapiocaZ https://github.com/Tapioca-DAO/tapioca-yieldbox-strategies https://github.com/Tapioca-DAO/YieldBox
- How many contracts are in scope?:   62
- Total SLoC for these contracts?:  13499
- How many external imports are there?: 15
- How many separate interfaces and struct definitions are there for the contracts within scope?:  50
- Does most of your code generally use composition or inheritance?:   Inheritance
- How many external calls?:   10
- What is the overall line coverage percentage provided by your tests?:  90
- Is there a need to understand a separate part of the codebase / get context in order to audit this part of the protocol?:  false 
- Please describe required context:   n/a
- Does it use an oracle?:  Custom oracle that may use Chainlink or UniV3 or best of Chainlink/UniV3
- Does the token conform to the ERC20 standard?:  True / also non-ERC20 token
- Are there any novel or unique curve logic or mathematical models?: twAML inherited contracts uses a math model that can be found on the page 5 of the paper https://www.tapioca.xyz/docs/twAML.pdf
- Does it use a timelock function?:  True
- Is it an NFT?: 
- Does it have an AMM?:   
- Is it a fork of a popular project?: True; Heavily modified version of Kashi lending & borrowing. It implements a new Permit system for both lending & borrowing actions, a new liquidation system and a module based architecture.
- Does it use rollups?:   
- Is it multi-chain?:  True
- Does it use a side-chain?: False
- Describe any specific areas you would like addressed. E.g. Please try to break XYZ.":
Tap-Token repo: 
Integrity of twAML model within the used contracts (TapiocaOptionBroker, TapiocaDAOPortal). 
Correct user participation and exit on twAML contracts (tOB, tDP). 
Proper OTC deal execution on tOB. 

Tapioca-Bar repo:
Lending & borrowing mechanism.
Function access with lend/borrow approval/permit.
Closed liquidations.

TapiocaZ repo:
mTapiocaOFT/Balancer contract balancing mechanism.

QuickStart

export ALCHEMY_API_KEY="<your-alchemy-api-key>" && export PRIVATE_KEY="ae330c71c0930902aae1bdabdca36457e5b92a095c8ad171fd3ae6519961cc2a" && rm -Rf 2023-07-tapioca || true && git clone https://github.com/code-423n4/2023-07-tapioca.git -j8 && cd 2023-07-tapioca && git submodule update --init && nvm install 18.0 && cd tapiocaz-audit && git submodule update --init && yarn && npx hardhat compile && cd .. && cd YieldBox && git submodule update --init && yarn && npx hardhat compile && cd .. && cd tapioca-bar-audit && git submodule update --init && yarn && npx hardhat compile && cd .. && cd tapioca-periph-audit && git submodule update --init && yarn && npx hardhat compile && cd .. && cd tapioca-yieldbox-strategies-audit && git submodule update --init && yarn && npx hardhat compile && cd .. && cd tap-token-audit && git submodule update --init && yarn && npx hardhat compile && cd ..  && cd tapiocaz-audit && REPORT_GAS=true npx hardhat test && cd .. && cd YieldBox && REPORT_GAS=true npx hardhat test && cd .. && cd tapioca-bar-audit && REPORT_GAS=true npx hardhat test && cd .. && cd tapioca-periph-audit && export BINANCE_WALLET_ADDRESS=0x28C6c06298d514Db089934071355E5743bf21d60 && export UniswapV2Router02=0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D && export UniswapV2Factory=0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f && export UniswapV3Router=0xE592427A0AEce92De3Edee1F18E0157C05861564 && export UniswapV3Factory=0x1F98431c8aD98523631AE4a59f267346ea31F984 && export Curve3Pool=0xbebc44782c7db0a1a60cb6fe97d0b483032ff1c7 && export USDT=0xdac17f958d2ee523a2206206994597c13d831ec7 && export USDC=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 && export WETH=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 && REPORT_GAS=true npx hardhat test && cd .. && cd tapioca-yieldbox-strategies-audit && REPORT_GAS=true NODE_ENV=mainnet npx hardhat test && cd .. && cd tap-token-audit && REPORT_GAS=true npx hardhat test && cd ..

Tests

Some tests are skipped, either because it requires a specific chain to be on (Some tests might run solely on Mainnet, while others on Arbitrum). Others are skipped due to being there for helping purposes, or being too old but aren't cleaned.

Hardhat tests:

Setup

yarn
npx hardhat compile

Test

npx hardhat test

Gas cost

Set enabled key to true in hardhat.export.ts>config.gasReporter

  gasReporter: {
      enabled: true,
  }

Slither

Slither does not currently work on tapioca-periph-audit repo. If you find a workaround, please share in the discord.

Coverage

Coverage is broken for some repos because we use IR compilation. Disabling it might output a stack too deep compilation error.

About


Languages

Language:HTML 100.0%