The function is intended to calculate reserves, but is flawed in it's calculations, leading to incorrect(inflated) reserve values.
From here onward assume the
calcReserve()
fromConstantProduct
ascalcReserveA()
and thecalcReserve()
fromConstantProduct2
as `calcReserveB()
Assume we are passing in n
as 2 cause we are trying to calculate the reserves in a two token well, which in normal instances should lead to the same for values in both implementations, keeping the exponentials asides
Given:
reserves = [1000]
j = 1
n = 2
lpTokenSupply = 100
calcReserveA()
calculates:
calcReserveB
calculates
Evidently we can see that the crucial step of dividing the lpTokenSupply
by the amount of tokens (2)
in the well is missing.
The formula in the current calculation would lead to returning the values of inflated reserve calculations, leading to mismanagement/misassumption of funds & incorrect protocol behaviour in all instances where the reserves is expected to be rightly returned
Manual Review
Reimplement the functionalities to be synced, considering in the previous implementation the lpTokenSupply
is first divided by the amount of tokens before being powered by it, i.e (lpTokenSupply / n) ** n
here however we only have the lpTokenSupply ** n
.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.