From 33344c2ae06ed524b42dba9816a410f4edff8fe8 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 1 Aug 2023 14:15:01 -0400 Subject: [PATCH] refactor: use uint instead of int for RLN indexes --- cmd/waku/flags_rln.go | 4 ++-- cmd/waku/options.go | 4 ++-- examples/chat2/flags.go | 4 ++-- examples/chat2/options.go | 6 +++--- flake.nix | 2 +- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- waku/v2/node/wakuoptions.go | 2 +- waku/v2/node/wakuoptions_rln.go | 2 +- .../rln/group_manager/dynamic/dynamic.go | 19 ++++++++++++++----- 10 files changed, 38 insertions(+), 29 deletions(-) diff --git a/cmd/waku/flags_rln.go b/cmd/waku/flags_rln.go index a0b10dfd..6246f517 100644 --- a/cmd/waku/flags_rln.go +++ b/cmd/waku/flags_rln.go @@ -16,7 +16,7 @@ func rlnFlags() []cli.Flag { Usage: "Enable spam protection through rln-relay", Destination: &options.RLNRelay.Enable, }, - &cli.IntFlag{ + &cli.UintFlag{ Name: "rln-relay-membership-group-index", Value: 0, Usage: "the index of credentials to use, within a specific rln membership set", @@ -51,7 +51,7 @@ func rlnFlags() []cli.Flag { Usage: "Password for encrypting RLN credentials", Destination: &options.RLNRelay.CredentialsPassword, }, - &cli.IntFlag{ + &cli.UintFlag{ Name: "rln-relay-membership-index", Value: 0, Usage: "the index of credentials to use", diff --git a/cmd/waku/options.go b/cmd/waku/options.go index 62b9c100..d9281a96 100644 --- a/cmd/waku/options.go +++ b/cmd/waku/options.go @@ -37,8 +37,8 @@ type RLNRelayOptions struct { Enable bool CredentialsPath string CredentialsPassword string - CredentialsIndex int - MembershipGroupIndex int + CredentialsIndex uint + MembershipGroupIndex uint PubsubTopic string ContentTopic string Dynamic bool diff --git a/examples/chat2/flags.go b/examples/chat2/flags.go index a767c934..fb7f068f 100644 --- a/examples/chat2/flags.go +++ b/examples/chat2/flags.go @@ -194,13 +194,13 @@ func getFlags() []cli.Flag { Usage: "Enable spam protection through rln-relay", Destination: &options.RLNRelay.Enable, }, - &cli.IntFlag{ + &cli.UintFlag{ Name: "rln-relay-membership-group-index", Value: 0, Usage: "the index of credentials to use, within a specific rln membership set", Destination: &options.RLNRelay.MembershipGroupIndex, }, - &cli.IntFlag{ + &cli.UintFlag{ Name: "rln-relay-membership-index", Value: 0, Usage: "the index of credentials to use", diff --git a/examples/chat2/options.go b/examples/chat2/options.go index 76e637f9..42945f75 100644 --- a/examples/chat2/options.go +++ b/examples/chat2/options.go @@ -31,9 +31,9 @@ type RLNRelayOptions struct { Enable bool CredentialsPath string CredentialsPassword string - CredentialsIndex int - MembershipGroupIndex int - MembershipIndex int + CredentialsIndex uint + MembershipGroupIndex uint + MembershipIndex uint PubsubTopic string ContentTopic string Dynamic bool diff --git a/flake.nix b/flake.nix index c23039ac..03934ac1 100644 --- a/flake.nix +++ b/flake.nix @@ -28,7 +28,7 @@ ]; doCheck = false; # FIXME: This needs to be manually changed when updating modules. - vendorSha256 = "sha256-tLlIROm613HFk7/8PduQL2KiuQ3iH1RhDOBneqbDbhc="; + vendorSha256 = "sha256-1sioJgLOO5erkjeAIkTWMLZglJERvMo7OzFNvKHwJXA="; # Fix for 'nix run' trying to execute 'go-waku'. meta = { mainProgram = "waku"; }; }; diff --git a/go.mod b/go.mod index d9d67cbf..07674b2e 100644 --- a/go.mod +++ b/go.mod @@ -39,7 +39,7 @@ require ( github.com/jackc/pgx/v5 v5.4.1 github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 github.com/waku-org/go-noise v0.0.4 - github.com/waku-org/go-zerokit-rln v0.1.13-0.20230726180145-0496a42e60fb + github.com/waku-org/go-zerokit-rln v0.1.13-0.20230803113701-ea89e5d7eedb github.com/wk8/go-ordered-map v1.0.0 ) @@ -71,9 +71,9 @@ require ( github.com/rjeczalik/notify v0.9.3 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect github.com/status-im/status-go/extkeys v1.1.2 // indirect - github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230726162122-13b66414cd5b // indirect - github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230726162204-c48a56712ef0 // indirect - github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230726162310-d761ca9911d8 // indirect + github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e // indirect + github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a // indirect + github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5 // indirect go.uber.org/dig v1.17.0 // indirect go.uber.org/fx v1.19.2 // indirect golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect diff --git a/go.sum b/go.sum index fdd78f7e..4374a349 100644 --- a/go.sum +++ b/go.sum @@ -1554,14 +1554,14 @@ github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 h1:0 github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7/go.mod h1:pFvOZ9YTFsW0o5zJW7a0B5tr1owAijRWJctXJ2toL04= github.com/waku-org/go-noise v0.0.4 h1:ZfQDcCw8pazm89EBl5SXY7GGAnzDQb9AHFXlw3Ktbvk= github.com/waku-org/go-noise v0.0.4/go.mod h1:+PWRfs2eSOVwKrPcQlfhwDngSh3faL/1QoxvoqggEKc= -github.com/waku-org/go-zerokit-rln v0.1.13-0.20230726180145-0496a42e60fb h1:pxPRTh2DWCPCC5dhFisHuBCm1k54fMtR8VR6hUWD734= -github.com/waku-org/go-zerokit-rln v0.1.13-0.20230726180145-0496a42e60fb/go.mod h1:QYTnrByLh6OXvMzSvPNs5aykT/w4fQb4krGcZfKgSZw= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230726162122-13b66414cd5b h1:wWs8b91SVrxYy37gdNnFDCbjv1hMUHMTwaJUktyjrJE= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230726162122-13b66414cd5b/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230726162204-c48a56712ef0 h1:JU5aMzRFeyG/DOiMwLy3F1AMuuXjzPrUKZpW72kAHxE= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230726162204-c48a56712ef0/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230726162310-d761ca9911d8 h1:pQmTryFdSQuUe8dxt/dHgEfRdLwqf1DEGeReuMcJ9Yg= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230726162310-d761ca9911d8/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= +github.com/waku-org/go-zerokit-rln v0.1.13-0.20230803113701-ea89e5d7eedb h1:f1UbFvroZbAul1HTlzM4ZGgjQ3mtn0bW8Jvk7XZQ5V4= +github.com/waku-org/go-zerokit-rln v0.1.13-0.20230803113701-ea89e5d7eedb/go.mod h1:1S6g1KXC45HkDXhIWD9+mdAs9fdyzQy8gtmw4RLjVcM= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e h1:Ad0rJod5F1FuYCJ8SUB/bQZsQwirNHQRE0IcaVloxZo= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a h1:10cre+P76QvnLeyeCVAM8WDbUCri/y5xY3LtwI9Y5DE= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5 h1:GseAHwGMixJ2zlY1kFYr3z1Ts0dREIYbgW4yIji9Ksw= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/willf/bitset v1.1.11/go.mod h1:83CECat5yLh5zVOf4P1ErAgKA5UDvKtgyUABdr3+MjI= diff --git a/waku/v2/node/wakuoptions.go b/waku/v2/node/wakuoptions.go index 5f6cf24a..99a47f2f 100644 --- a/waku/v2/node/wakuoptions.go +++ b/waku/v2/node/wakuoptions.go @@ -102,7 +102,7 @@ type WakuNodeParameters struct { rlnETHClientAddress string keystorePath string keystorePassword string - keystoreIndex int + keystoreIndex uint rlnMembershipContractAddress common.Address rlnRegistrationHandler func(tx *types.Transaction) diff --git a/waku/v2/node/wakuoptions_rln.go b/waku/v2/node/wakuoptions_rln.go index ecf81d73..52b90c01 100644 --- a/waku/v2/node/wakuoptions_rln.go +++ b/waku/v2/node/wakuoptions_rln.go @@ -27,7 +27,7 @@ func WithStaticRLNRelay(pubsubTopic string, contentTopic string, memberIndex r.M // WithDynamicRLNRelay enables the Waku V2 RLN protocol in onchain mode. // Requires the `gowaku_rln` build constrain (or the env variable RLN=true if building go-waku) -func WithDynamicRLNRelay(pubsubTopic string, contentTopic string, keystorePath string, keystorePassword string, keystoreIndex int, membershipContract common.Address, membershipGroupIndex uint, spamHandler rln.SpamHandler, ethClientAddress string, ethPrivateKey *ecdsa.PrivateKey, registrationHandler rln.RegistrationHandler) WakuNodeOption { +func WithDynamicRLNRelay(pubsubTopic string, contentTopic string, keystorePath string, keystorePassword string, keystoreIndex uint, membershipContract common.Address, membershipGroupIndex uint, spamHandler rln.SpamHandler, ethClientAddress string, ethPrivateKey *ecdsa.PrivateKey, registrationHandler rln.RegistrationHandler) WakuNodeOption { return func(params *WakuNodeParameters) error { params.enableRLN = true params.rlnRelayDynamic = true diff --git a/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go b/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go index d646137c..eef6241d 100644 --- a/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go +++ b/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go @@ -56,7 +56,7 @@ type DynamicGroupManager struct { saveKeystore bool keystorePath string keystorePassword string - keystoreIndex int + keystoreIndex uint rootTracker *group_manager.MerkleRootTracker } @@ -106,7 +106,7 @@ func NewDynamicGroupManager( membershipGroupIndex uint, keystorePath string, keystorePassword string, - keystoreIndex int, + keystoreIndex uint, saveKeystore bool, registrationHandler RegistrationHandler, log *zap.Logger, @@ -199,9 +199,18 @@ func (gm *DynamicGroupManager) Start(ctx context.Context, rlnInstance *rln.RLN, return err } - if len(credentials) >= gm.keystoreIndex+1 { - gm.identityCredential = &credentials[gm.keystoreIndex].IdentityCredential - gm.membershipIndex = &credentials[gm.keystoreIndex].MembershipGroups[gm.membershipGroupIndex].TreeIndex + if len(credentials) != 0 { + if int(gm.keystoreIndex) <= len(credentials)-1 { + credential := credentials[gm.keystoreIndex] + gm.identityCredential = &credential.IdentityCredential + if int(gm.membershipGroupIndex) <= len(credential.MembershipGroups)-1 { + gm.membershipIndex = &credential.MembershipGroups[gm.membershipGroupIndex].TreeIndex + } else { + return errors.New("invalid membership group index") + } + } else { + return errors.New("invalid keystore index") + } } }