-
Notifications
You must be signed in to change notification settings - Fork 105
fix: Oracle EndBlocker: Unhandled panic in pickReferenceDenom can cause consensus failure #219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Oracle EndBlocker: Unhandled panic in pickReferenceDenom can cause consensus failure #219
Conversation
WalkthroughThe PR changes pickReferenceDenom in the oracle module to return an error as a third return value instead of panicking when parameter retrieval fails. tally.go now propagates and returns errors from k.Params.Get(ctx). EndBlocker in abci.go is updated to handle and log the error returned by pickReferenceDenom and to return on error. Tests calling pickReferenceDenom were updated to accept the additional return value (discarding it). CHANGELOG.md was updated with a Fixed entry referencing the change. Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
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. Comment |
f5f872b to
36e7df1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @CHANGELOG.md:
- Line 20: The changelog contains a duplicate entry "Handle error in
pickReferenceDenom instead of panic to prevent consensus failure
[#203](https://github.com/KiiChain/kiichain/issues/203)" present in both the
UNRELEASED section and the v6.0.0 section; remove the duplicate from the
appropriate section: if v6.0.0 has already been released, delete the entry from
the UNRELEASED section, otherwise delete the entry from the v6.0.0 section so
the fix only appears in UNRELEASED; locate the exact line by searching for the
quoted entry text to update the correct section.
In @x/oracle/tally.go:
- Line 22: The call to k.StakingKeeper.TotalBondedTokens(ctx) currently ignores
its returned error, which can yield invalid totalBondedTokens and bad threshold
math; update the code to capture the error (e.g., totalBondedTokens, err :=
k.StakingKeeper.TotalBondedTokens(ctx)), check err, and propagate or handle it
consistently with the PR's error-handling pattern (return the error or wrap it
with context) instead of discarding it.
🧹 Nitpick comments (1)
x/oracle/tally_test.go (1)
100-100: Consider adding a test case for the error path.Discarding the error with
_is acceptable for this happy-path test sinceParamsis properly set up (lines 45-49). However, consider adding a separate test case that verifiespickReferenceDenomreturns an error whenk.Params.Get(ctx)fails (e.g., when params are not initialized). This would ensure the new error-handling behavior is covered.Would you like me to generate a test case for the error scenario?
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
CHANGELOG.mdx/oracle/abci.gox/oracle/tally.gox/oracle/tally_test.go
🧰 Additional context used
🧬 Code graph analysis (1)
x/oracle/tally.go (4)
x/oracle/keeper/keeper.go (1)
Keeper(22-42)x/oracle/types/params.pb.go (6)
Denom(113-116)Denom(119-119)Denom(120-122)Params(28-50)Params(53-53)Params(54-56)x/oracle/types/ballot.go (2)
ExchangeRateBallot(51-51)Claim(13-19)x/oracle/types/expected_keepers.go (1)
StakingKeeper(17-24)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: tests
- GitHub Check: test-e2e
- GitHub Check: golangci-lint
- GitHub Check: Analyze
🔇 Additional comments (3)
x/oracle/tally.go (2)
26-29: LGTM!The panic is correctly replaced with proper error propagation. Returning the error allows the caller (
EndBlocker) to handle it gracefully, preventing consensus failure.
67-67: LGTM!The successful path correctly returns
nilfor the error, maintaining the expected behavior when no errors occur.x/oracle/abci.go (1)
78-81: LGTM!The error is properly captured and returned, following the same pattern used elsewhere in
EndBlocker(e.g., lines 22-24, 34-36). This ensures that parameter retrieval failures inpickReferenceDenomare gracefully propagated rather than causing a panic.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a critical consensus failure vulnerability in the oracle module by replacing an unhandled panic with proper error handling. The panic in pickReferenceDenom was being triggered from the EndBlocker ABCI method, which could cause all validators to crash simultaneously and halt the chain.
Key Changes:
- Modified
pickReferenceDenomfunction signature to return an error instead of panicking - Updated the EndBlocker to handle errors from
pickReferenceDenom - Updated unit tests to accommodate the new function signature
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| x/oracle/tally.go | Changed pickReferenceDenom function signature to return error; replaced panic(err) with return "", nil, err for proper error propagation |
| x/oracle/abci.go | Updated EndBlocker to handle the error returned by pickReferenceDenom |
| x/oracle/tally_test.go | Updated TestPickReferenceDenom to handle the additional error return value from pickReferenceDenom |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Return error from pickReferenceDenom instead of panic(err) - Handle error in EndBlocker caller with proper logging - Update test to handle new return value - Fixes KiiChain#203
b9cd73b to
955caa2
Compare
|
Same fix as #220, closing this one |
[BUG] Oracle EndBlocker: Unhandled panic in pickReferenceDenom can cause consensus failure
Bug Description
Found a panic in the oracle module that can cause chain halt. The
pickReferenceDenomfunction is called from EndBlocker, and contains an unhandledpanic(err).Location:
x/oracle/tally.goThe
pickReferenceDenomfunction is called fromEndBlockerinx/oracle/abci.go:This is dangerous - panic in a function called from an ABCI method (EndBlocker) will crash all validators on the same block.
Attack Flow
Conditions that cause
Params.Get()to error:Environment
x/oracle/tally.goline 28pickReferenceDenom()x/oracle/abci.goEndBlockerImpact
Severity: Critical
Similar bugs:
MsgRemove{Delegate}Stakewith negative amount sherlock-audit/2024-06-allora-judging#21Fix
Return error instead of panic:
Full Fix Files
File 1:
x/oracle/tally.go(MODIFIED)Change function signature to return error and replace panic with return:
File 2:
x/oracle/abci.go(MODIFIED)Update caller to handle error:
File 3:
x/oracle/tally_test.go(MODIFIED)Update test to handle new return value:
Test Result (After Fix)