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: Added dynamic curve order in exported circuit #16

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -147,6 +147,7 @@ type ExCircuit struct {
Inputs []ExArg
Gadgets []ExGadget
Code []App
Field ecc.ID
}

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

func ExportPrelude() string {
// Order could be extracted from circuit curve
s := `import ProvenZk.Gates
func ExportPrelude(field ecc.ID) string {
s := fmt.Sprintf(`import ProvenZk.Gates
import ProvenZk.VectorExtensions

namespace Circuit

def Order : ℕ := 21888242871839275222246405745257275088548364400416034343698204186575808495617
def Order : ℕ := %s
Eagle941 marked this conversation as resolved.
Show resolved Hide resolved
variable [Fact (Nat.Prime Order)]
abbrev F := ZMod Order`
abbrev F := ZMod Order`, field.ScalarField())

return fmt.Sprintf("%s", s)
return s
}

func ExportFooter() string {
Expand All @@ -46,7 +45,7 @@ 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()
prelude := ExportPrelude(circuit.Field)
footer := ExportFooter()
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 @@ -176,6 +175,7 @@ func CircuitToLean(circuit abstractor.Circuit, field ecc.ID) (string, error) {
Inputs: GetExArgs(circuit, schema.Fields),
Gadgets: api.Gadgets,
Code: api.Code,
Field: api.Field,
}
out := ExportCircuit(extractorCircuit)
return out, nil
Expand Down