Skip to content

Commit 59fb2e7

Browse files
authored
Fixes dust balance handling for pallet revive (#9357)
fix issue: paritytech/contract-issues#141 Corrects the condition for minting a new currency unit when transferring dust. The condition was incorrectly checking `to_info.dust.saturating_add(dust) >= plank` which could lead to unexpected minting behavior. It now correctly checks if `to_info.dust >= plank` before minting.
1 parent bcee8dc commit 59fb2e7

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

prdoc/pr_9357.prdoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
title: "Fix dust balance handling in ETH transfers"
2+
3+
doc:
4+
- audience: Runtime Dev
5+
description: |-
6+
Fixed a bug in the eth-decimals implementation where ETH transfers were failing due to incorrect receiver dust balance handling. The condition for minting a new currency unit when transferring dust was checking `to_info.dust.saturating_add(dust) >= plank` which `to_info.dust` has been added twice, could lead to unexpected minting behavior.
7+
This fix ensures that ETH transfers work correctly, enabling proper operation of DeFi protocols like Uniswap on PolkaVM.
8+
9+
crates:
10+
- name: pallet-revive
11+
bump: patch

substrate/frame/revive/src/exec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ where
14431443
transfer_balance::<T>(from, to, value)?;
14441444
transfer_dust::<T>(&mut from_info, &mut to_info, dust)?;
14451445

1446-
if to_info.dust.saturating_add(dust) >= plank {
1446+
if to_info.dust >= plank {
14471447
T::Currency::mint_into(to, 1u32.into())?;
14481448
to_info.dust =
14491449
to_info.dust.checked_sub(plank).ok_or_else(|| Error::<T>::TransferFailed)?;

substrate/frame/revive/src/tests.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,15 @@ fn transfer_with_dust_works() {
518518
expected_to_balance: BalanceWithDust::new_unchecked::<Test>(2, 0),
519519
total_issuance_diff: -1,
520520
},
521+
TestCase {
522+
description: "receiver dust less than 1 plank",
523+
from_balance: BalanceWithDust::new_unchecked::<Test>(100, plank / 10),
524+
to_balance: BalanceWithDust::new_unchecked::<Test>(0, plank / 2),
525+
amount: BalanceWithDust::new_unchecked::<Test>(1, plank / 10 * 3),
526+
expected_from_balance: BalanceWithDust::new_unchecked::<Test>(98, plank / 10 * 8),
527+
expected_to_balance: BalanceWithDust::new_unchecked::<Test>(1, plank / 10 * 8),
528+
total_issuance_diff: 1,
529+
},
521530
];
522531

523532
for TestCase {

0 commit comments

Comments
 (0)