Git Product home page Git Product logo

Comments (7)

mratsim avatar mratsim commented on May 25, 2024 1

After investigating some more, note that zkVM of interest use Risc-V 32-bit instruction, see cargo toolchain update: rust-lang/rust#117958.

The compiler target-triple (an LLVM abstraction) is riscv32im-risc0-zkvm-elf

BLST C/ASM

According to BLST, when the pointer is of size 4 bytes / 32-bit, no assembly should be pulled:

https://github.com/supranational/blst/blob/0d46eefa45fc1e57aceb42bba0e84eab3a7a9725/build/assembly.S#L136-L139

#elif defined(__BLST_NO_ASM__) || \
      (defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__==4)
/* inaccurate way to detect a 32-bit processor, but it's close enough */
#else

And within the code, the fallback to no_asm.h is triggered by __BLST_NO_ASM__ which is automatically set for 32-bit platforms:
https://github.com/supranational/blst/blob/0d46eefa45fc1e57aceb42bba0e84eab3a7a9725/src/vect.h#L28-L36

#else                   /* 32 bits on 32-bit platforms, 64 - on 64-bit */
typedef unsigned long limb_t;
#  ifdef _LP64
#   define LIMB_T_BITS   64
#  else
#   define LIMB_T_BITS   32
#   define __BLST_NO_ASM__
#  endif
#endif

I conclude that for some reason the rust toolchain does not report the pointer size properly or maybe there is cross-compilation mixup somewhere.

BLST Go

Looking at BLST Go further confirm my suspicions on 32-bit platforms: https://github.com/supranational/blst/blob/0d46eefa45fc1e57aceb42bba0e84eab3a7a9725/bindings/go/blst.go#L13-L15

// #cgo CFLAGS: -I${SRCDIR}/.. -I${SRCDIR}/../../build -I${SRCDIR}/../../src -D__BLST_CGO__ -fno-builtin-memcpy -fno-builtin-memset
// #cgo amd64 CFLAGS: -D__ADX__ -mno-avx
// #cgo mips64 mips64le ppc64 ppc64le riscv64 s390x CFLAGS: -D__BLST_NO_ASM__

#cgo has no custom flags for 32-bit, I guess because it's not necessary and detected.
Though I'm not sure why specifying the non-amd64 non-aarch64 platforms is necessary either.

Current conclusion

If the custom toolchain does not setup the cross-compilation for zkVM correctly, I doubt #399 will help, the downstream application will be the better place to pass -D__BLST_NO_ASM__.

If the custom toolchain does setup the cross-compilation correctly, then I think BLST will do the right thing™ and actually nothing will be needed on c-kzg-4844 side.

We're continuing investigation.

from c-kzg-4844.

mratsim avatar mratsim commented on May 25, 2024 1

This is worked on at zkVM-level. Closing.

from c-kzg-4844.

jtraglia avatar jtraglia commented on May 25, 2024

Hey @mratsim, is this problem specific to the Rust bindings? Would you be willing to make a PR for this?

from c-kzg-4844.

jtraglia avatar jtraglia commented on May 25, 2024

Hey again. I made a quick PR which I think will handle this. Do you have a system to test this with?

from c-kzg-4844.

mratsim avatar mratsim commented on May 25, 2024

Other platforms might also need something similar if they use a package manager and integrate building C libraries, like Go and Nim.

I will make a PR.

from c-kzg-4844.

jtraglia avatar jtraglia commented on May 25, 2024

Thanks for the response. Sounds good, keep us updated. I will close #399.

from c-kzg-4844.

jtraglia avatar jtraglia commented on May 25, 2024

Hey @mratsim any updates on this?

from c-kzg-4844.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.