Skip to content
Misconfiguration Audit finding Intermediate

The Constructor Caveat leads to bricking of Configurator contract.

The Configurator contract sets critical state variables, including the governance address, in its constructor. Because it is deployed behind a proxy, those constructor assignments never run in the proxy's storage, leaving governance and the curve pool as the zero address and breaking all governance-dependent functions.

cthulhu_cult Follow

Originally disclosed on Code4rena

Submitted by cthulhu_cult

In Solidity, code that is inside a constructor or part of a global variable declaration is not part of a deployed contract’s runtime bytecode. This code is executed only once, when the contract instance is deployed. As a consequence of this, the code within a logic contract’s constructor will never be executed in the context of the proxy’s state. This means that any state changes made in the constructor of a logic contract will not be reflected in the proxy’s state.

  1. This will lead to governance timelocks contract and the curvePool contract contain default values of zero values.
  2. As a result, all the functions that rely on governance will be broken, since the governance address is set to zero address.

Proof of Concept

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Test.sol";
import {ITransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

import {LybraProxy} from "@lybra/Proxy/LybraProxy.sol";
import {LybraProxyAdmin} from "@lybra/Proxy/LybraProxyAdmin.sol";
import {GovernanceTimelock} from "@lybra/governance/GovernanceTimelock.sol";
import {PeUSDMainnet} from "@lybra/token/PeUSDMainnetStableVision.sol";
import {Configurator} from "@lybra/configuration/LybraConfigurator.sol";
import {EUSDMock} from "@mocks/mockEUSD.sol";
import {mockCurve} from "@mocks/mockCurve.sol";
import {mockUSDC} from "@mocks/mockUSDC.sol";

/* remappings used
@lybra=contracts/lybra/
@mocks=contracts/mocks/
 */
contract CounterScript is Test {
    address goerliEndPoint = 0xbfD2135BFfbb0B5378b56643c2Df8a87552Bfa23;

    LybraProxy proxy;
    LybraProxyAdmin admin;
    GovernanceTimelock govTimeLock;
    mockUSDC usdc;
    mockCurve curve;
    Configurator configurator;
    Configurator configuratorLogic;
     EUSDMock eusd;
    PeUSDMainnet peUsdMainnet;
    address owner = address(7);
    address[] govTimelockArr;

     function setUp() public {
         vm.startPrank(owner);
         govTimelockArr.push(owner);
         govTimeLock = new GovernanceTimelock(
             1,
             govTimelockArr,
             govTimelockArr,
             owner
         );

         usdc = new mockUSDC();
         curve = new mockCurve();
         eusd = new EUSDMock(address(configurator));
         //  _dao , _curvePool
         configuratorLogic = new Configurator(address(govTimeLock), address(curve));

         admin = new LybraProxyAdmin();
         proxy = new LybraProxy(address(configuratorLogic),address(admin),bytes(""));
         configurator = Configurator(address(proxy));

        peUsdMainnet = new PeUSDMainnet(
             address(configurator),
             8,
             goerliEndPoint
         );
         vm.stopPrank();
    }

    function test_LybraConfigurationContractDoesNotInitialize() public {
        vm.startPrank(address(owner));
        vm.expectRevert(); // Since the Governance time lock is set to zero.
        configurator.initToken(address(eusd), address(peUsdMainnet));
    }
}

Tools Used

  1. Manual Code review
  2. Foundry for POC

Recommended Mitigation Steps

LybraConfiguration.sol#L81 contracts should move the code within the constructor to a regular “initializer” function, and have this function be called whenever the proxy links to this logic contract. Special care needs to be taken with this initializing function so that it can only be called once and use another initialization mechanism, since the governance address should be set in the initialize.

Assessed type

Upgradable

LybraFinance confirmed

0xean (judge) commented:

On the fence re: severity here and could see the argument for this being M. Will leave as submitted for now, but open to comment during QA on the topic.


The original report as published on Code4rena, by cthulhu_cult. 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

The logic contract initialises critical state variables in its constructor instead of in an initializer function called through the proxy.

Impact

Governance-dependent functions are broken because the governance address is zero, and the curve pool also holds default zero values.

What the attacker needed

Contract deployed behind a proxy

The fix

The constructor logic should be moved into an initializer function that is called once through the proxy, with protection against being called more than once.

How it was found

  1. Deploy the GovernanceTimelock contract.
  2. Deploy the Configurator logic contract with the timelock and curve pool addresses.
  3. Deploy a proxy pointing at the Configurator logic contract.
  4. Call initToken on the proxy and observe it reverts because the governance address is zero.

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 proxy is a contract that forwards calls to another contract (the logic contract) while keeping its own storage. When the logic contract is deployed, its constructor runs only in the logic contract's own storage, not in the proxy's storage. So any values set in the constructor, such as the governance address, are missing when users interact through the proxy.

What is Misconfiguration?

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.

More from Lybra Finance

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Security misconfiguration

The lesson behind this report.

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.