forked from yetanotherco/aligned_layer
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmina.go
More file actions
44 lines (35 loc) · 1.09 KB
/
mina.go
File metadata and controls
44 lines (35 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package mina
/*
#cgo darwin LDFLAGS: -L./lib -lmina_state_verifier_ffi
#cgo linux LDFLAGS: ${SRCDIR}/lib/libmina_state_verifier_ffi.so -ldl -lrt -lm -lssl -lcrypto -Wl,--allow-multiple-definition
#include "lib/mina_verifier.h"
*/
import "C"
import (
"fmt"
"unsafe"
)
func VerifyMinaState(proofBuffer []byte, pubInputBuffer []byte) (isVerified bool, err error) {
// Here we define the return value on failure
isVerified = false
err = nil
if len(proofBuffer) == 0 || len(pubInputBuffer) == 0 {
return isVerified, err
}
// This will catch any go panic
defer func() {
rec := recover()
if rec != nil {
err = fmt.Errorf("Panic was caught while verifying sp1 proof: %s", rec)
}
}()
proofPtr := (*C.uchar)(unsafe.Pointer(&proofBuffer[0]))
pubInputPtr := (*C.uchar)(unsafe.Pointer(&pubInputBuffer[0]))
r := (C.int32_t)(C.verify_mina_state_ffi(proofPtr, (C.uint32_t)(len(proofBuffer)), pubInputPtr, (C.uint32_t)(len(pubInputBuffer))))
if r == -1 {
err = fmt.Errorf("Panic happened on FFI while verifying Mina proof")
return isVerified, err
}
isVerified = (r == 1)
return isVerified, err
}