Skip to content

Commit

Permalink
feat: randomized mine-udc-salt
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Aug 29, 2023
1 parent c1c37d1 commit 1b32cad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ hex-literal = "0.4.1"
log = "0.4.19"
num-bigint = "0.4.3"
num-integer = "0.1.45"
rand = "0.8.5"
rayon = "1.7.0"
regex = "1.8.4"
rpassword = "7.2.0"
Expand Down
14 changes: 12 additions & 2 deletions src/subcommands/lab/mine_udc_salt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
use anyhow::Result;
use clap::Parser;
use colored::Colorize;
use rand::{rngs::StdRng, RngCore, SeedableRng};
use rayon::prelude::*;
use starknet::core::{
crypto::{compute_hash_on_elements, pedersen_hash},
Expand Down Expand Up @@ -144,11 +145,20 @@ impl MineUdcSalt {

let cancellation_token = Arc::new(AtomicBool::new(false));

// Randomizes starting nonces so that the mining process can be horizontally scaled.
let mut rng = StdRng::from_entropy();
let mut nonce_offset = [0u8; 32];
rng.fill_bytes(&mut nonce_offset[1..]);

// We only filled 31 bytes so this value is always in range.
let nonce_offset = FieldElement::from_bytes_be(&nonce_offset).unwrap();

let result = (0..self.jobs)
.into_par_iter()
.map(|job_id| {
let start_nonce =
FieldElement::MAX.floor_div(self.jobs.into()) * FieldElement::from(job_id);
let start_nonce = FieldElement::MAX.floor_div(self.jobs.into())
* FieldElement::from(job_id)
+ nonce_offset;

let miner = Miner {
udc_uniqueness: udc_uniqueness.clone(),
Expand Down

0 comments on commit 1b32cad

Please sign in to comment.