AragonBlack / fundraising

Fundraising apps suite for Aragon organizations
https://fundraising.aragon.black/
GNU Affero General Public License v3.0
75 stars 43 forks source link

MarketMaker: parameter interpolation for collateral token updates #149

Closed izqui closed 4 years ago

izqui commented 5 years ago

Using updateCollateralToken will lead to major frontrunning opportunities (or not even, as if there's a vote involved it could be atomically attacked), which will result in the reserve bleeding value:

  1. A vote is created to perform updateCollateralToken
  2. Ahead of the vote executing, a frontrunner analyzes how to take advantage of the update
  3. Depending on the direction of the change, the attacker performs either a massive buy or sell
  4. Vote is executed updating the collateral token params
  5. Attacker buys back or sells the tokens to the curve

I am not super familiar with how the collateral updates impact the currently ongoing batch, but in case that the update happens immediately, the attack could be performed atomically (with a contract that performs steps 3-5 in one tx) with 0 risk for the attacker.

My proposal for tackling this problem would be to perform the parameter update progressively across a certain number of batches (could be a param to updateCollateralToken or a global variable), interpolating the change delta linearly across those batches.

This wouldn't completely solve the problem, as if there is no more trading during that period, the attacker would be able to make the same profit as they can right now (but it shouldn't be any more profit). But if there's other trading, the value lost would also be captured by legitimate users. I was chatting with @vbuterin about this during the weekend in Taipei, and we couldn't come up with a better solution than this.

I don't see this as a requirement for the initial release, but it is an important upgrade that should be made before the bonding curves for ANJ and ARA are launched since it is going to be very hard to come up with the optimal reserve ratio and it will likely need to be changed.

lkngtn commented 4 years ago

I'm a fan of the idea of smoothing these events in order to turn them from a single discrete change into something more continuous. However, the mechanics of the current batch filling process seem like they have a pretty significant impact on this process.

osarrouy commented 4 years ago

Moved to #179.