From 0ce506ef1bde225a55b056070e5e5f357a829c91 Mon Sep 17 00:00:00 2001
From: Emanuele Valzano <100088167+0xMenna01@users.noreply.github.com>
Date: Fri, 22 Dec 2023 13:08:08 +0100
Subject: [PATCH] incrementing sufficient accounts references with
 saturating_add for safety. (#2768)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Even though it is difficult to overflow the sufficients variable, since
an attacker that is willing to rapidly increase the number must every
time deposit a minimum deposit of a given asset, it is safer to use
saturating_add().

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
---
 substrate/frame/assets/src/functions.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/substrate/frame/assets/src/functions.rs b/substrate/frame/assets/src/functions.rs
index c2c1b683906..8791aaa736b 100644
--- a/substrate/frame/assets/src/functions.rs
+++ b/substrate/frame/assets/src/functions.rs
@@ -77,7 +77,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
 			}
 		} else if d.is_sufficient {
 			frame_system::Pallet::<T>::inc_sufficients(who);
-			d.sufficients += 1;
+			d.sufficients.saturating_inc();
 			ExistenceReason::Sufficient
 		} else {
 			frame_system::Pallet::<T>::inc_consumers(who)
-- 
GitLab