Skip to content
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
15 changes: 8 additions & 7 deletions rln-cli/src/examples/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rln::prelude::{
hash_to_field_le, keygen, poseidon_hash, recover_id_secret, Fr, IdSecret, PmtreeConfigBuilder,
RLNProofValues, RLNWitnessInput, RLN,
};
use zerokit_utils::Mode;
use zerokit_utils::pm_tree::Mode;

const MESSAGE_LIMIT: u32 = 1;

Expand Down Expand Up @@ -49,7 +49,7 @@ struct Identity {

impl Identity {
fn new() -> Self {
let (identity_secret, id_commitment) = keygen();
let (identity_secret, id_commitment) = keygen().unwrap();
Identity {
identity_secret,
id_commitment,
Expand Down Expand Up @@ -117,7 +117,8 @@ impl RLNSystem {
let index = self.rln.leaves_set();
let identity = Identity::new();

let rate_commitment = poseidon_hash(&[identity.id_commitment, Fr::from(MESSAGE_LIMIT)]);
let rate_commitment =
poseidon_hash(&[identity.id_commitment, Fr::from(MESSAGE_LIMIT)]).unwrap();
match self.rln.set_next_leaf(rate_commitment) {
Ok(_) => {
println!("Registered User Index: {index}");
Expand Down Expand Up @@ -146,7 +147,7 @@ impl RLNSystem {
};

let (path_elements, identity_path_index) = self.rln.get_merkle_proof(user_index)?;
let x = hash_to_field_le(signal.as_bytes());
let x = hash_to_field_le(signal.as_bytes())?;

let witness = RLNWitnessInput::new(
identity.identity_secret.clone(),
Expand Down Expand Up @@ -230,9 +231,9 @@ fn main() -> Result<()> {
println!("Initializing RLN instance...");
print!("\x1B[2J\x1B[1;1H");
let mut rln_system = RLNSystem::new()?;
let rln_epoch = hash_to_field_le(b"epoch");
let rln_identifier = hash_to_field_le(b"rln-identifier");
let external_nullifier = poseidon_hash(&[rln_epoch, rln_identifier]);
let rln_epoch = hash_to_field_le(b"epoch")?;
let rln_identifier = hash_to_field_le(b"rln-identifier")?;
let external_nullifier = poseidon_hash(&[rln_epoch, rln_identifier]).unwrap();
println!("RLN Relay Example:");
println!("Message Limit: {MESSAGE_LIMIT}");
println!("----------------------------------");
Expand Down
15 changes: 8 additions & 7 deletions rln-cli/src/examples/stateless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rln::prelude::{
hash_to_field_le, keygen, poseidon_hash, recover_id_secret, Fr, IdSecret, PoseidonHash,
RLNProofValues, RLNWitnessInput, DEFAULT_TREE_DEPTH, RLN,
};
use zerokit_utils::{OptimalMerkleTree, ZerokitMerkleProof, ZerokitMerkleTree};
use zerokit_utils::merkle_tree::{OptimalMerkleTree, ZerokitMerkleProof, ZerokitMerkleTree};

const MESSAGE_LIMIT: u32 = 1;

Expand Down Expand Up @@ -48,7 +48,7 @@ struct Identity {

impl Identity {
fn new() -> Self {
let (identity_secret, id_commitment) = keygen();
let (identity_secret, id_commitment) = keygen().unwrap();
Identity {
identity_secret,
id_commitment,
Expand Down Expand Up @@ -101,7 +101,8 @@ impl RLNSystem {
let index = self.tree.leaves_set();
let identity = Identity::new();

let rate_commitment = poseidon_hash(&[identity.id_commitment, Fr::from(MESSAGE_LIMIT)]);
let rate_commitment =
poseidon_hash(&[identity.id_commitment, Fr::from(MESSAGE_LIMIT)]).unwrap();
self.tree.update_next(rate_commitment)?;

println!("Registered User Index: {index}");
Expand All @@ -125,7 +126,7 @@ impl RLNSystem {
};

let merkle_proof = self.tree.proof(user_index)?;
let x = hash_to_field_le(signal.as_bytes());
let x = hash_to_field_le(signal.as_bytes())?;

let witness = RLNWitnessInput::new(
identity.identity_secret.clone(),
Expand Down Expand Up @@ -219,9 +220,9 @@ fn main() -> Result<()> {
println!("Initializing RLN instance...");
print!("\x1B[2J\x1B[1;1H");
let mut rln_system = RLNSystem::new()?;
let rln_epoch = hash_to_field_le(b"epoch");
let rln_identifier = hash_to_field_le(b"rln-identifier");
let external_nullifier = poseidon_hash(&[rln_epoch, rln_identifier]);
let rln_epoch = hash_to_field_le(b"epoch")?;
let rln_identifier = hash_to_field_le(b"rln-identifier")?;
let external_nullifier = poseidon_hash(&[rln_epoch, rln_identifier]).unwrap();
println!("RLN Stateless Relay Example:");
println!("Message Limit: {MESSAGE_LIMIT}");
println!("----------------------------------");
Expand Down
Loading
Loading