Skip to main content

Precompiles

SP1 provides precompiles for cryptographic operations to reduce execution time and proving costs. Patched cryptography crates use these precompiles from ordinary Rust APIs.

Patched Crates​

Use the entry that matches the package name and version in your guest dependency tree. You only need patches for the crates your program uses. The following table lists the SP1 6.10.0 patch releases and the separate SHA3 0.11 compatibility tag. Each 6.10.0 link opens an immutable GitHub Release with its source commit and release attestation. The SHA3 0.11 link opens its existing Git tag.

PackageCrate versionGit tagCargo entry
bls12_381 (digest 0.10)0.8.0patch-0.8.0-sp1-6.10.0-r1bls12_381 = { git = "https://github.com/sp1-patches/bls12_381", package = "bls12_381", tag = "patch-0.8.0-sp1-6.10.0-r1" }
bls12_381 (digest 0.9)0.8.0patch-0.8.0-sp1-6.10.0-v2-r1bls12_381 = { git = "https://github.com/sp1-patches/bls12_381", package = "bls12_381", tag = "patch-0.8.0-sp1-6.10.0-v2-r1" }
crypto-bigint0.5.5patch-0.5.5-sp1-6.10.0-r2crypto-bigint = { git = "https://github.com/sp1-patches/RustCrypto-bigint", package = "crypto-bigint", tag = "patch-0.5.5-sp1-6.10.0-r2" }
curve25519-dalek4.1.3patch-4.1.3-sp1-6.10.0-r1curve25519-dalek = { git = "https://github.com/sp1-patches/curve25519-dalek", package = "curve25519-dalek", tag = "patch-4.1.3-sp1-6.10.0-r1" }
curve25519-dalek-ng4.1.1patch-4.1.1-sp1-6.10.0-r1curve25519-dalek-ng = { git = "https://github.com/sp1-patches/curve25519-dalek-ng", package = "curve25519-dalek-ng", tag = "patch-4.1.1-sp1-6.10.0-r1" }
ed25519-consensus2.1.0patch-2.1.0-sp1-6.10.0-r1ed25519-consensus = { git = "https://github.com/sp1-patches/ed25519-consensus", package = "ed25519-consensus", tag = "patch-2.1.0-sp1-6.10.0-r1" }
k2560.13.4patch-k256-13.4-sp1-6.10.0k256 = { git = "https://github.com/sp1-patches/elliptic-curves", package = "k256", tag = "patch-k256-13.4-sp1-6.10.0" }
p2560.13.2patch-p256-13.2-sp1-6.10.0p256 = { git = "https://github.com/sp1-patches/elliptic-curves", package = "p256", tag = "patch-p256-13.2-sp1-6.10.0" }
rsa0.9.6patch-0.9.6-sp1-6.10.0-r1rsa = { git = "https://github.com/sp1-patches/RustCrypto-RSA", package = "rsa", tag = "patch-0.9.6-sp1-6.10.0-r1" }
secp256k10.29.1patch-0.29.1-sp1-6.10.0-r1secp256k1 = { git = "https://github.com/sp1-patches/rust-secp256k1", package = "secp256k1", tag = "patch-0.29.1-sp1-6.10.0-r1" }
secp256k10.30.0patch-0.30.0-sp1-6.10.0-r1secp256k1 = { git = "https://github.com/sp1-patches/rust-secp256k1", package = "secp256k1", tag = "patch-0.30.0-sp1-6.10.0-r1" }
sha20.9.8patch-sha2-0.9.8-sp1-6.10.0sha2 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha2", tag = "patch-sha2-0.9.8-sp1-6.10.0" }
sha20.9.9patch-sha2-0.9.9-sp1-6.10.0sha2 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha2", tag = "patch-sha2-0.9.9-sp1-6.10.0" }
sha20.10.6patch-sha2-0.10.6-sp1-6.10.0sha2 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha2", tag = "patch-sha2-0.10.6-sp1-6.10.0" }
sha20.10.8patch-sha2-0.10.8-sp1-6.10.0sha2 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha2", tag = "patch-sha2-0.10.8-sp1-6.10.0" }
sha20.10.9patch-sha2-0.10.9-sp1-6.10.0sha2 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha2", tag = "patch-sha2-0.10.9-sp1-6.10.0" }
sha20.11.0patch-sha2-0.11.0-sp1-6.10.0sha2 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha2", tag = "patch-sha2-0.11.0-sp1-6.10.0" }
sha30.10.8patch-sha3-0.10.8-sp1-6.10.0-r1sha3 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha3", tag = "patch-sha3-0.10.8-sp1-6.10.0-r1" }
substrate-bn0.6.0patch-0.6.0-sp1-6.10.0-substrate-bn-r1substrate-bn = { git = "https://github.com/sp1-patches/bn", package = "substrate-bn", tag = "patch-0.6.0-sp1-6.10.0-substrate-bn-r1" }
substrate-bn-succinct-rs0.6.2patch-0.6.2-sp1-6.10.0substrate-bn-succinct-rs = { git = "https://github.com/sp1-patches/bn", package = "substrate-bn-succinct-rs", tag = "patch-0.6.2-sp1-6.10.0" }
tiny-keccak2.0.2patch-2.0.2-sp1-6.10.0tiny-keccak = { git = "https://github.com/sp1-patches/tiny-keccak", package = "tiny-keccak", tag = "patch-2.0.2-sp1-6.10.0" }
sha30.11.0patch-sha3-0.11.0-sp1-6.0.0sha3 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha3", tag = "patch-sha3-0.11.0-sp1-6.0.0" }

