Open hats-bug-reporter[bot] opened 2 days ago
I think, its comment error. the implementation correctly using A value. check test
Thanks for your submission So typo's or errors in the documentation are not usually rewarded - as you can see from the rules. Can you please indicate where in the code there is an issue here?
Github username: -- Twitter username: -- Submission hash (on-chain): 0xca7711493d278c5dc733a88e0111ddbe6bb16bf6ce891e3898aab1fe2aa3774f Severity: medium
Description: Description\ In the
StableSwapTwoPool
andStableSwapThreePool
contracts, the amplification coefficient_A
is described in the comments as being scaled byn * (n - 1)
.This scaling is intended to adjust the amplification coefficient for use in the stable swap invariant equation. However, this formula is incorrect for pools with more than two tokens. The correct scaling should be
n**(n-1)
i.e n^(n-1)and not n*(n-1) to ensure accurate calculations in the stable swap algorithm.Attack Scenario\ For a pool with exactly two tokens (lets say n = 2), the formulas
2 * (2 - 1)
and2^(2-1)
retuns the same result, so the issue is not critical in this specific case. However, for pools with more than two tokens, such as theStableSwapThreePool
contract, the discrepancy becomes significant. Using the incorrect scaling factor can lead to inaccurate calculations when swapping between tokens, potentially resulting in incorrect token amounts being exchanged.Attachments
Consider a pool with three tokens (n = 3).
The current scaling formula
n * (n - 1)
would calculate the scaling factor as3 * (3 - 1) = 6
. However, the correct scaling factor should ben^(n-1) = 3^(3-1) = 9
. This difference in scaling can lead to significant errors in the invariant calculations and the resulting swap amounts.affected code:
StableSwapFactory.sol
StableSwapThreePool.sol
StableSwapTwoPool.sol
Additional resources: Same issue found in the connext which is also inspired by curve and the issue was found by the spearbit report
issue : 5.2.11
fix: https://github.com/connext/monorepo/commit/d7262e9e82e0f5c49d8fc31ba4352bfeac9c44fe
pr : https://github.com/connext/monorepo/pull/2353