fix(validator): Validator Balance Tracker Silent Underflow During Penalty Exceeding Balance - #93
Open
Mona-i wants to merge 2 commits into
Open
Conversation
…lty #241
- Add src/validator/balance_tracker.rs
* apply_penalty() now uses checked_sub instead of saturating_sub
* Returns Err(BalanceError::InsufficientBalance) when penalty > balance
* Records excess as a debt in a separate BTreeMap<ValidatorIndex, u64>
* ejection_eligible() treats any validator with outstanding debt as
immediately ejectable, regardless of stored effective balance
* apply_reward() is capped at MAX_EFFECTIVE_BALANCE (32 ETH in Gwei)
* clear_debt() allows callers to purge the debt record after ejection
- Add src/slashing/penalty_calculator.rs
* compute_slashing_penalty(): 1/32 whistleblower + 1/32 correlation = 1/16 of effective balance
* compute_inactivity_penalty(): epochs_since_finality^2 * balance / INACTIVITY_PENALTY_QUOTIENT
* cap_effective_balance(): enforces MAX_EFFECTIVE_BALANCE invariant
* u128 intermediate arithmetic prevents overflow in inactivity formula
- Add tests/validator/balance_underflow_test.rs
* Acceptance criterion: 1 ETH validator + 1.5 ETH penalty => ejected same epoch
* Normal penalty path regression: penalty <= balance reduces balance correctly
* Ejection threshold boundary test
* Reward cap tests (saturates at MAX_EFFECTIVE_BALANCE)
* Debt lifecycle test (clear_debt after ejection)
* Penalty calculator unit tests
* Property test: effective_balance never exceeds MAX_EFFECTIVE_BALANCE after rewards
* Property test: penalty > balance always returns InsufficientBalance + records debt
- Update src/validator/mod.rs: expose balance_tracker module
- Update src/slashing/mod.rs: expose penalty_calculator module
- Update Cargo.toml: register balance_underflow_test integration test
Resolve Cargo.toml conflict by keeping both integration test entries: - proof_of_connectivity_epoch_nonce_test (from main, PR VeriNode-Labs#94) - balance_underflow_test (from this branch, issue #241)
Contributor
|
resolve conflicts @Mona-i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #24
Replaces saturating_sub with checked_sub in apply_penalty(). Returns InsufficientBalance error when penalty exceeds balance. Records debt and forces immediate ejection. Adds penalty_calculator.rs and full test suite including property tests.