Skip to content

bindings/go: reject negative randBits in PairingMulNAggregate - #295

Closed
arib06 wants to merge 1 commit into
supranational:masterfrom
arib06:go-randbits-negative-guard
Closed

arib06 wants to merge 1 commit into
supranational:masterfrom
arib06:go-randbits-negative-guard

Conversation

@arib06

@arib06 arib06 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

PairingMulNAggregatePkInG1 and PairingMulNAggregatePkInG2 reject randBits > 256 but not negative values. randBits is a signed int handed to C as C.size_t(randBits), so a negative value such as -1 wraps to SIZE_MAX, slips past the signed > 256 comparison, and reaches blst_pairing_chk_n_mul_n_aggr_pk_in_g{1,2} and in turn POINTonE{1,2}_mult_w5. That routine reads the scalar at byte offset about (nbits-1)/8, far past the 32-byte rand Scalar, an out-of-bounds read. The other nbits entry points in the binding already reject non-positive values (MultAssign, MultNAccumulate, P1AffinesMult/P2AffinesMult), so these two were the odd ones out. The fix adds randBits < 0 to the existing guard in the blst_px.tgo template and regenerates blst.go, covering both the PkInG1 and PkInG2 forms.

Added a regression test that calls both functions with randBits = -1. It fails on master, where the call falls through the guard, and passes with the fix, which panics with the existing "scalar length mismatch" message. go test in bindings/go stays green.

PairingMulNAggregatePkInG1/G2 rejected randBits > 256 but not negative
values. randBits is a signed int passed to C as C.size_t(randBits), so a
negative value wraps to a huge size_t that slips past the signed compare
and reaches POINTonE{1,2}_mult_w5, which then reads past the 32-byte rand
scalar. Extend the guard to reject randBits < 0, matching the <= 0 checks
the other Go nbits entry points already use.
@dot-asm dot-asm closed this in e22749f Oct 14, 2026
@dot-asm

dot-asm commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

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