Skip to content

fix: reject self-transfer in resource_credits::transfer_credits - #395

Merged
Qoder-Voidd merged 2 commits into
Akazajan:mainfrom
Olayinka93:fix/issue-253-resource-credits-transfer-credits-does-not
Aug 29, 2026
Merged

fix: reject self-transfer in resource_credits::transfer_credits#395
Qoder-Voidd merged 2 commits into
Akazajan:mainfrom
Olayinka93:fix/issue-253-resource-credits-transfer-credits-does-not

Conversation

@Olayinka93

Copy link
Copy Markdown
Contributor

Overview

This PR adds a protocol-safety guard to resource_credits::transfer_credits so that calls where from == to are rejected. Previously, a self-transfer left balances unchanged but emitted a misleading event and wasted ledger gas. The change rejects self-transfers before any balance mutation or event emission, while preserving authorization, storage/ABI compatibility, and ledger-time behavior.

Related Issue

Changes

🔒 Self-Transfer Guard

  • [MODIFY] contracts/resource_credits/src/lib.rs

    • Add a from != to guard immediately after from.require_auth() in transfer_credits.
    • Return Error::SelfTransferNotAllowed when from == to, before any balance reads/writes or event emission.
    • Keep the existing function signature, storage schema, and ABI unchanged.
  • [MODIFY] contracts/resource_credits/src/test.rs

    • Add regression test test_transfer_credits_rejects_self_transfer covering the invalid self-transfer path.
    • Extend the success path to verify from != to still transfers normally, updates balances, and emits the expected event.

Verification Results

cargo test -p resource_credits
✅ all tests passed

Live acceptance check:
✅ self-transfer (from == to) rejected
✅ no misleading TransferCredit event emitted
✅ balances unchanged on rejected path
✅ successful transfer between distinct accounts works
✅ authorization/storage/ABI compatibility preserved
Acceptance Criteria Status
transfer_credits rejects from == to ✅ Guard added before any balance/event side effects
Successful transfer path remains valid from != to transfers still update balances and emit TransferCredit
No misleading event is emitted ✅ Rejected self-transfer returns error without emitting an event
Authorization is preserved from.require_auth() remains the first authorization check
Storage/ABI compatibility maintained ✅ No signature or storage layout changes

Closes #253

@Qoder-Voidd Qoder-Voidd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Qoder-Voidd
Qoder-Voidd merged commit d1cbc5f into Akazajan:main Aug 29, 2026
0 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'resource_credits::transfer_credits` does not prevent self-transfer

2 participants