Closed sherlock-admin closed 10 months ago
1 comment(s) were left on this issue during the judging contest.
auditsea commented:
The issue describes about TWAP can be manipulated because
update
function can be called anytime and by anyone, thus TWAP period can be as short as 1 block. It seems like a valid issue but after caeful consideration, it's noticed that the TWAP issue does not come from its period but the logic itself is incorrect, thus marking this as Invalid
1 comment(s) were left on this issue during the judging contest.
auditsea commented:
The issue describes about TWAP can be manipulated because
update
function can be called anytime and by anyone, thus TWAP period can be as short as 1 block. It seems like a valid issue but after caeful consideration, it's noticed that the TWAP issue does not come from its period but the logic itself is incorrect, thus marking this as Invalid
cducrest-brainbot
high
TWAPOracle price are calculated on very small windows
Summary
The
LibTWAPOracle
library responsible for calculating the price of Ubiquity dollar based on the 3CRV/Ubiquity dollar metapool uses time window that start at the previous update and end on the current block. This time window can be as small as a single block and is not suitable for a TWAP price calculation.Vulnerability Detail
The function to update the quote prices of the library uses the time window
blockTimestamp - ts.pricesBlockTimestampLast
to calculate the TWAP before updatingts.pricesBlockTimestampLast
toblockTimestamp
:blockTimestamp
is the latest update timestamp on the metapool:If the metapool is updated on block
x
andx+1
and the TWAP oracle is updated on the same blocks, then the time window for TWAP calculation is only 1 block.The update can be triggered externally with no restriction by anyone on the metapool (via any action that updates the balances) and on the TWAPOracle via
TWAPOracleDollar3poolFacet.update()
.Impact
The TWAP price for Ubiquity dollar relies on a very short window and is extremely easy to manipulate.
This TWAP price is used to determine whether minting/redeeming Ubiquity dollar is allowed in
LibUbiquityPool.sol
. These minting/redeeming functions are core to the stability of the Ubiquity dollar and if not properly protected will make the coin unstable.Code Snippet
https://github.com/sherlock-audit/2023-12-ubiquity/blob/main/ubiquity-dollar/packages/contracts/src/dollar/libraries/LibTWAPOracle.sol#L68-L102
https://github.com/sherlock-audit/2023-12-ubiquity/blob/main/ubiquity-dollar/packages/contracts/src/dollar/libraries/LibTWAPOracle.sol#L129-L137
https://etherscan.io/address/0x20955CB69Ae1515962177D164dfC9522feef567E#code
Tool used
Manual Review
Recommendation
Use a longer time window (e.g. a week) to calculate the TWAP price for Ubiquity dollar on the metapool.
Duplicate of #20