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

fix:(staking-pool) edge case #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

luciotato
Copy link

fixes #99

@@ -514,10 +518,11 @@ mod tests {
owner: String,
stake_public_key: String,
reward_fee_fraction: RewardFeeFraction,
initial_balance: Balance,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a 4th parameter for testing, initial balance

@@ -183,6 +183,10 @@ impl StakingContract {
"The owner account ID is invalid"
);
let account_balance = env::account_balance();
assert!(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid total_staked_balance=0

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realistically, this is impossible, because the storage required for the contract itself covers this.

Copy link
Author

@luciotato luciotato Sep 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. The contract will stop working way before that.

@luciotato luciotato changed the title fix: edge case fix:(staking-pool) edge case Sep 7, 2020
@@ -183,6 +183,10 @@ impl StakingContract {
"The owner account ID is invalid"
);
let account_balance = env::account_balance();
assert!(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realistically, this is impossible, because the storage required for the contract itself covers this.

@@ -183,6 +183,10 @@ impl StakingContract {
"The owner account ID is invalid"
);
let account_balance = env::account_balance();
assert!(
account_balance > STAKE_SHARE_PRICE_GUARANTEE_FUND,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this is strictly higher?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because if account_balance == STAKE_SHARE_PRICE_GUARANTEE_FUND then in the next line total_staked_balance becomes zero. total_staked_balance is used in several share calculations as denominator, so total_staked_balance==0 leads to div by zero panics. (i.e. fn num_shares_from_staked_amount_rounded_down/up)

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

Successfully merging this pull request may close these issues.

bug: (staking-pool) edge case bug - contract account with low balance
2 participants