diff --git a/Cargo.lock b/Cargo.lock index 303a17c..aee2577 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", "rayon", "serde", @@ -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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60414dc4fe4b8676bd4b6136b309185e6b3c006eb5564ef4cf5dfae6d9d47f32" 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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f2fecd03416a20949dc7cd4b481c37d744c4d398467f94213c65279a0f00048" 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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a66da8af6115b9e2df4363cd55efebf2c6d30de0af3e99dac56dd7b77aff24" 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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95104feb4b9895733f92204ec70ba8944dbab39c39b235c0a00adf1456149619" 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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81b2f57569293b9964b1bae68d64e796bfbf3c271718268beb53a0fb761a5819" 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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56aae7630ff6df83fb7421d5bd97df27620e5f0e29422b7e8f6a294d44cce297" 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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0e9a7053c439444f5c4be80ecc08b255a046bc5d23762abe8a4460ae0fca583" 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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85324dc45db4196ce0083971393124f5ed03741507f9165d5c923c97890b4838" 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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b0bb6a709b26cead74e7c605f4e51e793642870e54a7c280a05cd66b7914866" dependencies = [ "p3-field", "p3-matrix", @@ -1162,14 +1148,15 @@ dependencies = [ [[package]] name = "p3-matrix" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d916550e4261126457d4f139fc3156fc796b1cf2f2687bf1c9b269b1efa8ad42" dependencies = [ "itertools 0.14.0", "p3-field", "p3-maybe-rayon", "p3-util", - "rand", + "rand 0.9.2", "serde", "tracing", "transpose", @@ -1177,30 +1164,31 @@ dependencies = [ [[package]] name = "p3-maybe-rayon" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0db6a290f867061aed54593d48f0dfd7ff2d0f706a603d03209fd0eac79518f3" dependencies = [ "rayon", ] [[package]] name = "p3-mds" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "745a478473a5f3699f76b284378651eaa9d74e74f820b34ea563a4a72ab8a4a6" 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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "615f09d1c83ca2ad0dd1f8fb4e496445f9c24a224bac81b98849973f444ee86c" dependencies = [ "itertools 0.14.0", "p3-commit", @@ -1209,15 +1197,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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f124f989bc5697728a9e71d2094eda673c45a536c6a8b8ec87b7f3660393aad0" dependencies = [ "itertools 0.14.0", "num-bigint", @@ -1229,55 +1219,59 @@ 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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc0930e45272609b239052346e2abe8965adaf22b8237eddb679d659af53f28" 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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b0c96988fd809e7a3086d8d683ddb93c965f8bb08b37c82e3617d12347bf77f" 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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a0c44c47992126b5eb4f5a33444d6059b883c1ea520f1d34590d46338314178" 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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dabf1c93a83305b291118dec6632357da69f3137d33fc1791225e38fcb615836" dependencies = [ "itertools 0.14.0", "p3-field", @@ -1286,8 +1280,9 @@ dependencies = [ [[package]] name = "p3-util" -version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb#539bbc84085efb609f4f62cb03cf49588388abdb" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92074eab13c8a30d23ad7bcf99b82787a04c843133a0cba39ca1cf39d434492" dependencies = [ "serde", ] @@ -1398,7 +1393,7 @@ version = "0.1.0" dependencies = [ "ff_ext", "p3", - "rand", + "rand 0.8.5", "serde", ] @@ -1455,7 +1450,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 +1469,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 +1482,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 +1619,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 +1691,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 +1698,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 +1731,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 +1794,11 @@ dependencies = [ "p3", "p3-goldilocks", "poseidon", - "rand", + "rand 0.8.5", "rayon", "serde", "sumcheck_macro", - "thiserror", + "thiserror 1.0.69", "tracing", "transcript", ] @@ -1794,7 +1813,7 @@ dependencies = [ "p3", "proc-macro2", "quote", - "rand", + "rand 0.8.5", "sumcheck", "syn", ] @@ -1816,7 +1835,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 +1859,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]] @@ -2099,7 +2118,7 @@ dependencies = [ "itertools 0.14.0", "multilinear_extensions", "p3", - "rand", + "rand 0.8.5", "rand_chacha", "rayon", "serde", @@ -2310,7 +2329,7 @@ dependencies = [ "ff_ext", "multilinear_extensions", "p3", - "rand", + "rand 0.8.5", "rayon", "tracing", ] diff --git a/Cargo.toml b/Cargo.toml index c9606ef..b80e25c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,24 +43,24 @@ 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.1", default-features = false } +p3-baby-bear = { version = "=0.4.1", default-features = false } +p3-challenger = { version = "=0.4.1", default-features = false } +p3-commit = { version = "=0.4.1", default-features = false } +p3-dft = { version = "=0.4.1", default-features = false } +p3-field = { version = "=0.4.1", default-features = false } +p3-fri = { version = "=0.4.1", default-features = false } +p3-goldilocks = { version = "=0.4.1", default-features = false } +p3-matrix = { version = "=0.4.1", default-features = false } +p3-maybe-rayon = { version = "=0.4.1", default-features = false } +p3-mds = { version = "=0.4.1", default-features = false } +p3-merkle-tree = { version = "=0.4.1", default-features = false } +p3-monty-31 = { version = "=0.4.1", default-features = false } +p3-poseidon = { version = "=0.4.1", default-features = false } +p3-poseidon2 = { version = "=0.4.1", default-features = false } +p3-poseidon2-air = { version = "=0.4.1", default-features = false } +p3-symmetric = { version = "=0.4.1", default-features = false } +p3-util = { version = "=0.4.1", default-features = false } rand = "0.8" rand_chacha = { version = "0.3", features = ["serde1"] } rand_core = "0.6" 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..c19a0cd 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/src/basefold.rs b/crates/mpcs/src/basefold.rs index 1a5586e..714196e 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 f97c70b..d4c519a 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/lib.rs b/crates/mpcs/src/lib.rs index a8defea..27ad848 100644 --- a/crates/mpcs/src/lib.rs +++ b/crates/mpcs/src/lib.rs @@ -290,7 +290,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; @@ -338,7 +338,6 @@ pub mod test_util { num_vars_end: usize, ) where Pcs: PolynomialCommitmentScheme, - Standard: Distribution, { use multilinear_extensions::mle::ArcMultilinearExtension; @@ -391,7 +390,6 @@ pub mod test_util { ) where E: ExtensionField, Pcs: PolynomialCommitmentScheme, - Standard: Distribution, { use multilinear_extensions::mle::ArcMultilinearExtension; @@ -451,7 +449,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 d17a9c8..127b4fd 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))) } } @@ -1363,7 +1335,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))) } } )* @@ -1378,7 +1350,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))) } } )* @@ -1535,7 +1507,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() { @@ -1704,9 +1676,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 f1370da..c7d1096 100644 --- a/crates/multilinear_extensions/src/mle.rs +++ b/crates/multilinear_extensions/src/mle.rs @@ -1,3 +1,4 @@ +use p3::field::PrimeCharacteristicRing; use std::{any::TypeId, borrow::Cow, mem, sync::Arc}; use crate::{ @@ -11,10 +12,7 @@ use either::Either; use ff_ext::{ExtensionField, FromUniformBytes}; #[cfg(not(feature = "parallel"))] use itertools::Itertools; -use p3::{ - field::{Field, FieldAlgebra}, - maybe_rayon::prelude::*, -}; +use p3::{field::Field, maybe_rayon::prelude::*}; use rand::Rng; use serde::{Deserialize, Serialize, de::DeserializeOwned}; use std::fmt::Debug; @@ -242,7 +240,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(), } } @@ -958,13 +956,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/virtual_polys.rs b/crates/multilinear_extensions/src/virtual_polys.rs index 5494676..ad5b21c 100644 --- a/crates/multilinear_extensions/src/virtual_polys.rs +++ b/crates/multilinear_extensions/src/virtual_polys.rs @@ -362,7 +362,7 @@ impl<'a, E: ExtensionField> VirtualPolynomials<'a, E> { let scalar = E::random(&mut *rng); monimial_term.push(Term { scalar, product }); // need to scale up for the smaller nv - sum += E::from_canonical_u64(1 << (max_num_variables - nv)) * product_sum * scalar; + sum += E::from_u64(1 << (max_num_variables - nv)) * product_sum * scalar; } } exit_span!(start); 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/devirgo_sumcheck.rs b/crates/sumcheck/benches/devirgo_sumcheck.rs index 5e24011..3857089 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::thread_rng; use sumcheck::structs::IOPProverState; @@ -39,7 +39,9 @@ pub fn transpose(v: Vec>) -> Vec> { .collect() } -fn prepare_input<'a, E: ExtensionField>(nv: usize) -> (E, Vec>) { +fn prepare_input<'a, E: ExtensionField + PrimeCharacteristicRing>( + nv: usize, +) -> (E, Vec>) { let mut rng = thread_rng(); let fs = (0..NUM_DEGREE) .map(|_| MultilinearExtension::::random(nv, &mut rng)) diff --git a/crates/sumcheck/src/extrapolate.rs b/crates/sumcheck/src/extrapolate.rs index d2b6248..61265cb 100644 --- a/crates/sumcheck/src/extrapolate.rs +++ b/crates/sumcheck/src/extrapolate.rs @@ -1,5 +1,6 @@ use ff_ext::ExtensionField; use itertools::Itertools; +use p3::field::PrimeCharacteristicRing; use std::{ any::{Any, TypeId}, collections::BTreeMap, @@ -31,19 +32,19 @@ use std::{ /// This structure stores all `v_j` coefficients for each `(degree, target_z)` pair. /// At runtime, extrapolation is done by a simple dot product of `v_j` with the known values `f(x_j)`, /// without needing any inverses. -pub struct ExtrapolationTable { +pub struct ExtrapolationTable { /// weights[degree][z - degree - 1][j] = coefficient for f(x_j) when extrapolating to z pub weights: Vec>>, } -impl ExtrapolationTable { +impl ExtrapolationTable { pub fn new(min_degree: usize, max_degree: usize) -> Self { let mut weights = Vec::new(); 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 +59,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 +71,7 @@ impl ExtrapolationTable { // Normalize for t in tmp.iter_mut() { - *t = *t / den; + *t /= den; } degree_weights.push(tmp); @@ -83,11 +84,11 @@ impl ExtrapolationTable { } } -pub struct ExtrapolationCache { +pub struct ExtrapolationCache { _marker: PhantomData, } -impl ExtrapolationCache { +impl ExtrapolationCache { fn global_cache() -> &'static Mutex>> { static GLOBAL_CACHE: OnceLock>>> = OnceLock::new(); diff --git a/crates/sumcheck/src/prover.rs b/crates/sumcheck/src/prover.rs index 900b873..e7cd437 100644 --- a/crates/sumcheck/src/prover.rs +++ b/crates/sumcheck/src/prover.rs @@ -23,7 +23,7 @@ use crate::{ merge_sumcheck_prover_state, }, }; -use p3::field::FieldAlgebra; +use p3::field::PrimeCharacteristicRing; struct Phase1Workers<'a, E: ExtensionField> { workers_states: Vec>, diff --git a/crates/sumcheck/src/test.rs b/crates/sumcheck/src/test.rs index fc37738..2fbc8a5 100644 --- a/crates/sumcheck/src/test.rs +++ b/crates/sumcheck/src/test.rs @@ -12,7 +12,7 @@ use multilinear_extensions::{ virtual_poly::{VPAuxInfo, VirtualPolynomial}, virtual_polys::VirtualPolynomials, }; -use p3::field::FieldAlgebra; +use p3::field::PrimeCharacteristicRing; use rand::{Rng, thread_rng}; use transcript::{BasicTranscript, Transcript}; @@ -218,7 +218,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..73cdfaf 100644 --- a/crates/sumcheck/src/util.rs +++ b/crates/sumcheck/src/util.rs @@ -14,7 +14,7 @@ use multilinear_extensions::{ virtual_poly::VirtualPolynomial, virtual_polys::PolyMeta, }; -use p3::field::Field; +use p3::field::{Field, PrimeCharacteristicRing}; use transcript::Transcript; use crate::{extrapolate::ExtrapolationCache, structs::IOPProverState}; @@ -27,7 +27,10 @@ use crate::{extrapolate::ExtrapolationCache, structs::IOPProverState}; /// efficient barycentric extrapolation without requiring any inverse operations at runtime. /// /// Note: this function is highly optimized without field inverse. see [`ExtrapolationTable`] for how to achieve it -pub fn extrapolate_from_table(uni_variate: &mut [E], start: usize) { +pub fn extrapolate_from_table( + uni_variate: &mut [E], + start: usize, +) { let cur_degree = start - 1; let table = ExtrapolationCache::::get(cur_degree, uni_variate.len() - 1); let target_len = uni_variate.len(); @@ -53,7 +56,7 @@ pub fn extrapolate_from_table(uni_variate: &mut [E], start: u } } -fn extrapolate_uni_poly_deg_1(p0: F, p1: F, eval_at: F) -> F { +fn extrapolate_uni_poly_deg_1(p0: F, p1: F, eval_at: F) -> F { let x0 = F::ZERO; let x1 = F::ONE; @@ -75,17 +78,22 @@ fn extrapolate_uni_poly_deg_1(p0: F, p1: F, eval_at: F) -> F { l * (t0 + t1) } -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); +fn extrapolate_uni_poly_deg_2( + p0: F, + p1: F, + p2: F, + eval_at: F, +) -> F { + 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; @@ -104,20 +112,26 @@ fn extrapolate_uni_poly_deg_2(p0: F, p1: F, p2: F, eval_at: F) -> F { l * (t0 + t1 + t2) } -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); +fn extrapolate_uni_poly_deg_3( + p0: F, + p1: F, + p2: F, + p3: F, + eval_at: F, +) -> F { + 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 +154,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 +459,12 @@ impl Mul for AdditiveVec { mod tests { use super::*; use ff_ext::GoldilocksExt2; - use p3::field::FieldAlgebra; #[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..12d1a0b 100644 --- a/crates/sumcheck_macro/examples/expand.rs +++ b/crates/sumcheck_macro/examples/expand.rs @@ -9,12 +9,12 @@ 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; #[derive(Default)] -struct Container<'a, E: ExtensionField> { +struct Container<'a, E: ExtensionField + PrimeCharacteristicRing> { poly: VirtualPolynomial<'a, E>, is_main_worker: bool, phase2_numvar: Option, @@ -25,7 +25,7 @@ fn main() { c.run(); } -impl Container<'_, E> { +impl Container<'_, E> { pub fn run(&self) { let poly = &self.poly.flattened_ml_extensions; let _result = diff --git a/crates/sumcheck_macro/src/lib.rs b/crates/sumcheck_macro/src/lib.rs index e3e66d1..7524810 100644 --- a/crates/sumcheck_macro/src/lib.rs +++ b/crates/sumcheck_macro/src/lib.rs @@ -291,7 +291,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 { @@ -315,7 +315,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..06f457c 100644 --- a/crates/whir/src/ntt/ntt_impl.rs +++ b/crates/whir/src/ntt/ntt_impl.rs @@ -9,7 +9,7 @@ use super::{ }; use ff_ext::ExtensionField; use p3::{ - field::{Field, TwoAdicField}, + field::{Field, PrimeCharacteristicRing, TwoAdicField}, matrix::{ Matrix, dense::{DenseMatrix, RowMajorMatrix}, @@ -31,7 +31,7 @@ static ENGINE_CACHE: LazyLock>> /// Enginge for computing NTTs over arbitrary fields. /// Assumes the field has large two-adicity. -pub struct NttEngine { +pub struct NttEngine { order: usize, // order of omega_orger omega_order: F, // primitive order'th root. @@ -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 738a39e..b4e07cc 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 a2e13bc..6474752 100644 --- a/crates/whir/src/whir/fold.rs +++ b/crates/whir/src/whir/fold.rs @@ -66,7 +66,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; @@ -120,7 +120,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; @@ -173,7 +173,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; @@ -360,7 +360,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}, @@ -382,17 +382,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); @@ -412,7 +409,7 @@ mod tests { &folding_randomness, coset_offset.inverse(), coset_gen.inverse(), - F::from_canonical_u64(2).inverse(), + F::from_u64(2).inverse(), folding_factor, ); @@ -437,17 +434,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) @@ -476,7 +470,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 3710134..d9b2878 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, @@ -43,15 +43,15 @@ pub struct RowMajorMatrix { padding_strategy: InstancePaddingStrategy, } -impl RowMajorMatrix { - pub fn rand(rng: &mut R, rows: usize, cols: usize) -> Self - where - Standard: Distribution, - { +impl RowMajorMatrix { + 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, @@ -205,7 +205,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)); }) }); } @@ -303,7 +303,7 @@ impl DerefMut for RowMajorMatri } } -impl Index for RowMajorMatrix { +impl Index for RowMajorMatrix { type Output = [F]; fn index(&self, idx: usize) -> &Self::Output { diff --git a/test_assoc b/test_assoc new file mode 100755 index 0000000..f4e7a7f Binary files /dev/null and b/test_assoc differ