Skip to content

Reduce OrchardPrimitives generic parameter usage - #261

Open
ConstanceBeguier wants to merge 43 commits into
zsa1from
remove_orchard_primitives
Open

Reduce OrchardPrimitives generic parameter usage#261
ConstanceBeguier wants to merge 43 commits into
zsa1from
remove_orchard_primitives

Conversation

@ConstanceBeguier

@ConstanceBeguier ConstanceBeguier commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

This PR has two objectives

  • reduce the diff between our implementation and upstream
  • get an architecture closer with upstream (using enums instead of generic parameters to select between the different protocols)

Also

  • Remove OrchardPrimitives from ZK cirucit and expected_proof_size
  • Remove OrchardPrimitives from digests function (hash_bundle_txid_data and hash_bundle_auth_data)
  • Remove OrchardPrimitives from note encryption

@ConstanceBeguier ConstanceBeguier changed the title Reduce OrchardCircuit generic parameter usage Reduce OrchardPrimitives generic parameter usage Jul 23, 2026
@ConstanceBeguier
ConstanceBeguier force-pushed the remove_orchard_primitives branch 3 times, most recently from c00574f to 06b2b29 Compare July 24, 2026 15:12
@ConstanceBeguier
ConstanceBeguier force-pushed the remove_orchard_primitives branch from 06b2b29 to 86e91c7 Compare July 28, 2026 12:42
@ConstanceBeguier
ConstanceBeguier changed the base branch from cross_adress_zsa_circuit to zsa1 July 28, 2026 12:42
@ConstanceBeguier

Copy link
Copy Markdown
Collaborator Author

Rebase on zsa1

@ConstanceBeguier
ConstanceBeguier marked this pull request as ready for review July 29, 2026 15:11

@PaulLaux PaulLaux left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Overall very good result. Added comments. Also

  • Burn is unprotected. Lets add a check to Builder::add_burn() to allow only when self is ZSA.
  • Consider protecting further: add validate_burn(&burn, bundle_version) returning BurnNotPermitted, called from the three sites that already call validate_action_ciphertext_kind
  • Same check but in burn_validation.rs (select which set of all options is the most appropriate)
  • Split the burn logic away from the main logic so it is easier to swallow.

Also,

  • please run cargo clippy --all-targets --all-features: we have new warnings caused by our new code.

Comment thread benches/circuit.rs
.unwrap();
}
let bundle: Bundle<_, i64, FL> = builder.build(rng).unwrap().unwrap().0;
let bundle: Bundle<_, i64> = builder.build(rng).unwrap().unwrap().0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

as discussed cargo bench panics somewhere here

@ConstanceBeguier ConstanceBeguier Aug 5, 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.

Fixed

Comment thread src/bundle.rs Outdated

