Skip to content

bug: Custom builders don't construct deferred constraints #1638

@matthew-a-klein

Description

@matthew-a-klein

Description

Gnark allows for custom builders, allowing to build a constraint system without a circuit structure.
This inherits the frontend.API interface, allowing one to call deferred constraints such as with the lookup table interface.

Expected Behavior

When we call builder.Compile() we should construct the deferred constraints. Just like the Compile() function does for stnadard circuit construction. So if we constract a binary API, the constraints do not appear in the compiled constraint system.

Actual Behavior

All constraints attempted by the builder should be compiled in the constraint system.

Possible Fix

In the Compile function fo the r1cs and scs custom builders, we should call the equivalent of the callDeferred() function of the circuit Compile() function.

Steps to Reproduce

  1. Construct a new builder as follows builder, err := r1cs.NewBuilder[E](ecc.BN254.ScalarField(), frontend.CompileConfig{ CompressThreshold: 300, })
  2. Construct a binary field api as follows uapi, err := uints.New[uints.U64](builder)
  3. Now uapi.AssertEq(uints.NewU64(0), uints.NewU64(1)) will not fail, because the constraints are never called

Context

Attempting to write a custom gnark circuit without having to use the circuit struct as above.

Your Environment

  • gnark version used 0.14.0
  • gnark-crypto version used: 0.19.0
  • go version (e.g. 1.20.6): go1.24.4 darwin/arm64
  • Operating System and version: macOS Sequoia 15.6.1

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