The security objective is to contain spam activity in a GossipSub network by enforcing a global messaging rate to all the peers. Peers that violate the messaging rate are considered spammers and their message is considered spam. Spammers are also financially punished and removed from the system.
The security objective is to contain spam activity in a GossipSub network by enforcing a global messaging rate to all the peers. Peers that violate the messaging rate are considered spammers and their message is considered spam. Spammers are also financially punished and removed from the system.
</ul><p>The <code>17/WAKU2-RLN-RELAY</code> protocol is an extension of <code>11/WAKU2-RELAY</code> which additionally provides spam protection using <ahref="/spec/32">Rate Limiting Nullifiers (RLN)</a>.</p>
<p>The security objective is to contain spam activity in a GossipSub network by enforcing a global messaging rate to all the peers.
Peers that violate the messaging rate are considered spammers and their message is considered spam.
Spammers are also financially punished and removed from the system.</p>
<!-- raw HTML omitted -->
<h1id="motivation">
Motivation
<aclass="anchor"href="#motivation">#</a>
</h1>
<p>In open and anonymous p2p messaging networks, one big problem is spam resistance.
Existing solutions, such as Whisper’s proof of work are computationally expensive hence not suitable for resource-limited nodes.
Other reputation-based approaches might not be desirable, due to issues around arbitrary exclusion and privacy.</p>
<p>We augment the <ahref="/spec/11"><code>11/WAKU2-RELAY</code></a> protocol with a novel construct of <ahref="/spec/32">RLN</a> to enable an efficient economic spam prevention mechanism that can be run in resource-constrained environments.</p>
<h1id="flow">
Flow
<aclass="anchor"href="#flow">#</a>
</h1>
<p>The messaging rate is defined by the <code>period</code> which indicates how many messages can be sent in a given period.
We define an <code>epoch</code> as $\lceil$ <code>unix_time</code> / <code>period</code> $\rceil$. For example, if <code>unix_time</code> is <code>1644810116</code> and we set <code>period</code> to <code>30</code>, then <code>epoch</code> is $\lceil$<code>(unix_time/period)</code>$\rceil$ <code>= 54827003</code>.
Note that <code>epoch</code> refers to epoch in RLN and not Unix epoch. This means a message can only be sent every period, where period is up to the application.
See see section <ahref="#recommended-system-parameters">Recommended System Parameters</a> for some recommended ways to set a sensible <code>period</code> value depending on the application.
Peers subscribed to a spam-protected <code>pubsubTopic</code> are only allowed to send one message per <code>epoch</code>.
The higher-level layers adopting <code>17/WAKU2-RLN-RELAY</code> MAY choose to enforce the messaging rate for <code>WakuMessages</code> with a specific <code>contentTopic</code> published on a <code>pubsubTopic</code>.</p>
For the registration, a peer creates a transaction that invokes the registration function of the contract via which registers its <code>pk</code> in the group.
The transaction also transfers some amount of ether to the contract to be staked.
This amount is denoted by <code>staked_fund</code> and is a system parameter.
The peer who has the secret key <code>sk</code> associated with a registered <code>pk</code> would be able to withdraw a portion <code>reward_portion</code> of the staked fund by providing valid proof. <!-- raw HTML omitted -->
<code>reward_portion</code> is also a system parameter.</p>
<p>Note that <code>sk</code> is initially only known to its owning peer however, it may get exposed to other peers in case the owner attempts spamming the system i.e., sending more than one message per <code>epoch</code>.
An overview of registration is illustrated in Figure 1.</p>
<p>To publish at a given <code>epoch</code>, the publishing peer proceeds based on the regular <ahref="/spec/11"><code>11/WAKU2-RELAY</code></a> protocol.<br>
However, to protect against spamming, each <code>WakuMessage</code> (which is wrapped inside the <code>data</code> field of a PubSub message) MUST carry a <ahref="##RateLimitProof"><code>RateLimitProof</code></a> with the following fields.
Section <ahref="#payloads">Payload</a> covers the details about the type and encoding of these fields.</p>
<p>The <code>merkle_root</code> contains the root of the Merkle tree.</p>
<p>The <code>epoch</code> represents the current epoch.</p>
<p>The <code>nullifier</code> is an internal nullifier acting as a fingerprint that allows specifying whether two messages are published by the same peer during the same <code>epoch</code>.
The <code>nullifier</code> is a deterministic value derived from <code>sk</code> and <code>epoch</code> therefore any two messages issued by the same peer (i.e., using the same <code>sk</code>) for the same <code>epoch</code> are guaranteed to have identical <code>nullifier</code>s.</p>
<p>The <code>share_x</code> and <code>share_y</code> can be seen as partial disclosure of peer’s <code>sk</code> for the intended <code>epoch</code>.
They are derived deterministically from peer’s <code>sk</code> and current <code>epoch</code> using <ahref="/spec/32">Shamir secret sharing scheme</a>.
If a peer discloses more than one such pair (<code>share_x</code>, <code>share_y</code>) for the same <code>epoch</code>, it would allow full disclosure of its <code>sk</code> and hence get access to its staked fund in the membership contract.</p>
<p>The <code>proof</code> field is a zero-knowledge proof signifying that:</p>
<ol>
<li>The message owner is the current member of the group i.e., her/his identity commitment key <code>pk</code> is part of the membership group Merkle tree with the root <code>merkle_root</code>.</li>
<li><code>share_x</code> and <code>share_y</code> are correctly computed.</li>
<li>The <code>nullifier</code> is constructed correctly.
For more details about the proof generation check <ahref="/spec/32">RLN</a>
The proof generation relies on the knowledge of two pieces of private information i.e., <code>sk</code> and <code>authPath</code>.
The <code>authPath</code> is a subset of Merkle tree nodes by which a peer can prove the inclusion of its <code>pk</code> in the group. <!-- raw HTML omitted -->
The proof generation also requires a set of public inputs which are: the Merkle tree root <code>merkle_root</code>, the current <code>epoch</code>, and the message for which the proof is going to be generated.
In <code>17/WAKU2-RLN-RELAY</code>, the message is the concatenation of <code>WakuMessage</code>’s <code>payload</code> filed and its <code>contentTopic</code> i.e., <code>payload||contentTopic</code>.</li>
<p>Proof generation relies on the knowledge of Merkle tree root <code>merkle_root</code> and <code>authPath</code> which both require access to the membership Merkle tree.
Getting access to the Merkle tree can be done in various ways.
One way is that all the peers construct the tree locally.
This can be done by listening to the registration and deletion events emitted by the membership contract.
Another approach for synchronizing the state of slashed <code>pk</code>s is to disseminate such information through a p2p GossipSub network to which all peers are subscribed.
This is in addition to sending the deletion transaction to the membership contract.
The benefit of an off-chain slashing is that it allows real-time removal of spammers as opposed to on-chain slashing in which peers get informed with a delay,
where the delay is due to mining the slashing transaction.
For the group synchronization, one important security consideration is that peers MUST make sure they always use the most recent Merkle tree root in their proof generation.
The reason is that using an old root can allow inference about the index of the user’s <code>pk</code> in the membership tree hence compromising user privacy and breaking message unlinkability.</p>
<h2id="routing">
Routing
<aclass="anchor"href="#routing">#</a>
</h2>
<p>Upon the receipt of a PubSub message via <ahref="/spec/11"><code>11/WAKU2-RELAY</code></a> protocol, the routing peer parses the <code>data</code> field as a <code>WakuMessage</code> and gets access to the <code>RateLimitProof</code> field.<br>
The peer then validates the <code>RateLimitProof</code> as explained next.</p>
<p><strong>Epoch Validation</strong>
If the <code>epoch</code> attached to the message is more than <code>max_epoch_gap</code> apart from the routing peer’s current <code>epoch</code> then the message is discarded and considered invalid.
This is to prevent a newly registered peer from spamming the system by messaging for all the past epochs.
<code>max_epoch_gap</code> is a system parameter for which we provide some recommendations in section <ahref="#recommended-system-parameters">Recommended System Parameters</a>.</p>
<p><strong>Merkle Root Validation</strong>
The routing peers MUST check whether the provided Merkle root in the <code>RateLimitProof</code> is valid.
It can do so by maintaining a local set of valid Merkle roots, which consist of <code>acceptable_root_window_size</code> past roots.
This allows peers which are not well connected to the network to be able to send messages, accounting for network delay.
This network delay is related to the nature of asynchronous network conditions, which means that peers see membership changes asynchronously, and therefore may have differing local Merkle trees.
See <ahref="#recommended-system-parameters">Recommended System Parameters</a> on choosing an appropriate <code>acceptable_root_window_size</code>.</p>
<p><strong>Proof Verification</strong>
The routing peers MUST check whether the zero-knowledge proof <code>proof</code> is valid.
It does so by running the zk verification algorithm as explained in <ahref="/spec/32">RLN</a>.
If <code>proof</code> is invalid then the message is discarded.</p>
<p><strong>Spam detection</strong>
To enable local spam detection and slashing, routing peers MUST record the <code>nullifier</code>, <code>share_x</code>, and <code>share_y</code> of incoming messages which are not discarded i.e., not found spam or with invalid proof or epoch.
To spot spam messages, the peer checks whether a message with an identical <code>nullifier</code> has already been relayed.</p>
<ol>
<li>If such a message exists and its <code>share_x</code> and <code>share_y</code> components are different from the incoming message, then slashing takes place.
That is, the peer uses the <code>share_x</code> and <code>share_y</code> of the new message and the <code>share'_x</code> and <code>share'_y</code> of the old record to reconstruct the <code>sk</code> of the message owner.
The <code>sk</code> then can be used to delete the spammer from the group and withdraw a portion <code>reward_portion</code> of its staked fund.</li>
<li>If the <code>share_x</code> and <code>share_y</code> fields of the previously relayed message are identical to the incoming message, then the message is a duplicate and shall be discarded.</li>
<li>If none is found, then the message gets relayed.</li>
</ol>
<p>An overview of the routing procedure and slashing is provided in Figure 2.</p>
<!-- raw HTML omitted -->
<p><imgsrc="../../../../rfcs/17/rln-message-verification.png"alt="Figure 2: Publishing, Routing and Slashing workflow."/></p>
<hr>
<h1id="payloads">
Payloads
<aclass="anchor"href="#payloads">#</a>
</h1>
<p>Payloads are protobuf messages implemented using <ahref="https://developers.google.com/protocol-buffers/">protocol buffers v3</a>.
Nodes MAY extend the <ahref="/spec/14">14/WAKU2-MESSAGE</a> with a <code>rate_limit_proof</code> field to indicate that their message is not spam.</p>
<td>the root of membership group Merkle tree at the time of publishing the message</td>
</tr>
<tr>
<tdstyle="text-align:right"><code>share_x</code> and <code>share_y</code></td>
<td>array of 32 bytes each</td>
<td>Shamir secret shares of the user’s secret identity key <code>sk</code> . <code>share_x</code> is the Poseidon hash of the <code>WakuMessage</code>’s <code>payload</code> concatenated with its <code>contentTopic</code> . <code>share_y</code> is calculated using <ahref="/spec/32">Shamir secret sharing scheme</a></td>
<td>The maximum number of past Merkle roots to store</td>
</tr>
</tbody>
</table>
<h2id="epoch-length">
Epoch Length
<aclass="anchor"href="#epoch-length">#</a>
</h2>
<p>A sensible value for the <code>period</code> depends on the application for which the spam protection is going to be used.
For example, while the <code>period</code> of <code>1</code> second i.e., messaging rate of <code>1</code> per second, might be acceptable for a chat application, might be too low for communication among Ethereum network validators.
One should look at the desired throughput of the application to decide on a proper <code>period</code> value.
In the proof of concept implementation of <code>17/WAKU2-RLN-RELAY</code> protocol which is available in <ahref="https://github.com/status-im/nim-waku">nim-waku</a>, the <code>period</code> is set to <code>1</code> second.
Nevertheless, this value is also subject to change depending on user experience.</p>
<h2id="maximum-epoch-gap">
Maximum Epoch Gap
<aclass="anchor"href="#maximum-epoch-gap">#</a>
</h2>
<p>We discussed in the <ahref="#routing">Routing</a> section that the gap between the epoch observed by the routing peer and the one attached to the incoming message should not exceed a threshold denoted by <code>max_epoch_gap</code> .
The value of <code>max_epoch_gap</code> can be measured based on the following factors.</p>
<ul>
<li>Network transmission delay <code>Network_Delay</code>: the maximum time that it takes for a message to be fully disseminated in the GossipSub network.</li>
<li>Clock asynchrony <code>Clock_Asynchrony</code>: The maximum difference between the Unix epoch clocks perceived by network peers which can be due to clock drifts.</li>
</ul>
<p>With a reasonable approximation of the preceding values, one can set <code>max_epoch_gap</code> as
<code>max_epoch_gap</code> $= \lceil \frac{\text{Network Delay} + \text{Clock Asynchrony}}{\text{Epoch Length}}\rceil$ where <code>period</code> is the length of the <code>epoch</code> in seconds.
<code>Network_Delay</code> and <code>Clock_Asynchrony</code> MUST have the same resolution as <code>period</code> .
By this formulation, <code>max_epoch_gap</code> indeed measures the maximum number of <code>epoch</code>s that can elapse since a message gets routed from its origin to all the other peers in the network.</p>
<p><code>acceptable_root_window_size</code> depends upon the underlying chain’s average blocktime, <code>block_time</code></p>
<p>The lower bound for the <code>acceptable_root_window_size</code> SHOULD be set as $acceptable_root_window_size=(Network_Delay)/block_time$</p>
<p><code>Network_Delay</code> MUST have the same resolution as <code>block_time</code>.</p>
<p>By this formulation, <code>acceptable_root_window_size</code> will provide a lower bound of how many roots can be acceptable by a routing peer.</p>
<p>The <code>acceptable_root_window_size</code> should indicate how many blocks may have been mined during the time it takes for a peer to receive a message.
This formula represents a lower bound of the number of acceptable roots.</p>
<h1id="copyright">
Copyright
<aclass="anchor"href="#copyright">#</a>
</h1>
<p>Copyright and related rights waived via <ahref="https://creativecommons.org/publicdomain/zero/1.0/">CC0</a>.</p>