Skip to content

fix:(staking-pool) edge case#100

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

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

Conversation

@luciotato

Copy link
Copy Markdown

fixes #99

Comment thread staking-pool/src/lib.rs
owner: String,
stake_public_key: String,
reward_fee_fraction: RewardFeeFraction,
initial_balance: Balance,

Copy link
Copy Markdown
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

Comment thread staking-pool/src/lib.rs
"The owner account ID is invalid"
);
let account_balance = env::account_balance();
assert!(

Copy link
Copy Markdown
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
Copy Markdown
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.

@luciotato luciotato Sep 15, 2020

Copy link
Copy Markdown
Author

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
Comment thread staking-pool/src/lib.rs
"The owner account ID is invalid"
);
let account_balance = env::account_balance();
assert!(

Copy link
Copy Markdown
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.

Comment thread staking-pool/src/lib.rs
);
let account_balance = env::account_balance();
assert!(
account_balance > STAKE_SHARE_PRICE_GUARANTEE_FUND,

Copy link
Copy Markdown
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
Copy Markdown
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