Skip to content

Commit d65a189

Browse files
committed
Refactor to match changes
1 parent 52a7f69 commit d65a189

5 files changed

Lines changed: 23 additions & 91 deletions

File tree

Cargo.lock

Lines changed: 10 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ keywords = ["proof-of-work", "pow", "ddos", "firewall", "crypto"]
1111
categories = ["cryptography", "algorithms", "concurrency"]
1212

1313
[dependencies]
14-
ironshield-types = { version = "0.2", path = "../types" }
14+
ironshield-types = { version = "0.2" }
1515
serde = { version = "1.0", features = ["derive"] }
1616
serde_json = "1.0"
1717
hex = "0.4"
@@ -30,6 +30,6 @@ path = "src/lib.rs"
3030
[features]
3131
default = ["parallel"]
3232
# Core features
33-
parallel = ["rayon"]
33+
parallel = ["rayon"]
3434
# Testing features - use inverted logic
3535
no-parallel = [] # Disables parallel when enabled

src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ mod solve;
99
mod verify;
1010

1111
// Re-export public functions from modules
12-
pub use solve::find_solution_single_threaded;
1312
pub use solve::PoWConfig;
1413

1514
#[cfg(all(feature = "parallel", not(feature = "no-parallel")))]
16-
pub use solve::find_solution_multi_threaded;
15+
pub use solve::find_solution;
1716

1817
pub use verify::verify_ironshield_solution;
1918

@@ -113,7 +112,7 @@ mod tests {
113112
);
114113

115114
// Solve the challenge
116-
let result = find_solution_single_threaded(&challenge, None);
115+
let result = find_solution(&challenge, None, None, None, None);
117116
assert!(result.is_ok(), "Should find solution for integration test");
118117

119118
let response = result.unwrap();
@@ -140,7 +139,7 @@ mod tests {
140139
);
141140

142141
// Solve the challenge
143-
let result = find_solution_single_threaded(&challenge, None);
142+
let result = find_solution(&challenge, None, None, None, None);
144143
assert!(result.is_ok(), "Should find solution for IronShield integration test");
145144

146145
let response = result.unwrap();
@@ -168,7 +167,7 @@ mod tests {
168167
);
169168

170169
// Solve the challenge using multi-threaded version
171-
let result = find_solution_multi_threaded(&challenge, None, None, None, None);
170+
let result = find_solution(&challenge, None, None, None, None);
172171
assert!(result.is_ok(), "Should find solution for IronShield multi-threaded integration test");
173172

174173
let response = result.unwrap();

