Skip to content

fix(rewards): skip ReleasedAmount denom check when amount is zero - #355

Open
amathxbt wants to merge 1 commit into
KiiChain:mainfrom
amathxbt:fix/validate-schedule-zero-coin-denom
Open

fix(rewards): skip ReleasedAmount denom check when amount is zero#355
amathxbt wants to merge 1 commit into
KiiChain:mainfrom
amathxbt:fix/validate-schedule-zero-coin-denom

Conversation

@amathxbt

@amathxbt amathxbt commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Bug: validateSchedule ran the denom-consistency check on ReleasedAmount before the IsZero guard. A fresh ReleaseSchedule built from InitialReleaseSchedule() uses sdk.Coin{} (empty denom) for ReleasedAmount. This caused a misleading "denom mismatch" error when submitting a new-schedule governance proposal, blocking legitimate governance actions.

Fix: Move denom and amount validation inside the !IsZero block.

Files changed

  • x/rewards/keeper/validation.go

validateSchedule ran the denom-consistency check on ReleasedAmount
unconditionally, before the IsZero guard. This rejected schedules whose
ReleasedAmount was sdk.Coin{} (empty denom) with a misleading error.

Fix: move denom validation inside the !IsZero block.
@amathxbt
amathxbt requested a review from jhelison as a code owner July 6, 2026 12:10
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The change modifies schedule validation logic in the rewards keeper to allow a fresh release schedule with a zero-value ReleasedAmount. Previously, denom-consistency checks were applied unconditionally, which could reject zero-value coins with an empty denom. Now these checks are skipped when ReleasedAmount.IsZero() is true. All other validation logic, including total amount, module params denom, end time, and active/inactive consistency checks, remains unchanged.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

Not applicable — the change is a conditional logic tweak within a single validation function rather than a multi-component interaction flow.

Related Issues: Not specified in the provided information.

Related PRs: Not specified in the provided information.

Suggested labels: bug, rewards-module

Suggested reviewers: Not specified in the provided information.

Poem

A rabbit hopped through code so neat,
Found a zero that once meant defeat,
"No denom yet? That's quite alright,"
It skipped the check, made schedules light,
Now fresh releases hop with ease complete. 🐰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the core fix to skip the ReleasedAmount denom check when the amount is zero.
Description check ✅ Passed The description accurately explains the bug, the fix, and the affected file, matching the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@x/rewards/keeper/validation.go`:
- Around line 76-91: The released-amount validation in validateSchedule
currently skips denom checks whenever ReleasedAmount.IsZero(), which lets
zero-amount coins with a non-empty, mismatched denom slip through. Update the
logic in validateSchedule so zero-amount released coins still validate the denom
unless it is the canonical empty coin, and keep the amount/limit checks guarded
appropriately. Use ReleasedAmount, TotalAmount, and validateAmount as the key
symbols when adjusting the condition, and align msg_server_test.go expectations
if the rule changes.
🪄 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: ef0f16d3-7a4b-4c63-b8a2-0879cfdff5ef

📥 Commits

Reviewing files that changed from the base of the PR and between e0d3113 and 093a03e.

📒 Files selected for processing (1)
  • x/rewards/keeper/validation.go

Comment on lines +76 to +91
\t// Validate ReleasedAmount only when non-zero. The denom check was previously
\t// run unconditionally, which rejected zero-value coins (sdk.Coin{} with empty
\t// denom) used to represent a fresh schedule with no released tokens yet.
\tif !schedule.ReleasedAmount.IsZero() {
\t if schedule.ReleasedAmount.Denom != schedule.TotalAmount.Denom {
\t return fmt.Errorf("released amount denom %s doesn't match total amount denom %s",
\t schedule.ReleasedAmount.Denom, schedule.TotalAmount.Denom)
\t }
\t if err := validateAmount(schedule.ReleasedAmount); err != nil {
\t return fmt.Errorf("invalid released amount: %w", err)
\t }
\t if schedule.ReleasedAmount.Amount.GT(schedule.TotalAmount.Amount) {
\t return fmt.Errorf("released amount %s cannot exceed total amount %s",
\t schedule.ReleasedAmount, schedule.TotalAmount)
\t }
\t}

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n "denom mismatch" -A 10 x/rewards/keeper/msg_server_test.go

Repository: KiiChain/kiichain

Length of output: 482


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- validation.go ---'
cat -n x/rewards/keeper/validation.go | sed -n '1,180p'

echo
echo '--- release_schedule.go ---'
cat -n x/rewards/types/release_schedule.go | sed -n '1,220p'

echo
echo '--- msg_server_test.go relevant section ---'
cat -n x/rewards/keeper/msg_server_test.go | sed -n '180,230p'

Repository: KiiChain/kiichain

Length of output: 8631


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n "ReleasedAmount|ReleasedAmount\." x/rewards -g'*.go'

Repository: KiiChain/kiichain

Length of output: 6967


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n "ReleasedAmount|ReleasedAmount\\." x/rewards -g'*.go'

Repository: KiiChain/kiichain

Length of output: 6967


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- x/rewards/types/release_schedule_test.go ---'
cat -n x/rewards/types/release_schedule_test.go | sed -n '1,140p'

echo
echo '--- x/rewards/types/genesis_test.go ---'
cat -n x/rewards/types/genesis_test.go | sed -n '1,160p'

echo
echo '--- x/rewards/types/reward.go ---'
cat -n x/rewards/types/reward.go | sed -n '1,120p'

Repository: KiiChain/kiichain

Length of output: 10885


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- x/rewards/keeper/abci.go ---'
cat -n x/rewards/keeper/abci.go | sed -n '1,160p'

echo
echo '--- sdk coin subtraction semantics references ---'
rg -n "func \\(c Coin\\) Sub|Sub\\(" "$(go env GOPATH 2>/dev/null)/pkg/mod" -g'coin.go' -g'*.go' 2>/dev/null | head -n 40

Repository: KiiChain/kiichain

Length of output: 5723


Zero-amount released coins should still reject mismatched denoms.

ReleasedAmount.IsZero() only checks Amount, so sdk.NewCoin("otherdenom", 0) now skips the denom check and makes the msg_server_test.go “denom mismatch” case pass unexpectedly. If zero released amounts are only meant to allow the canonical empty coin, keep validating Denom when it is set; otherwise update the test and callers to the new rule.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@x/rewards/keeper/validation.go` around lines 76 - 91, The released-amount
validation in validateSchedule currently skips denom checks whenever
ReleasedAmount.IsZero(), which lets zero-amount coins with a non-empty,
mismatched denom slip through. Update the logic in validateSchedule so
zero-amount released coins still validate the denom unless it is the canonical
empty coin, and keep the amount/limit checks guarded appropriately. Use
ReleasedAmount, TotalAmount, and validateAmount as the key symbols when
adjusting the condition, and align msg_server_test.go expectations if the rule
changes.

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.

1 participant