MerkleMinter created through TokenFactory cannot be upgraded
The TokenFactory contract creates MerkleMinter instances using a clone (minimal proxy) rather than an upgradeable proxy, so the resulting contract cannot be upgraded despite inheriting from an upgradeable base. An attacker could not exploit this directly; it is a functional flaw that prevents the intended upgrade path.
Submitted by adriro
During the token creation process in the TokenFactory contract, the function creates a MerkleMinter contract to setup and handle token initial token distribution.
...
// Clone and initialize a `MerkleMinter`
address merkleMinter = merkleMinterBase.clone();
MerkleMinter(merkleMinter).initialize(
_managingDao,
IERC20MintableUpgradeable(token),
distributorBase
);
...
The MerkleMinter contract is an upgradeable contract, as it inherits from PluginUUPSUpgradeable:
contract MerkleMinter is IMerkleMinter, PluginUUPSUpgradeable {
However, as we can see in the first code snippet, the MerkleMinter instance created in createToken is a cloned instance (using OpenZeppelin Clones library). This is incompatible with upgradeable contracts, which require the use of a proxy.
This issue will cause the MerkleMinter instance created through TokenFactory to fail to be upgraded. The MerkleMinter contract will contain all the required logic to be upgraded, but the action will fail as there is no proxy to change to a new potential implementation.
Proof of Concept
The following test illustrates the issue. We call createToken to get an instance of MerkleMinter. We then simulate a new version of the contract to upgrade to (merkleMinterV2Impl) and try to upgrade the MerkleMinter instance to this new implementation. The call fails with a “Function must be called through active proxy” error (error is defined in OpenZeppelin base UUPSUpgradeable contract).
Note: the snippet shows only the relevant code for the test. Full test file can be found here.
function test_TokenFactory_createToken_MerkleMinterNotUpgradeable() public {
DAO dao = createDao();
TokenFactory tokenFactory = new TokenFactory();
grantRootPermission(dao, address(tokenFactory));
TokenFactory.TokenConfig memory tokenConfig = TokenFactory.TokenConfig({
addr: address(0),
name: "DAO Token",
symbol: "DAOT"
});
address[] memory receivers = new address[](0);
uint256[] memory amounts = new uint256[](0);
GovernanceERC20.MintSettings memory mintSettings = GovernanceERC20.MintSettings({
receivers: receivers,
amounts: amounts
});
(, MerkleMinter merkleMinter) = tokenFactory.createToken(dao, tokenConfig, mintSettings);
// Assume we have a new V2 implementation...
MerkleMinter merkleMinterV2Impl = new MerkleMinter();
// The following will fail when the UUPS checks if the upgrade came from the proxy (since there's no proxy)
vm.expectRevert("Function must be called through active proxy");
PluginUUPSUpgradeable(merkleMinter).upgradeTo(address(merkleMinterV2Impl));
}
Recommendation
The MerkleMinter instance should be created using a proxy over the base implementation (createERC1967Proxy) instead of cloning the implementation:
diff --git a/src/framework/utils/TokenFactory.sol b/src/framework/utils/TokenFactory.sol
index 381e745..91441e5 100644
--- a/src/framework/utils/TokenFactory.sol
+++ b/src/framework/utils/TokenFactory.sol
@@ -15,6 +15,7 @@ import {GovernanceWrappedERC20} from "../../token/ERC20/governance/GovernanceWra
import {IERC20MintableUpgradeable} from "../../token/ERC20/IERC20MintableUpgradeable.sol";
import {DAO} from "../../core/dao/DAO.sol";
import {IDAO} from "../../core/dao/IDAO.sol";
+import {createERC1967Proxy} from "../../utils/Proxy.sol";
/// @title TokenFactory
/// @author Aragon Association - 2022-2023
@@ -116,12 +117,15 @@ contract TokenFactory {
_mintSettings
);
- // Clone and initialize a `MerkleMinter`
- address merkleMinter = merkleMinterBase.clone();
- MerkleMinter(merkleMinter).initialize(
- _managingDao,
- IERC20MintableUpgradeable(token),
- distributorBase
+ // Create proxy and initialize a `MerkleMinter`
+ address merkleMinter = createERC1967Proxy(
+ merkleMinterBase,
+ abi.encodeWithSelector(
+ MerkleMinter.initialize.selector,
+ _managingDao,
+ token,
+ distributorBase
+ )
);
// Emit the event
I don’t believe a MerkleMinter instance is intended to be upgradeable.
“The Clones library provides a way to deploy minimal non-upgradeable proxies for cheap. This can be useful for applications that require deploying many instances of the same contract (for example one per user, or one per task). These instances are designed to be both cheap to deploy, and cheap to call. The drawback being that they are not upgradeable.”
Will leave open for sponsor confirmation. But most likely this is invalid.
novaknole20 (Aragon) confirmed
It appears the sponsor does intend for this to be upgradeable since they confirmed the issue. Awarding as Medium.
Please note: the following additional discussion took place after judging and awarding were finalized.
novaknole20 (Aragon) commented:
Sorry we don’t know why this got confirmed from our side… As seen in the code the MerkleMinter is only used by the
TokenFactoryand there we use clones (minimal non-upgradable proxies). Therefore we need to extend fromPluginUUPSUpgradeableto disable the initializer in the base during construction. We’d like to note our mistake in accepting it and that we never intend to use it in an upgradeable pattern.
novaknole20 (Aragon) commented:
MerkleMinterisUUPSUpgradeableand the upgradeability is part of its feature set. However, in the context of theTokenFactorywe opted to deploy it via the minimal proxy pattern to save gas. This is because its upgradeability feature is not needed here and the cloning can be done as well. We are fully aware that theMerkleMinterproxies created through theTokenFactoryare not upgradeable.Although we accidentally accepted this medium risk finding initially, we don’t think that intentional absent of upgradeability qualifies as medium risk/finding. Accordingly, we would suggest to not rate this as a medium risk finding in the final audit report.
To make our intentions more clear, we made the following change to the documentation: https://github.com/aragon/osx/pull/362/files
It is also worth noting that we are currently using neither
TokenFactorynorMerkleMinter/MerkleDistributorin our framework and that we will move the code out of the aragon/osx repository in the future.
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 factory used a clone (minimal non-upgradeable proxy) for a contract that inherits from an upgradeable base, so the upgrade mechanism has no proxy to operate on.
Impact
The MerkleMinter created via TokenFactory cannot be upgraded, but the sponsor later clarified that upgradeability was intentionally omitted in this context, so no security impact was accepted.
What the attacker needed
TokenFactory deployed and used to create a token
The fix
The instance should be created using an upgradeable proxy (createERC1967Proxy) instead of cloning, though the sponsor stated the non-upgradeable behaviour was intentional and only updated documentation.
How it was found
- Call createToken on TokenFactory to obtain a MerkleMinter instance.
- Deploy a new implementation contract to upgrade to.
- Call upgradeTo on the MerkleMinter instance with the new implementation.
- Observe the call reverts with 'Function must be called through active proxy'.
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.
A smart contract can be designed to be upgradeable, meaning its logic can be replaced later while keeping the same address. This usually requires deploying it behind a special proxy contract. Here, the factory used a cheaper clone that cannot be upgraded, so attempts to upgrade fail.
What is Misconfiguration?
Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.