diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 597742d..a73e5ad 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -237,6 +237,14 @@ dependencies = [ "logos-blockchain-circuits-types", ] +[[package]] +name = "logos-blockchain-circuits-tests" +version = "0.5.0" +dependencies = [ + "logos-blockchain-circuits-pol-sys", + "logos-blockchain-circuits-poq-sys", +] + [[package]] name = "logos-blockchain-circuits-types" version = "0.5.0" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index ef61e69..4c72d98 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -15,6 +15,7 @@ members = [ "logos-blockchain-circuits-pol-sys", "logos-blockchain-circuits-poq-sys", "logos-blockchain-circuits-signature-sys", + "logos-blockchain-circuits-tests", "logos-blockchain-circuits-types", "logos-blockchain-circuits-common", ] diff --git a/rust/logos-blockchain-circuits-tests/Cargo.toml b/rust/logos-blockchain-circuits-tests/Cargo.toml new file mode 100644 index 0000000..8f4ac9b --- /dev/null +++ b/rust/logos-blockchain-circuits-tests/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "logos-blockchain-circuits-tests" +edition.workspace = true +license.workspace = true +version.workspace = true +publish = false + +[dev-dependencies] +lbc-pol-sys = { workspace = true, features = ["prebuilt"] } +lbc-poq-sys = { workspace = true, features = ["prebuilt"] } diff --git a/rust/logos-blockchain-circuits-tests/src/lib.rs b/rust/logos-blockchain-circuits-tests/src/lib.rs new file mode 100644 index 0000000..5aaee20 --- /dev/null +++ b/rust/logos-blockchain-circuits-tests/src/lib.rs @@ -0,0 +1,22 @@ +pub mod roots { + use std::path::{Path, PathBuf}; + use std::sync::LazyLock; + + pub static TESTS: LazyLock = + LazyLock::new(|| PathBuf::from(env!("CARGO_MANIFEST_DIR"))); + pub static REPOSITORY: LazyLock<&Path> = + LazyLock::new(|| TESTS.parent().expect("Failed to find the repository root.")); + pub static POL: LazyLock = + LazyLock::new(|| REPOSITORY.join("logos-blockchain-circuits-pol-sys")); + pub static POQ: LazyLock = + LazyLock::new(|| REPOSITORY.join("logos-blockchain-circuits-poq-sys")); +} + +pub mod inputs { + use super::roots; + use std::path::PathBuf; + use std::sync::LazyLock; + + pub static POL: LazyLock = LazyLock::new(|| roots::POL.join("sample.input.json")); + pub static POQ: LazyLock = LazyLock::new(|| roots::POQ.join("sample.input.json")); +} diff --git a/rust/logos-blockchain-circuits-tests/tests/conflicts.rs b/rust/logos-blockchain-circuits-tests/tests/conflicts.rs new file mode 100644 index 0000000..6933b11 --- /dev/null +++ b/rust/logos-blockchain-circuits-tests/tests/conflicts.rs @@ -0,0 +1,23 @@ +#[cfg(test)] +mod tests { + use lbc_poq_sys::PoqWitnessInput; + use logos_blockchain_circuits_tests::inputs; + + #[test] + fn test_both_circuits_generate_witness() { + let pol_inputs_raw = std::fs::read_to_string(inputs::POL.as_path()).unwrap(); + let pol_witness_input = lbc_pol_sys::PolWitnessInput::new(pol_inputs_raw).unwrap(); + + // Each sys crate compiles a copy of the same C++ runtime (loadCircuit, get_size_of_witness, …) + // under identical symbol names. When two crates are linked into the same binary, the linker + // silently keeps one definition of each symbol, so one circuit ends up using the other's + // size constants — corrupting dat parsing and causing a SIGSEGV. + // This test reproduces the conflict by calling generate_witness on both circuits in the same binary. + let _pol_witness = lbc_pol_sys::generate_witness(&pol_witness_input); + + let inputs_json_raw = std::fs::read_to_string(inputs::POQ.as_path()).unwrap(); + let inputs_json = PoqWitnessInput::new(inputs_json_raw).unwrap(); + let poq_result = lbc_poq_sys::generate_witness(&inputs_json); + assert!(poq_result.is_ok()); + } +}