Missing scaling factor in recordKeyPurchase
?
#156
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
help wanted
Extra attention is needed
Handle
cmichel
Vulnerability details
The
Unlock.recordKeyPurchase
function computes themaxTokens
as:Note that
grossNetworkProduct
was already increased byvalueInETH
in the code before.Meaning, the
(2 + 2 * valueInETH / grossNetworkProduct)
part of the computation will almost always be2
as usuallygrossNetworkProduct > 2 * valueInETH
, and thus the2 * valueInETH / grossNetworkProduct
is zero by integer division.Impact
The
maxTokens
curve might not be computed as intended and lead to being able to receive more token rewards than intended.Recommended Mitigation Steps
The comment "we distribute tokens using asymptotic curve between 0 and 0.5" should be more clear to indicate how exactly the curve looks like.
It could be that a floating-point number was desired instead of the integer division in
2 * valueInETH / grossNetworkProduct
. In that case, consider adding a scaling factor to this term and divide by it at the end of the computation again.The text was updated successfully, but these errors were encountered: