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

Potential overflow at updateBaseRate() function #142

Open
code423n4 opened this issue Jul 2, 2022 · 1 comment
Open

Potential overflow at updateBaseRate() function #142

code423n4 opened this issue Jul 2, 2022 · 1 comment
Labels
bug Something isn't working QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 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

Lines of code

https://github.com/Plex-Engineer/lending-market-v2/blob/443a8c0fed3c5018e95f3881a31b81a555c42b2d/contracts/NoteInterest.sol#L145-L147

Vulnerability details

Impact

When casting to int from uint, the overflow might happen.

Proof of Concept

https://github.com/Plex-Engineer/lending-market-v2/blob/443a8c0fed3c5018e95f3881a31b81a555c42b2d/contracts/NoteInterest.sol#L145-L147

            uint twapMantissa = oracle.getUnderlyingPrice(cNote); // returns price as mantissa
            //uint ir = (1 - twapMantissa).mul(adjusterCoefficient).add(baseRatePerYear);
            int diff = BASE - int(twapMantissa); //possible annoyance if 1e18 - twapMantissa > 2**255, differ

int(twapMantissa) can overflow depending on the value of uint twapMantissa. Even if this is not expected, handling this case should be good.

Tools Used

Static analysis

Recommended Mitigation Steps

Consider using the logic of toInt256 provided by OpenZeppelin.

https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeCast.sol#L1130-L1134

@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 Jul 2, 2022
code423n4 added a commit that referenced this issue Jul 2, 2022
@nivasan1 nivasan1 added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Jul 20, 2022
@GalloDaSballo
Copy link
Collaborator

I think the warden has shown code where theoretically a potential overflow could happen.

However, both the oracle and the Router will return a uint

Because the pattern is a code smell, I'll downgrade to QA - NC. However I believe the overflow cannot ever happen in the in-scope codebase

@GalloDaSballo GalloDaSballo added QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Aug 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 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