From 32fdb4e81eb06ef4ed3c32f58802cff78ad2362a Mon Sep 17 00:00:00 2001 From: rymnc <43716372+rymnc@users.noreply.github.com> Date: Tue, 5 Mar 2024 17:02:50 +0530 Subject: [PATCH] fix: wakunode tests --- tests/wakunode_rest/test_rest_relay.nim | 5 +++++ waku/waku_api/rest/relay/handlers.nim | 4 ++-- waku/waku_rln_relay/nonce_manager.nim | 2 +- waku/waku_rln_relay/rln/wrappers.nim | 11 ++++++++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/wakunode_rest/test_rest_relay.nim b/tests/wakunode_rest/test_rest_relay.nim index 9ec2485af5..b196e5061e 100644 --- a/tests/wakunode_rest/test_rest_relay.nim +++ b/tests/wakunode_rest/test_rest_relay.nim @@ -210,6 +210,7 @@ suite "Waku v2 Rest API - Relay": await node.mountRelay() await node.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayCredIndex: some(1.uint), + rlnRelayUserMessageLimit: 20, rlnEpochSizeSec: 1, rlnRelayTreePath: genTempPath("rln_tree", "wakunode_1"))) @@ -413,6 +414,7 @@ suite "Waku v2 Rest API - Relay": await node.mountRelay() await node.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayCredIndex: some(1.uint), + rlnRelayUserMessageLimit: 20, rlnEpochSizeSec: 1, rlnRelayTreePath: genTempPath("rln_tree", "wakunode_1"))) @@ -458,6 +460,7 @@ suite "Waku v2 Rest API - Relay": await node.mountRelay() await node.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayCredIndex: some(1.uint), + rlnRelayUserMessageLimit: 20, rlnEpochSizeSec: 1, rlnRelayTreePath: genTempPath("rln_tree", "wakunode_1"))) @@ -498,6 +501,7 @@ suite "Waku v2 Rest API - Relay": await node.mountRelay() await node.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayCredIndex: some(1.uint), + rlnRelayUserMessageLimit: 20, rlnEpochSizeSec: 1, rlnRelayTreePath: genTempPath("rln_tree", "wakunode_1"))) @@ -543,6 +547,7 @@ suite "Waku v2 Rest API - Relay": await node.mountRelay() await node.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayCredIndex: some(1.uint), + rlnRelayUserMessageLimit: 20, rlnEpochSizeSec: 1, rlnRelayTreePath: genTempPath("rln_tree", "wakunode_1"))) diff --git a/waku/waku_api/rest/relay/handlers.nim b/waku/waku_api/rest/relay/handlers.nim index d3efa02781..00e94caa7b 100644 --- a/waku/waku_api/rest/relay/handlers.nim +++ b/waku/waku_api/rest/relay/handlers.nim @@ -132,7 +132,7 @@ proc installRelayApiHandlers*(router: var RestRouter, node: WakuNode, cache: Mes # append the proof to the message node.wakuRlnRelay.appendRLNProof(message, float64(getTime().toUnix())).isOkOr: - return RestApiResponse.internalServerError("Failed to publish: error appending RLN proof to message") + return RestApiResponse.internalServerError("Failed to publish: error appending RLN proof to message: " & $error) (await node.wakuRelay.validateMessage(pubsubTopic, message)).isOkOr: return RestApiResponse.badRequest("Failed to publish: " & error) @@ -220,7 +220,7 @@ proc installRelayApiHandlers*(router: var RestRouter, node: WakuNode, cache: Mes if not node.wakuRlnRelay.isNil(): node.wakuRlnRelay.appendRLNProof(message, float64(getTime().toUnix())).isOkOr: return RestApiResponse.internalServerError( - "Failed to publish: error appending RLN proof to message") + "Failed to publish: error appending RLN proof to message: " & $error) (await node.wakuRelay.validateMessage(pubsubTopic, message)).isOkOr: return RestApiResponse.badRequest("Failed to publish: " & error) diff --git a/waku/waku_rln_relay/nonce_manager.nim b/waku/waku_rln_relay/nonce_manager.nim index 76bda77d1f..13f8ae546a 100644 --- a/waku/waku_rln_relay/nonce_manager.nim +++ b/waku/waku_rln_relay/nonce_manager.nim @@ -62,6 +62,6 @@ proc getNonce*(n: NonceManager): NonceManagerResult[Nonce] = if retNonce >= n.nonceLimit: return err(NonceManagerError(kind: NonceLimitReached, - error: "Nonce limit reached. Please wait for the next epoch")) + error: "Nonce limit reached. Please wait for the next epoch. requested nonce: " & $retNonce & " & nonceLimit: " & $n.nonceLimit)) return ok(retNonce) diff --git a/waku/waku_rln_relay/rln/wrappers.nim b/waku/waku_rln_relay/rln/wrappers.nim index 92e1c9d0cb..1db2e42e67 100644 --- a/waku/waku_rln_relay/rln/wrappers.nim +++ b/waku/waku_rln_relay/rln/wrappers.nim @@ -266,6 +266,8 @@ when defined(rln_v2): let output = RateLimitProof(proof: zkproof, merkleRoot: proofRoot, externalNullifier: externalNullifier, + epoch: epoch, + rlnIdentifier: rlnIdentifier, shareX: shareX, shareY: shareY, nullifier: nullifier) @@ -339,8 +341,15 @@ proc proofVerify*(rlnInstance: ptr RLN, validRoots: seq[MerkleNode] = @[]): RlnRelayResult[bool] = ## verifies the proof, returns an error if the proof verification fails ## returns true if the proof is valid + var normalizedProof = proof + when defined(rln_v2): + # when we do this, we ensure that we compute the proof for the derived value + # of the externalNullifier. The proof verification will fail if a malicious peer + # attaches invalid epoch+rlnidentifier pair + normalizedProof.externalNullifier = poseidon(@[@(proof.epoch), @(proof.rlnIdentifier)]).valueOr: + return err("could not construct the external nullifier") var - proofBytes = serialize(proof, data) + proofBytes = serialize(normalizedProof, data) proofBuffer = proofBytes.toBuffer() validProof: bool rootsBytes = serialize(validRoots)