fix(oracle): handle ValAddressFromBech32 error in EndBlocker#241
Conversation
WalkthroughThis change updates the EndBlocker in x/oracle/abci.go to handle errors from sdk.ValAddressFromBech32 when parsing validator operator addresses. On parse error, the code now logs the operator and error and skips that validator; on success, it uses the parsed operator address to create and map the claim. A changelog entry describing this fix was also added. Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@x/oracle/abci.go`:
- Line 63: The syntax error is caused by two statements on one line; split the
call to types.NewClaim and the assignment to validatorClaimMap into separate
statements: create the claim with types.NewClaim(...) and then on the next line
assign it with validatorClaimMap[operator] = claim (referencing types.NewClaim,
validatorClaimMap and operator to locate the code).
🧹 Nitpick comments (1)
x/oracle/abci.go (1)
55-62: Proper error handling added for address parsing.The error handling approach is correct: logging the failure with structured context (
operatoranderror) and skipping the invalid validator prevents nil addresses from propagating through the claim system. This is preferable to halting the EndBlocker entirely.Minor nit: Line 56 duplicates the comment from line 55 ("Parse the operator address").
🔧 Remove duplicate comment
operator := validator.GetOperator() // Get address to receive coins - // Parse the operator address // Parse the operator address operatorAddr, err := sdk.ValAddressFromBech32(operator)
- Add proper error handling for validator address parsing - Log error and skip invalid validators instead of using nil operatorAddr - Update CHANGELOG.md with fix entry - Fix import formatting with gci Fixes KiiChain#234
3add895 to
6373622
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Severity: LOW
File:
x/oracle/abci.goLine: 56
Repository: https://github.com/KiiChain/kiichain
Version: v6.1.0
Commit:
79bdc96Issue: #234
PR: #240
Auditor: ngapaxs
Date: 2025-01-19
Summary
Found an ignored error in the oracle module's EndBlocker. When parsing validator addresses fails, the code just ignores it with
_, which means that validator gets skipped silently.Affected Code
Root Cause
The error from
ValAddressFromBech32gets ignored with_. If parsing fails,operatorAddrends up nil and the claim gets an invalid recipient.Impact
Recommended Fix
Just log the error and skip that validator. Don't return error because that could let malicious validators disable the whole module.
Reference
https://github.com/KiiChain/kiichain/blob/v6.1.0/x/oracle/abci.go#L56