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

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

merged 1 commit into from
Feb 22, 2023

Conversation

rymnc
Copy link
Contributor

@rymnc rymnc commented Feb 22, 2023

Changes and optimizations included in zerokit's bump - vacp2p/zerokit@005393d...master

This included ffi changes -

-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

Note that we've changed the proc name since it conflicted with hash() generated in hashcommon.nim (stdlib), and since it is more indicative of the underlying hash function.

Required as a prerequisite to #1451

@rymnc rymnc added this to the Release 0.16.0 milestone Feb 22, 2023
@rymnc rymnc added track:rln RLN Track (Secure Messaging/Applied ZK), e.g. relay and applications track:zerokit labels Feb 22, 2023
@rymnc rymnc self-assigned this Feb 22, 2023
@rymnc rymnc marked this pull request as ready for review February 22, 2023 09:33
@rymnc rymnc added track:rlnp2p and removed track:rln RLN Track (Secure Messaging/Applied ZK), e.g. relay and applications labels Feb 22, 2023
Copy link
Contributor

@LNSD LNSD left a comment

Choose a reason for hiding this comment

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

LGTM ✅

One little comment for the future :)

Comment on lines +81 to 96
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)
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!

@rymnc rymnc merged commit b6a0117 into master Feb 22, 2023
@rymnc rymnc deleted the bump-zerokit branch February 22, 2023 14:17
@rymnc rymnc mentioned this pull request Feb 22, 2023
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants