mirror of
https://github.com/waku-org/nwaku.git
synced 2025-02-19 10:28:30 +00:00
deploy: 0c60e6537f0a3b60100907f87c24389e7694af90
This commit is contained in:
parent
6a5c602523
commit
d2059a04bb
@ -1 +1 @@
|
|||||||
1612859498
|
1612990301
|
50
tests/v2/test_rln_relay_wrappers.nim
Normal file
50
tests/v2/test_rln_relay_wrappers.nim
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
{.used.}
|
||||||
|
|
||||||
|
import
|
||||||
|
std/[unittest],
|
||||||
|
stew/byteutils,
|
||||||
|
chronicles,
|
||||||
|
../../waku/v2/protocol/waku_rln_relay/rln
|
||||||
|
|
||||||
|
suite "Waku rln relay":
|
||||||
|
test "rln lib: Keygen Nim Wrappers":
|
||||||
|
var
|
||||||
|
merkleDepth: csize_t = 32
|
||||||
|
# parameters.key contains the parameters related to the Poseidon hasher
|
||||||
|
# to generate this file, clone this repo https://github.com/kilic/rln
|
||||||
|
# and run the following command in the root directory of the cloned project
|
||||||
|
# cargo run --example export_test_keys
|
||||||
|
# the file is generated separately and copied here
|
||||||
|
parameters = readFile("waku/v2/protocol/waku_rln_relay/parameters.key")
|
||||||
|
pbytes = parameters.toBytes()
|
||||||
|
len : csize_t = uint(pbytes.len)
|
||||||
|
parametersBuffer = Buffer(`ptr`: unsafeAddr(pbytes[0]), len: len)
|
||||||
|
check:
|
||||||
|
# check the parameters.key is not empty
|
||||||
|
pbytes.len != 0
|
||||||
|
|
||||||
|
# ctx holds the information that is going to be used for the key generation
|
||||||
|
var
|
||||||
|
obj = RLNBn256()
|
||||||
|
objPtr = unsafeAddr(obj)
|
||||||
|
ctx = objPtr
|
||||||
|
let res = newCircuitFromParams(merkleDepth, unsafeAddr parametersBuffer, ctx)
|
||||||
|
check:
|
||||||
|
# check whether the circuit parameters are generated successfully
|
||||||
|
res == true
|
||||||
|
|
||||||
|
# keysBufferPtr will hold the generated key pairs i.e., secret and public keys
|
||||||
|
var
|
||||||
|
keysBufferPtr : Buffer
|
||||||
|
done = keyGen(ctx, keysBufferPtr)
|
||||||
|
check:
|
||||||
|
# check whether the keys are generated successfully
|
||||||
|
done == true
|
||||||
|
|
||||||
|
if done:
|
||||||
|
var generatedKeys = cast[ptr array[64, byte]](keysBufferPtr.`ptr`)[]
|
||||||
|
check:
|
||||||
|
# the public and secret keys together are 64 bytes
|
||||||
|
generatedKeys.len == 64
|
||||||
|
debug "generated keys: ", generatedKeys
|
||||||
|
|
0
tests/v2/test_rln_wrappers.nim
Normal file
0
tests/v2/test_rln_wrappers.nim
Normal file
@ -10,7 +10,7 @@ generated by GNU Autoconf 2.69. Invocation command line was
|
|||||||
## Platform. ##
|
## Platform. ##
|
||||||
## --------- ##
|
## --------- ##
|
||||||
|
|
||||||
hostname = fv-az183-280
|
hostname = fv-az174-680
|
||||||
uname -m = x86_64
|
uname -m = x86_64
|
||||||
uname -r = 5.4.0-1039-azure
|
uname -r = 5.4.0-1039-azure
|
||||||
uname -s = Linux
|
uname -s = Linux
|
||||||
@ -841,7 +841,7 @@ configure:12482: $? = 0
|
|||||||
configure:12482: result: yes
|
configure:12482: result: yes
|
||||||
configure:12499: checking for getexecname
|
configure:12499: checking for getexecname
|
||||||
configure:12499: gcc -o conftest -g -O3 -std=gnu11 -pipe -Wall -Wextra -fPIC conftest.c >&5
|
configure:12499: gcc -o conftest -g -O3 -std=gnu11 -pipe -Wall -Wextra -fPIC conftest.c >&5
|
||||||
/tmp/cccnUdu2.o: In function `main':
|
/tmp/ccEG0SS8.o: In function `main':
|
||||||
/home/runner/work/nim-waku/nim-waku/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/conftest.c:73: undefined reference to `getexecname'
|
/home/runner/work/nim-waku/nim-waku/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/conftest.c:73: undefined reference to `getexecname'
|
||||||
collect2: error: ld returned 1 exit status
|
collect2: error: ld returned 1 exit status
|
||||||
configure:12499: $? = 1
|
configure:12499: $? = 1
|
||||||
@ -1134,7 +1134,7 @@ generated by GNU Autoconf 2.69. Invocation command line was
|
|||||||
CONFIG_COMMANDS =
|
CONFIG_COMMANDS =
|
||||||
$ ./config.status
|
$ ./config.status
|
||||||
|
|
||||||
on fv-az183-280
|
on fv-az174-680
|
||||||
|
|
||||||
config.status:1150: creating Makefile
|
config.status:1150: creating Makefile
|
||||||
config.status:1150: creating backtrace-supported.h
|
config.status:1150: creating backtrace-supported.h
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
# libtool - Provide generalized library-building support services.
|
# libtool - Provide generalized library-building support services.
|
||||||
# Generated automatically by config.status (libbacktrace) version-unused
|
# Generated automatically by config.status (libbacktrace) version-unused
|
||||||
# Libtool was configured on host fv-az183-280:
|
# Libtool was configured on host fv-az174-680:
|
||||||
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
|
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
|
||||||
#
|
#
|
||||||
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
|
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
|
||||||
|
BIN
waku/v2/protocol/waku_rln_relay/parameters.key
Normal file
BIN
waku/v2/protocol/waku_rln_relay/parameters.key
Normal file
Binary file not shown.
68
waku/v2/protocol/waku_rln_relay/rln.nim
Normal file
68
waku/v2/protocol/waku_rln_relay/rln.nim
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
# this module contains the Nim wrappers for the rln library https://github.com/kilic/rln/blob/3bbec368a4adc68cd5f9bfae80b17e1bbb4ef373/src/ffi.rs
|
||||||
|
|
||||||
|
import stew/byteutils, os
|
||||||
|
from strutils import rsplit
|
||||||
|
|
||||||
|
template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
|
||||||
|
# librln.dylib is the binary executable of rln library (originally implemented in rust with an exposed C API)
|
||||||
|
# contains the key generation and other relevant functions
|
||||||
|
# to generate librln.dylib, clone this repo https://github.com/kilic/rln
|
||||||
|
# and run the following command in the root directory of the cloned project
|
||||||
|
# cargo build
|
||||||
|
# can find the .dylib file under the target/debug directory
|
||||||
|
# this file is already generated and copied here
|
||||||
|
const libName* = sourceDir / "librln.dylib" # TODO may need to load different libs based on OS
|
||||||
|
|
||||||
|
# Data types -----------------------------
|
||||||
|
|
||||||
|
# pub struct Buffer {
|
||||||
|
# pub ptr: *const u8,
|
||||||
|
# pub len: usize,
|
||||||
|
# }
|
||||||
|
|
||||||
|
type
|
||||||
|
Buffer* = object
|
||||||
|
`ptr`*: pointer
|
||||||
|
len*: csize_t
|
||||||
|
RLNBn256* = object
|
||||||
|
|
||||||
|
# Procedures ------------------------------
|
||||||
|
# all the following procedures are Nim wrappers for the functions defined in libName
|
||||||
|
{.push dynlib: libName.}
|
||||||
|
|
||||||
|
# pub extern "C" fn new_circuit_from_params(
|
||||||
|
# merkle_depth: usize,
|
||||||
|
# index: usize,
|
||||||
|
# parameters_buffer: *const Buffer,
|
||||||
|
# ctx: *mut *mut RLN<Bn256>,
|
||||||
|
# ) -> bool
|
||||||
|
proc newCircuitFromParams*(merkle_depth: csize_t, parameters_buffer: ptr Buffer, ctx: var ptr RLNBn256): bool{.importc: "new_circuit_from_params".}
|
||||||
|
|
||||||
|
# pub extern "C" fn key_gen(ctx: *const RLN<Bn256>, keypair_buffer: *mut Buffer) -> bool
|
||||||
|
proc keyGen*(ctx: ptr RLNBn256, keypair_buffer: var Buffer): bool {.importc: "key_gen".}
|
||||||
|
|
||||||
|
|
||||||
|
# pub extern "C" fn hash(
|
||||||
|
# ctx: *const RLN<Bn256>,
|
||||||
|
# inputs_buffer: *const Buffer,
|
||||||
|
# input_len: *const usize,
|
||||||
|
# output_buffer: *mut Buffer,
|
||||||
|
# ) -> bool
|
||||||
|
proc hash*(ctx: ptr RLNBn256, inputs_buffer:ptr Buffer, input_len: ptr csize_t, output_buffer: ptr Buffer ) {.importc: "hash".} #TODO not tested yet
|
||||||
|
|
||||||
|
# pub extern "C" fn verify(
|
||||||
|
# ctx: *const RLN<Bn256>,
|
||||||
|
# proof_buffer: *const Buffer,
|
||||||
|
# public_inputs_buffer: *const Buffer,
|
||||||
|
# result_ptr: *mut u32,
|
||||||
|
# ) -> bool
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# pub extern "C" fn generate_proof(
|
||||||
|
# ctx: *const RLN<Bn256>,
|
||||||
|
# input_buffer: *const Buffer,
|
||||||
|
# output_buffer: *mut Buffer,
|
||||||
|
# ) -> bool
|
||||||
|
|
||||||
|
{.pop.}
|
Loading…
x
Reference in New Issue
Block a user