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

stake-pool: Specify the space used for new stake accounts (OS-SSP-SUG-00) #4000

Merged
merged 1 commit into from
Feb 1, 2023

Conversation

joncinque
Copy link
Contributor

Description

Ensure rent-exempt calculations are performed on actual data size instead of theoretical data size. E.g.
in AddValidatorToPool, rent exempt calculation on the reserve_pool is performed on the default
account size:

let space = std::mem::size_of::<stake::state::StakeState>();
let stake_minimum_delegation = stake::tools::get_minimum_delegation()?;
let required_lamports = minimum_delegation(stake_minimum_delegation)
.saturating_add(rent.minimum_balance(space));

If it was possible to create a Stake account larger than the default (200 bytes), this computation would
be inaccurate and the stake account may be able to be closed here.
Note: the stake program validates the account size during initialization and during split the remaining
lamports must be either greater than the minimum requirement or zero.

Remediation

Calculate minimum rent based on the actual size of the account to be created.

In all other places, we're using the rent_exempt_reserve reported on the stake account's Meta, so we're safe there.

@joncinque joncinque merged commit e71ea00 into solana-labs:master Feb 1, 2023
@joncinque joncinque deleted the sp-space branch February 1, 2023 17:10
HaoranYi pushed a commit to HaoranYi/solana-program-library that referenced this pull request Jul 19, 2023
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.

None yet

1 participant