AMM Cannot Be initialize() Except By Governance
The AMM contract's initialize function calls syncDeps, which has an onlyGovernance modifier, so initialisation reverts unless the caller is the governance address. This prevents deployment by a normal deployer account and requires governance to deploy the proxy and encode arguments.
Originally disclosed on Code4rena
Submitted by kirk-baird
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/AMM.sol#L93-L108 https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/AMM.sol#L730-L734 https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/legos/Governable.sol#L10-L13
The contact AMM.sol cannot be initialize unless it is called from the _governance address.
This prevents the use of a deployer account and requires the governance to be able to deploy proxy contracts and encode the required arguements. If this is not feasible then the contract cannot be deployed.
Proof of Concept
initialize() calls _setGovernace(_governance); which will store the governance address.
Following this it will call syncDeps(_registry); which has onlyGovernance modifier. Thus, if the msg.sender of initialize() is not the same as the parameter _governance then the initialisation will revert.
function initialize(
address _registry,
address _underlyingAsset,
string memory _name,
address _vamm,
address _governance
) external initializer {
_setGovernace(_governance);
vamm = IVAMM(_vamm);
underlyingAsset = _underlyingAsset;
name = _name;
fundingBufferPeriod = 15 minutes;
syncDeps(_registry);
}
Recommended Mitigation Steps
Consider adding the steps manually to initialize(). i.e.
function initialize(
address _registry,
address _underlyingAsset,
string memory _name,
address _vamm,
address _governance
) external initializer {
_setGovernace(_governance);
vamm = IVAMM(_vamm);
underlyingAsset = _underlyingAsset;
name = _name;
fundingBufferPeriod = 15 minutes;
IRegistry registry = IRegistry(_registry);
clearingHouse = registry.clearingHouse();
oracle = IOracle(registry.oracle());
}
atvanguard (Hubble) confirmed and resolved
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 initialize function calls syncDeps, which is restricted to governance, before the caller is guaranteed to be the governance address.
Impact
The contract cannot be deployed by a normal deployer account; deployment is only possible if governance itself deploys the proxy and encodes the arguments.
What the attacker needed
Governance must deploy the proxy; governance must encode constructor arguments
The fix
The recommended mitigation is to replace the syncDeps call with direct registry lookups inside initialize.
How it was found
- Call initialize with a governance address different from the caller.
- initialize sets the governance address to the parameter.
- initialize then calls syncDeps, which checks that the caller is governance.
- The check fails and the transaction reverts.
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 often has a setup function that runs once after deployment. Here that setup function calls another function that only the governance address is allowed to call. So if a normal deployer tries to set it up, the transaction fails.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.