QuantAMM

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

missing validation at pool creation leading to errors

Summary

At pool creation in QuantAMMWeightedPoolFactory both functions createWithoutArgs and create don't enforce the number of tokens to match the number of initial weights leading to errors with swapping

ex: a pool created with n tokens of 8 but only gave initialweights with a length of 4
a pool would be created for 4 tokens but registered on the vault with 8 tokens

The error appears when using swaps calling onSwap function from the vault as on the vault there are 8 tokens registered so he try to swap between ex: index 7 and index 0. The swap will revert with out of bounds as there are only 4 tokens in the pool not 8

POC

Add this test function in QuantAMMWeightedPool2TokenTest

function testOnSwapInGivenOutInitial_wrong_index() public {
QuantAMMWeightedPoolFactory.NewPoolParams memory params = _createPoolParams();
(address quantAMMWeightedPool, ) = quantAMMWeightedPoolFactory.create(params);
int256[] memory newWeights = new int256[]();
newWeights[0] = 0.6e18;
newWeights[1] = 0.4e18;
newWeights[2] = 0e18;
newWeights[3] = 0e18;
vm.prank(address(updateWeightRunner));
QuantAMMWeightedPool(quantAMMWeightedPool).setWeights(
newWeights,
quantAMMWeightedPool,
uint40(block.timestamp + 5)
);
uint256[] memory balances = new uint256[]();
balances[0] = 1000e18;
balances[1] = 2000e18;
PoolSwapParams memory swapParams = PoolSwapParams({
kind: SwapKind.EXACT_OUT,
amountGivenScaled18: 100e18,
balancesScaled18: balances,
indexIn: 0,
indexOut: 2,
router: address(router),
userData: abi.encode(0)
});
vm.expectRevert();
vm.prank(address(vault));
uint256 newBalance = QuantAMMWeightedPool(quantAMMWeightedPool).onSwap(swapParams);
}

Impact

  • broken onSwap function

  • contradiction between tokens recorded for the pool in the vault and real ones

Tools Used

Manual review

Recommendations

Add an extra check when creating a pool to ensure that initialWeights length match tokens length

++ require(params.tokens.length = params._initialWeights.length, " tokens must match weights length")
Updates

Lead Judging Commences

n0kto Lead Judge 11 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!