Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Threadpool: remove stdlib dependencies #293

Merged
merged 16 commits into from
Dec 26, 2023
Merged

Threadpool: remove stdlib dependencies #293

merged 16 commits into from
Dec 26, 2023

Conversation

mratsim
Copy link
Owner

@mratsim mratsim commented Oct 27, 2023

This PR:

  • removes dependency on Nim std/cpuinfo. Fix Remove Nim stdlib dependencies #291
    • implement available threads on OS, taking into account VMs with restricted cores.
    • export the procedure to C and Rust.
      • removes requiring Rust CSPRNG or NumCPUs to reduce supply chain attack surface, see Remove Nim stdlib dependencies #291.
      • We don't do the same in Go at the moment as Go has a runtime which provides the number of CPUs and crypt/rand has cryptographers reviewing and auditing the code. The cryptographic code is also part of OSS-Fuzz.
  • Rework the Rust crate structure to introduce a constantine-core crate with common functionality like csprngs and threadpool.
  • Outline topology detection goals:
    • get_num_threads_logical: with no OS/C stdlib dependency on x86 (all other arch need privileges to access specific registers)
    • get_num_threads_physical: with no OS/C stdlib dependency on x86 (all other arch need privileges to access specific registers)
    • get_num_threads_os: takes into account disabled cores (Virtual machines)
    • get_num_threads_process: Takes into account cgroup and schedaffinity

Previous targets

This addresses #291

  • Counting cores
    • Allow counting physical cores on major platforms (supports FreeBSD, Linux, MacOS including iOS, Windows)
      • Allow counting physical cores without syscalls/IO on Linux x86 (no /proc or /sys read) for hardened trusted enclaves like SGX.
    • Allow counting available cores on Linux when running constrained by cgroups or CPUSET. Evaluate for docker/kubernetes
    • For completeness, allow counting logical cores without std/cpuinfo dependency
      • Allow counting logical cores without syscalls/IO on Linux x86 (no /proc or /sys read) for hardened trusted enclaves like SGX.
  • Runtime trusted setup parsing without allocating a ref object or exceptions
    • Remove std/streams and just use C stdlib File stream API in
      proc loadTrustedSetup*(ctx: ptr EthereumKZGContext, filePath: string): TrustedSetupStatus =
      static: doAssert cpuEndian == littleEndian, "Trusted setup creation is only supported on little-endian CPUs at the moment."
      let f = try: openFileStream(filePath, fmRead)
      except IOError, OSError: return tsMissingFile
      defer:
      try:
      f.close()
      except Exception: # For some reason close can raise a bare Exception.
      quit "Unrecoverable error while closing trusted setup file."
      try:
      var buf = newSeqOfCap[byte](32)
      var len = 0
      buf.setLen(12)
      len = f.readData(buf[0].addr, 12)
      done in Productionize KZG EIP-4844 #304

@mratsim mratsim changed the title Reduce external dependencies and trusted enclaves suitability External dependencies and trusted enclaves suitability Oct 27, 2023
@mratsim mratsim changed the title External dependencies and trusted enclaves suitability Threadpool: remove countProcessors dependencies and improve trusted enclaves suitability Dec 25, 2023
@mratsim mratsim changed the title Threadpool: remove countProcessors dependencies and improve trusted enclaves suitability Threadpool: remove stdlib dependencies Dec 26, 2023
@mratsim mratsim marked this pull request as ready for review December 26, 2023 15:02
@mratsim mratsim merged commit 0a29534 into master Dec 26, 2023
32 checks passed
@mratsim mratsim deleted the audit-deps branch December 26, 2023 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove Nim stdlib dependencies
1 participant