diff --git a/Cargo.lock b/Cargo.lock index a529d89..698840f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,25 +4,30 @@ version = 3 [[package]] name = "ahash" -version = "0.7.6" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ + "cfg-if", "const-random", - "getrandom", "once_cell", "version_check", + "zerocopy", ] [[package]] -name = "ahash" -version = "0.8.3" +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" dependencies = [ - "cfg-if", - "once_cell", - "version_check", + "libc", ] [[package]] @@ -154,6 +159,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "bitvec" version = "1.0.1" @@ -178,34 +189,60 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "cc" +version = "1.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" +dependencies = [ + "shlex", +] + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "serde", + "windows-targets", +] + [[package]] name = "const-random" -version = "0.1.15" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368a7a772ead6ce7e1de82bfb04c485f3db8ec744f72925af5735e29a22cc18e" +checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359" dependencies = [ "const-random-macro", - "proc-macro-hack", ] [[package]] name = "const-random-macro" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d7d6ab3c3a2282db210df5f02c4dab6e0a7057af0fb7ebd4070f30fe05c0ddb" +checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" dependencies = [ "getrandom", "once_cell", - "proc-macro-hack", "tiny-keccak", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "crossbeam-channel" version = "0.5.8" @@ -265,6 +302,51 @@ dependencies = [ "typenum", ] +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.32", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.32", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", + "serde", +] + [[package]] name = "derivative" version = "2.2.0" @@ -300,6 +382,12 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "funty" version = "2.0.0" @@ -334,11 +422,6 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -dependencies = [ - "ahash 0.7.6", - "rayon", - "serde", -] [[package]] name = "hashbrown" @@ -346,7 +429,18 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ - "ahash 0.8.3", + "ahash", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "rayon", + "serde", ] [[package]] @@ -361,6 +455,46 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + [[package]] name = "itertools" version = "0.10.5" @@ -461,6 +595,12 @@ dependencies = [ "rand", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" version = "0.1.45" @@ -527,33 +667,32 @@ checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "plonky2" -version = "0.1.3" -source = "git+https://github.com/InternetMaximalism/plonky2?rev=541e127#541e127c3ffec4e0e61e302f0e39bea4f943e19c" +version = "0.2.2" +source = "git+https://github.com/Lagrange-Labs/plonky2?branch=upstream#22c42f64367e8f087e565bdb664525910a62fc76" dependencies = [ - "ahash 0.7.6", + "ahash", "anyhow", "getrandom", - "hashbrown 0.12.3", - "hex", - "itertools 0.10.5", + "hashbrown 0.14.5", + "itertools 0.11.0", "keccak-hash", "log", "num", "plonky2_field", - "plonky2_maybe_rayon 0.1.1", + "plonky2_maybe_rayon 0.2.0 (git+https://github.com/Lagrange-Labs/plonky2?branch=upstream)", "plonky2_util", "rand", "rand_chacha", "serde", - "serde_json", "static_assertions", "unroll", + "web-time", ] [[package]] name = "plonky2-bn254" version = "0.1.0" -source = "git+https://github.com/qope/plonky2-bn254.git?rev=d616d57#d616d575e517f35e5839ed8eb90f1a2bf1b32c80" +source = "git+https://github.com/Lagrange-Labs/plonky2-bn254#8500d603d2e0d602559150dbf11b63fa6aaa3ae5" dependencies = [ "anyhow", "ark-bn254", @@ -563,35 +702,53 @@ dependencies = [ "bitvec", "hex", "itertools 0.10.5", + "log", "num", "num-bigint", "num-traits", "plonky2", + "plonky2_crypto", "plonky2_ecdsa", - "plonky2_u32", "rand", "serde", ] +[[package]] +name = "plonky2_crypto" +version = "0.1.0" +source = "git+https://github.com/Lagrange-Labs/plonky2-crypto#c8e4d83f43bc5836a0c9443cd0b4bcc17f0ab0bc" +dependencies = [ + "anyhow", + "hex", + "itertools 0.10.5", + "log", + "num", + "plonky2", + "plonky2_maybe_rayon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand", + "rayon", + "serde", + "serde_with", +] + [[package]] name = "plonky2_ecdsa" version = "0.1.0" -source = "git+https://github.com/InternetMaximalism/plonky2?rev=541e127#541e127c3ffec4e0e61e302f0e39bea4f943e19c" +source = "git+https://github.com/Lagrange-Labs/plonky2-ecdsa#1e8a320ad98ca7eb65ffaf932fea18f559962abf" dependencies = [ "anyhow", "itertools 0.10.5", "num", "plonky2", - "plonky2_maybe_rayon 0.1.0", - "plonky2_u32", + "plonky2_crypto", + "plonky2_maybe_rayon 0.1.1", "serde", ] [[package]] name = "plonky2_field" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d33a655ab5d274f763c292fe7e14577f25e40d9d8607b70ef10b39f8619e60b4" +version = "0.2.2" +source = "git+https://github.com/Lagrange-Labs/plonky2?branch=upstream#22c42f64367e8f087e565bdb664525910a62fc76" dependencies = [ "anyhow", "itertools 0.11.0", @@ -605,37 +762,37 @@ dependencies = [ [[package]] name = "plonky2_maybe_rayon" -version = "0.1.0" -source = "git+https://github.com/InternetMaximalism/plonky2?rev=541e127#541e127c3ffec4e0e61e302f0e39bea4f943e19c" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194db0cbdd974e92d897cd92b74adb3968dc1b967315eb280357c49a7637994e" dependencies = [ "rayon", ] [[package]] name = "plonky2_maybe_rayon" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194db0cbdd974e92d897cd92b74adb3968dc1b967315eb280357c49a7637994e" -dependencies = [ - "rayon", -] +checksum = "92ff44a90aaca13e10e7ddf8fab815ba1b404c3f7c3ca82aaf11c46beabaa923" [[package]] -name = "plonky2_u32" -version = "0.1.0" -source = "git+https://github.com/InternetMaximalism/plonky2?rev=541e127#541e127c3ffec4e0e61e302f0e39bea4f943e19c" +name = "plonky2_maybe_rayon" +version = "0.2.0" +source = "git+https://github.com/Lagrange-Labs/plonky2?branch=upstream#22c42f64367e8f087e565bdb664525910a62fc76" dependencies = [ - "anyhow", - "itertools 0.10.5", - "num", - "plonky2", + "rayon", ] [[package]] name = "plonky2_util" -version = "0.1.1" +version = "0.2.0" +source = "git+https://github.com/Lagrange-Labs/plonky2?branch=upstream#22c42f64367e8f087e565bdb664525910a62fc76" + +[[package]] +name = "powerfmt" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5696e2e2a6bb5c48a6e33fb0dd4d20d0a9472784b709964f337f224e99bd6d06" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "ppv-lite86" @@ -653,12 +810,6 @@ dependencies = [ "uint", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.20+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" - [[package]] name = "proc-macro2" version = "1.0.66" @@ -764,22 +915,22 @@ checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" [[package]] name = "serde" -version = "1.0.183" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.183" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.32", ] [[package]] @@ -793,16 +944,54 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07ff71d2c147a7b57362cead5e22f772cd52f6ab31cfcd9edcd7f6aeb2a0afbe" +dependencies = [ + "base64", + "chrono", + "hex", + "indexmap", + "serde", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "881b6f881b17d13214e5d494c939ebab463d01264ce1811e9d4ac3a882e7695f" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.32", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "starky" -version = "0.1.1" -source = "git+https://github.com/InternetMaximalism/plonky2?rev=541e127#541e127c3ffec4e0e61e302f0e39bea4f943e19c" +version = "0.4.0" +source = "git+https://github.com/Lagrange-Labs/plonky2?branch=upstream#22c42f64367e8f087e565bdb664525910a62fc76" dependencies = [ + "ahash", "anyhow", - "itertools 0.10.5", + "hashbrown 0.14.5", + "itertools 0.11.0", "log", + "num-bigint", "plonky2", - "plonky2_maybe_rayon 0.1.1", + "plonky2_maybe_rayon 0.2.0 (git+https://github.com/Lagrange-Labs/plonky2?branch=upstream)", + "plonky2_util", ] [[package]] @@ -823,8 +1012,7 @@ dependencies = [ "num-traits", "plonky2", "plonky2-bn254", - "plonky2_maybe_rayon 0.1.0", - "plonky2_u32", + "plonky2_maybe_rayon 0.2.0 (git+https://github.com/Lagrange-Labs/plonky2?branch=upstream)", "rand", "rand_chacha", "starky", @@ -837,6 +1025,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "syn" version = "1.0.109" @@ -850,9 +1044,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.28" +version = "2.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" +checksum = "239814284fd6f1a4ffe4ca893952cdd93c224b6a1571c9a9eadd670295c0c9e2" dependencies = [ "proc-macro2", "quote", @@ -865,6 +1059,37 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "time" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tiny-keccak" version = "2.0.2" @@ -941,7 +1166,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.32", "wasm-bindgen-shared", ] @@ -963,7 +1188,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.32", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -974,6 +1199,89 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "wyz" version = "0.5.1" @@ -983,6 +1291,26 @@ dependencies = [ "tap", ] +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.32", +] + [[package]] name = "zeroize" version = "1.6.0" @@ -1000,5 +1328,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.32", ] diff --git a/Cargo.toml b/Cargo.toml index 87feece..cefbf08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,18 +13,17 @@ timing = ["plonky2/timing"] [dependencies] anyhow = { version = "1.0.40", default-features = false } -itertools = { version = "0.10.0"} +itertools = { version = "0.10.0" } log = { version = "0.4.14", default-features = false } -plonky2_maybe_rayon = {git="https://github.com/InternetMaximalism/plonky2", rev="541e127"} -plonky2={git="https://github.com/InternetMaximalism/plonky2", rev="541e127"} -plonky2_u32={git="https://github.com/InternetMaximalism/plonky2", rev="541e127"} -starky ={git="https://github.com/InternetMaximalism/plonky2", rev="541e127"} -plonky2-bn254={git="https://github.com/qope/plonky2-bn254.git", rev="d616d57"} +plonky2 = "0.2.2" +plonky2-bn254 = { git = "https://github.com/Lagrange-Labs/plonky2-bn254" } +plonky2_maybe_rayon = { git = "https://github.com/Lagrange-Labs/plonky2", branch = "upstream" } +starky = { git = "https://github.com/Lagrange-Labs/plonky2", branch = "upstream" } static_assertions = "1.1.0" num = "0.4.0" num-bigint = "0.4.3" rand = "0.8.5" -rand_chacha="0.3.1" +rand_chacha = "0.3.1" ark-bn254 = "0.4.0" ark-ec = "0.4.2" ark-ff = "0.4.2" @@ -33,4 +32,6 @@ bitvec = "1.0.1" byteorder = "1.4.3" num-traits = "0.2.15" - +[patch.crates-io] +plonky2 = { git = "https://github.com/Lagrange-Labs/plonky2", branch = "upstream" } +plonky2_field = { git = "https://github.com/Lagrange-Labs/plonky2", branch = "upstream" } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 4a5741c..5d56faf 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly-2023-10-12" +channel = "nightly" diff --git a/src/fields/fq/circuit.rs b/src/fields/fq/circuit.rs index 2db5585..83af3ca 100644 --- a/src/fields/fq/circuit.rs +++ b/src/fields/fq/circuit.rs @@ -11,10 +11,12 @@ use plonky2::{ target::Target, witness::{PartialWitness, PartitionWitness}, }, + plonk::circuit_data::CommonCircuitData, plonk::{ circuit_builder::CircuitBuilder, config::{AlgebraicHasher, GenericConfig}, }, + util::serialization::IoResult, util::{serialization::Buffer, timing::TimingTree}, }; use plonky2_bn254::fields::{fq_target::FqTarget, u256_target::U256Target}; @@ -28,7 +30,9 @@ use starky::{ verifier::verify_stark_proof, }; -use crate::fields::fq::exp::{read_fq_exp_io, FqExpStark, FQ_EXP_IO_LEN}; +use crate::fields::fq::exp::{ + num_columns, num_public_inputs, read_fq_exp_io, FqExpStark, FQ_EXP_IO_LEN, +}; use crate::{fields::fq::exp::FqExpIONative, utils::utils::get_u256_biguint}; pub const FQ_EXP_INPUT_LEN: usize = 3 * 8; @@ -83,204 +87,6 @@ impl, const D: usize> FqExpInputTarget { } } -fn fq_exp_circuit_with_proof_target< - F: RichField + Extendable, - C: GenericConfig, - const D: usize, ->( - builder: &mut CircuitBuilder, - log_num_io: usize, -) -> ( - Vec>, - Vec>, - StarkProofWithPublicInputsTarget, -) -where - >::Hasher: AlgebraicHasher, -{ - assert!(log_num_io >= 7); - let num_io = 1 << log_num_io; - let stark = FqExpStark::::new(num_io); - let inner_config = stark.config(); - let degree_bits = 9 + log_num_io; - let starky_proof_t = - add_virtual_stark_proof_with_pis(builder, stark, &inner_config, degree_bits); - verify_stark_proof_circuit::(builder, stark, &starky_proof_t, &inner_config); - assert!(starky_proof_t.public_inputs.len() == FQ_EXP_IO_LEN * num_io); - let mut cur_col = 0; - let mut inputs = vec![]; - let mut outputs = vec![]; - let pi = starky_proof_t.public_inputs.clone(); - for _ in 0..num_io { - let io = read_fq_exp_io(&pi, &mut cur_col); - let x = FqTarget::from_limbs(builder, &io.x); - let offset = FqTarget::from_limbs(builder, &io.offset); - let output = FqTarget::from_limbs(builder, &io.output); - let exp_val = U256Target::::from_vec(&io.exp_val); - let input = FqExpInputTarget { x, offset, exp_val }; - inputs.push(input); - outputs.push(output); - } - (inputs, outputs, starky_proof_t) -} - -#[derive(Clone, Debug)] -pub struct FqExpOutputGenerator, const D: usize> { - pub input: FqExpInputTarget, - pub output: FqTarget, -} - -impl SimpleGenerator for FqExpOutputGenerator -where - F: RichField + Extendable, -{ - fn dependencies(&self) -> Vec { - self.input.to_vec() - } - - fn run_once(&self, pw: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let x = get_u256_biguint(pw, &self.input.x.to_vec()); - let offset = get_u256_biguint(pw, &self.input.offset.to_vec()); - let exp_val = get_u256_biguint(pw, &self.input.exp_val.to_vec()); - let x = Fq::from(x); - let offset = Fq::from(offset); - use ark_ff::Field; - let output = x.pow(&exp_val.to_u64_digits()) * offset; - self.output.set_witness(out_buffer, &output); - } - - fn id(&self) -> String { - "FqExpOutputGenerator".to_string() - } - fn serialize(&self, _dst: &mut Vec) -> plonky2::util::serialization::IoResult<()> { - todo!() - } - fn deserialize(_src: &mut Buffer) -> plonky2::util::serialization::IoResult { - todo!() - } -} - -#[derive(Clone, Debug)] -pub struct FqExpStarkyProofGenerator< - F: RichField + Extendable, - C: GenericConfig, - const D: usize, -> { - pub inputs: Vec>, - pub outputs: Vec>, - pub starky_proof: StarkProofWithPublicInputsTarget, - _config: std::marker::PhantomData, -} - -impl SimpleGenerator for FqExpStarkyProofGenerator -where - F: RichField + Extendable, - C: GenericConfig + 'static, - C::Hasher: AlgebraicHasher, -{ - fn dependencies(&self) -> Vec { - let mut targets = vec![]; - self.inputs.iter().cloned().for_each(|input| { - targets.extend(input.to_vec()); - }); - targets - } - fn run_once(&self, pw: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let ios_native = self - .inputs - .iter() - .cloned() - .map(|input| { - let x = get_u256_biguint(pw, &input.x.to_vec()); - let offset = get_u256_biguint(pw, &input.offset.to_vec()); - let exp_val = get_u256_biguint(pw, &input.exp_val.to_vec()); - let x = Fq::from(x); - let offset = Fq::from(offset); - use ark_ff::Field; - let output = x.pow(&exp_val.to_u64_digits()) * offset; - let mut exp_val_u32 = exp_val.to_u32_digits(); - exp_val_u32.extend(vec![0; 8 - exp_val_u32.len()]); - FqExpIONative { - x, - offset, - exp_val: exp_val_u32.try_into().unwrap(), - output, - } - }) - .collect_vec(); - - let num_io = ios_native.len(); - let stark = FqExpStark::::new(num_io); - let inner_config = stark.config(); - let trace = stark.generate_trace(&ios_native); - let pi = stark.generate_public_inputs(&ios_native); - let inner_proof = prove::( - stark, - &inner_config, - trace, - pi.try_into().unwrap(), - &mut TimingTree::default(), - ) - .unwrap(); - verify_stark_proof(stark, inner_proof.clone(), &inner_config).unwrap(); - set_stark_proof_with_pis_target(out_buffer, &self.starky_proof, &inner_proof); - } - - fn id(&self) -> String { - "FqExpStarkyProofGenerator".to_string() - } - fn serialize(&self, _dst: &mut Vec) -> plonky2::util::serialization::IoResult<()> { - todo!() - } - fn deserialize(_src: &mut Buffer) -> plonky2::util::serialization::IoResult { - todo!() - } -} - -pub fn fq_exp_circuit< - F: RichField + Extendable, - C: GenericConfig + 'static, - const D: usize, ->( - builder: &mut CircuitBuilder, - inputs: &[FqExpInputTarget], -) -> Vec> -where - C::Hasher: AlgebraicHasher, -{ - let n = inputs.len(); - let next_power_of_two = n.next_power_of_two(); - assert!(next_power_of_two >= 128); - let mut inputs = inputs.to_vec(); - inputs.resize(next_power_of_two, inputs.last().unwrap().clone()); - let log_num_io = next_power_of_two.trailing_zeros() as usize; - - let (inputs_constr, outputs, starky_proof) = - fq_exp_circuit_with_proof_target::(builder, log_num_io); - - for (input_c, input) in inputs_constr.iter().zip(inputs.iter()) { - FqExpInputTarget::connect(builder, input_c, input); - } - - for (input, output) in inputs.iter().zip(outputs.iter()) { - let output_generator = FqExpOutputGenerator { - input: input.to_owned(), - output: output.to_owned(), - }; - builder.add_simple_generator(output_generator); - } - - let proof_generator = FqExpStarkyProofGenerator:: { - inputs: inputs.to_vec(), - outputs: outputs.clone(), - starky_proof, - _config: PhantomData, - }; - builder.add_simple_generator(proof_generator); - - outputs[..n].to_vec() -} - #[cfg(test)] mod tests { diff --git a/src/fields/fq/exp.rs b/src/fields/fq/exp.rs index e6d14f0..97d8171 100644 --- a/src/fields/fq/exp.rs +++ b/src/fields/fq/exp.rs @@ -3,7 +3,24 @@ //<------------------------------------------>main_cols: 9*N_LIMBS + 14 //<------------------------------>range_check(start: 0, end: 9*N_LIMBS-1)) -fn constants(num_io: usize) -> ExpStarkConstants { +pub const fn num_columns(num_io: usize) -> usize { + let start_flags_col = 9 * N_LIMBS; + let num_main_cols = start_flags_col + NUM_FLAGS_COLS; + + let start_periodic_pulse_col = num_main_cols; + let start_io_pulses_col = start_periodic_pulse_col + 2; + let start_lookups_col = start_io_pulses_col + 1 + 4 * num_io; + + let num_range_check_cols = 9 * N_LIMBS - 1; + + start_lookups_col + 1 + 2 * num_range_check_cols +} + +pub const fn num_public_inputs(num_io: usize) -> usize { + FQ_EXP_IO_LEN * num_io +} + +const fn constants(num_io: usize) -> ExpStarkConstants { let start_flags_col = 9 * N_LIMBS; let num_main_cols = start_flags_col + NUM_FLAGS_COLS; @@ -44,20 +61,21 @@ use plonky2::{ polynomial::PolynomialValues, }, hash::hash_types::RichField, + iop::ext_target::ExtensionTarget, plonk::circuit_builder::CircuitBuilder, util::transpose, }; use starky::{ config::StarkConfig, constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}, - permutation::PermutationPair, + evaluation_frame::{StarkEvaluationFrame, StarkFrame}, stark::Stark, - vars::{StarkEvaluationTargets, StarkEvaluationVars}, }; use crate::{ - constants::{ExpStarkConstants, N_LIMBS}, + constants::{self, ExpStarkConstants, N_LIMBS}, modular::modular::{read_u256, write_u256}, + types::{StarkEvaluationTargets, StarkEvaluationVars}, utils::{ equals::{fq_equal_transition, fq_equal_transition_circuit, vec_equal, vec_equal_circuit}, flags::{ @@ -70,7 +88,6 @@ use crate::{ }, range_check::{ eval_u16_range_check, eval_u16_range_check_circuit, generate_u16_range_check, - u16_range_check_pairs, }, utils::{ columns_to_fq, fq_to_columns, fq_to_u32_columns, i64_to_column_positive, read_u32_fq, @@ -190,26 +207,19 @@ fn get_pulse_positions(num_io: usize) -> Vec { } #[derive(Clone, Copy)] -pub struct FqExpStark, const D: usize> { - pub num_io: usize, +pub struct FqExpStark, const D: usize, const NUM_IO: usize> { _phantom: PhantomData, } -impl, const D: usize> FqExpStark { - pub fn new(num_io: usize) -> Self { +impl, const D: usize, const NUM_IO: usize> FqExpStark { + pub fn new() -> Self { Self { - num_io, _phantom: PhantomData, } } - pub fn constants(&self) -> ExpStarkConstants { - constants(self.num_io) - } - pub fn config(&self) -> StarkConfig { - let c = self.constants(); - StarkConfig::standard_fast_config(c.num_columns, c.num_public_inputs) + StarkConfig::standard_fast_config() } pub fn generate_trace_for_one_block( @@ -218,7 +228,7 @@ impl, const D: usize> FqExpStark { offset: Fq, exp_val: [u32; NUM_INPUT_LIMBS], ) -> Vec> { - let c = self.constants(); + let c = constants(NUM_IO); let num_rows = 2 * INPUT_LIMB_BITS * NUM_INPUT_LIMBS; let mut lv = vec![F::ZERO; c.num_main_cols]; generate_flags_first_row(&mut lv, c.start_flags_col, exp_val); @@ -247,7 +257,7 @@ impl, const D: usize> FqExpStark { } pub fn generate_trace(&self, inputs: &[FqExpIONative]) -> Vec> { - let c = self.constants(); + let c = constants(NUM_IO); assert!(inputs.len() == c.num_io); let mut rows = vec![]; @@ -285,23 +295,40 @@ impl, const D: usize> FqExpStark { } } -impl, const D: usize> Stark for FqExpStark { +impl, const D: usize, const NUM_IO: usize> Stark + for FqExpStark +where + [(); num_columns(NUM_IO)]:, + [(); num_public_inputs(NUM_IO)]:, +{ + type EvaluationFrame = StarkFrame + where + FE: FieldExtension, + P: PackedField; + + type EvaluationFrameTarget = StarkFrame< + ExtensionTarget, + ExtensionTarget, + { num_columns(NUM_IO) }, + { num_public_inputs(NUM_IO) }, + >; + fn eval_packed_generic( &self, - vars: StarkEvaluationVars, + vars: &Self::EvaluationFrame, yield_constr: &mut ConstraintConsumer

, ) where FE: FieldExtension, P: PackedField, { - let c = self.constants(); + let c = constants(NUM_IO); let is_final_col = c.start_flags_col; let is_sq_col = c.start_flags_col + 2; let is_mul_col = c.start_flags_col + 4; let start_limbs_col = c.start_flags_col + 6; - let lv = vars.local_values; - let nv = vars.next_values; + let lv = vars.get_local_values(); + let nv = vars.get_next_values(); let mut cur_col = 0; let a = read_u256(lv, &mut cur_col); @@ -320,7 +347,11 @@ impl, const D: usize> Stark for FqExpStark, const D: usize> Stark for FqExpStark, const D: usize> Stark for FqExpStark, const D: usize> Stark for FqExpStark, - vars: StarkEvaluationTargets, + vars: &Self::EvaluationFrameTarget, yield_constr: &mut RecursiveConstraintConsumer, ) { let one = builder.one_extension(); - let c = self.constants(); + let c = constants(NUM_IO); let is_final_col = c.start_flags_col; let is_sq_col = c.start_flags_col + 2; let is_mul_col = c.start_flags_col + 4; let start_limbs_col = c.start_flags_col + 6; - let lv = vars.local_values; - let nv = vars.next_values; + let lv = vars.get_local_values(); + let nv = vars.get_next_values(); let mut cur_col = 0; let a = read_u256(lv, &mut cur_col); @@ -430,7 +466,7 @@ impl, const D: usize> Stark for FqExpStark, const D: usize> Stark for FqExpStark, const D: usize> Stark for FqExpStark, const D: usize> Stark for FqExpStark usize { 3 } - - fn permutation_pairs(&self) -> Vec { - let c = self.constants(); - u16_range_check_pairs( - c.start_lookups_col, - c.start_range_check_col..c.end_range_check_col, - ) - } } #[cfg(test)] diff --git a/src/fields/fq12/circuit.rs b/src/fields/fq12/circuit.rs index 09b6177..faa09d0 100644 --- a/src/fields/fq12/circuit.rs +++ b/src/fields/fq12/circuit.rs @@ -95,250 +95,6 @@ impl, const D: usize> Fq12ExpInputTarget { } } -#[derive(Clone, Debug)] -pub struct Fq12ExpOutputGenerator, const D: usize> { - pub input: Fq12ExpInputTarget, - pub output: Fq12Target, -} - -impl SimpleGenerator for Fq12ExpOutputGenerator -where - F: RichField + Extendable, -{ - fn dependencies(&self) -> Vec { - self.input.to_vec() - } - - fn run_once(&self, pw: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let x_coeffs: [Fq; 12] = self - .input - .x - .clone() - .coeffs - .map(|x| get_u256_biguint(pw, &x.to_vec()).into()); - let x: Fq12 = MyFq12 { coeffs: x_coeffs }.into(); - let offset_coeffs = self - .input - .offset - .clone() - .coeffs - .map(|x| get_u256_biguint(pw, &x.to_vec()).into()); - let offset: Fq12 = MyFq12 { - coeffs: offset_coeffs, - } - .into(); - let exp_val = get_u256_biguint(pw, &self.input.exp_val.to_vec()); - let output = offset * x.pow(&exp_val.to_u64_digits()); - self.output.set_witness(out_buffer, &output); - } - - fn id(&self) -> String { - "Fq12ExpOutputGenerator".to_string() - } - fn serialize(&self, _dst: &mut Vec) -> plonky2::util::serialization::IoResult<()> { - todo!() - } - fn deserialize(_src: &mut Buffer) -> plonky2::util::serialization::IoResult { - todo!() - } -} - -#[derive(Clone, Debug)] -pub struct Fq12ExpStarkyProofGenerator< - F: RichField + Extendable, - C: GenericConfig, - const D: usize, -> { - pub inputs: Vec>, - pub outputs: Vec>, - pub starky_proof: StarkProofWithPublicInputsTarget, - _config: std::marker::PhantomData, -} - -impl SimpleGenerator for Fq12ExpStarkyProofGenerator -where - F: RichField + Extendable, - C: GenericConfig + 'static, - C::Hasher: AlgebraicHasher, -{ - fn dependencies(&self) -> Vec { - let mut targets = vec![]; - self.inputs.iter().cloned().for_each(|input| { - targets.extend(input.to_vec()); - }); - targets - } - fn run_once(&self, pw: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let ios_native = self - .inputs - .iter() - .cloned() - .map(|input| { - let x_coeffs: [Fq; 12] = input - .x - .coeffs - .map(|x| get_u256_biguint(pw, &x.to_vec()).into()); - let x: Fq12 = MyFq12 { coeffs: x_coeffs }.into(); - let offset_coeffs = input - .offset - .coeffs - .map(|x| get_u256_biguint(pw, &x.to_vec()).into()); - let offset: Fq12 = MyFq12 { - coeffs: offset_coeffs, - } - .into(); - let exp_val = get_u256_biguint(pw, &input.exp_val.to_vec()); - let mut exp_val_u32 = exp_val.to_u32_digits(); - exp_val_u32.extend(vec![0; 8 - exp_val_u32.len()]); - let output = offset * x.pow(&exp_val.to_u64_digits()); - Fq12ExpIONative { - x, - offset, - exp_val: exp_val_u32.try_into().unwrap(), - output, - } - }) - .collect_vec(); - - let num_io = ios_native.len(); - let stark = Fq12ExpStark::::new(num_io); - let inner_config = stark.config(); - let trace = stark.generate_trace(&ios_native); - let pi = stark.generate_public_inputs(&ios_native); - let inner_proof = prove::( - stark, - &inner_config, - trace, - pi.try_into().unwrap(), - &mut TimingTree::default(), - ) - .unwrap(); - verify_stark_proof(stark, inner_proof.clone(), &inner_config).unwrap(); - set_stark_proof_with_pis_target(out_buffer, &self.starky_proof, &inner_proof); - } - - fn id(&self) -> String { - "Fq12ExpStarkyProofGenerator".to_string() - } - fn serialize(&self, _dst: &mut Vec) -> plonky2::util::serialization::IoResult<()> { - todo!() - } - fn deserialize(_src: &mut Buffer) -> plonky2::util::serialization::IoResult { - todo!() - } -} - -fn fq12_exp_circuit_with_proof_target< - F: RichField + Extendable, - C: GenericConfig, - const D: usize, ->( - builder: &mut CircuitBuilder, - log_num_io: usize, -) -> ( - Vec>, - Vec>, - StarkProofWithPublicInputsTarget, -) -where - >::Hasher: AlgebraicHasher, -{ - let num_io = 1 << log_num_io; - let stark = Fq12ExpStark::::new(num_io); - let inner_config = stark.config(); - let degree_bits = 9 + log_num_io; - let starky_proof_t = - add_virtual_stark_proof_with_pis(builder, stark, &inner_config, degree_bits); - verify_stark_proof_circuit::(builder, stark, &starky_proof_t, &inner_config); - assert!(starky_proof_t.public_inputs.len() == FQ12_EXP_IO_LEN * num_io); - let mut cur_col = 0; - let mut inputs = vec![]; - let mut outputs = vec![]; - let pi = starky_proof_t.public_inputs.clone(); - for _ in 0..num_io { - let io = read_fq12_exp_io(&pi, &mut cur_col); - let x_coeffs = - io.x.iter() - .map(|limb| { - // range check - limb.iter().for_each(|l| builder.range_check(*l, 16)); - let limb_u32 = u16_columns_to_u32_columns_base_circuit(builder, *limb); - FqTarget::from_limbs(builder, &limb_u32) - }) - .collect_vec(); - let offset_coeffs = io - .offset - .iter() - .map(|limb| { - // range check - limb.iter().for_each(|l| builder.range_check(*l, 16)); - let limb_u32 = u16_columns_to_u32_columns_base_circuit(builder, *limb); - FqTarget::from_limbs(builder, &limb_u32) - }) - .collect_vec(); - let output_coeffs = io - .output - .iter() - .map(|limb| { - // range check - // limb.iter().for_each(|l| builder.range_check(*l, 16)); - let limb_u32 = u16_columns_to_u32_columns_base_circuit(builder, *limb); - FqTarget::from_limbs(builder, &limb_u32) - }) - .collect_vec(); - let x = Fq12Target::new(x_coeffs); - let offset = Fq12Target::new(offset_coeffs); - let output = Fq12Target::new(output_coeffs); - let exp_val = U256Target::::from_vec(&io.exp_val); - let input = Fq12ExpInputTarget { x, offset, exp_val }; - inputs.push(input); - outputs.push(output); - } - (inputs, outputs, starky_proof_t) -} - -pub fn fq12_exp_circuit< - F: RichField + Extendable, - C: GenericConfig + 'static, - const D: usize, ->( - builder: &mut CircuitBuilder, - inputs: &[Fq12ExpInputTarget], -) -> Vec> -where - C::Hasher: AlgebraicHasher, -{ - let n = inputs.len(); - let next_power_of_two = n.next_power_of_two(); - let mut inputs = inputs.to_vec(); - inputs.resize(next_power_of_two, inputs.last().unwrap().clone()); - let log_num_io = next_power_of_two.trailing_zeros() as usize; - - let (inputs_constr, outputs, starky_proof) = - fq12_exp_circuit_with_proof_target::(builder, log_num_io); - - for (input_c, input) in inputs_constr.iter().zip(inputs.iter()) { - Fq12ExpInputTarget::connect(builder, input_c, input); - } - - for (input, output) in inputs.iter().zip(outputs.iter()) { - let output_generator = Fq12ExpOutputGenerator { - input: input.to_owned(), - output: output.to_owned(), - }; - builder.add_simple_generator(output_generator); - } - - let proof_generator = Fq12ExpStarkyProofGenerator:: { - inputs: inputs.to_vec(), - outputs: outputs.clone(), - starky_proof, - _config: PhantomData, - }; - builder.add_simple_generator(proof_generator); - outputs[..n].to_vec() -} - #[cfg(test)] mod tests { use std::time::Instant; @@ -420,14 +176,9 @@ mod tests { let trace = stark.generate_trace(&ios); let pi = stark.generate_public_inputs(&ios); - let inner_proof = prove::( - stark, - &inner_config, - trace, - pi.try_into().unwrap(), - &mut TimingTree::default(), - ) - .unwrap(); + let inner_proof = + prove::(stark, &inner_config, trace, &pi, &mut TimingTree::default()) + .unwrap(); verify_stark_proof(stark, inner_proof.clone(), &inner_config).unwrap(); dbg!(builder.num_gates()); diff --git a/src/fields/fq12/exp.rs b/src/fields/fq12/exp.rs index ce8adb5..8510f6f 100644 --- a/src/fields/fq12/exp.rs +++ b/src/fields/fq12/exp.rs @@ -3,7 +3,24 @@ //<------------------------------------------------->main_cols: 108*N_LIMBS + 14 // <--------->range_check(start: 24*N_LIMBS, end: 108*N_LIMBS-12)) -fn constants(num_io: usize) -> ExpStarkConstants { +pub const fn num_columns(num_io: usize) -> usize { + let start_flags_col = 108 * N_LIMBS; + let num_main_cols = start_flags_col + NUM_FLAGS_COLS; + + let start_periodic_pulse_col = num_main_cols; + let start_io_pulses_col = start_periodic_pulse_col + 2; + let start_lookups_col = start_io_pulses_col + 1 + 4 * num_io; + + let num_range_check_cols = 84 * N_LIMBS - 12; + + start_lookups_col + 1 + 6 * num_range_check_cols +} + +pub const fn num_public_inputs(num_io: usize) -> usize { + FQ12_EXP_IO_LEN * num_io +} + +const fn constants(num_io: usize) -> ExpStarkConstants { let start_flags_col = 108 * N_LIMBS; let num_main_cols = start_flags_col + NUM_FLAGS_COLS; @@ -49,6 +66,7 @@ use plonky2::{ polynomial::PolynomialValues, }, hash::hash_types::RichField, + iop::ext_target::ExtensionTarget, plonk::circuit_builder::CircuitBuilder, util::transpose, }; @@ -57,13 +75,13 @@ use plonky2_bn254::fields::native::MyFq12; use starky::{ config::StarkConfig, constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}, - permutation::PermutationPair, + evaluation_frame::{StarkEvaluationFrame, StarkFrame}, stark::Stark, - vars::{StarkEvaluationTargets, StarkEvaluationVars}, }; use crate::{ constants::{ExpStarkConstants, N_LIMBS}, + types::{StarkEvaluationTargets, StarkEvaluationVars}, utils::{ equals::{ fq12_equal_transition, fq12_equal_transition_circuit, vec_equal, vec_equal_circuit, @@ -78,7 +96,7 @@ use crate::{ }, range_check::{ eval_split_u16_range_check, eval_split_u16_range_check_circuit, - generate_split_u16_range_check, split_u16_range_check_pairs, + generate_split_u16_range_check, }, utils::{ columns_to_fq12, fq_to_columns, fq_to_u16_columns, i64_to_column_positive, read_u16_fq, @@ -226,26 +244,23 @@ pub fn get_pulse_positions(num_io: usize) -> Vec { } #[derive(Clone, Copy)] -pub struct Fq12ExpStark, const D: usize> { - pub num_io: usize, +pub struct Fq12ExpStark, const D: usize, const NUM_IO: usize> { _phantom: PhantomData, } -impl, const D: usize> Fq12ExpStark { - pub fn new(num_io: usize) -> Self { +impl, const D: usize, const NUM_IO: usize> Fq12ExpStark { + pub fn new() -> Self { Self { - num_io, _phantom: PhantomData, } } pub fn constants(&self) -> ExpStarkConstants { - constants(self.num_io) + constants(NUM_IO) } pub fn config(&self) -> StarkConfig { - let c = self.constants(); - StarkConfig::standard_fast_config(c.num_columns, c.num_public_inputs) + StarkConfig::standard_fast_config() } pub fn generate_trace_for_one_block( @@ -320,10 +335,27 @@ impl, const D: usize> Fq12ExpStark { } } -impl, const D: usize> Stark for Fq12ExpStark { +impl, const D: usize, const NUM_IO: usize> Stark + for Fq12ExpStark +where + [(); num_columns(NUM_IO)]:, + [(); num_public_inputs(NUM_IO)]:, +{ + type EvaluationFrame = StarkFrame + where + FE: FieldExtension, + P: PackedField; + + type EvaluationFrameTarget = StarkFrame< + ExtensionTarget, + ExtensionTarget, + { num_columns(NUM_IO) }, + { num_public_inputs(NUM_IO) }, + >; + fn eval_packed_generic( &self, - vars: StarkEvaluationVars, + vars: &Self::EvaluationFrame, yield_constr: &mut ConstraintConsumer

, ) where FE: FieldExtension, @@ -335,8 +367,8 @@ impl, const D: usize> Stark for Fq12ExpStark< let is_mul_col = c.start_flags_col + 4; let start_limbs_col = c.start_flags_col + 6; - let lv = vars.local_values; - let nv = vars.next_values; + let lv = vars.get_local_values(); + let nv = vars.get_next_values(); let mut cur_col = 0; let a = read_fq12(lv, &mut cur_col); @@ -355,7 +387,11 @@ impl, const D: usize> Stark for Fq12ExpStark< yield_constr.constraint(is_final - sum_is_output); // public inputs - let pi: &[P] = &vars.public_inputs.iter().map(|&x| x.into()).collect_vec(); + let pi: &[P] = &vars + .get_public_inputs() + .iter() + .map(|&x| x.into()) + .collect_vec(); cur_col = 0; for i in (0..2 * c.num_io).step_by(2) { let fq12_exp_io = read_fq12_exp_io(pi, &mut cur_col); @@ -399,14 +435,14 @@ impl, const D: usize> Stark for Fq12ExpStark< // flags, pulses, and lookup eval_flags( yield_constr, - vars.local_values, - vars.next_values, + vars.get_local_values(), + vars.get_next_values(), c.start_flags_col, ); eval_periodic_pulse( yield_constr, - vars.local_values, - vars.next_values, + vars.get_local_values(), + vars.get_next_values(), c.start_flags_col + 1, c.start_periodic_pulse_col, 2 * INPUT_LIMB_BITS, @@ -414,11 +450,16 @@ impl, const D: usize> Stark for Fq12ExpStark< ); eval_pulse( yield_constr, - vars.local_values, - vars.next_values, + vars.get_local_values(), + vars.get_next_values(), c.start_io_pulses_col, get_pulse_positions(c.num_io), ); + let vars = StarkEvaluationVars { + local_values: vars.get_local_values(), + next_values: vars.get_next_values(), + public_inputs: vars.get_public_inputs(), + }; eval_split_u16_range_check( vars, yield_constr, @@ -430,7 +471,7 @@ impl, const D: usize> Stark for Fq12ExpStark< fn eval_ext_circuit( &self, builder: &mut CircuitBuilder, - vars: StarkEvaluationTargets, + vars: &Self::EvaluationFrameTarget, yield_constr: &mut RecursiveConstraintConsumer, ) { let one = builder.one_extension(); @@ -440,8 +481,8 @@ impl, const D: usize> Stark for Fq12ExpStark< let is_mul_col = c.start_flags_col + 4; let start_limbs_col = c.start_flags_col + 6; - let lv = vars.local_values; - let nv = vars.next_values; + let lv = vars.get_local_values(); + let nv = vars.get_next_values(); let mut cur_col = 0; let a = read_fq12(lv, &mut cur_col); @@ -464,7 +505,7 @@ impl, const D: usize> Stark for Fq12ExpStark< // public inputs cur_col = 0; for i in (0..2 * c.num_io).step_by(2) { - let fq12_exp_io = read_fq12_exp_io(vars.public_inputs, &mut cur_col); + let fq12_exp_io = read_fq12_exp_io(vars.get_public_inputs(), &mut cur_col); let is_ith_input = lv[get_pulse_col(c.start_io_pulses_col, i)]; let is_ith_output = lv[get_pulse_col(c.start_io_pulses_col, i + 1)]; (0..12).for_each(|i| { @@ -560,15 +601,15 @@ impl, const D: usize> Stark for Fq12ExpStark< eval_flags_circuit( builder, yield_constr, - vars.local_values, - vars.next_values, + vars.get_local_values(), + vars.get_next_values(), c.start_flags_col, ); eval_periodic_pulse_circuit( builder, yield_constr, - vars.local_values, - vars.next_values, + vars.get_local_values(), + vars.get_next_values(), c.start_flags_col + 1, c.start_periodic_pulse_col, 2 * INPUT_LIMB_BITS, @@ -577,11 +618,16 @@ impl, const D: usize> Stark for Fq12ExpStark< eval_pulse_circuit( builder, yield_constr, - vars.local_values, - vars.next_values, + vars.get_local_values(), + vars.get_next_values(), c.start_io_pulses_col, get_pulse_positions(c.num_io), ); + let vars = StarkEvaluationTargets { + local_values: vars.get_local_values(), + next_values: vars.get_next_values(), + public_inputs: vars.get_public_inputs(), + }; eval_split_u16_range_check_circuit( builder, vars, @@ -594,14 +640,6 @@ impl, const D: usize> Stark for Fq12ExpStark< fn constraint_degree(&self) -> usize { 3 } - - fn permutation_pairs(&self) -> Vec { - let c = self.constants(); - split_u16_range_check_pairs( - c.start_lookups_col, - c.start_range_check_col..c.end_range_check_col, - ) - } } #[cfg(test)] diff --git a/src/fields/fq12_u64/circuit.rs b/src/fields/fq12_u64/circuit.rs index a65e9c5..15797c2 100644 --- a/src/fields/fq12_u64/circuit.rs +++ b/src/fields/fq12_u64/circuit.rs @@ -2,7 +2,8 @@ use std::marker::PhantomData; use crate::{ fields::fq12_u64::exp_u64::{ - read_fq12_exp_u64_io, Fq12ExpU64IONative, Fq12ExpU64Stark, FQ12_EXP_U64_IO_LEN, + num_columns, num_public_inputs, read_fq12_exp_u64_io, Fq12ExpU64IONative, Fq12ExpU64Stark, + FQ12_EXP_U64_IO_LEN, }, utils::utils::{get_u256_biguint, u16_columns_to_u32_columns_base_circuit}, }; @@ -17,10 +18,12 @@ use plonky2::{ target::Target, witness::{PartialWitness, PartitionWitness, Witness, WitnessWrite}, }, + plonk::circuit_data::CommonCircuitData, plonk::{ circuit_builder::CircuitBuilder, config::{AlgebraicHasher, GenericConfig}, }, + util::serialization::IoResult, util::{serialization::Buffer, timing::TimingTree}, }; use plonky2_bn254::fields::{fq12_target::Fq12Target, fq_target::FqTarget, native::MyFq12}; @@ -96,7 +99,7 @@ pub struct Fq12ExpU64OutputGenerator, const D: usiz pub output: Fq12Target, } -impl SimpleGenerator for Fq12ExpU64OutputGenerator +impl SimpleGenerator for Fq12ExpU64OutputGenerator where F: RichField + Extendable, { @@ -130,10 +133,14 @@ where fn id(&self) -> String { "Fq12ExpU64OutputGenerator".to_string() } - fn serialize(&self, _dst: &mut Vec) -> plonky2::util::serialization::IoResult<()> { + fn serialize( + &self, + _dst: &mut Vec, + _common_data: &CommonCircuitData, + ) -> IoResult<()> { todo!() } - fn deserialize(_src: &mut Buffer) -> plonky2::util::serialization::IoResult { + fn deserialize(_src: &mut Buffer, _common_data: &CommonCircuitData) -> IoResult { todo!() } } @@ -143,18 +150,23 @@ pub struct Fq12ExpU64StarkyProofGenerator< F: RichField + Extendable, C: GenericConfig, const D: usize, + const NUM_IO: usize, > { pub inputs: Vec>, pub outputs: Vec>, pub starky_proof: StarkProofWithPublicInputsTarget, + pub zero: Target, _config: std::marker::PhantomData, } -impl SimpleGenerator for Fq12ExpU64StarkyProofGenerator +impl SimpleGenerator + for Fq12ExpU64StarkyProofGenerator where F: RichField + Extendable, C: GenericConfig + 'static, C::Hasher: AlgebraicHasher, + [(); num_columns(NUM_IO)]:, + [(); num_public_inputs(NUM_IO)]:, { fn dependencies(&self) -> Vec { let mut targets = vec![]; @@ -164,6 +176,7 @@ where targets } fn run_once(&self, pw: &PartitionWitness, out_buffer: &mut GeneratedValues) { + assert_eq!(self.inputs.len(), NUM_IO); let ios_native = self .inputs .iter() @@ -193,30 +206,29 @@ where }) .collect_vec(); - let num_io = ios_native.len(); - let stark = Fq12ExpU64Stark::::new(num_io); + assert_eq!(ios_native.len(), NUM_IO); + let stark = Fq12ExpU64Stark::::new(); let inner_config = stark.config(); let trace = stark.generate_trace(&ios_native); let pi = stark.generate_public_inputs(&ios_native); - let inner_proof = prove::( - stark, - &inner_config, - trace, - pi.try_into().unwrap(), - &mut TimingTree::default(), - ) - .unwrap(); + let inner_proof = + prove::(stark, &inner_config, trace, &pi, &mut TimingTree::default()) + .unwrap(); verify_stark_proof(stark, inner_proof.clone(), &inner_config).unwrap(); - set_stark_proof_with_pis_target(out_buffer, &self.starky_proof, &inner_proof); + set_stark_proof_with_pis_target(out_buffer, &self.starky_proof, &inner_proof, self.zero); } fn id(&self) -> String { "Fq12ExpU64StarkyProofGenerator".to_string() } - fn serialize(&self, _dst: &mut Vec) -> plonky2::util::serialization::IoResult<()> { + fn serialize( + &self, + _dst: &mut Vec, + _common_data: &CommonCircuitData, + ) -> IoResult<()> { todo!() } - fn deserialize(_src: &mut Buffer) -> plonky2::util::serialization::IoResult { + fn deserialize(_src: &mut Buffer, _common_data: &CommonCircuitData) -> IoResult { todo!() } } @@ -225,9 +237,9 @@ fn fq12_exp_u64_circuit_with_proof_target< F: RichField + Extendable, C: GenericConfig, const D: usize, + const NUM_IO: usize, >( builder: &mut CircuitBuilder, - log_num_io: usize, ) -> ( Vec>, Vec>, @@ -235,20 +247,22 @@ fn fq12_exp_u64_circuit_with_proof_target< ) where >::Hasher: AlgebraicHasher, + [(); num_columns(NUM_IO)]:, + [(); num_public_inputs(NUM_IO)]:, { - let num_io = 1 << log_num_io; - let stark = Fq12ExpU64Stark::::new(num_io); + let log_num_io = NUM_IO.trailing_zeros() as usize; + let stark = Fq12ExpU64Stark::::new(); let inner_config = stark.config(); let degree_bits = 7 + log_num_io; let starky_proof_t = - add_virtual_stark_proof_with_pis(builder, stark, &inner_config, degree_bits); - verify_stark_proof_circuit::(builder, stark, &starky_proof_t, &inner_config); - assert!(starky_proof_t.public_inputs.len() == FQ12_EXP_U64_IO_LEN * num_io); + add_virtual_stark_proof_with_pis(builder, &stark, &inner_config, degree_bits, 0, 0); + verify_stark_proof_circuit::(builder, stark, starky_proof_t.clone(), &inner_config); + assert!(starky_proof_t.public_inputs.len() == FQ12_EXP_U64_IO_LEN * NUM_IO); let mut cur_col = 0; let mut inputs = vec![]; let mut outputs = vec![]; let pi = starky_proof_t.public_inputs.clone(); - for _ in 0..num_io { + for _ in 0..NUM_IO { let io = read_fq12_exp_u64_io(&pi, &mut cur_col); let x_coeffs = io.x.iter() @@ -294,21 +308,24 @@ pub fn fq12_exp_u64_circuit< F: RichField + Extendable, C: GenericConfig + 'static, const D: usize, + const NUM_IO: usize, >( builder: &mut CircuitBuilder, inputs: &[Fq12ExpU64InputTarget], ) -> Vec> where C::Hasher: AlgebraicHasher, + [(); num_columns(NUM_IO)]:, + [(); num_public_inputs(NUM_IO)]:, { + assert!(NUM_IO.is_power_of_two()); let n = inputs.len(); - let next_power_of_two = n.next_power_of_two(); + assert!(n <= NUM_IO); let mut inputs = inputs.to_vec(); - inputs.resize(next_power_of_two, inputs.last().unwrap().clone()); - let log_num_io = next_power_of_two.trailing_zeros() as usize; + inputs.resize(NUM_IO, inputs.last().unwrap().clone()); let (inputs_constr, outputs, starky_proof) = - fq12_exp_u64_circuit_with_proof_target::(builder, log_num_io); + fq12_exp_u64_circuit_with_proof_target::(builder); for (input_c, input) in inputs_constr.iter().zip(inputs.iter()) { Fq12ExpU64InputTarget::connect(builder, input_c, input); @@ -322,10 +339,11 @@ where builder.add_simple_generator(output_generator); } - let proof_generator = Fq12ExpU64StarkyProofGenerator:: { + let proof_generator = Fq12ExpU64StarkyProofGenerator:: { inputs: inputs.to_vec(), outputs: outputs.clone(), starky_proof, + zero: builder.zero(), _config: PhantomData, }; builder.add_simple_generator(proof_generator); diff --git a/src/fields/fq12_u64/exp_u64.rs b/src/fields/fq12_u64/exp_u64.rs index 2b00f3c..07a1167 100644 --- a/src/fields/fq12_u64/exp_u64.rs +++ b/src/fields/fq12_u64/exp_u64.rs @@ -3,6 +3,22 @@ //<------------------------------------------------->main_cols: 108*N_LIMBS + 6 // <--------->range_check(start: 24*N_LIMBS, end: 108*N_LIMBS-12)) +pub const fn num_columns(num_io: usize) -> usize { + let start_flags_col = 108 * N_LIMBS; + let num_main_cols = start_flags_col + NUM_FLAGS_U64_COLS; + + let start_io_pulses_col = num_main_cols; + let start_lookups_col = start_io_pulses_col + 1 + 4 * num_io; + + let num_range_check_cols = 84 * N_LIMBS - 12; + + start_lookups_col + 1 + 6 * num_range_check_cols +} + +pub const fn num_public_inputs(num_io: usize) -> usize { + FQ12_EXP_U64_IO_LEN * num_io +} + pub struct ExpU64StarkConstants { pub num_columns: usize, pub num_public_inputs: usize, @@ -16,7 +32,7 @@ pub struct ExpU64StarkConstants { pub num_range_check_cols: usize, } -fn constants(num_io: usize) -> ExpU64StarkConstants { +const fn constants(num_io: usize) -> ExpU64StarkConstants { let start_flags_col = 108 * N_LIMBS; let num_main_cols = start_flags_col + NUM_FLAGS_U64_COLS; @@ -58,7 +74,7 @@ use crate::{ utils::pulse::{eval_pulse, eval_pulse_circuit, generate_pulse, get_pulse_col}, utils::range_check::{ eval_split_u16_range_check, eval_split_u16_range_check_circuit, - generate_split_u16_range_check, split_u16_range_check_pairs, + generate_split_u16_range_check, }, utils::utils::{ columns_to_fq12, fq_to_columns, fq_to_u16_columns, i64_to_column_positive, read_u16_fq, @@ -74,17 +90,18 @@ use plonky2::{ polynomial::PolynomialValues, }, hash::hash_types::RichField, + iop::ext_target::ExtensionTarget, plonk::circuit_builder::CircuitBuilder, util::transpose, }; +use crate::types::{StarkEvaluationTargets, StarkEvaluationVars}; use plonky2_bn254::fields::native::MyFq12; use starky::{ config::StarkConfig, constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}, - permutation::PermutationPair, + evaluation_frame::{StarkEvaluationFrame, StarkFrame}, stark::Stark, - vars::{StarkEvaluationTargets, StarkEvaluationVars}, }; use super::flags_u64::{eval_flags_u64, eval_flags_u64_circuit, NUM_FLAGS_U64_COLS}; @@ -231,26 +248,25 @@ pub fn get_pulse_u64_positions(num_io: usize) -> Vec { } #[derive(Clone, Copy)] -pub struct Fq12ExpU64Stark, const D: usize> { - pub num_io: usize, +pub struct Fq12ExpU64Stark, const D: usize, const NUM_IO: usize> { _phantom: PhantomData, } -impl, const D: usize> Fq12ExpU64Stark { - pub fn new(num_io: usize) -> Self { +impl, const D: usize, const NUM_IO: usize> + Fq12ExpU64Stark +{ + pub fn new() -> Self { Self { - num_io, _phantom: PhantomData, } } pub fn constants(&self) -> ExpU64StarkConstants { - constants(self.num_io) + constants(NUM_IO) } pub fn config(&self) -> StarkConfig { - let c = self.constants(); - StarkConfig::standard_fast_config(c.num_columns, c.num_public_inputs) + StarkConfig::standard_fast_config() } pub fn generate_trace_for_one_block(&self, x: Fq12, offset: Fq12, exp_val: u64) -> Vec> { @@ -311,10 +327,27 @@ impl, const D: usize> Fq12ExpU64Stark { } } -impl, const D: usize> Stark for Fq12ExpU64Stark { +impl, const D: usize, const NUM_IO: usize> Stark + for Fq12ExpU64Stark +where + [(); num_columns(NUM_IO)]:, + [(); num_public_inputs(NUM_IO)]:, +{ + type EvaluationFrame = StarkFrame + where + FE: FieldExtension, + P: PackedField; + + type EvaluationFrameTarget = StarkFrame< + ExtensionTarget, + ExtensionTarget, + { num_columns(NUM_IO) }, + { num_public_inputs(NUM_IO) }, + >; + fn eval_packed_generic( &self, - vars: StarkEvaluationVars, + vars: &Self::EvaluationFrame, yield_constr: &mut ConstraintConsumer

, ) where FE: FieldExtension, @@ -326,8 +359,8 @@ impl, const D: usize> Stark for Fq12ExpU64Sta let is_mul_col = c.start_flags_col + 3; let exp_val_col = c.start_flags_col + 5; - let lv = vars.local_values; - let nv = vars.next_values; + let lv = vars.get_local_values(); + let nv = vars.get_next_values(); let mut cur_col = 0; let a = read_fq12(lv, &mut cur_col); @@ -346,7 +379,11 @@ impl, const D: usize> Stark for Fq12ExpU64Sta yield_constr.constraint(is_final - sum_is_output); // public inputs - let pi: &[P] = &vars.public_inputs.iter().map(|&x| x.into()).collect_vec(); + let pi: &[P] = &vars + .get_public_inputs() + .iter() + .map(|&x| x.into()) + .collect_vec(); cur_col = 0; for i in (0..2 * c.num_io).step_by(2) { let fq12_exp_io = read_fq12_exp_u64_io(pi, &mut cur_col); @@ -389,17 +426,22 @@ impl, const D: usize> Stark for Fq12ExpU64Sta // flags and lookup eval_flags_u64( yield_constr, - vars.local_values, - vars.next_values, + vars.get_local_values(), + vars.get_next_values(), c.start_flags_col, ); eval_pulse( yield_constr, - vars.local_values, - vars.next_values, + vars.get_local_values(), + vars.get_next_values(), c.start_io_pulses_col, get_pulse_u64_positions(c.num_io), ); + let vars = StarkEvaluationVars { + local_values: vars.get_local_values(), + next_values: vars.get_next_values(), + public_inputs: vars.get_public_inputs(), + }; eval_split_u16_range_check( vars, yield_constr, @@ -411,7 +453,7 @@ impl, const D: usize> Stark for Fq12ExpU64Sta fn eval_ext_circuit( &self, builder: &mut CircuitBuilder, - vars: StarkEvaluationTargets, + vars: &Self::EvaluationFrameTarget, yield_constr: &mut RecursiveConstraintConsumer, ) { let one = builder.one_extension(); @@ -421,8 +463,8 @@ impl, const D: usize> Stark for Fq12ExpU64Sta let is_mul_col = c.start_flags_col + 3; let exp_val_col = c.start_flags_col + 5; - let lv = vars.local_values; - let nv = vars.next_values; + let lv = vars.get_local_values(); + let nv = vars.get_next_values(); let mut cur_col = 0; let a = read_fq12(lv, &mut cur_col); @@ -445,7 +487,7 @@ impl, const D: usize> Stark for Fq12ExpU64Sta // public inputs cur_col = 0; for i in (0..2 * c.num_io).step_by(2) { - let fq12_exp_io = read_fq12_exp_u64_io(vars.public_inputs, &mut cur_col); + let fq12_exp_io = read_fq12_exp_u64_io(vars.get_public_inputs(), &mut cur_col); let is_ith_input = lv[get_pulse_col(c.start_io_pulses_col, i)]; let is_ith_output = lv[get_pulse_col(c.start_io_pulses_col, i + 1)]; (0..12).for_each(|i| { @@ -536,18 +578,23 @@ impl, const D: usize> Stark for Fq12ExpU64Sta eval_flags_u64_circuit( builder, yield_constr, - vars.local_values, - vars.next_values, + vars.get_local_values(), + vars.get_next_values(), c.start_flags_col, ); eval_pulse_circuit( builder, yield_constr, - vars.local_values, - vars.next_values, + vars.get_local_values(), + vars.get_next_values(), c.start_io_pulses_col, get_pulse_u64_positions(c.num_io), ); + let vars = StarkEvaluationTargets { + local_values: vars.get_local_values(), + next_values: vars.get_next_values(), + public_inputs: vars.get_public_inputs(), + }; eval_split_u16_range_check_circuit( builder, vars, @@ -560,14 +607,6 @@ impl, const D: usize> Stark for Fq12ExpU64Sta fn constraint_degree(&self) -> usize { 3 } - - fn permutation_pairs(&self) -> Vec { - let c = self.constants(); - split_u16_range_check_pairs( - c.start_lookups_col, - c.start_range_check_col..c.end_range_check_col, - ) - } } mod tests { @@ -629,14 +668,9 @@ mod tests { let now = Instant::now(); let trace = stark.generate_trace(&inputs); let pi = stark.generate_public_inputs(&inputs); - let inner_proof = prove::( - stark, - &inner_config, - trace, - pi.try_into().unwrap(), - &mut TimingTree::default(), - ) - .unwrap(); + let inner_proof = + prove::(stark, &inner_config, trace, &pi, &mut TimingTree::default()) + .unwrap(); verify_stark_proof(stark, inner_proof.clone(), &inner_config).unwrap(); println!("end stark proof generation: {:?}", now.elapsed()); diff --git a/src/fields/fq12_u64/mod.rs b/src/fields/fq12_u64/mod.rs index 5ec1d2e..ca4679c 100644 --- a/src/fields/fq12_u64/mod.rs +++ b/src/fields/fq12_u64/mod.rs @@ -1,3 +1,3 @@ -pub mod flags_u64; +pub mod circuit; pub mod exp_u64; -pub mod circuit; \ No newline at end of file +pub mod flags_u64; diff --git a/src/fields/mod.rs b/src/fields/mod.rs index c0ec642..65c0f1c 100644 --- a/src/fields/mod.rs +++ b/src/fields/mod.rs @@ -1,4 +1,4 @@ pub mod fq; pub mod fq12; pub mod fq12_u64; -pub mod fq2; \ No newline at end of file +// pub mod fq2; diff --git a/src/lib.rs b/src/lib.rs index c840379..44484ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,8 @@ +#![feature(generic_const_exprs)] + pub mod constants; -pub mod curves; +// pub mod curves; pub mod fields; pub mod modular; +pub mod types; pub mod utils; diff --git a/src/types.rs b/src/types.rs new file mode 100644 index 0000000..bb581ca --- /dev/null +++ b/src/types.rs @@ -0,0 +1,21 @@ +use plonky2::field::packed::PackedField; +use plonky2::field::types::Field; +use plonky2::iop::ext_target::ExtensionTarget; + +#[derive(Debug, Copy, Clone)] +pub struct StarkEvaluationVars<'a, F, P> +where + F: Field, + P: PackedField, +{ + pub local_values: &'a [P], + pub next_values: &'a [P], + pub public_inputs: &'a [P::Scalar], +} + +#[derive(Debug, Copy, Clone)] +pub struct StarkEvaluationTargets<'a, const D: usize> { + pub local_values: &'a [ExtensionTarget], + pub next_values: &'a [ExtensionTarget], + pub public_inputs: &'a [ExtensionTarget], +} diff --git a/src/utils/lookup.rs b/src/utils/lookup.rs index 12c535e..89d79a5 100644 --- a/src/utils/lookup.rs +++ b/src/utils/lookup.rs @@ -7,8 +7,8 @@ use plonky2::field::types::{Field, PrimeField64}; use plonky2::hash::hash_types::RichField; use plonky2::plonk::circuit_builder::CircuitBuilder; +use crate::types::{StarkEvaluationTargets, StarkEvaluationVars}; use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; -use starky::vars::{StarkEvaluationTargets, StarkEvaluationVars}; pub fn eval_lookups>( vars: StarkEvaluationVars, diff --git a/src/utils/range_check.rs b/src/utils/range_check.rs index b1033b0..5870b7e 100644 --- a/src/utils/range_check.rs +++ b/src/utils/range_check.rs @@ -9,12 +9,9 @@ use plonky2::{ use super::lookup::{eval_lookups, eval_lookups_circuit, permuted_cols}; use crate::constants::LIMB_BITS; +use crate::types::{StarkEvaluationTargets, StarkEvaluationVars}; -use starky::{ - constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}, - permutation::PermutationPair, - vars::{StarkEvaluationTargets, StarkEvaluationVars}, -}; +use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; /// 1 + 2*target_cols.len() pub fn generate_u16_range_check( @@ -93,25 +90,6 @@ pub fn eval_u16_range_check_circuit, const D: usize yield_constr.constraint_last_row(builder, t); } -pub fn u16_range_check_pairs( - start_lookups: usize, - target_cols: Range, -) -> Vec { - let mut pairs = vec![]; - - for (i, pos) in target_cols.enumerate() { - // table - pairs.push(PermutationPair::singletons( - start_lookups, - start_lookups + 1 + 2 * i + 1, - )); - - // cols - pairs.push(PermutationPair::singletons(pos, start_lookups + 1 + 2 * i)); - } - pairs -} - /// 1 + 6*target_cols.len() pub fn generate_split_u16_range_check( target_cols: Range, @@ -226,21 +204,3 @@ pub fn eval_split_u16_range_check_circuit, const D: let t = builder.sub_extension(cur_table, range_max); yield_constr.constraint_last_row(builder, t); } - -pub fn split_u16_range_check_pairs( - main_col: usize, - target_cols: Range, -) -> Vec { - let mut pairs = vec![]; - - for i in (main_col + 1..main_col + 1 + 6 * target_cols.len()).step_by(6) { - // table - pairs.push(PermutationPair::singletons(main_col, i + 2)); - pairs.push(PermutationPair::singletons(main_col, i + 5)); - - // cols - pairs.push(PermutationPair::singletons(i, i + 1)); - pairs.push(PermutationPair::singletons(i + 3, i + 4)); - } - pairs -}