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
Rank: 45/55
Findings: 1
Award: $32.96
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: DadeKuma
Also found by: 0xStalin, 0xhacksmithh, 99Crits, Aymen0909, Bauchibred, CodeWasp, Dup1337, IllIllI, John_Femi, K42, KupiaSec, Naresh, Rhaydden, Rolezn, Sathish9098, Topmark, ZanyBonzy, albahaca, bareli, blockchainbuttonmasher, cheatc0d3, codeslide, crc32, d3e4, favelanky, grearlake, hihen, jasonxiale, jesjupyter, lanrebayode77, lirezArAzAvi, lsaudit, mining_mario, oualidpro, pfapostol, radin100, rbserver, sammy, satoshispeedrunner, slvDev, twcctop, zabihullahazadzoi
32.9585 USDC - $32.96
PanopticMath.sol
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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