codex-storage-proofs/codex_proofs_ffi.nim

58 lines
1.5 KiB
Nim

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_storage_proofs*(r1cs: Buffer,
wasm: Buffer,
zkey: ptr Buffer): (ptr StorageProofs) {.importc: "init_storage_proofs".}
## # 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".}