Skip to content
Access control Audit finding Intermediate

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.

Haipls Follow

Originally disclosed on Code4rena

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:

  1. Hardhat does not stop the process with a deploy and does not show failed transactions if they have occurred in some cases
  2. 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):

  1. User listen transaction in mempool, etherscan, transaction in block etc
  2. 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
  3. 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:

  1. User listen transaction in mempool, etherscan, transaction in block for listne when HomeFi will deployed
  2. Send transaction for initialize HomeFi with his _treasury address
  3. Transfer the admin ownership the right to the real address to divert the eyes
  4. The address of the treasury remains with the attacker
  5. 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 _data as 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.


The original report as published on Code4rena, by Haipls. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. Watch the blockchain for the deployment of the HomeFi contract.
  2. Call the initialise function on HomeFi with an attacker-controlled treasury address.
  3. Transfer admin ownership to the real address to avoid suspicion.
  4. 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.

More by Haipls

View all

7 more disclosed reports, best first.

More from Rigor Protocol contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.