Skip to content

Commit

Permalink
feat(rlnv2): clean fork of rlnv2 (#2828)
Browse files Browse the repository at this point in the history
* chore(rlnv2): contract interface changes (#2770)
* fix: tests
* fix: remove stuint[32]
* chore(submodule): update zerokit submodule to v0.5.1 (#2782)
* fix: remove cond comp for lightpush test
* fix: ci and nonceManager
  • Loading branch information
rymnc authored and Ivansete-status committed Jun 20, 2024
1 parent 31daaba commit a02832f
Show file tree
Hide file tree
Showing 30 changed files with 856 additions and 1,671 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ jobs:
strategy:
fail-fast: false
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 @@ -78,20 +77,19 @@ 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:
fail-fast: false
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 @@ -120,7 +118,7 @@ jobs:
export MAKEFLAGS="-j1"
export NIMFLAGS="--colors:off -d:chronicles_colors:none"
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
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
path = vendor/zerokit
url = https://github.com/vacp2p/zerokit.git
ignore = dirty
branch = v0.3.4
branch = v0.5.1
[submodule "vendor/nim-regex"]
path = vendor/nim-regex
url = https://github.com/nitely/nim-regex.git
Expand Down
17 changes: 4 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,10 @@ clean: | clean-libbacktrace
##################
## RLN ##
##################
.PHONY: librln shouldUseRLNV2
.PHONY: librln

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

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 Expand Up @@ -320,7 +311,7 @@ endif

rebuild-nat-libs: | clean-cross nat-libs

libwaku-android-precheck: shouldUseRLNV2
libwaku-android-precheck:
ifndef ANDROID_NDK_HOME
$(error ANDROID_NDK_HOME is not set)
endif
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
6 changes: 3 additions & 3 deletions scripts/build_rln.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ host_triplet=$(rustc --version --verbose | awk '/host:/{print $2}')

tarball="${host_triplet}"

# use arkzkey feature for v0.4.4
# use arkzkey feature for v0.5.1
# TODO: update this script in the future when arkzkey is default
if [[ "${rln_version}" == "v0.4.4" ]]; then
if [[ "${rln_version}" == "v0.5.1" ]]; then
tarball+="-arkzkey-rln.tar.gz"
else
tarball+="-rln.tar.gz"
Expand Down Expand Up @@ -52,6 +52,6 @@ else
exit 1
fi
# if submodule version = version in Makefile, build rln
cargo build --release -p rln --manifest-path "${build_dir}/rln/Cargo.toml"
cargo build --release -p rln --manifest-path "${build_dir}/rln/Cargo.toml" --features arkzkey
cp "${build_dir}/target/release/librln.a" "${output_filename}"
fi
23 changes: 8 additions & 15 deletions tests/node/test_wakunode_lightpush.nim
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,14 @@ suite "RLN Proofs as a Lightpush Service":
client = newTestWakuNode(clientKey, ValidIpAddress.init("0.0.0.0"), Port(0))

# mount rln-relay
when defined(rln_v2):
let wakuRlnConfig = WakuRlnConfig(
rlnRelayDynamic: false,
rlnRelayCredIndex: some(1.uint),
rlnRelayUserMessageLimit: 1,
rlnEpochSizeSec: 1,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode"),
)
else:
let wakuRlnConfig = WakuRlnConfig(
rlnRelayDynamic: false,
rlnRelayCredIndex: some(1.uint),
rlnEpochSizeSec: 1,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode"),
)
let wakuRlnConfig = WakuRlnConfig(
rlnRelayDynamic: false,
rlnRelayCredIndex: some(1.uint),
rlnRelayUserMessageLimit: 1,
rlnEpochSizeSec: 1,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode"),
)


await allFutures(server.start(), client.start())
await server.start()
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 a02832f

Please sign in to comment.