QuantAMM

QuantAMM
49,600 OP
View results
Submission Details
Severity: low
Invalid

Weight validation missing in QuantAMM pool factory

Summary

The QuantAMMWeightedPoolFactory contract lacks essential validation for token weights during pool creation, violating a fundamental mathematical requirement of weighted pools. The weights must sum to FixedPoint.ONE (1.0) to ensure correct price calculations and pool operations.

Vulnerability Details

Here's the comment on the contract:

* @param normalizedWeights The pool weights (must add to FixedPoint.ONE)

https://github.com/Cyfrin/2024-12-quantamm/blob/a775db4273eb36e7b4536c5b60207c9f17541b92/pkg/pool-quantamm/contracts/QuantAMMWeightedPoolFactory.sol#L23C1-L23C73

Here are the affected code:

struct NewPoolParams {
string name;
string symbol;
TokenConfig[] tokens;
uint256[] normalizedWeights; // Weights accepted without validation
// ... other fields
}
function create(NewPoolParams memory params) external returns (address pool, bytes memory poolArgs) {
// No validation of normalizedWeights
pool = _create(abi.encode(
QuantAMMWeightedPool.NewPoolParams({
// ... parameters
}),
getVault()
), params.salt);
}
function createWithoutArgs(NewPoolParams memory params) external returns (address pool) {
// Same issue - no validation of normalizedWeights
pool = _create(abi.encode(
// ... same creation logic
), params.salt);
}

https://github.com/Cyfrin/2024-12-quantamm/blob/a775db4273eb36e7b4536c5b60207c9f17541b92/pkg/pool-quantamm/contracts/QuantAMMWeightedPoolFactory.sol#L44

https://github.com/Cyfrin/2024-12-quantamm/blob/a775db4273eb36e7b4536c5b60207c9f17541b92/pkg/pool-quantamm/contracts/QuantAMMWeightedPoolFactory.sol#L131C3-L173C2

https://github.com/Cyfrin/2024-12-quantamm/blob/a775db4273eb36e7b4536c5b60207c9f17541b92/pkg/pool-quantamm/contracts/QuantAMMWeightedPoolFactory.sol#L85C1-L125C6

The weight validation is crucial because:

  1. Price Calculation Formula: P = (Balance_out/Weight_out)/(Balance_in/Weight_in)

    • Incorrect weights directly distort this calculation

    • Example: With weights summing to 1.2 instead of 1.0, prices are off by 20%

  2. Pool Balance Requirements:

    Correct Example (sum = 1.0):
    - Token A: 0.4 (40%)
    - Token B: 0.6 (60%)
    Result: Balanced pricing and swaps
    Incorrect Example (sum = 1.3):
    - Token A: 0.7 (70%)
    - Token B: 0.6 (60%)
    Result: Overvalued assets, broken swap math

Impact

  1. Price Distortions:

    • Swaps execute at incorrect prices

    • Arbitrage opportunities emerge

    • Pool value can be extracted

  2. Liquidity Provider Effects:

    • Incorrect share distribution

    • Impermanent loss miscalculations

    • Unintended exposure ratios

  3. Pool Operations:

    • All swap calculations permanently incorrect

    • Join/Exit ratios distorted

    • Fee calculations inaccurate

  4. Connected Systems:

    • Price oracles receive wrong data

    • Connected pools affected

    • Trading strategies compromised

Tools Used

Manual review

Recommendations

function validateWeights(uint256[] memory weights) internal pure {
uint256 sum;
for (uint256 i = 0; i < weights.length; i++) {
sum += weights[i];
}
require(sum == FixedPoint.ONE, "Weights must sum to ONE");
}
function create(NewPoolParams memory params) external returns (address pool, bytes memory poolArgs) {
validateWeights(params.normalizedWeights); // Add validation
// Rest of creation logic
}
Updates

Lead Judging Commences

n0kto Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational or Gas / Admin is trusted / Pool creation is trusted / User mistake / Suppositions

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelyhood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!