Skip to content

Fix unguarded worker_index read and harden POS commit-reveal - #216

Merged
sanada08 merged 2 commits into
Beldex-Coin:devfrom
Tore-tto:dev
Aug 27, 2026
Merged

Fix unguarded worker_index read and harden POS commit-reveal#216
sanada08 merged 2 commits into
Beldex-Coin:devfrom
Tore-tto:dev

Conversation

@Tore-tto

Copy link
Copy Markdown
  • master_node_voting: the signature-failure log read quorum.workers[vote.state_change.worker_index] for all vote types, but worker_index only exists on obligation votes -- for a checkpoint vote it aliases attacker-controlled bytes and indexes an empty vector. Guard it by vote type. Also re-enable the two success logs at MTRACE (level 3) instead of leaving them commented out.

  • pos: only accept a random value reveal from a quorum position that actually committed a hash, so the commit-reveal binding is enforced locally rather than relying on the stage timeout.

  • pos: drop the dead std::sample in signature selection and fix the comment -- the loop always used the first N.

-master_node_voting: the signature-failure log read
quorum.workers[vote.state_change.worker_index] for all vote types, but
worker_index only exists on obligation votes -- for a checkpoint vote it
aliases attacker-controlled bytes and indexes an empty vector. Guard it by
vote type. Also re-enable the two success logs at MTRACE (level 3) instead
of leaving them commented out.

-pos: only accept a random value reveal from a quorum position that actually
committed a hash, so the commit-reveal binding is enforced locally rather
than relying on the stage timeout.

-pos: drop the dead std::sample in signature selection and fix the comment --
the loop always used the first N.
@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 8399061c-1ea8-4d0f-af79-89401a785752

📥 Commits

Reviewing files that changed from the base of the PR and between c8e0c11 and 1f4912f.

📒 Files selected for processing (1)
  • src/wallet/wallet2.cpp

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation of random-value messages by rejecting messages without required prior verification data.
    • Corrected vote-signature handling for different vote types, preventing invalid data access during verification.
    • Final block signatures are now selected consistently from the lowest participating validator positions.
    • Corrected wallet error reporting when no matching output is found, preventing invalid data access.
  • Diagnostics
    • Added trace-level logging for successfully verified signatures to support troubleshooting.

Walkthrough

The changes update vote-signature logging, require committed hashes for random values, select the lowest participating validator positions for final signatures, and prevent invalid wallet output indexing in an error message.

Changes

Voting and PoS validation

Layer / File(s) Summary
Vote signature logging
src/cryptonote_core/master_node_voting.cpp
Accepted signatures now use trace logging. Invalid-signature logs use worker details only for obligation votes and validator details for other vote types.
PoS validation and signature selection
src/cryptonote_core/pos.cpp
Random values without committed hashes are rejected. Final signatures use the lowest participating validator positions. The minimum-signature assertion remains.

Wallet output error safety

Layer / File(s) Summary
Safe missing-output error reporting
src/wallet/wallet2.cpp
The missing-output exception now reports the requested amount without indexing an invalid output entry.

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

Merge Risk: ⚪ Minimal · up to 1f491

The PR makes localized validation, logging, and cleanup changes; no actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: agatha-luna, victor-tucci

Poem

A rabbit checks each vote with care,
No committed hash, no value there.
Lowest validators lead the way,
Safe wallet errors guard the day.
Trace logs glow as checks complete.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the unguarded worker_index read and the POS commit-reveal hardening, which are the primary changes. It is concise and specific.
Description check ✅ Passed The description accurately explains the voting fix, POS commit-reveal validation, signature-selection cleanup, and logging changes. It is related to the changeset.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1 too large.)

✨ 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.

When the requested amount is missing from the light wallet server's response, the search loop in light_wallet_get_outs exits with amount_key == amount_outs.size(). The error message then indexes amount_outs at that position, reading one past the end of the vector.

Report `amount` instead: it is the value being searched for, and on the success path it equals amount_outs[amount_key].amount by definition.
@sanada08
sanada08 self-requested a review August 27, 2026 10:38
@sanada08
sanada08 merged commit fae7bed into Beldex-Coin:dev Aug 27, 2026
2 checks passed
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.

2 participants