Skip to content

Commit

Permalink
chore(rln-relay): bump zerokit and update ffi
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc committed Feb 22, 2023
1 parent 59203c7 commit c250612
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
6 changes: 3 additions & 3 deletions tests/v2/test_waku_rln_relay.nim
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ suite "Waku rln relay":
# prepare other inputs to the hash function
let outputBuffer = default(Buffer)

let hashSuccess = hash(rlnInstance.get(), unsafeAddr hashInputBuffer,
unsafeAddr outputBuffer)
let hashSuccess = sha256(unsafeAddr hashInputBuffer,
unsafeAddr outputBuffer)
require:
hashSuccess
let outputArr = cast[ptr array[32, byte]](outputBuffer.`ptr`)[]
Expand All @@ -429,7 +429,7 @@ suite "Waku rln relay":
# prepare the input
let msg = "Hello".toBytes()

let hash = rln.hash(msg)
let hash = sha256(msg)

check:
"1e32b3ab545c07c8b4a7ab1ca4f46bc31e4fdc29ac3b240ef1d54b4017a26e4c" ==
Expand Down
15 changes: 12 additions & 3 deletions waku/v2/protocol/waku_rln_relay/rln/rln_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,20 @@ proc new_circuit_from_data*(tree_height: uint, circom_buffer: ptr Buffer, zkey_b
## ctx holds the final created rln object
## the return bool value indicates the success or failure of the operation

proc hash*(ctx: ptr RLN,
input_buffer: ptr Buffer,
output_buffer: ptr Buffer): bool {.importc: "hash".}
#-------------------------------- Hashing utils -------------------------------------------

proc sha256*(input_buffer: ptr Buffer,
output_buffer: ptr Buffer): bool {.importc: "hash".}
## it hashes (sha256) the plain text supplied in inputs_buffer and then maps it to a field element
## this proc is used to map arbitrary signals to field element for the sake of proof generation
## inputs_buffer holds the hash input as a byte seq
## the hash output is generated and populated inside output_buffer
## the output_buffer contains 32 bytes hash output

proc poseidon*(input_buffer: ptr Buffer,
output_buffer: ptr Buffer): bool {.importc: "poseidon_hash".}
## it hashes (poseidon) the plain text supplied in inputs_buffer
## this proc is used to compute the identity secret hash, and external nullifier
## inputs_buffer holds the hash input as a byte seq
## the hash output is generated and populated inside output_buffer
## the output_buffer contains 32 bytes hash output
12 changes: 6 additions & 6 deletions waku/v2/protocol/waku_rln_relay/rln/wrappers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ proc createRLNInstance*(d: int = MerkleTreeDepth): RLNResult =
res = createRLNInstanceLocal(d)
return res

proc hash*(rlnInstance: ptr RLN, data: openArray[byte]): MerkleNode =
## a thin layer on top of the Nim wrapper of the Poseidon hasher
debug "hash input", hashhex = data.toHex()
proc sha256*(data: openArray[byte]): MerkleNode =
## a thin layer on top of the Nim wrapper of the sha256 hasher
debug "sha256 hash input", hashhex = data.toHex()
var lenPrefData = appendLength(data)
var
hashInputBuffer = lenPrefData.toBuffer()
outputBuffer: Buffer # will holds the hash output

debug "hash input buffer length", bufflen = hashInputBuffer.len
debug "sha256 hash input buffer length", bufflen = hashInputBuffer.len
let
hashSuccess = hash(rlnInstance, addr hashInputBuffer, addr outputBuffer)
hashSuccess = sha256(addr hashInputBuffer, addr outputBuffer)

# check whether the hash call is done successfully
if not hashSuccess:
debug "error in hash"
debug "error in sha256 hash"
return default(MerkleNode)

let
Expand Down

0 comments on commit c250612

Please sign in to comment.