The UUPS proxie standard is implemented incorrectly, making the protocol not upgradeable
The AssetFactory and FlashSwapRouter contracts inherit UUPSUpgradeable but set their owner to ModuleCore, which lacks the upgradeToAndCall function, so the contracts cannot be upgraded. This breaks the intended upgradeability of the protocol.
Source: https://github.com/sherlock-audit/2024-08-cork-protocol-judging/issues/47
The protocol has acknowledged this issue.
Found by
dimulski
Summary
Both the AssetFactory.sol and FlashSwapRouter.sol contracts inherit the UUPSUpgradeable contract from Openzepelin, indicating that the devs of the protocol want to have the possibility of upgrading the above mentioned contracts at some point in the future. Both of the contracts also implement the OwnableUpgradeable contract, and the _authorizeUpgrade() function in both contracts has the onlyOwner modifer. This function is used to check whether the person who tries to update the implementation contract in the Proxy has the required access. However in both contracts the initialize function sets the owner of the contract to the ModuleCore.sol contract as can be seen in the AssetFactory::initialize() and FlashSwapRouter::initialize() functions. The function from the UUPSUpgradeable contract that is used to upgrade the implementation contract in the proxy is the upgradeToAndCall() function, however this function can't be called from the ModuleCore.sol contract, as the functionality is not implemented. The ModuleCore.sol contract is the owner of both the contracts, and there isn't any functionality to transfer the ownership either. Thus AssetFactory.sol and FlashSwapRouter.sol contracts are effectively not upgradable, breaking a very important functionality of the protocol.
Root Cause
The upgradeToAndCall() function can't be called from the ModuleCore.sol contract and upgrade the AssetFactory.sol and FlashSwapRouter.sol contracts.
Internal pre-conditions
- All the contracts in the protocol are deployed
- The protocol team decides the want to update the
AssetFactory.soland/or theFlashSwapRouter.solcontracts
External pre-conditions
No response
Attack Path
No response
Impact
Contracts that are expected to be upgradable, can't be upgraded due to missing functionality in the ModuleCore.sol contract.
PoC
No response
Mitigation
Implement a call to the upgradeToAndCall() function in the ModuleCore.sol contract
Discussion
AtanasDimulski
Escalate, I don't agree that this is a dup of #185, as It describes a completely different way that will prevent contracts from being upgraded. Missign the upgrade upgradeToAndCall() function. Even if the issue described in #185 is fixed, the contracts won't be upgradeable.
sherlock-admin4
Escalate, I don't agree that this is a dup of #185, as It describes a completely different way that will prevent contracts from being upgraded. Missign the upgrade upgradeToAndCall() function. Even if the issue described in #185 is fixed, the contracts won't be upgradeable.
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
0xsimao
The lead judge grouped them because they fall under the umbrella of upgradeable issues. The comment here also has a point.
WangSecurity
I see how they can be groupped by the issue of incorrect upgradeability, but I agree with the escalation that this issue should be de-duplicated as it shows a completely different problem and "upgradeability issues" are too broad of a root cause. Planning to accept the escalation and de-dup this issue with medium severity.
@cvetanovv @AtanasDimulski are there other duplicates?
AtanasDimulski
Hey @WangSecurity all issues that are grouped under #185 and submitted by MadSisyphus talk about the notDelegated modifier, as far as I can see there are no other dups.
WangSecurity
Result: Medium Unique
sherlock-admin2
Escalations have been resolved successfully!
Escalation status:
- AtanasDimulski: accepted
ziankork
This issue is valid and have been fixed, but, we don't intend to make those contract upgradeable on mainnet(due to legal reasons) so we plan to remove the upgradeability of the contract later. The reason we provide a way to upgrade was initially due to the trading competition.
conclusion : valid, but won't fix
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/Cork-Technology/Depeg-swap/pull/69/commits/2325f6faf12467fc1e899ef7e95269d6f617b8b7
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the owner of the upgradeable contracts is set to ModuleCore, which does not implement a function to call upgradeToAndCall, and ownership cannot be transferred.
Impact
Contracts that are expected to be upgradable cannot be upgraded due to missing functionality in ModuleCore.
What the attacker needed
All contracts deployed; Team wants to upgrade AssetFactory or FlashSwapRouter
The fix
The issue was fixed by implementing a call to upgradeToAndCall in ModuleCore, though the team later stated they do not intend to keep the contracts upgradeable on mainnet.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Smart contracts can be designed to be upgradeable, meaning the code can be replaced later while keeping the same address. This report says two contracts were set up to be upgradeable, but the only account allowed to trigger an upgrade is another contract that doesn't have the function to do so. As a result, the upgrade feature is broken and the contracts are stuck as they are.
What is Misconfiguration?
Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.