Skip to content

Commit

Permalink
Merge pull request #21 from yetanotherco/feat/precompile_fixes
Browse files Browse the repository at this point in the history
feat(Precompiles): Doc Updates
  • Loading branch information
PatStiles authored Aug 23, 2024
2 parents efb23ae + 8c1726e commit 41cb442
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,18 @@ cargo run --release -- prove-sp1 --submit-to-aligned-with-keystore <PATH_TO_KEYS

- `--precompiles`: Enables in acceleration via precompiles for supported zkVM's. Specifying this flag allows for VM specific speedups for specific expensive operations such as SHA256, SHA3, bigint multiplication, and ed25519 signature verification. By specifying this flag proving operations for specific operations within the following rust crates are accelerated:
- SP1:
- `sha2`
- `sha3`
- `crypto-bigint`
- `tiny-keccak`
- `ed25519-consensus`
- `ecdsa-core`
- `secp256k1`
- `sha2 v0.10.6`
- `sha3 v0.10.8`
- `crypto-bigint v0.5.5`
- `tiny-keccak v2.0.2`
- `ed25519-consensus v2.1.0`
- `ecdsa-core v0.16.9`
- `secp256k1 v0.29.0`
- Risc0:
- `sha2`
- `k256`
- `crypto-bigint`
- `sha2 v0.10.6`
- `k256 v0.13.1`
- `crypto-bigint v0.5.5`
NOTE: for the precompiles to be included within the compilation step the crate version you are using must match the crate version above.

## Limitations:
Currently zkRust does not support fully support the following:
Expand Down
2 changes: 1 addition & 1 deletion examples/ecdsa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ edition = "2021"
[dependencies]
rand_core = "0.6.4"
hex-literal = "0.4"
k256 = { version = "=0.13.3", features = ["arithmetic", "serde", "expose-field", "std", "ecdsa"], default_features = false }
k256 = { version = "=0.13.1", features = ["arithmetic", "serde", "expose-field", "std", "ecdsa"], default_features = false }
2 changes: 1 addition & 1 deletion examples/rsa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ edition = "2021"
digest = "0.10.7"
rand = "0.8.5"
rsa = "0.6.0" # Check for the latest version
sha2 = "0.10.8"
sha2 = "0.10.6"
2 changes: 1 addition & 1 deletion src/risc0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub const RISC0_GUEST_PROGRAM_HEADER_STD: &str =
"#![no_main]\n\nrisc0_zkvm::guest::entry!(main);\n";

/// RISC0 Cargo patch for accelerated SHA-256, K256, and bigint-multiplication circuits
pub const RISC0_ACCELERATION_IMPORT: &str = "\n[patch.crates-io]\nsha2 = { git = \"https://github.com/risc0/RustCrypto-hashes\", tag = \"sha2-v0.10.6-risczero.0\" }\nk256 = { git = \"https://github.com/risc0/RustCrypto-elliptic-curves\", tag = \"k256/v0.13.1-risczero.1\" }\ncrypto-bigint = { git = \"https://github.com/risc0/RustCrypto-crypto-bigint\", tag = \"v0.5.2-risczero.0\" }";
pub const RISC0_ACCELERATION_IMPORT: &str = "\n[patch.crates-io]\nsha2 = { git = \"https://github.com/risc0/RustCrypto-hashes\", tag = \"sha2-v0.10.6-risczero.0\" }\nk256 = { git = \"https://github.com/risc0/RustCrypto-elliptic-curves\", tag = \"k256/v0.13.1-risczero.1\" }\ncrypto-bigint = { git = \"https://github.com/risc0/RustCrypto-crypto-bigint\", tag = \"v0.5.5-risczero.0\" }";

/// This function mainly adds this header to the guest in order for it to be proven by
/// risc0:
Expand Down
6 changes: 4 additions & 2 deletions src/sp1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub const SP1_PROOF_PATH: &str = "./proof_data/sp1/sp1.proof";
pub const SP1_PROGRAM_HEADER: &str = "#![no_main]\nsp1_zkvm::entrypoint!(main);\n";

/// SP1 Cargo patch for accelerated SHA-256, K256, and bigint-multiplication circuits
pub const SP1_ACCELERATION_IMPORT: &str = "\n[patch.crates-io]\nsha2-v0-10-8 = { git = \"https://github.com/sp1-patches/RustCrypto-hashes\", package = \"sha2\", branch = \"patch-sha2-v0.10.8\" }\nsha3-v0-10-8 = { git = \"https://github.com/sp1-patches/RustCrypto-hashes\", package = \"sha3\", branch = \"patch-sha3-v0.10.8\" }\ncrypto-bigint = { git = \"https://github.com/sp1-patches/RustCrypto-bigint\", branch = \"patch-v0.5.5\" }\ntiny-keccak = { git = \"https://github.com/sp1-patches/tiny-keccak\", branch = \"patch-v2.0.2\" }\ned25519-consensus = { git = \"https://github.com/sp1-patches/ed25519-consensus\", branch = \"patch-v2.1.0\" }\necdsa-core = { git = \"https://github.com/sp1-patches/signatures\", package = \"ecdsa\", branch = \"patch-ecdsa-v0.16.9\" }\n";
pub const SP1_ACCELERATION_IMPORT: &str = "\n[patch.crates-io]\nsha2 = { git = \"https://github.com/sp1-patches/RustCrypto-hashes\", package = \"sha2\", branch = \"patch-sha2-v0.10.6\" }\nsha3 = { git = \"https://github.com/sp1-patches/RustCrypto-hashes\", package = \"sha3\", branch = \"patch-sha3-v0.10.8\" }\ncrypto-bigint = { git = \"https://github.com/sp1-patches/RustCrypto-bigint\", branch = \"patch-v0.5.5\" }\ntiny-keccak = { git = \"https://github.com/sp1-patches/tiny-keccak\", branch = \"patch-v2.0.2\" }\ned25519-consensus = { git = \"https://github.com/sp1-patches/ed25519-consensus\", branch = \"patch-v2.1.0\" }\necdsa-core = { git = \"https://github.com/sp1-patches/signatures\", package = \"ecdsa\", branch = \"patch-ecdsa-v0.16.9\" }\n";

/// This function mainly adds this header to the guest in order for it to be proven by
/// sp1:
Expand All @@ -34,11 +34,13 @@ pub fn prepare_sp1_program() -> io::Result<()> {
/// Generates SP1 proof and ELF
pub fn generate_sp1_proof() -> io::Result<()> {
let guest_path = fs::canonicalize(SP1_SCRIPT_DIR)?;

Command::new("cargo")
.arg("run")
.arg("--release")
.current_dir(guest_path)
.status()?;
.status()
.unwrap();

Ok(())
}

0 comments on commit 41cb442

Please sign in to comment.