The crate version and the SP1 version in a tag are separate values. For example, patch-p256-13.2-sp1-6.10.0 contains package p256 version 0.13.2. Use SP1 6.10.0 for the 6.10.0 patch set, and check dependency manifests for minimum version requirements. See the upgrade guide when updating an existing application.

If you need another patched library or version, open an SP1 issue.

Using Patched Crates​

Put patches in the Cargo.toml at the root of the workspace that builds your guest program. If your host and guest use separate workspaces, their patches and lockfiles are separate too. Copy the required Cargo entries from the table into the [patch.crates-io] section of that file. For multiple versions of one package, give each entry a unique key and keep its package value.

Patching crates.io Dependencies​

For p256 version 0.13.2:

[dependencies]
p256 = "=0.13.2"

[patch.crates-io]
p256 = { git = "https://github.com/sp1-patches/elliptic-curves", tag = "patch-p256-13.2-sp1-6.10.0" }

After changing a patch, update the lockfile in that workspace:

cargo update -p p256 --precise 0.13.2
cargo tree -p p256

The resolved package must show the intended Git source and tag:

p256 v0.13.2 (https://github.com/sp1-patches/elliptic-curves?tag=patch-p256-13.2-sp1-6.10.0#...)

Patching GitHub Dependencies​

For an upstream Git dependency, use the upstream repository URL in the patch section:

[dependencies]
p256 = { git = "https://github.com/RustCrypto/elliptic-curves", tag = "p256/v0.13.2" }

[patch."https://github.com/RustCrypto/elliptic-curves"]
p256 = { git = "https://github.com/sp1-patches/elliptic-curves", tag = "patch-p256-13.2-sp1-6.10.0" }

Checking Resolved Dependencies​

Run cargo tree from the guest workspace and inspect its Cargo.lock. Check the package name, version, and Git source for each patch. An entry under [[patch.unused]] means that Cargo did not use that patch. If several versions of a crate are present, check each one that your program uses. A patch for SHA3 0.10 cannot replace a dependency that requires SHA3 0.11.

After updating the lockfile, rebuild the guest ELF and test proof generation and verification. Changing a host dependency or a patch declaration does not update an existing ELF.

Compatibility Notes​

BN​

substrate-bn and substrate-bn-succinct-rs are different package names. Select the matching table entry for a Git patch. For a registry dependency, use substrate-bn-succinct-rs 0.6.2.

[dependencies]
substrate-bn-succinct-rs = "0.6.2"

sp1-verifier 6.10.0 requires substrate-bn-succinct-rs 0.6.1 or a compatible newer version. If the verifier already brings in BN from crates.io, update the existing lockfile entry from the workspace root.

cargo update -p substrate-bn-succinct-rs --precise 0.6.2
cargo tree --locked -i substrate-bn-succinct-rs

BLS12-381​

For SP1 6.10.0, the -r1 BLS tag uses digest 0.10. Use the -v2-r1 tag for digest 0.9. Choose the variant that matches your dependency's API.

The separately named registry package is available as:

[dependencies]
sp1_bls12_381 = "=0.8.0-sp1-6.10.0"

A Git patch for package bls12_381 does not replace package sp1_bls12_381. Check both names in the guest lockfile if your dependency graph uses both.

secp256k1​

The -r1 tags for 0.29.1 and 0.30.0 match native libsecp256k1 on these ECDSA inputs. For a zero r or s, recover_ecdsa returns InvalidSignature and verify_ecdsa returns IncorrectSignature. Recovery accepts valid high-s signatures. Verification rejects high-s signatures.

K256/P256​

K256 and P256 use a patched ecdsa dependency. Prefer their ecdsa reexports when sharing types with these crates. A separate direct ecdsa dependency can resolve to a different source and produce incompatible types.

Rust Toolchain​

The secp256k1 0.29.1 patch declares Rust 1.85 as its minimum version. SHA2 0.11 and SHA3 0.11 also require Rust 1.85. Check the requirements of the full dependency graph when selecting a toolchain.

alloy-primitives keccak256​

alloy-primitives selects its keccak256 implementation through Cargo features. The default uses tiny-keccak; the sha3-keccak feature selects sha3. Patch the crate and version that your build enables. For a dependency on sha3 ^0.11, use the SHA3 0.11 tag in the table. A SHA3 0.10 patch does not satisfy that requirement and can leave software hashing enabled.

KZG Acceleration​

kzg-rs provides KZG operations through the patched BLS crate. Use the published registry version:

[dependencies]
kzg-rs = "0.2.9"

Version 0.2.9 pins sp1_bls12_381 to 0.8.0-sp1-6.10.0 in both its runtime and build dependencies. Check that the guest lockfile resolves these versions and that older Git overrides do not replace them. For revm, check which kzg-rs version its kzg-rs feature selects.

Troubleshooting​

Verifying Precompile Execution​

Cargo resolution confirms which source was selected. To check whether an input uses a precompile, inspect ExecutionReport.syscall_counts after guest execution. For SHA256, check SHA_EXTEND and SHA_COMPRESS. See the patch testing example. Then generate and verify a proof for the program.

Cargo Git Fetch Issues​

If Cargo cannot fetch a Git dependency, retry with the Git CLI:

CARGO_NET_GIT_FETCH_WITH_CLI=true cargo update -p <patch-crate-name>