Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Dynamic circuit namespace #17

Merged
merged 3 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extractor/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ type ExCircuit struct {
Gadgets []ExGadget
Code []App
Field ecc.ID
Name string
}

type CodeExtractor struct {
Expand Down
19 changes: 11 additions & 8 deletions extractor/lean_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ import (
"github.com/consensys/gnark/frontend/schema"
)

func ExportPrelude(field ecc.ID) string {
func ExportPrelude(circuit ExCircuit) string {
s := fmt.Sprintf(`import ProvenZk.Gates
import ProvenZk.VectorExtensions

namespace Circuit
namespace %s

def Order : ℕ := 0x%s
variable [Fact (Nat.Prime Order)]
abbrev F := ZMod Order`, field.ScalarField().Text(16))
abbrev F := ZMod Order`, circuit.Name, circuit.Field.ScalarField().Text(16))

return s
}

func ExportFooter() string {
s := `end Circuit`
return fmt.Sprintf("%s", s)
func ExportFooter(circuit ExCircuit) string {
s := fmt.Sprintf(`end %s`, circuit.Name)
return s
}

func ExportGadget(gadget ExGadget) string {
Expand All @@ -45,8 +45,8 @@ func ExportCircuit(circuit ExCircuit) string {
gadgets[i] = ExportGadget(gadget)
}
circ := fmt.Sprintf("def circuit %s: Prop :=\n%s", genArgs(circuit.Inputs), genCircuitBody(circuit))
prelude := ExportPrelude(circuit.Field)
footer := ExportFooter()
prelude := ExportPrelude(circuit)
footer := ExportFooter(circuit)
return fmt.Sprintf("%s\n\n%s\n\n%s\n\n%s", prelude, strings.Join(gadgets, "\n\n"), circ, footer)
}

Expand Down Expand Up @@ -171,11 +171,14 @@ func CircuitToLean(circuit abstractor.Circuit, field ecc.ID) (string, error) {
return "", err
}

name := reflect.TypeOf(circuit).Elem().Name()

extractorCircuit := ExCircuit{
Inputs: GetExArgs(circuit, schema.Fields),
Gadgets: api.Gadgets,
Code: api.Code,
Field: api.Field,
Name: name,
}
out := ExportCircuit(extractorCircuit)
return out, nil
Expand Down