Repository navigation
Fungible: explicit total_supply in capped - #662
Conversation
WalkthroughThe Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/tokens/src/fungible/extensions/capped/storage.rs (1)
64-73: Clarify the trust boundary fortotal_supplyin docs.Please explicitly state that
total_supplymust come from the same authoritative source used by mint state transitions (and be read immediately before mint), otherwise cap enforcement can be bypassed by stale input.✍️ Suggested doc adjustment
-/// * `total_supply` - The current total supply of tokens. +/// * `total_supply` - The current total supply of tokens from the authoritative +/// supply source used by mint logic (e.g., `Base::total_supply`). +/// Passing stale or derived values can invalidate cap enforcement.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/tokens/src/fungible/extensions/capped/storage.rs` around lines 64 - 73, The documentation for check_cap does not specify the trust boundary for the total_supply parameter; update the doc comment for pub fn check_cap(e: &Env, amount: i128, total_supply: i128) to state that total_supply must be read from the same authoritative mint state (the live storage used for mint transitions) immediately before calling check_cap (i.e., do not pass stale or external totals), and note that failing to do so can allow cap enforcement to be bypassed; also reference query_cap and any mint-state accessor (e.g., the contract's total_supply getter) so callers know the correct source to read from.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/tokens/src/fungible/extensions/capped/test.rs`:
- Around line 22-23: Add a targeted regression test in
packages/tokens/src/fungible/extensions/capped/test.rs that replicates the
stale/local-supply desynchronization bypass from issue `#626`: simulate a scenario
where total supply observed by the cap check (use check_cap and
Base::total_supply) is stale relative to a concurrent/local mint path and then
invoke the mint flow (Base::mint) to assert the cap cannot be exceeded;
specifically create steps that (1) set supply near the cap, (2) read/record a
stale supply value, (3) perform the alternate mint path that previously bypassed
the cap, and (4) assert via check_cap and a final Base::total_supply that total
supply ≤ cap. Reference and reuse existing helpers check_cap, Base::mint, and
Base::total_supply so the test proves the chosen mint flow blocks the bypass and
add equivalent cases for the other reported line ranges.
---
Nitpick comments:
In `@packages/tokens/src/fungible/extensions/capped/storage.rs`:
- Around line 64-73: The documentation for check_cap does not specify the trust
boundary for the total_supply parameter; update the doc comment for pub fn
check_cap(e: &Env, amount: i128, total_supply: i128) to state that total_supply
must be read from the same authoritative mint state (the live storage used for
mint transitions) immediately before calling check_cap (i.e., do not pass stale
or external totals), and note that failing to do so can allow cap enforcement to
be bypassed; also reference query_cap and any mint-state accessor (e.g., the
contract's total_supply getter) so callers know the correct source to read from.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4485a92b-7183-4f3e-a98c-97091fe35e7b
📒 Files selected for processing (4)
examples/fungible-capped/src/contract.rspackages/tokens/src/fungible/extensions/capped/mod.rspackages/tokens/src/fungible/extensions/capped/storage.rspackages/tokens/src/fungible/extensions/capped/test.rs
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #662 +/- ##
==========================================
- Coverage 96.16% 96.16% -0.01%
==========================================
Files 59 59
Lines 6134 6132 -2
==========================================
- Hits 5899 5897 -2
Misses 235 235 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fixes #626
PR Checklist
Summary by CodeRabbit
Breaking Changes
Documentation