Panoptic - blockchainbuttonmasher's results

Permissionless, perpetual options trading on any token, any strike, any size.

General Information

Platform: Code4rena

Start Date: 01/04/2024

Pot Size: $120,000 USDC

Total HM: 11

Participants: 55

Period: 21 days

Judge: Picodes

Total Solo HM: 6

Id: 354

League: ETH

Panoptic

Findings Distribution

Researcher Performance

Rank: 44/55

Findings: 1

Award: $32.96

🌟 Selected for report: 0

🚀 Solo Findings: 0

Math.sol

  1. Unchecked Calls and Integer Overflows:

    • In multiple places, the code makes use of the unchecked keyword which skips overflow checks for arithmetic operations. This could potentially result in silent integer overflows or underflows that lead to incorrect calculations.
    • However, the usage of unchecked is often intentional in Solidity to save gas since Solidity 0.8.0 includes built-in overflow checks. In this case, one needs to ensure that the logic of each operation is correct, resists any overflow/underflow issues, and aligns with the expected mathematical properties. For instance, the functions mulDiv, mulDiv64, mulDiv96, mulDiv128, and mulDiv192 are structured to handle large number multiplications safely and don't typically require overflow checks.
  2. Unused or Missing Imports:

    • Without seeing the actual imported Errors.sol and Constants.sol files, it's difficult to confirm that all imported errors are handled or that the constants are correct. Additionally, the usage of LiquidityChunkLibrary is inferred but not explicitly seen, which means that either the import is missing or the code that relies on it is not provided.
  3. Type Conversion Checks:

    • The toUint128, toUint128Capped, toInt128, and toInt256 functions include checks to ensure safe typecasting between different numerical types. An overflow would result in a revert with a CastingError. However, depending on the use cases of these functions, it might be better to include underflow checks too if any decrement operations are expected.
  4. abs and absUint Functions:

    • The abs function does not support type(int256).min and will revert for this value as the negative of type(int256).min cannot be represented in an int256. This could potentially be a bug depending on the context of where abs is used.
    • The absUint function comment says it supports type(int256).min, but we don't see the explicit check here. The code does not seem to have a flaw, as the conversion will work because uint256(-type(int256).min) is perfectly valid.
  5. Potential Roundup Errors:

    • In the mulDivRoundingUp and other similar functions, there is a check for any remainder using mulmod. If there is any remainder, the result is incremented by one to round up. However, this does not consider the edge case where the result could be exactly type(uint256).max and incrementing would cause an overflow.
  6. Liquidity Chunk Math:

    • The getAmount0ForLiquidity and getAmount1ForLiquidity functions assume particular return values from getSqrtRatioAtTick but it's unclear without knowledge of that function's correctness if those assumptions always hold true.
  7. Documentation and Consistency:

    • Some functions have missing or incomplete documentation. For example, getLiquidityForAmount0 and getLiquidityForAmount1 have the comment "Had to use a less optimal calculation to match Uniswap's implementation." This is not elaborated on, so future maintainers might not understand why the decisions were made, or what exactly is suboptimal.
    • There are multiple min and max functions for different types, but they all have identical descriptions in their comments. This may cause confusion for users of the library concerning which function applies to their use case.
  8. Comments and Code Consistency:

    • There are several commented "RealV" lines in getSqrtRatioAtTick. It's unclear if these are intended to be used or are vestigial remnants of an older version. This could be confusing or misleading and should be clarified or removed.

This review is not exhaustive, but it covers several notable points that should be addressed for safer code or better maintainability. Remember that smart contract code is immutable once deployed on the blockchain, and even a small bug can lead to significant financial loss, so thorough testing and auditing are crucial.

#0 - c4-judge

2024-04-26T17:18:57Z

Picodes marked the issue as grade-b

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