logos-storage-proofs/codex_storage_proofs.nim

59 lines
1.5 KiB
Nim
Raw Normal View History

import std/os
2023-12-22 18:24:12 -07:00
import std/strutils
import std/macros
2023-12-22 18:07:17 -07:00
const
currentDir = currentSourcePath().parentDir()
2023-12-22 18:45:26 -07:00
libDir* = currentDir/"target"/"release"
libPath* = libDir/"libcodex_storage_proofs.a"
2023-12-22 18:07:17 -07:00
static:
2023-12-22 18:24:12 -07:00
let cmd = "cargo build --release"
2023-12-22 18:28:15 -07:00
warning "\nBuilding codex-storage-proofs: " & cmd
2023-12-22 18:07:17 -07:00
let (output, exitCode) = gorgeEx cmd
2023-12-22 18:24:12 -07:00
for ln in output.splitLines():
2023-12-22 18:28:15 -07:00
warning("cargo> " & ln)
2023-12-22 18:07:17 -07:00
if exitCode != 0:
raise (ref Defect)(msg: "Failed to build codex-storage-proofs")
2023-12-22 18:45:26 -07:00
{.passl: "-lcodex_storage_proofs" & " -L" & libDir.}
2023-12-22 19:03:43 -07:00
2023-12-22 19:40:03 -07:00
include codex_proofs_ffi
2023-12-22 19:45:17 -07:00
template unsafeBufferPath*(path: var string): Buffer =
2023-12-22 19:40:03 -07:00
assert path.len() > 0
2023-12-22 19:45:17 -07:00
Buffer(data: cast[ptr uint8](path.cstring),
len: path.len().uint)
template unsafeBufferFromFile*(path: string): Buffer =
assert path.len() > 0
let entireFile = readFile(path)
Buffer(data: cast[ptr uint8](entireFile.cstring),
len: entireFile.len().uint)
2023-12-22 19:05:31 -07:00
when isMainModule:
2023-12-22 19:40:03 -07:00
var
r1cs_path = "src/circuit_tests/artifacts/storer-test.r1cs"
wasm_path = "src/circuit_tests/artifacts/storer-test_js/storer-test.wasm"
2023-12-22 19:45:17 -07:00
2023-12-22 19:40:03 -07:00
let
r1cs_buff = unsafeBufferPath(r1cs_path)
wasm_buff = unsafeBufferPath(wasm_path)
let storage_ctx = init_storage_proofs(r1cs_buff, wasm_buff, nil)
echo "storage_ctx: ", storage_ctx.repr
assert storage_ctx != nil
2023-12-22 19:47:09 -07:00
var
2023-12-22 19:45:17 -07:00
mpack_arg_path = "test/proof_test.mpack"
2023-12-22 19:47:09 -07:00
proofBuff = unsafeBufferFromFile(mpack_arg_path)
echo "proofArgs:size: ", proofBuff.len
let res = prove_mpack_ext(storage_ctx, addr proofBuff)
echo "result: ", res.repr