Submitted by Chom
https://github.com/Plex-Engineer/stableswap/blob/489d010eb99a0885139b2d5ed5a2d826838cc5f9/contracts/BaseV1-core.sol#L190-L201
https://github.com/Plex-Engineer/stableswap/blob/489d010eb99a0885139b2d5ed5a2d826838cc5f9/contracts/BaseV1-core.sol#L154-L171
Attacker may use huge amount of their fund to pump the token in a liquidity pair for one entire block. The oracle will capture the manipulated price as current TWAP implementation may only cover 1 block if timed correctly. (First block on every periodSize = 1800 minutes)
This is possible and similar to Inverse finance April attack: https://www.coindesk.com/tech/2022/04/02/defi-lender-inverse-finance-exploited-for-156-million/
Assume currently is the first block after periodSize = 1800 minutes
timeElapsed > periodSize (Just greater as periodSize is just passed) -> add current cumulative reserve to observations list
Now, let pump the token. And use some technique that inverse finance hacker have used to hold that price for 1 block.
1 Block passed
reserve0Cumulative or reserve1Cumulative may now be skyrocketed due to current token pumping.
timeElapsed = block.timestamp - _observation.timestamp is less than 20 seconds (= 1 block) since _observation.timestamp has just stamped in the previous block.
As timeElapsed is less than 20 seconds (= 1 block) this mean _reserve0 and _reserve1 are just a TWAP of less than 20 seconds (= 1 block) which is easily manipulated by Inverse finance pumping attack technique.
As reserve0Cumulative or reserve1Cumulative is skyrocketed in the 1 block timeframe that is being used in TWAP, _reserve0 or _reserve1 also skyrocketed.
As a conclusion, price oracle may be attacked if attacker can pump price for 1 block since TWAP just cover 1 block.
You should calculate TWAP average of _reserve0 and _reserve1 in the _update function by using cumulative reserve difference from last update to now which has a duration of periodSize = 1800 minutes.
And when querying for current price you can just return _reserve0 and _reserve1.
Refer to official uniswap v2 TWAP oracle example: https://github.com/Uniswap/v2-periphery/blob/master/contracts/examples/ExampleOracleSimple.sol
nivasan1 (Canto) acknowledged
Alex the Entreprenerd (judge) decreased severity to Medium and commented:
