Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

41/WAKU2-RLN-CONTRACT: Raw spec #522

Closed
wants to merge 20 commits into from
Closed

41/WAKU2-RLN-CONTRACT: Raw spec #522

wants to merge 20 commits into from

Conversation

kgrgpg
Copy link

@kgrgpg kgrgpg commented Aug 1, 2022

The following standard allows for the implementation of a standard API for Rate Limiting Nullifier Contract that manages membership of the participants in a group. This pull request is for the issue explained in #511.

Copy link
Contributor

@fryorcraken fryorcraken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe some security considerations should be reviewed.

content/docs/rfcs/38/README.md Outdated Show resolved Hide resolved
### Constructor

* `constructor(uint256 membershipDeposit, uint256 depth, address _poseidonHasher) public`
* `membershipDeposit` sets the amount of ETH that must be deposited to `register` to the RLN group.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the thoughts around offering a smart contract that accept ERC-20 tokens as deposit?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

content/docs/rfcs/38/README.md Outdated Show resolved Hide resolved
* `function registerBatch(uint256[] calldata pubkeys) external payable`


* withdraw: This function accepts the `secret` of the public key at index`_pubkeyIndex` to withdraw the ETH equal to the`membershipDeposit` to the `receiver` address. This function MUST remove the associated member from the list of members. This function MUST fire the `MemberWithdrawn` event.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I would advise to *not have the receiver parameter but instead, withdraw the ETH to the contract caller to protect against MEV attacks (where ones learns the secret by monitoring the mempool and squeeze a transaction faster to own the funds).

  2. We discussed about considering the RLN as a membership that was not refundable. So that a spammer gets slashed but the funds remain in the pool. Are we still considering this design?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your suggestion. I am notified of this now. The contract needs design changes and the RFC will reflect so.



* withdrawBatch: This function accepts multiple `secrets` of the public keys at the indices `pubkeyIndexes` to withdraw the ETH equal to the `membershipDeposit * secrets.length` to the `receiver` address. This function MUST remove the associated members from the list of members. This function MUST fire the `MemberWithdrawn` event for each member slashed from the group.
* `function withdrawBatch(uint256[] calldata secrets, uint256[] calldata pubkeyIndexes, address payable[] calldata receivers) external`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same an above, receiver should not be included to avoid MEV attacks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted.

@@ -0,0 +1,76 @@
---
slug: 38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

38 is taken already: #512
The next free one is 41, afaik.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken 41.

@kgrgpg
Copy link
Author

kgrgpg commented Aug 2, 2022

@fryorcraken Thanks for your comments.

Note that this RFC has been written with https://github.com/kgrgpg/rln/blob/main/contracts/Rln.sol in mind. This will evolve as RLN contract implementation changes with time.

The support for ERC-20 tokens has been created as a new issue. This can be found at waku-org/nwaku#1058 . Please contribute to the discussion there.

kgrgpg and others added 5 commits August 2, 2022 14:14
Co-authored-by: fryorcraken.eth <110212804+fryorcraken@users.noreply.github.com>
Co-authored-by: fryorcraken.eth <110212804+fryorcraken@users.noreply.github.com>
@fryorcraken
Copy link
Contributor

Note that this RFC has been written with https://github.com/kgrgpg/rln/blob/main/contracts/Rln.sol in mind. This will evolve as RLN contract implementation changes with time.

Has anyone reviewed the solidity contract? I don't see any PR on https://github.com/kgrgpg/rln/ that could have given the opportunity to review the solidity code.

It's a bit of a deadlock here if feedback on the RFC is handled as "that's how the contract API is" but there are no opportunity to review the contract API.

@s1fr0
Copy link
Contributor

s1fr0 commented Aug 2, 2022

@fryorcraken seems to be a revision of https://github.com/kilic/rlnapp/blob/master/packages/contracts/contracts/RLN.sol but no PR/issue/review though.

@oskarth
Copy link
Contributor

oskarth commented Aug 3, 2022

  1. I'm also confused about how the contract code was changed and reviewed, haven't seen this anywhere - @staheri14 do you know how this came to be?

From my understanding, there was a RLN contract that already exists that Blagoj/Taylor were working on. I guess this is https://github.com/kilic/rlnapp/blob/master/packages/contracts/contracts/RLN.sol or something similar (can't find it under PSE GH, but presumably somewhere there? zk-kit, rln, rlnapp, what does zk-chat use?...) Then there was a piece of work to deploy that. There may have been changes required to add e.g. ERC20 support, but not clear to me beyond that.

  1. Regardless, the RLN contract should be in vacp2p org (unless we just use upstream PSE repo), not in an individual repo. We can either transfer this or open as PR. Since code doesn't seem to have been reviewed, maybe it'd be good to actually do that. I opened an empty repo here https://github.com/vacp2p/rln-contract if we think upstream doesn't work (would be useful to understand why or how this came about).

  2. Regardless, Blagoj and/or Taylor should also review this PR

@oskarth oskarth changed the title Rln contract rfc 41/WAKU2-RLN-CONTRACT: Raw spec Aug 3, 2022
@oskarth
Copy link
Contributor

oskarth commented Aug 3, 2022

Also, how is this contract Waku 2 specific? As opposed to being generally useful for RLN.

@kgrgpg
Copy link
Author

kgrgpg commented Aug 3, 2022

@oskarth#7074 @fryorcraken @s1fr0 I was introduced to https://github.com/kilic/rlnapp/blob/master/packages/contracts/contracts/RLN.sol at the start of my employment. I had wondered the same about it not being under the Status/Vac organisation. Since I needed more control of the repo, I created a public clone on my personal repo. In any case, the contract is now pushed to https://github.com/vacp2p/rln-contract .

