Skip to content

Conversation

@ananas-block
Copy link
Contributor

@ananas-block ananas-block commented Jan 23, 2026

Changes

  1. New Constant Definition
  • Added DECOMPRESSED_PDA_DISCRIMINATOR: [u8; 8] = [255u8; 8] to program-libs/compressible/src/lib.rs
  • Marks placeholder compressed accounts created when PDAs are decompressed to Solana accounts
  • Shared constant used across MintAction and SDK implementations
  1. MintAction Changes (Compressed Token Program)

Three files updated to handle decompressed mint placeholders:

mint_output.rs:

  • Modified serialize_compressed_mint() to accept validated_accounts parameter
  • When mint is decompressed:
    • Allocate exactly 32 bytes for data (was 0)
    • Copy PDA pubkey to data field
    • Set discriminator to DECOMPRESSED_PDA_DISCRIMINATOR
    • Hash PDA pubkey with Sha256BE for data_hash

mint_input.rs:

  • When processing input for decompressed mints:
    • Set discriminator to DECOMPRESSED_PDA_DISCRIMINATOR
    • Hash mint pubkey with Sha256BE for data_hash

zero_copy_config.rs:

  • Allocate 32 bytes for decompressed mint data (was 0)
  1. SDK Interface Changes

Three files updated for generic PDA compression/decompression flows:

compress_account_on_init.rs:

  • Added set_decompressed_pda_output() helper with #[inline(never)] for stack optimization
  • Sets PDA pubkey in data, hashes it, sets decompressed discriminator

compress_account.rs:

  • Added set_decompressed_pda_input() helper with #[inline(never)] for stack optimization
  • When re-compressing a decompressed PDA, fixes input to use new format

decompress_idempotent.rs:

  • Added set_decompressed_pda_output() helper with #[inline(never)] for stack optimization
  • Sets output for decompressed PDA placeholder with new format
  1. Test Updates
  • program-tests/utils/src/assert_mint_action.rs: Updated to verify discriminator and PDA pubkey in decompressed placeholder
  • sdk-tests/csdk-anchor-full-derived-test/tests/basic_test.rs: Updated assertions for decompressed PDA format
  • sdk-tests/csdk-anchor-full-derived-test/tests/mint/metadata_test.rs: Updated assertions for decompressed PDA format

Technical Details

  • Used #[inline(never)] on helper functions to reduce stack usage and avoid SBF stack limit issues
  • Sha256BE hash used for all PDA pubkey hashing to maintain consistency
  • Placeholder data is always exactly 32 bytes (the PDA pubkey)
  • All three SDK interface files (compress, compress_on_init, decompress) now use consistent format

Summary by CodeRabbit

  • New Features

    • Decompressed accounts now use a distinct marker and store the PDA pubkey as the payload, with its hash recorded for integrity.
  • Improvements

    • Serialization and account preparation paths updated to populate decompressed outputs/inputs with PDA data and computed hashes.
    • Zero-copy layout and validation updated to expect 32-byte decompressed mint data.
  • Bug Fixes

    • More consistent metadata and error messages for decompressed account handling.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 23, 2026

📝 Walkthrough

Walkthrough

Adds a new public constant DECOMPRESSED_PDA_DISCRIMINATOR and updates compressed-mint handling and SDK account preparation/serialization to use that discriminator with SHA-256 hashed PDA pubkeys for decompressed PDA placeholders.

Changes

Cohort / File(s) Summary
Core Constant Definition
program-libs/compressible/src/lib.rs
Adds public constant DECOMPRESSED_PDA_DISCRIMINATOR: [u8; 8] (value: [255,255,255,255,255,255,255,0]) with docs marking decompressed PDA placeholders.
Mint action — input, output, config
programs/compressed-token/program/src/compressed_token/mint_action/mint_input.rs, .../mint_output.rs, .../zero_copy_config.rs
mint_input.rs: imports discriminator and uses it with SHA‑256(mint PDA) for decompressed-input hashing. mint_output.rs: serialize_compressed_mint(...) gains validated_accounts: &MintActionAccounts, when decompressed sets discriminator to DECOMPRESSED_PDA_DISCRIMINATOR, writes 32‑byte CMint PDA into data and sets data_hash = SHA‑256(pda). zero_copy_config.rs: decompressed mint output data length changed from 0 to 32.
SDK — account prepare/serialize helpers
sdk-libs/sdk/src/interface/compress_account.rs, sdk-libs/sdk/src/interface/compress_account_on_init.rs, sdk-libs/sdk/src/interface/decompress_idempotent.rs
Adds private helpers (e.g., set_decompressed_pda_input / set_decompressed_pda_output) that set discriminator = DECOMPRESSED_PDA_DISCRIMINATOR, write PDA pubkey bytes to data, and compute data_hash = SHA‑256(pubkey). Integrates these into account preparation flows for compression input, init output, and idempotent decompression output.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

ai-review

Suggested reviewers

  • sergeytimoshin
  • SwenSchaeferjohann

Poem

🧩 A marker set where zeros once lay,
Eight bytes beckon a clearer way,
Pubkeys hashed, discriminators shine,
Mints and SDKs now speak the same line —
Small change, tidy song, code aligned.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 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: introducing a new discriminator constant and updating code to expose the PDA pubkey in decompressed account placeholders across multiple files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 70.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jorrit/refactor-add-255u8-discriminators

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@program-libs/compressible/src/lib.rs`:
- Around line 7-10: Update the doc comment for DECOMPRESSED_PDA_DISCRIMINATOR to
state that the decompressed PDA entry stores the raw PDA pubkey bytes in the
account data (not a hashed pubkey) and that the pubkey is hashed separately into
data_hash elsewhere; mention that this discriminator marks a compressed account
as a decompressed PDA placeholder so readers know where raw pubkey bytes are
stored and how the hash is derived later.

In `@sdk-libs/sdk/src/interface/compress_account_on_init.rs`:
- Around line 133-140: The code uses a temporary method call &account_info.key()
when calling set_decompressed_pda_output; update this to the established pattern
by passing a reference to the byte array from the field conversion used
elsewhere—replace the argument with &account_info.key.to_bytes() (keeping the
surrounding logic in the if !with_data branch where compressed_account,
account_info_result, with_data, and set_decompressed_pda_output are used) so the
call site matches decompress_idempotent.rs and stays consistent across the
codebase.

@ananas-block ananas-block force-pushed the jorrit/refactor-add-255u8-discriminators branch from ac354b7 to 2de431e Compare January 23, 2026 17:58
@ananas-block ananas-block merged commit 9abe420 into main Jan 24, 2026
33 of 34 checks passed
@ananas-block ananas-block deleted the jorrit/refactor-add-255u8-discriminators branch January 24, 2026 02:07
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