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 withdraw underflow #20104

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

fix withdraw underflow #20104

wants to merge 4 commits into from

Conversation

longbowlu
Copy link
Contributor

Description

Describe the changes or additions included in this PR.

Test plan

How did you test the new or updated feature?


Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • Indexer:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:
  • REST API:

Copy link

vercel bot commented Oct 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 8, 2024 6:54pm
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Nov 8, 2024 6:54pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Nov 8, 2024 6:54pm
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview Nov 8, 2024 6:54pm

@@ -371,8 +375,15 @@ module sui_system::staking_pool {
/// Called at epoch boundaries to process pending stake withdraws requested during the epoch.
/// Also called immediately upon withdrawal if the pool is inactive.
fun process_pending_stake_withdraw(pool: &mut StakingPool) {
pool.sui_balance = pool.sui_balance - pool.pending_total_sui_withdraw;
pool.pool_token_balance = pool.pool_token_balance - pool.pending_pool_token_withdraw;
pool.sui_balance =
Copy link
Contributor

Choose a reason for hiding this comment

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

How can you end up in a scenario where the pending_total_sui_withdraw is actually more than the balance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

check test_process_pending_stake_withdraw_no_underflow_in_safe_mode and line 661-666

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, my more precise question is why is this even possible (and why do we accept it as being possible instead of figuring out how to prevent it in the first place?). Accepting it is fine by me, I mainly try to understand why we do.

@@ -698,6 +698,13 @@ module sui_system::sui_system {
self.set_epoch_for_testing(epoch_num)
}

// NEVER remove `#[test_only]`
#[test_only]
public(package) fun increment_epoch_for_testing(wrapper: &mut SuiSystemState) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can reuse the function above set_epoch_for_testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i used this and decided with @emmazzz that this may be helpful when writing advancing-epoch tests. But you are right we could make the test work without this. I can remove it if you prefer

#[test_only]
public(package) fun set_epoch_for_testing(self: &mut SuiSystemStateInnerV2, epoch_num: u64) {
self.epoch = epoch_num
}

// NEVER remove `#[test_only]`
#[test_only]
public(package) fun increment_epoch_for_testing(self: &mut SuiSystemStateInnerV2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto, are you sure you need increment if you have set_...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see above

Copy link
Contributor

github-actions bot commented Jan 8, 2025

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants