Weekly update on development process (Mar 6, 2023)

Fairpool
3 min readMar 6, 2023

Fairpool is a DEX for personal tokens. Create your own token & receive royalties from trading volume. Increase volume by offering dividends / selling content for your token. Subscribe to our Telegram / Twitter to get notified about updates.

Weekly progress

  • ⚒ Added a direct referral system.
  • ⚒ Discovered a loophole in the earnings distribution algorithm & designed solutions for it.

The earnings distribution algorithm

Fairpool distributes earnings to token holders. The earnings come from the trading fees, which are charged on every sell transaction. However, distributing the earnings fairly is quite a challenge. A naive algorithm would work like this: iterate over holders, give everyone their share. However, this quickly becomes impractical due to gas costs (increasing with every iteration, becoming higher than the block gas limit at 1000 holders).

So we have implemented an optimized version:

  • Randomly select an index in the holders array.
  • Iterate 256 times max: on every iteration, distribute the share to the current holder by index, then increment the index.

Holder share is calculated as “holder balance / local total balance”. Local total balance is calculated as “sum of all 256 holder balances”.

However, this algorithm has a loophole: the exploiter could simply buy multiple small amounts from different addresses, thus inflating the length of the holders array. This way, the exploiter would have a higher probability of receiving a non-zero share, along with a higher probability of receiving a bigger share.

Potential solutions:

  1. Introduce a “minimum balance” variable, filter out the balances that are lower than the minimum balance.
  2. Introduce a “step” variable, set the step to a random value once before the cycle, increment the index by step (instead of by 1). This would ensure that the exploiter would receive a very low amount if at least one “normal” address is included in the distribution.
  3. Think about a new algorithm that distributes the earnings to every holder but does it without the loop (a prototype solution was proposed by Batog et al. in Scalable Reward Distribution on the Ethereum Blockchain — however, this solution increments the “sum” variable indefinitely, which would result in overflow and brick the contract).

We’ve currently settled on a combination of 1 and 2. Hope it’ll be enough to deter the exploiters by raising the amount of capital needed for a successful exploit — to the point where the “exploiter” becomes just another holder.

Next week’s focus

  1. ⚒ Develop Fairpool.

About Fairpool

Fairpool is a DEX for personal tokens. Create your own token & receive royalties from trading volume. Increase volume by offering dividends / selling content for your token. If you want to get notified about updates to our products, please follow our Telegram & Twitter.

Any questions? Reach out to us:

Website: fairpool.io

Telegram: @FairpoolDEX

Twitter: @FairpoolDEX

Anchor Podcasts: @FairpoolDEX

Medium: fairpool-dex.medium.com

$FAIR token: Uniswap + PancakeSwap

--

--

Fairpool

Fairpool is a DEX for personal tokens. Create your token & receive royalties from trading volume. Increase volume by offering dividends / selling content.