code-423n4 / 2021-04-vader-findings

1 stars 0 forks source link

Wrong `calcAsymmetricShare` calculation #214

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

@cmichelio

Vulnerability details

Vulnerability Details

The inline-comment defines the number of asymmetric shares as (u * U * (2 * A^2 - 2 * U * u + U^2))/U^3 but the Utils.calcAsymmetricShare function computes (uA * 2U^2 - 2uU + u^2) / U^3 which is not equivalent as can be seen from the A^2 term in the first term which does not occur in the second one. The associativity on P * part1 is wrong, and part2 is not multiplied by P.

Impact

The math from the spec is not correctly implemented and could lead to the protocol being economically exploited, as the asymmetric share which is used to determine the collateral value in base tokens could be wrong. For example, it might be possible to borrow more than the collateral put up.

Recommended Mitigation Steps

Clarify if the comment is correct or the code and fix them.

strictly-scarce commented 3 years ago

Valid

strictly-scarce commented 3 years ago

Whilst the math is incorrect, in the current implementation it is not yet implemented, so disagree with Severity (funds not lost), recommend: 2