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

fix(rln-relay): make nullifier log abide by epoch ordering #2508

Merged
merged 3 commits into from
Mar 6, 2024

Conversation

rymnc
Copy link
Contributor

@rymnc rymnc commented Mar 5, 2024

Description

Instead of using the epoch as the key for the nullifierLog, externalNullifier was being used. This could lead to a node only accepting one valid message sent during an epoch e, and reject all other messages sent during epoch e.
Made the NullifierLog properly map from Epoch to Nullifiers instead of ExternalNullifier to ProofMetadata.
Optimized by nesting the hashmap to locate duplicates faster instead of searching an array.

Changes

  • nullifierLog is now OrderedTable[Epoch, Table[Nullifier, ProofMetadata]]
  • updated tests

@rymnc rymnc added the E:RLN on mainnet see https://github.com/waku-org/pm/issues/98 for details label Mar 5, 2024
@rymnc rymnc self-assigned this Mar 5, 2024
Copy link

github-actions bot commented Mar 5, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2508

Built from a06cd42

@rymnc rymnc changed the title fix(rln-relay): nullifier log abide by epoch ordering fix(rln-relay): make nullifier log abide by epoch ordering Mar 5, 2024
@rymnc rymnc marked this pull request as ready for review March 5, 2024 19:51
Copy link
Contributor

@alrevuelta alrevuelta left a comment

Choose a reason for hiding this comment

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

Can we add a test to protect the code from future modifications and understand that

This could lead to a node only accepting one valid message sent during an epoch e, and reject all other messages sent during epoch e.

can indeed happen?

# check if the epoch exists
if not rlnPeer.nullifierLog.hasKey(externalNullifier):
let nullifier = proofMetadata.nullifier
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe all this can be replace by something like (disregard types). getOrDefault might be useful.

return defaultTable.getOrDefault("epoch1", initTable[string, int]()).hasKey("key1")

A quick example would be something like this.

import tables

var defaultTable: Table[string, Table[string, int]] = {"epoch1":{"key1": 3, "key2": 3}.toTable,
                                                       "epoch2": {"key3": 3, "key4": 3}.toTable}.toTable

echo defaultTable.getOrDefault("epoch1", initTable[string, int]()).hasKey("key1")
# true
  
echo defaultTable.getOrDefault("epoch1", initTable[string, int]()).hasKey("key200")
# false

echo defaultTable.getOrDefault("epoch5", initTable[string, int]()).hasKey("key1")
# false

just an idea though, at your discretion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed in 6d20aef

Copy link
Contributor

Choose a reason for hiding this comment

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

not sure thats addressed there. in any case not blocking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't actually need to get the value from the nullifierLog table, just check if it exists.

waku/waku_rln_relay/rln_relay.nim Outdated Show resolved Hide resolved
tests/waku_rln_relay/test_waku_rln_relay.nim Show resolved Hide resolved
@rymnc rymnc requested a review from alrevuelta March 6, 2024 10:45
@rymnc rymnc mentioned this pull request Mar 6, 2024
17 tasks
Copy link
Collaborator

@Ivansete-status Ivansete-status left a comment

Choose a reason for hiding this comment

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

LGTM! Just minor comments on the surface

waku/waku_rln_relay/rln_relay.nim Outdated Show resolved Hide resolved
waku/waku_rln_relay/rln_relay.nim Outdated Show resolved Hide resolved
tests/waku_rln_relay/test_waku_rln_relay.nim Outdated Show resolved Hide resolved
# check if the epoch exists
if not rlnPeer.nullifierLog.hasKey(externalNullifier):
let nullifier = proofMetadata.nullifier
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure thats addressed there. in any case not blocking.

Co-authored-by: Ivan FB <128452529+Ivansete-status@users.noreply.github.com>
@rymnc rymnc force-pushed the rln-relay-nullifier-log-fix branch from 378100a to c8bc4a6 Compare March 6, 2024 17:49
@rymnc rymnc merged commit beba14d into master Mar 6, 2024
9 of 10 checks passed
@rymnc rymnc deleted the rln-relay-nullifier-log-fix branch March 6, 2024 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E:RLN on mainnet see https://github.com/waku-org/pm/issues/98 for details
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants