Skip to content

[CT-06] Implement Resource Credit Deduction Validator with balance guard in Rust #1023

@devwums

Description

@devwums

Problem

The resource_credits contract can deduct credits without validating the balance, potentially allowing negative credit balances that corrupt member state.

Proposed Solution

Create contracts/cntr/credit_deduction.rs implementing pub fn validate_deduction(current_balance: i128, deduction_amount: i128) -> Result<i128, &'static str>. Returns Ok(new_balance) only when deduction_amount > 0 and current_balance >= deduction_amount. All implementation must live inside contracts/cntr/.

Acceptance Criteria

  • File at contracts/cntr/credit_deduction.rs
  • Returns Err("Deduction amount must be positive") when deduction_amount <= 0
  • Returns Err("Insufficient credits") when balance would go negative
  • Returns Ok(current_balance - deduction_amount) on success
  • At least 6 unit tests covering: success, exact balance, insufficient, zero deduction, negative deduction
  • Compiles with cargo test

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions