Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lost annualized fees due to early division #155

Open
code423n4 opened this issue Dec 19, 2021 · 1 comment
Open

Lost annualized fees due to early division #155

code423n4 opened this issue Dec 19, 2021 · 1 comment
Labels
1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

Handle

kenzo

Vulnerability details

An early division in calcOutStandingAnnualizedFee will lose accuracy of the fees calculation.

Impact

Lost fees for the protocol.

Proof of Concept

calcOutStandingAnnualizedFee uses the following formula to calculate the fees: (Code ref)

return
            totalSupply.mul(annualizedFee).div(10**18).mul(timePassed).div(
                365 days
            );

Since it is dividing by 10**18 in the middle of the calculation, the remainder of that division will be lost.
This is why in Solidity, division should come in the end.

Recommended Mitigation Steps

Move div(10**18) to the end of the calculation.

By the way, you might wanna consider changing your fee structure to a smaller basis. Making the base 1e18 gives you granularity that you might not need. For example, if the annualized fee is planned to be 1%, instead of it being 1e15 out of 1e18 it can be 100 out of 10000. This will help prevent overflow if that was the reason you chose to divide in the midst of the calculation.

@code423n4 code423n4 added 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 labels Dec 19, 2021
code423n4 added a commit that referenced this issue Dec 19, 2021
@loki-sama loki-sama added disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") labels Jan 4, 2022
This was referenced Jan 7, 2022
@0xleastwood
Copy link
Collaborator

I think this qualifies as low. Typically value leak from the protocol would be considered medium, however, this value isn't actually lost but just slightly incorrect.

@0xleastwood 0xleastwood added 1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Jan 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

No branches or pull requests

3 participants