Skip to content

fix: conditionally include discriminator in CPI context account hashing#2369

Open
sergeytimoshin wants to merge 1 commit intomainfrom
claude/fix-cpi-context-hash-L05cn
Open

fix: conditionally include discriminator in CPI context account hashing#2369
sergeytimoshin wants to merge 1 commit intomainfrom
claude/fix-cpi-context-hash-L05cn

Conversation

@sergeytimoshin
Copy link
Copy Markdown
Contributor

@sergeytimoshin sergeytimoshin commented Apr 5, 2026

CpiContextInAccount and CpiContextOutAccount always passed
Some((discriminator, data_hash)) to hash_with_hashed_values, even when
has_data() was false. This caused hash mismatches for no-data compressed
accounts, as the regular account hashing correctly passes None when there
is no data. Now both implementations check has_data() before including
discriminator/data_hash in the hash, matching the behavior of the
non-CPI-context account hashing.

Forester is not affected - it uses pre-computed hashes from the indexer
and never calls hash_with_hashed_values directly.

https://claude.ai/code/session_01GEhytcJ5GZXB2ZZMH1ouS3

Summary by CodeRabbit

  • Bug Fixes
    • Fixed state validation for cross-program invocation operations with certain account configurations, improving the accuracy of contract interactions.

CpiContextInAccount and CpiContextOutAccount always passed
Some((discriminator, data_hash)) to hash_with_hashed_values, even when
has_data() was false. This caused hash mismatches for no-data compressed
accounts, as the regular account hashing correctly passes None when there
is no data. Now both implementations check has_data() before including
discriminator/data_hash in the hash, matching the behavior of the
non-CPI-context account hashing.

Forester is not affected - it uses pre-computed hashes from the indexer
and never calls hash_with_hashed_values directly.

https://claude.ai/code/session_01GEhytcJ5GZXB2ZZMH1ouS3
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 863e3d3b-8270-4e12-988b-9e1d3a196af4

📥 Commits

Reviewing files that changed from the base of the PR and between 8ddf06b and 16dfa8a.

📒 Files selected for processing (1)
  • programs/system/src/cpi_context/account.rs

📝 Walkthrough

Walkthrough

The PR updates the hash computation logic for CPI context accounts, making discriminator and data hash inclusion conditional. Previously, these values were always included in the hashing input; now they are included only when has_data() is true, switching the third parameter from Some(...) to None for accounts without data.

Changes

Cohort / File(s) Summary
CPI Context Account Hashing
programs/system/src/cpi_context/account.rs
Modified hash_with_hashed_values for both CpiContextInAccount and CpiContextOutAccount to conditionally include (discriminator, data_hash) tuple based on presence of account data, altering hash semantics for empty accounts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

The change affects critical hashing semantics that impact account verification. Reviewers should verify the motivation behind the conditional logic, assess backward compatibility implications, confirm that empty accounts are properly handled throughout the system, and ensure adequate test coverage validates both the presence and absence cases.

Poem

🔐 When data sleeps, the hash transforms anew,
From Some to None, a conditional view,
Accounts without substance now lighter they fly,
Hash semantics shift—why, oh why?

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 70.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: conditionally including the discriminator in CPI context account hashing, which directly addresses the core fix to resolve hash mismatches for no-data accounts.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 claude/fix-cpi-context-hash-L05cn

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.

@ananas-block
Copy link
Copy Markdown
Contributor

Compressed accounts owned by programs must always have data.
We need to check that with this fix cpi context behavior fully matches non cpi context behavior.

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.

3 participants