Skip to content

Commit

Permalink
feat(rlnv2): rlnv2 fork feature branch
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc committed Jun 5, 2024
1 parent 16709d1 commit 46e28a2
Show file tree
Hide file tree
Showing 25 changed files with 799 additions and 1,579 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ jobs:
if: ${{ needs.changes.outputs.v2 == 'true' || needs.changes.outputs.common == 'true' }}
strategy:
matrix:
rln_version: [1, 2]
os: [ubuntu-latest, macos-13]
runs-on: ${{ matrix.os }}
timeout-minutes: 60

name: build-${{ matrix.os }}-rln-v${{ matrix.rln_version }}
name: build-${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -77,19 +76,18 @@ jobs:
key: ${{ runner.os }}-vendor-modules-${{ steps.submodules.outputs.hash }}

- name: Build binaries
run: make RLN_V${{matrix.rln_version}}=true V=1 QUICK_AND_DIRTY_COMPILER=1 all tools
run: make V=1 QUICK_AND_DIRTY_COMPILER=1 all tools

test:
needs: changes
if: ${{ needs.changes.outputs.v2 == 'true' || needs.changes.outputs.common == 'true' }}
strategy:
matrix:
rln_version: [1, 2]
os: [ubuntu-latest, macos-13]
runs-on: ${{ matrix.os }}
timeout-minutes: 60

name: test-${{ matrix.os }}-rln-v${{ matrix.rln_version }}
name: test-${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down Expand Up @@ -118,7 +116,7 @@ jobs:
postgres_enabled=1
fi
make RLN_V${{matrix.rln_version}}=true V=1 LOG_LEVEL=DEBUG QUICK_AND_DIRTY_COMPILER=1 POSTGRES=$postgres_enabled test testwakunode2
make V=1 LOG_LEVEL=DEBUG QUICK_AND_DIRTY_COMPILER=1 POSTGRES=$postgres_enabled test testwakunode2
build-docker-image:
needs: changes
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/container-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ jobs:
build-docker-image:
strategy:
matrix:
rln_version : [1, 2]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 60

name: docker-build-${{ matrix.os }}-rln-v${{ matrix.rln_version }}
name: docker-build-${{ matrix.os }}
outputs:
image: ${{ steps.build.outputs.image }}
steps:
Expand Down Expand Up @@ -67,12 +66,12 @@ jobs:
if: ${{ steps.secrets.outcome == 'success' }}
run: |
make RLN_V${{matrix.rln_version}}=true -j${NPROC} V=1 QUICK_AND_DIRTY_COMPILER=1 NIMFLAGS="-d:disableMarchNative -d:postgres" wakunode2
make -j${NPROC} V=1 QUICK_AND_DIRTY_COMPILER=1 NIMFLAGS="-d:disableMarchNative -d:postgres" wakunode2
SHORT_REF=$(git rev-parse --short HEAD)
TAG=$([ "${PR_NUMBER}" == "" ] && echo "${SHORT_REF}" || echo "${PR_NUMBER}")
IMAGE=quay.io/wakuorg/nwaku-pr:${TAG}-rln-v${{matrix.rln_version}}
IMAGE=quay.io/wakuorg/nwaku-pr:${TAG}
echo "image=${IMAGE}" >> $GITHUB_OUTPUT
echo "commit_hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
Expand Down
11 changes: 1 addition & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,7 @@ clean: | clean-libbacktrace
.PHONY: librln shouldUseRLNV2

LIBRLN_BUILDDIR := $(CURDIR)/vendor/zerokit
ifeq ($(RLN_V2),true)
LIBRLN_VERSION := v0.4.4
else
LIBRLN_VERSION := v0.3.7
endif

ifeq ($(OS),Windows_NT)
LIBRLN_FILE := rln.lib
Expand All @@ -155,12 +151,7 @@ $(LIBRLN_FILE):
echo -e $(BUILD_MSG) "$@" && \
./scripts/build_rln.sh $(LIBRLN_BUILDDIR) $(LIBRLN_VERSION) $(LIBRLN_FILE)

shouldUseRLNV2:
ifeq ($(RLN_V2),true)
$(eval NIM_PARAMS += -d:rln_v2)
endif

librln: | $(LIBRLN_FILE) shouldUseRLNV2
librln: | $(LIBRLN_FILE)
$(eval NIM_PARAMS += --passL:$(LIBRLN_FILE) --passL:-lm)

clean-librln:
Expand Down
31 changes: 10 additions & 21 deletions apps/chat2/chat2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -542,27 +542,16 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =

echo "rln-relay preparation is in progress..."

when defined(rln_v2):
let rlnConf = WakuRlnConfig(
rlnRelayDynamic: conf.rlnRelayDynamic,
rlnRelayCredIndex: conf.rlnRelayCredIndex,
rlnRelayEthContractAddress: conf.rlnRelayEthContractAddress,
rlnRelayEthClientAddress: string(conf.rlnRelayethClientAddress),
rlnRelayCredPath: conf.rlnRelayCredPath,
rlnRelayCredPassword: conf.rlnRelayCredPassword,
rlnRelayUserMessageLimit: conf.rlnRelayUserMessageLimit,
rlnEpochSizeSec: conf.rlnEpochSizeSec,
)
else:
let rlnConf = WakuRlnConfig(
rlnRelayDynamic: conf.rlnRelayDynamic,
rlnRelayCredIndex: conf.rlnRelayCredIndex,
rlnRelayEthContractAddress: conf.rlnRelayEthContractAddress,
rlnRelayEthClientAddress: string(conf.rlnRelayethClientAddress),
rlnRelayCredPath: conf.rlnRelayCredPath,
rlnRelayCredPassword: conf.rlnRelayCredPassword,
rlnEpochSizeSec: conf.rlnEpochSizeSec,
)
let rlnConf = WakuRlnConfig(
rlnRelayDynamic: conf.rlnRelayDynamic,
rlnRelayCredIndex: conf.rlnRelayCredIndex,
rlnRelayEthContractAddress: conf.rlnRelayEthContractAddress,
rlnRelayEthClientAddress: string(conf.rlnRelayethClientAddress),
rlnRelayCredPath: conf.rlnRelayCredPath,
rlnRelayCredPassword: conf.rlnRelayCredPassword,
rlnRelayUserMessageLimit: conf.rlnRelayUserMessageLimit,
rlnEpochSizeSec: conf.rlnEpochSizeSec,
)

waitFor node.mountRlnRelay(rlnConf, spamHandler = some(spamHandler))

Expand Down
70 changes: 22 additions & 48 deletions tests/waku_relay/utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -95,51 +95,25 @@ proc sendRlnMessage*(
let isCompleted = await completionFuture.withTimeout(FUTURE_TIMEOUT)
return isCompleted

when defined(rln_v2):
proc sendRlnMessageWithInvalidProof*(
client: WakuNode,
pubsubTopic: string,
contentTopic: string,
completionFuture: Future[bool],
payload: seq[byte] = "Hello".toBytes(),
): Future[bool] {.async.} =
let
extraBytes: seq[byte] = @[byte(1), 2, 3]
rateLimitProofRes = client.wakuRlnRelay.groupManager.generateProof(
concat(payload, extraBytes),
# we add extra bytes to invalidate proof verification against original payload
client.wakuRlnRelay.getCurrentEpoch(),
messageId = MessageId(0),
)
rateLimitProof = rateLimitProofRes.get().encode().buffer
message = WakuMessage(
payload: @payload, contentTopic: contentTopic, proof: rateLimitProof
)

discard await client.publish(some(pubsubTopic), message)
let isCompleted = await completionFuture.withTimeout(FUTURE_TIMEOUT)
return isCompleted

else:
proc sendRlnMessageWithInvalidProof*(
client: WakuNode,
pubsubTopic: string,
contentTopic: string,
completionFuture: Future[bool],
payload: seq[byte] = "Hello".toBytes(),
): Future[bool] {.async.} =
let
extraBytes: seq[byte] = @[byte(1), 2, 3]
rateLimitProofRes = client.wakuRlnRelay.groupManager.generateProof(
concat(payload, extraBytes),
# we add extra bytes to invalidate proof verification against original payload
client.wakuRlnRelay.getCurrentEpoch(),
)
rateLimitProof = rateLimitProofRes.get().encode().buffer
message = WakuMessage(
payload: @payload, contentTopic: contentTopic, proof: rateLimitProof
)

discard await client.publish(some(pubsubTopic), message)
let isCompleted = await completionFuture.withTimeout(FUTURE_TIMEOUT)
return isCompleted
proc sendRlnMessageWithInvalidProof*(
client: WakuNode,
pubsubTopic: string,
contentTopic: string,
completionFuture: Future[bool],
payload: seq[byte] = "Hello".toBytes(),
): Future[bool] {.async.} =
let
extraBytes: seq[byte] = @[byte(1), 2, 3]
rateLimitProofRes = client.wakuRlnRelay.groupManager.generateProof(
concat(payload, extraBytes),
# we add extra bytes to invalidate proof verification against original payload
client.wakuRlnRelay.getCurrentEpoch(),
messageId = MessageId(0),
)
rateLimitProof = rateLimitProofRes.get().encode().buffer
message =
WakuMessage(payload: @payload, contentTopic: contentTopic, proof: rateLimitProof)

discard await client.publish(some(pubsubTopic), message)
let isCompleted = await completionFuture.withTimeout(FUTURE_TIMEOUT)
return isCompleted
13 changes: 5 additions & 8 deletions tests/waku_rln_relay/rln/waku_rln_relay_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ proc unsafeAppendRLNProof*(
let input = msg.toRLNSignal()
let epoch = rlnPeer.calcEpoch(senderEpochTime)

when defined(rln_v2):
# we do not fetch a nonce from the nonce manager,
# instead we use 0 as the nonce
let proof = rlnPeer.groupManager.generateProof(input, epoch, 0).valueOr:
return err("could not generate rln-v2 proof: " & $error)
else:
let proof = rlnPeer.groupManager.generateProof(input, epoch).valueOr:
return err("could not generate rln proof: " & $error)
# we do not fetch a nonce from the nonce manager,
# instead we use 0 as the nonce
let proof = rlnPeer.groupManager.generateProof(input, epoch, 0).valueOr:
return err("could not generate rln-v2 proof: " & $error)


msg.proof = proof.encode().buffer
return ok()
6 changes: 2 additions & 4 deletions tests/waku_rln_relay/test_all.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@ import
./test_rln_group_manager_static,
./test_waku_rln_relay,
./test_wakunode_rln_relay,
./test_rln_nonce_manager

when defined(rln_v2):
import ./rln_v2/test_rln_relay_v2_serde
./test_rln_nonce_manager,
./test_rln_serde
Loading

0 comments on commit 46e28a2

Please sign in to comment.