diff --git a/Cargo.lock b/Cargo.lock index 007cbb7..37ec609 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -226,12 +226,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - [[package]] name = "base64ct" version = "1.6.0" @@ -597,18 +591,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array 0.14.7", - "rand_core 0.6.4", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -669,7 +651,6 @@ dependencies = [ "block-buffer 0.10.4", "const-oid", "crypto-common", - "subtle", ] [[package]] @@ -724,45 +705,12 @@ dependencies = [ "wio", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest 0.10.7", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - [[package]] name = "either" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest 0.10.7", - "ff", - "generic-array 0.14.7", - "group", - "pkcs8", - "rand_core 0.6.4", - "sec1", - "subtle", - "zeroize", -] - [[package]] name = "embedded-io" version = "0.4.0" @@ -800,16 +748,6 @@ dependencies = [ "simd-adler32", ] -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "rand_core 0.6.4", - "subtle", -] - [[package]] name = "fixedbitset" version = "0.5.6" @@ -916,7 +854,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -951,23 +888,12 @@ dependencies = [ "weezl", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core 0.6.4", - "subtle", -] - [[package]] name = "guest" version = "0.1.0" dependencies = [ "jolt-sdk", - "k256", + "rsa", ] [[package]] @@ -1008,7 +934,7 @@ dependencies = [ "hash32", "rustc_version", "serde", - "spin", + "spin 0.9.8", "stable_deref_trait", ] @@ -1030,15 +956,6 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest 0.10.7", -] - [[package]] name = "iana-time-zone" version = "0.1.60" @@ -1156,8 +1073,8 @@ version = "0.1.0" dependencies = [ "guest", "jolt-sdk", - "k256", "rand_core 0.6.4", + "rsa", ] [[package]] @@ -1206,20 +1123,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2", - "signature", -] - [[package]] name = "keccak" version = "0.1.5" @@ -1234,6 +1137,9 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin 0.5.2", +] [[package]] name = "libc" @@ -1251,6 +1157,12 @@ dependencies = [ "windows-targets 0.52.4", ] +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + [[package]] name = "libredox" version = "0.1.3" @@ -1326,6 +1238,23 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-bigint-dig" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" +dependencies = [ + "byteorder", + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand 0.8.5", + "smallvec", + "zeroize", +] + [[package]] name = "num-integer" version = "0.1.46" @@ -1335,6 +1264,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.18" @@ -1342,6 +1282,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -1420,9 +1361,9 @@ dependencies = [ [[package]] name = "pathfinder_simd" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0444332826c70dc47be74a7c6a5fc44e23a7905ad6858d4162b658320455ef93" +checksum = "ebf45976c56919841273f2a0fc684c28437e2f304e264557d9c72be5d5a718be" dependencies = [ "rustc_version", ] @@ -1433,6 +1374,17 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + [[package]] name = "pkcs8" version = "0.10.2" @@ -1684,22 +1636,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] -name = "rfc6979" -version = "0.4.0" +name = "rgb" +version = "0.8.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +checksum = "05aaa8004b64fd573fc9d002f4e632d51ad4f026c2b5ba95fcb6c2f32c2c47d8" dependencies = [ - "hmac", - "subtle", + "bytemuck", ] [[package]] -name = "rgb" -version = "0.8.37" +name = "rsa" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05aaa8004b64fd573fc9d002f4e632d51ad4f026c2b5ba95fcb6c2f32c2c47d8" +checksum = "5d0e5124fcb30e76a7e79bfee683a2746db83784b86289f6251b54b7950a0dfc" dependencies = [ - "bytemuck", + "const-oid", + "digest 0.10.7", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core 0.6.4", + "sha2", + "signature", + "spki", + "subtle", + "zeroize", ] [[package]] @@ -1749,20 +1712,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array 0.14.7", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "semver" version = "1.0.22" @@ -1855,6 +1804,12 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "spin" version = "0.9.8" diff --git a/Cargo.toml b/Cargo.toml index 7878f7e..c549e13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,10 +16,8 @@ jolt = { package = "jolt-sdk", git = "https://github.com/a16z/jolt", features = "std", ] } guest = { path = "./guest" } -k256 = "0.13.3" rand_core = "0.6.4" -# rsa = { version = "0.9.6", default-features = false, features = ["sha2"] } -# rand = "0.8.5" +rsa = { version = "0.9.6", default-features = false, features = ["sha2"] } [patch.crates-io] ark-ff = { git = "https://github.com/a16z/arkworks-algebra", branch = "optimize/field-from-u64" } diff --git a/guest/Cargo.toml b/guest/Cargo.toml index 4ceeef6..b4e1117 100644 --- a/guest/Cargo.toml +++ b/guest/Cargo.toml @@ -11,6 +11,5 @@ path = "./src/lib.rs" guest = [] [dependencies] -k256 = { version = "0.13.3", default-features = false, features = ["schnorr"] } jolt = { package = "jolt-sdk", git = "https://github.com/a16z/jolt" } -# rsa = { version = "0.9.6", default-features = false, features = ["sha2"] } +rsa = { version = "0.9.6", default-features = false, features = ["sha2"] } \ No newline at end of file diff --git a/guest/src/lib.rs b/guest/src/lib.rs index c8851d8..44acd58 100644 --- a/guest/src/lib.rs +++ b/guest/src/lib.rs @@ -17,28 +17,16 @@ fn fib(n: u32) -> u128 { b } -/// Verify Schnorr Signature -/// Trace length: 169422912 +/// Verify RSA Signature +/// Trace length: #[jolt::provable(stack_size = 100000, memory_size = 10000000)] -fn schnorr(message: &[u8], verifying_key_bytes: &[u8], signature_bytes: &[u8]) { - use k256::schnorr::{Signature, signature::Verifier, VerifyingKey}; - let verifying_key = VerifyingKey::from_bytes(&verifying_key_bytes).unwrap(); +fn rsa(message: &[u8], verifying_key_bytes: &[u8], signature_bytes: &[u8]) { + use rsa::pkcs1v15::VerifyingKey; + use rsa::signature::Verifier; + use rsa::{pkcs1::DecodeRsaPublicKey, pkcs1v15::Signature, sha2::Sha256}; + let verifying_key: VerifyingKey = VerifyingKey::from_pkcs1_der(&verifying_key_bytes).unwrap(); let signature = Signature::try_from(signature_bytes).unwrap(); verifying_key .verify(message, &signature) .unwrap(); -} - -// /// Verify RSA Signature -// /// Trace length: -// #[jolt::provable(stack_size = 100000, memory_size = 10000000)] -// fn rsa(message: &[u8], verifying_key_bytes: &[u8], signature_bytes: &[u8]) { -// use rsa::pkcs1v15::VerifyingKey; -// use rsa::signature::Verifier; -// use rsa::{pkcs1::DecodeRsaPublicKey, pkcs1v15::Signature, sha2::Sha256}; -// let verifying_key: VerifyingKey = VerifyingKey::from_pkcs1_der(&verifying_key_bytes).unwrap(); -// let signature = Signature::try_from(signature_bytes).unwrap(); -// verifying_key -// .verify(message, &signature) -// .unwrap(); -// } \ No newline at end of file +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 7f26d3d..bb93f90 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,37 +14,6 @@ pub fn main() { let (_output, _proof) = prove_fib(1000); }); - { - // Schnorr Signature - use k256::schnorr::{signature::Signer, SigningKey}; - use rand_core::OsRng; // requires 'getrandom' feature - - let message = b"Schnorr signatures prove knowledge of a secret in the random oracle model"; - // Signing - let signing_key = SigningKey::random(&mut OsRng); // serialize with `.to_bytes()` - let verifying_key_bytes = signing_key.verifying_key().to_bytes(); // 32-bytes - let signature = signing_key.sign(message); // returns `k256::schnorr::Signature` - let signature_bytes = signature.to_bytes(); // 64-bytes - print_time("native Schnorr verify", || { - guest::execute_schnorr( - message, - verifying_key_bytes.as_slice(), - signature_bytes.as_slice(), - ); - }); - let (prove_schnorr, _verify_schnorr) = guest::build_schnorr(); - print_time("zkVM Schnorr verify", || { - let (_output, _proof) = prove_schnorr( - message, - verifying_key_bytes.as_slice(), - signature_bytes.as_slice(), - ); - }); - // let is_valid = verify_schnorr(proof); - // println!("output: {}", output); - // println!("valid: {}", is_valid); - } - /* { // RSA Signature use rsa::pkcs1v15::{SigningKey, VerifyingKey}; @@ -52,17 +21,16 @@ pub fn main() { use rsa::sha2::{Digest, Sha256}; use rsa::signature::{Keypair, RandomizedSigner, SignatureEncoding, Verifier}; use rsa::RsaPrivateKey; - - let mut rng = rand::thread_rng(); + use rand_core::OsRng; let bits = 2048; - let private_key = RsaPrivateKey::new(&mut rng, bits).expect("failed to generate a key"); + let private_key = RsaPrivateKey::new(&mut OsRng, bits).expect("failed to generate a key"); let signing_key = SigningKey::::new(private_key); let verifying_key = signing_key.verifying_key(); // Sign let data = b"hello world"; - let signature = signing_key.sign_with_rng(&mut rng, data); + let signature = signing_key.sign_with_rng(&mut OsRng, data); assert_ne!(signature.to_bytes().as_ref(), data.as_slice()); let signature_bytes = signature.to_bytes(); let verifying_key_bytes = verifying_key.to_pkcs1_der().unwrap(); @@ -83,5 +51,4 @@ pub fn main() { ); }); } - */ }