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

Document TWAP manipulation in PoS #16

Open
sambacha opened this issue Dec 20, 2022 · 1 comment
Open

Document TWAP manipulation in PoS #16

sambacha opened this issue Dec 20, 2022 · 1 comment

Comments

@sambacha
Copy link

TWAP is more susceptible to manipulation attacks in PoS, in fact Euler has moved to Chainlink from their TWAP oracles

https://github.com/euler-xyz/uni-v3-twap-manipulation

From Liveness section

Uniswap v3 TWAP oracles may fail in more subtle ways than manipulation. When calling observe, the oracle specifies a secondsAgo which is a parameter that sets the length of the TWAP. Observations is an array that contains cumulative values of the TWAP. If you call observe with secondsAgo = $[3600,0]$ you should get a 1 hour TWAP right? Well as long as sufficiently many entries of the observations array have been initialized so that the earliest tick cumulative was added at least an hour ago, you would be right. If the earliest tick cumulative is more recent than an hour ago, you are not actually getting a 1 hour TWAP you are getting something shorter.

The key insight in this discussion is that the number of initialized observations on a univ3 pool decides its TWAP behavior as much or more than secondsAgo in the observe call. The actionable result is to monitor this input when calculating oracle quality.

Refs.

https://www.euler.finance/blog/oracle-attack-simulator
https://oracle.euler.finance/
euler-xyz/uni-v3-twap-manipulation#3

@jjranalli
Copy link
Contributor

Thanks for opening this and linking these resources @sambacha, much appreciated! And apologies for getting back to you just now

On manipulation attacks
The Euler document linked actually states that single block manipulation is basically not possible, while multi-block risks outweighs potential rewards.

Practical considerations show that in real-life circumstances an attack on a Uni v3 TWAP for a liquid asset would be infeasible.

Also I'm not following the matter closely but from their docs it seems they're still using Uniswap as primary oracles and only use Chainlink for pairs with liquidity insufficient to protect from manipulation.

On oracle quality
Yes, number of observations influence oracle quality, which is why the feed provides a way to programmatically increase cardinality.

I'm planning to add an index to estimate quality and safety of a pool, allowing the caller to decide whether to rely on a quote based on them. This would take into account mainly observations and liquidity, but if you have suggestions I'd love to hear them!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants