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

Insufficient internal ReservePool causing Hatchers to loose all tokens #16

Open
EnchanterIO opened this issue Nov 15, 2019 · 3 comments

Comments

@EnchanterIO
Copy link

EnchanterIO commented Nov 15, 2019

Description

Currently, there is no way for a hatcher to claim ALL of his tokens due to a bug in reserve pool business logic.

The reserve pool is minted at the end of hatching period as:

uint256 amountReserveInternal = (initialRaise / p0) * (DENOMINATOR_PPM - theta) / DENOMINATOR_PPM;

_mint(address(this), amountReserveInternal);
  • notice the FundingPool THETA substraction

BUT

Each hatcher is assigned tokens based on full allocation (including the theta) as:

initialContributions[msg.sender].lockedInternal += contributed * p0;

Claiming tokens fail because there is insufficient reserve and no tokens what so ever can be claimed causing the hatcher to fully LOST his original hatch contribution.

claim() {
     _transfer(address(this), msg.sender, toUnlock);

With the following contract ~state (for better problem visualization):

6500000000000000000000)   // total supply
6500000000000000000000)   // CommonsStack balance
10000000000000000000000) // Hatcher unlocked tokens
  • whooops, 35% FundingPool theta missing causing all hatchers to loose tokens

Steps to reproduce

  1. Hatch the CommonsToken
  2. Generate so much in funding pool fees by buying and selling that all hatchers tokens are unlocked
  3. Try to claim tokens

I created the following test reproducing the problem: https://github.com/lightstreams-network/genesis-contracts/blob/master/test/06_insufficient_reserve.js

Proposed solution

Calculate the reserve in the following way:

// Mint INTERNAL tokens to the reserve:
_mint(address(this), initialRaise * p0);
EnchanterIO added a commit to lightstreams-network/genesis-contracts that referenced this issue Nov 18, 2019
@EnchanterIO
Copy link
Author

EnchanterIO commented Nov 18, 2019

Here is the fix: lightstreams-network@c0ff3d9#diff-a47469acf810b124d04e7d1a3ea5b4feR292

PS: The commit contains also some additional little fixes for a custom behaviour, ignore rest of the changes aside of the highlighted line.

@Eknir
Copy link
Contributor

Eknir commented Jan 20, 2020

Thanks for catching this one!

@Eknir
Copy link
Contributor

Eknir commented Jan 20, 2020

cf1f8cc
Fix

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