Skip to content

Commit 2255492

Browse files
mpetrun5tolak
andauthored
fix: add overflow checks (#96)
Co-authored-by: Wenfeng Wang <[email protected]>
1 parent db11298 commit 2255492

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

bridge/src/lib.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ pub mod pallet {
198198
ExtractDestDataFailed,
199199
/// Failed on the decimal converter
200200
DecimalConversionFail,
201+
/// Deposit nonce has reached max integer qvalue
202+
DepositNonceOverflow,
201203
/// Function unimplemented
202204
Unimplemented,
203205
}
@@ -484,7 +486,10 @@ pub mod pallet {
484486

485487
// Bump deposit nonce
486488
let deposit_nonce = DepositCounts::<T>::get(dest_domain_id);
487-
DepositCounts::<T>::insert(dest_domain_id, deposit_nonce + 1);
489+
DepositCounts::<T>::insert(
490+
dest_domain_id,
491+
deposit_nonce.checked_add(1).ok_or(Error::<T>::DepositNonceOverflow)?,
492+
);
488493

489494
// convert the asset decimal
490495
let decimal_converted_amount =
@@ -742,11 +747,11 @@ pub mod pallet {
742747
}
743748
let amount: u128 = U256::from_big_endian(&data[0..32])
744749
.try_into()
745-
.expect("Amount convert failed. qed.");
750+
.expect("Amount conversion failed.");
746751
let recipient_len: usize = U256::from_big_endian(&data[32..64])
747752
.try_into()
748-
.expect("Length convert failed. qed.");
749-
if data.len() != (64 + recipient_len) {
753+
.expect("Length conversion failed.");
754+
if (data.len() - 64) != recipient_len {
750755
return None
751756
}
752757
let recipient = data[64..data.len()].to_vec();

0 commit comments

Comments
 (0)