libsnark icon indicating copy to clipboard operation
libsnark copied to clipboard

Does not compile on OS X

Open imeckler opened this issue 6 years ago • 11 comments

Hi, the readme claims that libsnark should build on OS X, but I've had a lot of trouble. First, I just symlinked openssl headers into the expected location with

cd /usr/local/include
ln -s ../opt/openssl/include/openssl .

But ./prepare-depends.sh fails with a slew of errors of the form

../src/crypto_sign/ed25519/amd64-51-30k/choose_t.s:2676:1: error: 32-bit absolute addressing is not supported in 64-bit mode
movq crypto_sign_ed25519_amd64_51_30k_batch_2P0,%rdi
^

and if I try make NO_PROCPS=1 NO_GTEST=1 NO_DOCS=1 I get

c++ -o src/zk_proof_systems/ppzkadsnark/r1cs_ppzkadsnark/examples/demo_r1cs_ppzkadsnark.o   src/zk_proof_systems/ppzkadsnark/r1cs_ppzkadsnark/examples/demo_r1cs_ppzkadsnark.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
In file included from src/zk_proof_systems/ppzkadsnark/r1cs_ppzkadsnark/examples/demo_r1cs_ppzkadsnark.cpp:15:
In file included from src/zk_proof_systems/ppzkadsnark/r1cs_ppzkadsnark/examples/run_r1cs_ppzkadsnark.hpp:33:
In file included from src/zk_proof_systems/ppzkadsnark/r1cs_ppzkadsnark/examples/run_r1cs_ppzkadsnark.tcc:18:
In file included from src/zk_proof_systems/ppzkadsnark/r1cs_ppzkadsnark/r1cs_ppzkadsnark.hpp:672:
src/zk_proof_systems/ppzkadsnark/r1cs_ppzkadsnark/r1cs_ppzkadsnark.tcc:377:30: fatal error: invalid operands to binary expression ('Fr<snark_pp<libsnark::default_r1cs_ppzkadsnark_pp> >'
      (aka 'libsnark::Fp_model<4, &libsnark::bn128_modulus_r>') and 'libsnark::bn128_G1')
    G1<snark_pp<ppT>> I1 = i * G1<snark_pp<ppT>>::one();

imeckler avatar Aug 02 '17 00:08 imeckler

I installed gcc (rather than the default clang) and make NO_PROCPS=1 NO_GTEST=1 NO_DOCS=1 CXX=gcc-7 seemed to get further, though still failed:

