Harden untrusted decode paths - #2
Open
mellowcroc wants to merge 2 commits into
Open
Conversation
mellowcroc
force-pushed
the
audit/ed25519-key-validation
branch
from
August 13, 2026 09:48
4164355 to
dbbfb84
Compare
mellowcroc
force-pushed
the
harden/untrusted-decode-dos
branch
from
August 13, 2026 09:48
96daa63 to
56f410e
Compare
mellowcroc
force-pushed
the
audit/ed25519-key-validation
branch
from
August 14, 2026 06:01
dbbfb84 to
4932d2b
Compare
mellowcroc
force-pushed
the
harden/untrusted-decode-dos
branch
from
August 14, 2026 06:01
56f410e to
d29a4bc
Compare
mellowcroc
force-pushed
the
harden/untrusted-decode-dos
branch
from
August 14, 2026 06:23
d29a4bc to
c92f9d2
Compare
KeySource.open decodes the G1 singletons (alpha, beta, delta) and the G2 singletons (beta, delta) with NoSubgroupChecks. Skipping the subgroup check is a deliberate throughput trade on a proving key that callers are expected to digest-authenticate first, and internal/msmengine makes the same trade. The difference is that msmengine still runs IsOnCurve on every decoded point, and streampk ran no validation at all. That gap matters because OpenKeyURL reaches this code over HTTP range requests, and the URL caller in cmd/wasm-prover does not digest the proving key before opening it. A point that parses but is not on the curve therefore entered a multi-scalar multiplication unchallenged. IsOnCurve is cheap relative to the decode and is now applied to all five singletons. This does not close the missing digest verification on the URL path, which needs a separate change.
Four consumer paths decoded ceremony-derived artifacts before checking the length/count fields that drive allocation, letting a hostile or corrupt input exhaust memory or panic (unrecoverable throw on the native verifier, module abort on wasm): - prover.UnmarshalProof: preflight the BSB22 commitment-count prefix and the exact encoded length before gnark-crypto runs make([]G1Affine, count). Closes a remote unauthenticated OOM on the verifier HTTP API. - wasm-prover fetchCCS: bound the decoded CCS to its signed size, cap the zstd decoder window, and recover() the decode so a hostile length prefix errors instead of aborting the module. - proofassets.ValidatePKIndexAllocations: bound NbWires, NbInfinityA/B, and NbCommitmentKeys against the signed FileSize and section geometry. Applied on the full-index paths (ReadPKIndex, streampk.ValidateIndex); the manifest digest covers only geometry, so the counters were otherwise free. - streampk domain decode: validate the FFT cardinality is canonical before precomputing twiddles, so a hostile 2^32 cardinality is rejected before the ~274 GB allocation. Adds regression tests for the proof and PK-index paths.
mellowcroc
force-pushed
the
harden/untrusted-decode-dos
branch
from
August 14, 2026 06:26
c92f9d2 to
e9743f5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four consumer paths decoded ceremony-derived artifacts before checking the
length/count fields that drive allocation, letting a hostile or corrupt input
exhaust memory or panic — an unrecoverable
throwon the native verifier, amodule abort on wasm.
prover.UnmarshalProof— preflight the BSB22 commitment-count prefix andthe exact encoded length before gnark-crypto runs
make([]G1Affine, count).Closes a remote, unauthenticated OOM on the verifier HTTP API (a ~200-byte
body with a
0xFFFFFFFFcount requested ~412 GB).wasm-prover
fetchCCS— bound the decoded CCS to its signed size(
io.LimitReader), cap the zstd decoder window (WithDecoderMaxMemory, was64 GiB default), and
recover()the decode so a hostile length prefix errorsinstead of aborting the module.
proofassets.ValidatePKIndexAllocations— boundNbWires,NbInfinityA/B, andNbCommitmentKeysagainst the signedFileSizeandsection geometry. Applied on the full-index paths (
ReadPKIndex,streampk.ValidateIndex); the manifest digest covers only geometry, so thecounters were otherwise free.
streampk domain decode — validate the FFT cardinality is canonical
(power-of-two with a real generator, bounding it to the field's 2-adicity)
before precomputing twiddles, so a hostile
2^32cardinality is rejectedbefore the ~274 GB allocation.
Reject untrimmed whitespace in attested string fields —
ContributionEnvironment.OS/.Architectureand audit findings used a plain== ""check, so a single space satisfied "must not be empty". Requires thetrimmed, non-empty form, matching
Identity.DisplayNameand artifact names.(Moved here from PR Audit hardening: Ed25519 key validation and input-validation fixes #1 during a history rewrite; it was never part of the
audit series.)
Keep on-curve validation when skipping subgroup checks —
KeySource.opendecodes the G1 and G2 singletons with
NoSubgroupChecks. Skipping the subgroupcheck is a deliberate throughput trade on a proving key callers are expected to
digest-authenticate first, and
internal/msmenginemakes the same trade — butmsmengine still runs
IsOnCurveon every decoded point andstreampkran novalidation at all.
OpenKeyURLreaches this code over HTTP range requests, andthe URL caller in
cmd/wasm-proverdoes not digest the proving key beforeopening it, so a point that parsed but was not on the curve entered a
multi-scalar multiplication unchallenged. This does not close that missing
digest verification, which needs a separate change.
Adds regression tests for the proof and PK-index paths.
Independent of #1: the two PRs now touch no files in common. #1 is ceremony code
(
internal/mpcceremony,cmd/mpc-ceremony, docs); this PR is the proving andartifact-decode surface. They can land in either order.