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

Kimchi verifier #10

Draft
wants to merge 4 commits into
base: mina
Choose a base branch
from
Draft
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
49 changes: 49 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,34 @@ batcher_send_mina_burst:
--repetitions 15 \
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657

batcher_send_kimchi_task:
@echo "Sending Kimchi task to Batcher..."
@cd batcher/aligned/ && cargo run --release -- submit \
--proving_system Kimchi \
--proof test_files/kimchi/kimchi_ec_add.proof \
--public_input test_files/kimchi/empty_public_input.bin \
--vk test_files/kimchi/kimchi_verifier_index.bin \
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657

batcher_send_kimchi_task_bad:
@echo "Sending Kimchi task to Batcher..."
@cd batcher/aligned/ && cargo run --release -- submit \
--proving_system Kimchi \
--proof test_files/kimchi/kimchi_ec_add.proof \
--public_input test_files/kimchi/empty_public_input.bin \
--vk test_files/kimchi/bad_kimchi_verifier_index.bin \
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657

batcher_send_kimchi_burst:
@echo "Sending Kimchi task to Batcher..."
@cd batcher/aligned/ && cargo run --release -- submit \
--proving_system Kimchi \
--proof test_files/kimchi/kimchi_ec_add.proof \
--public_input test_files/kimchi/empty_public_input.bin \
--vk test_files/kimchi/kimchi_verifier_index.bin \
--repetitions 15 \
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657

__TASK_SENDERS__:
# TODO add a default proving system

Expand Down Expand Up @@ -709,6 +737,27 @@ test_mina_go_bindings_linux: build_mina_linux
@echo "Testing Mina Go bindings..."
go test ./operator/mina/... -v

__KIMCHI_FFI_:
build_kimchi_macos:
@cd operator/kimchi/lib && cargo build --release
@cp operator/kimchi/lib/target/release/libkimchi_verifier_ffi.dylib operator/kimchi/lib/libkimchi_verifier.dylib

build_kimchi_linux:
@cd operator/kimchi/lib && cargo build --release
@cp operator/kimchi/lib/target/release/libkimchi_verifier_ffi.so operator/kimchi/lib/libkimchi_verifier.so

test_kimchi_rust_ffi:
@echo "Testing Kimchi Rust FFI source code..."
@cd operator/kimchi/lib && cargo t --release

test_kimchi_go_bindings_macos: build_kimchi_macos
@echo "Testing Kimchi Go bindings..."
go test ./operator/kimchi/... -v

test_kimchi_go_bindings_linux: build_kimchi_linux
@echo "Testing Kimchi Go bindings..."
go test ./operator/kimchi/... -v

__BUILD_ALL_FFI__:

build_all_ffi: ## Build all FFIs
Expand Down
1 change: 1 addition & 0 deletions batcher/aligned-batcher-lib/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub enum ProvingSystemId {
Halo2IPA,
Risc0,
Mina,
Kimchi,
}

#[derive(Debug, Serialize, Deserialize, Default, Clone)]
Expand Down
4 changes: 4 additions & 0 deletions batcher/aligned-batcher/src/zk_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,9 @@ pub(crate) fn verify(verification_data: &VerificationData) -> bool {
// verifier. These checks are fast and if they aren't successful then the Pickles proof
// isn't valid.
}
ProvingSystemId::Kimchi => {
// TODO(gabrielbosio): add Kimchi checks
true
}
}
}
6 changes: 5 additions & 1 deletion batcher/aligned/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ pub enum ProvingSystemArg {
Risc0,
#[clap(name = "Mina")]
Mina,
#[clap(name = "Kimchi")]
Kimchi,
}

impl From<ProvingSystemArg> for ProvingSystemId {
Expand All @@ -162,6 +164,7 @@ impl From<ProvingSystemArg> for ProvingSystemId {
ProvingSystemArg::Halo2IPA => ProvingSystemId::Halo2IPA,
ProvingSystemArg::Risc0 => ProvingSystemId::Risc0,
ProvingSystemArg::Mina => ProvingSystemId::Mina,
ProvingSystemArg::Kimchi => ProvingSystemId::Kimchi,
}
}
}
Expand Down Expand Up @@ -380,7 +383,8 @@ fn verification_data_from_args(args: SubmitArgs) -> Result<VerificationData, Bat
| ProvingSystemId::Halo2IPA
| ProvingSystemId::GnarkPlonkBls12_381
| ProvingSystemId::GnarkPlonkBn254
| ProvingSystemId::Groth16Bn254 => {
| ProvingSystemId::Groth16Bn254
| ProvingSystemId::Kimchi => {
verification_key = Some(read_file_option("--vk", args.verification_key_file_name)?);
pub_input = Some(read_file_option(
"--public_input",
Expand Down
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
7 changes: 6 additions & 1 deletion common/proving_systems.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ const (
Halo2IPA
Risc0
Mina
Kimchi
)

func (t *ProvingSystemId) String() string {
return [...]string{"GnarkPlonkBls12_381", "GnarkPlonkBn254", "Groth16Bn254", "SP1", "Halo2IPA", "Mina"}[*t]
return [...]string{"GnarkPlonkBls12_381", "GnarkPlonkBn254", "Groth16Bn254", "SP1", "Halo2IPA", "Mina", "Kimchi"}[*t]
}

func ProvingSystemIdFromString(provingSystem string) (ProvingSystemId, error) {
Expand All @@ -40,6 +41,8 @@ func ProvingSystemIdFromString(provingSystem string) (ProvingSystemId, error) {
return Risc0, nil
case "Mina":
return Mina, nil
case "Kimchi":
return Kimchi, nil
}

return 0, fmt.Errorf("unknown proving system: %s", provingSystem)
Expand All @@ -63,6 +66,8 @@ func ProvingSystemIdToString(provingSystem ProvingSystemId) (string, error) {
return "Risc0", nil
case Mina:
return "Mina", nil
case Kimchi:
return "Kimchi", nil
}

return "", fmt.Errorf("unknown proving system: %d", provingSystem)
Expand Down
24 changes: 24 additions & 0 deletions operator/kimchi/kimchi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package kimchi

/*
#cgo darwin LDFLAGS: -L./lib -lkimchi_verifier
#cgo linux LDFLAGS: -L./lib -lkimchi_verifier -ldl -lrt -lm

#include "lib/kimchi.h"
*/
import "C"
import (
"unsafe"
)

// TODO(xqft): check proof size
const MAX_PROOF_SIZE = 16 * 1024
const MAX_PUB_INPUT_SIZE = 50 * 1024
const MAX_VERIFIER_INDEX_SIZE = 50 * 1024

func VerifyKimchiProof(proofBuffer [MAX_PROOF_SIZE]byte, proofLen uint, pubInputBuffer [MAX_PUB_INPUT_SIZE]byte, pubInputLen uint, verifierIndexBuffer [MAX_VERIFIER_INDEX_SIZE]byte, verifierIndexLen uint) bool {
proofPtr := (*C.uchar)(unsafe.Pointer(&proofBuffer[0]))
pubInputPtr := (*C.uchar)(unsafe.Pointer(&pubInputBuffer[0]))
verifierIndexPtr := (*C.uchar)(unsafe.Pointer(&verifierIndexBuffer[0]))
return (bool)(C.verify_kimchi_proof_ffi(proofPtr, (C.uint)(proofLen), pubInputPtr, (C.uint)(pubInputLen), verifierIndexPtr, (C.uint)(verifierIndexLen)))
}
40 changes: 40 additions & 0 deletions operator/kimchi/kimchi_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package kimchi_test

import (
"fmt"
"os"
"testing"

"github.com/yetanotherco/aligned_layer/operator/kimchi"
)

func TestEcAddKimchiProofVerifies(t *testing.T) {
fmt.Println(os.Getwd())
proofFile, err := os.Open("lib/kimchi_ec_add.proof")
if err != nil {
t.Errorf("could not open kimchi proof file")
}

proofBuffer := make([]byte, kimchi.MAX_PROOF_SIZE)
proofLen, err := proofFile.Read(proofBuffer)
if err != nil {
t.Errorf("could not read bytes from kimchi proof file")
}

pubInputBuffer := make([]byte, kimchi.MAX_PUB_INPUT_SIZE)
pubInputLen := 0

verifierIndexFile, err := os.Open("lib/kimchi_verifier_index.bin")
if err != nil {
t.Errorf("could not open kimchi aggregated public input file")
}
verifierIndexBuffer := make([]byte, kimchi.MAX_VERIFIER_INDEX_SIZE)
verifierIndexLen, err := verifierIndexFile.Read(verifierIndexBuffer)
if err != nil {
t.Errorf("could not read bytes from kimchi aggregated verifier index")
}

if !kimchi.VerifyKimchiProof(([kimchi.MAX_PROOF_SIZE]byte)(proofBuffer), uint(proofLen), ([kimchi.MAX_PUB_INPUT_SIZE]byte)(pubInputBuffer), uint(pubInputLen), ([kimchi.MAX_PUB_INPUT_SIZE]byte)(verifierIndexBuffer), uint(verifierIndexLen)) {
t.Errorf("proof did not verify")
}
}
5 changes: 5 additions & 0 deletions operator/kimchi/lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/target

libkimchi_verifier.so
libkimchi_verifier.a
libkimchi_verifier.dylib
Loading