gcc-7 -o src/zk_proof_systems/ppzkadsnark/r1cs_ppzkadsnark/examples/demo_r1cs_ppzkadsnark.o   src/zk_proof_systems/ppzkadsnark/r1cs_ppzkadsnark/examples/demo_r1cs_ppzkadsnark.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/alt_bn128/alt_bn128_g1.o   src/algebra/curves/alt_bn128/alt_bn128_g1.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/alt_bn128/alt_bn128_g2.o   src/algebra/curves/alt_bn128/alt_bn128_g2.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/alt_bn128/alt_bn128_init.o   src/algebra/curves/alt_bn128/alt_bn128_init.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/alt_bn128/alt_bn128_pairing.o   src/algebra/curves/alt_bn128/alt_bn128_pairing.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/alt_bn128/alt_bn128_pp.o   src/algebra/curves/alt_bn128/alt_bn128_pp.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/edwards/edwards_g1.o   src/algebra/curves/edwards/edwards_g1.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/edwards/edwards_g2.o   src/algebra/curves/edwards/edwards_g2.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/edwards/edwards_init.o   src/algebra/curves/edwards/edwards_init.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/edwards/edwards_pairing.o   src/algebra/curves/edwards/edwards_pairing.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/edwards/edwards_pp.o   src/algebra/curves/edwards/edwards_pp.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/mnt/mnt4/mnt4_g1.o   src/algebra/curves/mnt/mnt4/mnt4_g1.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/mnt/mnt4/mnt4_g2.o   src/algebra/curves/mnt/mnt4/mnt4_g2.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/mnt/mnt4/mnt4_init.o   src/algebra/curves/mnt/mnt4/mnt4_init.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/mnt/mnt4/mnt4_pairing.o   src/algebra/curves/mnt/mnt4/mnt4_pairing.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/mnt/mnt4/mnt4_pp.o   src/algebra/curves/mnt/mnt4/mnt4_pp.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/mnt/mnt46_common.o   src/algebra/curves/mnt/mnt46_common.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/mnt/mnt6/mnt6_g1.o   src/algebra/curves/mnt/mnt6/mnt6_g1.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/mnt/mnt6/mnt6_g2.o   src/algebra/curves/mnt/mnt6/mnt6_g2.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/mnt/mnt6/mnt6_init.o   src/algebra/curves/mnt/mnt6/mnt6_init.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/mnt/mnt6/mnt6_pairing.o   src/algebra/curves/mnt/mnt6/mnt6_pairing.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/algebra/curves/mnt/mnt6/mnt6_pp.o   src/algebra/curves/mnt/mnt6/mnt6_pp.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/common/data_structures/integer_permutation.o   src/common/data_structures/integer_permutation.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/common/data_structures/set_commitment.o   src/common/data_structures/set_commitment.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/common/default_types/r1cs_ppzkpcd_pp.o   src/common/default_types/r1cs_ppzkpcd_pp.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
gcc-7 -o src/common/default_types/tinyram_ppzksnark_pp.o   src/common/default_types/tinyram_ppzksnark_pp.cpp -c -MMD -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors -O2 -march=native -mtune=native -DUSE_ASM -DMONTGOMERY_OUTPUT -DCURVE_BN128 -Idepinst/include -Isrc -DBN_SUPPORT_SNARK -DNO_PROCPS -fPIC
In file included from src/gadgetlib1/gadgets/cpu_checkers/tinyram/components/alu_arithmetic.hpp:682:0,
                 from src/gadgetlib1/gadgets/cpu_checkers/tinyram/components/alu_gadget.hpp:17,
                 from src/gadgetlib1/gadgets/cpu_checkers/tinyram/tinyram_cpu_checker.hpp:19,
                 from src/relations/ram_computations/rams/tinyram/tinyram_params.hpp:17,
                 from src/common/default_types/tinyram_ppzksnark_pp.hpp:17,
                 from src/common/default_types/tinyram_ppzksnark_pp.cpp:12:
src/gadgetlib1/gadgets/cpu_checkers/tinyram/components/alu_arithmetic.tcc:29:10: error: 'function' in namespace 'std' does not name a template type
     std::function<T*

imeckler avatar Aug 02 '17 00:08 imeckler

IIRC, libsnark currently doesn't compile under clang, so installing gcc was the right move.

I think the error you reported in the second comment is a legitimate bug in libsnark master.

There has been work on migrating from prepare-depends.sh + Makefiles to a CMake-based build system, and a lot of other improvements, including a fix for this bug, are in the candidate-master branch which is using CMake.

Can you try checking out candidate-master and building with CMake?

Sorry for the confusion.

aleksejspopovs avatar Aug 02 '17 00:08 aleksejspopovs

Having trouble installing the dependency libprocps. Any pointers? Seems hard to find for OS X somehow.

imeckler avatar Aug 02 '17 01:08 imeckler

I think librocps doesn't work under macOS, and README (in section "Portability") says that -DWITH_PROCPS=OFF should me used on macOS.

aleksejspopovs avatar Aug 02 '17 02:08 aleksejspopovs

Any ideas about this issue?

../src/crypto_sign/ed25519/amd64-51-30k/choose_t.s:2676:1: error: 32-bit absolute addressing is not supported in 64-bit mode
movq crypto_sign_ed25519_amd64_51_30k_batch_2P0,%rdi
^

