Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialization Deadlock in KatanaV3Pool Due to Conflicting Constructor and initializeImmutables Logic #44

Closed
howlbot-integration bot opened this issue Nov 4, 2024 · 1 comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate-26 🤖_04_group AI based duplicate group recommendation sufficient quality report This report is of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@howlbot-integration
Copy link

Lines of code

https://github.com/ronin-chain/katana-v3-contracts/blob/03c80179e04f40d96f06c451ea494bb18f2a58fc/src/core/KatanaV3Pool.sol#L111
https://github.com/ronin-chain/katana-v3-contracts/blob/03c80179e04f40d96f06c451ea494bb18f2a58fc/src/core/KatanaV3Pool.sol#L117

Vulnerability details

Summary

The KatanaV3Pool contract has an initialization deadlock where the constructor sets factory = address(1) while initializeImmutables() requires factory == address(0) to proceed. This creates a paradox. The initialization protection mechanism conflicts with the proxy pattern design, creating a deadlock where the very check meant to protect initialization makes it impossible.

constructor() {
    factory = address(1);  // Sets factory to 1
}

function initializeImmutables(...) public virtual override {
    require(factory == address(0), "AII");  // Requires factory to be 0
    // ... initialization logic that can never be reached
}

Impact

  • Pool initialization is permanently blocked
  • Proxy deployment pattern becomes unusable
  • Contract parameters cannot be set
  • Pool cannot be used for its intended purpose

The problem stems from a contradiction in the initialization logic. The constructor immediately sets factory = address(1), but the initializeImmutables function requires factory == address(0) to proceed. This creates a logical impossibility - the initialization function can never be called successfully because its primary guard condition can never be satisfied.

Scenario

Let's walk through the execution flow:

  1. When the contract is deployed, the constructor executes:
constructor() {
    factory = address(1);
}

This permanently sets the factory address to 1. The comment suggests this is intended to "disable immutables initialization", but this creates issues with the proxy pattern implementation.

  1. Later, when someone attempts to initialize the pool through initializeImmutables, the first check is:
require(factory == address(0), "AII");

This check will always fail because factory is already set to address(1). The error "AII" (Already Initialized Immutables) will be thrown in every case.

This becomes particularly problematic when considering the contract's intended usage with proxy patterns, as indicated by the comment:

// These below immutable constants are set when deploying the beacon proxy of the pool and
// cannot be changed unless upgraded.

Fix

Remove the constructor initialization of factory since it's breaking the proxy initialization pattern:

// BEFORE - Problematic constructor
constructor() {
    // disable immutables initialization
    factory = address(1);  // This prevents initialization
}

// AFTER - Fixed constructor
constructor() {
    // Remove factory initialization entirely
    // Let proxy handle initialization properly
}

The initialization check in initializeImmutables() can stay as is:

function initializeImmutables(...) public virtual override {
    require(factory == address(0), "AII");  // Now this can actually pass during proxy initialization
    // ... rest of the initialization logic
}

The fixed version is better because:

  1. The proxy pattern already provides initialization safety
  2. The factory=1 setting was an unnecessary and problematic protection
  3. The require(factory == address(0)) check is sufficient for ensuring single initialization

This allows the proxy deployment pattern to work as intended while maintaining the one-time initialization guarantee through the zero-address check.

Assessed type

Context

@howlbot-integration howlbot-integration bot added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value 🤖_04_group AI based duplicate group recommendation bug Something isn't working duplicate-26 sufficient quality report This report is of sufficient quality labels Nov 4, 2024
howlbot-integration bot added a commit that referenced this issue Nov 4, 2024
@c4-judge
Copy link

alex-ppg marked the issue as unsatisfactory:
Invalid

@c4-judge c4-judge added the unsatisfactory does not satisfy C4 submission criteria; not eligible for awards label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate-26 🤖_04_group AI based duplicate group recommendation sufficient quality report This report is of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

1 participant