Dispatcher.sol uses initializer modifier instead of onlyInitializing
The Dispatcher contract uses the initializer modifier instead of onlyInitializing, which prevents the parent Router contract from completing its own initialization. This could cause deployment failures for critical protocol contracts.
- Disclosed after under an hour
#43195 [SC-Insight] `Dispatcher.sol` uses `initializer` modifier instead of `onlyInitializing`
Submitted on Apr 3rd 2025 at 15:31:11 UTC by @Kyosi for Audit Comp | Spectra Finance
- Report ID: #43195
- Report Type: Smart Contract
- Report severity: Insight
- Target: https://github.com/immunefi-team/Spectra-Audit-Competition/blob/main/src/router/Dispatcher.sol
- Impacts:
- Contract fails to deliver promised returns, but doesn't lose value
Description
Brief/Intro
Dispatcher contract is a child contract of the Router contract and it uses initializer modifier instead of onlyInitializing. In the inheritance model, the contract Router has its own initialize function, which includes the initializer modifier and calls the __Dispatcher_init function of Dispatcher contract. The problem here is that both the parent contract (Router) and the child contract (Dispatcher) are using the initializer modifier, which limits initialization to only one call.
Vulnerability Details
According to the Openzeppelin documentation https://docs.openzeppelin.com/contracts/4.x/api/proxy#Initializable-initializer-- , the onlyInitializing modifier should be used to allow initialization in both the parent and child contracts (https://docs.openzeppelin.com/contracts/4.x/api/proxy#Initializable-onlyInitializing--). The onlyInitializing modifier ensures that when the initialize function is called, any contracts in the inheritance chain can still complete their own initialization. From the Openzeppelin docs: A modifier that defines a protected initializer function that can be invoked at most once. In its scope, onlyInitializing functions can be used to initialize parent contracts.
Impact Details
The vulnerability causes an operational issue, preventing inheriting contracts from completing initialization. This could lead to a failure in the deployment of critical protocol contracts, affecting the overall system functionality.
References
Same issue found in another protocol: https://solodit.cyfrin.io/issues/m-5-masteramo-should-not-use-the-initializer-modifier-sherlock-axion-git
Mitigation
Replace initializer with onlyInitializing on Dispatcher.sol
function __Dispatcher_init(address _routerUtil, address _kyberRouter) internal onlyInitializing {
if (_routerUtil == address(0)) {
revert AddressError();
}
routerUtil = _routerUtil;
kyberRouter = _kyberRouter;
}
Proof of Concept
Proof of Concept
None
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 developer used the initializer modifier on the child contract's internal init function instead of onlyInitializing, which blocks the parent contract's initialization.
Impact
This could lead to a failure in the deployment of critical protocol contracts, affecting the overall system functionality.
What the attacker needed
None
The fix
Replace initializer with onlyInitializing on Dispatcher.sol.
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.
In Solidity, contracts can inherit from other contracts. When a child contract is set up, it may need to call setup functions in its parent. The initializer modifier stops any setup from running more than once, so if both parent and child use it, the parent's setup is blocked. The onlyInitializing modifier is designed to allow each contract in the chain to run its own setup once.
What is Misconfiguration?
Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.