#[test]
fn commitment_hashes_the_wire_flag_byte(bundle in BundleArb::<OrchardVanilla>::arb_bundle(3)) {
fn commitment_hashes_the_wire_flag_byte(bundle in arb_bundle(3)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This will get a ZSA bundle once in 5 draws due to arb_bundle_version() then will build Bundle::from_parts_unchecked( under the assumbption that this is a vanilla bundle. Need to change to arb_bundle_vanilla() to keep semantics unchanged.

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.

Done

Comment thread src/bundle.rs Outdated
#[test]
fn ironwood_rejects_v5_commitment_version(bundle in BundleArb::<OrchardVanilla>::arb_bundle(3)) {
let bundle_i64 = Bundle::from_parts_unchecked(
fn ironwood_rejects_v5_commitment_version(bundle in arb_bundle(3)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Done

Comment thread src/bundle.rs Outdated
/// the same bundle commits to distinct transaction-ID digests under each.
#[test]
fn anchor_placement_follows_tx_version(bundle in BundleArb::<OrchardVanilla>::arb_bundle(3)) {
fn anchor_placement_follows_tx_version(bundle in arb_bundle(3)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Done

Comment thread src/bundle.rs Outdated

#[test]
fn try_from_parts_rejects_mismatched_action_ciphertext_kind(
bundle in arb_bundle(3)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This bundle can be ZSA and can be Vanilla. Is this what we want?

@ConstanceBeguier ConstanceBeguier Aug 5, 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.

Fixed

  • Created arb_bundle_zsa strategy for ZSA bundle
  • Used this strategy here.
  • Updated this test. Each actions in a bundle created with this new strategy has a ZSA ciphertext. Thus, the first rows of this test are now unnecessary.

Comment thread src/bundle/commitments.rs
BundleCommitmentFormat::OrchardV6 | BundleCommitmentFormat::IronwoodV6
BundleCommitmentFormat::OrchardV6
| BundleCommitmentFormat::IronwoodV6
| BundleCommitmentFormat::ZSA

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

OK, we added ZSA here but it is unused on the ZSA path. Should probably taken into account in hash_bundle_auth_data_zsa(). At least assert.

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.

Added an assert in hash_bundle_auth_data_zsa and a comment in includes_anchor_in_authorizing_digest

Comment thread src/bundle.rs
/// The arbitrary-bundle strategies generate flags independently of the version; this pairs them
/// into a combination that a `Bundle` can actually be constructed from.
fn flags_for_version(bundle_version: BundleVersion, flags: Flags) -> Flags {
pub(crate) fn flags_for_version(bundle_version: BundleVersion, flags: Flags) -> Flags {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should document the ZSA flag here.

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.

Done

Comment thread src/note_encryption.rs Outdated
Comment on lines +56 to +59
pub(crate) const ENC_CIPHERTEXT_SIZE_VANILLA: usize = NOTE_PLAINTEXT_SIZE_VANILLA + AEAD_TAG_SIZE;
/// The size of a ZSA encrypted note ciphertext, accounting for the AEAD tag.
pub(crate) const ENC_CIPHERTEXT_SIZE_ZSA: usize = NOTE_PLAINTEXT_SIZE_ZSA + AEAD_TAG_SIZE;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These 2 should be Public.

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 updated the visibility to public for those two constants.
I am not sure whether these constants are used in other crates.

Comment thread src/action.rs
Comment on lines +217 to -223
fn encrypted_note_for(
note: Note,
memo: Vec<u8>,
cv_net: &ValueCommitment,
cmx: &ExtractedNoteCommitment,
mut rng: impl RngCore,
) -> TransmittedNoteCiphertext {
// The Orchard, Ironwood and ZSA encryptor aliases share encryption behavior;
// `Note::version()` selects the note plaintext lead byte.
let encryptor = NoteEncryption::<NoteEncryptionDomain<OrchardVersion>>::new(
None,
note,
memo.try_into().unwrap(),
);

TransmittedNoteCiphertext {
epk_bytes: NoteEncryptionDomain::<OrchardVersion>::epk_bytes(encryptor.epk()).0,
enc_ciphertext: encryptor.encrypt_note_plaintext(),
out_ciphertext: encryptor.encrypt_outgoing_plaintext(cv_net, cmx, &mut rng),
}
}

impl<Pr: OrchardPrimitives> ActionArb<Pr> {
/// Builds a real, decryptable `TransmittedNoteCiphertext` for `note`,
/// mirroring `OutputInfo::build`: the same encryptor yields a non-identity
/// ephemeral public key (satisfying the `Action::from_parts` epk invariant)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the diff is strange here. can we reduce so it does not look like our change?

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 do not know how to reduce it. It is mainly a diff in indentation because we remove impl<Pr: OrchardPrimitives> ActionArb<Pr>

@ConstanceBeguier ConstanceBeguier Aug 6, 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.

You could add "?w=1" at the end of the github url. It will hide whitespace changes and make the diff much easier to read.
This URL for the whole PR diff
https://github.com/QED-it/orchard/pull/261/changes?w=1
This URL for the action.rs file diff
https://github.com/QED-it/orchard/pull/261/changes?w=1#diff-f4ccec926f8a15e422ea29ba8516940bab45ed47ee2845930c70531ef4ffa4c9

Comment thread src/action.rs
)(
nf in arb_nullifier(),
(rsk, rk) in arb_valid_spendauth_keypair(),
note in arb_note(output_value, note_version),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same for strange / unneeded diff

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.

See previous comment
The diff are due to the indentation changes (I removed an impl block which is no longer required)
You could add "?w=1" at the end of the url to hide whitespace changes

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.

2 participants