diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 0a53057..10b7db6 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -24,4 +24,3 @@ When Copilot reviews this PR, apply `.github/copilot-instructions.md` strictly. - Prioritize soundness, performance, and architecture risks over style. - Output order: findings by severity, then open questions, then brief summary. - If PR description is empty or missing key context, report `PR metadata: description` as a finding. - diff --git a/Cargo.lock b/Cargo.lock index a4a5bea..97b1a38 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -133,16 +133,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" -[[package]] -name = "cc" -version = "1.2.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d05d92f4b1fd76aad469d46cdd858ca761576082cd37df81416691e50199fb" -dependencies = [ - "find-msvc-tools", - "shlex", -] - [[package]] name = "cfg-if" version = "1.0.3" @@ -331,7 +321,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" dependencies = [ "generic-array 0.14.7", - "rand_core", + "rand_core 0.6.4", "subtle", "zeroize", ] @@ -505,7 +495,7 @@ dependencies = [ "group", "pem-rfc7468", "pkcs8", - "rand_core", + "rand_core 0.6.4", "sec1", "subtle", "zeroize", @@ -546,7 +536,7 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393" dependencies = [ - "rand_core", + "rand_core 0.6.4", "subtle", ] @@ -556,22 +546,10 @@ version = "0.1.0" dependencies = [ "once_cell", "p3", - "rand_core", + "rand_core 0.6.4", "serde", ] -[[package]] -name = "find-msvc-tools" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0399f9d26e5191ce32c498bebd31e7a3ceabc2745f0ac54af3f335126c3f24b3" - -[[package]] -name = "gcd" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d758ba1b47b00caf47f24925c0074ecb20d6dfcffe7f6d53395c0465674841a" - [[package]] name = "generic-array" version = "0.14.7" @@ -621,7 +599,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ "ff", - "rand_core", + "rand_core 0.6.4", "subtle", ] @@ -799,6 +777,15 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + [[package]] name = "log" version = "0.4.27" @@ -832,7 +819,7 @@ dependencies = [ "multilinear_extensions", "num-integer", "p3", - "rand", + "rand 0.8.5", "rand_chacha", "serde", "sumcheck", @@ -855,7 +842,7 @@ dependencies = [ "itertools 0.13.0", "log", "p3", - "rand", + "rand 0.8.5", "rayon", "serde", "serde_json", @@ -894,7 +881,7 @@ checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ "num-integer", "num-traits", - "rand", + "rand 0.8.5", ] [[package]] @@ -904,7 +891,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" dependencies = [ "num-traits", - "rand", + "rand 0.8.5", ] [[package]] @@ -962,18 +949,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "nums" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf3c74f925fb8cfc49a8022f2afce48a0683b70f9e439885594e84c5edbf5b01" -dependencies = [ - "num-bigint", - "num-integer", - "num-traits", - "rand", -] - [[package]] name = "once_cell" version = "1.21.3" @@ -1036,8 +1011,9 @@ dependencies = [ [[package]] name = "p3-air" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daee3082e2ca0db2ac876c43c9c8fd53204b0fcb95cfe7258d21f4a925ad82c4" dependencies = [ "p3-field", "p3-matrix", @@ -1045,25 +1021,28 @@ dependencies = [ [[package]] name = "p3-baby-bear" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a1a49f4d9c8b8cbdab61e25d9de1b78b3c8347dd2fb88b11d990b3efa8cdd3a" dependencies = [ + "p3-challenger", "p3-field", "p3-mds", "p3-monty-31", "p3-poseidon2", "p3-symmetric", - "rand", - "serde", + "rand 0.9.2", ] [[package]] name = "p3-challenger" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7d2d45f5a51dc3f965e8d6da60a6c26c807e88657863d56da275eaa05ad36f1" dependencies = [ "p3-field", "p3-maybe-rayon", + "p3-monty-31", "p3-symmetric", "p3-util", "tracing", @@ -1071,8 +1050,9 @@ dependencies = [ [[package]] name = "p3-commit" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf6d7dcb58a8f21f0e1325dc7f7699ad749878ccbe7e286e61f9d46bde2bfa88" dependencies = [ "itertools 0.14.0", "p3-challenger", @@ -1085,38 +1065,40 @@ dependencies = [ [[package]] name = "p3-dft" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "beabb40bc8ac7f5f95870f271fb844c7e2e1ebb7f0761a8eebb2614b56c6b1c1" dependencies = [ "itertools 0.14.0", "p3-field", "p3-matrix", "p3-maybe-rayon", "p3-util", + "spin", "tracing", ] [[package]] name = "p3-field" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4819a3e4c1882431a63d4847ffa10d110017aee4cb9cf4319ca6dca191930969" dependencies = [ "itertools 0.14.0", "num-bigint", - "num-integer", - "num-traits", - "nums", "p3-maybe-rayon", "p3-util", - "rand", + "paste", + "rand 0.9.2", "serde", "tracing", ] [[package]] name = "p3-fri" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13ca6a795cfc4180425fbf16dfdb4c9c2bfa85971dd55b5930d97b513e0835df" dependencies = [ "itertools 0.14.0", "p3-challenger", @@ -1127,32 +1109,36 @@ dependencies = [ "p3-matrix", "p3-maybe-rayon", "p3-util", - "rand", + "rand 0.9.2", "serde", + "thiserror 2.0.18", "tracing", ] [[package]] name = "p3-goldilocks" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c47d5c650bbeb25941b9a1fa9bfaf59b3cd202a438ea2c20892489af001399" dependencies = [ "num-bigint", + "p3-challenger", "p3-dft", "p3-field", "p3-mds", - "p3-poseidon", "p3-poseidon2", "p3-symmetric", "p3-util", - "rand", + "paste", + "rand 0.9.2", "serde", ] [[package]] name = "p3-interpolation" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f27a3696641a8f4ec990ff8c91862fb4f3b4ff29f589f78005d046023fe3550f" dependencies = [ "p3-field", "p3-matrix", @@ -1162,45 +1148,46 @@ dependencies = [ [[package]] name = "p3-matrix" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6fde449bd2963d394284ec46db8c647e6a5602d90601117b76752072ab54168" dependencies = [ "itertools 0.14.0", "p3-field", "p3-maybe-rayon", "p3-util", - "rand", + "rand 0.9.2", "serde", "tracing", - "transpose", ] [[package]] name = "p3-maybe-rayon" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54afab3883d8a14676b492709d6c4e9fa535c36718b737db0817aacfaaaa11f6" dependencies = [ "rayon", ] [[package]] name = "p3-mds" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3895055d735ac96d010747b3aaabd4c2645b9fd80226960550318db2e25afb75" dependencies = [ - "itertools 0.14.0", "p3-dft", "p3-field", - "p3-matrix", "p3-symmetric", "p3-util", - "rand", + "rand 0.9.2", ] [[package]] name = "p3-merkle-tree" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60e20f61ea816e94f83ed7b8134a5e98d0cad7bd6dff226bc1da17a5143c63cb" dependencies = [ "itertools 0.14.0", "p3-commit", @@ -1209,15 +1196,17 @@ dependencies = [ "p3-maybe-rayon", "p3-symmetric", "p3-util", - "rand", + "rand 0.9.2", "serde", + "thiserror 2.0.18", "tracing", ] [[package]] name = "p3-monty-31" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9fe0be661891af1f703ceaf57334fcbd540804988984dc2b500dd99740e7c81" dependencies = [ "itertools 0.14.0", "num-bigint", @@ -1229,55 +1218,58 @@ dependencies = [ "p3-poseidon2", "p3-symmetric", "p3-util", - "rand", + "paste", + "rand 0.9.2", "serde", + "spin", "tracing", - "transpose", ] [[package]] name = "p3-poseidon" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "548af7ff569975882bc411f653aba7d89a6d85813ca58ef922fd0b1ecb6b5866" dependencies = [ "p3-field", "p3-mds", "p3-symmetric", - "rand", + "rand 0.9.2", ] [[package]] name = "p3-poseidon2" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c6fc2368447576283f8b3849a36095017f25addf06eab9e33b0ce7f96b0b99d" dependencies = [ - "gcd", "p3-field", "p3-mds", "p3-symmetric", - "rand", + "p3-util", + "rand 0.9.2", ] [[package]] name = "p3-poseidon2-air" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a80481b023f74c0f8ded5058dab8054174e8060d82d400da7b67cf7f2f0a87bc" dependencies = [ "p3-air", "p3-field", "p3-matrix", "p3-maybe-rayon", "p3-poseidon2", - "p3-util", - "rand", - "tikv-jemallocator", + "rand 0.9.2", "tracing", ] [[package]] name = "p3-symmetric" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a14456a42a7d9e65f13999706f1bca2832175935169b3a54286e18331cf1d82f" dependencies = [ "itertools 0.14.0", "p3-field", @@ -1286,10 +1278,12 @@ dependencies = [ [[package]] name = "p3-util" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "911154accf66034b0eec4452956c088f92a200b37a8225c1caed74cfbd38cc8d" dependencies = [ "serde", + "transpose", ] [[package]] @@ -1398,7 +1392,7 @@ version = "0.1.0" dependencies = [ "ff_ext", "p3", - "rand", + "rand 0.8.5", "serde", ] @@ -1455,7 +1449,16 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +dependencies = [ + "rand_core 0.9.5", ] [[package]] @@ -1465,7 +1468,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", "serde", ] @@ -1478,6 +1481,12 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" + [[package]] name = "rayon" version = "1.11.0" @@ -1609,6 +1618,12 @@ dependencies = [ "syn", ] +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "sec1" version = "0.7.3" @@ -1675,12 +1690,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - [[package]] name = "signature" version = "2.2.0" @@ -1688,7 +1697,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ "digest", - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -1721,14 +1730,23 @@ dependencies = [ "multilinear_extensions", "num", "p256", - "p3-field", - "rand", + "p3", + "rand 0.8.5", "rug", "serde", "snowbridge-amcl", "typenum", ] +[[package]] +name = "spin" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5fe4ccb98d9c292d56fec89a5e07da7fc4cf0dc11e156b41793132775d3e591" +dependencies = [ + "lock_api", +] + [[package]] name = "spki" version = "0.7.3" @@ -1775,11 +1793,11 @@ dependencies = [ "p3", "p3-goldilocks", "poseidon", - "rand", + "rand 0.8.5", "rayon", "serde", "sumcheck_macro", - "thiserror", + "thiserror 1.0.69", "tracing", "transcript", ] @@ -1794,7 +1812,7 @@ dependencies = [ "p3", "proc-macro2", "quote", - "rand", + "rand 0.8.5", "sumcheck", "syn", ] @@ -1816,7 +1834,16 @@ version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl 2.0.18", ] [[package]] @@ -1831,32 +1858,23 @@ dependencies = [ ] [[package]] -name = "thread_local" -version = "1.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "tikv-jemalloc-sys" -version = "0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7" +name = "thiserror-impl" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd3c60906412afa9c2b5b5a48ca6a5abe5736aec9eb48ad05037a677e52e4e2d" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" dependencies = [ - "cc", - "libc", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "tikv-jemallocator" -version = "0.6.0" +name = "thread_local" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cec5ff18518d81584f477e9bfdf957f5bb0979b0bac3af4ca30b5b3ae2d2865" +checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" dependencies = [ - "libc", - "tikv-jemalloc-sys", + "cfg-if", ] [[package]] @@ -1926,7 +1944,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee40835db14ddd1e3ba414292272eddde9dad04d3d4b65509656414d1c42592f" dependencies = [ "smallvec", - "thiserror", + "thiserror 1.0.69", "tracing", "tracing-subscriber", ] @@ -2111,7 +2129,7 @@ dependencies = [ "itertools 0.14.0", "multilinear_extensions", "p3", - "rand", + "rand 0.8.5", "rand_chacha", "rayon", "serde", @@ -2322,7 +2340,7 @@ dependencies = [ "ff_ext", "multilinear_extensions", "p3", - "rand", + "rand 0.8.5", "rayon", "tracing", ] diff --git a/Cargo.toml b/Cargo.toml index c9606ef..1f16215 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,31 +43,31 @@ either = { version = "1.15.*", features = ["serde"] } generic-array = { version = "1.1.0", features = ["alloc", "serde"] } itertools = "0.13" num = "0.4.3" -p3-air = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" } -p3-baby-bear = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" } -p3-challenger = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" } -p3-commit = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" } -p3-dft = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" } -p3-field = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" } -p3-fri = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" } -p3-goldilocks = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" } -p3-matrix = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" } -p3-maybe-rayon = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" } -p3-mds = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" } -p3-merkle-tree = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" } -p3-monty-31 = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" } -p3-poseidon = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" } -p3-poseidon2 = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" } -p3-poseidon2-air = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" } -p3-symmetric = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" } -p3-util = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" } +p3-air = { version = "=0.4.3", default-features = false } +p3-baby-bear = { version = "=0.4.3", default-features = false } +p3-challenger = { version = "=0.4.3", default-features = false } +p3-commit = { version = "=0.4.3", default-features = false } +p3-dft = { version = "=0.4.3", default-features = false } +p3-field = { version = "=0.4.3", default-features = false } +p3-fri = { version = "=0.4.3", default-features = false } +p3-goldilocks = { version = "=0.4.3", default-features = false } +p3-matrix = { version = "=0.4.3", default-features = false } +p3-maybe-rayon = { version = "=0.4.3", default-features = false } +p3-mds = { version = "=0.4.3", default-features = false } +p3-merkle-tree = { version = "=0.4.3", default-features = false } +p3-monty-31 = { version = "=0.4.3", default-features = false } +p3-poseidon = { version = "=0.4.3", default-features = false } +p3-poseidon2 = { version = "=0.4.3", default-features = false } +p3-poseidon2-air = { version = "=0.4.3", default-features = false } +p3-symmetric = { version = "=0.4.3", default-features = false } +p3-util = { version = "=0.4.3", default-features = false } rand = "0.8" rand_chacha = { version = "0.3", features = ["serde1"] } rand_core = "0.6" rayon = "1.10" serde = { version = "1.0", features = ["derive", "rc"] } serde_json = "1.0" -thiserror = "1" # do we need this? +thiserror = "1" # do we need this? tracing = { version = "0.1", features = ["attributes"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/clippy.toml b/clippy.toml index 21e1ea3..6ced945 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1,4 +1,19 @@ # TODO(Matthias): review and see which exception we can remove over time. # Eg removing syn is blocked by ark-ff-asm cutting a new release # (https://github.com/arkworks-rs/algebra/issues/813) amongst other things. -allowed-duplicate-crates = ["regex-automata", "regex-syntax"] +allowed-duplicate-crates = [ + "dashu-base", + "dashu-float", + "dashu-int", + "dashu-ratio", + "generic-array", + "itertools", + "thiserror", + "thiserror-impl", + "regex-automata", + "regex-syntax", + "rand", + "rand_chacha", + "rand_core", + "getrandom", +] diff --git a/crates/curves/Cargo.toml b/crates/curves/Cargo.toml index 67bd2e1..4e6059f 100644 --- a/crates/curves/Cargo.toml +++ b/crates/curves/Cargo.toml @@ -19,7 +19,7 @@ generic-array.workspace = true k256 = { version = "0.13.3", features = ["expose-field"] } num.workspace = true p256 = { version = "0.13.2", features = ["expose-field"] } -p3-field.workspace = true +p3.workspace = true serde = { workspace = true, features = ["derive"] } typenum = "1.17.0" @@ -31,7 +31,7 @@ rug = { version = "1.26.1", optional = true } [dev-dependencies] num = { version = "0.4.3", features = ["rand"] } -rand = "0.8.5" +rand.workspace = true [features] bigint-rug = ["rug"] diff --git a/crates/curves/src/params.rs b/crates/curves/src/params.rs index 469ddf3..e0f1cba 100644 --- a/crates/curves/src/params.rs +++ b/crates/curves/src/params.rs @@ -13,7 +13,7 @@ use typenum::{U2, U4, Unsigned}; use generic_array::{ArrayLength, GenericArray, sequence::GenericSequence}; use num::BigUint; -use p3_field::Field; +use p3::field::Field; use crate::{polynomial::Polynomial, utils::biguint_from_limbs}; @@ -49,7 +49,7 @@ pub trait FieldParameters: fn modulus_field_iter() -> impl Iterator { Self::MODULUS .iter() - .map(|x| F::from_canonical_u8(*x)) + .map(|x| F::from_u8(*x)) .take(Self::NB_LIMBS) } @@ -64,7 +64,7 @@ pub trait FieldParameters: fn to_limbs_field_vec, F: Field>(x: &BigUint) -> Vec { Self::to_limbs(x) .into_iter() - .map(|x| F::from_canonical_u8(x).into()) + .map(|x| F::from_u8(x).into()) .collect::>() } diff --git a/crates/curves/src/polynomial.rs b/crates/curves/src/polynomial.rs index 47ca939..c94cca4 100644 --- a/crates/curves/src/polynomial.rs +++ b/crates/curves/src/polynomial.rs @@ -5,7 +5,7 @@ use core::{ use std::slice::Iter; use itertools::Itertools; -use p3_field::{Field, FieldAlgebra, FieldExtensionAlgebra}; +use p3::field::{Algebra, Field}; /// A polynomial represented as a vector of coefficients. #[derive(Debug, Clone)] @@ -45,15 +45,16 @@ impl Polynomial { } /// Evaluates the polynomial at a given point. - pub fn eval>(&self, x: S) -> S + pub fn eval(&self, x: S) -> S where - T: FieldAlgebra, + S: Field + Algebra, + T: Field, { let powers = x.powers(); self.coefficients .iter() .zip(powers) - .map(|(c, x)| x * c.clone()) + .map(|(c, x)| x * *c) .sum() } @@ -197,62 +198,51 @@ impl + Neg + Clone> Sub for &Polynomial { } } -impl Mul for Polynomial { +impl Mul for Polynomial { type Output = Self; fn mul(self, other: Self) -> Self { let mut result = vec![T::ZERO; self.coefficients.len() + other.coefficients.len() - 1]; for (i, a) in self.coefficients.into_iter().enumerate() { for (j, b) in other.coefficients.iter().enumerate() { - result[i + j] = result[i + j].clone() + a.clone() * b.clone(); + result[i + j] += a * *b; } } Self::new(result) } } -impl Mul for &Polynomial { +impl Mul for &Polynomial { type Output = Polynomial; fn mul(self, other: Self) -> Polynomial { let mut result = vec![T::ZERO; self.coefficients.len() + other.coefficients.len() - 1]; for (i, a) in self.coefficients.iter().enumerate() { for (j, b) in other.coefficients.iter().enumerate() { - result[i + j] = result[i + j].clone() + a.clone() * b.clone(); + result[i + j] += *a * *b; } } Polynomial::new(result) } } -impl Mul for Polynomial { +impl Mul for Polynomial { type Output = Self; fn mul(self, other: T) -> Self { - Self::new( - self.coefficients - .into_iter() - .map(|x| x * other.clone()) - .collect(), - ) + Self::new(self.coefficients.into_iter().map(|x| x * other).collect()) } } -impl Mul for &Polynomial { +impl Mul for &Polynomial { type Output = Polynomial; fn mul(self, other: T) -> Polynomial { - Polynomial::new( - self.coefficients - .iter() - .cloned() - .map(|x| x * other.clone()) - .collect(), - ) + Polynomial::new(self.coefficients.iter().map(|x| *x * other).collect()) } } -impl PartialEq> for Polynomial { +impl PartialEq> for Polynomial { fn eq(&self, other: &Polynomial) -> bool { if self.coefficients.len() != other.coefficients.len() { let (shorter, longer) = if self.coefficients.len() < other.coefficients.len() { @@ -277,11 +267,7 @@ impl PartialEq> for Polynomial { impl Polynomial { pub fn as_field(self) -> Polynomial { Polynomial { - coefficients: self - .coefficients - .iter() - .map(|x| F::from_canonical_u8(*x)) - .collect(), + coefficients: self.coefficients.iter().map(|x| F::from_u8(*x)).collect(), } } } diff --git a/crates/ff_ext/src/babybear.rs b/crates/ff_ext/src/babybear.rs index 5f8fb89..dfd1a8b 100644 --- a/crates/ff_ext/src/babybear.rs +++ b/crates/ff_ext/src/babybear.rs @@ -5,7 +5,7 @@ pub mod impl_babybear { babybear::{BabyBear, Poseidon2BabyBear}, challenger::DuplexChallenger, field::{ - Field, FieldAlgebra, FieldExtensionAlgebra, PackedValue, PrimeField32, TwoAdicField, + Field, PrimeCharacteristicRing, PrimeField32, TwoAdicField, extension::{BinomialExtensionField, BinomiallyExtendable}, }, merkle_tree::MerkleTreeMmcs, @@ -76,13 +76,13 @@ pub mod impl_babybear { impl FieldFrom for BabyBear { fn from_v(v: u64) -> Self { - Self::from_canonical_u64(v) + Self::from_u64(v) } } impl FieldFrom for BabyBearExt4 { fn from_v(v: u64) -> Self { - Self::from_canonical_u64(v) + Self::from_u64(v) } } @@ -167,7 +167,7 @@ pub mod impl_babybear { fn try_from_uniform_bytes(bytes: [u8; 8]) -> Option { let value = u32::from_le_bytes(bytes[..4].try_into().unwrap()); let is_canonical = value < Self::ORDER_U32; - is_canonical.then(|| Self::from_canonical_u32(value)) + is_canonical.then(|| Self::from_u32(value)) } } @@ -183,7 +183,7 @@ pub mod impl_babybear { array[..chunk.len()].copy_from_slice(chunk); unsafe { std::ptr::read_unaligned(array.as_ptr() as *const u32) } }) - .map(Self::from_canonical_u32) + .map(Self::from_u32) .collect::>() } @@ -206,7 +206,7 @@ pub mod impl_babybear { type BaseField = BabyBear; fn to_canonical_u64_vec(&self) -> Vec { - self.as_base_slice() + self.as_bases() .iter() .map(|v: &Self::BaseField| v.as_canonical_u32() as u64) .collect() diff --git a/crates/ff_ext/src/goldilock.rs b/crates/ff_ext/src/goldilock.rs index 4031bc6..a9e7f5f 100644 --- a/crates/ff_ext/src/goldilock.rs +++ b/crates/ff_ext/src/goldilock.rs @@ -8,7 +8,7 @@ pub mod impl_goldilocks { use p3::{ challenger::DuplexChallenger, field::{ - Field, FieldAlgebra, FieldExtensionAlgebra, PackedValue, PrimeField64, TwoAdicField, + Field, PrimeCharacteristicRing, PrimeField64, TwoAdicField, extension::{BinomialExtensionField, BinomiallyExtendable}, }, goldilocks::{ @@ -27,13 +27,13 @@ pub mod impl_goldilocks { impl FieldFrom for Goldilocks { fn from_v(v: u64) -> Self { - Self::from_canonical_u64(v) + Self::from_u64(v) } } impl FieldFrom for GoldilocksExt2 { fn from_v(v: u64) -> Self { - Self::from_canonical_u64(v) + Self::from_u64(v) } } @@ -92,7 +92,7 @@ pub mod impl_goldilocks { .flatten() .chain(HL_GOLDILOCKS_8_INTERNAL_ROUND_CONSTANTS.iter()) .chain(HL_GOLDILOCKS_8_EXTERNAL_ROUND_CONSTANTS[1].iter().flatten()) - .map(|v| Self::from_canonical_u64(*v)) + .map(|v| Self::from_u64(*v)) .collect() } @@ -117,7 +117,7 @@ pub mod impl_goldilocks { fn try_from_uniform_bytes(bytes: [u8; 8]) -> Option { let value = u64::from_le_bytes(bytes); let is_canonical = value < Self::ORDER_U64; - is_canonical.then(|| Self::from_canonical_u64(value)) + is_canonical.then(|| Self::from_u64(value)) } } @@ -133,7 +133,7 @@ pub mod impl_goldilocks { array[..chunk.len()].copy_from_slice(chunk); unsafe { std::ptr::read_unaligned(array.as_ptr() as *const u64) } }) - .map(Self::from_canonical_u64) + .map(Self::from_u64) .collect::>() } @@ -154,7 +154,7 @@ pub mod impl_goldilocks { type BaseField = Goldilocks; fn to_canonical_u64_vec(&self) -> Vec { - self.as_base_slice() + self.as_bases() .iter() .map(|v: &Self::BaseField| v.as_canonical_u64()) .collect() diff --git a/crates/ff_ext/src/lib.rs b/crates/ff_ext/src/lib.rs index 6e3cfcb..e31f5e0 100644 --- a/crates/ff_ext/src/lib.rs +++ b/crates/ff_ext/src/lib.rs @@ -1,14 +1,12 @@ #![deny(clippy::cargo)] use p3::field::{ - ExtensionField as P3ExtensionField, Field as P3Field, FieldAlgebra, PrimeField, TwoAdicField, + BasedVectorSpace, ExtensionField as P3ExtensionField, Field as P3Field, + PrimeCharacteristicRing, PrimeField, TwoAdicField, }; use rand_core::RngCore; use serde::{Serialize, de::DeserializeOwned}; -use std::{ - array::from_fn, - iter::{self, repeat_with}, -}; +use std::{array::from_fn, iter::repeat_with}; mod babybear; mod wrapper; pub use babybear::impl_babybear::*; @@ -61,16 +59,15 @@ pub trait FromUniformBytes: Sized { macro_rules! impl_from_uniform_bytes_for_binomial_extension { ($base:ty, $degree:literal) => { impl FromUniformBytes for p3::field::extension::BinomialExtensionField<$base, $degree> { - type Bytes = [u8; <$base as FromUniformBytes>::Bytes::WIDTH * $degree]; + type Bytes = [u8; core::mem::size_of::<<$base as FromUniformBytes>::Bytes>() * $degree]; fn try_from_uniform_bytes(bytes: Self::Bytes) -> Option { - Some(p3::field::FieldExtensionAlgebra::from_base_slice( - &array_try_from_uniform_bytes::< - $base, - { <$base as FromUniformBytes>::Bytes::WIDTH }, - $degree, - >(&bytes)?, - )) + let coeffs = array_try_from_uniform_bytes::< + $base, + { core::mem::size_of::<<$base as FromUniformBytes>::Bytes>() }, + $degree, + >(&bytes)?; + p3::field::BasedVectorSpace::from_basis_coefficients_slice(&coeffs) } } }; @@ -126,23 +123,23 @@ pub trait ExtensionField: + DeserializeOwned; fn from_ref_base(base: &Self::BaseField) -> Self { - Self::from_base_iter( - iter::once(*base).chain(iter::repeat_n(Self::BaseField::ZERO, Self::DEGREE - 1)), - ) + let mut coeffs = vec![Self::BaseField::ZERO; Self::DEGREE]; + coeffs[0] = *base; + Self::from_bases(&coeffs) } fn from_bases(bases: &[Self::BaseField]) -> Self { - debug_assert_eq!(bases.len(), Self::D,); - Self::from_base_slice(bases) + debug_assert_eq!(bases.len(), Self::DEGREE); + BasedVectorSpace::from_basis_coefficients_slice(bases).expect("slice length matches degree") } fn as_bases(&self) -> &[Self::BaseField] { - self.as_base_slice() + self.as_basis_coefficients_slice() } /// Convert limbs into self fn from_limbs(limbs: &[Self::BaseField]) -> Self { - Self::from_bases(&limbs[0..Self::D]) + Self::from_bases(&limbs[..Self::DEGREE]) } /// Convert a field elements to a u64 vector diff --git a/crates/ff_ext/src/poseidon.rs b/crates/ff_ext/src/poseidon.rs index 35e69d4..886a175 100644 --- a/crates/ff_ext/src/poseidon.rs +++ b/crates/ff_ext/src/poseidon.rs @@ -9,12 +9,11 @@ use crate::{ExtensionField, SmallField}; pub trait FieldChallengerExt: FieldChallenger { fn observe_ext_slice>(&mut self, exts: &[E]) { - exts.iter() - .for_each(|ext| self.observe_slice(ext.as_base_slice())); + self.observe_algebra_slice(exts); } fn sample_ext_vec>(&mut self, n: usize) -> Vec { - (0..n).map(|_| self.sample_ext_element()).collect() + (0..n).map(|_| self.sample_algebra_element()).collect() } } @@ -39,7 +38,7 @@ pub(crate) fn new_array(input: [u64; N]) -> [F; N let mut output = [F::ZERO; N]; let mut i = 0; while i < N { - output[i] = F::from_canonical_u64(input[i]); + output[i] = F::from_u64(input[i]); i += 1; } output diff --git a/crates/mpcs/benches/comparison.rs b/crates/mpcs/benches/comparison.rs index ae5305b..5d96ab9 100644 --- a/crates/mpcs/benches/comparison.rs +++ b/crates/mpcs/benches/comparison.rs @@ -7,7 +7,9 @@ use mpcs::{ jagged_batch_verify, jagged_commit, }; use multilinear_extensions::{util::ceil_log2, virtual_poly::build_eq_x_r_vec_sequential}; -use p3::{babybear::BabyBear, field::FieldAlgebra, matrix::Matrix, maybe_rayon::prelude::*}; +use p3::{ + babybear::BabyBear, field::PrimeCharacteristicRing, matrix::Matrix, maybe_rayon::prelude::*, +}; use rand::{Rng, thread_rng}; use transcript::{BasicTranscript, Transcript}; use witness::{InstancePaddingStrategy, RowMajorMatrix as WitnessRowMajorMatrix}; @@ -23,7 +25,7 @@ const NUM_COLS: usize = 32; fn make_rmm(num_rows: usize, num_cols: usize) -> WitnessRowMajorMatrix { let values: Vec = (0..num_rows * num_cols) .into_par_iter() - .map(|i| F::from_canonical_u32(((i as u64 * 13 + 7) % (1 << 30)) as u32)) + .map(|i| F::from_u32(((i as u64 * 13 + 7) % (1 << 30)) as u32)) .collect(); WitnessRowMajorMatrix::new_by_values(values, num_cols, InstancePaddingStrategy::Default) } diff --git a/crates/mpcs/benches/jagged_pcs.rs b/crates/mpcs/benches/jagged_pcs.rs index 5f4fa5c..e0be0db 100644 --- a/crates/mpcs/benches/jagged_pcs.rs +++ b/crates/mpcs/benches/jagged_pcs.rs @@ -7,7 +7,9 @@ use mpcs::{ jagged_commit, }; use multilinear_extensions::{util::ceil_log2, virtual_poly::build_eq_x_r_vec_sequential}; -use p3::{babybear::BabyBear, field::FieldAlgebra, matrix::Matrix, maybe_rayon::prelude::*}; +use p3::{ + babybear::BabyBear, field::PrimeCharacteristicRing, matrix::Matrix, maybe_rayon::prelude::*, +}; use rand::{Rng, thread_rng}; use transcript::BasicTranscript; use witness::{InstancePaddingStrategy, RowMajorMatrix as WitnessRowMajorMatrix}; @@ -23,7 +25,7 @@ const NUM_COLS: usize = 32; fn make_rmm(num_rows: usize, num_cols: usize) -> WitnessRowMajorMatrix { let values: Vec = (0..num_rows * num_cols) .into_par_iter() - .map(|i| F::from_canonical_u32(((i as u64 * 13 + 7) % (1 << 30)) as u32)) + .map(|i| F::from_u32(((i as u64 * 13 + 7) % (1 << 30)) as u32)) .collect(); WitnessRowMajorMatrix::new_by_values(values, num_cols, InstancePaddingStrategy::Default) } diff --git a/crates/mpcs/src/basefold.rs b/crates/mpcs/src/basefold.rs index eaa4c7c..ce9f308 100644 --- a/crates/mpcs/src/basefold.rs +++ b/crates/mpcs/src/basefold.rs @@ -7,7 +7,10 @@ use crate::{ }; pub use encoding::{EncodingScheme, RSCode, RSCodeDefaultSpec}; use ff_ext::ExtensionField; -use p3::{commit::Mmcs, field::FieldAlgebra, matrix::dense::DenseMatrix, util::log2_strict_usize}; +use p3::{ + commit::Mmcs, field::PrimeCharacteristicRing, matrix::dense::DenseMatrix, + util::log2_strict_usize, +}; use query_phase::{batch_query_phase, batch_verifier_query_phase}; use structure::BasefoldProof; pub use structure::{BasefoldSpec, Digest}; @@ -184,9 +187,8 @@ where transcript: &mut impl Transcript, ) -> Result<(), Error> { write_digest_to_transcript(&comm.commit(), transcript); - transcript.append_field_element(&E::BaseField::from_canonical_u64( - comm.log2_max_codeword_size as u64, - )); + transcript + .append_field_element(&E::BaseField::from_u64(comm.log2_max_codeword_size as u64)); Ok(()) } diff --git a/crates/mpcs/src/basefold/commit_phase.rs b/crates/mpcs/src/basefold/commit_phase.rs index d77d365..4c67c02 100644 --- a/crates/mpcs/src/basefold/commit_phase.rs +++ b/crates/mpcs/src/basefold/commit_phase.rs @@ -1,3 +1,4 @@ +use p3::field::PrimeCharacteristicRing; use std::collections::HashSet; use super::{ @@ -18,7 +19,7 @@ use itertools::{Either, Itertools}; use multilinear_extensions::{Expression, virtual_polys::VirtualPolynomialsBuilder}; use p3::{ commit::{ExtensionMmcs, Mmcs}, - field::{Field, FieldAlgebra}, + field::Field, matrix::{ Matrix, dense::{DenseMatrix, RowMajorMatrix}, @@ -331,7 +332,7 @@ pub(crate) fn basefold_fri_round>( let level = log2_strict_usize(target_len) - 1; let folding_coeffs = >::prover_folding_coeffs_level(pp, level); - let inv_2 = E::BaseField::from_canonical_u64(2).inverse(); + let inv_2 = E::BaseField::from_u64(2).inverse(); debug_assert_eq!(folding_coeffs.len(), 1 << level); // take codewords match with target length then fold diff --git a/crates/mpcs/src/basefold/encoding/rs.rs b/crates/mpcs/src/basefold/encoding/rs.rs index d09caa6..ee5c187 100644 --- a/crates/mpcs/src/basefold/encoding/rs.rs +++ b/crates/mpcs/src/basefold/encoding/rs.rs @@ -1,3 +1,4 @@ +use p3::field::PrimeCharacteristicRing; use std::marker::PhantomData; use super::{EncodingProverParameters, EncodingScheme}; @@ -6,8 +7,8 @@ use ff_ext::{ExtensionField, FieldFrom}; use itertools::Itertools; use p3::{ dft::{Radix2Dit, Radix2DitParallel, TwoAdicSubgroupDft}, - field::{Field, FieldAlgebra, TwoAdicField, batch_multiplicative_inverse}, - matrix::{Matrix, bitrev::BitReversableMatrix, dense::DenseMatrix}, + field::{Field, TwoAdicField, batch_multiplicative_inverse}, + matrix::{Matrix, bitrev::BitReversibleMatrix, dense::DenseMatrix}, util::reverse_bits_len, }; use serde::{Deserialize, Serialize, de::DeserializeOwned}; @@ -337,7 +338,7 @@ mod tests { // test basefold.encode(raw_message.fold(1-r, r)) ?= codeword.fold(1-r, r) let mut prove_data = vec![]; - let r = E::from_canonical_u64(97); + let r = E::from_u64(97); basefold_fri_round::( &pp, &mut running_codeword_opt, diff --git a/crates/mpcs/src/basefold/query_phase.rs b/crates/mpcs/src/basefold/query_phase.rs index 8daf593..4f2be84 100644 --- a/crates/mpcs/src/basefold/query_phase.rs +++ b/crates/mpcs/src/basefold/query_phase.rs @@ -1,3 +1,4 @@ +use p3::field::PrimeCharacteristicRing; use std::slice; use crate::{ @@ -9,9 +10,9 @@ use ff_ext::ExtensionField; use itertools::{Itertools, izip}; use multilinear_extensions::virtual_poly::{build_eq_x_r_vec, eq_eval}; use p3::{ - commit::{ExtensionMmcs, Mmcs}, - field::{Field, FieldAlgebra, dot_product}, - fri::{BatchOpening, CommitPhaseProofStep}, + commit::{BatchOpening, BatchOpeningRef, ExtensionMmcs, Mmcs}, + field::{Field, dot_product}, + fri::CommitPhaseProofStep, matrix::{Dimensions, dense::RowMajorMatrix}, util::log2_strict_usize, }; @@ -62,7 +63,8 @@ where // in the original (non-row-bit-reversed) format. let idx_shift = log2_max_codeword_size - pcs_data.log2_max_codeword_size; let idx = idx >> idx_shift; - let (opened_values, opening_proof) = mmcs.open_batch(idx, &pcs_data.codeword); + let opened = mmcs.open_batch(idx, &pcs_data.codeword); + let (opened_values, opening_proof) = opened.unpack(); BatchOpening { opened_values, opening_proof, @@ -82,7 +84,8 @@ where // 2. since even and odd parts are concatenated in the same leaf, // the overall merkle tree height is effectively halved, // so we divide by 2. - let (mut values, opening_proof) = mmcs_ext.open_batch(leaf_idx, tree); + let opened = mmcs_ext.open_batch(leaf_idx, tree); + let (mut values, opening_proof) = opened.unpack(); let leafs = values.pop().unwrap(); debug_assert_eq!(leafs.len(), 2); let sibling_value = leafs[(!is_interpolate_to_right_index) as usize]; @@ -112,7 +115,7 @@ pub fn batch_verifier_query_phase>( ) where E::BaseField: Serialize + DeserializeOwned, { - let inv_2 = E::BaseField::from_canonical_u64(2).inverse(); + let inv_2 = E::BaseField::from_u64(2).inverse(); let final_message = &proof.final_message; let sumcheck_messages = proof.sumcheck_proof.as_ref().unwrap(); let encode_span = entered_span!("encode_final_codeword"); @@ -168,8 +171,10 @@ pub fn batch_verifier_query_phase>( &commit.commit(), &dimensions, reduced_index, - &input_proof.opened_values, - &input_proof.opening_proof, + BatchOpeningRef::new( + &input_proof.opened_values, + &input_proof.opening_proof, + ), ) .expect("verify mmcs opening proof failed"); @@ -239,8 +244,7 @@ pub fn batch_verifier_query_phase>( height: 1 << (log2_height - 1), }], leaf_idx, - slice::from_ref(&leafs), - proof, + BatchOpeningRef::new(slice::from_ref(&leafs), proof), ) .expect("verify failed"); @@ -277,7 +281,7 @@ pub fn batch_verifier_query_phase>( .iter() .zip(batch_coeffs_iter.by_ref().take(evals.len())) .map(|(eval, coeff)| { - *coeff * (*eval) * E::from_canonical_u64(1 << (max_num_var - num_var) as u64) + *coeff * (*eval) * E::from_u64(1 << (max_num_var - num_var) as u64) }) .sum::(); } diff --git a/crates/mpcs/src/basefold/structure.rs b/crates/mpcs/src/basefold/structure.rs index 0f94893..22ed588 100644 --- a/crates/mpcs/src/basefold/structure.rs +++ b/crates/mpcs/src/basefold/structure.rs @@ -7,8 +7,8 @@ use core::fmt::Debug; use ff_ext::{ExtensionField, PoseidonField}; use itertools::izip; use p3::{ - commit::{ExtensionMmcs, Mmcs}, - fri::{BatchOpening, CommitPhaseProofStep}, + commit::{BatchOpening, ExtensionMmcs, Mmcs}, + fri::CommitPhaseProofStep, matrix::{Matrix, dense::DenseMatrix}, }; use serde::{Deserialize, Serialize, Serializer, de::DeserializeOwned}; diff --git a/crates/mpcs/src/jagged/assist.rs b/crates/mpcs/src/jagged/assist.rs index 51c5e3c..d4afab5 100644 --- a/crates/mpcs/src/jagged/assist.rs +++ b/crates/mpcs/src/jagged/assist.rs @@ -288,7 +288,7 @@ mod tests { }; use ff_ext::{FromUniformBytes, GoldilocksExt2}; use multilinear_extensions::{util::ceil_log2, virtual_poly::build_eq_x_r_vec}; - use p3::field::FieldAlgebra; + use p3::field::PrimeCharacteristicRing; use rand::thread_rng; use std::marker::PhantomData; use sumcheck::structs::IOPVerifierState; diff --git a/crates/mpcs/src/jagged/evaluator.rs b/crates/mpcs/src/jagged/evaluator.rs index 5ff1246..05bbae3 100644 --- a/crates/mpcs/src/jagged/evaluator.rs +++ b/crates/mpcs/src/jagged/evaluator.rs @@ -305,7 +305,7 @@ pub fn evaluate_g(z1: &[E], z2: &[E], z3: &[E], z4: &[E]) -> mod tests { use ff_ext::{BabyBearExt4, FromUniformBytes}; use multilinear_extensions::virtual_poly::build_eq_x_r_vec; - use p3::field::FieldAlgebra; + use p3::field::PrimeCharacteristicRing; use rand::thread_rng; use super::*; diff --git a/crates/mpcs/src/jagged/mod.rs b/crates/mpcs/src/jagged/mod.rs index 3c1f9b9..aa12810 100644 --- a/crates/mpcs/src/jagged/mod.rs +++ b/crates/mpcs/src/jagged/mod.rs @@ -128,7 +128,7 @@ use multilinear_extensions::{ util::ceil_log2, virtual_poly::{VPAuxInfo, build_eq_x_r_vec}, }; -use p3::{field::FieldAlgebra, maybe_rayon::prelude::*}; +use p3::{field::PrimeCharacteristicRing, maybe_rayon::prelude::*}; use serde::{Serialize, Serializer, de::DeserializeOwned}; use std::sync::Arc; use transcript::Transcript; @@ -807,13 +807,10 @@ where transcript: &mut impl Transcript, ) -> Result<(), Error> { InnerPcs::write_commitment(&comm.inner, transcript)?; - transcript - .append_field_element(&E::BaseField::from_canonical_usize(comm.reshape_log_height)); - transcript.append_field_element(&E::BaseField::from_canonical_usize( - comm.cumulative_heights.len(), - )); + transcript.append_field_element(&E::BaseField::from_usize(comm.reshape_log_height)); + transcript.append_field_element(&E::BaseField::from_usize(comm.cumulative_heights.len())); for height in &comm.cumulative_heights { - transcript.append_field_element(&E::BaseField::from_canonical_usize(*height)); + transcript.append_field_element(&E::BaseField::from_usize(*height)); } Ok(()) } @@ -999,7 +996,9 @@ mod tests { }; use ff_ext::GoldilocksExt2; use multilinear_extensions::mle::MultilinearExtension; - use p3::{field::FieldAlgebra, goldilocks::Goldilocks, matrix::dense::RowMajorMatrix}; + use p3::{ + field::PrimeCharacteristicRing, goldilocks::Goldilocks, matrix::dense::RowMajorMatrix, + }; type F = Goldilocks; type E = GoldilocksExt2; @@ -1007,7 +1006,7 @@ mod tests { fn make_rmm(num_rows: usize, num_cols: usize) -> WitnessRowMajorMatrix { let values: Vec = (0..num_rows * num_cols) - .map(|i| F::from_canonical_u64(i as u64 + 1)) + .map(|i| F::from_u64(i as u64 + 1)) .collect(); WitnessRowMajorMatrix::new_by_inner_matrix( RowMajorMatrix::new(values, num_cols), diff --git a/crates/mpcs/src/jagged/sumcheck.rs b/crates/mpcs/src/jagged/sumcheck.rs index 6aa434e..3609f86 100644 --- a/crates/mpcs/src/jagged/sumcheck.rs +++ b/crates/mpcs/src/jagged/sumcheck.rs @@ -480,7 +480,7 @@ mod tests { use super::*; use ff_ext::{FromUniformBytes, GoldilocksExt2}; use multilinear_extensions::virtual_poly::{VPAuxInfo, build_eq_x_r_vec}; - use p3::{field::FieldAlgebra, goldilocks::Goldilocks}; + use p3::{field::PrimeCharacteristicRing, goldilocks::Goldilocks}; use rand::thread_rng; use std::marker::PhantomData; use sumcheck::structs::IOPVerifierState; @@ -501,7 +501,7 @@ mod tests { let num_giga_vars = 4; // ceil(log2(12)) = 4, 2^4 = 16 let q_evals: Vec = (0..total_evals) - .map(|i| F::from_canonical_u64(i as u64 + 1)) + .map(|i| F::from_u64(i as u64 + 1)) .collect(); let cumulative_heights: Vec = (0..=num_polys).map(|i| i * poly_height).collect(); @@ -562,7 +562,7 @@ mod tests { let num_giga_vars = 16; // 2^16 = 65536 let q_evals: Vec = (0..total_evals) - .map(|i| F::from_canonical_u64((i as u64 * 7 + 3) % (1 << 20))) + .map(|i| F::from_u64((i as u64 * 7 + 3) % (1 << 20))) .collect(); let cumulative_heights: Vec = (0..=num_polys).map(|i| i * poly_height).collect(); @@ -614,7 +614,7 @@ mod tests { let num_giga_vars = 25; let q_evals: Vec = (0..total_evals) - .map(|i| F::from_canonical_u64((i as u64 * 13 + 7) % (1 << 30))) + .map(|i| F::from_u64((i as u64 * 13 + 7) % (1 << 30))) .collect(); let cumulative_heights: Vec = (0..=num_polys).map(|i| i * poly_height).collect(); diff --git a/crates/mpcs/src/lib.rs b/crates/mpcs/src/lib.rs index 4b7cf2e..3c83b5a 100644 --- a/crates/mpcs/src/lib.rs +++ b/crates/mpcs/src/lib.rs @@ -308,7 +308,7 @@ pub mod test_util { use itertools::Itertools; #[cfg(test)] - use rand::{distributions::Standard, prelude::Distribution, rngs::OsRng}; + use rand::rngs::OsRng; #[cfg(test)] use transcript::BasicTranscript; @@ -356,7 +356,6 @@ pub mod test_util { num_vars_end: usize, ) where Pcs: PolynomialCommitmentScheme, - Standard: Distribution, { use multilinear_extensions::mle::ArcMultilinearExtension; @@ -409,7 +408,6 @@ pub mod test_util { ) where E: ExtensionField, Pcs: PolynomialCommitmentScheme, - Standard: Distribution, { use multilinear_extensions::mle::ArcMultilinearExtension; @@ -469,7 +467,6 @@ pub mod test_util { ) where E: ExtensionField, Pcs: PolynomialCommitmentScheme, - Standard: Distribution, { for num_vars in num_vars_start..num_vars_end { let (pp, vp) = setup_pcs::(num_vars); diff --git a/crates/mpcs/src/util.rs b/crates/mpcs/src/util.rs index 587df7b..cb6b265 100644 --- a/crates/mpcs/src/util.rs +++ b/crates/mpcs/src/util.rs @@ -4,14 +4,14 @@ use std::collections::VecDeque; use ff_ext::{ExtensionField, SmallField}; pub mod merkle_tree; -use p3::field::FieldAlgebra; +use p3::field::PrimeCharacteristicRing; pub fn base_to_usize(x: &E::BaseField) -> usize { x.to_canonical_u64() as usize } pub fn u32_to_field(x: u32) -> E::BaseField { - E::BaseField::from_canonical_u32(x) + E::BaseField::from_u32(x) } /// splits a vector into multiple slices, where each slice length @@ -103,17 +103,15 @@ pub(crate) fn codeword_fold_with_challenge( #[cfg(test)] pub mod test { + #[cfg(test)] + use crate::util::{base_to_usize, u32_to_field}; use ff_ext::FromUniformBytes; + use p3::field::PrimeCharacteristicRing; use rand::{ CryptoRng, RngCore, SeedableRng, rngs::{OsRng, StdRng}, }; use std::{array, iter, ops::Range}; - #[cfg(test)] - use { - crate::util::{base_to_usize, u32_to_field}, - p3::field::FieldAlgebra, - }; #[cfg(test)] type E = ff_ext::GoldilocksExt2; @@ -142,10 +140,7 @@ pub mod test { #[test] pub fn test_field_transform() { - assert_eq!( - F::from_canonical_u64(2) * F::from_canonical_u64(3), - F::from_canonical_u64(6) - ); + assert_eq!(F::from_u64(2) * F::from_u64(3), F::from_u64(6)); assert_eq!(base_to_usize::(&u32_to_field::(1u32)), 1); assert_eq!(base_to_usize::(&u32_to_field::(10u32)), 10); } diff --git a/crates/mpcs/src/util/arithmetic.rs b/crates/mpcs/src/util/arithmetic.rs index 1351899..bd59ae0 100644 --- a/crates/mpcs/src/util/arithmetic.rs +++ b/crates/mpcs/src/util/arithmetic.rs @@ -1,14 +1,13 @@ use ff_ext::ExtensionField; use multilinear_extensions::mle::FieldType; use num_integer::Integer; -use p3::field::Field; +use p3::field::{Field, PrimeCharacteristicRing}; use std::{borrow::Borrow, iter}; mod hypercube; pub use hypercube::{ interpolate_field_type_over_boolean_hypercube, interpolate_over_boolean_hypercube, }; -use p3::field::FieldAlgebra; use itertools::Itertools; @@ -157,7 +156,7 @@ pub fn degree_2_eval(poly: &[F], point: F) -> F { pub fn base_from_raw_bytes(bytes: &[u8]) -> E::BaseField { let mut res = E::BaseField::ZERO; bytes.iter().for_each(|b| { - res += E::BaseField::from_canonical_u8(*b); + res += E::BaseField::from_u8(*b); }); res } diff --git a/crates/multilinear_extensions/src/expression.rs b/crates/multilinear_extensions/src/expression.rs index 05eef4d..0305641 100644 --- a/crates/multilinear_extensions/src/expression.rs +++ b/crates/multilinear_extensions/src/expression.rs @@ -9,7 +9,7 @@ use crate::{ }; use ff_ext::{ExtensionField, SmallField}; use itertools::{Either, Itertools, chain, izip}; -use p3::{field::FieldAlgebra, maybe_rayon::prelude::*}; +use p3::{field::PrimeCharacteristicRing, maybe_rayon::prelude::*}; use serde::de::DeserializeOwned; use std::{ cmp::max, @@ -1012,8 +1012,8 @@ impl Default for Expression { } } -impl FieldAlgebra for Expression { - type F = E::BaseField; +impl PrimeCharacteristicRing for Expression { + type PrimeSubfield = ::PrimeSubfield; const ZERO: Self = Expression::Constant(Either::Left(E::BaseField::ZERO)); @@ -1023,36 +1023,8 @@ impl FieldAlgebra for Expression { const NEG_ONE: Self = Expression::Constant(Either::Left(E::BaseField::NEG_ONE)); - fn from_f(f: Self::F) -> Self { - Expression::Constant(Either::Left(f)) - } - - fn from_canonical_u8(n: u8) -> Self { - Expression::Constant(Either::Left(E::BaseField::from_canonical_u8(n))) - } - - fn from_canonical_u16(n: u16) -> Self { - Expression::Constant(Either::Left(E::BaseField::from_canonical_u16(n))) - } - - fn from_canonical_u32(n: u32) -> Self { - Expression::Constant(Either::Left(E::BaseField::from_canonical_u32(n))) - } - - fn from_canonical_u64(n: u64) -> Self { - Expression::Constant(Either::Left(E::BaseField::from_canonical_u64(n))) - } - - fn from_canonical_usize(n: usize) -> Self { - Expression::Constant(Either::Left(E::BaseField::from_canonical_usize(n))) - } - - fn from_wrapped_u32(n: u32) -> Self { - Expression::Constant(Either::Left(E::BaseField::from_wrapped_u32(n))) - } - - fn from_wrapped_u64(n: u64) -> Self { - Expression::Constant(Either::Left(E::BaseField::from_wrapped_u64(n))) + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + Expression::Constant(Either::Left(E::BaseField::from_prime_subfield(f))) } } @@ -1364,7 +1336,7 @@ macro_rules! impl_expr_from_unsigned { $( impl> From<$t> for Expression { fn from(value: $t) -> Self { - Expression::Constant(Either::Left(F::from_canonical_u64(value as u64))) + Expression::Constant(Either::Left(F::from_u64(value as u64))) } } )* @@ -1379,7 +1351,7 @@ macro_rules! impl_from_signed { impl> From<$t> for Expression { fn from(value: $t) -> Self { let reduced = (value as i128).rem_euclid(F::MODULUS_U64 as i128) as u64; - Expression::Constant(Either::Left(F::from_canonical_u64(reduced))) + Expression::Constant(Either::Left(F::from_u64(reduced))) } } )* @@ -1536,7 +1508,7 @@ mod tests { use crate::{expression::WitIn, mle::IntoMLE, wit_infer_by_expr}; use either::Either; use ff_ext::{FieldInto, GoldilocksExt2}; - use p3::field::FieldAlgebra; + use p3::field::PrimeCharacteristicRing; #[test] fn test_expression_arithmetics() { @@ -1705,9 +1677,9 @@ mod tests { 0, &[], &[ - vec![B::from_canonical_u64(1)].into_mle().into(), - vec![B::from_canonical_u64(2)].into_mle().into(), - vec![B::from_canonical_u64(3)].into_mle().into(), + vec![B::from_u64(1)].into_mle().into(), + vec![B::from_u64(2)].into_mle().into(), + vec![B::from_u64(3)].into_mle().into(), ], &[], &[], diff --git a/crates/multilinear_extensions/src/expression/monomial.rs b/crates/multilinear_extensions/src/expression/monomial.rs index 32c3092..32ebea1 100644 --- a/crates/multilinear_extensions/src/expression/monomial.rs +++ b/crates/multilinear_extensions/src/expression/monomial.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use super::Expression; use Expression::*; -use p3::field::FieldAlgebra; +use p3::field::PrimeCharacteristicRing; use std::{collections::BTreeMap, fmt::Display, iter::Sum}; impl Expression { @@ -118,7 +118,7 @@ mod tests { use super::*; use either::Either; use ff_ext::{FieldInto, FromUniformBytes, GoldilocksExt2 as E}; - use p3::{field::FieldAlgebra, goldilocks::Goldilocks as F}; + use p3::goldilocks::Goldilocks as F; use rand::thread_rng; #[test] @@ -140,7 +140,7 @@ mod tests { let n1 = || Constant(Either::Left(103u64.into_f())); let n2 = || Constant(Either::Left(101u64.into_f())); - let m = || Constant(Either::Left(-F::from_canonical_u64(599))); + let m = || Constant(Either::Left(-F::from_u64(599))); let r = || Challenge(0, 1, E::ONE, E::ZERO); let test_exprs: &[Expression] = &[ diff --git a/crates/multilinear_extensions/src/expression/utils.rs b/crates/multilinear_extensions/src/expression/utils.rs index 04a8e83..be8a7de 100644 --- a/crates/multilinear_extensions/src/expression/utils.rs +++ b/crates/multilinear_extensions/src/expression/utils.rs @@ -891,7 +891,7 @@ mod tests { }; use either::Either; use ff_ext::{BabyBearExt4, ExtensionField}; - use p3::{babybear::BabyBear, field::FieldAlgebra}; + use p3::{babybear::BabyBear, field::PrimeCharacteristicRing}; use std::ops::Neg; type E = BabyBearExt4; @@ -934,9 +934,9 @@ mod tests { fn test_normal_expr_compression_to_dag_helper() { let a = Expression::::WitIn(0); let b = Expression::::WitIn(1); - let s2 = Expression::::Constant(Either::Left(B::from_canonical_u32(2))); - let s3 = Expression::::Constant(Either::Left(B::from_canonical_u32(3))); - let s4 = Expression::::Constant(Either::Left(B::from_canonical_u32(4))); + let s2 = Expression::::Constant(Either::Left(B::from_u32(2))); + let s3 = Expression::::Constant(Either::Left(B::from_u32(3))); + let s4 = Expression::::Constant(Either::Left(B::from_u32(4))); let e: Expression = s3.expr() * (s2.expr() * a.expr() * b.expr() + s4.expr()); let ( @@ -996,9 +996,8 @@ mod tests { let w1 = Expression::::WitIn(1); let c0 = Expression::::Challenge(0, 1, E::ONE, E::ZERO); let c1 = Expression::::Challenge(1, 1, E::ONE, E::ZERO); - let constant_2 = Expression::::Constant(Either::Left(B::from_canonical_u32(2))); - let constant_negative_1 = - Expression::::Constant(Either::Left(B::from_canonical_u32(1).neg())); + let constant_2 = Expression::::Constant(Either::Left(B::from_u32(2))); + let constant_negative_1 = Expression::::Constant(Either::Left(B::from_u32(1).neg())); let e: Expression = w1.expr() * (c1.expr() diff --git a/crates/multilinear_extensions/src/mle.rs b/crates/multilinear_extensions/src/mle.rs index 773fc10..afeda01 100644 --- a/crates/multilinear_extensions/src/mle.rs +++ b/crates/multilinear_extensions/src/mle.rs @@ -12,7 +12,7 @@ use ff_ext::{ExtensionField, FromUniformBytes}; #[cfg(not(feature = "parallel"))] use itertools::Itertools; use p3::{ - field::{Field, FieldAlgebra}, + field::{Field, PrimeCharacteristicRing}, maybe_rayon::prelude::*, }; use rand::Rng; @@ -250,7 +250,7 @@ impl<'a, E: ExtensionField> PartialEq for FieldType<'a, E> { (FieldType::Base(a), FieldType::Ext(b)) | (FieldType::Ext(b), FieldType::Base(a)) => a .par_iter() .zip_eq(b.par_iter()) - .all(|(a, b)| E::from_base(*a) == *b), + .all(|(a, b)| E::from_ref_base(a) == *b), _ => self.is_zero() && other.is_zero(), } } @@ -685,7 +685,8 @@ impl<'a, E: ExtensionField> MultilinearExtension<'a, E> { #[inline(always)] fn eval_pair_base_tail(lo: E::BaseField, point: E) -> E { - E::from_base(lo) + (E::ZERO - E::from_base(lo)) * point + let lo = E::from_ref_base(&lo); + lo + (E::ZERO - lo) * point } #[inline(always)] @@ -1244,13 +1245,13 @@ impl<'a, E: ExtensionField> MultilinearExtension<'a, E> { slice .iter() .enumerate() - .map(|(i, v)| E::BaseField::from_canonical_u32(i as u32 + 1) + *v) + .map(|(i, v)| E::BaseField::from_u32(i as u32 + 1) + *v) .product::(), ), FieldType::Ext(slice) => slice .iter() .enumerate() - .map(|(i, v)| E::from_canonical_u32(i as u32 + 1) + *v) + .map(|(i, v)| E::from_u32(i as u32 + 1) + *v) .product::(), _ => unreachable!(), } diff --git a/crates/multilinear_extensions/src/test.rs b/crates/multilinear_extensions/src/test.rs index f3559b0..14d2b35 100644 --- a/crates/multilinear_extensions/src/test.rs +++ b/crates/multilinear_extensions/src/test.rs @@ -1,6 +1,6 @@ use ff_ext::{ExtensionField, FromUniformBytes}; use p3::{ - field::{FieldAlgebra, extension::BinomialExtensionField}, + field::{PrimeCharacteristicRing, extension::BinomialExtensionField}, goldilocks::Goldilocks, }; use rand::thread_rng; @@ -28,17 +28,17 @@ fn test_eq_xr() { #[test] fn test_compact_fix_variables_matches_zero_padded() { let eval = vec![ - E::from_canonical_u32(3), - E::from_canonical_u32(5), - E::from_canonical_u32(7), - E::from_canonical_u32(11), - E::from_canonical_u32(13), + E::from_u32(3), + E::from_u32(5), + E::from_u32(7), + E::from_u32(11), + E::from_u32(13), ]; let compact = MultilinearExtension::from_evaluations_ext_vec_compact(3, eval.clone()); let mut padded = eval; padded.resize(1 << 3, E::ZERO); let padded = MultilinearExtension::from_evaluations_ext_vec(3, padded); - let point = [E::from_canonical_u32(9)]; + let point = [E::from_u32(9)]; let compact_fixed = compact.fix_variables(&point); let padded_fixed = padded.fix_variables(&point); @@ -56,8 +56,8 @@ fn test_compact_fix_variables_matches_zero_padded() { ); assert_eq!(compact_fixed.num_vars(), padded_fixed.num_vars()); - let r0 = E::from_canonical_u32(4); - let r1 = E::from_canonical_u32(6); + let r0 = E::from_u32(4); + let r1 = E::from_u32(6); let compact_fixed_2 = compact.fix_two_variables(r0, r1); let padded_fixed_2 = padded.fix_two_variables(r0, r1); let compact_fixed_2_eval = match compact_fixed_2.evaluations() { diff --git a/crates/multilinear_extensions/src/virtual_polys.rs b/crates/multilinear_extensions/src/virtual_polys.rs index 87e1da0..e0a4524 100644 --- a/crates/multilinear_extensions/src/virtual_polys.rs +++ b/crates/multilinear_extensions/src/virtual_polys.rs @@ -393,7 +393,7 @@ impl<'a, E: ExtensionField> VirtualPolynomials<'a, E> { let scalar = E::random(&mut *rng); monimial_term.push(Term { scalar, product }); let scale = if scale_suffix_missing_vars { - E::from_canonical_u64(1 << (max_num_variables - nv)) + E::from_u64(1 << (max_num_variables - nv)) } else { E::ONE }; diff --git a/crates/p3/Cargo.toml b/crates/p3/Cargo.toml index aa8e62a..cdbb363 100644 --- a/crates/p3/Cargo.toml +++ b/crates/p3/Cargo.toml @@ -30,10 +30,5 @@ p3-symmetric.workspace = true p3-util.workspace = true [features] -nightly-features = [ - "p3-baby-bear/nightly-features", - "p3-dft/nightly-features", - "p3-goldilocks/nightly-features", - "p3-poseidon2/nightly-features", -] +nightly-features = [] parallel = ["p3-maybe-rayon/parallel"] diff --git a/crates/sumcheck/benches/ceno_batched_main.rs b/crates/sumcheck/benches/ceno_batched_main.rs index 13119e3..ac1105c 100644 --- a/crates/sumcheck/benches/ceno_batched_main.rs +++ b/crates/sumcheck/benches/ceno_batched_main.rs @@ -9,7 +9,7 @@ use multilinear_extensions::{ util::max_usable_threads, virtual_polys::{VirtualPolynomials, VirtualPolynomialsBuilder}, }; -use p3::field::FieldAlgebra; +use p3::field::PrimeCharacteristicRing; use rand::{SeedableRng, rngs::StdRng}; use sumcheck::structs::{IOPProverState, SumcheckProverMode}; use transcript::BasicTranscript as Transcript; @@ -214,7 +214,7 @@ fn build_case<'a>(scale: &str, max_vars_override: Option) -> CenoBatchedM let product = (0..degree) .map(|offset| mle_start + ((term_idx * 3 + offset * 5) % shape.num_mles)) .collect_vec(); - let scalar = E::from_canonical_u64(((chip_idx + 1) * 17 + term_idx + 1) as u64); + let scalar = E::from_u64(((chip_idx + 1) * 17 + term_idx + 1) as u64); terms.push(TermShape { scalar, product }); } } diff --git a/crates/sumcheck/benches/devirgo_sumcheck.rs b/crates/sumcheck/benches/devirgo_sumcheck.rs index 1929c83..ea646d2 100644 --- a/crates/sumcheck/benches/devirgo_sumcheck.rs +++ b/crates/sumcheck/benches/devirgo_sumcheck.rs @@ -7,7 +7,7 @@ use criterion::*; use either::Either; use ff_ext::{ExtensionField, GoldilocksExt2}; use itertools::Itertools; -use p3::field::FieldAlgebra; +use p3::field::PrimeCharacteristicRing; use rand::{Rng, thread_rng}; use sumcheck::{ frontload, diff --git a/crates/sumcheck/benches/memory_usage.rs b/crates/sumcheck/benches/memory_usage.rs index e24199f..07cb5b2 100644 --- a/crates/sumcheck/benches/memory_usage.rs +++ b/crates/sumcheck/benches/memory_usage.rs @@ -13,7 +13,7 @@ use multilinear_extensions::{ mle::MultilinearExtension, monomial::Term, util::max_usable_threads, virtual_polys::VirtualPolynomials, }; -use p3::field::FieldAlgebra; +use p3::field::PrimeCharacteristicRing; use rand::thread_rng; use sumcheck::structs::{IOPProverState, SumcheckProverMode}; use transcript::BasicTranscript as Transcript; diff --git a/crates/sumcheck/src/extrapolate.rs b/crates/sumcheck/src/extrapolate.rs index d2b6248..fb8f7c6 100644 --- a/crates/sumcheck/src/extrapolate.rs +++ b/crates/sumcheck/src/extrapolate.rs @@ -43,7 +43,7 @@ impl ExtrapolationTable { for d in min_degree..=max_degree { let mut degree_weights = Vec::new(); - let xs: Vec = (0..=d as u64).map(E::from_canonical_u64).collect_vec(); + let xs: Vec = (0..=d as u64).map(E::from_u64).collect_vec(); let mut bary_weights = Vec::new(); // Compute barycentric weights w_j = 1 / prod_{i != j} (x_j - x_i) @@ -58,7 +58,7 @@ impl ExtrapolationTable { } for z_idx in d + 1..=max_degree { - let z = E::from_canonical_u64(z_idx as u64); + let z = E::from_u64(z_idx as u64); let mut den = E::ZERO; let mut tmp: Vec = Vec::with_capacity(d + 1); @@ -70,7 +70,7 @@ impl ExtrapolationTable { // Normalize for t in tmp.iter_mut() { - *t = *t / den; + *t /= den; } degree_weights.push(tmp); @@ -83,7 +83,7 @@ impl ExtrapolationTable { } } -pub struct ExtrapolationCache { +pub struct ExtrapolationCache { _marker: PhantomData, } diff --git a/crates/sumcheck/src/frontload.rs b/crates/sumcheck/src/frontload.rs index 8515fec..b47664a 100644 --- a/crates/sumcheck/src/frontload.rs +++ b/crates/sumcheck/src/frontload.rs @@ -8,7 +8,7 @@ use multilinear_extensions::{ virtual_poly::{MonomialTerms, VPAuxInfo, VirtualPolynomial}, virtual_polys::{PolyMeta, VirtualPolynomials}, }; -use p3::field::FieldAlgebra; +use p3::field::PrimeCharacteristicRing; use rayon::prelude::*; use transcript::{Challenge, Transcript}; @@ -577,7 +577,7 @@ impl<'a, E: ExtensionField> WorkingState<'a, E> { .product::(); let degree = metadata.degree; let evals = (0..=degree).map(|eval_idx| { - let z = E::from_canonical_u64(eval_idx as u64); + let z = E::from_u64(eval_idx as u64); product * (0..degree).map(|_| z).product::() }); self.add_evaluations(acc, degree, scalar_to_ext(&term.scalar), evals); @@ -719,7 +719,7 @@ impl<'a, E: ExtensionField> WorkingState<'a, E> { let scalar = scalar_to_ext(&term.scalar); for_each_active_lane(lane_count, required_ones_mask, |lane| { for (z_idx, eval) in evaluations.iter_mut().enumerate() { - let z = E::from_canonical_u64(z_idx as u64); + let z = E::from_u64(z_idx as u64); let product = term .product .iter() @@ -1002,7 +1002,7 @@ fn term_round_evaluations_across_workers<'a, E: ExtensionField>( for_each_active_lane(lane_count, required_ones_mask, |lane| { for (z_idx, eval) in evaluations.iter_mut().enumerate() { - let z = E::from_canonical_u64(z_idx as u64); + let z = E::from_u64(z_idx as u64); let mut term_eval = E::ZERO; for group_key in layout.future_group_keys(workers, round) { let product = term diff --git a/crates/sumcheck/src/prover.rs b/crates/sumcheck/src/prover.rs index d75e3dc..0a078ab 100644 --- a/crates/sumcheck/src/prover.rs +++ b/crates/sumcheck/src/prover.rs @@ -28,7 +28,7 @@ use crate::{ merge_sumcheck_prover_state, }, }; -use p3::field::FieldAlgebra; +use p3::field::PrimeCharacteristicRing; struct Phase1Workers<'a, E: ExtensionField> { workers_states: Vec>, @@ -708,7 +708,7 @@ impl<'a, E: ExtensionField> IOPProverState<'a, E> { // This amortises the r0 multiplications across all x values. let evals_len = f[prod[0]].evaluations().len(); let x_felts: Vec = (0..=degree) - .map(|x| E::BaseField::from_canonical_u32(x as u32)) + .map(|x| E::BaseField::from_u32(x as u32)) .collect(); let mut endpoints = vec![(E::ZERO, E::ZERO); degree]; let quad_len = evals_len / 4 * 4; @@ -747,7 +747,7 @@ impl<'a, E: ExtensionField> IOPProverState<'a, E> { // then evaluate for all x. let evals_len = f[prod[0]].evaluations().len(); let x_felts: Vec = (0..=degree) - .map(|x| E::BaseField::from_canonical_u32(x as u32)) + .map(|x| E::BaseField::from_u32(x as u32)) .collect(); let mut endpoints = vec![(E::ZERO, E::ZERO); degree]; let pair_len = largest_even_below(evals_len); diff --git a/crates/sumcheck/src/test.rs b/crates/sumcheck/src/test.rs index e7d3ffa..27cb87e 100644 --- a/crates/sumcheck/src/test.rs +++ b/crates/sumcheck/src/test.rs @@ -13,7 +13,7 @@ use multilinear_extensions::{ virtual_poly::{VPAuxInfo, VirtualPolynomial}, virtual_polys::VirtualPolynomials, }; -use p3::field::FieldAlgebra; +use p3::field::PrimeCharacteristicRing; use rand::{Rng, SeedableRng, rngs::StdRng, thread_rng}; use std::sync::Arc; use transcript::{BasicTranscript, Transcript}; @@ -573,11 +573,11 @@ fn test_runtime_prover_modes_are_compatible_helper() { #[test] fn test_compact_mle_matches_zero_padded_sumcheck() { let eval = vec![ - GoldilocksExt2::from_canonical_u32(2), - GoldilocksExt2::from_canonical_u32(3), - GoldilocksExt2::from_canonical_u32(5), - GoldilocksExt2::from_canonical_u32(7), - GoldilocksExt2::from_canonical_u32(11), + GoldilocksExt2::from_u32(2), + GoldilocksExt2::from_u32(3), + GoldilocksExt2::from_u32(5), + GoldilocksExt2::from_u32(7), + GoldilocksExt2::from_u32(11), ]; let compact = MultilinearExtension::from_evaluations_ext_vec_compact(3, eval.clone()); let mut padded_eval = eval; @@ -753,7 +753,7 @@ fn test_extrapolation() { let mut prng = rand::thread_rng(); let poly = DensePolynomial::rand_coeffs(degree, &mut prng); let evals = (0..=degree) - .map(|i| poly.evaluate(&GoldilocksExt2::from_canonical_u64(i as u64))) + .map(|i| poly.evaluate(&GoldilocksExt2::from_u64(i as u64))) .collect::>(); let query = GoldilocksExt2::random(&mut prng); assert_eq!( diff --git a/crates/sumcheck/src/util.rs b/crates/sumcheck/src/util.rs index 955bdab..4a3e0e1 100644 --- a/crates/sumcheck/src/util.rs +++ b/crates/sumcheck/src/util.rs @@ -76,16 +76,16 @@ fn extrapolate_uni_poly_deg_1(p0: F, p1: F, eval_at: F) -> F { } fn extrapolate_uni_poly_deg_2(p0: F, p1: F, p2: F, eval_at: F) -> F { - let x0 = F::from_canonical_u64(0); - let x1 = F::from_canonical_u64(1); - let x2 = F::from_canonical_u64(2); + let x0 = F::from_u64(0); + let x1 = F::from_u64(1); + let x2 = F::from_u64(2); // w0 = 1 / ((0−1)(0−2)) = 1/2 // w1 = 1 / ((1−0)(1−2)) = -1 // w2 = 1 / ((2−0)(2−1)) = 1/2 - let w0 = F::from_canonical_u64(1).div(F::from_canonical_u64(2)); + let w0 = F::from_u64(1).div(F::from_u64(2)); let w1 = -F::ONE; - let w2 = F::from_canonical_u64(1).div(F::from_canonical_u64(2)); + let w2 = F::from_u64(1).div(F::from_u64(2)); let d0 = eval_at - x0; let d1 = eval_at - x1; @@ -105,19 +105,19 @@ fn extrapolate_uni_poly_deg_2(p0: F, p1: F, p2: F, eval_at: F) -> F { } fn extrapolate_uni_poly_deg_3(p0: F, p1: F, p2: F, p3: F, eval_at: F) -> F { - let x0 = F::from_canonical_u64(0); - let x1 = F::from_canonical_u64(1); - let x2 = F::from_canonical_u64(2); - let x3 = F::from_canonical_u64(3); + let x0 = F::from_u64(0); + let x1 = F::from_u64(1); + let x2 = F::from_u64(2); + let x3 = F::from_u64(3); // w0 = 1 / ((0−1)(0−2)(0−3)) = -1/6 // w1 = 1 / ((1−0)(1−2)(1−3)) = 1/2 // w2 = 1 / ((2−0)(2−1)(2−3)) = -1/2 // w3 = 1 / ((3−0)(3−1)(3−2)) = 1/6 - let w0 = -F::from_canonical_u64(1).div(F::from_canonical_u64(6)); - let w1 = F::from_canonical_u64(1).div(F::from_canonical_u64(2)); - let w2 = -F::from_canonical_u64(1).div(F::from_canonical_u64(2)); - let w3 = F::from_canonical_u64(1).div(F::from_canonical_u64(6)); + let w0 = -F::from_u64(1).div(F::from_u64(6)); + let w1 = F::from_u64(1).div(F::from_u64(2)); + let w2 = -F::from_u64(1).div(F::from_u64(2)); + let w3 = F::from_u64(1).div(F::from_u64(6)); let d0 = eval_at - x0; let d1 = eval_at - x1; @@ -140,22 +140,22 @@ fn extrapolate_uni_poly_deg_3(p0: F, p1: F, p2: F, p3: F, eval_at: F) } fn extrapolate_uni_poly_deg_4(p0: F, p1: F, p2: F, p3: F, p4: F, eval_at: F) -> F { - let x0 = F::from_canonical_u64(0); - let x1 = F::from_canonical_u64(1); - let x2 = F::from_canonical_u64(2); - let x3 = F::from_canonical_u64(3); - let x4 = F::from_canonical_u64(4); + let x0 = F::from_u64(0); + let x1 = F::from_u64(1); + let x2 = F::from_u64(2); + let x3 = F::from_u64(3); + let x4 = F::from_u64(4); // w0 = 1 / ((0−1)(0−2)(0−3)(0−4)) = 1/24 // w1 = 1 / ((1−0)(1−2)(1−3)(1−4)) = -1/6 // w2 = 1 / ((2−0)(2−1)(2−3)(2−4)) = 1/4 // w3 = 1 / ((3−0)(3−1)(3−2)(3−4)) = -1/6 // w4 = 1 / ((4−0)(4−1)(4−2)(4−3)) = 1/24 - let w0 = F::from_canonical_u64(1).div(F::from_canonical_u64(24)); - let w1 = -F::from_canonical_u64(1).div(F::from_canonical_u64(6)); - let w2 = F::from_canonical_u64(1).div(F::from_canonical_u64(4)); - let w3 = -F::from_canonical_u64(1).div(F::from_canonical_u64(6)); - let w4 = F::from_canonical_u64(1).div(F::from_canonical_u64(24)); + let w0 = F::from_u64(1).div(F::from_u64(24)); + let w1 = -F::from_u64(1).div(F::from_u64(6)); + let w2 = F::from_u64(1).div(F::from_u64(4)); + let w3 = -F::from_u64(1).div(F::from_u64(6)); + let w4 = F::from_u64(1).div(F::from_u64(24)); let d0 = eval_at - x0; let d1 = eval_at - x1; @@ -445,13 +445,13 @@ impl Mul for AdditiveVec { mod tests { use super::*; use ff_ext::GoldilocksExt2; - use p3::field::FieldAlgebra; + use p3::field::PrimeCharacteristicRing; #[test] fn test_extrapolate_from_table() { type E = GoldilocksExt2; fn f(x: u64) -> E { - E::from_canonical_u64(2u64) * E::from_canonical_u64(x) + E::from_canonical_u64(3u64) + E::from_u64(2u64) * E::from_u64(x) + E::from_u64(3u64) } // Test a known linear polynomial: f(x) = 2x + 3 diff --git a/crates/sumcheck_macro/examples/expand.rs b/crates/sumcheck_macro/examples/expand.rs index cd0b06e..821a9c0 100644 --- a/crates/sumcheck_macro/examples/expand.rs +++ b/crates/sumcheck_macro/examples/expand.rs @@ -9,7 +9,7 @@ use multilinear_extensions::{ virtual_poly::VirtualPolynomial, virtual_polys::PolyMeta, }; -use p3::field::FieldAlgebra; +use p3::field::PrimeCharacteristicRing; use rand::rngs::OsRng; use sumcheck::util::AdditiveArray; diff --git a/crates/sumcheck_macro/src/lib.rs b/crates/sumcheck_macro/src/lib.rs index 9ac17bd..9e06a1e 100644 --- a/crates/sumcheck_macro/src/lib.rs +++ b/crates/sumcheck_macro/src/lib.rs @@ -315,7 +315,7 @@ pub fn sumcheck_code_gen(input: proc_macro::TokenStream) -> proc_macro::TokenStr quote! {-#v[b]} } else { let scale = x - 1; - quote! {-(#v[b] * E::BaseField::from_canonical_u32(#scale))} + quote! {-(#v[b] * E::BaseField::from_u32(#scale))} } }) .collect(), @@ -382,7 +382,7 @@ pub fn sumcheck_code_gen(input: proc_macro::TokenStream) -> proc_macro::TokenStr // the multiplicity .saturating_sub(num_var); if num_vars_multiplicity > 0 { - sum *= E::BaseField::from_canonical_u64(1 << num_vars_multiplicity); + sum *= E::BaseField::from_u64(1 << num_vars_multiplicity); } AdditiveArray::<_, #degree_plus_one>([sum; #degree_plus_one]) } else { @@ -406,7 +406,7 @@ pub fn sumcheck_code_gen(input: proc_macro::TokenStream) -> proc_macro::TokenStr .saturating_sub(1) .saturating_sub(num_var); if num_vars_multiplicity > 0 { - sum *= E::BaseField::from_canonical_u64(1 << num_vars_multiplicity); + sum *= E::BaseField::from_u64(1 << num_vars_multiplicity); } AdditiveArray::<_, #degree_plus_one>([sum; #degree_plus_one]) } else { diff --git a/crates/transcript/src/basic.rs b/crates/transcript/src/basic.rs index 3be5d22..e874885 100644 --- a/crates/transcript/src/basic.rs +++ b/crates/transcript/src/basic.rs @@ -26,12 +26,12 @@ impl Transcript for BasicTranscript { } fn append_field_element_ext(&mut self, element: &E) { - self.challenger.observe_ext_element(*element); + self.challenger.observe_algebra_element(*element); } fn read_challenge(&mut self) -> Challenge { Challenge { - elements: self.challenger.sample_ext_element(), + elements: self.challenger.sample_algebra_element(), } } diff --git a/crates/transcript/src/lib.rs b/crates/transcript/src/lib.rs index 2b76220..e91049f 100644 --- a/crates/transcript/src/lib.rs +++ b/crates/transcript/src/lib.rs @@ -7,7 +7,7 @@ pub mod basic; pub use basic::BasicTranscript; use ff_ext::SmallField; use itertools::Itertools; -use p3::{challenger::GrindingChallenger, field::FieldAlgebra}; +use p3::{challenger::GrindingChallenger, field::PrimeCharacteristicRing}; #[derive(Default, Copy, Clone, Eq, PartialEq, Debug)] pub struct Challenge { pub elements: F, @@ -135,7 +135,7 @@ pub trait ForkableTranscript: Transcript + Sized + Clone { (0..n) .map(|i| { let mut fork = self.clone(); - fork.append_field_element(&E::BaseField::from_canonical_u64(i as u64)); + fork.append_field_element(&E::BaseField::from_u64(i as u64)); fork }) .collect() diff --git a/crates/whir/Cargo.toml b/crates/whir/Cargo.toml index d928c40..386c389 100644 --- a/crates/whir/Cargo.toml +++ b/crates/whir/Cargo.toml @@ -18,8 +18,8 @@ clap.workspace = true ff_ext.workspace = true multilinear_extensions.workspace = true p3.workspace = true -rand = "0.8" -rand_chacha = "0.3" +rand.workspace = true +rand_chacha.workspace = true rayon = { workspace = true, optional = true } serde = { version = "1.0", features = ["derive"] } sumcheck.workspace = true diff --git a/crates/whir/src/bin/main.rs b/crates/whir/src/bin/main.rs index c982b83..4498ec0 100644 --- a/crates/whir/src/bin/main.rs +++ b/crates/whir/src/bin/main.rs @@ -1,7 +1,7 @@ use std::time::Instant; use multilinear_extensions::mle::MultilinearExtension; -use p3::field::FieldAlgebra; +use p3::field::PrimeCharacteristicRing; use transcript::BasicTranscript; use whir::{ cmdline_utils::{AvailableFields, AvailableMerkle, WhirType}, @@ -128,7 +128,7 @@ fn run_whir_as_ldt(args: Args, hash_params: Poseidon2MerkleMmcs) { let polynomial = MultilinearExtension::from_evaluations_ext_vec( num_variables, - (0..num_coeffs).map(E::from_canonical_u64).collect(), + (0..num_coeffs).map(E::from_u64).collect(), ); let whir_prover_time = Instant::now(); @@ -218,10 +218,10 @@ fn run_whir_pcs(args: Args, hash_params: Poseidon2MerkleMmcs) { let polynomial = MultilinearExtension::from_evaluations_ext_vec( num_variables, - (0..num_coeffs).map(E::from_canonical_u64).collect(), + (0..num_coeffs).map(E::from_u64).collect(), ); let points: Vec<_> = (0..num_evaluations) - .map(|i| vec![E::from_canonical_u64(i as u64); num_variables]) + .map(|i| vec![E::from_u64(i as u64); num_variables]) .collect(); let evaluations = points .iter() diff --git a/crates/whir/src/crypto/mod.rs b/crates/whir/src/crypto/mod.rs index daa6feb..1cad141 100644 --- a/crates/whir/src/crypto/mod.rs +++ b/crates/whir/src/crypto/mod.rs @@ -1,6 +1,6 @@ use ff_ext::{ExtensionField, PoseidonField}; use p3::{ - commit::{ExtensionMmcs, Mmcs}, + commit::{BatchOpeningRef, ExtensionMmcs, Mmcs}, matrix::{ Dimensions, dense::{DenseMatrix, RowMajorMatrix}, @@ -167,13 +167,23 @@ where MerkleTree::Base(merkle_tree) => MultiPath::Base( indices .par_iter() - .map(|index| hash_params.base_mmcs.open_batch(*index, merkle_tree)) + .map(|index| { + hash_params + .base_mmcs + .open_batch(*index, merkle_tree) + .unpack() + }) .collect(), ), MerkleTree::Ext(merkle_tree) => MultiPath::Ext( indices .par_iter() - .map(|index| hash_params.ext_mmcs.open_batch(*index, merkle_tree)) + .map(|index| { + hash_params + .ext_mmcs + .open_batch(*index, merkle_tree) + .unpack() + }) .collect(), ), } @@ -201,17 +211,15 @@ where .par_iter() .zip(proof.par_iter()) .map(|(index, path)| { - hash_params.base_mmcs - .verify_batch( - root, - &[Dimensions { - width: leaf_size, - height: 1 << matrix_height, - }], - *index, - &path.0, - &path.1, - ) + hash_params.base_mmcs.verify_batch( + root, + &[Dimensions { + width: leaf_size, + height: 1 << matrix_height, + }], + *index, + BatchOpeningRef::new(&path.0, &path.1), + ) .map_err(|e| { Error::MmcsError(format!( "Failed to verify proof for index {}, leaf size {}, matrix height log {}, error: {:?}", @@ -227,17 +235,15 @@ where .par_iter() .zip(proof.par_iter()) .map(|(index, path)| { - hash_params.ext_mmcs - .verify_batch( - root, - &[Dimensions { - width: leaf_size, - height: 1 << matrix_height, - }], - *index, - &path.0, - &path.1, - ) + hash_params.ext_mmcs.verify_batch( + root, + &[Dimensions { + width: leaf_size, + height: 1 << matrix_height, + }], + *index, + BatchOpeningRef::new(&path.0, &path.1), + ) .map_err(|e| { Error::MmcsError(format!( "Failed to verify proof for index {}, leaf size {}, matrix height log {}, error: {:?}", diff --git a/crates/whir/src/domain.rs b/crates/whir/src/domain.rs index 45e7478..84da7af 100644 --- a/crates/whir/src/domain.rs +++ b/crates/whir/src/domain.rs @@ -1,16 +1,12 @@ use ff_ext::ExtensionField; -use p3::{ - commit::TwoAdicMultiplicativeCoset, - field::{Field, FieldAlgebra, TwoAdicField}, -}; +use p3::field::{Field, PrimeCharacteristicRing, TwoAdicField, coset::TwoAdicMultiplicativeCoset}; #[derive(Debug, Clone)] pub struct Domain where E: ExtensionField, { - pub base_domain: Option>, // The domain (in the base - // field) for the initial FFT + pub base_domain: Option>, /* base-field domain for initial FFT */ pub backing_domain: TwoAdicMultiplicativeCoset, } @@ -20,15 +16,14 @@ where { pub fn new(degree: usize, log_rho_inv: usize) -> Option { let size = degree * (1 << log_rho_inv); - let base_domain = TwoAdicMultiplicativeCoset { - log_n: p3::util::log2_strict_usize(size), - shift: E::BaseField::from_canonical_u64(1), - }; - let backing_domain = Self::to_extension_domain(&base_domain); + let log_size = p3::util::log2_strict_usize(size); + let base_domain = TwoAdicMultiplicativeCoset::new(E::BaseField::from_u64(1), log_size)?; + let backing_domain = TwoAdicMultiplicativeCoset::new(E::ONE, log_size) + .expect("extension field must support the same two-adicity"); Some(Self { - backing_domain, base_domain: Some(base_domain), + backing_domain, }) } @@ -36,57 +31,50 @@ where // // This asserts that the domain size is divisible by 1 << folding_factor pub fn folded_size(&self, folding_factor: usize) -> usize { - assert!(self.backing_domain.log_n >= folding_factor); - 1 << (self.backing_domain.log_n - folding_factor) + let log_size = self.backing_domain.log_size(); + assert!(log_size >= folding_factor); + 1 << (log_size - folding_factor) } pub fn size(&self) -> usize { - 1 << self.backing_domain.log_n + self.backing_domain.size() } pub fn scale(&self, power: usize) -> Self { + debug_assert!( + power.is_power_of_two(), + "scale expects a power-of-two factor" + ); + let log_power = p3::util::log2_strict_usize(power); + let backing_domain = self + .backing_domain + .shrink_coset(log_power) + .expect("folding factor exceeds domain size"); Self { - backing_domain: self.scale_generator_by(power), - base_domain: None, // Set to zero because we only care for the initial - } - } - - fn to_extension_domain( - domain: &TwoAdicMultiplicativeCoset, - ) -> TwoAdicMultiplicativeCoset { - TwoAdicMultiplicativeCoset { - log_n: domain.log_n, - shift: E::from(domain.shift), - } - } - - // Takes the underlying backing_domain = , and computes the new domain - // (note this will have size |L| / power) - fn scale_generator_by(&self, power: usize) -> TwoAdicMultiplicativeCoset { - TwoAdicMultiplicativeCoset { - log_n: self.backing_domain.log_n - p3::util::log2_strict_usize(power), - shift: self.backing_domain.shift.exp_u64(power as u64), + backing_domain, + base_domain: None, } } pub fn backing_domain_group_gen(&self) -> E { - E::two_adic_generator(self.backing_domain.log_n) + E::two_adic_generator(self.backing_domain.log_size()) } pub fn base_domain_group_gen(&self) -> E::BaseField { - E::BaseField::two_adic_generator(self.backing_domain.log_n) + E::BaseField::two_adic_generator(self.backing_domain.log_size()) } pub fn base_domain_group_gen_inv(&self) -> E::BaseField { - E::BaseField::two_adic_generator(self.backing_domain.log_n).inverse() + self.base_domain_group_gen().inverse() } pub fn backing_domain_element(&self, index: usize) -> E { - E::two_adic_generator(self.backing_domain.log_n).exp_u64(index as u64) + E::two_adic_generator(self.backing_domain.log_size()).exp_u64(index as u64) } pub fn backing_domain_element_pow_of_2(&self, exp: usize) -> E { - assert!(exp <= self.backing_domain.log_n); - E::two_adic_generator(self.backing_domain.log_n - exp) + let log_size = self.backing_domain.log_size(); + assert!(exp <= log_size); + E::two_adic_generator(log_size - exp) } } diff --git a/crates/whir/src/ntt/ntt_impl.rs b/crates/whir/src/ntt/ntt_impl.rs index 2f0d2c5..cc6e0be 100644 --- a/crates/whir/src/ntt/ntt_impl.rs +++ b/crates/whir/src/ntt/ntt_impl.rs @@ -130,8 +130,8 @@ impl NttEngine { let omega_3_1 = res.root(3); let omega_3_2 = omega_3_1 * omega_3_1; // Note: char F cannot be 2 and so division by 2 works, because primitive roots of unity with even order exist. - res.half_omega_3_1_min_2 = (omega_3_1 - omega_3_2) / F::from_canonical_u64(2u64); - res.half_omega_3_1_plus_2 = (omega_3_1 + omega_3_2) / F::from_canonical_u64(2u64); + res.half_omega_3_1_min_2 = (omega_3_1 - omega_3_2) / F::from_u64(2u64); + res.half_omega_3_1_plus_2 = (omega_3_1 + omega_3_2) / F::from_u64(2u64); } if order.is_multiple_of(4) { res.omega_4_1 = res.root(4); diff --git a/crates/whir/src/sumcheck/mod.rs b/crates/whir/src/sumcheck/mod.rs index 6333f64..82097a4 100644 --- a/crates/whir/src/sumcheck/mod.rs +++ b/crates/whir/src/sumcheck/mod.rs @@ -13,7 +13,7 @@ mod tests { mle::{FieldType, MultilinearExtension}, virtual_poly::eq_eval, }; - use p3::field::FieldAlgebra; + use p3::field::PrimeCharacteristicRing; use crate::whir::fold::expand_from_univariate; @@ -24,28 +24,28 @@ mod tests { #[test] fn test_sumcheck_folding_factor_1() { let folding_factor = 1; - let eval_point = vec![F::from_canonical_u64(10), F::from_canonical_u64(11)]; + let eval_point = vec![F::from_u64(10), F::from_u64(11)]; let polynomial = MultilinearExtension::from_evaluations_ext_vec( 2, vec![ - F::from_canonical_u64(1), - F::from_canonical_u64(5), - F::from_canonical_u64(10), - F::from_canonical_u64(14), + F::from_u64(1), + F::from_u64(5), + F::from_u64(10), + F::from_u64(14), ], ); let claimed_value = polynomial.evaluate(&eval_point); - let mut prover = SumcheckCore::new(polynomial, &[eval_point], &[F::from_canonical_u64(1)]); + let mut prover = SumcheckCore::new(polynomial, &[eval_point], &[F::from_u64(1)]); let poly_1 = prover.compute_sumcheck_polynomial(folding_factor); // First, check that is sums to the right value over the hypercube assert_eq!(poly_1.sum_over_hypercube(), claimed_value); - let combination_randomness = F::from_canonical_u64(100101); - let folding_randomness = vec![F::from_canonical_u64(4999)]; + let combination_randomness = F::from_u64(100101); + let folding_randomness = vec![F::from_u64(4999)]; prover.compress(folding_factor, combination_randomness, &folding_randomness); @@ -64,21 +64,21 @@ mod tests { let polynomial = MultilinearExtension::from_evaluations_ext_vec( 2, vec![ - F::from_canonical_u64(1), - F::from_canonical_u64(2), - F::from_canonical_u64(3), - F::from_canonical_u64(4), + F::from_u64(1), + F::from_u64(2), + F::from_u64(3), + F::from_u64(4), ], ); - let ood_point = expand_from_univariate(F::from_canonical_u64(2), num_variables); - let statement_point = expand_from_univariate(F::from_canonical_u64(3), num_variables); + let ood_point = expand_from_univariate(F::from_u64(2), num_variables); + let statement_point = expand_from_univariate(F::from_u64(3), num_variables); let ood_answer = polynomial.evaluate(&ood_point); let statement_answer = polynomial.evaluate(&statement_point); - let epsilon_1 = F::from_canonical_u64(10); - let epsilon_2 = F::from_canonical_u64(100); + let epsilon_1 = F::from_u64(10); + let epsilon_2 = F::from_u64(100); let prover = SumcheckCore::new( polynomial.clone(), @@ -93,7 +93,7 @@ mod tests { epsilon_1 * ood_answer + epsilon_2 * statement_answer ); - let folding_randomness = vec![F::from_canonical_u64(400000), F::from_canonical_u64(800000)]; + let folding_randomness = vec![F::from_u64(400000), F::from_u64(800000)]; let poly_eval = polynomial.evaluate(&folding_randomness); let v_eval = epsilon_1 * eq_eval(&ood_point, &folding_randomness) @@ -109,29 +109,25 @@ mod tests { fn test_sumcheck_folding_factor_2() { let num_variables = 6; let folding_factor = 2; - let eval_point = vec![F::from_canonical_u64(97); num_variables]; + let eval_point = vec![F::from_u64(97); num_variables]; let polynomial = MultilinearExtension::from_evaluations_ext_vec( num_variables, - (0..1 << num_variables).map(F::from_canonical_u64).collect(), + (0..1 << num_variables).map(F::from_u64).collect(), ); let claimed_value = polynomial.evaluate(&eval_point); - let mut prover = SumcheckCore::new( - polynomial.clone(), - &[eval_point], - &[F::from_canonical_u64(1)], - ); + let mut prover = SumcheckCore::new(polynomial.clone(), &[eval_point], &[F::from_u64(1)]); let poly_1 = prover.compute_sumcheck_polynomial(folding_factor); // First, check that is sums to the right value over the hypercube assert_eq!(poly_1.sum_over_hypercube(), claimed_value); - let combination_randomness = [F::from_canonical_u64(293), F::from_canonical_u64(42)]; - let folding_randomness = vec![F::from_canonical_u64(335), F::from_canonical_u64(222)]; + let combination_randomness = [F::from_u64(293), F::from_u64(42)]; + let folding_randomness = vec![F::from_u64(335), F::from_u64(222)]; - let new_eval_point = vec![F::from_canonical_u64(32); num_variables - folding_factor]; + let new_eval_point = vec![F::from_u64(32); num_variables - folding_factor]; let folded_polynomial = polynomial.fix_variables(&folding_randomness); let new_fold_eval = folded_polynomial.evaluate(&new_eval_point); @@ -150,7 +146,7 @@ mod tests { + combination_randomness[1] * new_fold_eval ); - let combination_randomness = F::from_canonical_u64(23212); + let combination_randomness = F::from_u64(23212); prover.compress(folding_factor, combination_randomness, &folding_randomness); let poly_3 = prover.compute_sumcheck_polynomial(folding_factor); @@ -167,19 +163,19 @@ mod tests { let folding_factor = 2; let polynomial = MultilinearExtension::from_evaluations_ext_vec( num_variables, - (0..1 << num_variables).map(F::from_canonical_u64).collect(), + (0..1 << num_variables).map(F::from_u64).collect(), ); // Initial stuff - let ood_point = expand_from_univariate(F::from_canonical_u64(42), num_variables); - let statement_point = expand_from_univariate(F::from_canonical_u64(97), num_variables); + let ood_point = expand_from_univariate(F::from_u64(42), num_variables); + let statement_point = expand_from_univariate(F::from_u64(97), num_variables); // All the randomness - let [epsilon_1, epsilon_2] = [F::from_canonical_u64(15), F::from_canonical_u64(32)]; - let folding_randomness_1 = vec![F::from_canonical_u64(11), F::from_canonical_u64(31)]; - let fold_point = vec![F::from_canonical_u64(31), F::from_canonical_u64(15)]; - let combination_randomness = [F::from_canonical_u64(31), F::from_canonical_u64(4999)]; - let folding_randomness_2 = vec![F::from_canonical_u64(97), F::from_canonical_u64(36)]; + let [epsilon_1, epsilon_2] = [F::from_u64(15), F::from_u64(32)]; + let folding_randomness_1 = vec![F::from_u64(11), F::from_u64(31)]; + let fold_point = vec![F::from_u64(31), F::from_u64(15)]; + let combination_randomness = [F::from_u64(31), F::from_u64(4999)]; + let folding_randomness_2 = vec![F::from_u64(97), F::from_u64(36)]; let mut prover = SumcheckCore::new( polynomial.clone(), @@ -249,37 +245,33 @@ mod tests { let folding_factor = 2; let polynomial = MultilinearExtension::from_evaluations_ext_vec( num_variables, - (0..1 << num_variables).map(F::from_canonical_u64).collect(), + (0..1 << num_variables).map(F::from_u64).collect(), ); // Initial stuff - let ood_point = expand_from_univariate(F::from_canonical_u64(42), num_variables); - let statement_point = expand_from_univariate(F::from_canonical_u64(97), num_variables); + let ood_point = expand_from_univariate(F::from_u64(42), num_variables); + let statement_point = expand_from_univariate(F::from_u64(97), num_variables); // All the randomness - let [epsilon_1, epsilon_2] = [F::from_canonical_u64(15), F::from_canonical_u64(32)]; - let folding_randomness_1 = vec![F::from_canonical_u64(11), F::from_canonical_u64(31)]; - let folding_randomness_2 = vec![F::from_canonical_u64(97), F::from_canonical_u64(36)]; - let folding_randomness_3 = vec![F::from_canonical_u64(11297), F::from_canonical_u64(42136)]; + let [epsilon_1, epsilon_2] = [F::from_u64(15), F::from_u64(32)]; + let folding_randomness_1 = vec![F::from_u64(11), F::from_u64(31)]; + let folding_randomness_2 = vec![F::from_u64(97), F::from_u64(36)]; + let folding_randomness_3 = vec![F::from_u64(11297), F::from_u64(42136)]; let fold_point_11 = vec![ - F::from_canonical_u64(31), - F::from_canonical_u64(15), - F::from_canonical_u64(31), - F::from_canonical_u64(15), + F::from_u64(31), + F::from_u64(15), + F::from_u64(31), + F::from_u64(15), ]; let fold_point_12 = vec![ - F::from_canonical_u64(1231), - F::from_canonical_u64(15), - F::from_canonical_u64(4231), - F::from_canonical_u64(15), - ]; - let fold_point_2 = vec![F::from_canonical_u64(311), F::from_canonical_u64(115)]; - let combination_randomness_1 = [ - F::from_canonical_u64(1289), - F::from_canonical_u64(3281), - F::from_canonical_u64(10921), + F::from_u64(1231), + F::from_u64(15), + F::from_u64(4231), + F::from_u64(15), ]; - let combination_randomness_2 = [F::from_canonical_u64(3281), F::from_canonical_u64(3232)]; + let fold_point_2 = vec![F::from_u64(311), F::from_u64(115)]; + let combination_randomness_1 = [F::from_u64(1289), F::from_u64(3281), F::from_u64(10921)]; + let combination_randomness_2 = [F::from_u64(3281), F::from_u64(3232)]; let mut prover = SumcheckCore::new( polynomial.clone(), diff --git a/crates/whir/src/sumcheck/proof.rs b/crates/whir/src/sumcheck/proof.rs index 7211285..ca5a5be 100644 --- a/crates/whir/src/sumcheck/proof.rs +++ b/crates/whir/src/sumcheck/proof.rs @@ -76,7 +76,7 @@ where mod tests { use ff_ext::GoldilocksExt2; - use p3::field::FieldAlgebra; + use p3::field::PrimeCharacteristicRing; use crate::utils::base_decomposition; @@ -89,18 +89,13 @@ mod tests { let num_variables = 2; let num_evaluation_points = 3_usize.pow(num_variables as u32); - let evaluations = (0..num_evaluation_points as u64) - .map(F::from_canonical_u64) - .collect(); + let evaluations = (0..num_evaluation_points as u64).map(F::from_u64).collect(); let poly = SumcheckPolynomial::new(evaluations, num_variables); for i in 0..num_evaluation_points { let decomp = base_decomposition(i, 3, num_variables); - let point = decomp - .into_iter() - .map(F::from_canonical_u8) - .collect::>(); + let point = decomp.into_iter().map(F::from_u8).collect::>(); assert_eq!(poly.evaluate_at_point(&point), poly.evaluations()[i]); } } diff --git a/crates/whir/src/sumcheck/prover_batched.rs b/crates/whir/src/sumcheck/prover_batched.rs index 8d27100..148fc1c 100644 --- a/crates/whir/src/sumcheck/prover_batched.rs +++ b/crates/whir/src/sumcheck/prover_batched.rs @@ -48,7 +48,7 @@ where SumcheckSingle::eval_eq( point, &mut prover.evaluations_of_equality[i], - F::from_canonical_u64(1), + F::from_u64(1), ); prover.sum += poly_comb_coeff[i] * evals[i]; } @@ -232,7 +232,7 @@ where mod tests { use ff_ext::GoldilocksExt2; use multilinear_extensions::mle::MultilinearExtension; - use p3::field::FieldAlgebra; + use p3::field::PrimeCharacteristicRing; use super::SumcheckBatched; @@ -242,24 +242,24 @@ mod tests { fn test_sumcheck_folding_factor_1() { let num_rounds = 2; let eval_points = vec![ - vec![F::from_canonical_u64(10), F::from_canonical_u64(11)], - vec![F::from_canonical_u64(7), F::from_canonical_u64(8)], + vec![F::from_u64(10), F::from_u64(11)], + vec![F::from_u64(7), F::from_u64(8)], ]; let polynomials = vec![ vec![ - F::from_canonical_u64(1), - F::from_canonical_u64(5), - F::from_canonical_u64(10), - F::from_canonical_u64(14), + F::from_u64(1), + F::from_u64(5), + F::from_u64(10), + F::from_u64(14), ], vec![ - F::from_canonical_u64(2), - F::from_canonical_u64(6), - F::from_canonical_u64(11), - F::from_canonical_u64(13), + F::from_u64(2), + F::from_u64(6), + F::from_u64(11), + F::from_u64(13), ], ]; - let poly_comb_coeffs = vec![F::from_canonical_u64(2), F::from_canonical_u64(3)]; + let poly_comb_coeffs = vec![F::from_u64(2), F::from_u64(3)]; let evals: Vec = polynomials .iter() @@ -271,7 +271,7 @@ mod tests { let mut claimed_value: F = evals .iter() .zip(&poly_comb_coeffs) - .fold(F::from_canonical_u64(0), |sum, (eval, poly_rand)| { + .fold(F::from_u64(0), |sum, (eval, poly_rand)| { *eval * *poly_rand + sum }); @@ -286,8 +286,8 @@ mod tests { // First, check that is sums to the right value over the hypercube assert_eq!(poly.sum_over_hypercube(), claimed_value); - let next_comb_randomness = F::from_canonical_u64(100101); - let next_fold_randomness = vec![F::from_canonical_u64(4999)]; + let next_comb_randomness = F::from_u64(100101); + let next_fold_randomness = vec![F::from_u64(4999)]; prover.compress(next_comb_randomness, &next_fold_randomness, &poly); claimed_value = next_comb_randomness * poly.evaluate_at_point(&next_fold_randomness); diff --git a/crates/whir/src/sumcheck/prover_not_skipping.rs b/crates/whir/src/sumcheck/prover_not_skipping.rs index 8ddf4d2..8e35bc9 100644 --- a/crates/whir/src/sumcheck/prover_not_skipping.rs +++ b/crates/whir/src/sumcheck/prover_not_skipping.rs @@ -75,7 +75,7 @@ mod tests { mle::{FieldType, MultilinearExtension}, virtual_poly::eq_eval, }; - use p3::{field::FieldAlgebra, util::log2_strict_usize}; + use p3::{field::PrimeCharacteristicRing, util::log2_strict_usize}; use transcript::{BasicTranscript, Transcript}; use crate::{ @@ -102,16 +102,14 @@ mod tests { fn test_e2e_short() -> Result<(), Error> { let num_variables = 2; let folding_factor = 2; - let polynomial = (0..1 << num_variables) - .map(F::from_canonical_u64) - .collect::>(); + let polynomial = (0..1 << num_variables).map(F::from_u64).collect::>(); // Initial stuff - let ood_point = expand_from_univariate(F::from_canonical_u64(42), num_variables); - let statement_point = expand_from_univariate(F::from_canonical_u64(97), num_variables); + let ood_point = expand_from_univariate(F::from_u64(42), num_variables); + let statement_point = expand_from_univariate(F::from_u64(97), num_variables); // All the randomness - let [epsilon_1, epsilon_2] = [F::from_canonical_u64(15), F::from_canonical_u64(32)]; + let [epsilon_1, epsilon_2] = [F::from_u64(15), F::from_u64(32)]; // Prover part let mut transcript = T::new(b"test"); @@ -190,18 +188,16 @@ mod tests { fn test_e2e() -> Result<(), Error> { let num_variables = 4; let folding_factor = 2; - let polynomial = (0..1 << num_variables) - .map(F::from_canonical_u64) - .collect::>(); + let polynomial = (0..1 << num_variables).map(F::from_u64).collect::>(); // Initial stuff - let ood_point = expand_from_univariate(F::from_canonical_u64(42), num_variables); - let statement_point = expand_from_univariate(F::from_canonical_u64(97), num_variables); + let ood_point = expand_from_univariate(F::from_u64(42), num_variables); + let statement_point = expand_from_univariate(F::from_u64(97), num_variables); // All the randomness - let [epsilon_1, epsilon_2] = [F::from_canonical_u64(15), F::from_canonical_u64(32)]; - let fold_point = vec![F::from_canonical_u64(31), F::from_canonical_u64(15)]; - let combination_randomness = vec![F::from_canonical_u64(1000)]; + let [epsilon_1, epsilon_2] = [F::from_u64(15), F::from_u64(32)]; + let fold_point = vec![F::from_u64(31), F::from_u64(15)]; + let combination_randomness = vec![F::from_u64(1000)]; // Prover part let mut transcript = T::new(b"test"); diff --git a/crates/whir/src/sumcheck/prover_not_skipping_batched.rs b/crates/whir/src/sumcheck/prover_not_skipping_batched.rs index 2049e12..c512cc2 100644 --- a/crates/whir/src/sumcheck/prover_not_skipping_batched.rs +++ b/crates/whir/src/sumcheck/prover_not_skipping_batched.rs @@ -64,7 +64,7 @@ mod tests { mle::{FieldType, MultilinearExtension}, virtual_poly::eq_eval, }; - use p3::{field::FieldAlgebra, util::log2_strict_usize}; + use p3::{field::PrimeCharacteristicRing, util::log2_strict_usize}; use transcript::{BasicTranscript, Transcript}; use crate::{ @@ -96,20 +96,18 @@ mod tests { let num_variables = 2; let folding_factor = 2; let polynomials = vec![ - (0..1 << num_variables).map(F::from_canonical_u64).collect(), - (1..(1 << num_variables) + 1) - .map(F::from_canonical_u64) - .collect(), + (0..1 << num_variables).map(F::from_u64).collect(), + (1..(1 << num_variables) + 1).map(F::from_u64).collect(), ]; // Initial stuff let statement_points = vec![ - expand_from_univariate(F::from_canonical_u64(97), num_variables), - expand_from_univariate(F::from_canonical_u64(75), num_variables), + expand_from_univariate(F::from_u64(97), num_variables), + expand_from_univariate(F::from_u64(75), num_variables), ]; // Poly randomness - let [alpha_1, alpha_2] = [F::from_canonical_u64(15), F::from_canonical_u64(32)]; + let [alpha_1, alpha_2] = [F::from_u64(15), F::from_u64(32)]; // Prover part let mut transcript = T::new(b"test"); diff --git a/crates/whir/src/sumcheck/prover_single.rs b/crates/whir/src/sumcheck/prover_single.rs index e2f69a4..79b2fc5 100644 --- a/crates/whir/src/sumcheck/prover_single.rs +++ b/crates/whir/src/sumcheck/prover_single.rs @@ -238,7 +238,7 @@ where mod tests { use ff_ext::GoldilocksExt2; use multilinear_extensions::mle::MultilinearExtension; - use p3::field::FieldAlgebra; + use p3::field::PrimeCharacteristicRing; use super::SumcheckSingle; @@ -246,12 +246,12 @@ mod tests { #[test] fn test_sumcheck_folding_factor_1() { - let eval_point = vec![E::from_canonical_u64(10), E::from_canonical_u64(11)]; + let eval_point = vec![E::from_u64(10), E::from_u64(11)]; let polynomial = vec![ - E::from_canonical_u64(1), - E::from_canonical_u64(5), - E::from_canonical_u64(10), - E::from_canonical_u64(14), + E::from_u64(1), + E::from_u64(5), + E::from_u64(10), + E::from_u64(14), ]; let claimed_value = MultilinearExtension::from_evaluations_ext_vec(2, polynomial.clone()) @@ -259,20 +259,15 @@ mod tests { let eval = MultilinearExtension::from_evaluations_ext_vec(2, polynomial.clone()) .evaluate(&eval_point); - let mut prover = SumcheckSingle::new( - polynomial, - &[eval_point], - &[E::from_canonical_u64(1)], - &[eval], - ); + let mut prover = SumcheckSingle::new(polynomial, &[eval_point], &[E::from_u64(1)], &[eval]); let poly_1 = prover.compute_sumcheck_polynomial(); // First, check that is sums to the right value over the hypercube assert_eq!(poly_1.sum_over_hypercube(), claimed_value); - let combination_randomness = E::from_canonical_u64(100101); - let folding_randomness = vec![E::from_canonical_u64(4999)]; + let combination_randomness = E::from_u64(100101); + let folding_randomness = vec![E::from_u64(4999)]; prover.compress(combination_randomness, &folding_randomness, &poly_1); diff --git a/crates/whir/src/utils.rs b/crates/whir/src/utils.rs index a1ddf42..680ff62 100644 --- a/crates/whir/src/utils.rs +++ b/crates/whir/src/utils.rs @@ -161,7 +161,11 @@ pub fn interpolate_over_boolean_hypercube_rmm(evals: &mut RowMajorMatr let n = p3::util::log2_strict_usize(evals.height()); evals.par_row_chunks_mut(2).for_each(|mut chunk| { - let to_subtract = chunk.row(0).collect::>(); + let to_subtract = chunk + .row(0) + .expect("chunk must have a first row") + .into_iter() + .collect::>(); chunk .row_mut(1) .iter_mut() @@ -176,7 +180,11 @@ pub fn interpolate_over_boolean_hypercube_rmm(evals: &mut RowMajorMatr evals.par_row_chunks_mut(chunk_size).for_each(|mut chunk| { let half_chunk = chunk_size >> 1; for j in half_chunk..chunk_size { - let to_subtract = chunk.row(j - half_chunk).collect::>(); + let to_subtract = chunk + .row(j - half_chunk) + .expect("chunk must have requested row") + .into_iter() + .collect::>(); chunk .row_mut(j) .iter_mut() @@ -276,7 +284,7 @@ pub fn evaluate_as_univariate(evals: &[E], points: &[E]) -> V #[cfg(test)] mod tests { use multilinear_extensions::mle::FieldType; - use p3::field::FieldAlgebra; + use p3::field::PrimeCharacteristicRing; use rand::thread_rng; use witness::RowMajorMatrix; @@ -295,7 +303,7 @@ mod tests { let folding_factor = 3; let fold_size = 1 << folding_factor; assert_eq!(num % fold_size, 0); - let evals: Vec = (0..num as u64).map(F::from_canonical_u64).collect(); + let evals: Vec = (0..num as u64).map(F::from_u64).collect(); let stacked = stack_evaluations(evals, folding_factor); assert_eq!(stacked.len(), num); @@ -303,10 +311,7 @@ mod tests { for (i, fold) in stacked.chunks_exact(fold_size).enumerate() { assert_eq!(fold.len(), fold_size); for (j, item) in fold.iter().copied().enumerate().take(fold_size) { - assert_eq!( - item, - F::from_canonical_u64((i + j * num / fold_size) as u64) - ); + assert_eq!(item, F::from_u64((i + j * num / fold_size) as u64)); } } } diff --git a/crates/whir/src/whir/batch/prover.rs b/crates/whir/src/whir/batch/prover.rs index baa641a..79e40b4 100644 --- a/crates/whir/src/whir/batch/prover.rs +++ b/crates/whir/src/whir/batch/prover.rs @@ -385,7 +385,7 @@ where &round_state.folding_randomness, coset_offset_inv, coset_generator_inv, - E::from_canonical_u64(2).inverse(), + E::from_u64(2).inverse(), self.0.folding_factor.at_round(round_state.round), ) }, diff --git a/crates/whir/src/whir/committer.rs b/crates/whir/src/whir/committer.rs index 84042a2..48213ba 100644 --- a/crates/whir/src/whir/committer.rs +++ b/crates/whir/src/whir/committer.rs @@ -12,7 +12,7 @@ use crate::{ use ff_ext::ExtensionField; use multilinear_extensions::mle::{FieldType, MultilinearExtension}; use p3::{ - field::{Field, FieldAlgebra}, + field::{Field, PrimeCharacteristicRing}, matrix::dense::RowMajorMatrix, }; use sumcheck::macros::{entered_span, exit_span}; diff --git a/crates/whir/src/whir/fold.rs b/crates/whir/src/whir/fold.rs index 1ceffeb..fa4705c 100644 --- a/crates/whir/src/whir/fold.rs +++ b/crates/whir/src/whir/fold.rs @@ -65,7 +65,7 @@ pub fn restructure_evaluations( // Apply coset and size correction. // Stacked evaluation at i is f(B_l) where B_l = w^i * - let size_inv = F::from_canonical_u64(folding_size).inverse(); + let size_inv = F::from_u64(folding_size).inverse(); #[cfg(not(feature = "parallel"))] { let mut coset_offset_inv = F::ONE; @@ -119,7 +119,7 @@ pub fn restructure_evaluations_mut( // Apply coset and size correction. // Stacked evaluation at i is f(B_l) where B_l = w^i * - let size_inv = F::from_canonical_u64(folding_size).inverse(); + let size_inv = F::from_u64(folding_size).inverse(); #[cfg(not(feature = "parallel"))] { let mut coset_offset_inv = F::ONE; @@ -172,7 +172,7 @@ pub fn restructure_evaluations_mut_rmm( // Apply coset and size correction. // Stacked evaluation at i is f(B_l) where B_l = w^i * - let size_inv = F::from_canonical_u64(folding_size).inverse(); + let size_inv = F::from_u64(folding_size).inverse(); #[cfg(not(feature = "parallel"))] { let mut coset_offset_inv = F::ONE; @@ -359,7 +359,7 @@ where mod tests { use ff_ext::GoldilocksExt2; use multilinear_extensions::mle::MultilinearExtension; - use p3::field::{Field, FieldAlgebra, TwoAdicField}; + use p3::field::{Field, PrimeCharacteristicRing, TwoAdicField}; use crate::{ utils::{evaluate_over_hypercube, stack_evaluations}, @@ -381,17 +381,14 @@ mod tests { let poly = MultilinearExtension::from_evaluations_ext_vec( num_variables, - (0..num_coeffs) - .map(F::from_canonical_u64) - .collect::>(), + (0..num_coeffs).map(F::from_u64).collect::>(), ); let root_of_unity = F::two_adic_generator(p3::util::log2_strict_usize(domain_size)); let index = 15; - let folding_randomness: Vec<_> = (0..folding_factor) - .map(|i| F::from_canonical_u64(i as u64)) - .collect(); + let folding_randomness: Vec<_> = + (0..folding_factor).map(|i| F::from_u64(i as u64)).collect(); let coset_offset = root_of_unity.exp_u64(index); let coset_gen = root_of_unity.exp_u64((domain_size / folding_factor_exp) as u64); @@ -411,7 +408,7 @@ mod tests { &folding_randomness, coset_offset.inverse(), coset_gen.inverse(), - F::from_canonical_u64(2).inverse(), + F::from_u64(2).inverse(), folding_factor, ); @@ -436,17 +433,14 @@ mod tests { let poly = MultilinearExtension::from_evaluations_ext_vec( num_variables, - (0..num_coeffs) - .map(F::from_canonical_u64) - .collect::>(), + (0..num_coeffs).map(F::from_u64).collect::>(), ); let root_of_unity = F::two_adic_generator(p3::util::log2_strict_usize(domain_size)); let root_of_unity_inv = root_of_unity.inverse(); - let folding_randomness: Vec<_> = (0..folding_factor) - .map(|i| F::from_canonical_u64(i as u64)) - .collect(); + let folding_randomness: Vec<_> = + (0..folding_factor).map(|i| F::from_u64(i as u64)).collect(); // Evaluate the polynomial on the domain let domain_evaluations: Vec<_> = (0..domain_size) @@ -475,7 +469,7 @@ mod tests { &folding_randomness, offset_inv, coset_gen_inv, - F::from_canonical_u64(2).inverse(), + F::from_u64(2).inverse(), folding_factor, ); diff --git a/crates/whir/src/whir/mod.rs b/crates/whir/src/whir/mod.rs index dd39455..cc7da05 100644 --- a/crates/whir/src/whir/mod.rs +++ b/crates/whir/src/whir/mod.rs @@ -39,7 +39,7 @@ where mod tests { use ff_ext::{ExtensionField, FromUniformBytes, GoldilocksExt2}; use multilinear_extensions::mle::MultilinearExtension; - use p3::field::FieldAlgebra; + use p3::field::PrimeCharacteristicRing; use rand::SeedableRng; use rand_chacha::ChaCha8Rng; use transcript::BasicTranscript; @@ -91,7 +91,7 @@ mod tests { let polynomial = MultilinearExtension::from_evaluations_vec( num_variables, - vec![::BaseField::from_canonical_u64(1); num_coeffs], + vec![::BaseField::from_u64(1); num_coeffs], ); let points: Vec<_> = (0..num_points) diff --git a/crates/whir/src/whir/parameters.rs b/crates/whir/src/whir/parameters.rs index 4d8472c..1a91b03 100644 --- a/crates/whir/src/whir/parameters.rs +++ b/crates/whir/src/whir/parameters.rs @@ -71,7 +71,7 @@ impl WhirConfig { let protocol_security_level = 0.max(whir_parameters.security_level - whir_parameters.pow_bits); - let starting_domain = Domain::new( + let starting_domain = Domain::::new( 1 << mv_parameters.num_variables, whir_parameters.starting_log_inv_rate, ) diff --git a/crates/whir/src/whir/prover.rs b/crates/whir/src/whir/prover.rs index fe41305..c02d754 100644 --- a/crates/whir/src/whir/prover.rs +++ b/crates/whir/src/whir/prover.rs @@ -364,7 +364,7 @@ where &round_state.folding_randomness, coset_offset_inv, coset_generator_inv, - E::from_canonical_u64(2).inverse(), + E::from_u64(2).inverse(), self.0.folding_factor.at_round(round_state.round), ) }, diff --git a/crates/whir/src/whir/verifier.rs b/crates/whir/src/whir/verifier.rs index 3983843..2a34ee8 100644 --- a/crates/whir/src/whir/verifier.rs +++ b/crates/whir/src/whir/verifier.rs @@ -6,7 +6,7 @@ use ff_ext::{ExtensionField, PoseidonField}; use multilinear_extensions::{mle::MultilinearExtension, virtual_poly::eq_eval}; use p3::{ commit::Mmcs, - field::{Field, FieldAlgebra}, + field::{Field, PrimeCharacteristicRing}, maybe_rayon::prelude::*, }; use serde::{Deserialize, Serialize, de::DeserializeOwned}; @@ -74,7 +74,7 @@ where pub fn new(params: WhirConfig) -> Self { Verifier { params, - two_inv: E::BaseField::from_canonical_u64(2).inverse(), /* The only inverse in the entire code :) */ + two_inv: E::BaseField::from_u64(2).inverse(), /* The only inverse in the entire code :) */ } } @@ -160,7 +160,7 @@ where }; let mut prev_root = parsed_commitment.root.clone(); - let mut domain_gen = self.params.starting_domain.backing_domain_group_gen(); + let mut domain_gen: E = self.params.starting_domain.backing_domain_group_gen(); let mut exp_domain_gen = domain_gen.exp_power_of_2(self.params.folding_factor.at_round(0)); let mut domain_gen_inv = self .params diff --git a/crates/witness/src/lib.rs b/crates/witness/src/lib.rs index b5f82b4..976ac2f 100644 --- a/crates/witness/src/lib.rs +++ b/crates/witness/src/lib.rs @@ -1,9 +1,9 @@ use multilinear_extensions::mle::{IntoMLE, MultilinearExtension}; use p3::{ - field::{Field, FieldAlgebra}, + field::{Field, PrimeCharacteristicRing}, matrix::Matrix, }; -use rand::{Rng, distributions::Standard, prelude::Distribution}; +use rand::Rng; use rayon::{ iter::{IndexedParallelIterator, IntoParallelIterator, ParallelExtend, ParallelIterator}, prelude::ParallelSliceMut, @@ -65,19 +65,19 @@ struct DeviceMatrixBacking { layout: DeviceMatrixLayout, } -impl RowMajorMatrix { +impl RowMajorMatrix { fn invalidate_device_backing(&mut self) { self.device_backing = None; } - pub fn rand(rng: &mut R, rows: usize, cols: usize) -> Self - where - Standard: Distribution, - { + pub fn rand(rng: &mut R, rows: usize, cols: usize) -> Self { debug_assert!(rows > 0); let num_row_padded = next_pow2_instance_padding(rows); + let values = (0..num_row_padded * cols) + .map(|_| T::from_u64(rng.gen())) + .collect(); Self { - inner: p3::matrix::dense::RowMajorMatrix::rand(rng, num_row_padded, cols), + inner: p3::matrix::dense::RowMajorMatrix::new(values, cols), num_rows: rows, is_padded: true, log2_num_rotation: 0, @@ -325,7 +325,7 @@ impl RowMajorMat .enumerate() .for_each(|(i, instance)| { instance.iter_mut().enumerate().for_each(|(j, v)| { - *v = T::from_canonical_u64(fun((start_index + i) as u64, j as u64)); + *v = T::from_u64(fun((start_index + i) as u64, j as u64)); }) }); } @@ -447,7 +447,7 @@ impl DerefMut for RowMajorMatri } } -impl Index for RowMajorMatrix { +impl Index for RowMajorMatrix { type Output = [F]; fn index(&self, idx: usize) -> &Self::Output {