I'm trying to get a working macOS/clang build and this is still hindering it. That assembly looks autogenerated (presumably from some .q file) but it's from SUPERCOP and it seems pretty hard to track down the process that created it.

copumpkin avatar Jan 20 '18 01:01 copumpkin

For what it's worth, I was able to get a working build of libsnark on macOS (with clang) by passing in -DWITH_SUPERCOP=OFF (since supercop is where the bad assembly lives, and seems ancient and forgotten and it's unclear how to fix it) in addition to the WITH_PROCPS=OFF, and a patch I borrowed from zcash. If anyone wants to see the build expression, it's here.

copumpkin avatar Jan 21 '18 17:01 copumpkin

I also had luck installing on MacOS by adding -std=c++11 to my cxxflags.

jason-tilley avatar Mar 04 '18 19:03 jason-tilley

@ForTozs could you explain a bit more?

rstormsf avatar Aug 08 '18 04:08 rstormsf

I got it to compile, but many checks fail.

brew install cmake
brew install gmp
brew install boost
brew install gcc

# symlink openssl
ln -s /usr/local/opt/openssl/include/openssl /usr/local/include

git clone https://github.com/scipr-lab/libsnark.git

git submodule init && git submodule update


mkdir build && cd build && cmake -DWITH_PROCPS=OFF -DWITH_SUPERCOP=OFF ..
make

Build finished with only warns, but then I got poor results with make check

make check
....

43% tests passed, 13 tests failed out of 23

Total Test time (real) = 55.36 sec

The following tests FAILED:
2 - gadgetlib1_simple_test (Child aborted)
3 - gadgetlib1_r1cs_ppzksnark_verifier_gadget_test (Child aborted)
7 - gadgetlib2_integration_test (Child aborted)
10 - relations_qap_test (Child aborted)
11 - relations_sap_test (Child aborted)
12 - relations_ssp_test (Child aborted)
13 - zk_proof_systems_bacs_ppzksnark_test (Child aborted)
14 - zk_proof_systems_r1cs_ppzksnark_test (Child aborted)
15 - zk_proof_systems_r1cs_se_ppzksnark_test (Child aborted)
16 - zk_proof_systems_r1cs_gg_ppzksnark_test (Child aborted)
17 - zk_proof_systems_ram_ppzksnark_test (Child aborted)
18 - zk_proof_systems_tbcs_ppzksnark_test (Child aborted)
19 - zk_proof_systems_uscs_ppzksnark_test (Child aborted)

jkrauska avatar Aug 09 '18 04:08 jkrauska

Reposting for clarity and since it fixed my issues in compiling the tutorial. These changes fixed the PROCPS issue from https://github.com/scipr-lab/libsnark/issues/99.

LD_LIBRARY_PATH=/usr/local/opt/openssl/lib:"${LD_LIBRARY_PATH}"                    
CPATH=/usr/local/opt/openssl/include:"${CPATH}"                                    
PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig:"${PKG_CONFIG_PATH}"          
export LD_LIBRARY_PATH CPATH PKG_CONFIG_PATH       

CPPFLAGS=-I/usr/local/opt/openssl/include LDFLAGS=-L/usr/local/opt/openssl/lib PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig cmake -DWITH_PROCPS=OFF -DWITH_SUPERCOP=OFF ..

drewstone avatar Aug 19 '18 03:08 drewstone

pkg-config search-path: /usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/pkgconfig

  1. brew install openssl
ls -l `which openssl`
######/usr/local/bin/openssl -> /usr/local/Cellar/openssl/1.0.2n/bin/openssl
  1. cp /usr/local/Cellar/openssl/1.0.2n/lib/pkgconfig/* /usr/local/lib/pkgconfig/

pkg-config --list-all | grep libcrypto

build:

mkdir build && cd build 
cmake -DWITH_PROCPS=OFF -DWITH_SUPERCOP=OFF ..

lvxv avatar Oct 24 '18 10:10 lvxv