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

QA Report #131

Open
code423n4 opened this issue Feb 23, 2022 · 3 comments
Open

QA Report #131

code423n4 opened this issue Feb 23, 2022 · 3 comments
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 disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/AMM.sol#L354
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/AMM.sol#L392
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/AMM.sol#L656-L704

Vulnerability details

Impact

The getTwapPrice() is used by the settleFunding() function to calculate the premium and subsequently the new funding rate. The _calcTwap() function will use the latest reserve snapshot if this snapshot is earlier than the baseTimestamp. As a result, if there are no changes on the underlying positions within the AMM, then the _addReserveSnapshot() function will never be called to update the price data. Over time, if the AMM is not being actively used, the funding rate can end up being drastically different to what it should be.

Proof of Concept

Tools Used

Manual code review.

Recommended Mitigation Steps

Consider calling _addReserveSnapshot() in settleFunding() to ensure the most up to date price is being used before calculating premium.

@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 Feb 23, 2022
code423n4 added a commit that referenced this issue Feb 23, 2022
@atvanguard atvanguard added the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label Feb 24, 2022
@atvanguard
Copy link
Collaborator

If the AMM has seen a period of inactivity then timestamp < baseTimestamp and it will return the latest known price which is intended behavior.

@JasoonS
Copy link
Collaborator

JasoonS commented Mar 6, 2022

A valid consideration from what I can tell.

@JasoonS JasoonS 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 Mar 6, 2022
@JeeberC4
Copy link

Since this issue was downgraded to a QA level, and the warden did not submit a separate QA report, we've renamed this one to "QA report" for consistency.
The original title, for the record, was AMM.getTwapPrice() Potentially Uses an Outdated Price

@JeeberC4 JeeberC4 changed the title AMM.getTwapPrice() Potentially Uses an Outdated Price QA Report Mar 24, 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 disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Projects
None yet
Development

No branches or pull requests

4 participants