Skip to content

Add memo size check#1868

Open
levonpetrosyan93 wants to merge 2 commits into
masterfrom
memo_size
Open

Add memo size check#1868
levonpetrosyan93 wants to merge 2 commits into
masterfrom
memo_size

Conversation

@levonpetrosyan93

Copy link
Copy Markdown
Contributor

No description provided.

@codeant-ai

codeant-ai Bot commented Jul 6, 2026

Copy link
Copy Markdown

User petrosyan.levon93@gmail.com does not have a PR Review subscription.

Go to Team management and add this email to the PR Review subscription.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • Bug Fixes
    • Strengthened memo decoding during coin identification to ensure the decrypted memo data matches the expected format before extracting the memo length.
    • Improved memo validation consistency across both mint and spend identification paths, while preserving the same failure behavior if identification cannot be completed.

Walkthrough

Coin::identify() now centralizes padded memo validation and decoding through DecodeMemoOrThrow. Both mint and spend paths use the helper, which enforces the expected padded memo size and preserves the existing identification failure exception.

Changes

Memo decoding validation

Layer / File(s) Summary
Shared memo decoder and identification integration
src/libspark/coin.cpp
Adds DecodeMemoOrThrow for exact padded-memo size and encoded-length validation, then uses it in both mint and spend identification branches.

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

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning No PR description was provided, so the required intention and code changes sections are missing. Add the required PR intention and code changes brief sections, describing the memo size validation change and its purpose.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: adding a memo size check during coin identification.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch memo_size

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2972c16cbc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/libspark/coin.cpp Outdated
// Check that the memo length is valid
unsigned char memo_length = r.padded_memo[0];
if (memo_length > this->params->get_memo_bytes()) {
if (memo_length > this->params->get_memo_bytes() || memo_length > (r.padded_memo.size() - 1)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Guard empty memo buffers before subtracting

This new bounds check still misses a decrypted recipient payload whose serialized padded_memo is empty: r.padded_memo[0] has already read out of bounds, and r.padded_memo.size() - 1 wraps to a huge value, so the intended Unable to identify coin path is not reached. A sender can craft an authenticated payload with trailing bytes to satisfy the fixed outer ciphertext size while leaving the inner memo string empty, so wallet scanning can still hit undefined behavior instead of rejecting the coin; check empty() before indexing/subtracting in both identify paths.

Useful? React with 👍 / 👎.

@codeant-ai

codeant-ai Bot commented Jul 13, 2026

Copy link
Copy Markdown

User petrosyan.levon93@gmail.com does not have a PR Review subscription.

Go to Team management and add this email to the PR Review subscription.

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

🧹 Nitpick comments (1)
src/libspark/coin.cpp (1)

4-25: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Apply the repository’s C++ formatting rules to the new helper.

The anonymous namespace uses same-line braces, and the helper is tab-indented. Use a newline before the namespace brace and four spaces throughout this added block.

🤖 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 `@src/libspark/coin.cpp` around lines 4 - 25, Reformat the DecodeMemoOrThrow
helper block to match repository C++ style: place the anonymous namespace
opening brace on the following line and replace tab indentation with four spaces
throughout the added namespace and helper code. Preserve all logic unchanged.

Source: Coding guidelines

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

Nitpick comments:
In `@src/libspark/coin.cpp`:
- Around line 4-25: Reformat the DecodeMemoOrThrow helper block to match
repository C++ style: place the anonymous namespace opening brace on the
following line and replace tab indentation with four spaces throughout the added
namespace and helper code. Preserve all logic unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: cf3ad6a8-3d73-4b41-94d5-601821ef5724

📥 Commits

Reviewing files that changed from the base of the PR and between 2972c16 and efb4c57.

📒 Files selected for processing (1)
  • src/libspark/coin.cpp

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