Skip to content

Add max_supply cap enforcement to claim_reward function #178

Description

@DeFiVC

What

The claim_reward function in learn-token mints tokens by directly writing to balance and supply storage, bypassing the max_supply check that mint() enforces.

Why

If max_supply is set to a value lower than the total rewards that would be minted over time, the claim_reward path will exceed the cap. This undermines the supply cap guarantee — the primary token distribution path doesn't respect it.

Scope

  • Add the same max_supply check from mint() to claim_reward
  • Ensure the check uses the same logic and error message
  • Add a test verifying the cap is enforced

Technical Context

  • File: contracts/learn-token/src/lib.rs (lines ~418-423 for claim_reward, ~359-363 for mint)
  • claim_reward writes directly to storage: storage::write_balance and storage::write_supply
  • mint checks: if current_supply + amount > max_supply { panic!("maximum supply cap exceeded"); }

Acceptance Criteria

  • claim_reward panics when minting would exceed max_supply
  • The check is identical to the one in mint()
  • Unit test verifies the cap is enforced in the reward path

Metadata

Metadata

Assignees

No one assigned

    Labels

    mediumFunctionality impaired but workaround exists, edge case, partial feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions