From 352e3519a8f8928ae45ebe77bab93e3d878edd14 Mon Sep 17 00:00:00 2001 From: Uncle Stinky Date: Fri, 25 Sep 2026 12:23:38 +0300 Subject: [PATCH] apply exponential scale for bridge out amount Signed-off-by: Uncle Stinky --- pallets/exodus/Cargo.toml | 2 +- pallets/exodus/src/lib.rs | 16 +++++++++------- pallets/exodus/src/tests.rs | 17 ++++++++++++++--- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/pallets/exodus/Cargo.toml b/pallets/exodus/Cargo.toml index 11ce536..49a1ad5 100644 --- a/pallets/exodus/Cargo.toml +++ b/pallets/exodus/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ghost-exodus" -version = "0.0.14" +version = "0.0.15" description = "Threshold signature generation with DKG included" license.workspace = true authors.workspace = true diff --git a/pallets/exodus/src/lib.rs b/pallets/exodus/src/lib.rs index 72a0a6f..50a4ebe 100644 --- a/pallets/exodus/src/lib.rs +++ b/pallets/exodus/src/lib.rs @@ -1846,14 +1846,16 @@ pub mod pallet { let base_evm_amount: BalanceOf = T::BaseEvmAmount::get() .unique_saturated_into(); - let pending_requests_count = ExodusRequests::::count() - .unique_saturated_into(); + let is_amount_sufficient = 1u32.checked_shl(ExodusRequests::::count()) + .map(|scale| { + T::Currency::minimum_balance() + .saturating_mul(scale.unique_saturated_into()) + .saturating_add(base_evm_amount) + .le(&amount) + }) + .unwrap_or(false); - let minimum_amount = base_evm_amount - .saturating_mul(pending_requests_count) - .saturating_add(T::Currency::minimum_balance()); - - ensure!(amount >= minimum_amount, Error::::BridgeQueueMinimumNotMet); + ensure!(is_amount_sufficient, Error::::BridgeQueueMinimumNotMet); let actual_amount = T::Currency::burn_from( &who, diff --git a/pallets/exodus/src/tests.rs b/pallets/exodus/src/tests.rs index 62e0bd1..b54870d 100644 --- a/pallets/exodus/src/tests.rs +++ b/pallets/exodus/src/tests.rs @@ -1132,9 +1132,14 @@ fn test_all_validators_can_execute_dkg() { ExodusSignedGovernance::::iter().count() }); + let pending_exodus_requests = ext.execute_with(|| { + ExodusRequests::::count() + }); + assert_eq!(rotations_count, 3); assert_eq!(bridges_count, 2); assert_eq!(governances_count, 15); + assert_eq!(pending_exodus_requests, 0); } #[test] @@ -1476,7 +1481,7 @@ fn register_evm_bridge_out_dynamic_threshold_works() { QualificationDkgState::::insert(&network_curve, dkg_state); - let amount_1 = existential_deposit; + let amount_1 = base_evm_amount.saturating_add(existential_deposit); assert_ok!(Exodus::register_evm_bridge_out_exodus( RuntimeOrigin::signed(user.clone()), network_id, @@ -1508,7 +1513,10 @@ fn register_evm_bridge_out_dynamic_threshold_works() { Error::::BridgeQueueMinimumNotMet ); - let amount_2 = existential_deposit.saturating_add(base_evm_amount); + let amount_2 = existential_deposit + .saturating_mul(2) + .saturating_add(base_evm_amount); + assert_ok!(Exodus::register_evm_bridge_out_exodus( RuntimeOrigin::signed(user.clone()), network_id, @@ -1530,7 +1538,10 @@ fn register_evm_bridge_out_dynamic_threshold_works() { assert_eq!(ExodusRequests::::count(), 2); - let amount_3 = amount_2.saturating_add(base_evm_amount); + let amount_3 = existential_deposit + .saturating_mul(4) + .saturating_add(base_evm_amount); + assert_ok!(Exodus::register_evm_bridge_out_exodus( RuntimeOrigin::signed(user.clone()), network_id,