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

Need to use fresh value of StakingRewardPool #10

Closed
k06a opened this Issue Oct 11, 2018 · 5 comments

Comments

Projects
None yet
2 participants
@k06a
Copy link

k06a commented Oct 11, 2018

This line:

return StakingRewardPool.mul(_StakerWeight).div(TotalStakingWeight); //StakingRewardPool * _StakerWeight/TotalStakingWeight

Should use:

address(this).balance.sub(TotalStakingAmount);

Instead of:

StakingRewardPool

Because balance could be refilled by Treasure.

Auditing smart contracts in live stream: https://www.youtube.com/watch?v=efZY3_COaiE

Your CryptoManiacs :)

@Dexaran

This comment has been minimized.

Copy link
Member

Dexaran commented Oct 12, 2018

If I understand it correctly, then the issue you are talking about is that if someone deposited CLO into the contract with DEBUG_donation() function then the output of stake_reward() constant returns function will be incorrect because the StakingRewardPool is only updated within the new_block() function (here).

The issue is confirmed, however I think that it is better to insert the new_block() function into the DEBUG_donation() at L163

EDIT: but it is not yet possible because the donated msg.value will be subtracted from StakingRewardPool

StakingRewardPool = address(this).balance.sub(TotalStakingAmount + msg.value); //fix rewards pool for this block.

It may be really worth to use the address(this).balance.sub(TotalStakingAmount); as you suggest.

@Dexaran Dexaran added the confirmed label Oct 12, 2018

@Dexaran

This comment has been minimized.

Copy link
Member

Dexaran commented Oct 12, 2018

I can classify this as a minor observation, non-security issue (10,000 CLO)

yuriy77k added a commit to yuriy77k/Cold-staking that referenced this issue Oct 12, 2018

minor fixing
Removed:
- [Duplicate method staker_info](EthereumCommonwealth#11);
- [Duplicate condition](EthereumCommonwealth#8).

Updated function [stake_reward](EthereumCommonwealth#10).
@k06a

This comment has been minimized.

Copy link

k06a commented Oct 12, 2018

@Dexaran you can call this.new_block() to avoid msg.value substraction, but I prefer to use previous suggestion :)

@k06a

This comment has been minimized.

Copy link

k06a commented Oct 28, 2018

@Dexaran thanks!

@k06a k06a closed this Oct 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment