Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A malicious filler can prevent trades in markets inheriting from BaseMarketUpgradable #305

Open
c4-bot-10 opened this issue Jun 10, 2024 · 0 comments
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working edited-by-warden 🤖_31_group AI based duplicate group recommendation sufficient quality report This report is of sufficient quality

Comments

@c4-bot-10
Copy link
Contributor

c4-bot-10 commented Jun 10, 2024

Lines of code

https://github.com/code-423n4/2024-05-predy/blob/main/src/base/BaseMarketUpgradable.sol#L128-L130
https://github.com/code-423n4/2024-05-predy/blob/main/src/base/BaseMarketUpgradable.sol#L140-L142

Vulnerability details

Impact

As the filler is the one who makes sure that the traders' orders are executed, it is of utter importance for them to be available at all times. However, they are able to resign from the position in order to revert any execution of trades, or even worse - they can create a new contract, which can make them a profit by utilizing the incoming orders for the filler.

Proof of Concept

When deploying a new market, within the constructor of both BaseMarket and BaseMarketUpgradeable, the whitelistFiller address gets set and can only be updated using the function updateWhitelistSettlement (BaseMarket, BaseMarketUpgradeable), which is access controlled by the onlyFiller modifier. Nevertheless, calling updateWhitelistSettlement in BaseMarketUpgradeable would allow a malicious filler to resign from their role by calling that same function and setting the whitelistFiller to address(0) - making any trades in PerpMarketV1 and GammaTradeMarket revert, as a filler simply wouldn't exist.

...
if (tradeResult.minMargin > 0) {
    // only whitelisted filler can open position
    if (msg.sender != whitelistFiller) {
     revert CallerIsNotFiller();
   }
}
...
if (tradeResult.minMargin > 0) {
    // only whitelisted filler can open position
    if (msg.sender != whitelistFiller) {
     revert CallerIsNotFiller();
   }
}

The filler's other option is to create a contract that will profit from every order they would have to carry out. Besides having to create the contract, they would only have to call updateWhitelistSettlement and assign their malicious contract. The end result is profit for them and loss for the protocol and the users.

Even though the BaseMarket contract is mentioned in the report, it has proper access control, where the function whitelistFiller can only be called by the owner. As the only trusted roles in the protocol are the operator and the pool owner, the function has to be updated with valid access control.

Tools Used

Manual Review

Recommended Mitigation Steps

Consider implementing the following changes to updateWhitelistSettlement and the BaseMarketUpgradable: Firstly, import the Owned library (used by BaseMarket), make the contract inherit it from it, and initialize the Owned contract in __BaseMarket_init as this would set the Owner. Secondly, change updateWhitelistSettlement's code as follows:

-    function updateWhitelistSettlement(address settlementContractAddress, bool isEnabled) external onlyFiller {
+    function updateWhitelistSettlement(address settlementContractAddress, bool isEnabled) external onlyOwner {
        _whiteListedSettlements[settlementContractAddress] = isEnabled;
    }

Assessed type

Access Control

@c4-bot-10 c4-bot-10 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Jun 10, 2024
c4-bot-3 added a commit that referenced this issue Jun 10, 2024
@c4-bot-12 c4-bot-12 added the 🤖_31_group AI based duplicate group recommendation label Jun 14, 2024
howlbot-integration bot added a commit that referenced this issue Jun 17, 2024
@howlbot-integration howlbot-integration bot added the sufficient quality report This report is of sufficient quality label Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working edited-by-warden 🤖_31_group AI based duplicate group recommendation sufficient quality report This report is of sufficient quality
Projects
None yet
Development

No branches or pull requests

3 participants