feat: add standalone zkvm guest target - #2
Conversation
defined(standalone) shims for platforms with no OS primitives: - sysrand: deterministic zero-fill stub (no OS CSPRNG; the zkVM circuit guarantees integrity, so side-channel blinding is unnecessary) - threadpool: route barriers/futexes/topology/threads to *_standalone single-hart implementations
Single-hart zkVM guest implementations: - panicoverride: trap loop instead of OS abort - barriers_standalone: N=1 barrier releases immediately - futexes_standalone: spin-wait degenerates to a fence with one worker - threads_standalone: createThread traps (spawn loop is empty at n=1) - topology_standalone: report one core / one available thread
Signed-off-by: Roman <4833306+Filter94@users.noreply.github.com>
Signed-off-by: Roman <4833306+Filter94@users.noreply.github.com>
Signed-off-by: Roman <4833306+Filter94@users.noreply.github.com>
Signed-off-by: Roman <4833306+Filter94@users.noreply.github.com>
…on function name to zkvm as well Signed-off-by: Roman <4833306+Filter94@users.noreply.github.com>
Signed-off-by: Roman <4833306+Filter94@users.noreply.github.com>
…grams Signed-off-by: Roman <4833306+Filter94@users.noreply.github.com>
Signed-off-by: Roman <4833306+Filter94@users.noreply.github.com>
Signed-off-by: Roman <4833306+Filter94@users.noreply.github.com>
Signed-off-by: Roman <4833306+Filter94@users.noreply.github.com>
Signed-off-by: Roman <4833306+Filter94@users.noreply.github.com>
Review Comments1.
|
Signed-off-by: Ivo Kubjas <ivo.kubjas@consensys.net>
Signed-off-by: Ivo Kubjas <ivo.kubjas@consensys.net>
|
Second review round. The guest build and archive checks pass locally and the freestanding plug looks minimal and correct — no findings there. One request:
The canonical-scalar checks are load-bearing here because |
…recompile fix: BN254 pairing precompile bypass
Thanks for the comments! I addressed them |
ivokub
left a comment
There was a problem hiding this comment.
Looks good, thanks for the fixes. For downstream usage, have a look at the comment below
make_lib_riscv64_freestanding now requires llvm-nm in addition to llvm-ar. The new archive symbol-check gate at the end of the task (constantine.nimble:369-375
()) shells out to tests/check_riscv64_freestanding_archive.sh with an llvm-nm binary,constantine/constantine.nimble
Lines 369 to 375 in ba2b28f
resolved via LLVM_NM env var → Homebrew fallbacks → plain llvm-nm on PATH. That matches the existing llvm-ar resolution, so the toolchain surface just grows by one tool.Two small downstream implications:
zkevm-monorepo/riscv-guests's guest-crypto-ctt/build.zig resolves and forwards LLVM_AR explicitly but doesn't know about LLVM_NM — a fresh machine with llvm-ar but no llvm-nm on PATH will fail at the very end
of the archive build, after all compilation succeeded. Worth a one-line addition to the install-constantine-deps make target/docs (and possibly an LLVM_NM forward in guest-crypto-ctt/build.zig for symmetry)
when the pinned Constantine commit is bumped to include this PR.If CTT_OUTDIR is ever used to redirect the archive outside the dependency tree (the new env override), note the symbol check runs against that redirected path, which is the desired behavior — just worth knowing
the check is no longer anchored to lib/ when overriding.
This PR adds the EVM precompiles and makes the library compilable to R5 standalone target.
Note
High Risk
Touches KZG trusted-setup loading, pairing correctness, and new cryptographic entry points for bare-metal builds; BN254 fix changes EVM pairing behavior for mixed infinity inputs.
Overview
Adds a freestanding RISC-V64 (rv64im) build path for zkVM guests: Nim
--os:standalonegates file I/O and stdio, a clang shim plus stub headers/standalone_stdio.csatisfy the runtime, andmake_lib_riscv64_freestandingproduceslibconstantine.riscv64.awith embedded KZG verification-only (CTT_EMBEDDED_KZG+CTT_KZG_VERIFICATION_ONLY), no threads, and an archive symbol check.Embedded KZG can load the full ceremony from a compile-time
.datblob (ctt_eth_kzg_context_new_embedded) or, in verification-only mode, only embed[τ]G2and strip prover/PeerDAS APIs viafullKzgContext/fullKzgApimacros and slimmer C headers.zkVM secp256k1 adds raw
eth_zkvm_secp256k1_ecrecover/eth_zkvm_secp256k1_verify(digest-in, strict scalar checks, newcttEVM_MalformedSignature) plusverifyFromDigestfor ECDSA.BN254 pairing (EIP-197) fixes a regression where seeing an infinity pair short-circuited the whole check to success; infinity pairs are now skipped in the product like the spec expects, with dedicated tests/vectors.
CI gains embedded-KZG test batches, BN254 pairing and zkVM secp256k1 suites, and
.gitattributesLF enforcement for the embedded setup file.Reviewed by Cursor Bugbot for commit ba2b28f. Bugbot is set up for automated code reviews on this repo. Configure here.