Skip to content
Smart contracts Audit finding Intermediate

Update initializer modifier to prevent reentrancy during initialization

The project used an outdated OpenZeppelin contracts library version with a known high-severity flaw in its initializer logic. An attacker could potentially re-enter an initializer function during initialisation, which the report says could undermine the contract's setup.

Dravee Follow

Originally disclosed on Code4rena

Submitted by Dravee

https://github.com/code-423n4/2022-02-hubble/blob/main/package.json#L17 https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/legos/Governable.sol#L5 https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/legos/Governable.sol#L24

While Governable.sol is out of scope, I figured this issue would still be fair game.

The solution uses: "@openzeppelin/contracts": "4.2.0". This dependency has a known high severity vulnerability: https://security.snyk.io/vuln/SNYK-JS-OPENZEPPELINCONTRACTS-2320176 Which makes this contract vulnerable:

File: Governable.sol
05: import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
...
24: contract Governable is VanillaGovernable, Initializable {}

This contract is inherited at multiple places:

contracts/AMM.sol:
  11: contract AMM is IAMM, Governable {

contracts/InsuranceFund.sol:
  13: contract InsuranceFund is VanillaGovernable, ERC20Upgradeable {

contracts/Oracle.sol:
  11: contract Oracle is Governable {

contracts/legos/HubbleBase.sol:
  15: contract HubbleBase is Governable, Pausable, ERC2771Context {

contracts/ClearingHouse.sol:
  11: contract ClearingHouse is IClearingHouse, HubbleBase {

contracts/MarginAccount.sol:
  25: contract MarginAccount is IMarginAccount, HubbleBase {

ìnitializer()` is used here:

contracts/AMM.sol:
  99:     ) external initializer {

contracts/ClearingHouse.sol:
  44:     ) external initializer {

contracts/MarginAccount.sol:
  124:     ) external initializer {

contracts/Oracle.sol:
  20:     function initialize(address _governance) external initializer {

Recommended Mitigation Steps

Upgrade @openzeppelin/contracts to version 4.4.1 or higher.

atvanguard (Hubble) confirmed and resolved

moose-code (judge) commented:

Agreed. Other issues such as this have also popped up, so always safest to be on the newest OZ. This includes for contracts and contracts-upgradeable packages.


The original report as published on Code4rena, by Dravee. 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 project pinned an old OpenZeppelin contracts release whose Initializable modifier did not guard against reentrant calls during initialisation.

Impact

Contracts inheriting the flawed initializer could be re-entered during setup, though the report does not demonstrate a concrete exploit or loss.

What the attacker needed

Contract uses OpenZeppelin 4.2.0 Initializable; attacker can call during initialisation

The fix

The dependency should be upgraded to OpenZeppelin contracts 4.4.1 or later; the report notes the team confirmed and resolved it.

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.

Smart contracts are programs on a blockchain. Some are set up once by an 'initializer' function instead of a constructor. The library used to write that function had a bug: while setup was still running, someone could call back into it. The report only points at the outdated library version and does not show a working attack.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by Dravee

View all

9 more disclosed reports, best first.

More from Hubble contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.