Skip to content

Latest commit

 

History

History
102 lines (74 loc) · 4.48 KB

File metadata and controls

102 lines (74 loc) · 4.48 KB

Polynance Protocol Implementation Bug Report

Executive Summary

After extensive testing of the Polynance Protocol's Pool contract, I have identified a critical bug in the market initialization logic that prevents the borrow and repay functionality from working correctly. While the core financial logic appears sound, this implementation bug blocks all market operations.

Test Results Summary

Supply Tests: 100% Passing (7/7 tests)

  • All supply functionality works correctly
  • LP token minting, storage updates, and Aave integration function as expected
  • Fee calculations and edge cases handled properly

Borrow/Repay Tests: 27% Passing (3/11 tests)

  • Only tests that expect reverts pass
  • All positive test cases fail due to market initialization bug
  • Core borrow/repay logic cannot be tested due to the blocker

Critical Bug: Inverted Market Initialization Check

Location

src/Pool.sol:247

Bug Description

The market initialization check contains inverted logic:

// CURRENT (BUGGY) CODE:
if (isMarketActive[marketId]) revert PolynanceEE.MarketNotActive();

This code reverts with "MarketNotActive" when the market IS active, which is the opposite of the intended behavior.

Expected Behavior

// CORRECTED CODE:
if (!isMarketActive[marketId]) revert PolynanceEE.MarketNotActive();

The check should revert when the market is NOT active.

Impact

  1. Market Initialization Blocked: Curators cannot initialize new markets as the function fails when trying to initialize an inactive market
  2. All Borrow Operations Fail: Since markets cannot be initialized, all borrow attempts fail
  3. All Repay Operations Fail: Repay functionality depends on having active borrows
  4. Protocol Unusable: The entire lending functionality of the protocol is blocked

Attempted Workarounds

During testing, I attempted several workarounds:

  1. Direct Storage Manipulation: Tried to bypass initialization by directly setting market data in storage
  2. Commenting Out Checks: The _ensureMarketInitialized function body is already commented out (lines 266-270)
  3. Alternative Initialization: Tried using ReserveLogic.initializeMarket directly

None of these workarounds were sufficient because the bug is in the public initializeMarket function that curators must call.

Code Quality Observations

Positive Aspects

  1. Clean Architecture: The Functional Core/Imperative Shell pattern is well-implemented
  2. Math Precision: Proper use of Ray (1e27) and Wad (1e18) precision
  3. Storage Separation: Clear separation between business logic and storage
  4. Comprehensive Events: Good event coverage for tracking operations

Areas of Concern

  1. Incomplete Implementation:

    • _ensureMarketInitialized function body is commented out
    • Market initialization flow is broken
    • Liquidation logic is stubbed (mentioned as V2 feature)
  2. Testing Gaps:

    • No integration tests for the complete flow
    • Market initialization not properly tested
    • Missing tests for edge cases in multi-market scenarios

Recommendations

Immediate Fix Required

  1. Fix the inverted logic in Pool.sol:247
  2. Uncomment and properly implement _ensureMarketInitialized checks
  3. Add comprehensive tests for market initialization

Testing Strategy

After fixing the bug, the following test coverage is recommended:

  1. Market initialization tests (single and multiple markets)
  2. Full integration tests (supply → borrow → repay → withdraw)
  3. Multi-user scenarios with concurrent operations
  4. Interest accrual over various time periods
  5. Edge cases around LTV limits and liquidation thresholds

Additional Improvements

  1. Add require statements to verify market initialization state
  2. Implement proper access control for market operations
  3. Add circuit breakers for emergency situations
  4. Complete the liquidation implementation

Conclusion

The Polynance Protocol demonstrates solid financial engineering with its dual-layer debt system and integration with Aave V3. The mathematical models for utilization-based spread rates and multi-level debt calculations appear correct. However, the implementation has a critical bug that must be fixed before the protocol can function.

Once the market initialization bug is resolved, the protocol should undergo comprehensive testing to ensure all functionality works as designed. The clean architecture and separation of concerns suggest that fixing this bug should not require extensive refactoring.