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

feat(sds): migrate bloomfilter to bigint and import hashn function from nim #2253

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adklempner
Copy link
Member

@adklempner adklempner commented Feb 6, 2025

Problem / Description

Bloom filter implementation for SDS needs to match behavior of nim implementation. Specifically, the hashing algorithm and insert/lookup functions should result in the same bit vectors given the same bloom filter parameters and inputs.

Solution

  • Uses an array of bigint to store sufficient bits in bloom filter.
    • This was necessary as the maximum integer values represented by javascript's number is not large enough for nim's int when compiled using Nim Compiler Version 2.2.0 [MacOSX: arm64]
  • Updates all arithmetic to explicitly cast to bigint where necessary.
  • Makes the hashn function for bloomfilter a parameter.
    • This allows switching out the hash function later if necessary without modifying the rest of the bloom filter logic
  • Adds an implementation of hashn generated using nim compiler.
    • So far, this was the closest I could get to having a hash function that behaves the same way in js as it does in nim. It was compiled using the following command: nim js -d:release --threads:off --opt:speed --jsbigint64:off -d:nimStringHash2 src/nim_hashn.nim

Notes


Checklist

  • Code changes are covered by unit tests.
  • Code changes are covered by e2e tests, if applicable.
  • Dogfooding has been performed, if feasible.
  • A test version has been published, if required.
  • All CI checks pass successfully.

@adklempner adklempner requested a review from a team as a code owner February 6, 2025 01:21
Copy link

github-actions bot commented Feb 6, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
Waku node 84.73 KB (0%) 1.7 s (0%) 484 ms (-6% 🔽) 2.2 s
Waku Simple Light Node 135.69 KB (0%) 2.8 s (0%) 526 ms (+23.21% 🔺) 3.3 s
ECIES encryption 22.81 KB (0%) 457 ms (0%) 178 ms (+15.38% 🔺) 634 ms
Symmetric encryption 22.23 KB (0%) 445 ms (0%) 144 ms (+4.47% 🔺) 588 ms
DNS discovery 70.81 KB (0%) 1.5 s (0%) 293 ms (-14.55% 🔽) 1.8 s
Peer Exchange discovery 71.71 KB (0%) 1.5 s (0%) 438 ms (+51.87% 🔺) 1.9 s
Local Peer Cache Discovery 65.39 KB (0%) 1.4 s (0%) 209 ms (-40.03% 🔽) 1.6 s
Privacy preserving protocols 76.53 KB (0%) 1.6 s (0%) 322 ms (-24.44% 🔽) 1.9 s
Waku Filter 78.09 KB (0%) 1.6 s (0%) 238 ms (-40.31% 🔽) 1.8 s
Waku LightPush 75.3 KB (0%) 1.6 s (0%) 481 ms (+16.76% 🔺) 2 s
History retrieval protocols 75.72 KB (0%) 1.6 s (0%) 279 ms (-37.67% 🔽) 1.8 s
Deterministic Message Hashing 7.33 KB (0%) 147 ms (0%) 112 ms (+50.05% 🔺) 258 ms

…om nim

Uses an array of bigint to store sufficient bits in bloom filter.
Updates all arithmetic to explicitly cast to bigint where necessary.
Makes the hashn function for bloomfilter a parameter.
Adds an implementation of hashn generated using nim compiler.
Adds tests.
@adklempner adklempner force-pushed the feat/sds-bigint-nimhashn branch from 7ea7fa8 to be93e4b Compare February 6, 2025 01:27
@@ -0,0 +1,11 @@
/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it generated by nim-compiler too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants