Skip to content

fix: include segments_count bytes in worst_case_body_size (M8)#565

Merged
QuantumExplorer merged 1 commit into
developfrom
fix/M8-worst-case-body-size
Mar 6, 2026
Merged

fix: include segments_count bytes in worst_case_body_size (M8)#565
QuantumExplorer merged 1 commit into
developfrom
fix/M8-worst-case-body-size

Conversation

@QuantumExplorer
Copy link
Copy Markdown
Member

Summary

Fixes audit finding M8: worst_case_body_size underestimates prefix hash input by 8 bytes (on 64-bit platforms).

Problem

build_prefix_body constructs a body consisting of:

  1. All segment bytes concatenated
  2. segments_count.to_ne_bytes() — a usize (8 bytes on 64-bit)
  3. One u8 length byte per segment

But worst_case_body_size only accounted for #1 and #3:

path.len() + path.iter().map(|a| a.max_length() as usize).sum::<usize>()
// = segments_count + sum(segment_bytes)
// Missing: size_of::<usize>() for segments_count.to_ne_bytes()

This underestimate means a path with body size in [57, 64] would be estimated as needing 1 Blake3 block (≤64 bytes) when it actually requires 2 blocks (>64 bytes), causing fee cost estimation to undercharge.

Fix

Add std::mem::size_of::<usize>() to the computation:

path.iter().map(|a| a.max_length() as usize).sum::<usize>()
    + std::mem::size_of::<usize>()
    + path.len()

Test plan

  • All storage tests pass (cargo test -p grovedb-storage)
  • All 1274 grovedb lib tests pass (cargo test -p grovedb --lib)

🤖 Generated with Claude Code

worst_case_body_size was missing the size_of::<usize>() bytes from
segments_count.to_ne_bytes() that build_prefix_body appends. On 64-bit
platforms this underestimates by 8 bytes, causing paths with body sizes
in [57,64] to estimate 1 Blake3 block when 2 are actually needed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 6, 2026

Warning

Rate limit exceeded

@QuantumExplorer has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 27 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ad5829ec-7cf8-4b14-9fc5-04d72f46fee8

📥 Commits

Reviewing files that changed from the base of the PR and between a42c936 and 784dbc6.

📒 Files selected for processing (1)
  • storage/src/rocksdb_storage/storage.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/M8-worst-case-body-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 and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.66%. Comparing base (1b119d3) to head (784dbc6).
⚠️ Report is 4 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #565      +/-   ##
===========================================
- Coverage    90.66%   90.66%   -0.01%     
===========================================
  Files          182      182              
  Lines        49474    49491      +17     
===========================================
+ Hits         44856    44869      +13     
- Misses        4618     4622       +4     
Components Coverage Δ
grovedb-core 88.86% <ø> (-0.02%) ⬇️
merk 91.88% <ø> (ø)
storage 85.50% <100.00%> (+0.02%) ⬆️
commitment-tree 96.41% <ø> (ø)
mmr 96.72% <ø> (ø)
bulk-append-tree 91.50% <ø> (ø)
element 97.55% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member Author

@QuantumExplorer QuantumExplorer left a comment

Choose a reason for hiding this comment

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

Reviewed

@QuantumExplorer QuantumExplorer merged commit 32ae393 into develop Mar 6, 2026
10 checks passed
@QuantumExplorer QuantumExplorer deleted the fix/M8-worst-case-body-size branch March 6, 2026 11:50
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