code-423n4 / 2024-04-panoptic-findings

9 stars 4 forks source link

Missing input validation for the receiver address in the mint function #336

Closed c4-bot-6 closed 5 months ago

c4-bot-6 commented 5 months ago

Lines of code

https://github.com/code-423n4/2024-04-panoptic/blob/833312ebd600665b577fbd9c03ffa0daf250ed24/contracts/CollateralTracker.sol#L477-L500 https://github.com/code-423n4/2024-04-panoptic/blob/833312ebd600665b577fbd9c03ffa0daf250ed24/contracts/CollateralTracker.sol#L453-L468 https://github.com/code-423n4/2024-04-panoptic/blob/833312ebd600665b577fbd9c03ffa0daf250ed24/contracts/tokens/ERC20Minimal.sol#L122-L131

Vulnerability details

Impact

The mint function does not validate the receiver address, meaning any contract's address could be provided, for example the address of the SemiFungiblePositionManager contract.If the provided contract has no functions to withdraw the shares minted to its address, this could have following consequences: the shares would be locked inside the contract's address. If done on a huge scale, this would creates artificial scarcity, potentially inflating the value of the remaining circulating shares, allowing the attacker to profit by selling their shares at elevated prices. Such activities could destabilize the platform, leading to a loss of trust and potentially causing a decline in share prices if participants realize that shares are being inappropriately locked.

Proof of Concept

The mint function (https://github.com/code-423n4/2024-04-panoptic/blob/833312ebd600665b577fbd9c03ffa0daf250ed24/contracts/CollateralTracker.sol#L477-L500) allows users to participate in the project by providing collateral in exchange for shares. It calculates the number of underlying assets equivalent to a requested number of shares by calling the previewMint function, which adjusts for rounding and commission fees to prevent loss. It then ensures the assets do not exceed a system limit to prevent overflow, then securely transfers these assets from the user’s account to the PanopticPool. Finally, the function mints the corresponding shares to the specified receiver’s address and updates the pool’s asset tracking, logging the entire transaction with a Deposit event. If the SemiFungiblePositionManager's address is provided as the receiver address to the mint function, the shares will be locked side the SemiFungiblePositionManager contract, since it doesn't have methods to withdraw shares minted to its own address. This would upset the balance between tokens and shares, removing the shares from the active circulation.

An attacker could leverage this in the following way: He first purchases a huge amount of tokens. For a part of these tokens he proceeds according to standard and uses the mint function in the way it should be used, minting the shares to his own contract address of choice. For the remaining tokens, he then calls the mint function with the SemiFungiblePositionManager's address as the receiver address and mints a huge amount of shares to it, effectively locking them. This creates an artificial scarcity that will increase the valuation of the remaining circulating shares. The attacker does this deliberately to create a shortage. He then sells off his holdings of the shares at this inflated price, making a profit.

This would typically work in times when the total supply of shares or the dailiy trading volume is rather low, for example, in the beginning, and/ or when there is a very high demand for the shares of the platform. Another possible scenario would be that if market participants notice that shares are being locked out of circulation, they might turn away from the protocol and the price of shares would drop. Since (decentralized) trading platforms already experience high price volatility due to the speculative nature of options themselves, every manipulation of shares including producing artificial scarcity, should be urgently prevented and no risks should be taken.

Tools Used

Visual Inspection.

Recommended Mitigation Steps

Implement checks to ensure that the receiver address specified in the mint function is capable of interacting with the minted shares. Also implement limits on the number of shares that can be minted within a certain timeframe, especially to new addresses or unverified contracts.

Assessed type

Invalid Validation

c4-judge commented 5 months ago

Picodes marked the issue as unsatisfactory: Invalid