diff --git a/apps/wakunode2/external_config.nim b/apps/wakunode2/external_config.nim index 34a082d08d..bf65b5542b 100644 --- a/apps/wakunode2/external_config.nim +++ b/apps/wakunode2/external_config.nim @@ -214,7 +214,7 @@ type rlnRelayBandwidthThreshold* {. desc: "Message rate in bytes/sec after which verification of proofs should happen", defaultValue: 0 # to maintain backwards compatibility - name: "rln-relay-bandwidth-cutff" }: int + name: "rln-relay-bandwidth-cutoff" }: int staticnodes* {. desc: "Peer multiaddr to directly connect with. Argument may be repeated." diff --git a/tests/v2/waku_rln_relay/test_waku_rln_relay.nim b/tests/v2/waku_rln_relay/test_waku_rln_relay.nim index 60be443d8c..9c891aa96b 100644 --- a/tests/v2/waku_rln_relay/test_waku_rln_relay.nim +++ b/tests/v2/waku_rln_relay/test_waku_rln_relay.nim @@ -662,7 +662,8 @@ suite "Waku rln relay": let rlnConf = WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: RlnRelayPubsubTopic, rlnRelayContentTopic: RlnRelayContentTopic, - rlnRelayCredIndex: index.uint) + rlnRelayCredIndex: index.uint, + rlnRelayTreePath: genTempPath("rln_tree", "waku_rln_relay_2")) let wakuRlnRelayRes = await WakuRlnRelay.new(rlnConf) require: wakuRlnRelayRes.isOk() @@ -708,6 +709,63 @@ suite "Waku rln relay": msgValidate2 == MessageValidationResult.Spam msgValidate3 == MessageValidationResult.Valid msgValidate4 == MessageValidationResult.Invalid + + asyncTest "should validate invalid proofs if bandwidth is available": + let index = MembershipIndex(5) + + let rlnConf = WakuRlnConfig(rlnRelayDynamic: false, + rlnRelayPubsubTopic: RlnRelayPubsubTopic, + rlnRelayContentTopic: RlnRelayContentTopic, + rlnRelayCredIndex: index.uint, + rlnRelayBandwidthThreshold: 4, + rlnRelayTreePath: genTempPath("rln_tree", "waku_rln_relay_3")) + let wakuRlnRelayRes = await WakuRlnRelay.new(rlnConf) + require: + wakuRlnRelayRes.isOk() + let wakuRlnRelay = wakuRlnRelayRes.get() + + # get the current epoch time + let time = epochTime() + + # create some messages from the same peer and append rln proof to them, except wm4 + var + # this one will pass through the bandwidth threshold + wm1 = WakuMessage(payload: "Spam".toBytes()) + # this message, will be over the bandwidth threshold, hence has to be verified + wm2 = WakuMessage(payload: "Valid message".toBytes()) + # this message will be over the bandwidth threshold, hence has to be verified, will be false (since no proof) + wm3 = WakuMessage(payload: "Invalid message".toBytes()) + wm4 = WakuMessage(payload: "Spam message".toBytes()) + + let + proofAdded1 = wakuRlnRelay.appendRLNProof(wm1, time) + proofAdded2 = wakuRlnRelay.appendRLNProof(wm2, time+EpochUnitSeconds) + proofAdded3 = wakuRlnRelay.appendRLNProof(wm4, time) + + # ensure proofs are added + require: + proofAdded1 + proofAdded2 + proofAdded3 + + # validate messages + # validateMessage proc checks the validity of the message fields and adds it to the log (if valid) + let + # this should be no verification, Valid + msgValidate1 = wakuRlnRelay.validateMessage(wm1, some(time)) + # this should be verification, Valid + msgValidate2 = wakuRlnRelay.validateMessage(wm2, some(time)) + # this should be verification, Invalid + msgValidate3 = wakuRlnRelay.validateMessage(wm3, some(time)) + # this should be verification, Spam + msgValidate4 = wakuRlnRelay.validateMessage(wm4, some(time)) + + check: + msgValidate1 == MessageValidationResult.Valid + msgValidate2 == MessageValidationResult.Valid + msgValidate3 == MessageValidationResult.Invalid + msgValidate4 == MessageValidationResult.Spam + test "toIDCommitment and toUInt256": # create an instance of rln