CORIONplatform / solidity

GNU General Public License v3.0
12 stars 9 forks source link

ICO contract setInterestDB minor issue? #85

Closed gundas closed 7 years ago

gundas commented 7 years ago

If I am not mistaken, the following scenario could happen with the setInterestDB method in ICO contract:

  1. All the money are transferred out of an account X, thus the InterestDB amount is set to 0 and empty is set to true
  2. A few blocks later (or on the same block if transfer to contract refund happens) the same account X receives some new funds.

Result - if the _num (calculated as (block.number - startBlock) / interestBlockDelay ) happens to be the same in both setInterestDB calls above, the entry of the InterestDB for that account and for that _num will have amount bigger than 0 and empty = true. This will result in incorrect interest calculation.

The fix should be to also set empty to false explicitly, o re-think the use of empty.

        if ( balance == 0 ) { 
            interestDB[addr][_num].empty = true;
        } **else {
            interestDB[addr][_num].empty = false;
        }**
iFA88 commented 7 years ago

If the user transfer every CORIONS from his/her account then the empty will be true. Later, if he/she got any amount of CORION then would be empty = false. If you check the interest calculation, you can see how thats work: https://github.com/CORIONplatform/solidity/blob/master/ico.sol#L132-L149

gundas commented 7 years ago

Yes, but that will work only if the user gets CORION again after the certain amount of blocks - so a new value of _num is calculated. If there are less blocks in-between the two user actions (spend and receive CORION) than needed for the new _num value, then empty will be left to true.

For example, let's say:

startBlock = 10
interestBlockDelay = 5

1st call to 'setInterestDB(account, 0)', let's say 'block.number=11' uint256 _num = (block.number - startBlock) / interestBlockDelay = (11- 10)/5 = 0 result: interestDB[account][0].amount = 0 interestDB[account][0].empty = true

2nd call to 'setInterestDB(account, 1000)', let's say 'block.number=14' uint256 _num = (block.number - startBlock) / interestBlockDelay = (14- 10)/5 = 0 result: interestDB[account][0].amount = 1000 interestDB[account][0].empty = true <-- interest calculation breaks

iFA88 commented 7 years ago

Yes you have right, we need put an else for false to the setInterestDB!

iFA88 commented 7 years ago

https://github.com/CORIONplatform/solidity/pull/89