feat(Bridge/Clean): FormalCircuit as ConstraintSystem + BehavioralContract - #466
feat(Bridge/Clean): FormalCircuit as ConstraintSystem + BehavioralContract#466XC0R wants to merge 4 commits into
Conversation
🤖 PR SummaryMathematical Formalization
Infrastructure
Proof Completion
Statistics
Lean Declarations ✏️ **Added:** 3 declaration(s)
🎨 **Style Guide Adherence**The code review identified several stylistic violations in
📄 **Per-File Summaries**
Last updated: 2026-05-09 10:13 UTC. |
…ralContract Introduces a small theory of constraint systems that unifies the indexed relations used across ArkLib (R1CS, Plonkish, lookups, memory checking, AIR, CCS, and DSL-level systems such as Clean's FormalCircuit). ArkLib/ProofSystem/ConstraintSystem/Basic.lean (new): - `ConstraintSystem` bundling Index, Stmt, OStmt, Wit, satisfies. - Smart constructors `ofRelation` (no oracle slot) and `ofWitnessFree`. - `ConstraintSystem.Hom` — completeness-preserving morphism with `index`, `stmt`, `oStmt`, `wit`, and `preserves`. Name follows Mathlib convention (RelHom, RingHom, LinearMap). - `Hom.id`, `Hom.comp`, and the category laws `id_comp`, `comp_id`, `comp_assoc` (all rfl). - `Hom.isSatisfiable_map` lifting satisfiability along a morphism. - `BehavioralContract` — per-index contract with `Assumptions`, `Spec`, soundness, and completeness, mirroring Clean's `FormalCircuit` pattern. ArkLib/ProofSystem/ConstraintSystem/Examples.lean (new): - `R1CS.toConstraintSystem` and `Plonk.toConstraintSystem` (+ `Plonk.Shape`) wiring the existing concrete relations into the universal abstraction, with `Iff.rfl` sanity lemmas. ArkLib/ProofSystem/ConstraintSystem/Plonk.lean: - `Plonk.ConstraintSystem` marked `protected` so bare `ConstraintSystem` inside namespace `Plonk` resolves to the universal one. Internal uses qualified to `Plonk.ConstraintSystem`. ArkLib.lean regenerated via scripts/update-lib.sh. Made-with: Cursor
…tract Bridge Clean's FormalCircuit to ArkLib's universal ConstraintSystem abstraction: - toConstraintSystem: wraps FormalCircuit with satisfies checking input consistency (eval env inputVar = inp) and constraint satisfaction (ConstraintsHold). - toBehavioralContract: transfers Clean's original_soundness and original_completeness into ArkLib's BehavioralContract interface. Zero sorrys. Targets upstream Verified-zkEVM/clean at 4a013fed.
0989c06 to
1451492
Compare
There was a problem hiding this comment.
Seems reasonable. I would only change the Stmt to include the output.
I wonder if the dependency shouldn't be the other way round - clean imports arklib. That would feel more natural, with clean being more like a frontend that will implement many concrete circuits, and arklib more like a backend
| def toConstraintSystem (circuit : FormalCircuit F Input Output) : | ||
| ConstraintSystem where | ||
| Index := Unit | ||
| Stmt := fun _ => Input F |
There was a problem hiding this comment.
I think better would be to make the statement an (Input F, Output F) pair
| satisfies := fun _ inp _ env => | ||
| eval env (canonicalInputVar Input F) = inp ∧ | ||
| ConstraintsHold env | ||
| (circuit.main (canonicalInputVar Input F) |>.operations 0) |
| (hWitGen : ∀ inp, circuit.Assumptions inp → ∃ env : Environment F, | ||
| eval env (canonicalInputVar Input F) = inp ∧ | ||
| env.UsesLocalWitnesses 0 | ||
| (circuit.main (canonicalInputVar Input F) |>.operations 0)) : |
There was a problem hiding this comment.
Ok so this assumption is kinda expected because FormalCircuits don't guarantee this. But we do have established a way to prove this quite easily for any given circuit, so the assumption could actually be removed with some massaging of the framework
Output moves from PUnit placeholder to OStmt (oracle/committed statement). The prover commits to an output value; satisfies checks input encoding, circuit constraints, and output consistency. Completeness existentially quantifies over the committed output.
XC0R
left a comment
There was a problem hiding this comment.
Output now in OStmt (0a71a4a). Stmt rather than OStmt would force the verifier to fix the output value; completeness could not existentially quantify over it.
On dependency direction: clean → arklib is neat long-term. Current direction avoids adding a dependency to Clean's lakefile without maintainer agreement. The bridge is ~100 lines either way.
hWitGen is addressable on the XC0R/clean fork toolchain-bump-v4.29 branch (~40+ commits, ~80+ files of v4.29 migration; core framework builds, handful of application circuits remaining). Upstream Clean has ~60+ new commits since the pinned rev, including the ProverHint refactor (PR #359) which restructures Environment and witness generation; relevant to this surface.
I'm the maintainer of Clean, and I agree with the ArkLib dependency. @quangvdao wdyt about the direction? |
|
Does this mean Clean will depend on ArkLib or the other way around? I have no strong opinion either way |
|
Clean → ArkLib is the sound dependency direction. ArkLib provides the generic ConstraintSystem / BehavioralContract interface (#465); Clean instantiates it for FormalCircuit. Concretely: ArkLib/Bridge/Clean.lean moves to Clean/ArkLib/Bridge.lean (or similar), Clean adds ArkLib as a lake dependency, and ArkLib stays constraint-system-agnostic. The bridge is ~100 lines either way; the difference is which repo carries the specificity. This also means #465 can merge independently. It defines the target interface. The Clean-side instantiation lands separately. |
|
Re: dependency direction, I think it's fine either way and either direction does not necessarily preclude the other. I think for the purpose of ArkLib being a backend for Clean then Clean adding an ArkLib dependency makes more sense, but in ArkLib we might also benefit from having a circuit format which we can use to reason about recursion in a way that concretely ties in to what frontends do. |
|
G109 LANDED locally and kernel-checks: _G109ActualDepthTwoNonnegative.lean. This completes G108's plumbing on the actual maximal-cancellation fibers. For negation-closed, zero-free G in an odd-characteristic finite field, if n = #G >= 4 and q = #F >= n^3, Lean proves: Equivalently, allPairsDepthFiber G 2 2 <= q * depthFiber G 2 2. Ingredients are all actual APIs: the 3n^2-3n additive-energy floor, rEnergy G 2 = additiveEnergy G, exact depth partition, G97's D0 <= 2n^2, G104's D1 = 0, and P2 <= n^4. Axiom audit: propext only; no sorry. Interpretation: depth 2 is a genuine nonnegative producer throughout the prize regime, despite G107's sharp two-point negative countermodel. This does NOT close delta-star; higher-depth signed balance remains the obstruction. |
|
G114-G117 shifted-slice chain kernel-checks and closes the structural depth-five weld. Verified chain:
Thus the former refuted constant-21 cubic gate is replaced by a 177-times looser constant 3728. The structural slicing step has no analytic hypothesis. All headline declarations audit to propext only; no sorry. Remaining honest obstruction: prove or refute the relaxed production cubic-energy estimate, then assemble the remaining signed depths. |
|
G118 kernel-checks: RepThree is sufficient to close the exact production primitive depth-five budget. The existing canonical residual gives E3(G) <= 15|G|^3. Composing it with G117's shifted-slice chain immediately supplies the relaxed E3(G) <= 3728|G|^3 input and hence the |G|^8/288000 primitive-core target at |G|=2^30. So the depth-five lane has no independent cubic-energy residual: it is closed with a 3728/15 slack factor once RepThree transfers to characteristic p. The honest remaining issue is exactly that order-six transfer (or a weaker bound allowing controlled non-pairing relation classes). G118 audits to propext only; no sorry. |
|
G119 kernel-checks and strictly weakens the depth-five analytic residual. RepThree is not necessary. If the finite-field third energy is at most the characteristic-zero closed form plus C*n^2, with C <= 44, then round 53 absorbs the entire surplus into Wick headroom, yielding E3 <= 15n^3. Composed with G117, this proves the exact production primitive depth-five budget at n=2^30. This route permits non-pairing six-term relations; it asks only for the aggregate bound: Thus a single RepThree counterexample does not kill depth five. The new live target is a quadratic total wraparound surplus, not exact relation exclusion. Axiom audit: propext only; no sorry. |
|
G194 published: depth-three Möbius transform ( The new frontier file proves the exact pointwise identity
where Interpretation: the depth-three defect is not merely a positive union bound. The positive all-three overlap enters with coefficient
That polarization theorem is not claimed in G194; it is the next algebraic bridge needed before deciding whether the signed overlap is exploitable or another obstruction. Validation passed:
|
|
G195 published: exact centered depth-three Möbius polarization ( New axiom-clean results:
This is quantitatively nontrivial on G193's genuine subgroup Validation:
Next angle: formalize the F₇ numerical Möbius certificate, then determine whether |
|
G196 published: explicit F₇ Möbius cancellation certificate ( For the genuine order-three subgroup
So triple overlap cancels over 68% of the naïve unsigned Möbius envelope in this actual subgroup. This gives a checked regression benchmark for any proposed general pair/triple correlation theorem. Validation passed: focused proximity iteration, generated import update, and serialized module build (8,460 jobs). All printed targets use only Next: probe the sign of |
|
G197 published: universal depth-three Möbius overlap sign REFUTED ( For the genuine full multiplicative subgroup
Equivalently, the subgroup incidence count is Thus the overlap term can either cancel (G196/F₇: −180) or amplify (G197/F₅: +48). Any all-subgroup deletion argument based only on Validation passed: focused proximity check and serialized module build (8,461 jobs); printed targets use only Next viable refinement: derive the exact incidence-count normal form |
|
G198 published: exact depth-three Möbius incidence normal form ( Lean now parameterizes the canonical pair collision by
Consequences formalized:
This replaces the false qualitative sign target with a precise incidence-discrepancy magnitude target. For prime fields with Validation passed: focused proximity check and serialized build (8,462 jobs). All printed declarations use only Next analytic question: bound |
|
G199 published: multiplicative normalization of the depth-three Möbius incidence ( For any finite nonzero multiplicatively closed/inverse-closed
This is the sharpest coordinate reduction in the G194–G199 chain: a three-variable signed overlap has become one affine intersection of two multiplicative cosets. Important applicability audit: the current G103F Stepanov theorem controls Validation passed: focused proximity check and serialized build (8,463 jobs); printed targets use only |
|
G200 published: coefficient-absorption bridge to the existing Stepanov theorem ( New exact result: if a nonzero multiplicative subgroup-like
with the standard shifted collision set
Over
Applicability is explicitly fenced. The genuine order-three subgroup Validation passed: focused proximity check and serialized build (8,464 jobs); targets use only |
|
G201 published: common-envelope Stepanov reduction ( For arbitrary coefficient cosets, choose
Consequently, if
The result is also composed all the way back to the signed overlap:
This is fully general at the combinatorial level; the exact analytic cost is that Validation passed: focused proximity check and serialized build (8,465 jobs); targets use only |
|
G202 published: common-envelope exponent overhead is genuine ( Generic necessary condition now proved: if Concrete certified obstruction:
So the coefficient-generated common envelope cannot uniformly preserve the smooth subgroup scale. The envelope workaround can incur arithmetic enlargement before Stepanov is applied; a general prize argument cannot silently set Validation passed: focused proximity check and serialized build (8,466 jobs); printed results use only accepted axioms. Next surviving route: generalize the two-relation Stepanov construction directly to distinct cosets |
|
G203 published: scalar-twisted generators for direct two-coset Stepanov ( For distinct nonzero relation values Lean proves:
This removes the G202 envelope obstruction at the generator level while retaining exponent Validation passed: focused proximity check and serialized build (8,467 jobs); all printed declarations use accepted axioms only. |
|
G204 published: full two-coset Stepanov vanisher ( For arbitrary nonzero
Key correction discovered and formalized during assembly: the generators carry the scalar twist, but the coefficient-kernel conditions remain the original The envelope overhead from G202 is now eliminated at the vanisher level. Only the standard multiplicity-to-cardinality wrapper and Validation passed: focused proximity check and serialized build (8,468 jobs); all targets use accepted axioms only. |
Summary
toConstraintSystem: wrapsFormalCircuitas aConstraintSystemwith input consistency andConstraintsHoldsatisfactiontoBehavioralContract: transfersoriginal_soundnessandoriginal_completenessintoBehavioralContract(0 sorrys)Verified-zkEVM/cleanat4a013fed(clean#357)Supersedes #451. New file:
ArkLib/Bridge/Clean.lean.