diff --git a/lattices/fuzz/Cargo.lock b/lattices/fuzz/Cargo.lock deleted file mode 100644 index 11e79cc0b3af..000000000000 --- a/lattices/fuzz/Cargo.lock +++ /dev/null @@ -1,574 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "afl" -version = "0.15.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c21e10b6947189c5ff61343b5354e9ad1c1722bd47b69cd0a6b49e5fa7f7ecf6" -dependencies = [ - "home", - "libc", - "rustc_version", - "xdg", -] - -[[package]] -name = "android-tzdata" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" - -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - -[[package]] -name = "arbitrary" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" - -[[package]] -name = "autocfg" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" - -[[package]] -name = "bumpalo" -version = "3.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "cc" -version = "1.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "812acba72f0a070b003d3697490d2b55b837230ae7c6c6497f05cc2ddbb8d938" -dependencies = [ - "jobserver", - "libc", - "shlex", -] - -[[package]] -name = "cc-traits" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "060303ef31ef4a522737e1b1ab68c67916f2a787bb2f4f54f383279adba962b5" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "chrono" -version = "0.4.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" -dependencies = [ - "android-tzdata", - "iana-time-zone", - "js-sys", - "num-traits", - "wasm-bindgen", - "windows-targets", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - -[[package]] -name = "form_urlencoded" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "fuzz" -version = "0.0.0" -dependencies = [ - "afl", - "chrono", - "lattices", - "libfuzzer-sys", - "rand", - "url", -] - -[[package]] -name = "getrandom" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - -[[package]] -name = "home" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "iana-time-zone" -version = "0.1.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "windows-core", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] - -[[package]] -name = "idna" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "jobserver" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" -dependencies = [ - "libc", -] - -[[package]] -name = "js-sys" -version = "0.3.70" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "lattices" -version = "0.5.4" -dependencies = [ - "cc-traits", - "sealed", -] - -[[package]] -name = "libc" -version = "0.2.159" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" - -[[package]] -name = "libfuzzer-sys" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a96cfd5557eb82f2b83fed4955246c988d331975a002961b07c81584d107e7f7" -dependencies = [ - "arbitrary", - "cc", - "once_cell", -] - -[[package]] -name = "log" -version = "0.4.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" - -[[package]] -name = "num-traits" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -dependencies = [ - "autocfg", -] - -[[package]] -name = "once_cell" -version = "1.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" -dependencies = [ - "portable-atomic", -] - -[[package]] -name = "percent-encoding" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" - -[[package]] -name = "portable-atomic" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" - -[[package]] -name = "ppv-lite86" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" -dependencies = [ - "zerocopy", -] - -[[package]] -name = "proc-macro2" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rustc_version" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" -dependencies = [ - "semver", -] - -[[package]] -name = "sealed" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4a8caec23b7800fb97971a1c6ae365b6239aaeddfb934d6265f8505e795699d" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "semver" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" - -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - -[[package]] -name = "syn" -version = "2.0.79" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tinyvec" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - -[[package]] -name = "unicode-bidi" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" - -[[package]] -name = "unicode-ident" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" - -[[package]] -name = "unicode-normalization" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "url" -version = "2.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wasm-bindgen" -version = "0.2.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" -dependencies = [ - "cfg-if", - "once_cell", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" - -[[package]] -name = "windows-core" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - -[[package]] -name = "xdg" -version = "2.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546" - -[[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "byteorder", - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] diff --git a/lattices/fuzz/Cargo.toml b/lattices/fuzz/Cargo.toml index 59e4012bb3c9..129b83b8ada7 100644 --- a/lattices/fuzz/Cargo.toml +++ b/lattices/fuzz/Cargo.toml @@ -1,5 +1,6 @@ [package] -name = "fuzz" +name = "lattices-fuzz" +path = "src/lib.rs" version = "0.0.0" publish = false edition = "2021" @@ -9,46 +10,44 @@ cargo-fuzz = true [dependencies] libfuzzer-sys = "0.4" -lattices = { path = "../" } # Adjust if necessary -rand = "0.8" # or the latest version -chrono = "0.4" -afl = "0.15.10" -url = "*" - -[profile.dev] -opt-level = 1 -overflow-checks = true -debug = true -lto = true -codegen-units = 1 -panic = "abort" - -[profile.release] -opt-level = 2 -overflow-checks = true -debug = true -lto = true -codegen-units = 1 -panic = "abort" - -[[bin]] -name = "all_fuzz" -path = "fuzz_targets/all_fuzz.rs" +once_cell = "1.8.0" + + +[dependencies.lattices] +path = ".." + +[[bin]] +name = "associativity_fuzz" +path = "fuzz_targets/associativity_fuzz.rs" test = false doc = false bench = false +[[bin]] +name = "commutativity_fuzz" +path = "fuzz_targets/commutativity_fuzz.rs" +test = false +doc = false +bench = false -[build] -target = "aarch64-apple-darwin" +[[bin]] +name = "distributivity_fuzz" +path = "fuzz_targets/distributivity_fuzz.rs" +test = false +doc = false +bench = false -[target.aarch64-apple-darwin] -linker = "clang" -rustflags = [ - "-C", "link-arg=-mmacosx-version-min=14.0", - "-C", "link-arg=-lafl" # Link against the AFL library -] - +[[bin]] +name = "linearity_fuzz" +path = "fuzz_targets/linearity_fuzz.rs" +test = false +doc = false +bench = false -[workspace] +[[bin]] +name = "monotonicity_fuzz" +path = "fuzz_targets/monotonicity_fuzz.rs" +test = false +doc = false +bench = false \ No newline at end of file diff --git a/lattices/fuzz/fuzz_targets/all_fuzz.rs b/lattices/fuzz/fuzz_targets/all_fuzz.rs deleted file mode 100644 index 24a9215122d8..000000000000 --- a/lattices/fuzz/fuzz_targets/all_fuzz.rs +++ /dev/null @@ -1,80 +0,0 @@ -#![no_main] - -use std::fs::{create_dir_all, OpenOptions}; -use std::io::Write; -use std::time::{SystemTime, UNIX_EPOCH}; - -use lattices::algebra::{ - associativity_single, commutativity_single, distributive_single, linearity_single, -}; -use libfuzzer_sys::fuzz_target; - -fuzz_target!(|data: &[u8]| { - let crash_dir = "./artifacts/all_fuzz/crashes/"; - - // Create the directory if it doesn't exist - create_dir_all(crash_dir).expect("Failed to create crash log directory"); - - // Create a unique filename using the current timestamp - let timestamp = SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap() - .as_secs(); - let log_file_path = format!("{}crashes_{}.txt", crash_dir, timestamp); - - // Open the crash log file - let mut file = OpenOptions::new() - .write(true) - .create(true) - .open(&log_file_path) - .expect("Failed to open crash log file"); - - if data.len() < 3 { - writeln!(file, "Insufficient data length: expected at least 3 bytes").unwrap(); - return; // Ensure there's enough data for the fuzz target - } - - let a = data[0]; - let b = data[1]; - let c = data[2]; - - // Define the functions for testing - let f = |x: u8, y: u8| x ^ y; // XOR operation - let g = |x: u8, y: u8| x.wrapping_mul(y); // Multiplication modulo 256 - let q = |x: u8| x; // Identity function - - let associativity_result = associativity_single(a, b, c, f); - if !associativity_result { - writeln!( - file, - "Associativity test failed with inputs: a={}, b={}, c={}", - a, b, c - ) - .unwrap(); - } - - let commutativity_result = commutativity_single(a, b, f); - if !commutativity_result { - writeln!( - file, - "Commutativity test failed with inputs: a={}, b={}", - a, b - ) - .unwrap(); - } - - let linearity_result = linearity_single(a, b, f, q, g); - if !linearity_result { - writeln!(file, "Linearity test failed with inputs: a={}, b={}", a, b).unwrap(); - } - - let distributivity_result = distributive_single(a, b, c, f, g); - if !distributivity_result { - writeln!( - file, - "Distributivity test failed with inputs: a={}, b={}, c={}", - a, b, c - ) - .unwrap(); - } -}); diff --git a/lattices/fuzz/fuzz_targets/associativity_fuzz.rs b/lattices/fuzz/fuzz_targets/associativity_fuzz.rs index 32480ca2b4e8..75f37a8170a3 100644 --- a/lattices/fuzz/fuzz_targets/associativity_fuzz.rs +++ b/lattices/fuzz/fuzz_targets/associativity_fuzz.rs @@ -1,34 +1,28 @@ -// #![no_main] - -// extern crate libfuzzer_sys; -// use libfuzzer_sys::fuzz_target; -// use lattices::algebra::associativity_single; - -// // Define your function f outside -// fn wrapping_add(x: u8, y: u8) -> u8 { -// x.wrapping_add(y) -// } - -// fuzz_target!(|data: &[u8]| { -// if data.len() < 3 { -// return; // Ensure there's enough data for the test -// } - -// let a = data[0]; -// let b = data[1]; -// let c = data[2]; - -// // Now you can use your wrapping_add function -// let result = associativity_single(a, b, c, wrapping_add); -// println!("Associativity test result: {}", result); -// }); #![no_main] extern crate libfuzzer_sys; use libfuzzer_sys::fuzz_target; use lattices::algebra::associativity_single; +use once_cell::sync::Lazy; +use lattices_fuzz::algebra_functions::FuzzFunctions; + +type InputType = u8; +static FUNCTIONS: Lazy> = Lazy::new(|| FuzzFunctions::new( + |a: u8, b: u8| a ^ b, + Some(|a: u8| a), + Some(|a: u8, b: u8| a.wrapping_mul(b)), +)); + +fuzz_target!(|data: &[u8]| { + if data.len() < 3 { + println!("Not enough data for associativity test."); + return; + } + + let a = data[0]; + let b = data[1]; + let c = data[2]; -pub fn fuzz_target(a: u8, b: u8, c: u8, f: fn(u8, u8) -> u8) { - let result = associativity_single(a, b, c, f); + let result = associativity_single(a, b, c, FUNCTIONS.f); println!("Associativity test result: {}", result); -} +}); \ No newline at end of file diff --git a/lattices/fuzz/fuzz_targets/commutativity_fuzz.rs b/lattices/fuzz/fuzz_targets/commutativity_fuzz.rs index b67d5847d47a..a0944b1196ca 100644 --- a/lattices/fuzz/fuzz_targets/commutativity_fuzz.rs +++ b/lattices/fuzz/fuzz_targets/commutativity_fuzz.rs @@ -1,28 +1,28 @@ -// #![no_main] +#![no_main] -// extern crate libfuzzer_sys; -// use libfuzzer_sys::fuzz_target; -// use lattices::algebra::commutativity_single; +extern crate libfuzzer_sys; +use lattices::algebra::commutativity_single; +use lattices_fuzz::algebra_functions::FuzzFunctions; +use libfuzzer_sys::fuzz_target; +use once_cell::sync::Lazy; -// pub fn fuzz_target(data: &[u8], f: fn(u8, u8) -> u8) { -// if data.len() < 2 { -// println!("Not enough data for commutativity test."); -// return; -// } +type InputType = u8; +static FUNCTIONS: Lazy> = Lazy::new(|| FuzzFunctions::new( + |a: u8, b: u8| a ^ b, + Some(|a: u8| a), + Some(|a: u8, b: u8| a.wrapping_mul(b)), +)); -// let a = data[0]; -// let b = data[1]; +fuzz_target!(|data: &[u8]| { + if data.len() < 2 { + println!("Not enough data for commutativity test."); + return; + } -// let result = commutativity_single(a, b, f); -// println!("Commutativity test result: {}", result); -// } -#![no_main] + let a = data[0]; + let b = data[1]; -extern crate libfuzzer_sys; -use libfuzzer_sys::fuzz_target; -use lattices::algebra::commutativity_single; + let result = commutativity_single(a, b, FUNCTIONS.f); -pub fn fuzz_target(a: u8, b: u8, f: fn(u8, u8) -> u8) -> bool { - // Using the provided function f for testing - commutativity_single(a, b, f) -} + println!("Commutativity test result: {}", result); +}); diff --git a/lattices/fuzz/fuzz_targets/distributivity_fuzz.rs b/lattices/fuzz/fuzz_targets/distributivity_fuzz.rs index 44835d654749..510253c9d086 100644 --- a/lattices/fuzz/fuzz_targets/distributivity_fuzz.rs +++ b/lattices/fuzz/fuzz_targets/distributivity_fuzz.rs @@ -1,29 +1,32 @@ -// #![no_main] -// extern crate libfuzzer_sys; -// use libfuzzer_sys::fuzz_target; -// use lattices::algebra::distributive_single; - -// pub fn fuzz_target(data: &[u8], f: fn(u8, u8) -> u8, g: fn(u8, u8) -> u8) { - -// if data.len() < 3 { -// println!("Not enough data for distributive test."); -// return; -// } - -// let a = data[0]; -// let b = data[1]; -// let c = data[2]; - -// let result = distributive_single(a, b, c, f, g); -// println!("Distributive test result: {}", result); -// } #![no_main] extern crate libfuzzer_sys; +use lattices::algebra::distributive_single; +use lattices_fuzz::algebra_functions::FuzzFunctions; use libfuzzer_sys::fuzz_target; -use lattices::algebra::distributivity_single; +use once_cell::sync::Lazy; + +type InputType = u8; +static FUNCTIONS: Lazy> = Lazy::new(|| FuzzFunctions::new( + |a: u8, b: u8| a ^ b, + Some(|a: u8| a), + Some(|a: u8, b: u8| a.wrapping_mul(b)), +)); + +fuzz_target!(|data: &[u8]| { + if data.len() < 3 { + println!("Not enough data for distributivity test."); + return; + } + + let a = data[0]; + let b = data[1]; + let c = data[2]; -pub fn fuzz_target(a: u8, b: u8, f: fn(u8, u8) -> u8, g: fn(u8, u8) -> u8) { - let result = distributivity_single(a, b, f, g); - println!("Distributivity test result: {}", result); -} + if let Some(q) = FUNCTIONS.q { + let result = distributive_single(a, b, c, FUNCTIONS.f, q); + println!("Distributivity test result: {}", result); + } else { + println!("Skipping distributivity test because g is not available."); + } +}); diff --git a/lattices/fuzz/fuzz_targets/linearity_fuzz.rs b/lattices/fuzz/fuzz_targets/linearity_fuzz.rs index 886715e0bd3c..c2a27919fd23 100644 --- a/lattices/fuzz/fuzz_targets/linearity_fuzz.rs +++ b/lattices/fuzz/fuzz_targets/linearity_fuzz.rs @@ -1,16 +1,20 @@ #![no_main] + extern crate libfuzzer_sys; +use lattices::algebra::linearity_single; +use lattices_fuzz::algebra_functions::FuzzFunctions; use libfuzzer_sys::fuzz_target; -use lattices::algebra::linearity_single; +use once_cell::sync::Lazy; + +type InputType = u8; +static FUNCTIONS: Lazy> = Lazy::new(|| FuzzFunctions::new( + |a: u8, b: u8| a ^ b, + Some(|a: u8| a), + Some(|a: u8, b: u8| a.wrapping_mul(b)), +)); -// Define the fuzz target -pub fn fuzz_target( - data: &[u8], - f: fn(u8, u8) -> u8, - q: fn(u8) -> u8, - g: fn(u8, u8) -> u8, -) { - if data.len() < 3 { +fuzz_target!(|data: &[u8]| { + if data.len() < 2 { println!("Not enough data for linearity test."); return; } @@ -18,6 +22,11 @@ pub fn fuzz_target( let a = data[0]; let b = data[1]; - let result = linearity_single(a, b, f, q, g); - println!("Linearity test result: {}", result); -} \ No newline at end of file + if let (Some(g), Some(q)) = (FUNCTIONS.g, FUNCTIONS.q) { + let result = linearity_single(a, b, FUNCTIONS.f, g, q); + println!("Linearity test result: {}", result); + } else { + println!("Skipping linearity test because g or q is not available."); + } +}); + diff --git a/lattices/fuzz/fuzz_targets/monotonicity_fuzz.rs b/lattices/fuzz/fuzz_targets/monotonicity_fuzz.rs index a79e55531016..3cea6e754ff9 100644 --- a/lattices/fuzz/fuzz_targets/monotonicity_fuzz.rs +++ b/lattices/fuzz/fuzz_targets/monotonicity_fuzz.rs @@ -1,22 +1,28 @@ #![no_main] extern crate libfuzzer_sys; -use libfuzzer_sys::fuzz_target; use lattices::algebra::is_monotonic_single; +use lattices_fuzz::algebra_functions::FuzzFunctions; +use libfuzzer_sys::fuzz_target; +use once_cell::sync::Lazy; +type InputType = u8; +static FUNCTIONS: Lazy> = Lazy::new(|| FuzzFunctions::new( + |a: u8, b: u8| a ^ b, + Some(|a: u8| a), + Some(|a: u8, b: u8| a.wrapping_mul(b)), +)); -// Define the fuzz target for monotonicity property -pub fn fuzz_target(data: &[u8], f: fn(u8, u8) -> u8) { +fuzz_target!(|data: &[u8]| { // Check if there is enough data for the test (at least 2 values are needed) if data.len() < 2 { println!("Not enough data for monotonicity test."); return; } let a = data[0]; - let b = data[1]; + let b = data[1]; - let result = is_monotonic_single(a, b, f); + let result = is_monotonic_single(a, b, FUNCTIONS.g.unwrap()); println!("Monotonicity test result: {}", result); -} - \ No newline at end of file +}); diff --git a/lattices/fuzz/run_fuzzer.sh b/lattices/fuzz/run_fuzzer.sh deleted file mode 100755 index 7a861ea6146b..000000000000 --- a/lattices/fuzz/run_fuzzer.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -echo "Building the fuzzer..." -if ! cargo fuzz build; then - echo "Fuzzer build failed!" - exit 1 -fi - -echo "Starting fuzz testing for 15 seconds..." -cargo fuzz run all_fuzz -- -max_total_time=3 - -output_dir="fuzz/artifacts/all_fuzz/crashes" -if [ -d "$output_dir" ]; then - num_crashes=$(ls -1q "$output_dir" | wc -l) - if [ "$num_crashes" -gt 0 ]; then - echo "Fuzzing found $num_crashes crash(es). Check the $output_dir folder." - # echo "Crash log example:" - # head -n 20 "$output_dir/crash-0" - else - echo "No crashes found." - fi -else - echo "No crash output directory found. Fuzzing may not have finished yet." -fi diff --git a/lattices/fuzz/src/algebra_functions.rs b/lattices/fuzz/src/algebra_functions.rs new file mode 100644 index 000000000000..29cceb0c9a52 --- /dev/null +++ b/lattices/fuzz/src/algebra_functions.rs @@ -0,0 +1,27 @@ +// src/algebra_functions.rs +// pub struct FuzzFunctions { +// pub f: fn(u8, u8) -> u8, +// pub g: Option u8>, +// pub q: Option u8>, +// pub input_type: , +// } + +pub struct FuzzFunctions { + pub f: fn(T, T) -> T, + pub g: Option T>, + pub q: Option T>, +} + +impl FuzzFunctions { + pub fn new( + f: fn(T, T) -> T, + g: Option T>, + q: Option T>, + ) -> Self { + FuzzFunctions { + f, + g, + q, + } + } +} diff --git a/lattices/fuzz/src/lib.rs b/lattices/fuzz/src/lib.rs new file mode 100644 index 000000000000..5a24457b2088 --- /dev/null +++ b/lattices/fuzz/src/lib.rs @@ -0,0 +1 @@ +pub mod algebra_functions; \ No newline at end of file diff --git a/lattices/fuzz/src/main.rs b/lattices/fuzz/src/main.rs new file mode 100644 index 000000000000..499f572120d1 --- /dev/null +++ b/lattices/fuzz/src/main.rs @@ -0,0 +1,32 @@ + use std::process::Command; + +fn main() { + let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + let fuzz_targets = vec![ + "commutativity_fuzz", + "associativity_fuzz", + "linearity_fuzz", + "monotonicity_fuzz", + ]; + + for fuzz_target in fuzz_targets { + println!("Running fuzz target: {}", fuzz_target); + + let status = Command::new("cargo") + .arg("fuzz") + .arg("run") + .arg(fuzz_target) + .arg("--") + .arg("-max_total_time=5") // Run each fuzz target for 5 seconds + .current_dir(&manifest_dir) // Set the current working directory + .status() + .expect("Failed to execute fuzz target"); + + if !status.success() { + eprintln!("Fuzz target failed: {}", fuzz_target); + std::process::exit(1); + } + } + + println!("All fuzz targets ran successfully."); +} \ No newline at end of file