diff --git a/Cargo.lock b/Cargo.lock index 53945ab..698ac07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -807,12 +807,30 @@ version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + [[package]] name = "memchr" version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" +[[package]] +name = "nu-ansi-term" +version = "0.50.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4a28e057d01f97e61255210fcff094d74ed0466038633e95017f5beb68e4399" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "num-bigint" version = "0.3.3" @@ -892,6 +910,9 @@ dependencies = [ "syn 2.0.106", "thiserror 2.0.16", "time", + "tracing", + "tracing-forest", + "tracing-subscriber", ] [[package]] @@ -900,6 +921,12 @@ version = "11.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + [[package]] name = "plotters" version = "0.3.7" @@ -1242,6 +1269,15 @@ dependencies = [ "keccak", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "shlex" version = "1.3.0" @@ -1285,8 +1321,6 @@ dependencies = [ [[package]] name = "sigma-proofs" version = "0.1.0-sigma" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fe0d134228911458aa039f90582b9e512b06d193aa8fc460c78135367a18388" dependencies = [ "ahash", "ff", @@ -1300,10 +1334,17 @@ dependencies = [ "sha3", "subtle", "thiserror 1.0.69", + "tracing", "zerocopy", "zeroize", ] +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + [[package]] name = "strsim" version = "0.11.1" @@ -1384,6 +1425,15 @@ dependencies = [ "syn 2.0.106", ] +[[package]] +name = "thread_local" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" +dependencies = [ + "cfg-if", +] + [[package]] name = "time" version = "0.3.44" @@ -1425,6 +1475,79 @@ dependencies = [ "serde_json", ] +[[package]] +name = "tracing" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "tracing-core" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-forest" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee40835db14ddd1e3ba414292272eddde9dad04d3d4b65509656414d1c42592f" +dependencies = [ + "smallvec", + "thiserror 1.0.69", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2054a14f5307d601f88daf0553e1cbf472acc4f2c51afab632431cdcd72124d5" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex-automata", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + [[package]] name = "typenum" version = "1.18.0" @@ -1443,6 +1566,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + [[package]] name = "version_check" version = "0.9.5" @@ -1608,6 +1737,15 @@ dependencies = [ "windows-link 0.2.0", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.59.0" diff --git a/Cargo.toml b/Cargo.toml index 0033d50..67b5a8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,4 @@ resolver = "2" [patch.crates-io] cmz = { path = "include/cmz" } sigma-compiler-core = { path = "include/sigma-compiler/sigma-compiler-core" } +sigma-proofs = { path = "include/sigma-proofs" } \ No newline at end of file diff --git a/ooniauth-core/Cargo.toml b/ooniauth-core/Cargo.toml index 02e4107..31beeb0 100644 --- a/ooniauth-core/Cargo.toml +++ b/ooniauth-core/Cargo.toml @@ -20,9 +20,12 @@ subtle = "2.6.1" thiserror = "2.0.12" syn = "2.0.103" hex = "0.4" +tracing = "0.1" [dev-dependencies] criterion = { version = "0.5"} +tracing-subscriber = { version = "0.3", features = ["env-filter", "registry"] } +tracing-forest = "0.1" [[example]] name = "basic_usage" @@ -32,3 +35,4 @@ test = true [[bench]] name = "bench_server" harness = false + diff --git a/ooniauth-core/examples/basic_usage.rs b/ooniauth-core/examples/basic_usage.rs index 69220d9..040f00a 100644 --- a/ooniauth-core/examples/basic_usage.rs +++ b/ooniauth-core/examples/basic_usage.rs @@ -2,8 +2,22 @@ use std::time::Instant; use hex; use ooniauth_core::{scalar_u32, ServerState, UserState}; +use tracing_forest::ForestLayer; +use tracing_forest::util::LevelFilter; +use tracing_subscriber::layer::SubscriberExt; +use tracing_subscriber::util::SubscriberInitExt; +use tracing_subscriber::{EnvFilter, Registry}; fn main() -> Result<(), Box> { + // Initialize tracing with forest layer for runtime display + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::INFO.into()) + .from_env_lossy(); + + Registry::default() + .with(env_filter) + .with(ForestLayer::default()) + .init(); let mut rng = rand::thread_rng(); println!("=== Anonymous Credential Example ===\n"); diff --git a/ooniauth-core/src/submit.rs b/ooniauth-core/src/submit.rs index 55f8cdd..452f8d8 100644 --- a/ooniauth-core/src/submit.rs +++ b/ooniauth-core/src/submit.rs @@ -8,6 +8,7 @@ use curve25519_dalek::RistrettoPoint; use group::{Group, GroupEncoding}; use rand::{CryptoRng, RngCore}; use sha2::Sha512; +use tracing::{instrument, trace, debug}; const SESSION_ID: &[u8] = b"submit"; @@ -24,6 +25,7 @@ muCMZProtocol!(submit, measurement_count_range: std::ops::Range, ) -> Result<((submit::Request, submit::ClientState), [u8; 32]), CredentialError> { + trace!("Starting submit request"); + debug!("Age range: {:?}, Measurement count range: {:?}", age_range, measurement_count_range); cmz_group_init(G::hash_from_bytes::(b"CMZ Generator A")); // Get the current credential @@ -45,8 +49,10 @@ impl UserState { // Domain-specific generator and NYM computation let domain_str = format!("ooni.org/{}/{}", probe_cc, probe_asn); + trace!("Computing DOMAIN for: {}", domain_str); let DOMAIN = G::hash_from_bytes::(domain_str.as_bytes()); let NYM = Old.nym_id.unwrap() * DOMAIN; + debug!("NYM computed successfully"); // Ensure the credential timestamp is within the allowed range let age: u32 = match scalar_u32(&Old.age.unwrap()) { @@ -115,9 +121,16 @@ impl UserState { NYM, }; + trace!("Preparing submit proof with params"); match submit::prepare(rng, SESSION_ID, &Old, New, ¶ms) { - Ok(req_state) => Ok((req_state, NYM.compress().to_bytes())), - Err(_) => Err(CredentialError::CMZError(CMZError::CliProofFailed)), + Ok(req_state) => { + debug!("Submit request prepared successfully"); + Ok((req_state, NYM.compress().to_bytes())) + } + Err(_) => { + debug!("Failed to prepare submit request"); + Err(CredentialError::CMZError(CMZError::CliProofFailed)) + } } } @@ -139,6 +152,7 @@ impl UserState { } impl ServerState { + #[instrument(skip(self, rng, req))] pub fn handle_submit( &mut self, rng: &mut (impl RngCore + CryptoRng), @@ -149,6 +163,8 @@ impl ServerState { age_range: std::ops::Range, measurement_count_range: std::ops::Range, ) -> Result { + trace!("Server handling submit request"); + debug!("Age range: {:?}, Measurement count range: {:?}", age_range, measurement_count_range); let reqbytes = req.as_bytes(); let recvreq = submit::Request::try_from(&reqbytes[..]).unwrap(); @@ -189,8 +205,14 @@ impl ServerState { Ok(()) }, ) { - Ok((response, (_old_cred, _new_cred))) => Ok(response), - Err(e) => Err(e), + Ok((response, (_old_cred, _new_cred))) => { + debug!("Submit request verified successfully"); + Ok(response) + } + Err(e) => { + debug!("Submit request verification failed: {:?}", e); + Err(e) + } } } }