fix(crypto/ci): repair Keccak-256 KAT, purge claims_audit pseudo-inferences, enforce boolean release gate, package zymatica_cli
Browse files
crates/zymatica-zk-mesh/groth16/src/ceremony.rs
CHANGED
|
@@ -252,7 +252,8 @@ fn keccak_f1600(state: &mut [u64; 25]) {
|
|
| 252 |
}
|
| 253 |
}
|
| 254 |
|
| 255 |
-
///
|
|
|
|
| 256 |
#[allow(clippy::needless_range_loop)]
|
| 257 |
pub fn keccak256(data: &[u8]) -> [u8; 32] {
|
| 258 |
let rate = 136; // 1088 bits / 8
|
|
@@ -350,34 +351,17 @@ pub fn initialize(output_path: &str) -> Result<(), String> {
|
|
| 350 |
eprintln!(" Output: {}", output_path);
|
| 351 |
eprintln!(" Chain hash: {}", hex::encode(chain_hash));
|
| 352 |
eprintln!(" Contribution #0: coordinator (genesis)");
|
| 353 |
-
eprintln!();
|
| 354 |
-
eprintln!(
|
| 355 |
-
" Next step: distribute {} to the first contributor.",
|
| 356 |
-
output_path
|
| 357 |
-
);
|
| 358 |
-
eprintln!(" They should run:");
|
| 359 |
-
eprintln!(" zk_lorawan_prove ceremony contribute --input {} --output ceremony_0001.params --name \"<name>\"", output_path);
|
| 360 |
|
| 361 |
Ok(())
|
| 362 |
}
|
| 363 |
|
| 364 |
-
/// Phase 2:
|
| 365 |
-
|
| 366 |
-
pub fn contribute(
|
| 367 |
-
input_path: &str,
|
| 368 |
-
output_path: &str,
|
| 369 |
-
contributor_name: &str,
|
| 370 |
-
) -> Result<(), String> {
|
| 371 |
eprintln!("ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ");
|
| 372 |
eprintln!("β ZK-LoRaWAN MPC Ceremony β Phase 2: Contribute β");
|
| 373 |
eprintln!("ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ");
|
| 374 |
eprintln!();
|
| 375 |
|
| 376 |
-
// Load previous parameters
|
| 377 |
-
let data =
|
| 378 |
-
std::fs::read(input_path).map_err(|e| format!("Failed to read {}: {}", input_path, e))?;
|
| 379 |
-
let mut params = CeremonyParams::from_bytes(&data)?;
|
| 380 |
-
|
| 381 |
eprintln!(" Loaded ceremony params from: {}", input_path);
|
| 382 |
eprintln!(" Previous contribution: #{}", params.contribution_index);
|
| 383 |
eprintln!(
|
|
@@ -791,7 +775,7 @@ mod tests {
|
|
| 791 |
|
| 792 |
#[test]
|
| 793 |
fn test_keccak256_known_answer_test_vectors() {
|
| 794 |
-
//
|
| 795 |
assert_eq!(
|
| 796 |
hex::encode(keccak256(b"")),
|
| 797 |
"c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
|
|
@@ -802,7 +786,19 @@ mod tests {
|
|
| 802 |
);
|
| 803 |
assert_eq!(
|
| 804 |
hex::encode(keccak256(b"The quick brown fox jumps over the lazy dog")),
|
| 805 |
-
"
|
| 806 |
);
|
| 807 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 808 |
}
|
|
|
|
| 252 |
}
|
| 253 |
}
|
| 254 |
|
| 255 |
+
/// Keccak-256 using Ethereum/pre-SHA3 domain padding (0x01...0x80).
|
| 256 |
+
/// This is intentionally Keccak-256, NOT FIPS-202 SHA3-256 (0x06 domain).
|
| 257 |
#[allow(clippy::needless_range_loop)]
|
| 258 |
pub fn keccak256(data: &[u8]) -> [u8; 32] {
|
| 259 |
let rate = 136; // 1088 bits / 8
|
|
|
|
| 351 |
eprintln!(" Output: {}", output_path);
|
| 352 |
eprintln!(" Chain hash: {}", hex::encode(chain_hash));
|
| 353 |
eprintln!(" Contribution #0: coordinator (genesis)");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
|
| 355 |
Ok(())
|
| 356 |
}
|
| 357 |
|
| 358 |
+
/// Phase 2: Contribute entropy to the ceremony parameters.
|
| 359 |
+
pub fn contribute(input_path: &str, output_path: &str, contributor_name: &str) -> Result<(), String> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
eprintln!("ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ");
|
| 361 |
eprintln!("β ZK-LoRaWAN MPC Ceremony β Phase 2: Contribute β");
|
| 362 |
eprintln!("ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ");
|
| 363 |
eprintln!();
|
| 364 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
eprintln!(" Loaded ceremony params from: {}", input_path);
|
| 366 |
eprintln!(" Previous contribution: #{}", params.contribution_index);
|
| 367 |
eprintln!(
|
|
|
|
| 775 |
|
| 776 |
#[test]
|
| 777 |
fn test_keccak256_known_answer_test_vectors() {
|
| 778 |
+
// Ethereum / Keccak-256 standard Known Answer Test vectors
|
| 779 |
assert_eq!(
|
| 780 |
hex::encode(keccak256(b"")),
|
| 781 |
"c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
|
|
|
|
| 786 |
);
|
| 787 |
assert_eq!(
|
| 788 |
hex::encode(keccak256(b"The quick brown fox jumps over the lazy dog")),
|
| 789 |
+
"4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15"
|
| 790 |
);
|
| 791 |
}
|
| 792 |
+
|
| 793 |
+
#[test]
|
| 794 |
+
fn test_keccak256_sponge_boundary_differential() {
|
| 795 |
+
// Test sponge rate boundary conditions at 0, 1, 2, 31, 32, 135, 136, 137, 271, 272, 273, 4096 bytes
|
| 796 |
+
let test_lengths = [0, 1, 2, 31, 32, 135, 136, 137, 271, 272, 273, 4096];
|
| 797 |
+
for &len in &test_lengths {
|
| 798 |
+
let data = vec![0x61u8; len]; // Repeated 'a' bytes
|
| 799 |
+
let hash = keccak256(&data);
|
| 800 |
+
assert_eq!(hash.len(), 32);
|
| 801 |
+
assert_ne!(hash, [0u8; 32]);
|
| 802 |
+
}
|
| 803 |
+
}
|
| 804 |
}
|