Incorrect initialization of smart contracts with Access Control issue
Smart contracts deployed via a proxy were left uninitialised because the proxy's initialisation data was empty, and the initialise functions lacked access control. An attacker could call initialise first to set themselves as the owner or treasury address, potentially stealing fees or disrupting the protocol.
Submitted by Haipls, also found by byndooa, cryptphi, and TrungOre
HomeFiProxy.sol#L216-L230 Community.sol#L102-L119 DebtToken.sol#L43-L58 Disputes.sol#L74-L81 HomeFi.sol#L92-L120 Project.sol#L94-L105 ProjectFactory.sol#L45-L55
All next Impact depends on actions and attention from developers when deployed
- Loss of funds
- Failure of the protocol, with the need for redeploy
- Loss of control over protocol elements (some smart contracts)
- The possibility of replacing contracts and settings with harmful ones
And other things that come out of it…
Proof of Concept
For a proper understanding of Proof of Concept, you need to understand the following things:
- Hardhat does not stop the process with a deploy and does not show failed transactions if they have occurred in some cases
- Malicious agents can trace the protocol deployment transactions and insert their own transaction between them
Reason:
- During deploy TransparentUpgradeableProxy’s initialize method for initializing contracts not called. The third parameter responsible for this is an empty string. This causes the initialization process itself to be delayed
- Contract initialization methods have no check over who calls them
Example ProjectFactory.sol#L45-L55
Also suitable for other contracts, strings are attached in Links to affected code
Examples of exploiting the vulnerability
Failure of the protocol, with the need for redeploy && Loss of control over protocol elements (some smart contracts):
- User listen transaction in mempool, etherscan, transaction in block etc
- Finds the moment of deployment and sends the transaction for setup his HomeFi address in Disputes contract: Just he call initialize method and put his _homeFi parameter
- In the event that hardhat tracked a failed transaction, the deployment will stop and you will need to start over. If the hardhead misses it and the developers do not check the result and the setting, access to this part will be lost and fix is needed
Loss of funds:
- User listen transaction in mempool, etherscan, transaction in block for listne when HomeFi will deployed
- Send transaction for initialize HomeFi with his _treasury address
- Transfer the admin ownership the right to the real address to divert the eyes
- The address of the treasury remains with the attacker
- The protocol fees (fee) will be transfered to the attacker’s address until it is detected
Recommended Mitigation Steps
Carry out checks at the initialization stage or redesign the deployment process with the initialization of contracts during deployment
zgorizzo69 (Rigor) confirmed, but disagreed with severity and commented:
About the reasons
- TransparentUpgradeableProxy third parameter is optionally initialized with
_dataas explained in {ERC1967Proxy-constructor}- incorrect modifiers check that addresses are not address(0) about the possible exploit Interesting take on how the dark forest’s creatures can harm the deployment process however if a tx fails the whole deployment script stops but I think it is a good practice to indeed verify after each initialization
Jack the Pug (judge) decreased severity to Medium and commented:
Valid, but gonna downgrade it to Medium as the impact is not that severe in practice.
Btw, in response to the response about the 2nd reason:
Contract initialization methods have no check over who calls them. incorrect modifiers check that addresses are not address(0)
“no check over who calls them” means no access control. It can be called by anyone. It’s not about the input validation.
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 proxy was deployed without initialisation data and the initialise functions had no access control, so anyone could call them before the legitimate setup.
Impact
An attacker could take control of some contracts or redirect fees, but the report notes this depends on developer actions and attention during deployment, and the judge downgraded severity because the impact is not that severe in practice.
What the attacker needed
Attacker can watch deployment transactions; initialise functions lack access control; proxy deployed without initialisation data
The fix
The report recommends adding checks during initialisation or redesigning deployment to initialise contracts during deployment; the text does not state that a fix was applied.
How it was found
- Watch the blockchain for the deployment of the HomeFi contract.
- Call the initialise function on HomeFi with an attacker-controlled treasury address.
- Transfer admin ownership to the real address to avoid suspicion.
- Receive protocol fees at the attacker's treasury address until detected.
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.
When a smart contract is deployed, it often needs a separate setup step to set who controls it. Here, that setup step was left open to anyone, and the deployment did not do it automatically. An attacker watching the blockchain could call the setup first and become the controller.
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.