@kgrgpg
Copy link
Author

kgrgpg commented Aug 3, 2022

I was introduced last week to https://github.com/Rate-Limiting-Nullifier/consensus-layer-rln-registration/blob/main/contracts/RLN_Registry.sol by Taylor. This seemed rather a much trimmed down version for RLN membership contract to me when compared to https://github.com/kilic/rlnapp/blob/master/packages/contracts/contracts/RLN.sol. Taylor said to me that he didn't write the latter and will take a look when he is back from his vacation.

@fryorcraken fryorcraken dismissed their stale review August 15, 2022 03:01

comments taken in account

@b-d1
Copy link
Contributor

b-d1 commented Aug 15, 2022

@b-d1 Would be great if you could please review this PR. Thanks!

For sure, will take a look and add my comments in the next couple of days. I am sorry for the delay, but busy with other things.

@staheri14
Copy link
Contributor

@kgrgpg what is the state of this PR? would be great if we could get the comments addressed and get it merged.

@b-d1
Copy link
Contributor

b-d1 commented Aug 21, 2022

@b-d1 Would be great if you could please review this PR. Thanks!

For sure, will take a look and add my comments in the next couple of days. I am sorry for the delay, but busy with other things.

Things look good to me.

@kgrgpg
Copy link
Author

kgrgpg commented Aug 24, 2022

Re-requesting reviews.

Copy link
Contributor

@kaiserd kaiserd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this spec :).
I left comments.

title: 41/WAKU2-RLN-CONTRACT
name: Rate Limiting Nullifier Membership Contract
status: raw
category: RLN
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Category should be one of (Standards Track|Informational|Best Current Practice).
In this case, most likely Standards Track.

name: Rate Limiting Nullifier Membership Contract
status: raw
category: RLN
tags: 17/WAKU-RLN-RELAY
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, the only well defined tags are waku-application and waku-core-protocol.
We could introduce a new tag here, but I'd rather simply name it RLN, or RLN-core.
Any opinions?

contributors:
---

## Tags
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is just informational in the template. See template:

This section (including its subsections) MUST be removed.



# Abstract
The following standard allows for the implementation of a standard API for Rate Limiting Nullifier Contract that manages membership of the participants in a peer-to-peer messaging group.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The following standard allows for the implementation of a standard API for Rate Limiting Nullifier Contract that manages membership of the participants in a peer-to-peer messaging group.
The following standard specifies a standard API for Rate Limiting Nullifier Contract that manages membership of the participants in a peer-to-peer messaging group.

This API is intended to be used in conjunction with [17/WAKU-RLN-RELAY](https://rfc.vac.dev/spec/17/).
Peers that violate the messaging rate in a relay network,
like explained in [11/WAKU2-RELAY](https://rfc.vac.dev/spec/11/),
are considered spammers and their message is considered spam.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
are considered spammers and their message is considered spam.
are considered spammers and their messages are considered spam.

This is done via the `register` function of the RLN membership contract.
If a registered member of the RLN group spams messages in the network then its secret key get exposed which can be used to slash its membership from the group.
This is done by calling the `withdraw` function of the RLN membership contract, which removes the member from the Merkle tree thereby revoking its rights to send any messages.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a future draft (or at least for the stable function), I'd expect a more in depth explanation here.

If a registered member of the RLN group spams messages in the network then its secret key get exposed which can be used to slash its membership from the group.
This is done by calling the `withdraw` function of the RLN membership contract, which removes the member from the Merkle tree thereby revoking its rights to send any messages.

# Wire Format Specification / Syntax
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The section names in the template may be adjusted if it makes sense. Their content is what MUST be there.
While this section should exist and contain an implementable spec, in this case, I'd rather call it

Contract Specification

(This spec does not specify a protocol with wire format).

* withdraw: This function accepts the `secret` of the public key at index`_pubkeyIndex` to withdraw the ETH equal to the`membershipDeposit` to the `receiver` address.
This function MUST remove the associated member from the list of members.
This function MUST fire the `MemberWithdrawn` event.
* `function withdraw(uint256 secret, uint256 _pubkeyIndex, address payable receiver) external`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I'd suggest changing this even for the raw spec.
The spec should be a clear guideline to implementers and not be confusing.



# Implementation Suggestions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd not put an implementation here, as such specs should be implementation detail agnostic.
The purpose of this section is more to give guidance, e.g., pointing specific implementation choices that significantly improve performance.

If you want to link the implementation. I'd add a new subsection "Example Implementation".

You could also add an appendix that contains the whole source code.

# Copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

References Section listing the references in this spec. (See other specs)

@fryorcraken fryorcraken removed their request for review August 26, 2022 07:48
@oskarth
Copy link
Contributor

oskarth commented Sep 13, 2022

@kgrgpg what's the state of this PR?

@kgrgpg
Copy link
Author

kgrgpg commented Sep 14, 2022

@oskarth Only the latest comments from @kaiserd need to be addressed. I will do this soon.

All other comments have been addressed.

@kgrgpg
Copy link
Author

kgrgpg commented Sep 18, 2022

@kaiserd Thanks for your comments. I have addressed your comments.

@rymnc
Copy link
Contributor

rymnc commented Mar 15, 2023

Closing as not planned and active development on the rln-contract has been moved to https://github.com/rate-limiting-nullifier/rln-contract

@rymnc rymnc closed this Mar 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants