Skip to content

transfer(from, to, amount) in eco-token permits self-transfer; transfer_from rejects it — inconsistent security model #84

Closed

Description

@cybermax4200

Why this matters now:
transfer_from explicitly panics with "token: cannot transfer to self" (added in #67). transfer has no such guard. A self-transfer with transfer is a no-op (balance is correctly maintained due to the two-write pattern reading the already-updated value), but the inconsistency is a security model defect: the justification for rejecting self-transfer in transfer_from (allowance drain without token movement) applies equally to transfer (auth signature without value movement). An auditor reviewing the SEP-0041 implementation will flag this inconsistency. It should be fixed before the formal audit.

Problem / What:
In token.rs, transfer does not check if from == to { panic!(...) }. The function correctly handles the double-write (the test test_transfer_to_self passes and the balance is preserved), but a self-transfer burns the caller's require_auth() credential with no economic effect. The fix is a one-line guard matching transfer_from.

Key Challenges:

  • The existing test test_transfer_to_self asserts that self-transfer succeeds and leaves the balance unchanged — this test must be updated to assert that it panics after the fix.
  • Ensure the error message matches the transfer_from message for consistency: "token: cannot transfer to self".

Acceptance Criteria:

  • transfer(from, to, amount) panics with "token: cannot transfer to self" when from == to.
  • test_transfer_to_self is rewritten as #[should_panic(expected = "token: cannot transfer to self")].
  • A new positive test confirms valid transfers (from != to) still work.
  • cargo test -p eco-token passes.

Relevant files/functions:

  • contracts/eco-token/src/token.rs — TokenContract::transfer
  • contracts/eco-token/src/token.rs — test_transfer_to_self (test update)

Out of scope: TTL, allowance logic, transfer_from (already fixed).

Activity

  1. Cmitchelle7 commented on Aug 26, 2026

    @Cmitchelle7
    Contributor

    Hi Maintainer, reviewed the issue in detail. Full stack background with solid experience relevant to this task. No blockers on my end — I'm ready to submit a PR shortly. Please assign.

  2. grantfox-oss commented on Aug 26, 2026

    @grantfox-oss

    🦊 GrantFox — @Cmitchelle7 has been assigned to this issue as part of the Third Campaign campaign!

    Next steps:

    1. Open a Pull Request referencing this issue (e.g., Closes #84)
    2. Your PR will be reviewed by the ecotask-network maintainers

    Good luck! Track your progress on GrantFox.

  3. grantfox-oss commented on Sep 2, 2026

    @grantfox-oss

    🎉 This issue has been marked as completed on GrantFox!

    @Cmitchelle7's PR #89 was approved and merged by @cybermax4200.

    🏆 @Cmitchelle7: You earned 40 FoxPoints for this contribution! Your current tier: Builder (1,262 total points). Track your full progress on GrantFox.

    👏 Great work, @Cmitchelle7! Keep contributing to ecotask-network.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions