Skip to content

Harden discriminant and proof bounds validation#331

Open
hoffmang9 wants to merge 2 commits intomainfrom
fix/discriminant-proof-bounds
Open

Harden discriminant and proof bounds validation#331
hoffmang9 wants to merge 2 commits intomainfrom
fix/discriminant-proof-bounds

Conversation

@hoffmang9
Copy link
Copy Markdown
Member

@hoffmang9 hoffmang9 commented Mar 6, 2026

Summary

  • add explicit runtime bounds checks for discriminant size and form serialization in verifier and BQFC paths, replacing assert-only assumptions on externally derived inputs
  • harden vdf_client session parsing for iteration header/body and stop ACK handling with deterministic error returns on malformed network data
  • align discriminant-size validation to BQFC_MAX_D_BITS and add DiscriminantBoundsRegressionTest coverage for oversized discriminant/serialization inputs

Test plan

  • cmake -S src -B build-security-check -DBUILD_PYTHON=OFF -DBUILD_CHIAVDFC=OFF -DBUILD_VDF_CLIENT=OFF -DBUILD_VDF_BENCH=OFF -DBUILD_VDF_TESTS=ON -DBUILD_HW_TOOLS=OFF
  • cmake --build build-security-check --target regression_unit_tests regression_io_tests
  • ctest --test-dir build-security-check --output-on-failure -R '^regression\.'
  • performance check (vdf_bench square 250000, 5 runs baseline vs patched): median delta ~ -0.1%
  • performance check (vdf_bench square_asm 250000, 5 runs baseline vs patched): median delta 0.0%

Made with Cursor


Note

Medium Risk
Touches proof verification and quadratic-form serialization boundaries; incorrect bounds could cause valid proofs to be rejected or trigger new error paths, but changes are primarily defensive input validation.

Overview
Hardens bounds checking for discriminants and form serialization. bqfc_* routines now reject invalid d_bits/oversized forms at runtime (replacing assert assumptions), with bqfc_export returning errors on insufficient buffers and bqfc_serialize/bqfc_get_compr_size validating sizes against BQFC_MAX_D_BITS/BQFC_FORM_SIZE.

Tightens verifier and discriminant-size validation. The verifier now enforces disc_size_bits and discriminant bit-length ranges before processing proofs, CreateDiscriminant aligns its max to BQFC_MAX_D_BITS, and new regression tests cover oversized discriminant bits plus BQFC serialize/deserialize rejection.

Improves network input parsing in vdf_client. Iteration header/body parsing now validates decimal digits, length, and uint64_t overflow, and STOP ACK handling now throws on malformed responses instead of relying on assert.

Written by Cursor Bugbot for commit 01b75c3. This will update automatically on new commits. Configure here.

Replace assert-style input assumptions with explicit runtime checks in verifier, vdf client parsing, and BQFC serialization paths, and add regression coverage for oversized discriminant and serialization inputs.

Made-with: Cursor
@hoffmang9
Copy link
Copy Markdown
Member Author

@cursor review

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Allow ReadIteration to accept a 00 size header and return 0 so session loops process stop inline instead of throwing and falling through exception handling.

Made-with: Cursor
@hoffmang9
Copy link
Copy Markdown
Member Author

Cursor didn't find anything when run again. I pushed the tools to make sure these didn't hit performance, and logically they do not.

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.

1 participant