Skip to content

fix:(staking-pool) edge case#100

Open
luciotato wants to merge 2 commits intonear:masterfrom
luciotato:edge-cases
Open

fix:(staking-pool) edge case#100
luciotato wants to merge 2 commits intonear:masterfrom
luciotato:edge-cases

Conversation

@luciotato
Copy link

fixes #99

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

"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
"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.

);
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