diff --git a/build.nims b/build.nims new file mode 100644 index 0000000..f866946 --- /dev/null +++ b/build.nims @@ -0,0 +1,4 @@ + +task genffi, "update the nim ffi bindings": + exec "cargo install --force nbindgen" + exec "nbindgen --crate codex-storage-proofs --output codex_proofs_ffi.nim" diff --git a/codex_proofs_ffi.nim b/codex_proofs_ffi.nim new file mode 100644 index 0000000..279a261 --- /dev/null +++ b/codex_proofs_ffi.nim @@ -0,0 +1,57 @@ +const EXT_ID_U256_BE* = 51 + +const EXT_ID_U256_LE* = 50 + + +type StorageProofs* {.incompleteStruct.} = object + +type Buffer* = object + data: ptr uint8 + len: uint + +type ProofCtx* = object + proof: Buffer + public_inputs: Buffer + +## # Safety +# +# Use on a valid pointer to ProofCtx or panics +proc free_proof_ctx*(ctx: ptr ProofCtx) {.importc: "free_proof_ctx".} + +## # Safety +# +# Use on a valid pointer to StorageProofs or panics +proc free_prover*(prover: ptr StorageProofs) {.importc: "free_prover".} + +## # Safety +# +# Construct a StorageProofs object +proc init*(r1cs: ptr (ptr Buffer), + wasm: ptr (ptr Buffer), + zkey: ptr (ptr Buffer)): (ptr StorageProofs) {.importc: "init".} + +## # Safety +# +# Use after constructing a StorageProofs object with init +proc prove*(prover_ptr: ptr StorageProofs, + chunks: ptr Buffer, + siblings: ptr Buffer, + hashes: ptr Buffer, + path: ptr int32, + path_len: uint, + pubkey: ptr Buffer, + root: ptr Buffer, + salt: ptr Buffer): (ptr ProofCtx) {.importc: "prove".} + +## # Safety +# +# Use after constructing a StorageProofs object with init +proc prove_mpack_ext*(prover_ptr: ptr StorageProofs, + args: ptr Buffer): (ptr ProofCtx) {.importc: "prove_mpack_ext".} + +## # Safety +# +# Should be called on a valid proof and public inputs previously generated by prove +proc verify*(prover_ptr: ptr StorageProofs, + proof: ptr Buffer, + public_inputs: ptr Buffer): bool {.importc: "verify".} diff --git a/codex_storage_proofs.nim b/codex_storage_proofs.nim index 623aed3..d8feef4 100644 --- a/codex_storage_proofs.nim +++ b/codex_storage_proofs.nim @@ -20,3 +20,5 @@ static: {.passl: "-lcodex_storage_proofs" & " -L" & libDir.} + +proc prove_mpack_ext() diff --git a/codex_storage_proofs.nimble b/codex_storage_proofs.nimble index abac065..97463cd 100644 --- a/codex_storage_proofs.nimble +++ b/codex_storage_proofs.nimble @@ -7,3 +7,5 @@ srcDir = "." # Dependencies requires "nim >= 1.6.14" + +include "build.nims" diff --git a/config.nims b/config.nims new file mode 100644 index 0000000..c266802 --- /dev/null +++ b/config.nims @@ -0,0 +1,2 @@ + +include "build.nims"