nwaku/waku/v2/protocol/waku_rln_relay/rln.nim

61 lines
2.4 KiB
Nim
Raw Normal View History

# this module contains the Nim wrappers for the rln library https://github.com/kilic/rln/blob/3bbec368a4adc68cd5f9bfae80b17e1bbb4ef373/src/ffi.rs
import
os,
waku_rln_relay_types
const libPath = "vendor/rln/target/debug/"
when defined(Windows):
const libName* = libPath / "rln.dll"
elif defined(Linux):
const libName* = libPath / "librln.so"
elif defined(MacOsX):
const libName* = libPath / "librln.dylib"
# all the following procedures are Nim wrappers for the functions defined in libName
Rln-relay zkp module Nim bindings (#427) * entirely replaces the prior rln header, the var variables are changed to ptr * updates the unittest of key_gen * adds test for update_next_member * updates membershipKeyGen internals and prototype * adds createRLNInstance * adds helpers methods * adds generateKeyPairBuffer * cleans up the test and adds comments * renames merkleTreeDepth to d * fixes a buf re decoding the keys into sk and pk * adds getSKPK proc * unifies key gen helper procs, adds todos * comments out the createRLNInstance * refactors the code based on the updated createRLNInstance interface * adds the test for the verify proc * fixes a variable name and replaces random key gen with the real key gen * tests a simple hash * adds get_root method * fixes the data pointer issue and adds the proof breakdown * adds rln * adds unit tests for Merkle tree * adds a sample hash test * fixes the hash bug and comments out unused part of proof gen test * cleans up the proof gent test * replaces unsafeAddr with addr * fixes an issue in key gen * updates rln submodule * fixes the verification problem * adds a failed test * replaces an old test scenario with a new one * handles createRLNInstance output * working createRLNInstance2 * refactors the code by replacing the old createRLNInstance * renames createRLNInstance2 * adds documentation and reorganizes rln.nim * replace echo with debug, renames vars, adds a bad proof test * minor * minor * edits var names * adds one more check * adds one more test to the hash * enforcing exception handling * adds pacman -Sy * removes update:true * activates update
2021-04-01 00:39:27 +00:00
{.push dynlib: libName, raises: [Defect].}
## Buffer struct is taken from
# https://github.com/celo-org/celo-threshold-bls-rs/blob/master/crates/threshold-bls-ffi/src/ffi.rs
type Buffer* = object
`ptr`*: ptr uint8
len*: uint
Rln-relay zkp module Nim bindings (#427) * entirely replaces the prior rln header, the var variables are changed to ptr * updates the unittest of key_gen * adds test for update_next_member * updates membershipKeyGen internals and prototype * adds createRLNInstance * adds helpers methods * adds generateKeyPairBuffer * cleans up the test and adds comments * renames merkleTreeDepth to d * fixes a buf re decoding the keys into sk and pk * adds getSKPK proc * unifies key gen helper procs, adds todos * comments out the createRLNInstance * refactors the code based on the updated createRLNInstance interface * adds the test for the verify proc * fixes a variable name and replaces random key gen with the real key gen * tests a simple hash * adds get_root method * fixes the data pointer issue and adds the proof breakdown * adds rln * adds unit tests for Merkle tree * adds a sample hash test * fixes the hash bug and comments out unused part of proof gen test * cleans up the proof gent test * replaces unsafeAddr with addr * fixes an issue in key gen * updates rln submodule * fixes the verification problem * adds a failed test * replaces an old test scenario with a new one * handles createRLNInstance output * working createRLNInstance2 * refactors the code by replacing the old createRLNInstance * renames createRLNInstance2 * adds documentation and reorganizes rln.nim * replace echo with debug, renames vars, adds a bad proof test * minor * minor * edits var names * adds one more check * adds one more test to the hash * enforcing exception handling * adds pacman -Sy * removes update:true * activates update
2021-04-01 00:39:27 +00:00
type Auth* = object
secret_buffer*: ptr Buffer
index*: uint
Rln-relay zkp module Nim bindings (#427) * entirely replaces the prior rln header, the var variables are changed to ptr * updates the unittest of key_gen * adds test for update_next_member * updates membershipKeyGen internals and prototype * adds createRLNInstance * adds helpers methods * adds generateKeyPairBuffer * cleans up the test and adds comments * renames merkleTreeDepth to d * fixes a buf re decoding the keys into sk and pk * adds getSKPK proc * unifies key gen helper procs, adds todos * comments out the createRLNInstance * refactors the code based on the updated createRLNInstance interface * adds the test for the verify proc * fixes a variable name and replaces random key gen with the real key gen * tests a simple hash * adds get_root method * fixes the data pointer issue and adds the proof breakdown * adds rln * adds unit tests for Merkle tree * adds a sample hash test * fixes the hash bug and comments out unused part of proof gen test * cleans up the proof gent test * replaces unsafeAddr with addr * fixes an issue in key gen * updates rln submodule * fixes the verification problem * adds a failed test * replaces an old test scenario with a new one * handles createRLNInstance output * working createRLNInstance2 * refactors the code by replacing the old createRLNInstance * renames createRLNInstance2 * adds documentation and reorganizes rln.nim * replace echo with debug, renames vars, adds a bad proof test * minor * minor * edits var names * adds one more check * adds one more test to the hash * enforcing exception handling * adds pacman -Sy * removes update:true * activates update
2021-04-01 00:39:27 +00:00
#------------------------------ Merkle Tree operations -----------------------------------------
proc update_next_member*(ctx: ptr RLN[Bn256],
input_buffer: ptr Buffer): bool {.importc: "update_next_member".}
proc delete_member*(ctx: ptr RLN[Bn256], index: uint): bool {.importc: "delete_member".}
proc get_root*(ctx: ptr RLN[Bn256], output_buffer: ptr Buffer): bool {.importc: "get_root".}
#----------------------------------------------------------------------------------------------
Rln-relay zkp module Nim bindings (#427) * entirely replaces the prior rln header, the var variables are changed to ptr * updates the unittest of key_gen * adds test for update_next_member * updates membershipKeyGen internals and prototype * adds createRLNInstance * adds helpers methods * adds generateKeyPairBuffer * cleans up the test and adds comments * renames merkleTreeDepth to d * fixes a buf re decoding the keys into sk and pk * adds getSKPK proc * unifies key gen helper procs, adds todos * comments out the createRLNInstance * refactors the code based on the updated createRLNInstance interface * adds the test for the verify proc * fixes a variable name and replaces random key gen with the real key gen * tests a simple hash * adds get_root method * fixes the data pointer issue and adds the proof breakdown * adds rln * adds unit tests for Merkle tree * adds a sample hash test * fixes the hash bug and comments out unused part of proof gen test * cleans up the proof gent test * replaces unsafeAddr with addr * fixes an issue in key gen * updates rln submodule * fixes the verification problem * adds a failed test * replaces an old test scenario with a new one * handles createRLNInstance output * working createRLNInstance2 * refactors the code by replacing the old createRLNInstance * renames createRLNInstance2 * adds documentation and reorganizes rln.nim * replace echo with debug, renames vars, adds a bad proof test * minor * minor * edits var names * adds one more check * adds one more test to the hash * enforcing exception handling * adds pacman -Sy * removes update:true * activates update
2021-04-01 00:39:27 +00:00
#-------------------------------- zkSNARKs operations -----------------------------------------
proc key_gen*(ctx: ptr RLN[Bn256], keypair_buffer: ptr Buffer): bool {.importc: "key_gen".}
proc generate_proof*(ctx: ptr RLN[Bn256],
input_buffer: ptr Buffer,
auth: ptr Auth,
output_buffer: ptr Buffer): bool {.importc: "generate_proof".}
Rln-relay zkp module Nim bindings (#427) * entirely replaces the prior rln header, the var variables are changed to ptr * updates the unittest of key_gen * adds test for update_next_member * updates membershipKeyGen internals and prototype * adds createRLNInstance * adds helpers methods * adds generateKeyPairBuffer * cleans up the test and adds comments * renames merkleTreeDepth to d * fixes a buf re decoding the keys into sk and pk * adds getSKPK proc * unifies key gen helper procs, adds todos * comments out the createRLNInstance * refactors the code based on the updated createRLNInstance interface * adds the test for the verify proc * fixes a variable name and replaces random key gen with the real key gen * tests a simple hash * adds get_root method * fixes the data pointer issue and adds the proof breakdown * adds rln * adds unit tests for Merkle tree * adds a sample hash test * fixes the hash bug and comments out unused part of proof gen test * cleans up the proof gent test * replaces unsafeAddr with addr * fixes an issue in key gen * updates rln submodule * fixes the verification problem * adds a failed test * replaces an old test scenario with a new one * handles createRLNInstance output * working createRLNInstance2 * refactors the code by replacing the old createRLNInstance * renames createRLNInstance2 * adds documentation and reorganizes rln.nim * replace echo with debug, renames vars, adds a bad proof test * minor * minor * edits var names * adds one more check * adds one more test to the hash * enforcing exception handling * adds pacman -Sy * removes update:true * activates update
2021-04-01 00:39:27 +00:00
proc verify*(ctx: ptr RLN[Bn256],
proof_buffer: ptr Buffer,
result_ptr: ptr uint32): bool {.importc: "verify".}
Rln-relay zkp module Nim bindings (#427) * entirely replaces the prior rln header, the var variables are changed to ptr * updates the unittest of key_gen * adds test for update_next_member * updates membershipKeyGen internals and prototype * adds createRLNInstance * adds helpers methods * adds generateKeyPairBuffer * cleans up the test and adds comments * renames merkleTreeDepth to d * fixes a buf re decoding the keys into sk and pk * adds getSKPK proc * unifies key gen helper procs, adds todos * comments out the createRLNInstance * refactors the code based on the updated createRLNInstance interface * adds the test for the verify proc * fixes a variable name and replaces random key gen with the real key gen * tests a simple hash * adds get_root method * fixes the data pointer issue and adds the proof breakdown * adds rln * adds unit tests for Merkle tree * adds a sample hash test * fixes the hash bug and comments out unused part of proof gen test * cleans up the proof gent test * replaces unsafeAddr with addr * fixes an issue in key gen * updates rln submodule * fixes the verification problem * adds a failed test * replaces an old test scenario with a new one * handles createRLNInstance output * working createRLNInstance2 * refactors the code by replacing the old createRLNInstance * renames createRLNInstance2 * adds documentation and reorganizes rln.nim * replace echo with debug, renames vars, adds a bad proof test * minor * minor * edits var names * adds one more check * adds one more test to the hash * enforcing exception handling * adds pacman -Sy * removes update:true * activates update
2021-04-01 00:39:27 +00:00
#----------------------------------------------------------------------------------------------
#-------------------------------- Common procedures -------------------------------------------
proc new_circuit_from_params*(merkle_depth: uint,
parameters_buffer: ptr Buffer,
ctx: ptr (ptr RLN[Bn256])): bool {.importc: "new_circuit_from_params".}
Rln-relay zkp module Nim bindings (#427) * entirely replaces the prior rln header, the var variables are changed to ptr * updates the unittest of key_gen * adds test for update_next_member * updates membershipKeyGen internals and prototype * adds createRLNInstance * adds helpers methods * adds generateKeyPairBuffer * cleans up the test and adds comments * renames merkleTreeDepth to d * fixes a buf re decoding the keys into sk and pk * adds getSKPK proc * unifies key gen helper procs, adds todos * comments out the createRLNInstance * refactors the code based on the updated createRLNInstance interface * adds the test for the verify proc * fixes a variable name and replaces random key gen with the real key gen * tests a simple hash * adds get_root method * fixes the data pointer issue and adds the proof breakdown * adds rln * adds unit tests for Merkle tree * adds a sample hash test * fixes the hash bug and comments out unused part of proof gen test * cleans up the proof gent test * replaces unsafeAddr with addr * fixes an issue in key gen * updates rln submodule * fixes the verification problem * adds a failed test * replaces an old test scenario with a new one * handles createRLNInstance output * working createRLNInstance2 * refactors the code by replacing the old createRLNInstance * renames createRLNInstance2 * adds documentation and reorganizes rln.nim * replace echo with debug, renames vars, adds a bad proof test * minor * minor * edits var names * adds one more check * adds one more test to the hash * enforcing exception handling * adds pacman -Sy * removes update:true * activates update
2021-04-01 00:39:27 +00:00
proc hash*(ctx: ptr RLN[Bn256],
inputs_buffer: ptr Buffer,
input_len: uint,
output_buffer: ptr Buffer): bool {.importc: "hash".}
Rln-relay zkp module Nim bindings (#427) * entirely replaces the prior rln header, the var variables are changed to ptr * updates the unittest of key_gen * adds test for update_next_member * updates membershipKeyGen internals and prototype * adds createRLNInstance * adds helpers methods * adds generateKeyPairBuffer * cleans up the test and adds comments * renames merkleTreeDepth to d * fixes a buf re decoding the keys into sk and pk * adds getSKPK proc * unifies key gen helper procs, adds todos * comments out the createRLNInstance * refactors the code based on the updated createRLNInstance interface * adds the test for the verify proc * fixes a variable name and replaces random key gen with the real key gen * tests a simple hash * adds get_root method * fixes the data pointer issue and adds the proof breakdown * adds rln * adds unit tests for Merkle tree * adds a sample hash test * fixes the hash bug and comments out unused part of proof gen test * cleans up the proof gent test * replaces unsafeAddr with addr * fixes an issue in key gen * updates rln submodule * fixes the verification problem * adds a failed test * replaces an old test scenario with a new one * handles createRLNInstance output * working createRLNInstance2 * refactors the code by replacing the old createRLNInstance * renames createRLNInstance2 * adds documentation and reorganizes rln.nim * replace echo with debug, renames vars, adds a bad proof test * minor * minor * edits var names * adds one more check * adds one more test to the hash * enforcing exception handling * adds pacman -Sy * removes update:true * activates update
2021-04-01 00:39:27 +00:00
{.pop.}