Skip to content

Commit f1d1d9c

Browse files
frame-system: Don't underflow the sufficients (#8062)
Closes: #8044 --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 342f46a commit f1d1d9c

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

prdoc/pr_8062.prdoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
title: 'frame-system: Don''t underflow the sufficients'
2+
doc:
3+
- audience: Node Dev
4+
description: |
5+
Fixes a potential underflow for `dec_sufficients`.
6+
crates:
7+
- name: frame-system
8+
bump: patch

substrate/frame/system/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ impl<T: Config> Pallet<T> {
16931693
DecRefStatus::Reaped
16941694
},
16951695
(x, _) => {
1696-
account.sufficients = x - 1;
1696+
account.sufficients = x.saturating_sub(1);
16971697
*maybe_account = Some(account);
16981698
DecRefStatus::Exists
16991699
},

substrate/frame/system/src/tests.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ fn provider_ref_handover_to_self_sufficient_ref_works() {
155155
});
156156
}
157157

158+
#[test]
159+
fn dec_sufficients_does_not_undeflow() {
160+
new_test_ext().execute_with(|| {
161+
assert_eq!(System::inc_providers(&0), IncRefStatus::Created);
162+
assert_eq!(System::dec_sufficients(&0), DecRefStatus::Exists);
163+
});
164+
}
165+
158166
#[test]
159167
fn self_sufficient_ref_handover_to_provider_ref_works() {
160168
new_test_ext().execute_with(|| {

0 commit comments

Comments
 (0)