Skip to content

Refactor WitnessBuilder enum into a trait-based extensible architecture #334

@ocdbytes

Description

@ocdbytes

Problem

WitnessBuilder is a monolithic enum (currently 30+ variants) where adding a single new variant requires synchronized changes across 4 files:

  1. Enum definition — provekit/common/src/witness/witness_builder.rs (variant + num_witnesses)
  2. Solver — provekit/prover/src/witness/witness_builder.rs (witness value computation)
  3. Dependency analysis — provekit/common/src/witness/scheduling/dependency.rs (extract_reads / extract_writes)
  4. Index remapping — provekit/common/src/witness/scheduling/remapper.rs (remap_builder)

The MSM black-box optimization PR added 10+ new variants (NonNativeEcHint, FakeGLVHint, EcScalarMulHint, SelectWitness, BooleanOr, SignedBitHint,
MultiLimbAddQuotient, MultiLimbSubBorrow, MultiLimbMulModHint, MultiLimbModularInverse, EcDoubleHint, EcAddHint), each requiring all 4 match arms. This is
a pre-existing pattern, but the MSM work significantly exacerbated the maintenance burden — the enum now has ~87 match arms in dependency.rs and ~83 in
remapper.rs.

Key pain points:

  • Every new operation touches shared infrastructure files — high merge-conflict risk across teams
  • Exhaustive match in 4 files means one forgotten arm = compile error, but the fix is pure boilerplate
  • No encapsulation: MSM-specific operations live in common/, visible to all consumers
  • num_witnesses() is already a ~30-line match that will only grow

Ref: #310 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions