diff --git a/.update.timestamp b/.update.timestamp index 0d10fbea9..a2b1498e9 100644 --- a/.update.timestamp +++ b/.update.timestamp @@ -1 +1 @@ -1612859498 \ No newline at end of file +1612990301 \ No newline at end of file diff --git a/tests/v2/test_rln_relay_wrappers.nim b/tests/v2/test_rln_relay_wrappers.nim new file mode 100644 index 000000000..66be7e8c3 --- /dev/null +++ b/tests/v2/test_rln_relay_wrappers.nim @@ -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 + diff --git a/tests/v2/test_rln_wrappers.nim b/tests/v2/test_rln_wrappers.nim new file mode 100644 index 000000000..e69de29bb diff --git a/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/config.log b/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/config.log index d5e556852..0a6e8e026 100644 --- a/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/config.log +++ b/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/config.log @@ -10,7 +10,7 @@ generated by GNU Autoconf 2.69. Invocation command line was ## Platform. ## ## --------- ## -hostname = fv-az183-280 +hostname = fv-az174-680 uname -m = x86_64 uname -r = 5.4.0-1039-azure uname -s = Linux @@ -841,7 +841,7 @@ configure:12482: $? = 0 configure:12482: result: yes configure:12499: checking for getexecname 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' collect2: error: ld returned 1 exit status configure:12499: $? = 1 @@ -1134,7 +1134,7 @@ generated by GNU Autoconf 2.69. Invocation command line was CONFIG_COMMANDS = $ ./config.status -on fv-az183-280 +on fv-az174-680 config.status:1150: creating Makefile config.status:1150: creating backtrace-supported.h diff --git a/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool b/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool index 0e26537d8..4e4f29d13 100755 --- a/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool +++ b/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool @@ -2,7 +2,7 @@ # libtool - Provide generalized library-building support services. # 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. # # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, diff --git a/waku/v2/protocol/waku_rln_relay/parameters.key b/waku/v2/protocol/waku_rln_relay/parameters.key new file mode 100644 index 000000000..8691479c3 Binary files /dev/null and b/waku/v2/protocol/waku_rln_relay/parameters.key differ diff --git a/waku/v2/protocol/waku_rln_relay/rln.nim b/waku/v2/protocol/waku_rln_relay/rln.nim new file mode 100644 index 000000000..355d15dbe --- /dev/null +++ b/waku/v2/protocol/waku_rln_relay/rln.nim @@ -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, +# ) -> 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, 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, +# 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, +# proof_buffer: *const Buffer, +# public_inputs_buffer: *const Buffer, +# result_ptr: *mut u32, +# ) -> bool + + + +# pub extern "C" fn generate_proof( +# ctx: *const RLN, +# input_buffer: *const Buffer, +# output_buffer: *mut Buffer, +# ) -> bool + +{.pop.} \ No newline at end of file