succinctlabs / sp1

A performant, 100% open-source, contributor-friendly zkVM.
https://succinctlabs.github.io/sp1
Apache License 2.0
936 stars 287 forks source link

Compile error during compilation with `bitcoin` crate as dependency #1588

Closed MCJOHN974 closed 10 hours ago

MCJOHN974 commented 15 hours ago

Hi all! I'm very new to sp1 so sorry for noob questions.

I installed sp1 with instruction from sp1 book and cloned example repo. Than I added some code to main which depends on bitcoin crate, and got the following compiler error:

[sp1]  The following warnings were emitted during compilation:
[sp1]  
[sp1]  warning: secp256k1-sys@0.10.1: depend/secp256k1/contrib/lax_der_parsing.c:7:10: fatal error: string.h: No such file or directory
[sp1]  warning: secp256k1-sys@0.10.1:     7 | #include <string.h>
[sp1]  warning: secp256k1-sys@0.10.1:       |          ^~~~~~~~~~
[sp1]  warning: secp256k1-sys@0.10.1: compilation terminated.
[sp1]  warning: secp256k1-sys@0.10.1: In file included from depend/secp256k1/src/util.h:13,
[sp1]  warning: secp256k1-sys@0.10.1:                  from depend/secp256k1/src/field.h:10,
[sp1]  warning: secp256k1-sys@0.10.1:                  from depend/secp256k1/src/group.h:10,
[sp1]  warning: secp256k1-sys@0.10.1:                  from depend/secp256k1/src/precomputed_ecmult_gen.c:3:
[sp1]  warning: secp256k1-sys@0.10.1: /home/ubuntu/.sp1/riscv/riscv32im-linux-x86_64/lib/gcc/riscv32-unknown-elf/11.2.0/include/stdint.h:9:16: fatal error: stdint.h: No such file or directory
[sp1]  warning: secp256k1-sys@0.10.1:     9 | # include_next <stdint.h>
[sp1]  warning: secp256k1-sys@0.10.1:       |                ^~~~~~~~~~
[sp1]  warning: secp256k1-sys@0.10.1: compilation terminated.
[sp1]  
[sp1]  error: failed to run custom build command for `secp256k1-sys v0.10.1`
[sp1]  
[sp1]  Caused by:
[sp1]    process didn't exit successfully: `/home/ubuntu/sp1-project-template/target/elf-compilation/release/build/secp256k1-sys-ab9ee2f8c4ca1323/build-script-build` (exit status: 1)
[sp1]    --- stdout
[sp1]    OUT_DIR = Some(/home/ubuntu/sp1-project-template/target/elf-compilation/riscv32im-succinct-zkvm-elf/release/build/secp256k1-sys-547a8f31f1429475/out)
[sp1]    TARGET = Some(riscv32im-succinct-zkvm-elf)
[sp1]    OPT_LEVEL = Some(3)
[sp1]    HOST = Some(x86_64-unknown-linux-gnu)
[sp1]    cargo:rerun-if-env-changed=CC_riscv32im-succinct-zkvm-elf
[sp1]    CC_riscv32im-succinct-zkvm-elf = None
[sp1]    cargo:rerun-if-env-changed=CC_riscv32im_succinct_zkvm_elf
[sp1]    CC_riscv32im_succinct_zkvm_elf = Some(/home/ubuntu/.sp1/bin/riscv32-unknown-elf-gcc)
[sp1]    RUSTC_WRAPPER = None
[sp1]    cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
[sp1]    cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
[sp1]    CRATE_CC_NO_DEFAULTS = None
[sp1]    DEBUG = Some(false)
[sp1]    CARGO_CFG_TARGET_FEATURE = Some(m)
[sp1]    cargo:rerun-if-env-changed=CFLAGS_riscv32im-succinct-zkvm-elf
[sp1]    CFLAGS_riscv32im-succinct-zkvm-elf = None
[sp1]    cargo:rerun-if-env-changed=CFLAGS_riscv32im_succinct_zkvm_elf
[sp1]    CFLAGS_riscv32im_succinct_zkvm_elf = None
[sp1]    cargo:rerun-if-env-changed=TARGET_CFLAGS
[sp1]    TARGET_CFLAGS = None
[sp1]    cargo:rerun-if-env-changed=CFLAGS
[sp1]    CFLAGS = None
[sp1]    OUT_DIR = Some(/home/ubuntu/sp1-project-template/target/elf-compilation/riscv32im-succinct-zkvm-elf/release/build/secp256k1-sys-547a8f31f1429475/out)
[sp1]    cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
[sp1]    cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
[sp1]    CRATE_CC_NO_DEFAULTS = None
[sp1]    CARGO_CFG_TARGET_FEATURE = Some(m)
[sp1]    cargo:rerun-if-env-changed=CFLAGS_riscv32im-succinct-zkvm-elf
[sp1]    CFLAGS_riscv32im-succinct-zkvm-elf = None
[sp1]    cargo:rerun-if-env-changed=CFLAGS_riscv32im_succinct_zkvm_elf
[sp1]    CFLAGS_riscv32im_succinct_zkvm_elf = None
[sp1]    cargo:rerun-if-env-changed=TARGET_CFLAGS
[sp1]    TARGET_CFLAGS = None
[sp1]    cargo:rerun-if-env-changed=CFLAGS
[sp1]    CFLAGS = None
[sp1]    OUT_DIR = Some(/home/ubuntu/sp1-project-template/target/elf-compilation/riscv32im-succinct-zkvm-elf/release/build/secp256k1-sys-547a8f31f1429475/out)
[sp1]    cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
[sp1]    cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
[sp1]    CRATE_CC_NO_DEFAULTS = None
[sp1]    CARGO_CFG_TARGET_FEATURE = Some(m)
[sp1]    cargo:rerun-if-env-changed=CFLAGS_riscv32im-succinct-zkvm-elf
[sp1]    CFLAGS_riscv32im-succinct-zkvm-elf = None
[sp1]    cargo:rerun-if-env-changed=CFLAGS_riscv32im_succinct_zkvm_elf
[sp1]    CFLAGS_riscv32im_succinct_zkvm_elf = None
[sp1]    cargo:rerun-if-env-changed=TARGET_CFLAGS
[sp1]    TARGET_CFLAGS = None
[sp1]    cargo:rerun-if-env-changed=CFLAGS
[sp1]    CFLAGS = None
[sp1]    cargo:warning=depend/secp256k1/contrib/lax_der_parsing.c:7:10: fatal error: string.h: No such file or directory
[sp1]    cargo:warning=    7 | #include <string.h>
[sp1]    cargo:warning=      |          ^~~~~~~~~~
[sp1]    cargo:warning=compilation terminated.
[sp1]    cargo:warning=In file included from depend/secp256k1/src/util.h:13,
[sp1]    cargo:warning=                 from depend/secp256k1/src/field.h:10,
[sp1]    cargo:warning=                 from depend/secp256k1/src/group.h:10,
[sp1]    cargo:warning=                 from depend/secp256k1/src/precomputed_ecmult_gen.c:3:
[sp1]    cargo:warning=/home/ubuntu/.sp1/riscv/riscv32im-linux-x86_64/lib/gcc/riscv32-unknown-elf/11.2.0/include/stdint.h:9:16: fatal error: stdint.h: No such file or directory
[sp1]    cargo:warning=    9 | # include_next <stdint.h>
[sp1]    cargo:warning=      |                ^~~~~~~~~~
[sp1]    cargo:warning=compilation terminated.
[sp1]  
[sp1]    --- stderr
[sp1]  
[sp1]  
[sp1]    error occurred: Command "/home/ubuntu/.sp1/bin/riscv32-unknown-elf-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-march=rv32im" "-mabi=ilp32" "-I" "depend/secp256k1/" "-I" "depend/secp256k1/include" "-I" "depend/secp256k1/src" "-I" "wasm/wasm-sysroot" "-Wall" "-Wextra" "-Wno-unused-function" "-Wno-unused-parameter" "-DSECP256K1_API=" "-DENABLE_MODULE_ECDH=1" "-DENABLE_MODULE_SCHNORRSIG=1" "-DENABLE_MODULE_EXTRAKEYS=1" "-DENABLE_MODULE_ELLSWIFT=1" "-Dprintf(...)=" "-DECMULT_GEN_PREC_BITS=4" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-DENABLE_MODULE_RECOVERY=1" "-o" "/home/ubuntu/sp1-project-template/target/elf-compilation/riscv32im-succinct-zkvm-elf/release/build/secp256k1-sys-547a8f31f1429475/out/c928380082b86401-precomputed_ecmult_gen.o" "-c" "depend/secp256k1/src/precomputed_ecmult_gen.c" with args riscv32-unknown-elf-gcc did not execute successfully (status code exit status: 1).
[sp1]  
[sp1]  
[sp1]  warning: build failed, waiting for other jobs to finish...

And I have such error with pretty any code which depends on bitcoin crate. I tried this sp1up --c-toolchain but it didn't help. I tried it on macos and ubuntu, same behaviour on both.

Do I miss some setup steps, or this bitcoin crate can not be added to sp1 program this way??

MCJOHN974 commented 10 hours ago

I found solution, this steps helped me: