Skip to content

Commit ab7bc2d

Browse files
committed
Bind Kimchi to operator
1 parent 5abb55d commit ab7bc2d

12 files changed

Lines changed: 1755 additions & 3 deletions

File tree

common/proving_systems.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ const (
1515
Halo2KZG
1616
Halo2IPA
1717
Risc0
18+
Mina
1819
)
1920

2021
func (t *ProvingSystemId) String() string {
21-
return [...]string{"GnarkPlonkBls12_381", "GnarkPlonkBn254", "Groth16Bn254", "SP1", "Halo2IPA"}[*t]
22+
return [...]string{"GnarkPlonkBls12_381", "GnarkPlonkBn254", "Groth16Bn254", "SP1", "Halo2IPA", "Mina"}[*t]
2223
}
2324

2425
func ProvingSystemIdFromString(provingSystem string) (ProvingSystemId, error) {
@@ -37,6 +38,8 @@ func ProvingSystemIdFromString(provingSystem string) (ProvingSystemId, error) {
3738
return Halo2IPA, nil
3839
case "Risc0":
3940
return Risc0, nil
41+
case "Mina":
42+
return Mina, nil
4043
}
4144

4245
return 0, fmt.Errorf("unknown proving system: %s", provingSystem)
@@ -58,6 +61,8 @@ func ProvingSystemIdToString(provingSystem ProvingSystemId) (string, error) {
5861
return "Halo2IPA", nil
5962
case Risc0:
6063
return "Risc0", nil
64+
case Mina:
65+
return "Mina", nil
6166
}
6267

6368
return "", fmt.Errorf("unknown proving system: %d", provingSystem)

operator/kimchi/kimchi.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package kimchi
2+
3+
/*
4+
#cgo darwin LDFLAGS: -L./lib -lkimchi_verifier
5+
#cgo linux LDFLAGS: -L./lib -lkimchi_verifier -ldl -lrt -lm
6+
7+
#include "lib/kimchi.h"
8+
*/
9+
import "C"
10+
import (
11+
"unsafe"
12+
)
13+
14+
const MAX_PROOF_SIZE = 10 * 1024
15+
const MAX_PUB_INPUT_SIZE = 3 * 1024 * 1024
16+
17+
func VerifyKimchiProof(proofBuffer [MAX_PROOF_SIZE]byte, proofLen uint, pubInputBuffer [MAX_PUB_INPUT_SIZE]byte, pubInputLen uint) bool {
18+
proofPtr := (*C.uchar)(unsafe.Pointer(&proofBuffer[0]))
19+
pubInputPtr := (*C.uchar)(unsafe.Pointer(&pubInputBuffer[0]))
20+
return (bool)(C.verify_kimchi_proof_ffi(proofPtr, (C.uint)(proofLen), pubInputPtr, (C.uint)(pubInputLen)))
21+
}

operator/kimchi/kimchi_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package kimchi_test
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"testing"
7+
8+
"github.com/yetanotherco/aligned_layer/operator/kimchi"
9+
)
10+
11+
func TestEcAddKimchiProofVerifies(t *testing.T) {
12+
fmt.Println(os.Getwd())
13+
proofFile, err := os.Open("lib/kimchi_ec_add.proof")
14+
if err != nil {
15+
t.Errorf("could not open kimchi proof file")
16+
}
17+
18+
proofBuffer := make([]byte, kimchi.MAX_PROOF_SIZE)
19+
proofLen, err := proofFile.Read(proofBuffer)
20+
if err != nil {
21+
t.Errorf("could not read bytes from kimchi proof file")
22+
}
23+
24+
pubInputFile, err := os.Open("lib/kimchi_verifier_index.bin")
25+
if err != nil {
26+
t.Errorf("could not open kimchi aggregated public input file")
27+
}
28+
pubInputBuffer := make([]byte, kimchi.MAX_PUB_INPUT_SIZE)
29+
pubInputLen, err := pubInputFile.Read(pubInputBuffer)
30+
if err != nil {
31+
t.Errorf("could not read bytes from kimchi aggregated public input")
32+
}
33+
34+
if !kimchi.VerifyKimchiProof(([kimchi.MAX_PROOF_SIZE]byte)(proofBuffer), uint(proofLen), ([kimchi.MAX_PUB_INPUT_SIZE]byte)(pubInputBuffer), uint(pubInputLen)) {
35+
t.Errorf("proof did not verify")
36+
}
37+
}

operator/kimchi/lib/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+

0 commit comments

Comments
 (0)