Admin will not be able to upgrade the smart contracts, breaking core functionality and rendering the upgradeable contracts useless
The AssetFactory and FlashSwapRouter contracts inherit UUPSUpgradeable but use the notDelegated modifier on their initialize and _authorizeUpgrade functions, preventing them from being called through a proxy. As a result, the admin cannot upgrade these contracts, breaking core functionality and potentially causing stuck or lost funds.
0x73696d616f Follow with MadSisyphus and dimulski
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-08-cork-protocol-judging/issues/185
Found by
0x73696d616f, MadSisyphus, dimulski
Summary
The AssetFactory and FlashSwapRouter inherit the UUPSUpgradeable contract in order to be upgradeable. However, AssetFactory::initialize(), FlashSwapRouter::initialize(), AssetFactory::_authorizeUpgrade() and FlashSwapRouter::_authorizeUpgrade() have the notDelegated, which means they can not be called in the context of a proxy, hence they can not be upgradeable.
This renders the inherited UUPSUpgradeable useless and the 2 contracts will not be upgradeable. Additionally, the AssetFactory and FlashSwapRouter contracts are not deployed behind proxies, meaning that this problem would be noticed when trying to upgrade and failing.
Root Cause
In AssetFactory.sol:48, AssetFactory.sol:195, FlashSwapRouter.sol:32 and FlashSwapRouter.sol:41 the notDelegated modifiers are used.
Internal pre-conditions
None.
External pre-conditions
None.
Attack Path
Admin tries to upgrade the AssetFactory and FlashSwapRouter contracts but fails.
Impact
The UUPSUpgradeable contract is rendered useless, which means the AssetFactory and FlashSwapRouter contracts can not be upgraded. This leads to breaking major functionality as well as the possibility of stuck/lost funds.
PoC
FlashSwapRouter
contract RouterState is IDsFlashSwapUtility, IDsFlashSwapCore, OwnableUpgradeable, UUPSUpgradeable, IUniswapV2Callee {
...
function initialize(address moduleCore, address _univ2Router) external initializer notDelegated {
__Ownable_init(moduleCore);
__UUPSUpgradeable_init();
univ2Router = IUniswapV2Router02(_univ2Router);
}
...
function _authorizeUpgrade(address newImplementation) internal override onlyOwner notDelegated {}
}
AssetFactory
contract AssetFactory is IAssetFactory, OwnableUpgradeable, UUPSUpgradeable {
...
function initialize(address moduleCore) external initializer notDelegated {
__Ownable_init(moduleCore);
__UUPSUpgradeable_init();
}
...
function _authorizeUpgrade(address newImplementation) internal override onlyOwner notDelegated {}
}
Mitigation
Remove the notDelegated modifiers.
Discussion
ziankork
yes this is valid, we already removed this prior to our trading competition. will provide links later
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/Cork-Technology/Depeg-swap/pull/60
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
Impact
The contracts cannot be upgraded, which breaks major functionality and may lead to stuck or lost funds.
What the attacker needed
None
The fix
The notDelegated modifiers should be removed from the affected functions.
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 shows that two contracts were set up to be upgradeable but had a restriction that blocked the upgrade process entirely, so the admin could never perform an upgrade.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.