Skip to content

Add v2 memo plaintext ciphertext resolution#2555

Merged
nuttycom merged 3 commits into
mainfrom
dev/pczt-v2-memo-plaintext
Jul 8, 2026
Merged

Add v2 memo plaintext ciphertext resolution#2555
nuttycom merged 3 commits into
mainfrom
dev/pczt-v2-memo-plaintext

Conversation

@ValarDragon

@ValarDragon ValarDragon commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Represent Orchard encrypted note plaintext as either ciphertext or stripped memo plaintext in the logical PCZT model, and resolve compact fields before Orchard role parsing.

We plan for more compact fields to get resolved like this before Orchard role parsing. So what I did was add a mutative "resolve_fields" function, for resolving fields that have been redacted, but are needed for Orchard calls.

We add a function in redactor to swap all Orchard ciphertexts with memo's, for all memo's that are decryptable via the action struct.

This saves us ~570 bytes/action in serialization to Keystone's, which is very significant. It halves the size relative to the state after making Anchor optional. This reduces ~4 QR frames per action, and were talking about 90-150 action flows.

@ValarDragon
ValarDragon requested a review from nuttycom July 7, 2026 16:33
@ValarDragon
ValarDragon force-pushed the dev/pczt-v2-memo-plaintext branch 2 times, most recently from 0ebd4dd to f1b2599 Compare July 7, 2026 17:46
Represent Orchard encrypted note plaintext as either ciphertext or stripped memo plaintext in the logical PCZT model, and resolve compact fields before Orchard role parsing.

Co-Authored-By: OpenAI Codex <codex@openai.com>
@ValarDragon
ValarDragon force-pushed the dev/pczt-v2-memo-plaintext branch from f1b2599 to d620dfa Compare July 7, 2026 17:58
Comment thread pczt/src/orchard.rs
Comment on lines +1392 to +1394
pub fn resolve_fields(&mut self) -> Result<(), ::orchard::pczt::ParseError> {
self.resolve_memo_plaintexts()
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I want to add cv_net here in a follow-up PR.

Comment thread pczt/src/roles/redactor/orchard.rs Outdated
Comment thread pczt/src/orchard.rs
Comment on lines +1636 to +1638
enc_ciphertext: EncCiphertext::Encrypted(
output.encrypted_note().enc_ciphertext.to_vec(),
),

@ValarDragon ValarDragon Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Intentional, as we don't need to deal with "was this a more compressed memo representation". That is purely a redaction-time and serialization time concern.

Comment thread pczt/src/orchard.rs Outdated
Comment on lines +1519 to +1521
action
.output
.resolve_memo_plaintext(note_version, spend.nullifier().to_bytes())?;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Make this an assign, not a mutative operation

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The advantage of making this a mutative operation is actually that we get to avoid an excess 512 byte memo allocation - this appears in constrained devices, so seems worth the mutative API trade-off.

Comment thread pczt/src/orchard.rs Outdated
Have Orchard memo recovery return the stripped MemoPlaintext representation directly, so redaction callers do not need to wrap recovered memo bytes themselves.

Also tighten related rustdoc around memo plaintext recovery and redaction terminology.

Co-Authored-By: OpenAI Codex <noreply@openai.com>
@ValarDragon
ValarDragon force-pushed the dev/pczt-v2-memo-plaintext branch from 4225d46 to 94905a4 Compare July 8, 2026 01:34
Comment thread pczt/src/orchard.rs Outdated
Base automatically changed from adam/pczt-v2-optional-anchor-cv-net to main July 8, 2026 12:58
Comment thread pczt/src/orchard.rs
}
}

/// A memo plaintext with all trailing zero bytes stripped.

@dannywillems dannywillems Jul 8, 2026

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.

It is important to note that there is an invariant that the plaintext maximum length (i.e. the size of the inner vector) is MEMO_SIZE. All constructors MUST verify this invariant, which is the case at the moment, as it is not enforced by the type.

The second constructor, from_stripped_bytes, can construct vectors of any size below MEMO_SIZE.

@czarcas7ic

Copy link
Copy Markdown
Collaborator

As requested by nuttycom, lets only merge this and next PR until #2539 is merged @dannywillems, we can still get PR approved / ready though

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

Blocking merge until 2539 is merged, see #2555 (comment)

@dannywillems

Copy link
Copy Markdown
Contributor

As requested by nuttycom, lets only merge this and next PR until #2539 is merged @dannywillems, we can still get PR approved / ready though

I didn't know. Explicitly requesting changes to avoid anyone else merging, in case of other async review/approvals.

Comment thread pczt/src/orchard.rs
Require callers to construct the Encrypted variant explicitly so the encrypted-ciphertext and memo-plaintext representations remain visible at call sites.

Co-Authored-By: OpenAI Codex <noreply@openai.com>
@nuttycom
nuttycom dismissed dannywillems’s stale review July 8, 2026 16:01

Clearing the merge block now that #2539 has merged.

@nuttycom
nuttycom merged commit bb0cdbd into main Jul 8, 2026
49 checks passed
@nuttycom
nuttycom deleted the dev/pczt-v2-memo-plaintext branch July 8, 2026 16:01
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.

4 participants