Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use RLN with RC instead of Poseidon #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/rc-impls"]
path = lib/rc-impls
url = https://github.com/rymnc/reinforced-concrete-impls
47 changes: 43 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,52 @@
<img src="https://github.com/Rate-Limiting-Nullifier/rln-circuits-v2/workflows/Test/badge.svg" width="110">
</p>

<div align="center">
___

*The project was audited by Veridise, yAcademy fellows and internally.*
## This is a fork of RLN

</div>
This fork of RLN makes use of [RC hash function](https://rc-hash.info) as a drop in replacement to poseidon.

___

### Constraint differences

1. RLN Circuit =>

```diff
circom compiler 2.1.5
-template instances: 216
+template instances: 48
-non-linear constraints: 5820
+non-linear constraints: 957
linear constraints: 0
public inputs: 2
public outputs: 3
private inputs: 43
private outputs: 0
-wires: 5844
+wires: 1053
-labels: 18553
+labels: 24733
```

2. Withdraw Circuit =>

```diff
circom compiler 2.1.5
-template instances: 71
+template instances: 42
-non-linear constraints: 214
+non-linear constraints: 37
linear constraints: 0
public inputs: 1
public outputs: 1
private inputs: 1
private outputs: 0
-wires: 217
+wires: 43
-labels: 585
+labels: 1021
```

## What's RLN?

Expand Down
13 changes: 8 additions & 5 deletions circuits/rln.circom
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma circom 2.1.0;

include "./utils.circom";
include "../node_modules/circomlib/circuits/poseidon.circom";
include "../lib/rc-impls/rc-circom/circuits/reinforcedConcrete.circom";

template RLN(DEPTH, LIMIT_BIT_SIZE) {
// Private signals
Expand All @@ -20,8 +20,8 @@ template RLN(DEPTH, LIMIT_BIT_SIZE) {
signal output root;
signal output nullifier;

signal identityCommitment <== Poseidon(1)([identitySecret]);
signal rateCommitment <== Poseidon(2)([identityCommitment, userMessageLimit]);
signal identityCommitment <== ReinforcedConcreteHash()([identitySecret, 0]);
signal rateCommitment <== ReinforcedConcreteHash()([identityCommitment, userMessageLimit]);

// Membership check
root <== MerkleTreeInclusionProof(DEPTH)(rateCommitment, identityPathIndex, pathElements);
Expand All @@ -30,11 +30,14 @@ template RLN(DEPTH, LIMIT_BIT_SIZE) {
RangeCheck(LIMIT_BIT_SIZE)(messageId, userMessageLimit);

// SSS share calculations
signal a1 <== Poseidon(3)([identitySecret, externalNullifier, messageId]);
component rcPermutation = ReinforcedConcretePermutation();
signal a1;
rcPermutation.state <== [identitySecret, externalNullifier, messageId];
a1 <== rcPermutation.hash[0];
y <== identitySecret + a1 * x;

// nullifier calculation
nullifier <== Poseidon(1)([a1]);
nullifier <== ReinforcedConcreteHash()([a1, 0]);
}

component main { public [x, externalNullifier] } = RLN(20, 16);
4 changes: 2 additions & 2 deletions circuits/utils.circom
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma circom 2.1.0;

include "../node_modules/circomlib/circuits/poseidon.circom";
include "../lib/rc-impls/rc-circom/circuits/reinforcedConcrete.circom";
include "../node_modules/circomlib/circuits/mux1.circom";
include "../node_modules/circomlib/circuits/bitify.circom";
include "../node_modules/circomlib/circuits/comparators.circom";
Expand All @@ -27,7 +27,7 @@ template MerkleTreeInclusionProof(DEPTH) {
pathIndex[i]
);

levelHashes[i + 1] <== Poseidon(2)([mux[i][0], mux[i][1]]);
levelHashes[i + 1] <== ReinforcedConcreteHash()([mux[i][0], mux[i][1]]);
}

root <== levelHashes[DEPTH];
Expand Down
4 changes: 2 additions & 2 deletions circuits/withdraw.circom
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pragma circom 2.1.0;

include "../node_modules/circomlib/circuits/poseidon.circom";
include "../lib/rc-impls/rc-circom/circuits/reinforcedConcrete.circom";

template Withdraw() {
signal input identitySecret;
signal input address;

signal output identityCommitment <== Poseidon(1)([identitySecret]);
signal output identityCommitment <== ReinforcedConcreteHash()([identitySecret, 0]);

// Dummy constraint to prevent compiler optimizing it
signal addressSquared <== address * address;
Expand Down
1 change: 1 addition & 0 deletions lib/rc-impls
Submodule rc-impls added at b1b18a
Loading