Panoptic - mining_mario'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: 45/55

Findings: 1

Award: $32.96

🌟 Selected for report: 0

🚀 Solo Findings: 0

PanopticMath.sol

  1. Inadequate Input Validation**: Most functions in this library assume that the provided inputs are valid and do not perform input validation. It's important to ensure that inputs are validated somewhere else, otherwise the library is prone to misuse.

  2. Unchecked Return Variables**: Functions like twapFilter, computeInternalMedian, and haircutPremia are complex and interact with external contracts (IUniswapV3Pool and CollateralTracker). However, they do not check the return values for their correctness, which can lead to unexpected behavior.

  3. Division By Zero Risk**: Solidity will revert if a division by zero occurs. Although the library uses Math operations that presumably implement safe division, the contract assumes that certain ratios and price calculations will not result in a divide-by-zero situation. It would be best to assert or require that denominators are not zero before division occurs.

  4. Potential for Arithmetic Underflows/Overflows**: Although Solidity 0.8 implements safe math to guard against overflow/underflow without explicitly using a library, the custom Math library functions used must also implement safe arithmetic checks.

  5. Complex State Dependency**: The function haircutPremia modifies storage via a pointer passed to it. This kind of complex state dependency can be error-prone and can lead to unexpected side-effects if not managed correctly across different function calls and transactions.

  6. Use of Low-level Assembly in numberOfLeadingHexZeros**: The function numberOfLeadingHexZeros incorporates inline assembly (mostSignificantNibble). While this may be used for performance reasons, using assembly is risky as it bypasses several important safety features of Solidity. It can potentially make the contract susceptible to subtle bugs, especially if the Ethereum Virtual Machine's behaviors change with upgrades.

  7. Obscure Logic**: The logic within the twapFilter function and others that engage with Uniswap V3 pool's time-weighted average prices is intricate. It's important to document these to ensure contributors understand how these work and under what assumptions they are correct.

  8. Dependence on Block Timestamps**: Functions involving time (e.g., computeInternalMedian) use block.timestamp. Depending on how this timestamp is used, it could be subject to manipulation by miners. It's important to consider the impact of timestamp manipulation on logic.

  9. Hard-coded Constants**: There are constants like TICKSPACING_MASK and values such as 19 in twapFilter that can affect the upgradeability and flexibility of the library. Best practice would be to define these in such a way that they can be easily modified if the protocol's parameters change.

  10. Setting the Chaos Threshold**: Imprecision due to integer math or assumptions in price conversions can cause small discrepancies that may be significant in certain conditions, leading to potential economic exploits or unintended contract behavior.

  11. Lack of Reentrancy Guard**: If any of the functions in the library cause a state change in external contracts, which then call back into Panoptic contracts before the first invocation is finished, this can lead to reentrancy attacks. A reentrancy guard should be employed wherever such external calls are made.

  12. Gas Considerations**: Some functions appear to be gas-intensive due to loops and multiple storage reads and writes. One should investigate the potential gas cost for larger loops and, if necessary, add gas optimizations.

Without a broader system context and knowledge about related contracts and how this library is used within them, this list cannot be exhaustive. Some concerns might be addressed outside the library, making some of the points moot depending on the overall system architecture of Panoptic. It's crucial to have a comprehensive suite of tests and audits to ensure the code behaves as expected under all conditions.

#0 - c4-judge

2024-04-26T17:19:21Z

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