From 959892e4463ecfbd4082d231d7d3a432afd07cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=B6rgens?= Date: Fri, 6 Dec 2024 20:00:09 +0800 Subject: [PATCH 1/7] Upgrade `pprof` (#706) See https://github.com/scroll-tech/ceno/security/dependabot/3 for why. --- Cargo.lock | 236 +++++++++++++++++---------------- Cargo.toml | 2 +- ceno_zkvm/Cargo.toml | 4 +- ceno_zkvm/benches/riscv_add.rs | 2 +- 4 files changed, 129 insertions(+), 115 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c671c4904..fc7da65b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,9 +59,9 @@ checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] name = "anstream" -version = "0.6.15" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" dependencies = [ "anstyle", "anstyle-parse", @@ -74,43 +74,43 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" [[package]] name = "anstyle-parse" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.4" +version = "3.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" dependencies = [ "anstyle", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "anyhow" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" +checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7" [[package]] name = "ark-std" @@ -162,12 +162,6 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bitflags" version = "2.6.0" @@ -205,9 +199,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.19.0" +version = "1.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8334215b81e418a0a7bdb8ef0849474f40bb10c8b71f1c4ed315cff49f32494d" +checksum = "8b37c88a63ffd85d15b406896cc343916d7cf57838a847b3a6f2ca5d39a5695a" [[package]] name = "byteorder" @@ -223,9 +217,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.1.31" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f" +checksum = "f34d93e62b03caf570cccc334cbc6c2fceca82f39211051345108adcba3eebdc" dependencies = [ "shlex", ] @@ -276,7 +270,7 @@ dependencies = [ "multilinear_extensions", "num-traits", "paste", - "pprof", + "pprof2", "prettytable-rs", "rand", "rand_chacha", @@ -339,9 +333,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.21" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f" +checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" dependencies = [ "clap_builder", "clap_derive", @@ -349,9 +343,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.21" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec" +checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" dependencies = [ "anstream", "anstyle", @@ -368,20 +362,20 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.90", ] [[package]] name = "clap_lex" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "colorchoice" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" [[package]] name = "colored" @@ -430,9 +424,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.14" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +checksum = "16b80225097f2e5ae4e7179dd2266824648f3e2f49d9134d584b76389d31c4c3" dependencies = [ "libc", ] @@ -644,19 +638,19 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.9" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "fastrand" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" +checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" [[package]] name = "ff" @@ -848,9 +842,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "indexmap" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" dependencies = [ "equivalent", "hashbrown 0.15.2", @@ -858,13 +852,12 @@ dependencies = [ [[package]] name = "inferno" -version = "0.11.21" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "232929e1d75fe899576a3d5c7416ad0d88dbfbb3c3d6aa00873a7408a50ddb88" +checksum = "75a5d75fee4d36809e6b021e4b96b686e763d365ffdb03af2bd00786353f84fe" dependencies = [ "ahash", "indexmap", - "is-terminal", "itoa", "log", "num-format", @@ -938,16 +931,17 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.11" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "js-sys" -version = "0.3.72" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" +checksum = "a865e038f7f6ed956f788f0d7d60c541fff74c7bd74272c5d4cf15c63743e705" dependencies = [ + "once_cell", "wasm-bindgen", ] @@ -972,9 +966,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.161" +version = "0.2.167" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" +checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" [[package]] name = "libredox" @@ -982,7 +976,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.6.0", + "bitflags", "libc", ] @@ -1085,11 +1079,11 @@ dependencies = [ [[package]] name = "nix" -version = "0.26.4" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" +checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" dependencies = [ - "bitflags 1.3.2", + "bitflags", "cfg-if", "libc", ] @@ -1147,7 +1141,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.90", ] [[package]] @@ -1273,9 +1267,9 @@ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "pin-project-lite" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" [[package]] name = "plonky2" @@ -1376,10 +1370,10 @@ dependencies = [ ] [[package]] -name = "pprof" -version = "0.13.0" +name = "pprof2" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef5c97c51bd34c7e742402e216abdeb44d415fbe6ae41d56b114723e953711cb" +checksum = "8961ed0a916b512e565f8070eb0dfa05773dd140160b45ac9a5ad339b557adeb" dependencies = [ "backtrace", "cfg-if", @@ -1394,7 +1388,7 @@ dependencies = [ "smallvec", "symbolic-demangle", "tempfile", - "thiserror", + "thiserror 2.0.4", ] [[package]] @@ -1432,18 +1426,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.88" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] [[package]] name = "quick-xml" -version = "0.26.0" +version = "0.37.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f50b1c63b38611e7d4d7f68b82d3ad0cc71a2ad2e7f61fc10f1328d917c93cd" +checksum = "f22f29bdff3987b4d8632ef95fd6424ec7e4e0a57e2f4fc63e489e75357f6a03" dependencies = [ "memchr", ] @@ -1520,7 +1514,7 @@ version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ - "bitflags 2.6.0", + "bitflags", ] [[package]] @@ -1531,18 +1525,18 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ "getrandom", "libredox", - "thiserror", + "thiserror 1.0.69", ] [[package]] name = "regex" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.8", + "regex-automata 0.4.9", "regex-syntax 0.8.5", ] @@ -1557,9 +1551,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -1608,7 +1602,7 @@ checksum = "f265be5d634272320a7de94cea15c22a3bfdd4eb42eb43edc528415f066a1f25" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.90", ] [[package]] @@ -1625,11 +1619,11 @@ checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustix" -version = "0.38.40" +version = "0.38.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0" +checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" dependencies = [ - "bitflags 2.6.0", + "bitflags", "errno", "libc", "linux-raw-sys", @@ -1680,7 +1674,7 @@ checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.90", ] [[package]] @@ -1762,7 +1756,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.82", + "syn 2.0.90", ] [[package]] @@ -1791,9 +1785,9 @@ dependencies = [ [[package]] name = "symbolic-common" -version = "12.12.0" +version = "12.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "366f1b4c6baf6cfefc234bbd4899535fca0b06c74443039a73f6dfb2fad88d77" +checksum = "e5ba5365997a4e375660bed52f5b42766475d5bc8ceb1bb13fea09c469ea0f49" dependencies = [ "debugid", "memmap2", @@ -1803,9 +1797,9 @@ dependencies = [ [[package]] name = "symbolic-demangle" -version = "12.12.0" +version = "12.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aba05ba5b9962ea5617baf556293720a8b2d0a282aa14ee4bf10e22efc7da8c8" +checksum = "beff338b2788519120f38c59ff4bb15174f52a183e547bac3d6072c2c0aa48aa" dependencies = [ "cpp_demangle", "rustc-demangle", @@ -1825,9 +1819,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.82" +version = "2.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021" +checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" dependencies = [ "proc-macro2", "quote", @@ -1866,22 +1860,42 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.64" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +checksum = "2f49a1853cf82743e3b7950f77e0f4d622ca36cf4317cba00c767838bac8d490" dependencies = [ - "thiserror-impl", + "thiserror-impl 2.0.4", ] [[package]] name = "thiserror-impl" -version = "1.0.64" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.90", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8381894bb3efe0c4acac3ded651301ceee58a15d47c2e34885ed1908ad667061" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", ] [[package]] @@ -1932,7 +1946,7 @@ checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.90", ] [[package]] @@ -1952,7 +1966,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee40835db14ddd1e3ba414292272eddde9dad04d3d4b65509656414d1c42592f" dependencies = [ "smallvec", - "thiserror", + "thiserror 1.0.69", "tracing", "tracing-subscriber", ] @@ -2018,9 +2032,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "unicode-width" @@ -2080,9 +2094,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.95" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" +checksum = "d15e63b4482863c109d70a7b8706c1e364eb6ea449b201a76c5b89cedcec2d5c" dependencies = [ "cfg-if", "once_cell", @@ -2091,24 +2105,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.95" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" +checksum = "8d36ef12e3aaca16ddd3f67922bc63e48e953f126de60bd33ccc0101ef9998cd" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.90", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.95" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" +checksum = "705440e08b42d3e4b36de7d66c944be628d579796b8090bfa3471478a2260051" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2116,28 +2130,28 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.95" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" +checksum = "98c9ae5a76e46f4deecd0f0255cc223cfa18dc9b261213b8aa0c7b36f61b3f1d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.90", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.95" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" +checksum = "6ee99da9c5ba11bd675621338ef6fa52296b76b83305e9b6e5c77d4c286d6d49" [[package]] name = "web-sys" -version = "0.3.72" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112" +checksum = "a98bc3c33f0fe7e59ad7cd041b89034fa82a7c2d4365ca538dda6cdaf513863c" dependencies = [ "js-sys", "wasm-bindgen", @@ -2359,5 +2373,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.90", ] diff --git a/Cargo.toml b/Cargo.toml index 593fc5471..1ee0b66ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ num-traits = "0.2" paste = "1" plonky2 = "0.2" poseidon = { path = "./poseidon" } -pprof = { version = "0.13", features = ["flamegraph"] } +pprof2 = { version = "0.13", features = ["flamegraph"] } prettytable-rs = "^0.10" rand = "0.8" rand_chacha = { version = "0.3", features = ["serde1"] } diff --git a/ceno_zkvm/Cargo.toml b/ceno_zkvm/Cargo.toml index 014b33da4..f5bd125e7 100644 --- a/ceno_zkvm/Cargo.toml +++ b/ceno_zkvm/Cargo.toml @@ -46,14 +46,14 @@ thread_local = "1.1" [dev-dependencies] cfg-if.workspace = true criterion.workspace = true -pprof.workspace = true +pprof2.workspace = true [build-dependencies] glob = "0.3" [features] default = ["riv32", "forbid_overflow"] -flamegraph = ["pprof/flamegraph", "pprof/criterion"] +flamegraph = ["pprof2/flamegraph", "pprof2/criterion"] forbid_overflow = [] non_pow2_rayon_thread = [] riv32 = [] diff --git a/ceno_zkvm/benches/riscv_add.rs b/ceno_zkvm/benches/riscv_add.rs index 8b948a48a..d1e86ad98 100644 --- a/ceno_zkvm/benches/riscv_add.rs +++ b/ceno_zkvm/benches/riscv_add.rs @@ -21,7 +21,7 @@ cfg_if::cfg_if! { if #[cfg(feature = "flamegraph")] { criterion_group! { name = op_add; - config = Criterion::default().warm_up_time(Duration::from_millis(3000)).with_profiler(pprof::criterion::PProfProfiler::new(100, pprof::criterion::Output::Flamegraph(None))); + config = Criterion::default().warm_up_time(Duration::from_millis(3000)).with_profiler(pprof2::criterion::PProfProfiler::new(100, pprof2::criterion::Output::Flamegraph(None))); targets = bench_add } } else { From e23de25e440e54679680496b1e297e47aeac4791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=B6rgens?= Date: Sat, 7 Dec 2024 13:49:40 +0800 Subject: [PATCH 2/7] Update toolchain (#707) Just to avoid falling too far behind. There seem to be no issues with the update. --- .github/workflows/lints.yml | 2 +- .github/workflows/tests.yml | 2 +- Cargo.lock | 33 +++++++++++----------- ceno_emul/src/addr.rs | 2 +- ceno_zkvm/src/chip_handler/global_state.rs | 2 +- ceno_zkvm/src/chip_handler/memory.rs | 4 +-- ceno_zkvm/src/chip_handler/register.rs | 4 +-- ceno_zkvm/src/chip_handler/test.rs | 2 +- rust-toolchain.toml | 2 +- 9 files changed, 26 insertions(+), 27 deletions(-) diff --git a/.github/workflows/lints.yml b/.github/workflows/lints.yml index 61ecda6c6..f87d32886 100644 --- a/.github/workflows/lints.yml +++ b/.github/workflows/lints.yml @@ -46,7 +46,7 @@ jobs: components: rustfmt, clippy targets: riscv32im-unknown-none-elf # TODO(Matthias): see whether we can keep this in sync with rust-toolchain.toml automatically? - toolchain: nightly-2024-10-03 + toolchain: nightly-2024-12-06 - name: Cargo cache uses: actions/cache@v3 with: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9cfdc255f..7bc6ef35a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -44,7 +44,7 @@ jobs: with: targets: riscv32im-unknown-none-elf # TODO(Matthias): see whether we can keep this in sync with rust-toolchain.toml automatically? - toolchain: nightly-2024-10-03 + toolchain: nightly-2024-12-06 - name: Cargo cache uses: actions/cache@v3 with: diff --git a/Cargo.lock b/Cargo.lock index fc7da65b3..d84685eb4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -217,9 +217,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.2.2" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f34d93e62b03caf570cccc334cbc6c2fceca82f39211051345108adcba3eebdc" +checksum = "27f657647bcff5394bf56c7317665bbf790a137a50eaaa5c6bfbb9e27a518f2d" dependencies = [ "shlex", ] @@ -937,9 +937,9 @@ checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "js-sys" -version = "0.3.74" +version = "0.3.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a865e038f7f6ed956f788f0d7d60c541fff74c7bd74272c5d4cf15c63743e705" +checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" dependencies = [ "once_cell", "wasm-bindgen", @@ -2094,9 +2094,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d15e63b4482863c109d70a7b8706c1e364eb6ea449b201a76c5b89cedcec2d5c" +checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" dependencies = [ "cfg-if", "once_cell", @@ -2105,13 +2105,12 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d36ef12e3aaca16ddd3f67922bc63e48e953f126de60bd33ccc0101ef9998cd" +checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" dependencies = [ "bumpalo", "log", - "once_cell", "proc-macro2", "quote", "syn 2.0.90", @@ -2120,9 +2119,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "705440e08b42d3e4b36de7d66c944be628d579796b8090bfa3471478a2260051" +checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2130,9 +2129,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98c9ae5a76e46f4deecd0f0255cc223cfa18dc9b261213b8aa0c7b36f61b3f1d" +checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" dependencies = [ "proc-macro2", "quote", @@ -2143,15 +2142,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ee99da9c5ba11bd675621338ef6fa52296b76b83305e9b6e5c77d4c286d6d49" +checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" [[package]] name = "web-sys" -version = "0.3.74" +version = "0.3.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a98bc3c33f0fe7e59ad7cd041b89034fa82a7c2d4365ca538dda6cdaf513863c" +checksum = "04dd7223427d52553d3702c004d3b2fe07c148165faa56313cb00211e31c12bc" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/ceno_emul/src/addr.rs b/ceno_emul/src/addr.rs index 78b01563e..ff8f7c0a0 100644 --- a/ceno_emul/src/addr.rs +++ b/ceno_emul/src/addr.rs @@ -206,7 +206,7 @@ impl IterAddresses for Range { } } -impl<'a, T: GetAddr> IterAddresses for &'a [T] { +impl IterAddresses for &[T] { fn iter_addresses(&self) -> impl ExactSizeIterator { self.iter().map(T::get_addr) } diff --git a/ceno_zkvm/src/chip_handler/global_state.rs b/ceno_zkvm/src/chip_handler/global_state.rs index 110db6a84..27c28e166 100644 --- a/ceno_zkvm/src/chip_handler/global_state.rs +++ b/ceno_zkvm/src/chip_handler/global_state.rs @@ -6,7 +6,7 @@ use crate::{ use super::GlobalStateRegisterMachineChipOperations; -impl<'a, E: ExtensionField> GlobalStateRegisterMachineChipOperations for CircuitBuilder<'a, E> { +impl GlobalStateRegisterMachineChipOperations for CircuitBuilder<'_, E> { fn state_in(&mut self, pc: Expression, ts: Expression) -> Result<(), ZKVMError> { let record: Vec> = vec![ Expression::Constant(E::BaseField::from(RAMType::GlobalState as u64)), diff --git a/ceno_zkvm/src/chip_handler/memory.rs b/ceno_zkvm/src/chip_handler/memory.rs index 7c1100247..3b6b2ec53 100644 --- a/ceno_zkvm/src/chip_handler/memory.rs +++ b/ceno_zkvm/src/chip_handler/memory.rs @@ -9,8 +9,8 @@ use crate::{ }; use ff_ext::ExtensionField; -impl<'a, E: ExtensionField, NR: Into, N: FnOnce() -> NR> MemoryChipOperations - for CircuitBuilder<'a, E> +impl, N: FnOnce() -> NR> MemoryChipOperations + for CircuitBuilder<'_, E> { fn memory_read( &mut self, diff --git a/ceno_zkvm/src/chip_handler/register.rs b/ceno_zkvm/src/chip_handler/register.rs index e8a51a2d7..d2f1ebf14 100644 --- a/ceno_zkvm/src/chip_handler/register.rs +++ b/ceno_zkvm/src/chip_handler/register.rs @@ -11,8 +11,8 @@ use crate::{ use super::{RegisterChipOperations, RegisterExpr}; -impl<'a, E: ExtensionField, NR: Into, N: FnOnce() -> NR> RegisterChipOperations - for CircuitBuilder<'a, E> +impl, N: FnOnce() -> NR> RegisterChipOperations + for CircuitBuilder<'_, E> { fn register_read( &mut self, diff --git a/ceno_zkvm/src/chip_handler/test.rs b/ceno_zkvm/src/chip_handler/test.rs index 3df4b1e71..e8e36aa31 100644 --- a/ceno_zkvm/src/chip_handler/test.rs +++ b/ceno_zkvm/src/chip_handler/test.rs @@ -6,7 +6,7 @@ pub enum DebugIndex { RdWrite = 0, } -impl<'a, E: ExtensionField> CircuitBuilder<'a, E> { +impl CircuitBuilder<'_, E> { pub fn register_debug_expr>(&mut self, debug_index: T, expr: Expression) { self.cs.register_debug_expr(debug_index, expr) } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 5d1274a3e..eb12bd38f 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly-2024-10-03" +channel = "nightly-2024-12-06" From 238516f652467ebb2738f7cb02052723d5d8a179 Mon Sep 17 00:00:00 2001 From: Ho Date: Mon, 9 Dec 2024 16:00:07 +0900 Subject: [PATCH 3/7] Turn Transcript into trait (#692) This PR try to turn `Transcript` into a trait so we can apply different implenents (For example, the `TranscriptSyncronized`) in the future. We try to split the trait into a basic `Transcript` trait and a extended `Forkable` (with the `fork` method being provided) one. The original `Transcript` struct has been renamed into `BasicTranscript`. --- ceno_zkvm/benches/riscv_add.rs | 4 +- ceno_zkvm/examples/riscv_opcodes.rs | 2 +- ceno_zkvm/src/bin/e2e.rs | 2 +- ceno_zkvm/src/e2e.rs | 2 +- ceno_zkvm/src/scheme/prover.rs | 10 +-- ceno_zkvm/src/scheme/tests.rs | 14 ++-- ceno_zkvm/src/scheme/verifier.rs | 14 ++-- ceno_zkvm/src/utils.rs | 2 +- ceno_zkvm/src/virtual_polys.rs | 2 +- mpcs/benches/basefold.rs | 6 +- mpcs/src/basefold.rs | 14 ++-- mpcs/src/basefold/commit_phase.rs | 6 +- mpcs/src/basefold/query_phase.rs | 6 +- mpcs/src/lib.rs | 60 +++++++++--------- mpcs/src/sum_check.rs | 4 +- mpcs/src/sum_check/classic.rs | 14 ++-- mpcs/src/sum_check/classic/coeff.rs | 2 +- mpcs/src/util/hash.rs | 2 +- mpcs/src/util/merkle_tree.rs | 2 +- sumcheck/benches/devirgo_sumcheck.rs | 2 +- sumcheck/src/prover.rs | 4 +- sumcheck/src/prover_v2.rs | 4 +- sumcheck/src/test.rs | 10 +-- sumcheck/src/verifier.rs | 4 +- transcript/src/basic.rs | 95 ++++++---------------------- transcript/src/lib.rs | 84 +++++++++++++++++++++++- transcript/src/syncronized.rs | 42 ++++-------- 27 files changed, 211 insertions(+), 202 deletions(-) diff --git a/ceno_zkvm/benches/riscv_add.rs b/ceno_zkvm/benches/riscv_add.rs index d1e86ad98..bc3124440 100644 --- a/ceno_zkvm/benches/riscv_add.rs +++ b/ceno_zkvm/benches/riscv_add.rs @@ -15,7 +15,7 @@ use goldilocks::{Goldilocks, GoldilocksExt2}; use itertools::Itertools; use mpcs::{BasefoldDefault, PolynomialCommitmentScheme}; use multilinear_extensions::mle::IntoMLE; -use transcript::Transcript; +use transcript::{BasicTranscript, Transcript}; cfg_if::cfg_if! { if #[cfg(feature = "flamegraph")] { @@ -87,7 +87,7 @@ fn bench_add(c: &mut Criterion) { |wits_in| { let timer = Instant::now(); let num_instances = 1 << instance_num_vars; - let mut transcript = Transcript::new(b"riscv"); + let mut transcript = BasicTranscript::new(b"riscv"); let commit = Pcs::batch_commit_and_write(&prover.pk.pp, &wits_in, &mut transcript) .unwrap(); diff --git a/ceno_zkvm/examples/riscv_opcodes.rs b/ceno_zkvm/examples/riscv_opcodes.rs index 99b86173f..8ed2c4f7e 100644 --- a/ceno_zkvm/examples/riscv_opcodes.rs +++ b/ceno_zkvm/examples/riscv_opcodes.rs @@ -27,7 +27,7 @@ use itertools::Itertools; use mpcs::{Basefold, BasefoldRSParams, PolynomialCommitmentScheme}; use sumcheck::macros::{entered_span, exit_span}; use tracing_subscriber::{EnvFilter, Registry, fmt, fmt::format::FmtSpan, layer::SubscriberExt}; -use transcript::Transcript; +use transcript::BasicTranscript as Transcript; const PROGRAM_SIZE: usize = 16; // For now, we assume registers // - x0 is not touched, diff --git a/ceno_zkvm/src/bin/e2e.rs b/ceno_zkvm/src/bin/e2e.rs index 18f373d8b..60b1e6bce 100644 --- a/ceno_zkvm/src/bin/e2e.rs +++ b/ceno_zkvm/src/bin/e2e.rs @@ -14,7 +14,7 @@ use tracing_forest::ForestLayer; use tracing_subscriber::{ EnvFilter, Registry, filter::filter_fn, fmt, layer::SubscriberExt, util::SubscriberInitExt, }; -use transcript::Transcript; +use transcript::BasicTranscript as Transcript; /// Prove the execution of a fixed RISC-V program. #[derive(Parser, Debug)] diff --git a/ceno_zkvm/src/e2e.rs b/ceno_zkvm/src/e2e.rs index c8bfbe811..512f56982 100644 --- a/ceno_zkvm/src/e2e.rs +++ b/ceno_zkvm/src/e2e.rs @@ -20,7 +20,7 @@ use std::{ iter::zip, time::Instant, }; -use transcript::Transcript; +use transcript::BasicTranscript as Transcript; type E2EWitnessGen = ( ZKVMProver, diff --git a/ceno_zkvm/src/scheme/prover.rs b/ceno_zkvm/src/scheme/prover.rs index 2d31e656f..b0ff7b656 100644 --- a/ceno_zkvm/src/scheme/prover.rs +++ b/ceno_zkvm/src/scheme/prover.rs @@ -18,7 +18,7 @@ use sumcheck::{ macros::{entered_span, exit_span}, structs::{IOPProverMessage, IOPProverStateV2}, }; -use transcript::Transcript; +use transcript::{ForkableTranscript, Transcript}; use crate::{ circuit_builder::SetTableAddrType, @@ -62,7 +62,7 @@ impl> ZKVMProver { &self, witnesses: ZKVMWitnesses, pi: PublicValues, - mut transcript: Transcript, + mut transcript: impl ForkableTranscript, ) -> Result, ZKVMError> { let span = entered_span!("commit_to_fixed_commit", profiling_1 = true); let mut vm_proof = ZKVMProof::empty(pi); @@ -219,7 +219,7 @@ impl> ZKVMProver { wits_commit: PCS::CommitmentWithData, pi: &[ArcMultilinearExtension<'_, E>], num_instances: usize, - transcript: &mut Transcript, + transcript: &mut impl Transcript, challenges: &[E; 2], ) -> Result, ZKVMError> { let cs = circuit_pk.get_cs(); @@ -663,7 +663,7 @@ impl> ZKVMProver { witnesses: Vec>, wits_commit: PCS::CommitmentWithData, pi: &[ArcMultilinearExtension<'_, E>], - transcript: &mut Transcript, + transcript: &mut impl Transcript, challenges: &[E; 2], ) -> Result, ZKVMError> { let cs = circuit_pk.get_cs(); @@ -1152,7 +1152,7 @@ impl TowerProver { prod_specs: Vec>, logup_specs: Vec>, num_fanin: usize, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> (Point, TowerProofs) { // XXX to sumcheck batched product argument with logup, we limit num_product_fanin to 2 // TODO mayber give a better naming? diff --git a/ceno_zkvm/src/scheme/tests.rs b/ceno_zkvm/src/scheme/tests.rs index 260c17fae..fe3ce8f07 100644 --- a/ceno_zkvm/src/scheme/tests.rs +++ b/ceno_zkvm/src/scheme/tests.rs @@ -14,7 +14,7 @@ use mpcs::{Basefold, BasefoldDefault, BasefoldRSParams, PolynomialCommitmentSche use multilinear_extensions::{ mle::IntoMLE, util::ceil_log2, virtual_poly_v2::ArcMultilinearExtension, }; -use transcript::Transcript; +use transcript::{BasicTranscript, Transcript}; use crate::{ circuit_builder::CircuitBuilder, @@ -126,7 +126,7 @@ fn test_rw_lk_expression_combination() { // get proof let prover = ZKVMProver::new(pk); - let mut transcript = Transcript::new(b"test"); + let mut transcript = BasicTranscript::new(b"test"); let wits_in = zkvm_witness .into_iter_sorted() .next() @@ -157,7 +157,7 @@ fn test_rw_lk_expression_combination() { // verify proof let verifier = ZKVMVerifier::new(vk.clone()); - let mut v_transcript = Transcript::new(b"test"); + let mut v_transcript = BasicTranscript::new(b"test"); // write commitment into transcript and derive challenges from it Pcs::write_commitment(&proof.wits_commit, &mut v_transcript).unwrap(); let verifier_challenges = [ @@ -305,12 +305,12 @@ fn test_single_add_instance_e2e() { .unwrap(); let pi = PublicValues::new(0, 0, 0, 0, 0, vec![0]); - let transcript = Transcript::new(b"riscv"); + let transcript = BasicTranscript::new(b"riscv"); let zkvm_proof = prover .create_proof(zkvm_witness, pi, transcript) .expect("create_proof failed"); - let transcript = Transcript::new(b"riscv"); + let transcript = BasicTranscript::new(b"riscv"); assert!( verifier .verify_proof(zkvm_proof, transcript) @@ -325,7 +325,7 @@ fn test_tower_proof_various_prod_size() { let num_vars = ceil_log2(leaf_layer_size); let mut rng = test_rng(); type E = GoldilocksExt2; - let mut transcript = Transcript::new(b"test_tower_proof"); + let mut transcript = BasicTranscript::new(b"test_tower_proof"); let leaf_layer: ArcMultilinearExtension = (0..leaf_layer_size) .map(|_| E::random(&mut rng)) .collect_vec() @@ -348,7 +348,7 @@ fn test_tower_proof_various_prod_size() { &mut transcript, ); - let mut transcript = Transcript::new(b"test_tower_proof"); + let mut transcript = BasicTranscript::new(b"test_tower_proof"); let (rt_tower_v, prod_point_and_eval, _, _) = TowerVerify::verify( vec![ layers[0] diff --git a/ceno_zkvm/src/scheme/verifier.rs b/ceno_zkvm/src/scheme/verifier.rs index c9593f24f..e3cb38b2d 100644 --- a/ceno_zkvm/src/scheme/verifier.rs +++ b/ceno_zkvm/src/scheme/verifier.rs @@ -12,7 +12,7 @@ use multilinear_extensions::{ virtual_poly::{VPAuxInfo, build_eq_x_r_vec_sequential, eq_eval}, }; use sumcheck::structs::{IOPProof, IOPVerifierState}; -use transcript::Transcript; +use transcript::{ForkableTranscript, Transcript}; use crate::{ circuit_builder::SetTableAddrType, @@ -48,7 +48,7 @@ impl> ZKVMVerifier pub fn verify_proof( &self, vm_proof: ZKVMProof, - transcript: Transcript, + transcript: impl ForkableTranscript, ) -> Result { self.verify_proof_halt(vm_proof, transcript, true) } @@ -57,7 +57,7 @@ impl> ZKVMVerifier pub fn verify_proof_halt( &self, vm_proof: ZKVMProof, - transcript: Transcript, + transcript: impl ForkableTranscript, does_halt: bool, ) -> Result { // require ecall/halt proof to exist, depending whether we expect a halt. @@ -79,7 +79,7 @@ impl> ZKVMVerifier fn verify_proof_validity( &self, vm_proof: ZKVMProof, - mut transcript: Transcript, + mut transcript: impl ForkableTranscript, ) -> Result { // main invariant between opcode circuits and table circuits let mut prod_r = E::ONE; @@ -255,7 +255,7 @@ impl> ZKVMVerifier circuit_vk: &VerifyingKey, proof: &ZKVMOpcodeProof, pi: &[E], - transcript: &mut Transcript, + transcript: &mut impl Transcript, num_product_fanin: usize, _out_evals: &PointAndEval, challenges: &[E; 2], // derive challenge from PCS @@ -504,7 +504,7 @@ impl> ZKVMVerifier proof: &ZKVMTableProof, raw_pi: &[Vec], pi: &[E], - transcript: &mut Transcript, + transcript: &mut impl Transcript, num_logup_fanin: usize, _out_evals: &PointAndEval, challenges: &[E; 2], @@ -812,7 +812,7 @@ impl TowerVerify { tower_proofs: &TowerProofs, num_variables: Vec, num_fanin: usize, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> TowerVerifyResult { // XXX to sumcheck batched product argument with logup, we limit num_product_fanin to 2 // TODO mayber give a better naming? diff --git a/ceno_zkvm/src/utils.rs b/ceno_zkvm/src/utils.rs index f1ca5856b..8b7d8cbde 100644 --- a/ceno_zkvm/src/utils.rs +++ b/ceno_zkvm/src/utils.rs @@ -61,7 +61,7 @@ pub(crate) fn add_one_to_big_num(limb_modulo: F, limbs: &[F]) -> Vec( size: usize, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Vec { // println!("alpha_pow"); let alpha = transcript diff --git a/ceno_zkvm/src/virtual_polys.rs b/ceno_zkvm/src/virtual_polys.rs index a3d8064c6..b3d32eab3 100644 --- a/ceno_zkvm/src/virtual_polys.rs +++ b/ceno_zkvm/src/virtual_polys.rs @@ -177,7 +177,7 @@ mod tests { virtual_poly_v2::{ArcMultilinearExtension, VirtualPolynomialV2}, }; use sumcheck::structs::{IOPProverStateV2, IOPVerifierState}; - use transcript::Transcript; + use transcript::BasicTranscript as Transcript; use crate::{ circuit_builder::{CircuitBuilder, ConstraintSystem}, diff --git a/mpcs/benches/basefold.rs b/mpcs/benches/basefold.rs index 965d55035..19fb7aa03 100644 --- a/mpcs/benches/basefold.rs +++ b/mpcs/benches/basefold.rs @@ -18,11 +18,11 @@ use multilinear_extensions::{ mle::{DenseMultilinearExtension, MultilinearExtension}, virtual_poly_v2::ArcMultilinearExtension, }; -use transcript::Transcript; +use transcript::{BasicTranscript, Transcript}; type PcsGoldilocksRSCode = Basefold; type PcsGoldilocksBasecode = Basefold; -type T = Transcript; +type T = BasicTranscript; type E = GoldilocksExt2; const NUM_SAMPLES: usize = 10; @@ -292,7 +292,7 @@ fn bench_simple_batch_commit_open_verify_goldilocks, + transcript: &mut impl Transcript, ) -> Result<(), Error> { write_digest_to_transcript(&comm.root(), transcript); Ok(()) @@ -470,7 +470,7 @@ where comm: &Self::CommitmentWithData, point: &[E], _eval: &E, // Opening does not need eval, except for sanity check - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result { let timer = start_timer!(|| "Basefold::open"); @@ -550,7 +550,7 @@ where comms: &[Self::CommitmentWithData], points: &[Vec], evals: &[Evaluation], - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result { let timer = start_timer!(|| "Basefold::batch_open"); let num_vars = polys.iter().map(|poly| poly.num_vars).max().unwrap(); @@ -772,7 +772,7 @@ where comm: &Self::CommitmentWithData, point: &[E], evals: &[E], - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result { let timer = start_timer!(|| "Basefold::batch_open"); let num_vars = polys[0].num_vars(); @@ -858,7 +858,7 @@ where point: &[E], eval: &E, proof: &Self::Proof, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result<(), Error> { let timer = start_timer!(|| "Basefold::verify"); @@ -944,7 +944,7 @@ where points: &[Vec], evals: &[Evaluation], proof: &Self::Proof, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result<(), Error> { let timer = start_timer!(|| "Basefold::batch_verify"); // let key = "RAYON_NUM_THREADS"; @@ -1071,7 +1071,7 @@ where point: &[E], evals: &[E], proof: &Self::Proof, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result<(), Error> { let timer = start_timer!(|| "Basefold::simple batch verify"); let batch_size = evals.len(); diff --git a/mpcs/src/basefold/commit_phase.rs b/mpcs/src/basefold/commit_phase.rs index fe6b2b1e9..7d6e0b949 100644 --- a/mpcs/src/basefold/commit_phase.rs +++ b/mpcs/src/basefold/commit_phase.rs @@ -34,7 +34,7 @@ pub fn commit_phase>( pp: &>::ProverParameters, point: &[E], comm: &BasefoldCommitmentWithData, - transcript: &mut Transcript, + transcript: &mut impl Transcript, num_vars: usize, num_rounds: usize, ) -> (Vec>, BasefoldCommitPhaseProof) @@ -180,7 +180,7 @@ pub fn batch_commit_phase>( pp: &>::ProverParameters, point: &[E], comms: &[BasefoldCommitmentWithData], - transcript: &mut Transcript, + transcript: &mut impl Transcript, num_vars: usize, num_rounds: usize, coeffs: &[E], @@ -351,7 +351,7 @@ pub fn simple_batch_commit_phase>( point: &[E], batch_coeffs: &[E], comm: &BasefoldCommitmentWithData, - transcript: &mut Transcript, + transcript: &mut impl Transcript, num_vars: usize, num_rounds: usize, ) -> (Vec>, BasefoldCommitPhaseProof) diff --git a/mpcs/src/basefold/query_phase.rs b/mpcs/src/basefold/query_phase.rs index 946214c68..f0db40890 100644 --- a/mpcs/src/basefold/query_phase.rs +++ b/mpcs/src/basefold/query_phase.rs @@ -29,7 +29,7 @@ use super::{ }; pub fn prover_query_phase( - transcript: &mut Transcript, + transcript: &mut impl Transcript, comm: &BasefoldCommitmentWithData, trees: &[MerkleTree], num_verifier_queries: usize, @@ -65,7 +65,7 @@ where } pub fn batch_prover_query_phase( - transcript: &mut Transcript, + transcript: &mut impl Transcript, codeword_size: usize, comms: &[BasefoldCommitmentWithData], trees: &[MerkleTree], @@ -102,7 +102,7 @@ where } pub fn simple_batch_prover_query_phase( - transcript: &mut Transcript, + transcript: &mut impl Transcript, comm: &BasefoldCommitmentWithData, trees: &[MerkleTree], num_verifier_queries: usize, diff --git a/mpcs/src/lib.rs b/mpcs/src/lib.rs index b6716c19e..e9c67b866 100644 --- a/mpcs/src/lib.rs +++ b/mpcs/src/lib.rs @@ -4,7 +4,7 @@ use itertools::Itertools; use multilinear_extensions::mle::DenseMultilinearExtension; use serde::{Serialize, de::DeserializeOwned}; use std::fmt::Debug; -use transcript::Transcript; +use transcript::{BasicTranscript, Transcript}; use util::hash::Digest; pub mod sum_check; @@ -41,7 +41,7 @@ pub fn pcs_commit>( pub fn pcs_commit_and_write>( pp: &Pcs::ProverParam, poly: &DenseMultilinearExtension, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result { Pcs::commit_and_write(pp, poly, transcript) } @@ -56,7 +56,7 @@ pub fn pcs_batch_commit>( pub fn pcs_batch_commit_and_write>( pp: &Pcs::ProverParam, polys: &[DenseMultilinearExtension], - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result { Pcs::batch_commit_and_write(pp, polys, transcript) } @@ -67,7 +67,7 @@ pub fn pcs_open>( comm: &Pcs::CommitmentWithData, point: &[E], eval: &E, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result { Pcs::open(pp, poly, comm, point, eval, transcript) } @@ -78,7 +78,7 @@ pub fn pcs_batch_open>( comms: &[Pcs::CommitmentWithData], points: &[Vec], evals: &[Evaluation], - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result { Pcs::batch_open(pp, polys, comms, points, evals, transcript) } @@ -89,7 +89,7 @@ pub fn pcs_verify>( point: &[E], eval: &E, proof: &Pcs::Proof, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result<(), Error> { Pcs::verify(vp, comm, point, eval, proof, transcript) } @@ -100,7 +100,7 @@ pub fn pcs_batch_verify<'a, E: ExtensionField, Pcs: PolynomialCommitmentScheme], evals: &[Evaluation], proof: &Pcs::Proof, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result<(), Error> where Pcs::Commitment: 'a, @@ -132,7 +132,7 @@ pub trait PolynomialCommitmentScheme: Clone + Debug { fn commit_and_write( pp: &Self::ProverParam, poly: &DenseMultilinearExtension, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result { let comm = Self::commit(pp, poly)?; Self::write_commitment(&Self::get_pure_commitment(&comm), transcript)?; @@ -141,7 +141,7 @@ pub trait PolynomialCommitmentScheme: Clone + Debug { fn write_commitment( comm: &Self::Commitment, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result<(), Error>; fn get_pure_commitment(comm: &Self::CommitmentWithData) -> Self::Commitment; @@ -154,7 +154,7 @@ pub trait PolynomialCommitmentScheme: Clone + Debug { fn batch_commit_and_write( pp: &Self::ProverParam, polys: &[DenseMultilinearExtension], - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result { let comm = Self::batch_commit(pp, polys)?; Self::write_commitment(&Self::get_pure_commitment(&comm), transcript)?; @@ -167,7 +167,7 @@ pub trait PolynomialCommitmentScheme: Clone + Debug { comm: &Self::CommitmentWithData, point: &[E], eval: &E, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result; fn batch_open( @@ -176,7 +176,7 @@ pub trait PolynomialCommitmentScheme: Clone + Debug { comms: &[Self::CommitmentWithData], points: &[Vec], evals: &[Evaluation], - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result; /// This is a simple version of batch open: @@ -189,7 +189,7 @@ pub trait PolynomialCommitmentScheme: Clone + Debug { comm: &Self::CommitmentWithData, point: &[E], evals: &[E], - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result; fn verify( @@ -198,7 +198,7 @@ pub trait PolynomialCommitmentScheme: Clone + Debug { point: &[E], eval: &E, proof: &Self::Proof, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result<(), Error>; fn batch_verify( @@ -207,7 +207,7 @@ pub trait PolynomialCommitmentScheme: Clone + Debug { points: &[Vec], evals: &[Evaluation], proof: &Self::Proof, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result<(), Error>; fn simple_batch_verify( @@ -216,7 +216,7 @@ pub trait PolynomialCommitmentScheme: Clone + Debug { point: &[E], evals: &[E], proof: &Self::Proof, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result<(), Error>; } @@ -232,7 +232,7 @@ where point: &[E], eval: &E, ) -> Result { - let mut transcript = Transcript::::new(b"BaseFold"); + let mut transcript = BasicTranscript::::new(b"BaseFold"); Self::open(pp, poly, comm, point, eval, &mut transcript) } @@ -243,7 +243,7 @@ where points: &[Vec], evals: &[Evaluation], ) -> Result { - let mut transcript = Transcript::::new(b"BaseFold"); + let mut transcript = BasicTranscript::::new(b"BaseFold"); Self::batch_open(pp, polys, comms, points, evals, &mut transcript) } @@ -254,7 +254,7 @@ where eval: &E, proof: &Self::Proof, ) -> Result<(), Error> { - let mut transcript = Transcript::::new(b"BaseFold"); + let mut transcript = BasicTranscript::::new(b"BaseFold"); Self::verify(vp, comm, point, eval, proof, &mut transcript) } @@ -268,7 +268,7 @@ where where Self::Commitment: 'a, { - let mut transcript = Transcript::::new(b"BaseFold"); + let mut transcript = BasicTranscript::::new(b"BaseFold"); Self::batch_verify(vp, comms, points, evals, proof, &mut transcript) } } @@ -379,6 +379,8 @@ pub mod test_util { mle::MultilinearExtension, virtual_poly_v2::ArcMultilinearExtension, }; use rand::rngs::OsRng; + #[cfg(test)] + use transcript::BasicTranscript; use transcript::Transcript; pub fn setup_pcs>( @@ -414,7 +416,7 @@ pub mod test_util { pub fn get_point_from_challenge( num_vars: usize, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Vec { (0..num_vars) .map(|_| transcript.get_and_append_challenge(b"Point").elements) @@ -423,7 +425,7 @@ pub mod test_util { pub fn get_points_from_challenge( num_vars: impl Fn(usize) -> usize, num_points: usize, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Vec> { (0..num_points) .map(|i| get_point_from_challenge(num_vars(i), transcript)) @@ -433,7 +435,7 @@ pub mod test_util { pub fn commit_polys_individually>( pp: &Pcs::ProverParam, polys: &[DenseMultilinearExtension], - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Vec { polys .iter() @@ -454,7 +456,7 @@ pub mod test_util { // Commit and open let (comm, eval, proof, challenge) = { - let mut transcript = Transcript::new(b"BaseFold"); + let mut transcript = BasicTranscript::new(b"BaseFold"); let poly = gen_rand_poly(num_vars); let comm = Pcs::commit_and_write(&pp, &poly, &mut transcript).unwrap(); let point = get_point_from_challenge(num_vars, &mut transcript); @@ -470,7 +472,7 @@ pub mod test_util { }; // Verify { - let mut transcript = Transcript::new(b"BaseFold"); + let mut transcript = BasicTranscript::new(b"BaseFold"); Pcs::write_commitment(&comm, &mut transcript).unwrap(); let point = get_point_from_challenge(num_vars, &mut transcript); transcript.append_field_element_ext(&eval); @@ -505,7 +507,7 @@ pub mod test_util { .collect_vec(); let (comms, evals, proof, challenge) = { - let mut transcript = Transcript::new(b"BaseFold"); + let mut transcript = BasicTranscript::new(b"BaseFold"); let polys = gen_rand_polys(|i| num_vars - (i >> 1), batch_size, gen_rand_poly); let comms = @@ -536,7 +538,7 @@ pub mod test_util { }; // Batch verify { - let mut transcript = Transcript::new(b"BaseFold"); + let mut transcript = BasicTranscript::new(b"BaseFold"); let comms = comms .iter() .map(|comm| { @@ -577,7 +579,7 @@ pub mod test_util { let (pp, vp) = setup_pcs::(num_vars); let (comm, evals, proof, challenge) = { - let mut transcript = Transcript::new(b"BaseFold"); + let mut transcript = BasicTranscript::new(b"BaseFold"); let polys = gen_rand_polys(|_| num_vars, batch_size, gen_rand_poly); let comm = Pcs::batch_commit_and_write(&pp, polys.as_slice(), &mut transcript).unwrap(); @@ -601,7 +603,7 @@ pub mod test_util { }; // Batch verify { - let mut transcript = Transcript::new(b"BaseFold"); + let mut transcript = BasicTranscript::new(b"BaseFold"); Pcs::write_commitment(&comm, &mut transcript).unwrap(); let point = get_point_from_challenge(num_vars, &mut transcript); diff --git a/mpcs/src/sum_check.rs b/mpcs/src/sum_check.rs index cd42360df..f2fcf0e47 100644 --- a/mpcs/src/sum_check.rs +++ b/mpcs/src/sum_check.rs @@ -62,7 +62,7 @@ where num_vars: usize, virtual_poly: VirtualPolynomial, sum: E, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result, Error>; fn verify( @@ -71,7 +71,7 @@ where degree: usize, sum: E, proof: &SumcheckProof, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result<(E, Vec), Error>; } diff --git a/mpcs/src/sum_check/classic.rs b/mpcs/src/sum_check/classic.rs index 6d7a3e7a8..f99d832df 100644 --- a/mpcs/src/sum_check/classic.rs +++ b/mpcs/src/sum_check/classic.rs @@ -186,7 +186,7 @@ pub trait ClassicSumCheckProver: Clone + Debug { pub trait ClassicSumCheckRoundMessage: Sized + Debug { type Auxiliary: Default; - fn write(&self, transcript: &mut Transcript) -> Result<(), Error>; + fn write(&self, transcript: &mut impl Transcript) -> Result<(), Error>; fn sum(&self) -> E; @@ -234,7 +234,7 @@ where num_vars: usize, virtual_poly: VirtualPolynomial, sum: E, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result<(Vec, Vec, SumcheckProof), Error> { let _timer = start_timer!(|| { let degree = virtual_poly.expression.degree(); @@ -290,7 +290,7 @@ where degree: usize, sum: E, proof: &SumcheckProof, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Result<(E, Vec), Error> { let (msgs, challenges) = { let mut msgs = Vec::with_capacity(num_vars); @@ -321,7 +321,7 @@ mod tests { sum_check::eq_xy_eval, util::{arithmetic::inner_product, expression::Query, poly_iter_ext}, }; - use transcript::Transcript; + use transcript::BasicTranscript; use super::*; use goldilocks::{Goldilocks as Fr, GoldilocksExt2 as E}; @@ -368,7 +368,7 @@ mod tests { &build_eq_x_r_vec(&points[1]), ) * Fr::from(4) * Fr::from(2); // The third polynomial is summed twice because the hypercube is larger - let mut transcript = Transcript::::new(b"sumcheck"); + let mut transcript = BasicTranscript::::new(b"sumcheck"); let (challenges, evals, proof) = > as SumCheck>::prove( &(), @@ -383,7 +383,7 @@ mod tests { assert_eq!(polys[1].evaluate(&challenges), evals[1]); assert_eq!(polys[2].evaluate(&challenges[..1]), evals[2]); - let mut transcript = Transcript::::new(b"sumcheck"); + let mut transcript = BasicTranscript::::new(b"sumcheck"); let (new_sum, verifier_challenges) = > as SumCheck< E, @@ -400,7 +400,7 @@ mod tests { + evals[2] * eq_xy_eval(&points[1], &challenges[..1]) * Fr::from(4) ); - let mut transcript = Transcript::::new(b"sumcheck"); + let mut transcript = BasicTranscript::::new(b"sumcheck"); > as SumCheck>::verify( &(), diff --git a/mpcs/src/sum_check/classic/coeff.rs b/mpcs/src/sum_check/classic/coeff.rs index a6107bfe7..12f46880f 100644 --- a/mpcs/src/sum_check/classic/coeff.rs +++ b/mpcs/src/sum_check/classic/coeff.rs @@ -37,7 +37,7 @@ pub struct Coefficients(FieldType); impl ClassicSumCheckRoundMessage for Coefficients { type Auxiliary = (); - fn write(&self, transcript: &mut Transcript) -> Result<(), Error> { + fn write(&self, transcript: &mut impl Transcript) -> Result<(), Error> { match &self.0 { FieldType::Ext(coeffs) => transcript.append_field_element_exts(coeffs), FieldType::Base(coeffs) => coeffs diff --git a/mpcs/src/util/hash.rs b/mpcs/src/util/hash.rs index 754768140..499a053b5 100644 --- a/mpcs/src/util/hash.rs +++ b/mpcs/src/util/hash.rs @@ -9,7 +9,7 @@ use poseidon::poseidon::Poseidon; pub fn write_digest_to_transcript( digest: &Digest, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) { digest .0 diff --git a/mpcs/src/util/merkle_tree.rs b/mpcs/src/util/merkle_tree.rs index 66f896710..d24840496 100644 --- a/mpcs/src/util/merkle_tree.rs +++ b/mpcs/src/util/merkle_tree.rs @@ -182,7 +182,7 @@ where self.inner.iter() } - pub fn write_transcript(&self, transcript: &mut Transcript) { + pub fn write_transcript(&self, transcript: &mut impl Transcript) { self.inner .iter() .for_each(|hash| write_digest_to_transcript(hash, transcript)); diff --git a/sumcheck/benches/devirgo_sumcheck.rs b/sumcheck/benches/devirgo_sumcheck.rs index 3a101fe53..757106529 100644 --- a/sumcheck/benches/devirgo_sumcheck.rs +++ b/sumcheck/benches/devirgo_sumcheck.rs @@ -16,7 +16,7 @@ use multilinear_extensions::{ util::max_usable_threads, virtual_poly_v2::{ArcMultilinearExtension, VirtualPolynomialV2 as VirtualPolynomial}, }; -use transcript::Transcript; +use transcript::BasicTranscript as Transcript; criterion_group!(benches, sumcheck_fn, devirgo_sumcheck_fn,); criterion_main!(benches); diff --git a/sumcheck/src/prover.rs b/sumcheck/src/prover.rs index f27dd435c..7cee2169b 100644 --- a/sumcheck/src/prover.rs +++ b/sumcheck/src/prover.rs @@ -33,7 +33,7 @@ impl IOPProverState { pub fn prove_batch_polys( max_thread_id: usize, mut polys: Vec>, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> (IOPProof, IOPProverState) { assert!(!polys.is_empty()); assert_eq!(polys.len(), max_thread_id); @@ -476,7 +476,7 @@ impl IOPProverState { #[tracing::instrument(skip_all, name = "sumcheck::prove_parallel")] pub fn prove_parallel( poly: VirtualPolynomial, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> (IOPProof, IOPProverState) { let (num_variables, max_degree) = (poly.aux_info.num_variables, poly.aux_info.max_degree); diff --git a/sumcheck/src/prover_v2.rs b/sumcheck/src/prover_v2.rs index 4e38c0911..3dae3a101 100644 --- a/sumcheck/src/prover_v2.rs +++ b/sumcheck/src/prover_v2.rs @@ -39,7 +39,7 @@ impl<'a, E: ExtensionField> IOPProverStateV2<'a, E> { pub fn prove_batch_polys( max_thread_id: usize, mut polys: Vec>, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> (IOPProof, IOPProverStateV2<'a, E>) { assert!(!polys.is_empty()); assert_eq!(polys.len(), max_thread_id); @@ -604,7 +604,7 @@ impl<'a, E: ExtensionField> IOPProverStateV2<'a, E> { #[tracing::instrument(skip_all, name = "sumcheck::prove_parallel")] pub fn prove_parallel( poly: VirtualPolynomialV2<'a, E>, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> (IOPProof, IOPProverStateV2<'a, E>) { let (num_variables, max_degree) = (poly.aux_info.max_num_variables, poly.aux_info.max_degree); diff --git a/sumcheck/src/test.rs b/sumcheck/src/test.rs index d0ea28e4f..0c24e83cd 100644 --- a/sumcheck/src/test.rs +++ b/sumcheck/src/test.rs @@ -6,7 +6,7 @@ use ff_ext::ExtensionField; use goldilocks::GoldilocksExt2; use multilinear_extensions::{mle::MultilinearExtension, virtual_poly::VirtualPolynomial}; use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator}; -use transcript::Transcript; +use transcript::{BasicTranscript, Transcript}; use crate::{ structs::{IOPProverState, IOPVerifierState}, @@ -21,7 +21,7 @@ fn test_sumcheck( num_products: usize, ) { let mut rng = test_rng(); - let mut transcript = Transcript::new(b"test"); + let mut transcript = BasicTranscript::new(b"test"); let (poly, asserted_sum) = VirtualPolynomial::::random(nv, num_multiplicands_range, num_products, &mut rng); @@ -29,7 +29,7 @@ fn test_sumcheck( #[allow(deprecated)] let (proof, _) = IOPProverState::::prove_parallel(poly.clone(), &mut transcript); - let mut transcript = Transcript::new(b"test"); + let mut transcript = BasicTranscript::new(b"test"); let subclaim = IOPVerifierState::::verify(asserted_sum, &proof, &poly_info, &mut transcript); assert!( poly.evaluate( @@ -58,7 +58,7 @@ fn test_sumcheck_internal( let mut verifier_state = IOPVerifierState::verifier_init(&poly_info); let mut challenge = None; - let mut transcript = Transcript::new(b"test"); + let mut transcript = BasicTranscript::new(b"test"); transcript.append_message(b"initializing transcript for testing"); @@ -145,7 +145,7 @@ fn test_extract_sum() { fn test_extract_sum_helper() { let mut rng = test_rng(); - let mut transcript = Transcript::::new(b"test"); + let mut transcript = BasicTranscript::::new(b"test"); let (poly, asserted_sum) = VirtualPolynomial::::random(8, (2, 3), 3, &mut rng); #[allow(deprecated)] let (proof, _) = IOPProverState::::prove_parallel(poly, &mut transcript); diff --git a/sumcheck/src/verifier.rs b/sumcheck/src/verifier.rs index f67c09103..4dcd8767e 100644 --- a/sumcheck/src/verifier.rs +++ b/sumcheck/src/verifier.rs @@ -13,7 +13,7 @@ impl IOPVerifierState { claimed_sum: E, proof: &IOPProof, aux_info: &VPAuxInfo, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> SumCheckSubClaim { if aux_info.num_variables == 0 { return SumCheckSubClaim { @@ -66,7 +66,7 @@ impl IOPVerifierState { pub(crate) fn verify_round_and_update_state( &mut self, prover_msg: &IOPProverMessage, - transcript: &mut Transcript, + transcript: &mut impl Transcript, ) -> Challenge { let start = start_timer!(|| format!("sum check verify {}-th round and update state", self.round)); diff --git a/transcript/src/basic.rs b/transcript/src/basic.rs index b38dfc27a..ec455d236 100644 --- a/transcript/src/basic.rs +++ b/transcript/src/basic.rs @@ -3,14 +3,14 @@ use ff_ext::ExtensionField; use goldilocks::SmallField; use poseidon::poseidon_permutation::PoseidonPermutation; -use crate::Challenge; +use crate::{Challenge, ForkableTranscript, Transcript}; #[derive(Clone)] -pub struct Transcript { +pub struct BasicTranscript { permutation: PoseidonPermutation, } -impl Transcript { +impl BasicTranscript { /// Create a new IOP transcript. pub fn new(label: &'static [u8]) -> Self { let mut perm = PoseidonPermutation::new(core::iter::repeat(E::BaseField::ZERO)); @@ -21,96 +21,37 @@ impl Transcript { } } -impl Transcript { - /// Fork this transcript into n different threads. - pub fn fork(self, n: usize) -> Vec { - let mut forks = Vec::with_capacity(n); - for i in 0..n { - let mut fork = self.clone(); - fork.append_field_element(&(i as u64).into()); - forks.push(fork); - } - forks - } - - // Append the message to the transcript. - pub fn append_message(&mut self, msg: &[u8]) { - let msg_f = E::BaseField::bytes_to_field_elements(msg); - self.permutation.set_from_slice(&msg_f, 0); - self.permutation.permute(); - } - - // Append the field extension element to the transcript. - pub fn append_field_element_ext(&mut self, element: &E) { - self.permutation.set_from_slice(element.as_bases(), 0); - self.permutation.permute(); - } - - pub fn append_field_element_exts(&mut self, element: &[E]) { - for e in element { - self.append_field_element_ext(e); - } - } - - // Append the field elemetn to the transcript. - pub fn append_field_element(&mut self, element: &E::BaseField) { - self.permutation.set_from_slice(&[*element], 0); +impl Transcript for BasicTranscript { + fn append_field_elements(&mut self, elements: &[E::BaseField]) { + self.permutation.set_from_slice(elements, 0); self.permutation.permute(); } - // Append the challenge to the transcript. - pub fn append_challenge(&mut self, challenge: Challenge) { - self.permutation - .set_from_slice(challenge.elements.as_bases(), 0); - self.permutation.permute(); + fn append_field_element_ext(&mut self, element: &E) { + self.append_field_elements(element.as_bases()) } - // // Append the message to the transcript. - // pub fn append_serializable_element( - // &mut self, - // _label: &'static [u8], - // _element: &S, - // ) { - // unimplemented!() - // } - - // Generate the challenge from the current transcript - // and append it to the transcript. - // - // The output field element is statistical uniform as long - // as the field has a size less than 2^384. - pub fn get_and_append_challenge(&mut self, label: &'static [u8]) -> Challenge { - self.append_message(label); + fn read_challenge(&mut self) -> Challenge { + let r = E::from_bases(self.permutation.squeeze()); - let challenge = Challenge { - elements: E::from_limbs(self.permutation.squeeze()), - }; - challenge - } - - pub fn commit_rolling(&mut self) { - // do nothing + Challenge { elements: r } } - pub fn read_field_element_ext(&self) -> E { + fn read_field_element_exts(&self) -> Vec { unimplemented!() } - pub fn read_field_element_exts(&self) -> Vec { + fn read_field_element(&self) -> E::BaseField { unimplemented!() } - pub fn read_field_element(&self) -> E::BaseField { + fn send_challenge(&self, _challenge: E) { unimplemented!() } - pub fn read_challenge(&mut self) -> Challenge { - let r = E::from_bases(&self.permutation.squeeze()[..2]); - - Challenge { elements: r } - } - - pub fn send_challenge(&self, _challenge: E) { - unimplemented!() + fn commit_rolling(&mut self) { + // do nothing } } + +impl ForkableTranscript for BasicTranscript {} diff --git a/transcript/src/lib.rs b/transcript/src/lib.rs index 376bdb1ca..3c8c56038 100644 --- a/transcript/src/lib.rs +++ b/transcript/src/lib.rs @@ -5,7 +5,7 @@ pub mod basic; pub mod syncronized; -pub use basic::Transcript; +pub use basic::BasicTranscript; pub use syncronized::TranscriptSyncronized; mod hasher; @@ -14,3 +14,85 @@ mod hasher; pub struct Challenge { pub elements: F, } + +use ff_ext::ExtensionField; +use goldilocks::SmallField; +/// The Transcript trait +pub trait Transcript { + /// Append slice of base field elemets to the transcript. Implement + /// has to override at least one of append_field_elements / append_field_element + fn append_field_elements(&mut self, elements: &[E::BaseField]) { + for e in elements { + self.append_field_element(e); + } + } + + // Append a single field element to the transcript. Implement + /// has to override at least one of append_field_elements / append_field_element + fn append_field_element(&mut self, element: &E::BaseField) { + self.append_field_elements(&[*element]) + } + + /// Append the message to the transcript. + fn append_message(&mut self, msg: &[u8]) { + let msg_f = E::BaseField::bytes_to_field_elements(msg); + self.append_field_elements(&msg_f); + } + + /// Append the field extension element to the transcript.Implement + /// has to override at least one of append_field_element_ext / append_field_element_exts + fn append_field_element_ext(&mut self, element: &E) { + self.append_field_element_exts(&[*element]) + } + + /// Append slice of field extension elements to the transcript. Implement + /// has to override at least one of append_field_element_ext / append_field_element_exts + fn append_field_element_exts(&mut self, element: &[E]) { + for e in element { + self.append_field_element_ext(e); + } + } + + /// Append the challenge to the transcript. + fn append_challenge(&mut self, challenge: Challenge) { + self.append_field_element_ext(&challenge.elements) + } + + /// Generate the challenge from the current transcript + /// and append it to the transcript. + /// + /// The output field element is statistical uniform as long + /// as the field has a size less than 2^384. + fn get_and_append_challenge(&mut self, label: &'static [u8]) -> Challenge { + self.append_message(label); + self.read_challenge() + } + + fn read_field_element_ext(&self) -> E { + self.read_field_element_exts()[0] + } + + fn read_field_element_exts(&self) -> Vec; + + fn read_field_element(&self) -> E::BaseField; + + fn read_challenge(&mut self) -> Challenge; + + fn send_challenge(&self, challenge: E); + + fn commit_rolling(&mut self); +} + +/// Forkable Transcript trait, enable fork method +pub trait ForkableTranscript: Transcript + Sized + Clone { + /// Fork this transcript into n different threads. + fn fork(self, n: usize) -> Vec { + let mut forks = Vec::with_capacity(n); + for i in 0..n { + let mut fork = self.clone(); + fork.append_field_element(&(i as u64).into()); + forks.push(fork); + } + forks + } +} diff --git a/transcript/src/syncronized.rs b/transcript/src/syncronized.rs index c7e1fdb83..51a32e2b6 100644 --- a/transcript/src/syncronized.rs +++ b/transcript/src/syncronized.rs @@ -2,9 +2,9 @@ use std::array; use crossbeam_channel::{Receiver, Sender, bounded}; use ff_ext::ExtensionField; -use goldilocks::SmallField; +// use goldilocks::SmallField; -use crate::Challenge; +use crate::{Challenge, Transcript}; #[derive(Clone)] pub struct TranscriptSyncronized { @@ -42,36 +42,24 @@ impl TranscriptSyncronized { } } -impl TranscriptSyncronized { - // Append the message to the transcript. - pub fn append_message(&mut self, msg: &[u8]) { - let msg_f = E::BaseField::bytes_to_field_elements(msg); - self.bf_append_tx[self.rolling_index].send(msg_f).unwrap(); - } - - pub fn append_field_element_ext(&mut self, element: &E) { - self.ef_append_tx[self.rolling_index] +impl Transcript for TranscriptSyncronized { + fn append_field_element(&mut self, element: &E::BaseField) { + self.bf_append_tx[self.rolling_index] .send(vec![*element]) .unwrap(); } - pub fn append_field_element_exts(&mut self, element: &[E]) { + fn append_field_element_exts(&mut self, element: &[E]) { self.ef_append_tx[self.rolling_index] .send(element.to_vec()) .unwrap(); } - pub fn append_field_element(&mut self, element: &E::BaseField) { - self.bf_append_tx[self.rolling_index] - .send(vec![*element]) - .unwrap(); - } - - pub fn append_challenge(&mut self, _challenge: Challenge) { + fn append_challenge(&mut self, _challenge: Challenge) { unimplemented!() } - pub fn get_and_append_challenge(&mut self, _label: &'static [u8]) -> Challenge { + fn get_and_append_challenge(&mut self, _label: &'static [u8]) -> Challenge { Challenge { elements: self.challenge_rx[self.rolling_index].recv().unwrap(), } @@ -91,29 +79,25 @@ impl TranscriptSyncronized { // } } - pub fn read_field_element_ext(&self) -> E { - self.ef_append_rx[self.rolling_index].recv().unwrap()[0] - } - - pub fn read_field_element_exts(&self) -> Vec { + fn read_field_element_exts(&self) -> Vec { self.ef_append_rx[self.rolling_index].recv().unwrap() } - pub fn read_field_element(&self) -> E::BaseField { + fn read_field_element(&self) -> E::BaseField { self.bf_append_rx[self.rolling_index].recv().unwrap()[0] } - pub fn read_challenge(&self, _challenge: Challenge) { + fn read_challenge(&mut self) -> Challenge { unimplemented!() } - pub fn send_challenge(&self, challenge: E) { + fn send_challenge(&self, challenge: E) { self.challenge_tx[self.rolling_index] .send(challenge) .unwrap(); } - pub fn commit_rolling(&mut self) { + fn commit_rolling(&mut self) { self.rolling_index = (self.rolling_index + 1) % 2 } } From c4a6f090861a8e2d1aeb38d8e2b8426d5ec4e1ad Mon Sep 17 00:00:00 2001 From: mcalancea Date: Mon, 9 Dec 2024 12:11:24 +0200 Subject: [PATCH 4/7] Further break down e2e logic (#703) Fixes #691. - Refactors e2e into smaller steps. - Introduces a `run_partial` method which takes a `prefix` argument, indicating when to stop the run of the pipeline. According to this argument, different parts of the state are yielded back. This part isn't too pretty type-wise, but ultimately I think it's not dangerous and a reasonable compromise for the moment. Later edit: I've also included a benchmark for witness generation of the Fibonacci program, since it is a consumer of this refactor and helps to exemplify it. --- ceno_emul/src/vm_state.rs | 5 +- ceno_emul/tests/test_vm_trace.rs | 9 +- ceno_zkvm/Cargo.toml | 4 + ceno_zkvm/benches/fibonacci.rs | 31 +- ceno_zkvm/benches/fibonacci_witness.rs | 83 +++++ ceno_zkvm/examples/riscv_opcodes.rs | 11 +- ceno_zkvm/src/bin/e2e.rs | 43 +-- ceno_zkvm/src/e2e.rs | 483 ++++++++++++++++++------- ceno_zkvm/src/scheme/mock_prover.rs | 2 +- ceno_zkvm/src/scheme/tests.rs | 2 +- ceno_zkvm/src/tables/mod.rs | 2 +- 11 files changed, 479 insertions(+), 196 deletions(-) create mode 100644 ceno_zkvm/benches/fibonacci_witness.rs diff --git a/ceno_emul/src/vm_state.rs b/ceno_emul/src/vm_state.rs index 8f1746d79..e071cb000 100644 --- a/ceno_emul/src/vm_state.rs +++ b/ceno_emul/src/vm_state.rs @@ -29,9 +29,8 @@ impl VMState { /// 32 architectural registers + 1 register RD_NULL for dark writes to x0. pub const REG_COUNT: usize = 32 + 1; - pub fn new(platform: Platform, program: Program) -> Self { + pub fn new(platform: Platform, program: Arc) -> Self { let pc = program.entry; - let program = Arc::new(program); let mut vm = Self { pc, @@ -52,7 +51,7 @@ impl VMState { } pub fn new_from_elf(platform: Platform, elf: &[u8]) -> Result { - let program = Program::load_elf(elf, u32::MAX)?; + let program = Arc::new(Program::load_elf(elf, u32::MAX)?); Ok(Self::new(platform, program)) } diff --git a/ceno_emul/tests/test_vm_trace.rs b/ceno_emul/tests/test_vm_trace.rs index d931a6a9c..2aa5f0da2 100644 --- a/ceno_emul/tests/test_vm_trace.rs +++ b/ceno_emul/tests/test_vm_trace.rs @@ -1,6 +1,9 @@ #![allow(clippy::unusual_byte_groupings)] use anyhow::Result; -use std::collections::{BTreeMap, HashMap}; +use std::{ + collections::{BTreeMap, HashMap}, + sync::Arc, +}; use ceno_emul::{ CENO_PLATFORM, Cycle, EmuContext, InsnKind, Platform, Program, StepRecord, Tracer, VMState, @@ -24,7 +27,7 @@ fn test_vm_trace() -> Result<()> { }) .collect(), ); - let mut ctx = VMState::new(CENO_PLATFORM, program); + let mut ctx = VMState::new(CENO_PLATFORM, Arc::new(program)); let steps = run(&mut ctx)?; @@ -52,7 +55,7 @@ fn test_empty_program() -> Result<()> { vec![], BTreeMap::new(), ); - let mut ctx = VMState::new(CENO_PLATFORM, empty_program); + let mut ctx = VMState::new(CENO_PLATFORM, Arc::new(empty_program)); let res = run(&mut ctx); assert!(matches!(res, Err(e) if e.to_string().contains("InstructionAccessFault")),); Ok(()) diff --git a/ceno_zkvm/Cargo.toml b/ceno_zkvm/Cargo.toml index f5bd125e7..4bb427eb9 100644 --- a/ceno_zkvm/Cargo.toml +++ b/ceno_zkvm/Cargo.toml @@ -67,3 +67,7 @@ name = "riscv_add" [[bench]] harness = false name = "fibonacci" + +[[bench]] +harness = false +name = "fibonacci_witness" diff --git a/ceno_zkvm/benches/fibonacci.rs b/ceno_zkvm/benches/fibonacci.rs index a90521cfc..f75c4ddd1 100644 --- a/ceno_zkvm/benches/fibonacci.rs +++ b/ceno_zkvm/benches/fibonacci.rs @@ -7,7 +7,7 @@ use std::{ use ceno_emul::{CENO_PLATFORM, Platform, Program, WORD_SIZE}; use ceno_zkvm::{ self, - e2e::{run_e2e_gen_witness, run_e2e_proof}, + e2e::{Checkpoint, run_e2e_with_checkpoint}, }; use criterion::*; @@ -15,17 +15,20 @@ use goldilocks::GoldilocksExt2; use mpcs::BasefoldDefault; criterion_group! { - name = fibonacci; + name = fibonacci_prove_group; config = Criterion::default().warm_up_time(Duration::from_millis(20000)); - targets = bench_e2e + targets = fibonacci_prove, } -criterion_main!(fibonacci); +criterion_main!(fibonacci_prove_group); const NUM_SAMPLES: usize = 10; -fn bench_e2e(c: &mut Criterion) { - type Pcs = BasefoldDefault; +type Pcs = BasefoldDefault; +type E = GoldilocksExt2; + +// Relevant init data for fibonacci run +fn setup() -> (Program, Platform, u32, u32) { let mut file_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); file_path.push("examples/fibonacci.elf"); let stack_size = 32768; @@ -33,7 +36,6 @@ fn bench_e2e(c: &mut Criterion) { let elf_bytes = fs::read(&file_path).expect("read elf file"); let program = Program::load_elf(&elf_bytes, u32::MAX).unwrap(); - // use sp1 platform let platform = Platform { // The stack section is not mentioned in ELF headers, so we repeat the constant STACK_TOP here. stack_top: 0x0020_0400, @@ -44,6 +46,11 @@ fn bench_e2e(c: &mut Criterion) { ..CENO_PLATFORM }; + (program, platform, stack_size, heap_size) +} + +fn fibonacci_prove(c: &mut Criterion) { + let (program, platform, stack_size, heap_size) = setup(); for max_steps in [1usize << 20, 1usize << 21, 1usize << 22] { // expand more input size once runtime is acceptable let mut group = c.benchmark_group(format!("fibonacci_max_steps_{}", max_steps)); @@ -58,18 +65,20 @@ fn bench_e2e(c: &mut Criterion) { |b| { b.iter_with_setup( || { - run_e2e_gen_witness::( + run_e2e_with_checkpoint::( program.clone(), platform.clone(), stack_size, heap_size, vec![], max_steps, + Checkpoint::PrepE2EProving, ) }, - |(prover, _, zkvm_witness, pi, _, _, _)| { + |(_, run_e2e_proof)| { let timer = Instant::now(); - let _ = run_e2e_proof(prover, zkvm_witness, pi); + + run_e2e_proof(); println!( "Fibonacci::create_proof, max_steps = {}, time = {}", max_steps, @@ -82,6 +91,4 @@ fn bench_e2e(c: &mut Criterion) { group.finish(); } - - type E = GoldilocksExt2; } diff --git a/ceno_zkvm/benches/fibonacci_witness.rs b/ceno_zkvm/benches/fibonacci_witness.rs new file mode 100644 index 000000000..2f09adaee --- /dev/null +++ b/ceno_zkvm/benches/fibonacci_witness.rs @@ -0,0 +1,83 @@ +use std::{fs, path::PathBuf, time::Duration}; + +use ceno_emul::{CENO_PLATFORM, Platform, Program, WORD_SIZE}; +use ceno_zkvm::{ + self, + e2e::{Checkpoint, run_e2e_with_checkpoint}, +}; +use criterion::*; + +use goldilocks::GoldilocksExt2; +use mpcs::BasefoldDefault; + +criterion_group! { + name = fibonacci; + config = Criterion::default().warm_up_time(Duration::from_millis(20000)); + targets = fibonacci_witness +} + +criterion_main!(fibonacci); + +const NUM_SAMPLES: usize = 10; +type Pcs = BasefoldDefault; +type E = GoldilocksExt2; + +// Relevant init data for fibonacci run +fn setup() -> (Program, Platform, u32, u32) { + let mut file_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + file_path.push("examples/fibonacci.elf"); + let stack_size = 32768; + let heap_size = 2097152; + let elf_bytes = fs::read(&file_path).expect("read elf file"); + let program = Program::load_elf(&elf_bytes, u32::MAX).unwrap(); + + let platform = Platform { + // The stack section is not mentioned in ELF headers, so we repeat the constant STACK_TOP here. + stack_top: 0x0020_0400, + rom: program.base_address + ..program.base_address + (program.instructions.len() * WORD_SIZE) as u32, + ram: 0x0010_0000..0xFFFF_0000, + unsafe_ecall_nop: true, + ..CENO_PLATFORM + }; + + (program, platform, stack_size, heap_size) +} + +fn fibonacci_witness(c: &mut Criterion) { + let (program, platform, stack_size, heap_size) = setup(); + + let max_steps = usize::MAX; + let mut group = c.benchmark_group(format!("fib_wit_max_steps_{}", max_steps)); + group.sample_size(NUM_SAMPLES); + + // Benchmark the proving time + group.bench_function( + BenchmarkId::new( + "fibonacci_witness", + format!("fib_wit_max_steps_{}", max_steps), + ), + |b| { + b.iter_with_setup( + || { + run_e2e_with_checkpoint::( + program.clone(), + platform.clone(), + stack_size, + heap_size, + vec![], + max_steps, + Checkpoint::PrepWitnessGen, + ) + }, + |(_, generate_witness)| { + generate_witness(); + }, + ); + }, + ); + + group.finish(); + + type E = GoldilocksExt2; +} diff --git a/ceno_zkvm/examples/riscv_opcodes.rs b/ceno_zkvm/examples/riscv_opcodes.rs index 8ed2c4f7e..fe119bb25 100644 --- a/ceno_zkvm/examples/riscv_opcodes.rs +++ b/ceno_zkvm/examples/riscv_opcodes.rs @@ -1,4 +1,4 @@ -use std::{panic, time::Instant}; +use std::{panic, sync::Arc, time::Instant}; use ceno_zkvm::{ declare_program, @@ -177,7 +177,7 @@ fn main() { // init vm.x1 = 1, vm.x2 = -1, vm.x3 = step_loop let public_io_init = init_public_io(&[1, u32::MAX, step_loop]); - let mut vm = VMState::new(CENO_PLATFORM, program.clone()); + let mut vm = VMState::new(CENO_PLATFORM, Arc::new(program.clone())); // init memory mapped IO for record in &public_io_init { @@ -290,12 +290,7 @@ fn main() { trace_report.save_json("report.json"); trace_report.save_table("report.txt"); - MockProver::assert_satisfied_full( - zkvm_cs.clone(), - zkvm_fixed_traces.clone(), - &zkvm_witness, - &pi, - ); + MockProver::assert_satisfied_full(&zkvm_cs, zkvm_fixed_traces.clone(), &zkvm_witness, &pi); let timer = Instant::now(); diff --git a/ceno_zkvm/src/bin/e2e.rs b/ceno_zkvm/src/bin/e2e.rs index 60b1e6bce..07baf8998 100644 --- a/ceno_zkvm/src/bin/e2e.rs +++ b/ceno_zkvm/src/bin/e2e.rs @@ -1,6 +1,6 @@ use ceno_emul::{CENO_PLATFORM, IterAddresses, Platform, Program, WORD_SIZE, Word}; use ceno_zkvm::{ - e2e::{run_e2e_gen_witness, run_e2e_proof, run_e2e_verify}, + e2e::{Checkpoint, run_e2e_with_checkpoint}, with_panic_hook, }; use clap::{Parser, ValueEnum}; @@ -8,7 +8,7 @@ use ff_ext::ff::Field; use goldilocks::{Goldilocks, GoldilocksExt2}; use itertools::Itertools; use mpcs::{Basefold, BasefoldRSParams}; -use std::{fs, panic, time::Instant}; +use std::{fs, panic}; use tracing::level_filters::LevelFilter; use tracing_forest::ForestLayer; use tracing_subscriber::{ @@ -143,37 +143,17 @@ fn main() { type B = Goldilocks; type Pcs = Basefold; - let (prover, verifier, zkvm_witness, pi, cycle_num, e2e_start, exit_code) = - run_e2e_gen_witness::( - program, - platform, - args.stack_size, - args.heap_size, - hints, - max_steps, - ); - - let timer = Instant::now(); - let mut zkvm_proof = run_e2e_proof(prover, zkvm_witness, pi); - let proving_time = timer.elapsed().as_secs_f64(); - let e2e_time = e2e_start.elapsed().as_secs_f64(); - let witgen_time = e2e_time - proving_time; - println!( - "Proving finished.\n\ -\tProving time = {:.3}s, freq = {:.3}khz\n\ -\tWitgen time = {:.3}s, freq = {:.3}khz\n\ -\tTotal time = {:.3}s, freq = {:.3}khz\n\ -\tthread num: {}", - proving_time, - cycle_num as f64 / proving_time / 1000.0, - witgen_time, - cycle_num as f64 / witgen_time / 1000.0, - e2e_time, - cycle_num as f64 / e2e_time / 1000.0, - rayon::current_num_threads() + let (state, _) = run_e2e_with_checkpoint::( + program, + platform, + args.stack_size, + args.heap_size, + hints, + max_steps, + Checkpoint::PrepSanityCheck, ); - run_e2e_verify(&verifier, zkvm_proof.clone(), exit_code, max_steps); + let (mut zkvm_proof, verifier) = state.expect("PrepSanityCheck should yield state."); // do sanity check let transcript = Transcript::new(b"riscv"); @@ -207,7 +187,6 @@ fn main() { } }; } - fn memory_from_file(path: &Option) -> Vec { path.as_ref() .map(|path| { diff --git a/ceno_zkvm/src/e2e.rs b/ceno_zkvm/src/e2e.rs index 512f56982..b1d5b4d77 100644 --- a/ceno_zkvm/src/e2e.rs +++ b/ceno_zkvm/src/e2e.rs @@ -5,136 +5,69 @@ use crate::{ prover::ZKVMProver, verifier::ZKVMVerifier, }, state::GlobalState, - structs::{ProgramParams, ZKVMConstraintSystem, ZKVMFixedTraces, ZKVMWitnesses}, - tables::{MemFinalRecord, MemInitRecord, ProgramTableCircuit}, + structs::{ + ProgramParams, ZKVMConstraintSystem, ZKVMFixedTraces, ZKVMProvingKey, ZKVMWitnesses, + }, + tables::{MemFinalRecord, MemInitRecord, ProgramTableCircuit, ProgramTableConfig}, }; use ceno_emul::{ ByteAddr, EmuContext, InsnKind::EANY, IterAddresses, Platform, Program, StepRecord, Tracer, VMState, WORD_SIZE, WordAddr, }; use ff_ext::ExtensionField; -use itertools::{Itertools, MinMaxResult, chain, enumerate}; +use itertools::{Itertools, MinMaxResult, chain}; use mpcs::PolynomialCommitmentScheme; use std::{ collections::{HashMap, HashSet}, iter::zip, - time::Instant, + ops::Deref, + sync::Arc, }; use transcript::BasicTranscript as Transcript; -type E2EWitnessGen = ( - ZKVMProver, - ZKVMVerifier, - ZKVMWitnesses, - PublicValues, - usize, // number of cycles - Instant, // e2e start, excluding key gen time - Option, -); - -pub fn run_e2e_gen_witness>( - program: Program, - platform: Platform, - stack_size: u32, - heap_size: u32, - hints: Vec, - max_steps: usize, -) -> E2EWitnessGen { - let stack_addrs = platform.stack_top - stack_size..platform.stack_top; - - // Detect heap as starting after program data. - let heap_start = program.image.keys().max().unwrap() + WORD_SIZE as u32; - let heap_addrs = heap_start..heap_start + heap_size; - - let mut mem_padder = MemPadder::new(heap_addrs.end..platform.ram.end); - - let mem_init = { - let program_addrs = program.image.iter().map(|(addr, value)| MemInitRecord { - addr: *addr, - value: *value, - }); - - let stack = stack_addrs - .iter_addresses() - .map(|addr| MemInitRecord { addr, value: 0 }); +pub struct FullMemState { + mem: Vec, + io: Vec, + reg: Vec, + priv_io: Vec, +} - let heap = heap_addrs - .iter_addresses() - .map(|addr| MemInitRecord { addr, value: 0 }); +type InitMemState = FullMemState; +type FinalMemState = FullMemState; - let mem_init = chain!(program_addrs, stack, heap).collect_vec(); +pub struct EmulationResult { + exit_code: Option, + all_records: Vec, + final_mem_state: FinalMemState, + pi: PublicValues, +} - mem_padder.padded_sorted(mem_init.len().next_power_of_two(), mem_init) - }; +fn emulate_program( + program: Arc, + max_steps: usize, + init_mem_state: InitMemState, + platform: &Platform, + hints: Vec, +) -> EmulationResult { + let InitMemState { + mem: mem_init, + io: io_init, + reg: reg_init, + priv_io: _, + } = init_mem_state; - let mut vm = VMState::new(platform.clone(), program); + let mut vm: VMState = VMState::new(platform.clone(), program); for (addr, value) in zip(platform.hints.iter_addresses(), &hints) { vm.init_memory(addr.into(), *value); } - // keygen - let pcs_param = PCS::setup(1 << MAX_NUM_VARIABLES).expect("Basefold PCS setup"); - let (pp, vp) = PCS::trim(pcs_param, 1 << MAX_NUM_VARIABLES).expect("Basefold trim"); - let program_params = ProgramParams { - platform: platform.clone(), - program_size: vm.program().instructions.len(), - static_memory_len: mem_init.len(), - ..ProgramParams::default() - }; - let mut zkvm_cs = ZKVMConstraintSystem::new_with_platform(program_params); - - let config = Rv32imConfig::::construct_circuits(&mut zkvm_cs); - let mmu_config = MmuConfig::::construct_circuits(&mut zkvm_cs); - let dummy_config = DummyExtraConfig::::construct_circuits(&mut zkvm_cs); - let prog_config = zkvm_cs.register_table_circuit::>(); - zkvm_cs.register_global_state::(); - - let mut zkvm_fixed_traces = ZKVMFixedTraces::default(); - - zkvm_fixed_traces.register_table_circuit::>( - &zkvm_cs, - &prog_config, - vm.program(), - ); - - // IO is not used in this program, but it must have a particular size at the moment. - let io_init = mem_padder.padded_sorted(mmu_config.public_io_len(), vec![]); - - let reg_init = mmu_config.initial_registers(); - config.generate_fixed_traces(&zkvm_cs, &mut zkvm_fixed_traces); - mmu_config.generate_fixed_traces( - &zkvm_cs, - &mut zkvm_fixed_traces, - ®_init, - &mem_init, - &io_init.iter().map(|rec| rec.addr).collect_vec(), - ); - dummy_config.generate_fixed_traces(&zkvm_cs, &mut zkvm_fixed_traces); - - let pk = zkvm_cs - .clone() - .key_gen::(pp.clone(), vp.clone(), zkvm_fixed_traces.clone()) - .expect("keygen failed"); - let vk = pk.get_vk(); - - // proving - let e2e_start = Instant::now(); - let prover = ZKVMProver::new(pk); - let verifier = ZKVMVerifier::new(vk); - let all_records = vm .iter_until_halt() .take(max_steps) .collect::, _>>() .expect("vm exec failed"); - let cycle_num = all_records.len(); - tracing::info!("Proving {} execution steps", cycle_num); - for (i, step) in enumerate(&all_records).rev().take(5).rev() { - tracing::trace!("Step {i}: {:?} - {:?}\n", step.insn().codes().kind, step); - } - // Find the exit code from the HALT step, if halting at all. let exit_code = all_records .iter() @@ -158,16 +91,6 @@ pub fn run_e2e_gen_witness io_init.iter().map(|rec| rec.value).collect_vec(), ); - let mut zkvm_witness = ZKVMWitnesses::default(); - // assign opcode circuits - let dummy_records = config - .assign_opcode_circuit(&zkvm_cs, &mut zkvm_witness, all_records) - .unwrap(); - dummy_config - .assign_opcode_circuit(&zkvm_cs, &mut zkvm_witness, dummy_records) - .unwrap(); - zkvm_witness.finalize_lk_multiplicities(); - // Find the final register values and cycles. let reg_final = reg_init .iter() @@ -208,7 +131,11 @@ pub fn run_e2e_gen_witness // Find the final public IO cycles. let io_final = io_init .iter() - .map(|rec| *final_access.get(&rec.addr.into()).unwrap_or(&0)) + .map(|rec| MemFinalRecord { + addr: rec.addr, + value: rec.value, + cycle: *final_access.get(&rec.addr.into()).unwrap_or(&0), + }) .collect_vec(); let priv_io_final = zip(platform.hints.iter_addresses(), &hints) @@ -219,45 +146,331 @@ pub fn run_e2e_gen_witness }) .collect_vec(); + EmulationResult { + pi, + exit_code, + all_records, + final_mem_state: FinalMemState { + reg: reg_final, + io: io_final, + mem: mem_final, + priv_io: priv_io_final, + }, + } +} + +fn init_mem( + program: &Program, + platform: &Platform, + mem_padder: &mut MemPadder, + stack_size: u32, + heap_size: u32, +) -> Vec { + let stack_addrs = platform.stack_top - stack_size..platform.stack_top; + // Detect heap as starting after program data. + let heap_start = program.image.keys().max().unwrap() + WORD_SIZE as u32; + let heap_addrs = heap_start..heap_start + heap_size; + let program_addrs = program.image.iter().map(|(addr, value)| MemInitRecord { + addr: *addr, + value: *value, + }); + + let stack = stack_addrs + .iter_addresses() + .map(|addr| MemInitRecord { addr, value: 0 }); + + let heap = heap_addrs + .iter_addresses() + .map(|addr| MemInitRecord { addr, value: 0 }); + + let mem_init = chain!(program_addrs, stack, heap).collect_vec(); + + mem_padder.padded_sorted(mem_init.len().next_power_of_two(), mem_init) +} + +pub struct ConstraintSystemConfig { + zkvm_cs: ZKVMConstraintSystem, + config: Rv32imConfig, + mmu_config: MmuConfig, + dummy_config: DummyExtraConfig, + prog_config: ProgramTableConfig, +} + +fn construct_configs( + program_params: ProgramParams, +) -> ConstraintSystemConfig { + let mut zkvm_cs = ZKVMConstraintSystem::new_with_platform(program_params); + + let config = Rv32imConfig::::construct_circuits(&mut zkvm_cs); + let mmu_config = MmuConfig::::construct_circuits(&mut zkvm_cs); + let dummy_config = DummyExtraConfig::::construct_circuits(&mut zkvm_cs); + let prog_config = zkvm_cs.register_table_circuit::>(); + zkvm_cs.register_global_state::(); + ConstraintSystemConfig { + zkvm_cs, + config, + mmu_config, + dummy_config, + prog_config, + } +} + +fn generate_fixed_traces( + system_config: &ConstraintSystemConfig, + init_mem_state: &InitMemState, + program: &Program, +) -> ZKVMFixedTraces { + let mut zkvm_fixed_traces = ZKVMFixedTraces::default(); + + zkvm_fixed_traces.register_table_circuit::>( + &system_config.zkvm_cs, + &system_config.prog_config, + program, + ); + + system_config + .config + .generate_fixed_traces(&system_config.zkvm_cs, &mut zkvm_fixed_traces); + system_config.mmu_config.generate_fixed_traces( + &system_config.zkvm_cs, + &mut zkvm_fixed_traces, + &init_mem_state.reg, + &init_mem_state.mem, + &init_mem_state.io.iter().map(|rec| rec.addr).collect_vec(), + ); + system_config + .dummy_config + .generate_fixed_traces(&system_config.zkvm_cs, &mut zkvm_fixed_traces); + + zkvm_fixed_traces +} + +pub fn generate_witness( + system_config: &ConstraintSystemConfig, + emul_result: EmulationResult, + program: &Program, +) -> ZKVMWitnesses { + let mut zkvm_witness = ZKVMWitnesses::default(); + // assign opcode circuits + let dummy_records = system_config + .config + .assign_opcode_circuit( + &system_config.zkvm_cs, + &mut zkvm_witness, + emul_result.all_records, + ) + .unwrap(); + system_config + .dummy_config + .assign_opcode_circuit(&system_config.zkvm_cs, &mut zkvm_witness, dummy_records) + .unwrap(); + zkvm_witness.finalize_lk_multiplicities(); + // assign table circuits - config - .assign_table_circuit(&zkvm_cs, &mut zkvm_witness) + system_config + .config + .assign_table_circuit(&system_config.zkvm_cs, &mut zkvm_witness) .unwrap(); - mmu_config + system_config + .mmu_config .assign_table_circuit( - &zkvm_cs, + &system_config.zkvm_cs, &mut zkvm_witness, - ®_final, - &mem_final, - &io_final, - &priv_io_final, + &emul_result.final_mem_state.reg, + &emul_result.final_mem_state.mem, + &emul_result + .final_mem_state + .io + .iter() + .map(|rec| rec.cycle) + .collect_vec(), + &emul_result.final_mem_state.priv_io, ) .unwrap(); // assign program circuit zkvm_witness - .assign_table_circuit::>(&zkvm_cs, &prog_config, vm.program()) + .assign_table_circuit::>( + &system_config.zkvm_cs, + &system_config.prog_config, + program, + ) .unwrap(); + zkvm_witness +} + +// Encodes useful early return points of the e2e pipeline +pub enum Checkpoint { + PrepE2EProving, + PrepWitnessGen, + PrepSanityCheck, + Complete, +} + +// Currently handles state required by the sanity check in `bin/e2e.rs` +// Future cases would require this to be an enum +pub type IntermediateState = (ZKVMProof, ZKVMVerifier); + +// Runs end-to-end pipeline, stopping at a certain checkpoint and yielding useful state. +// +// The return type is a pair of: +// 1. Explicit state +// 2. A no-input-no-ouptut closure +// +// (2.) is useful when you want to setup a certain action and run it +// elsewhere (i.e, in a benchmark) +// (1.) is useful for exposing state which must be further combined with +// state external to this pipeline (e.g, sanity check in bin/e2e.rs) + +#[allow(clippy::type_complexity)] +pub fn run_e2e_with_checkpoint + 'static>( + program: Program, + platform: Platform, + stack_size: u32, + heap_size: u32, + hints: Vec, + max_steps: usize, + checkpoint: Checkpoint, +) -> (Option>, Box) { + // Detect heap as starting after program data. + let heap_start = program.image.keys().max().unwrap() + WORD_SIZE as u32; + let heap_addrs = heap_start..heap_start + heap_size; + let mut mem_padder = MemPadder::new(heap_addrs.end..platform.ram.end); + let mem_init = init_mem(&program, &platform, &mut mem_padder, stack_size, heap_size); + + let program_params = ProgramParams { + platform: platform.clone(), + program_size: program.instructions.len(), + static_memory_len: mem_init.len(), + ..ProgramParams::default() + }; + + let program = Arc::new(program); + let system_config = construct_configs::(program_params); + + // IO is not used in this program, but it must have a particular size at the moment. + let io_init = mem_padder.padded_sorted(system_config.mmu_config.public_io_len(), vec![]); + let reg_init = system_config.mmu_config.initial_registers(); + + let init_full_mem = InitMemState { + mem: mem_init, + reg: reg_init, + io: io_init, + priv_io: vec![], + }; + + // Generate fixed traces + let zkvm_fixed_traces = generate_fixed_traces(&system_config, &init_full_mem, &program); + + // Keygen + let pcs_param = PCS::setup(1 << MAX_NUM_VARIABLES).expect("Basefold PCS setup"); + let (pp, vp) = PCS::trim(pcs_param, 1 << MAX_NUM_VARIABLES).expect("Basefold trim"); + let pk = system_config + .zkvm_cs + .clone() + .key_gen::(pp.clone(), vp.clone(), zkvm_fixed_traces.clone()) + .expect("keygen failed"); + let vk = pk.get_vk(); + + if let Checkpoint::PrepE2EProving = checkpoint { + return ( + None, + Box::new(move || { + _ = run_e2e_proof( + program, + max_steps, + init_full_mem, + platform, + hints, + &system_config, + pk, + zkvm_fixed_traces, + ) + }), + ); + } + + // Emulate program + let emul_result = emulate_program(program.clone(), max_steps, init_full_mem, &platform, hints); + + // Clone some emul_result fields before consuming + let pi = emul_result.pi.clone(); + let exit_code = emul_result.exit_code; + + if let Checkpoint::PrepWitnessGen = checkpoint { + return ( + None, + Box::new(move || _ = generate_witness(&system_config, emul_result, program.deref())), + ); + } + + // Generate witness + let zkvm_witness = generate_witness(&system_config, emul_result, &program); + + // proving + let prover = ZKVMProver::new(pk); + if std::env::var("MOCK_PROVING").is_ok() { - MockProver::assert_satisfied_full(zkvm_cs, zkvm_fixed_traces, &zkvm_witness, &pi); + MockProver::assert_satisfied_full( + &system_config.zkvm_cs, + zkvm_fixed_traces.clone(), + &zkvm_witness, + &pi, + ); tracing::info!("Mock proving passed"); } - ( - prover, - verifier, - zkvm_witness, - pi, - cycle_num, - e2e_start, - exit_code, - ) + + // Run proof phase + let transcript = Transcript::new(b"riscv"); + let zkvm_proof = prover + .create_proof(zkvm_witness, pi, transcript) + .expect("create_proof failed"); + + let verifier = ZKVMVerifier::new(vk); + + run_e2e_verify(&verifier, zkvm_proof.clone(), exit_code, max_steps); + + if let Checkpoint::PrepSanityCheck = checkpoint { + return (Some((zkvm_proof, verifier)), Box::new(|| ())); + } + + (None, Box::new(|| ())) } +// Runs program emulation + witness generation + proving +#[allow(clippy::too_many_arguments)] pub fn run_e2e_proof>( - prover: ZKVMProver, - zkvm_witness: ZKVMWitnesses, - pi: PublicValues, + program: Arc, + max_steps: usize, + init_full_mem: InitMemState, + platform: Platform, + hints: Vec, + system_config: &ConstraintSystemConfig, + pk: ZKVMProvingKey, + zkvm_fixed_traces: ZKVMFixedTraces, ) -> ZKVMProof { + // Emulate program + let emul_result = emulate_program(program.clone(), max_steps, init_full_mem, &platform, hints); + + // clone pi before consuming + let pi = emul_result.pi.clone(); + + // Generate witness + let zkvm_witness = generate_witness(system_config, emul_result, program.deref()); + + // proving + let prover = ZKVMProver::new(pk); + + if std::env::var("MOCK_PROVING").is_ok() { + MockProver::assert_satisfied_full( + &system_config.zkvm_cs, + zkvm_fixed_traces.clone(), + &zkvm_witness, + &pi, + ); + tracing::info!("Mock proving passed"); + } + let transcript = Transcript::new(b"riscv"); prover .create_proof(zkvm_witness, pi, transcript) diff --git a/ceno_zkvm/src/scheme/mock_prover.rs b/ceno_zkvm/src/scheme/mock_prover.rs index 70b543090..ccd8e0a07 100644 --- a/ceno_zkvm/src/scheme/mock_prover.rs +++ b/ceno_zkvm/src/scheme/mock_prover.rs @@ -746,7 +746,7 @@ Hints: } pub fn assert_satisfied_full( - cs: ZKVMConstraintSystem, + cs: &ZKVMConstraintSystem, mut fixed_trace: ZKVMFixedTraces, witnesses: &ZKVMWitnesses, pi: &PublicValues, diff --git a/ceno_zkvm/src/scheme/tests.rs b/ceno_zkvm/src/scheme/tests.rs index fe3ce8f07..13ef29a66 100644 --- a/ceno_zkvm/src/scheme/tests.rs +++ b/ceno_zkvm/src/scheme/tests.rs @@ -261,7 +261,7 @@ fn test_single_add_instance_e2e() { let vk = pk.get_vk(); // single instance - let mut vm = VMState::new(CENO_PLATFORM, program.clone()); + let mut vm = VMState::new(CENO_PLATFORM, program.clone().into()); let all_records = vm .iter_until_halt() .collect::, _>>() diff --git a/ceno_zkvm/src/tables/mod.rs b/ceno_zkvm/src/tables/mod.rs index b27f04e54..892babb3f 100644 --- a/ceno_zkvm/src/tables/mod.rs +++ b/ceno_zkvm/src/tables/mod.rs @@ -14,7 +14,7 @@ mod ops; pub use ops::*; mod program; -pub use program::{InsnRecord, ProgramTableCircuit}; +pub use program::{InsnRecord, ProgramTableCircuit, ProgramTableConfig}; mod ram; pub use ram::*; From 5cc69590230ec0eedc7be64273d2f454d394a7ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=B6rgens?= Date: Tue, 10 Dec 2024 09:19:07 +0800 Subject: [PATCH 5/7] Simplify SLTI tests (#710) Extracted from https://github.com/scroll-tech/ceno/pull/667 to make that PR smaller and easier to review. --- ceno_zkvm/src/instructions/riscv/slti.rs | 79 +++++++++++++----------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/ceno_zkvm/src/instructions/riscv/slti.rs b/ceno_zkvm/src/instructions/riscv/slti.rs index d88f0336c..76894f7a0 100644 --- a/ceno_zkvm/src/instructions/riscv/slti.rs +++ b/ceno_zkvm/src/instructions/riscv/slti.rs @@ -150,29 +150,31 @@ mod test { #[test] fn test_sltiu_true() { - verify::("lt = true, 0 < 1", 0, 1, 1); - verify::("lt = true, 1 < 2", 1, 2, 1); - verify::("lt = true, 10 < 20", 10, 20, 1); - verify::("lt = true, 0 < imm upper boundary", 0, 2047, 1); + let verify = |name, a, imm| verify::(name, a, imm, true); + verify("lt = true, 0 < 1", 0, 1); + verify("lt = true, 1 < 2", 1, 2); + verify("lt = true, 10 < 20", 10, 20); + verify("lt = true, 0 < imm upper boundary", 0, 2047); // negative imm is treated as positive - verify::("lt = true, 0 < u32::MAX-1", 0, -1, 1); - verify::("lt = true, 1 < u32::MAX-1", 1, -1, 1); - verify::("lt = true, 0 < imm lower bondary", 0, -2048, 1); + verify("lt = true, 0 < u32::MAX-1", 0, -1); + verify("lt = true, 1 < u32::MAX-1", 1, -1); + verify("lt = true, 0 < imm lower bondary", 0, -2048); } #[test] fn test_sltiu_false() { - verify::("lt = false, 1 < 0", 1, 0, 0); - verify::("lt = false, 2 < 1", 2, 1, 0); - verify::("lt = false, 100 < 50", 100, 50, 0); - verify::("lt = false, 500 < 100", 500, 100, 0); - verify::("lt = false, 100000 < 2047", 100000, 2047, 0); - verify::("lt = false, 100000 < 0", 100000, 0, 0); - verify::("lt = false, 0 == 0", 0, 0, 0); - verify::("lt = false, 1 == 1", 1, 1, 0); - verify::("lt = false, imm upper bondary", u32::MAX, 2047, 0); + let verify = |name, a, imm| verify::(name, a, imm, false); + verify("lt = false, 1 < 0", 1, 0); + verify("lt = false, 2 < 1", 2, 1); + verify("lt = false, 100 < 50", 100, 50); + verify("lt = false, 500 < 100", 500, 100); + verify("lt = false, 100000 < 2047", 100000, 2047); + verify("lt = false, 100000 < 0", 100000, 0); + verify("lt = false, 0 == 0", 0, 0); + verify("lt = false, 1 == 1", 1, 1); + verify("lt = false, imm upper bondary", u32::MAX, 2047); // negative imm is treated as positive - verify::("lt = false, imm lower bondary", u32::MAX, -2048, 0); + verify("lt = false, imm lower bondary", u32::MAX, -2048); } #[test] @@ -181,34 +183,36 @@ mod test { let a: u32 = rng.gen::(); let b: i32 = rng.gen_range(-2048..2048); println!("random: {} ("random unsigned comparison", a, b, (a < (b as u32)) as u32); + verify::("random unsigned comparison", a, b, a < (b as u32)); } #[test] fn test_slti_true() { - verify::("lt = true, 0 < 1", 0, 1, 1); - verify::("lt = true, 1 < 2", 1, 2, 1); - verify::("lt = true, -1 < 0", -1i32 as u32, 0, 1); - verify::("lt = true, -1 < 1", -1i32 as u32, 1, 1); - verify::("lt = true, -2 < -1", -2i32 as u32, -1, 1); + let verify = |name, a: i32, imm| verify::(name, a as u32, imm, true); + verify("lt = true, 0 < 1", 0, 1); + verify("lt = true, 1 < 2", 1, 2); + verify("lt = true, -1 < 0", -1, 0); + verify("lt = true, -1 < 1", -1, 1); + verify("lt = true, -2 < -1", -2, -1); // -2048 <= imm <= 2047 - verify::("lt = true, imm upper bondary", i32::MIN as u32, 2047, 1); - verify::("lt = true, imm lower bondary", i32::MIN as u32, -2048, 1); + verify("lt = true, imm upper bondary", i32::MIN, 2047); + verify("lt = true, imm lower bondary", i32::MIN, -2048); } #[test] fn test_slti_false() { - verify::("lt = false, 1 < 0", 1, 0, 0); - verify::("lt = false, 2 < 1", 2, 1, 0); - verify::("lt = false, 0 < -1", 0, -1, 0); - verify::("lt = false, 1 < -1", 1, -1, 0); - verify::("lt = false, -1 < -2", -1i32 as u32, -2, 0); - verify::("lt = false, 0 == 0", 0, 0, 0); - verify::("lt = false, 1 == 1", 1, 1, 0); - verify::("lt = false, -1 == -1", -1i32 as u32, -1, 0); + let verify = |name, a: i32, imm| verify::(name, a as u32, imm, false); + verify("lt = false, 1 < 0", 1, 0); + verify("lt = false, 2 < 1", 2, 1); + verify("lt = false, 0 < -1", 0, -1); + verify("lt = false, 1 < -1", 1, -1); + verify("lt = false, -1 < -2", -1, -2); + verify("lt = false, 0 == 0", 0, 0); + verify("lt = false, 1 == 1", 1, 1); + verify("lt = false, -1 == -1", -1, -1); // -2048 <= imm <= 2047 - verify::("lt = false, imm upper bondary", i32::MAX as u32, 2047, 0); - verify::("lt = false, imm lower bondary", i32::MAX as u32, -2048, 0); + verify("lt = false, imm upper bondary", i32::MAX, 2047); + verify("lt = false, imm lower bondary", i32::MAX, -2048); } #[test] @@ -217,10 +221,11 @@ mod test { let a: i32 = rng.gen(); let b: i32 = rng.gen_range(-2048..2048); println!("random: {} ("random 1", a as u32, b, (a < b) as u32); + verify::("random 1", a as u32, b, a < b); } - fn verify(name: &'static str, rs1_read: u32, imm: i32, expected_rd: u32) { + fn verify(name: &'static str, rs1_read: u32, imm: i32, expected_rd: bool) { + let expected_rd = expected_rd as u32; let mut cs = ConstraintSystem::::new(|| "riscv"); let mut cb = CircuitBuilder::new(&mut cs); From 79ce99f79627b430e57cdefc6c91cf0521e3c854 Mon Sep 17 00:00:00 2001 From: Ho Date: Tue, 10 Dec 2024 13:19:35 +0900 Subject: [PATCH 6/7] [FIX] Broken integration test caused by transcript (#715) (#721) This PR has fixed issue #715 by respect the assertion in `from_base` method of the Godilock extension field Notice there is two method `from_base` and `form_limbs` in the `ExtensionField` trait which is not well illustrated and maybe we should update them later. The two running mentioned in #715 have been success under this PR `cargo run --package ceno_zkvm --bin e2e -- --platform=sp1 ceno_zkvm/examples/fibonacci.elf` `cargo run --package ceno_zkvm --example riscv_opcodes -- --start 10 --end 11` --- transcript/src/basic.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/transcript/src/basic.rs b/transcript/src/basic.rs index ec455d236..47c32cdf4 100644 --- a/transcript/src/basic.rs +++ b/transcript/src/basic.rs @@ -32,7 +32,13 @@ impl Transcript for BasicTranscript { } fn read_challenge(&mut self) -> Challenge { - let r = E::from_bases(self.permutation.squeeze()); + // notice `from_bases` and `from_limbs` has the same behavior but + // `from_bases` has a sanity check for length of input slices + // while `from_limbs` use the first two fields silently + // we select `from_base` here to make it being more clear that + // we only use the first 2 fields here to construct the + // extension field (i.e. the challenge) + let r = E::from_bases(&self.permutation.squeeze()[..2]); Challenge { elements: r } } From 33901fd8d097abe866d1279afe0315ebd2c8e68f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=B6rgens?= Date: Tue, 10 Dec 2024 14:00:54 +0800 Subject: [PATCH 7/7] Enable debug assertions in integration tests (#714) To catch some bugs, like the recent breakage. --------- Co-authored-by: noelwei --- .github/workflows/integration.yml | 6 ++++-- Cargo.toml | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 767758a8b..ec0de0b14 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -56,10 +56,12 @@ jobs: - name: Run example env: RAYON_NUM_THREADS: 2 - run: cargo run --release --package ceno_zkvm --example riscv_opcodes --target ${{ matrix.target }} -- --start 10 --end 11 + RUSTFLAGS: "-C opt-level=3" + run: cargo run --package ceno_zkvm --example riscv_opcodes --target ${{ matrix.target }} -- --start 10 --end 11 - name: Run fibonacci env: RAYON_NUM_THREADS: 8 RUST_LOG: debug - run: cargo run --release --package ceno_zkvm --bin e2e --target ${{ matrix.target }} -- --platform=sp1 ceno_zkvm/examples/fibonacci.elf \ No newline at end of file + RUSTFLAGS: "-C opt-level=3" + run: cargo run --package ceno_zkvm --bin e2e --target ${{ matrix.target }} -- --platform=sp1 ceno_zkvm/examples/fibonacci.elf diff --git a/Cargo.toml b/Cargo.toml index 1ee0b66ef..ead19b880 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,5 +52,8 @@ tracing = { version = "0.1", features = [ tracing-forest = { version = "0.1.6" } tracing-subscriber = { version = "0.3", features = ["env-filter"] } +[profile.dev] +lto = "thin" + [profile.release] lto = "thin"