Repository: ergoplatform/sigma-rust (language: rust)

Issue:
Bug: Storage fee calculation uses output candidate instead of input box for storage fee calculation
Storage fee calculation uses output candidate instead of input box for storage fee calculation:
https://github.com/ergoplatform/sigma-rust/blob/1801136a167c7f83b63a68ce315793daccca6191/ergo-lib/src/chain/transaction/storage_rent.rs#L38-L39

According to:
https://github.com/ergoplatform/ergo/blob/1a417f44459e78acdb4edf6cc00f6d594494faf0/ergo-wallet/src/main/scala/org/ergoplatform/wallet/interpreter/ErgoInterpreter.scala#L34-L45

input box should be used to calculate if storage fee exceeds the box value


Discussion / hints:

Fix patch:
diff --git a/ergo-lib/src/chain/transaction/storage_rent.rs b/ergo-lib/src/chain/transaction/storage_rent.rs
index 9dae96c7f..38e4b18d2 100644
--- a/ergo-lib/src/chain/transaction/storage_rent.rs
+++ b/ergo-lib/src/chain/transaction/storage_rent.rs
@@ -35,7 +35,7 @@ pub(crate) fn try_spend_storage_rent(
             .ok()?;
         let output_candidate = context.outputs.get(output_idx as usize)?;
 
-        let storage_fee = output_candidate.sigma_serialize_bytes().ok()?.len() as u64
+        let storage_fee = input_box.sigma_serialize_bytes().ok()?.len() as u64
             * state_context.parameters.storage_fee_factor() as u64;
         // If the box's value is less than the required storage fee, the box can be spent without any further restrictions
         if context.self_box.value.as_u64() <= &storage_fee {


Test patch: