Skip to content

fix DSC Key Smuggling via Unsigned TBS Data [LA-A]#368

Merged
ashpect merged 3 commits into
v1from
us/fix-dsckey-smuggling
Mar 26, 2026
Merged

fix DSC Key Smuggling via Unsigned TBS Data [LA-A]#368
ashpect merged 3 commits into
v1from
us/fix-dsckey-smuggling

Conversation

@x-senpai-x
Copy link
Copy Markdown
Collaborator

@x-senpai-x x-senpai-x commented Mar 22, 2026

Summary

This PR addresses the DSC Key Smuggling via Unsigned TBS Data audit finding. It includes:

1. Zero-padding constraint (1300-byte path)

  • Adds check_zero_padding(tbs_certificate, tbs_certificate_len) in t_add_dsc_verify_1300 immediately after the length bounds check
  • Imports utils::check_zero_padding, which already exists and is used in the 720-byte path

2. Constrained ASN.1 length validation (both DSC circuits)

  • Adds get_asn1_element_length constrained utility to utils/utils/src/lib.nr — computes total TLV length from a DER element header without unconstrained/unsafe
  • Both t_add_dsc_720 and t_add_dsc_verify_1300 now validate the prover-supplied tbs_certificate_len against the value derived from the DER SEQUENCE header, preventing a malicious prover from lying about the signed length

3. Pubkey signed-length bound check

  • verify_rsa_pubkey_in_tbs now accepts tbs_certificate_len and asserts pubkey_offset + DSC_KEY_SIZE <= tbs_certificate_len, ensuring the key lies within the authenticated region of the TBS, not just within the fixed-size buffer
  • Both t_add_id_data_720 and t_add_id_data_1300 compute tbs_certificate_len from the DER header and pass it through

4. DER SubjectPublicKeyInfo structural validation

  • verify_rsa_pubkey_in_tbs now validates that the modulus is wrapped in a proper DER INTEGER (tag, long-form length, optional leading zero) and that the INTEGER is the first child of an RSAPublicKey SEQUENCE (30 82)
  • Encoding form (leading-zero vs. no-leading-zero) is inferred from TBS bytes rather than from dsc_pubkey, preventing a prover from manipulating which path is taken

5. Modify ProverInputs and remove signed_attributes_size field

  • Matched the inputs according to the ones generated using passport-input-gen library as they follow ASN.1 parsing.

Background

The 1300-byte DSC registration circuit splits SHA-256 hashing across two sub-circuits (t_add_dsc_hash_1300 + t_add_dsc_verify_1300) using a pre-computed hash. Unlike the 720-byte path — which calls sig_check_rsa::verify_signaturesha256_and_check_data_to_signcheck_zero_padding automatically — the 1300-byte path passes a pre-computed msg_hash: [u8; 32] directly to fragmented_sig_check_rsa::verify_rsa_signature, which never sees the raw TBS buffer. This meant the zero-padding guard was never applied.


Note

The following items from the audit are deferred to subsequent PRs:

Binding tbs_certificate_len into the commitment chain (if needed)
Audit suggestion 1 (separate PR)

Copilot AI review requested due to automatic review settings March 22, 2026 09:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR closes a security gap in the 1300-byte DSC verification circuit by ensuring the padded portion of the fixed-size TBS buffer is constrained to zero, preventing attacker-controlled trailing bytes from influencing downstream commitments while not being covered by the signature/hash path.

Changes:

  • Import and apply utils::check_zero_padding to tbs_certificate in t_add_dsc_verify_1300 right after the tbs_certificate_len bounds check.
  • Add an explanatory comment clarifying why the constraint is required for commitment safety.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@x-senpai-x x-senpai-x changed the title fix DSC Key Smuggling via Unsigned TBS Data fix DSC Key Smuggling via Unsigned TBS Data [LA-A] Mar 22, 2026
@ashpect ashpect merged commit fb5f290 into v1 Mar 26, 2026
1 of 3 checks passed
dcbuild3r pushed a commit that referenced this pull request May 16, 2026
fix DSC Key Smuggling via Unsigned TBS Data [LA-A]
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