src/solve.rs

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl PoWConfig {
103103
/// ```
104104
/// use ironshield_core::{
105105
/// IronShieldChallenge,
106-
/// find_solution_multi_threaded,
106+
/// find_solution,
107107
/// SigningKey
108108
/// };
109109
///
@@ -117,7 +117,7 @@ impl PoWConfig {
117117
/// );
118118
///
119119
/// // JavaScript worker coordination mode
120-
/// let response = find_solution_multi_threaded(&challenge, None, Some(0), Some(8), None)?;
120+
/// let response = find_solution(&challenge, None, Some(0), Some(8), None)?;
121121
/// println!("Found solution: {}", response.solution);
122122
/// # Ok(())
123123
/// # }
@@ -285,41 +285,6 @@ mod tests {
285285
}
286286
}
287287

288-
#[test]
289-
fn test_find_solution_single_threaded_easy() {
290-
// Create a challenge with very high threshold (easy to solve).
291-
let dummy_key = SigningKey::from_bytes(&[0u8; 32]);
292-
let challenge = IronShieldChallenge::new(
293-
"test_website".to_string(),
294-
1, // Easiest difficulty.
295-
dummy_key,
296-
[0x00; 32],
297-
);
298-
299-
let result = find_solution_single_threaded(&challenge, None);
300-
assert!(result.is_ok(), "Should find solution for easy challenge");
301-
302-
let response = result.unwrap();
303-
assert_eq!(response.solved_challenge.challenge_signature, challenge.challenge_signature);
304-
assert!(response.solution >= 0, "Solution should be non-negative");
305-
}
306-
307-
#[test]
308-
fn test_find_solution_single_threaded_custom_config() {
309-
// Test with custom configuration.
310-
let dummy_key = SigningKey::from_bytes(&[0u8; 32]);
311-
let challenge = IronShieldChallenge::new(
312-
"test_website".to_string(),
313-
1, // Easiest difficulty.
314-
dummy_key,
315-
[0x00; 32],
316-
);
317-
318-
let config = PoWConfig::custom(10_000, 1_000);
319-
let result = find_solution_single_threaded(&challenge, Some(config));
320-
assert!(result.is_ok(), "Should find solution with custom config");
321-
}
322-
323288

324289
#[test]
325290
fn test_performance_optimization_correctness() {
@@ -361,7 +326,7 @@ mod tests {
361326
[0x00; 32],
362327
);
363328

364-
let result = find_solution_multi_threaded(&challenge, None, None, None, None);
329+
let result = find_solution(&challenge, None, None, None, None);
365330
assert!(result.is_ok(), "Should find solution for easy challenge");
366331

367332
let response = result.unwrap();
@@ -373,40 +338,6 @@ mod tests {
373338
"Multi-threaded solution should pass verification");
374339
}
375340

376-
#[test]
377-
#[cfg(all(feature = "parallel", not(feature = "no-parallel")))]
378-
fn test_find_solution_multi_threaded_vs_single_threaded() {
379-
// Test that multithreaded and single-threaded versions find valid solutions
380-
// for the same challenge (solutions may differ due to search order).
381-
let dummy_key = SigningKey::from_bytes(&[0u8; 32]);
382-
let challenge = IronShieldChallenge::new(
383-
"test_website".to_string(),
384-
1000, // Medium difficulty.
385-
dummy_key,
386-
[0x00; 32],
387-
);
388-
389-
// Solve with single-threaded version.
390-
let single_result = find_solution_single_threaded(&challenge, None);
391-
assert!(single_result.is_ok(), "Single-threaded should find solution");
392-
393-
// Solve with multithreaded version.
394-
let multi_result = find_solution_multi_threaded(&challenge, None, None, None, None);
395-
assert!(multi_result.is_ok(), "Multi-threaded should find solution");
396-
397-
let single_response = single_result.unwrap();
398-
let multi_response = multi_result.unwrap();
399-
400-
// Both solutions should be valid (but may be different nonces).
401-
assert!(crate::verify::verify_ironshield_solution(&single_response),
402-
"Single-threaded solution should be valid");
403-
assert!(crate::verify::verify_ironshield_solution(&multi_response),
404-
"Multi-threaded solution should be valid");
405-
406-
// Both should have the same challenge signature.
407-
assert_eq!(single_response.solved_challenge.challenge_signature, multi_response.solved_challenge.challenge_signature);
408-
}
409-
410341
#[test]
411342
#[cfg(all(feature = "parallel", not(feature = "no-parallel")))]
412343
fn test_find_solution_multi_threaded_deterministic_correctness() {
@@ -421,7 +352,7 @@ mod tests {
421352
);
422353

423354
// Should find a solution relatively quickly with 50% probability per attempt.
424-
let result = find_solution_multi_threaded(&challenge, None, None, None, None);
355+
let result = find_solution(&challenge, None, None, None, None);
425356
assert!(result.is_ok(), "Should find solution for medium difficulty challenge");
426357

427358
let response = result.unwrap();

src/verify.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use ironshield_types::*;
2727
///
2828
/// # Example
2929
/// ```
30-
/// use ironshield_core::{find_solution_single_threaded, verify_ironshield_solution, IronShieldChallenge, SigningKey};
30+
/// use ironshield_core::{find_solution, verify_ironshield_solution, IronShieldChallenge, SigningKey};
3131
///
3232
/// let dummy_key = SigningKey::from_bytes(&[0u8; 32]);
3333
/// let challenge = IronShieldChallenge::new(
@@ -37,7 +37,7 @@ use ironshield_types::*;
3737
/// [0x00; 32],
3838
/// );
3939
///
40-
/// let response = find_solution_single_threaded(&challenge, None).unwrap();
40+
/// let response = find_solution(&challenge, None, None, None, None).unwrap();
4141
/// assert!(verify_ironshield_solution(&response));
4242
/// ```
4343
pub fn verify_ironshield_solution(response: &IronShieldChallengeResponse) -> bool {
@@ -79,7 +79,7 @@ mod tests {
7979
);
8080

8181
// Find a solution using the solver
82-
let result = crate::solve::find_solution_single_threaded(&challenge, None);
82+
let result = crate::solve::find_solution(&challenge, None, None, None, None);
8383
assert!(result.is_ok(), "Should find solution for reasonable challenge");
8484

8585
let response = result.unwrap();

0 commit comments

Comments
 (0)