Skip to content

Off-by-one circuit index validation allows heap OOB in prover and verifier #145

Description

@jilgolfo

In lib/proto/circuit.h, CircuitRep::from_bytes() has off-by-one bounds checks for quad gate and wire indices:

// `lib/proto/circuit.h:215` – comment says "index of quad must be < wires in the layer"
if (g > max_g) return nullptr;   // accepts g == max_g (one-past-end)

// `lib/proto/circuit.h:220`
if (hl > nw || hr > nw) return nullptr;  // accepts hl/hr == nw (one-past-end)

lib/proto/circuit.h:224 in the same function uses the correct >= pattern for an analogous constant-index check (if (vi >= numconst)), confirming the inconsistency.

These boundary values are later dereferenced without bounds checks.

A malformed circuit blob with a single quad index at the boundary value (g == max_g or h == nw) is sufficient to trigger OOB on prover evaluation, and can also trigger OOB on verifier-side EQ indexing.

Fix: Change > to >= in both checks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions