From c290578665bee405035af2b07d1947b674bf83f3 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Tue, 13 May 2025 17:22:45 +0100 Subject: [PATCH] add initial jolt code --- Cargo.lock | 869 +++++++++++++++++++++++++++- Cargo.toml | 11 +- crates/ere-jolt/Cargo.toml | 24 + crates/ere-jolt/src/jolt_methods.rs | 91 +++ crates/ere-jolt/src/lib.rs | 154 +++++ crates/ere-jolt/src/utils.rs | 75 +++ 6 files changed, 1192 insertions(+), 32 deletions(-) create mode 100644 crates/ere-jolt/Cargo.toml create mode 100644 crates/ere-jolt/src/jolt_methods.rs create mode 100644 crates/ere-jolt/src/lib.rs create mode 100644 crates/ere-jolt/src/utils.rs diff --git a/Cargo.lock b/Cargo.lock index 1eb3e10..38970c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,7 +62,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2179ba839ac532f50279f5da2a6c5047f791f03f6f808b4dfab11327b97902f" dependencies = [ "alloy-eips", - "alloy-primitives", + "alloy-primitives 1.1.0", "alloy-rlp", "alloy-serde", "alloy-trie", @@ -86,7 +86,7 @@ checksum = "aec6f67bdc62aa277e0ec13c1b1fb396c8a62b65c8e9bd8c1d3583cc6d1a8dd3" dependencies = [ "alloy-consensus", "alloy-eips", - "alloy-primitives", + "alloy-primitives 1.1.0", "alloy-rlp", "alloy-serde", "serde", @@ -98,7 +98,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "741bdd7499908b3aa0b159bba11e71c8cddd009a2c2eb7a06e825f1ec87900a5" dependencies = [ - "alloy-primitives", + "alloy-primitives 1.1.0", "alloy-rlp", "crc", "serde", @@ -111,7 +111,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b82752a889170df67bbb36d42ca63c531eb16274f0d7299ae2a680facba17bd" dependencies = [ - "alloy-primitives", + "alloy-primitives 1.1.0", "alloy-rlp", "serde", ] @@ -122,7 +122,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "804cefe429015b4244966c006d25bda5545fa9db5990e9c9079faf255052f50a" dependencies = [ - "alloy-primitives", + "alloy-primitives 1.1.0", "alloy-rlp", "serde", "thiserror 2.0.12", @@ -137,7 +137,7 @@ dependencies = [ "alloy-eip2124", "alloy-eip2930", "alloy-eip7702", - "alloy-primitives", + "alloy-primitives 1.1.0", "alloy-rlp", "alloy-serde", "auto_impl", @@ -154,7 +154,7 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0068ae277f5ee3153a95eaea8ff10e188ed8ccde9b7f9926305415a2c0ab2442" dependencies = [ - "alloy-primitives", + "alloy-primitives 1.1.0", "alloy-sol-type-parser", "serde", "serde_json", @@ -166,8 +166,8 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3994ab6ff6bdeb5aebe65381a8f6a47534789817570111555e8ac413e242ce06" dependencies = [ - "alloy-primitives", - "alloy-sol-types", + "alloy-primitives 1.1.0", + "alloy-sol-types 1.1.0", "serde", "serde_json", "thiserror 2.0.12", @@ -185,12 +185,12 @@ dependencies = [ "alloy-eips", "alloy-json-rpc", "alloy-network-primitives", - "alloy-primitives", + "alloy-primitives 1.1.0", "alloy-rpc-types-any", "alloy-rpc-types-eth", "alloy-serde", "alloy-signer", - "alloy-sol-types", + "alloy-sol-types 1.1.0", "async-trait", "auto_impl", "derive_more 2.0.1", @@ -208,11 +208,33 @@ checksum = "498f2ee2eef38a6db0fc810c7bf7daebdf5f2fa8d04adb8bd53e54e91ddbdea3" dependencies = [ "alloy-consensus", "alloy-eips", - "alloy-primitives", + "alloy-primitives 1.1.0", "alloy-serde", "serde", ] +[[package]] +name = "alloy-primitives" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccb3ead547f4532bc8af961649942f0b9c16ee9226e26caa3f38420651cc0bf4" +dependencies = [ + "alloy-rlp", + "bytes", + "cfg-if", + "const-hex", + "derive_more 0.99.20", + "hex-literal", + "itoa", + "k256", + "keccak-asm", + "proptest", + "rand 0.8.5", + "ruint", + "serde", + "tiny-keccak", +] + [[package]] name = "alloy-primitives" version = "1.1.0" @@ -283,10 +305,10 @@ dependencies = [ "alloy-consensus-any", "alloy-eips", "alloy-network-primitives", - "alloy-primitives", + "alloy-primitives 1.1.0", "alloy-rlp", "alloy-serde", - "alloy-sol-types", + "alloy-sol-types 1.1.0", "itertools 0.14.0", "serde", "serde_json", @@ -299,7 +321,7 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4dba6ff08916bc0a9cbba121ce21f67c0b554c39cf174bc7b9df6c651bd3c3b" dependencies = [ - "alloy-primitives", + "alloy-primitives 1.1.0", "serde", "serde_json", ] @@ -310,7 +332,7 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c580da7f00f3999e44e327223044d6732358627f93043e22d92c583f6583556" dependencies = [ - "alloy-primitives", + "alloy-primitives 1.1.0", "async-trait", "auto_impl", "either", @@ -327,7 +349,7 @@ checksum = "a00f0f07862bd8f6bc66c953660693c5903062c2c9d308485b2a6eee411089e7" dependencies = [ "alloy-consensus", "alloy-network", - "alloy-primitives", + "alloy-primitives 1.1.0", "alloy-signer", "async-trait", "k256", @@ -335,27 +357,59 @@ dependencies = [ "thiserror 2.0.12", ] +[[package]] +name = "alloy-sol-macro" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b40397ddcdcc266f59f959770f601ce1280e699a91fc1862f29cef91707cd09" +dependencies = [ + "alloy-sol-macro-expander 0.7.7", + "alloy-sol-macro-input 0.7.7", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.101", +] + [[package]] name = "alloy-sol-macro" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d3ef8e0d622453d969ba3cded54cf6800efdc85cb929fe22c5bdf8335666757" dependencies = [ - "alloy-sol-macro-expander", - "alloy-sol-macro-input", + "alloy-sol-macro-expander 1.1.0", + "alloy-sol-macro-input 1.1.0", "proc-macro-error2", "proc-macro2", "quote", "syn 2.0.101", ] +[[package]] +name = "alloy-sol-macro-expander" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "867a5469d61480fea08c7333ffeca52d5b621f5ca2e44f271b117ec1fc9a0525" +dependencies = [ + "alloy-sol-macro-input 0.7.7", + "const-hex", + "heck 0.5.0", + "indexmap 2.9.0", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.101", + "syn-solidity 0.7.7", + "tiny-keccak", +] + [[package]] name = "alloy-sol-macro-expander" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0e84bd0693c69a8fbe3ec0008465e029c6293494df7cb07580bf4a33eff52e1" dependencies = [ - "alloy-sol-macro-input", + "alloy-sol-macro-input 1.1.0", "const-hex", "heck 0.5.0", "indexmap 2.9.0", @@ -363,10 +417,25 @@ dependencies = [ "proc-macro2", "quote", "syn 2.0.101", - "syn-solidity", + "syn-solidity 1.1.0", "tiny-keccak", ] +[[package]] +name = "alloy-sol-macro-input" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e482dc33a32b6fadbc0f599adea520bd3aaa585c141a80b404d0a3e3fa72528" +dependencies = [ + "const-hex", + "dunce", + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.101", + "syn-solidity 0.7.7", +] + [[package]] name = "alloy-sol-macro-input" version = "1.1.0" @@ -380,7 +449,7 @@ dependencies = [ "proc-macro2", "quote", "syn 2.0.101", - "syn-solidity", + "syn-solidity 1.1.0", ] [[package]] @@ -393,6 +462,18 @@ dependencies = [ "winnow 0.7.10", ] +[[package]] +name = "alloy-sol-types" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a91ca40fa20793ae9c3841b83e74569d1cc9af29a2f5237314fd3452d51e38c7" +dependencies = [ + "alloy-primitives 0.7.7", + "alloy-sol-macro 0.7.7", + "const-hex", + "serde", +] + [[package]] name = "alloy-sol-types" version = "1.1.0" @@ -400,8 +481,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5460a975434ae594fe2b91586253c1beb404353b78f0a55bf124abcd79557b15" dependencies = [ "alloy-json-abi", - "alloy-primitives", - "alloy-sol-macro", + "alloy-primitives 1.1.0", + "alloy-sol-macro 1.1.0", "const-hex", "serde", ] @@ -412,7 +493,7 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "983d99aa81f586cef9dae38443245e585840fcf0fc58b09aee0b1f27aed1d500" dependencies = [ - "alloy-primitives", + "alloy-primitives 1.1.0", "alloy-rlp", "arrayvec", "derive_more 2.0.1", @@ -502,6 +583,38 @@ version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" +[[package]] +name = "ark-bn254" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d69eab57e8d2663efa5c63135b2af4f396d66424f88954c21104125ab6b3e6bc" +dependencies = [ + "ark-ec", + "ark-ff 0.5.0", + "ark-std 0.5.0", +] + +[[package]] +name = "ark-ec" +version = "0.5.0" +source = "git+https://github.com/a16z/arkworks-algebra?branch=v0.5.0-optimize-mul-u64#4ae5018533f1e757bb321e21927c8bbbf8c27ffc" +dependencies = [ + "ahash", + "ark-ff 0.5.0", + "ark-poly", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "educe", + "fnv", + "hashbrown 0.15.3", + "itertools 0.13.0", + "num-bigint 0.4.6", + "num-integer", + "num-traits", + "rayon", + "zeroize", +] + [[package]] name = "ark-ff" version = "0.3.0" @@ -540,6 +653,26 @@ dependencies = [ "zeroize", ] +[[package]] +name = "ark-ff" +version = "0.5.0" +source = "git+https://github.com/a16z/arkworks-algebra?branch=v0.5.0-optimize-mul-u64#4ae5018533f1e757bb321e21927c8bbbf8c27ffc" +dependencies = [ + "ark-ff-asm 0.5.0", + "ark-ff-macros 0.5.0", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "arrayvec", + "digest 0.10.7", + "educe", + "itertools 0.13.0", + "num-bigint 0.4.6", + "num-traits", + "paste", + "rayon", + "zeroize", +] + [[package]] name = "ark-ff-asm" version = "0.3.0" @@ -560,6 +693,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "ark-ff-asm" +version = "0.5.0" +source = "git+https://github.com/a16z/arkworks-algebra?branch=v0.5.0-optimize-mul-u64#4ae5018533f1e757bb321e21927c8bbbf8c27ffc" +dependencies = [ + "quote", + "syn 2.0.101", +] + [[package]] name = "ark-ff-macros" version = "0.3.0" @@ -585,6 +727,32 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "ark-ff-macros" +version = "0.5.0" +source = "git+https://github.com/a16z/arkworks-algebra?branch=v0.5.0-optimize-mul-u64#4ae5018533f1e757bb321e21927c8bbbf8c27ffc" +dependencies = [ + "num-bigint 0.4.6", + "num-traits", + "proc-macro2", + "quote", + "syn 2.0.101", +] + +[[package]] +name = "ark-poly" +version = "0.5.0" +source = "git+https://github.com/a16z/arkworks-algebra?branch=v0.5.0-optimize-mul-u64#4ae5018533f1e757bb321e21927c8bbbf8c27ffc" +dependencies = [ + "ahash", + "ark-ff 0.5.0", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "educe", + "fnv", + "hashbrown 0.15.3", +] + [[package]] name = "ark-serialize" version = "0.3.0" @@ -606,6 +774,40 @@ dependencies = [ "num-bigint 0.4.6", ] +[[package]] +name = "ark-serialize" +version = "0.5.0" +source = "git+https://github.com/a16z/arkworks-algebra?branch=v0.5.0-optimize-mul-u64#4ae5018533f1e757bb321e21927c8bbbf8c27ffc" +dependencies = [ + "ark-serialize-derive 0.5.0 (git+https://github.com/a16z/arkworks-algebra?branch=v0.5.0-optimize-mul-u64)", + "ark-std 0.5.0", + "arrayvec", + "digest 0.10.7", + "num-bigint 0.4.6", + "rayon", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213888f660fddcca0d257e88e54ac05bca01885f258ccdf695bafd77031bb69d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.5.0" +source = "git+https://github.com/a16z/arkworks-algebra?branch=v0.5.0-optimize-mul-u64#4ae5018533f1e757bb321e21927c8bbbf8c27ffc" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + [[package]] name = "ark-std" version = "0.3.0" @@ -626,6 +828,17 @@ dependencies = [ "rand 0.8.5", ] +[[package]] +name = "ark-std" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "246a225cc6131e9ee4f24619af0f19d67761fff15d7ccc22e42b80846e69449a" +dependencies = [ + "num-traits", + "rand 0.8.5", + "rayon", +] + [[package]] name = "arrayref" version = "0.3.9" @@ -776,7 +989,7 @@ dependencies = [ "cfg-if", "libc", "miniz_oxide", - "object", + "object 0.36.7", "rustc-demangle", "serde", "windows-targets 0.52.6", @@ -818,7 +1031,7 @@ dependencies = [ "bitflags", "cexpr", "clang-sys", - "itertools 0.13.0", + "itertools 0.11.0", "log", "prettyplease", "proc-macro2", @@ -1171,12 +1384,31 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + [[package]] name = "colorchoice" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" +[[package]] +name = "common" +version = "0.2.0" +source = "git+https://github.com/kevaundray/jolt?branch=kw%2Fere-fork#831dd937303b1055f995d3836d0dd61a818969fe" +dependencies = [ + "ark-serialize 0.5.0", + "serde", + "serde_json", + "strum", + "strum_macros", + "syn 1.0.109", +] + [[package]] name = "console" version = "0.15.11" @@ -1241,6 +1473,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation" version = "0.10.0" @@ -1291,6 +1533,15 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + [[package]] name = "crossbeam" version = "0.8.4" @@ -1762,6 +2013,18 @@ dependencies = [ "spki", ] +[[package]] +name = "educe" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7bc049e1bd8cdeb31b68bbd586a9464ecf9f3944af3958a7a9d0f8b9799417" +dependencies = [ + "enum-ordinalize", + "proc-macro2", + "quote", + "syn 2.0.101", +] + [[package]] name = "either" version = "1.15.0" @@ -1798,12 +2061,33 @@ dependencies = [ "zeroize", ] +[[package]] +name = "embedded-io" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" + +[[package]] +name = "embedded-io" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" + [[package]] name = "encode_unicode" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + [[package]] name = "endian-type" version = "0.1.2" @@ -1831,6 +2115,26 @@ dependencies = [ "syn 2.0.101", ] +[[package]] +name = "enum-ordinalize" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea0dcfa4e54eeb516fe454635a95753ddd39acda650ce703031c6973e315dd5" +dependencies = [ + "enum-ordinalize-derive", +] + +[[package]] +name = "enum-ordinalize-derive" +version = "4.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + [[package]] name = "enum_dispatch" version = "0.3.13" @@ -1872,6 +2176,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" +[[package]] +name = "ere-jolt" +version = "0.1.0" +dependencies = [ + "ark-serialize 0.5.0", + "jolt", + "jolt-core", + "jolt-sdk", + "thiserror 2.0.12", + "toml", + "zkvm-interface", +] + [[package]] name = "ere-openvm" version = "0.1.0" @@ -2036,6 +2353,22 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "fixedbitset" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" + +[[package]] +name = "flate2" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "fnv" version = "1.0.7" @@ -2048,6 +2381,21 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -2191,6 +2539,17 @@ dependencies = [ "typenum", ] +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + [[package]] name = "getrandom" version = "0.2.16" @@ -2655,6 +3014,22 @@ dependencies = [ "tower-service", ] +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + [[package]] name = "hyper-util" version = "0.1.11" @@ -2969,6 +3344,102 @@ dependencies = [ "syn 2.0.101", ] +[[package]] +name = "jolt" +version = "0.1.0" +source = "git+https://github.com/kevaundray/jolt?branch=kw%2Fere-fork#831dd937303b1055f995d3836d0dd61a818969fe" +dependencies = [ + "clap", + "common", + "eyre", + "jolt-core", + "jolt-sdk", + "rand 0.8.5", + "rmp-serde", + "serde", + "syn 1.0.109", + "sysinfo", + "toml_edit 0.22.26", +] + +[[package]] +name = "jolt-core" +version = "0.1.0" +source = "git+https://github.com/kevaundray/jolt?branch=kw%2Fere-fork#831dd937303b1055f995d3836d0dd61a818969fe" +dependencies = [ + "alloy-primitives 0.7.7", + "alloy-sol-types 0.7.7", + "anyhow", + "ark-bn254", + "ark-ec", + "ark-ff 0.5.0", + "ark-serialize 0.5.0", + "ark-serialize-derive 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ark-std 0.5.0", + "bincode", + "bytemuck", + "clap", + "common", + "dirs", + "enum_dispatch", + "eyre", + "fixedbitset", + "getrandom 0.2.16", + "indicatif", + "itertools 0.10.5", + "memory-stats", + "num", + "num-derive", + "num-integer", + "num-traits", + "once_cell", + "paste", + "postcard", + "rand 0.7.3", + "rand_chacha 0.3.1", + "rand_core 0.6.4", + "rand_distr", + "rayon", + "reqwest", + "serde", + "sha3", + "strum", + "strum_macros", + "sys-info", + "target-lexicon", + "thiserror 1.0.69", + "tokio", + "tracer", + "tracing", + "tracing-chrome", + "tracing-subscriber", +] + +[[package]] +name = "jolt-sdk" +version = "0.1.0" +source = "git+https://github.com/kevaundray/jolt?branch=kw%2Fere-fork#831dd937303b1055f995d3836d0dd61a818969fe" +dependencies = [ + "ark-bn254", + "ark-ec", + "common", + "jolt-core", + "jolt-sdk-macros", + "postcard", + "tracer", +] + +[[package]] +name = "jolt-sdk-macros" +version = "0.1.0" +source = "git+https://github.com/kevaundray/jolt?branch=kw%2Fere-fork#831dd937303b1055f995d3836d0dd61a818969fe" +dependencies = [ + "common", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "js-sys" version = "0.3.77" @@ -3159,6 +3630,16 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "memory-stats" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c73f5c649995a115e1a0220b35e4df0a1294500477f97a91d0660fb5abeb574a" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "memuse" version = "0.2.2" @@ -3243,6 +3724,23 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "native-tls" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework 2.11.1", + "security-framework-sys", + "tempfile", +] + [[package]] name = "nibble_vec" version = "0.1.0" @@ -3351,6 +3849,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +[[package]] +name = "num-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + [[package]] name = "num-integer" version = "0.1.46" @@ -3469,6 +3978,17 @@ dependencies = [ "smallvec", ] +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "flate2", + "memchr", + "ruzstd", +] + [[package]] name = "object" version = "0.36.7" @@ -3484,12 +4004,50 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "openssl" +version = "0.10.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fedfea7d58a1f73118430a55da6a286e7b044961736ce96a16a17068ea25e5da" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + [[package]] name = "openssl-probe" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" +[[package]] +name = "openssl-sys" +version = "0.9.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e145e1651e858e820e4860f7b9c5e169bc1d8ce1c86043be79fa7b7634821847" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "openvm" version = "1.1.1" @@ -5629,6 +6187,12 @@ dependencies = [ "spki", ] +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + [[package]] name = "portable-atomic" version = "1.11.0" @@ -5659,6 +6223,18 @@ dependencies = [ "thiserror 1.0.69", ] +[[package]] +name = "postcard" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "170a2601f67cc9dba8edd8c4870b15f71a6a2dc196daec8c83f72b59dff628a8" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "serde", +] + [[package]] name = "potential_utf" version = "0.1.2" @@ -5732,6 +6308,30 @@ dependencies = [ "toml_edit 0.22.26", ] +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro-error-attr2" version = "2.0.0" @@ -5913,6 +6513,19 @@ dependencies = [ "nibble_vec", ] +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc", +] + [[package]] name = "rand" version = "0.8.5" @@ -5936,6 +6549,16 @@ dependencies = [ "serde", ] +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + [[package]] name = "rand_chacha" version = "0.3.1" @@ -5956,6 +6579,15 @@ dependencies = [ "rand_core 0.9.3", ] +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", +] + [[package]] name = "rand_core" version = "0.6.4" @@ -5975,6 +6607,25 @@ dependencies = [ "serde", ] +[[package]] +name = "rand_distr" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31" +dependencies = [ + "num-traits", + "rand 0.8.5", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + [[package]] name = "rand_xorshift" version = "0.3.0" @@ -6106,18 +6757,23 @@ checksum = "d19c46a6fdd48bc4dab94b6103fccc55d34c67cc0ad04653aad4ea2a07cd7bbb" dependencies = [ "base64", "bytes", + "encoding_rs", + "futures-channel", "futures-core", "futures-util", + "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", + "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", + "native-tls", "once_cell", "percent-encoding", "pin-project-lite", @@ -6129,7 +6785,9 @@ dependencies = [ "serde_json", "serde_urlencoded", "sync_wrapper", + "system-configuration", "tokio", + "tokio-native-tls", "tokio-rustls", "tokio-util", "tower 0.5.2", @@ -6192,6 +6850,28 @@ dependencies = [ "rustc-hex", ] +[[package]] +name = "rmp" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "228ed7c16fa39782c3b3468e974aec2795e9089153cd08ee2e9aefb3613334c4" +dependencies = [ + "byteorder", + "num-traits", + "paste", +] + +[[package]] +name = "rmp-serde" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52e599a477cf9840e92f2cde9a7189e67b42c57532749bf90aea6ec10facd4db" +dependencies = [ + "byteorder", + "rmp", + "serde", +] + [[package]] name = "rrs-lib" version = "0.1.0" @@ -6325,7 +7005,7 @@ dependencies = [ "openssl-probe", "rustls-pki-types", "schannel", - "security-framework", + "security-framework 3.2.0", ] [[package]] @@ -6376,6 +7056,17 @@ dependencies = [ "wait-timeout", ] +[[package]] +name = "ruzstd" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58c4eb8a81997cf040a091d1f7e1938aeab6749d3a0dfa73af43cdc32393483d" +dependencies = [ + "byteorder", + "derive_more 0.99.20", + "twox-hash", +] + [[package]] name = "ryu" version = "1.0.20" @@ -6451,6 +7142,19 @@ dependencies = [ "zeroize", ] +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation 0.9.4", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + [[package]] name = "security-framework" version = "3.2.0" @@ -6458,7 +7162,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "271720403f46ca04f7ba6f55d438f8bd878d6b8ca0a1046e8228c4145bcbb316" dependencies = [ "bitflags", - "core-foundation", + "core-foundation 0.10.0", "core-foundation-sys", "libc", "security-framework-sys", @@ -7167,10 +7871,10 @@ version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9dc0553bed3674fe271a65dd9cdd3569670c619fdc3aaac7588cc6fce39e622" dependencies = [ - "alloy-primitives", + "alloy-primitives 1.1.0", "alloy-signer", "alloy-signer-local", - "alloy-sol-types", + "alloy-sol-types 1.1.0", "anyhow", "async-trait", "backoff", @@ -7346,6 +8050,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn-solidity" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c837dc8852cb7074e46b444afb81783140dab12c58867b49fb3898fbafedf7ea" +dependencies = [ + "paste", + "proc-macro2", + "quote", + "syn 2.0.101", +] + [[package]] name = "syn-solidity" version = "1.1.0" @@ -7378,6 +8094,16 @@ dependencies = [ "syn 2.0.101", ] +[[package]] +name = "sys-info" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b3a0d0aba8bf96a0e1ddfdc352fc53b3df7f39318c71854910c3c4b024ae52c" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "sysinfo" version = "0.30.13" @@ -7393,12 +8119,39 @@ dependencies = [ "windows", ] +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation 0.9.4", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "tap" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + [[package]] name = "tempfile" version = "3.20.0" @@ -7618,6 +8371,16 @@ dependencies = [ "syn 2.0.101", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.26.2" @@ -7785,6 +8548,17 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" +[[package]] +name = "tracer" +version = "0.2.0" +source = "git+https://github.com/kevaundray/jolt?branch=kw%2Fere-fork#831dd937303b1055f995d3836d0dd61a818969fe" +dependencies = [ + "common", + "fnv", + "object 0.32.2", + "tracing", +] + [[package]] name = "tracing" version = "0.1.41" @@ -7820,6 +8594,17 @@ dependencies = [ "syn 2.0.101", ] +[[package]] +name = "tracing-chrome" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf0a738ed5d6450a9fb96e86a23ad808de2b727fd1394585da5cdd6788ffe724" +dependencies = [ + "serde_json", + "tracing-core", + "tracing-subscriber", +] + [[package]] name = "tracing-core" version = "0.1.33" @@ -7910,6 +8695,16 @@ dependencies = [ "url", ] +[[package]] +name = "twox-hash" +version = "1.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" +dependencies = [ + "cfg-if", + "static_assertions", +] + [[package]] name = "typenum" version = "1.18.0" @@ -8003,6 +8798,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "vec_map" version = "0.8.2" @@ -8036,6 +8837,12 @@ dependencies = [ "try-lock", ] +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index 3898ebb..b304e2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,10 @@ members = [ "crates/zkvm-interface", # zkVMs "crates/ere-sp1", - "crates/ere-risczero", "crates/ere-openvm", "crates/ere-pico", + "crates/ere-risczero", + "crates/ere-openvm", + "crates/ere-pico", + "crates/ere-jolt", ] resolver = "2" @@ -19,3 +22,9 @@ license = "MIT OR Apache-2.0" [workspace.dependencies] # local dependencies zkvm-interface = { path = "crates/zkvm-interface" } + +[patch.crates-io] +# These patches are only needed by Jolt +ark-ff = { git = "https://github.com/a16z/arkworks-algebra", branch = "v0.5.0-optimize-mul-u64" } +ark-ec = { git = "https://github.com/a16z/arkworks-algebra", branch = "v0.5.0-optimize-mul-u64" } +ark-serialize = { git = "https://github.com/a16z/arkworks-algebra", branch = "v0.5.0-optimize-mul-u64" } diff --git a/crates/ere-jolt/Cargo.toml b/crates/ere-jolt/Cargo.toml new file mode 100644 index 0000000..ae893e4 --- /dev/null +++ b/crates/ere-jolt/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "ere-jolt" +version.workspace = true +edition.workspace = true +rust-version.workspace = true +license.workspace = true + +[dependencies] +zkvm-interface = { workspace = true } +jolt-sdk = { git = "https://github.com/kevaundray/jolt", branch = "kw/ere-fork", features = [ + "host", +] } +jolt-core = { git = "https://github.com/kevaundray/jolt", branch = "kw/ere-fork", features = [ + "host", +] } +jolt = { git = "https://github.com/kevaundray/jolt", branch = "kw/ere-fork", features = [ + "host", +] } +thiserror = "2" +toml = "0.8" +ark-serialize = "0.5.0" + +[lints] +workspace = true diff --git a/crates/ere-jolt/src/jolt_methods.rs b/crates/ere-jolt/src/jolt_methods.rs new file mode 100644 index 0000000..5d89c5d --- /dev/null +++ b/crates/ere-jolt/src/jolt_methods.rs @@ -0,0 +1,91 @@ +use zkvm_interface::Input; + +pub fn preprocess_prover( + program: &jolt::host::Program, +) -> jolt::JoltProverPreprocessing<4, jolt::F, jolt::PCS, jolt::ProofTranscript> { + use jolt::{Jolt, JoltProverPreprocessing, MemoryLayout, RV32IJoltVM}; + let (bytecode, memory_init) = program.decode(); + let memory_layout = MemoryLayout::new(4096, 4096); + let preprocessing: JoltProverPreprocessing<4, jolt::F, jolt::PCS, jolt::ProofTranscript> = + RV32IJoltVM::prover_preprocess( + bytecode, + memory_layout, + memory_init, + 1 << 20, + 1 << 20, + 1 << 24, + ); + preprocessing +} + +pub fn preprocess_verifier( + program: &jolt::host::Program, +) -> jolt::JoltVerifierPreprocessing<4, jolt::F, jolt::PCS, jolt::ProofTranscript> { + use jolt::{Jolt, JoltVerifierPreprocessing, MemoryLayout, RV32IJoltVM}; + + let (bytecode, memory_init) = program.decode(); + let memory_layout = MemoryLayout::new(4096, 4096); + let preprocessing: JoltVerifierPreprocessing<4, jolt::F, jolt::PCS, jolt::ProofTranscript> = + RV32IJoltVM::verifier_preprocess( + bytecode, + memory_layout, + memory_init, + 1 << 20, + 1 << 20, + 1 << 24, + ); + preprocessing +} + +pub fn verify_generic( + proof: jolt::JoltHyperKZGProof, + // TODO: input should be private input + inputs: Input, + outputs: Input, + preprocessing: jolt::JoltVerifierPreprocessing<4, jolt::F, jolt::PCS, jolt::ProofTranscript>, +) -> bool { + use jolt::{Jolt, RV32IJoltVM, tracer}; + + let preprocessing = std::sync::Arc::new(preprocessing); + let preprocessing = (*preprocessing).clone(); + let mut io_device = tracer::JoltDevice::new( + preprocessing.memory_layout.max_input_size, + preprocessing.memory_layout.max_output_size, + ); + + io_device.inputs = inputs.bytes().to_vec(); + io_device.outputs = outputs.bytes().to_vec(); + + RV32IJoltVM::verify( + preprocessing, + proof.proof, + proof.commitments, + io_device, + None, + ) + .is_ok() +} + +pub fn prove_generic( + program: &jolt::host::Program, + preprocessing: jolt::JoltProverPreprocessing<4, jolt::F, jolt::PCS, jolt::ProofTranscript>, + inputs: &Input, +) -> (Vec, jolt::JoltHyperKZGProof) { + use jolt::{Jolt, RV32IJoltVM}; + + let mut program = program.clone(); + + // Convert inputs to a flat vector + let input_bytes = inputs.bytes().to_vec(); + + let (io_device, trace) = program.trace(&input_bytes); + + let (jolt_proof, jolt_commitments, output_io_device, _) = + RV32IJoltVM::prove(io_device, trace, preprocessing); + + let proof = jolt::JoltHyperKZGProof { + proof: jolt_proof, + commitments: jolt_commitments, + }; + (output_io_device.outputs.clone(), proof) +} diff --git a/crates/ere-jolt/src/lib.rs b/crates/ere-jolt/src/lib.rs new file mode 100644 index 0000000..ba7013d --- /dev/null +++ b/crates/ere-jolt/src/lib.rs @@ -0,0 +1,154 @@ +use jolt_core::host::Program; +use jolt_methods::{preprocess_prover, preprocess_verifier, prove_generic, verify_generic}; +use jolt_sdk::host::DEFAULT_TARGET_DIR; +use utils::{ + deserialize_public_input_with_proof, package_name_from_manifest, + serialize_public_input_with_proof, +}; +use zkvm_interface::{Compiler, Input, ProgramExecutionReport, ProgramProvingReport, zkVM}; + +mod jolt_methods; +mod utils; + +pub struct JOLT_TARGET; + +#[derive(Debug, thiserror::Error)] +pub enum JoltError { + #[error("Proof verification failed")] + ProofVerificationFailed, +} + +impl Compiler for JOLT_TARGET { + type Error = JoltError; + + type Program = Program; + + fn compile(path_to_program: &std::path::Path) -> Result { + let manifest_path = path_to_program.to_path_buf().join("Cargo.toml"); + let package_name = package_name_from_manifest(&manifest_path).unwrap(); + let mut program = Program::new(&package_name); + program.set_manifest_path(manifest_path); + program.set_memory_size(10485760u64); + program.set_stack_size(4096u64); + program.set_max_input_size(4096u64); + program.set_max_output_size(4096u64); + + // TODO: Note that if this fails, it will panic + program.build(DEFAULT_TARGET_DIR); + + // Read the ELF file and return its bytes + // let elf_path = program.elf.expect("expect elf path"); + // println!("{:?}", elf_path); + // let elf_bytes = std::fs::read(elf_path).unwrap(); + + Ok(program) + } +} + +pub struct EreJolt; + +impl zkVM for EreJolt { + type Error = JoltError; + + fn execute( + program_bytes: &::Program, + inputs: &zkvm_interface::Input, + ) -> Result { + // TODO: check ProgramSummary + let summary = program_bytes + .clone() + .trace_analyze::(inputs.bytes()); + let trace_len = summary.trace_len(); + + Ok(ProgramExecutionReport::new(trace_len as u64)) + } + + fn prove( + program: &::Program, + inputs: &zkvm_interface::Input, + ) -> Result<(Vec, zkvm_interface::ProgramProvingReport), Self::Error> { + // TODO: make this stateful and do in setup since its expensive and should be done once per program; + let preprocessed_key = preprocess_prover(&program); + + let now = std::time::Instant::now(); + let (output_bytes, proof) = prove_generic(program, preprocessed_key, inputs); + let elapsed = now.elapsed(); + + let proof_with_public_inputs = + serialize_public_input_with_proof(&output_bytes, &proof).unwrap(); + + Ok((proof_with_public_inputs, ProgramProvingReport::new(elapsed))) + } + + fn verify( + program: &::Program, + proof_with_public_inputs: &[u8], + ) -> Result<(), Self::Error> { + let preprocessed_verifier = preprocess_verifier(program); + let (public_inputs, proof) = + deserialize_public_input_with_proof(proof_with_public_inputs).unwrap(); + + let mut outputs = Input::new(); + assert!(public_inputs.is_empty()); + outputs.write(&public_inputs).unwrap(); + + // TODO: I don't think we should require the inputs when verifying + let inputs = Input::new(); + + let valid = verify_generic(proof, inputs, outputs, preprocessed_verifier); + if valid { + Ok(()) + } else { + Err(JoltError::ProofVerificationFailed) + } + } +} + +#[cfg(test)] +mod tests { + use crate::{EreJolt, JOLT_TARGET}; + use std::path::PathBuf; + use zkvm_interface::{Compiler, Input, zkVM}; + + // TODO: for now, we just get one test file + // TODO: but this should get the whole directory and compile each test + fn get_compile_test_guest_program_path() -> PathBuf { + let workspace_dir = env!("CARGO_WORKSPACE_DIR"); + PathBuf::from(workspace_dir) + .join("tests") + .join("jolt") + .join("compile") + .join("basic") + .join("guest") + .canonicalize() + .expect("Failed to find or canonicalize test guest program at /tests/compile/jolt") + } + + #[test] + fn test_compile_trait() { + let test_guest_path = get_compile_test_guest_program_path(); + let program = JOLT_TARGET::compile(&test_guest_path).unwrap(); + assert!(program.elf.is_some(), "elf has not been compiled"); + } + + #[test] + fn test_execute() { + let test_guest_path = get_compile_test_guest_program_path(); + let program = JOLT_TARGET::compile(&test_guest_path).unwrap(); + let mut inputs = Input::new(); + inputs.write(&(1 as u32)).unwrap(); + + let _execution = EreJolt::execute(&program, &inputs).unwrap(); + } + #[test] + fn test_prove_verify() { + let test_guest_path = get_compile_test_guest_program_path(); + let program = JOLT_TARGET::compile(&test_guest_path).unwrap(); + + // TODO: I don't think we should require the inputs when verifying + let inputs = Input::new(); + + let (proof, _) = EreJolt::prove(&program, &inputs).unwrap(); + EreJolt::verify(&program, &proof).unwrap(); + } +} diff --git a/crates/ere-jolt/src/utils.rs b/crates/ere-jolt/src/utils.rs new file mode 100644 index 0000000..336e7d2 --- /dev/null +++ b/crates/ere-jolt/src/utils.rs @@ -0,0 +1,75 @@ +use jolt::JoltHyperKZGProof; +use std::{fs, path::Path}; +use toml::Value; + +use crate::JoltError; + +/// Reads the `[package] name` out of a Cargo.toml. +/// +/// * `manifest_path` – absolute or relative path to a Cargo.toml. +/// * Returns → `String` with the package name (`fib`, `my_guest`, …). +pub(crate) fn package_name_from_manifest(manifest_path: &Path) -> Result { + let manifest = fs::read_to_string(manifest_path).unwrap(); + let value: Value = manifest.parse::().unwrap(); + + value + .get("package") + .and_then(|pkg| pkg.get("name")) + .and_then(Value::as_str) + .map(|s| s.to_owned()) + .ok_or_else(|| panic!("no [package] name found in {}", manifest_path.display())) +} + +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize, SerializationError}; +use std::io::Cursor; + +/// Serializes the public input (as raw bytes) and proof into a single byte vector +pub fn serialize_public_input_with_proof( + public_input: &Vec, + proof: &JoltHyperKZGProof, +) -> Result, SerializationError> { + let mut buffer = Vec::new(); + + // First, serialize the length of the public input as u64 + let public_input_size = public_input.len() as u64; + public_input_size.serialize_compressed(&mut buffer)?; + + // Append the public input directly (it's already bytes) + buffer.extend_from_slice(public_input); + + // Now serialize the proof + let mut proof_bytes = Vec::new(); + proof.serialize_compressed(&mut proof_bytes)?; + + // Append the serialized proof to the buffer + buffer.extend_from_slice(&proof_bytes); + + Ok(buffer) +} + +/// Deserializes a byte vector into a public input (Vec) and proof +pub fn deserialize_public_input_with_proof( + bytes: &[u8], +) -> Result<(Vec, JoltHyperKZGProof), SerializationError> { + let mut cursor = Cursor::new(bytes); + + // Read the size of the public input + let public_input_size: u64 = CanonicalDeserialize::deserialize_compressed(&mut cursor)?; + + // Get the current position after reading the size + let current_position = cursor.position() as usize; + let public_input_end = current_position + public_input_size as usize; + + if public_input_end > bytes.len() { + return Err(SerializationError::InvalidData); + } + + // Extract the public input bytes directly + let public_input = bytes[current_position..public_input_end].to_vec(); + + // The rest is the proof + let proof_bytes = &bytes[public_input_end..]; + let proof = JoltHyperKZGProof::deserialize_compressed(&mut Cursor::new(proof_bytes))?; + + Ok((public_input, proof)) +}