supranational / sppark

Zero-knowledge template library
Apache License 2.0
179 stars 64 forks source link

Linker issue with blst-msm #4

Closed vmx closed 1 year ago

vmx commented 1 year ago

I get an error like

  = note: /usr/bin/ld: /tmp/blstmsmlinkerissue/target/debug/deps/libblst_msm-f154847bd3acdcfa.rlib(blst_msm-f154847bd3acdcfa.blst_msm.14511a1f-cgu.6.rcgu.o): in function `blst_msm::multi_scalar_mult':
          /home/vmx/.cargo/git/checkouts/sppark-766e0a6fee265121/f939f36/poc/blst-cuda/src/lib.rs:49: undefined reference to `mult_pippenger'
          collect2: error: ld returned 1 exit status

  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

when trying to use blst-msm as a dependency. Steps to reproduce (you can copy&paste that into your terminal and execute it directly):

cargo init blstmsmlinkerissue
cd blstmsmlinkerissue
cargo add blst
cargo add blst-msm --git https://github.com/supranational/sppark --features bls12_381
cat > src/main.rs << EOF
use blst::{blst_scalar, blst_p1_affine, blst_fp};

fn main() {                                      
    let bases = vec![blst_scalar{ b: [0; 32] }];
    let exponents = vec![blst_p1_affine{ x: blst_fp { l: [0; 6] }, y: blst_fp { l: [0; 6]} }];
    let point = blst_msm::multi_scalar_mult(&exponents, &bases);                              
    println!("point: {:?}", point);                             
}                                  
EOF
cargo build 

I'm on Debian.

vmx commented 1 year ago

I got a fix via side-channel. You need to include pipenger.cu instead of pipenger_inf.cu if you want to use it with blst based types.


diff --git a/poc/blst-cuda/build.rs b/poc/blst-cuda/build.rs
index a44513b..367552b 100644
--- a/poc/blst-cuda/build.rs
+++ b/poc/blst-cuda/build.rs
@@ -115,7 +115,7 @@ fn main() {
         if let Some(include) = env::var_os("DEP_SPPARK_ROOT") {
             nvcc.include(include);
         }
-        nvcc.file("cuda/pippenger_inf.cu").compile("blst_cuda_msm");
+        nvcc.file("cuda/pippenger.cu").compile("blst_cuda_msm");

         println!("cargo:rustc-cfg=feature=\"cuda\"");
         println!("cargo:rerun-if-changed=cuda");
dot-asm commented 1 year ago

when trying to use blst-msm as a dependency.

PoCs are not meant to be used as dependency, but as an example of how to use sppark as dependency.

vmx commented 1 year ago

as an example of how to use sppark as dependency

Agreed. But I'd expect it to to be a working example, so that one can then use it as a template for your own stuff. When it's not a PoC for working blst, then I think that part should be removed.

dot-asm commented 1 year ago

But I'd expect it to to be a working example,

And it's working. You do cd poc/blst-cuda && cargo test --features=bls12_381 and it works :-) No further promises are made.

Just in case, I do recognize your problem, which is effectively rooted in poor messaging from our side. At this point I reckon that it would be more efficient if we use more interactive means of communications to move forward. More interactive than github issues that is :-)

vmx commented 1 year ago

The POC isn't meant to be used with blstrs types (although the code is there), hence I'm closing this issue.