Skip to content

Commit

Permalink
feat: Added dynamic curve order in exported circuit (#16)
Browse files Browse the repository at this point in the history
* Added dynamic curve order in exported circuit

* Print order as hex
  • Loading branch information
Eagle941 authored Jul 20, 2023
1 parent 27502f8 commit 5265998
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
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 : ℕ := 0x%s
variable [Fact (Nat.Prime Order)]
abbrev F := ZMod Order`
abbrev F := ZMod Order`, field.ScalarField().Text(16))

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

0 comments on commit 5265998

Please sign in to comment.