Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(rln-relay): bump zerokit and update ffi #1571

Merged
merged 1 commit into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/chat2/chat2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ proc toString*(message: Chat2Message): string =

# Similarly as Status public chats now.
proc generateSymKey(contentTopic: ContentTopic): SymKey =
var ctx: HMAC[sha256]
var ctx: HMAC[pbkdf2.sha256]
var symKey: SymKey
if pbkdf2(ctx, contentTopic.toBytes(), "", 65356, symKey) != sizeof(SymKey):
raise (ref Defect)(msg: "Should not occur as array is properly sized")
Expand Down
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
2 changes: 1 addition & 1 deletion vendor/zerokit
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)
Comment on lines +81 to 96
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Knowing that this is out of this PR's scope, I recommend revisiting the log levels within the module.

In this diff snippet, for example, the log level should be set to trace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed!


let
Expand Down