Skip to content

ChaCha20-Poly1305: open zeroes the data on a wrong tag, in verified code - #4347

Merged
alex merged 10 commits into
mainfrom
claude/audit-4139-chacha-open-zero
Nov 6, 2026
Merged

alex merged 10 commits into
mainfrom
claude/audit-4139-chacha-open-zero

Conversation

@alex

@alex alex commented Nov 6, 2026

Copy link
Copy Markdown
Member

Part of #4139 (finding 7: ChaCha20-Poly1305: zeroing on a bad tag is Rust's)

Implements openZeroApi (spec merged in #4312) for every target and variant. On a wrong tag, vg_chacha20_poly1305_open now zeroes len bytes at data itself. It leaks only whether the tag was right (openLeak). The Rust data.fill(0) in decrypt_in_place is deleted, and so is the "ChaCha20-Poly1305 decryption" entry under "What is not verified" in the README.

What changed

  • Code. After the tags are compared, each open branches on the result and runs a byte loop that zeroes the data (zeroData). This is the only new code on the success path: a compare and a branch the taint analysis checks against the leak.
    • x86-64 (baseline and stitched AVX2): one shared openTail, in Proof/ChaCha20Poly1305/X86_64/OpenTail.lean.
    • AArch64, x86, ARMv7, PPC64LE, RISC-V: the same pattern in each target's code.
  • AArch64 frame. Some AArch64 paths (stitched, wide, OpenPad) reuse x22/x23, so at the tail no register holds data and len. open therefore saves them after the context (saveData, ctx[1280, 1296)). Its frame grows from 1280 to 1296 bytes, and its scratch contract from 160 to 162 words.
    • The code up to the tag is still proven with permission to write only the data, the context and those 16 bytes.
    • That proof is moved to the 1296-byte contract with RegionModel.verified_narrowTo.
    • seal, the gather variant and ctxR are unchanged.
  • Constant time.
    • Branch on the result: both runs agree, by correctness plus the contract's leak.
    • Zeroing loop: it runs on len and stores at data. Correctness shows these are the values the code loaded, which are public.
  • Frame wrappers. The stack-scratch wrappers on x86-64 (StackArgScratchWipe), AArch64, RISC-V, PPC64LE and ARMv7 now take a contract leak. Every other caller passes none.
  • Cleanup. Removed the now-unused untrusted openScratchContract/openPost_local/openPost_out, and AArch64's unused openWith/«open»/openStitched.

No change to TCB/ or Spec/. The old Spec.ChaCha20Poly1305.openApi/openContract/openPost are now unused, and I'll remove them in a follow-up PR of their own, since that is a Spec/ change.

Checks

  • Full lake build and Emit.lean. Only the six chacha20poly1305 crate files change.
  • The static checks of the lean-imports job.
  • check_lean_public_imports.py on the edited modules.
  • cargo fmt --check and cargo clippy --all-targets -- -D warnings.
  • cargo test with Wycheproof on x86-64, and VG_CPU_FEATURES=none for the ChaCha20-Poly1305 tests.
  • The existing tests (round_trip, Wycheproof, RFC 8439 forgery) check that data is zeroed on a wrong tag, so they now test the verified code.

Benchmarks, scoped to chacha20poly1305 on every architecture against the base: https://github.com/pyca/verified-garbage/actions/runs/42266494176


Generated by Claude Code

@alex
alex enabled auto-merge November 6, 2026 18:03
@alex
alex added this pull request to the merge queue Nov 6, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 6, 2026
# Conflicts:
#	README.md
#	lean/VerifiedGarbage/Impl/ChaCha20Poly1305/AArch64/Stitched.lean
#	lean/VerifiedGarbage/Proof/ChaCha20Poly1305/AArch64/Correct.lean
@alex
alex enabled auto-merge November 6, 2026 19:04
@alex

alex commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

CI is failing

alex commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

Lean: shard (1) failed on the merge with main because Proof/ChaCha20Poly1305/X86_64/OpenTail.lean used ea_disp. #4345 deleted it as dead, since nothing on main used it then. It was a one-line rfl lemma, and 058bff2 inlines it.


Generated by Claude Code

@alex
alex added this pull request to the merge queue Nov 6, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 6, 2026

alex commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

The merge-queue run (https://github.com/pyca/verified-garbage/actions/runs/42280340668) failed on one job only. Rust (Linux, RISC-V, host) ran on the RISE runner for 23 minutes, was cancelled, and has no log (404). all-green and Rust coverage failed or were cancelled as a result. Every other job passed, Lean and the other architectures included. The same RISC-V job passed in this PR's own CI on this head (058bff2). This looks like the runner, not this change. I can't re-queue it myself: could it be re-queued?


Generated by Claude Code

@alex
alex added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit 3939552 Nov 6, 2026
36 checks passed
@alex
alex deleted the claude/audit-4139-chacha-open-zero branch November 6, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants