Closed gundas closed 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
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
Yes you have right, we need put an else for false to the setInterestDB
!
If I am not mistaken, the following scenario could happen with the setInterestDB method in ICO contract:
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.