diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd473c1d..335ebacc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,8 +9,6 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly-2022-12-10 - override: true components: rustfmt - run: make fmt clippy: @@ -20,8 +18,6 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly-2022-12-10 - override: true components: clippy - run: make clippy test: @@ -31,8 +27,6 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly-2022-12-10 - override: true - run: make test par-test: runs-on: ubuntu-latest @@ -41,8 +35,6 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly-2022-12-10 - override: true - run: make test_par bench: runs-on: ubuntu-latest @@ -51,6 +43,4 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly-2022-12-10 - override: true - run: make bench diff --git a/Cargo.lock b/Cargo.lock index 9521e45e..6c730417 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -94,7 +94,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", "winapi", ] @@ -123,12 +123,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" -[[package]] -name = "base64" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" - [[package]] name = "base64" version = "0.21.5" @@ -219,7 +213,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f5353f36341f7451062466f0b755b96ac3a9547e4d7f6b70d603fc721a7d7896" dependencies = [ - "sha2 0.10.8", + "sha2", "tinyvec", ] @@ -294,7 +288,7 @@ dependencies = [ "js-sys", "num-traits", "wasm-bindgen", - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -373,10 +367,10 @@ dependencies = [ "bs58", "coins-core", "digest 0.10.7", - "hmac 0.12.1", + "hmac", "k256", "serde", - "sha2 0.10.8", + "sha2", "thiserror", ] @@ -388,11 +382,11 @@ checksum = "3db8fba409ce3dc04f7d804074039eb68b960b0829161f8e06c95fea3f122528" dependencies = [ "bitvec", "coins-bip32", - "hmac 0.12.1", + "hmac", "once_cell", "pbkdf2 0.12.2", "rand", - "sha2 0.10.8", + "sha2", "thiserror", ] @@ -402,7 +396,7 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5286a0843c21f8367f7be734f89df9b822e0321d8bcce8d6e735aadff7d74979" dependencies = [ - "base64 0.21.5", + "base64", "bech32", "bs58", "digest 0.10.7", @@ -411,7 +405,7 @@ dependencies = [ "ripemd", "serde", "serde_derive", - "sha2 0.10.8", + "sha2", "sha3 0.10.8", "thiserror", ] @@ -641,16 +635,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "crypto-mac" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" -dependencies = [ - "generic-array", - "subtle", -] - [[package]] name = "ctr" version = "0.9.2" @@ -861,16 +845,16 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "elliptic-curve" -version = "0.13.7" +version = "0.13.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9775b22bc152ad86a0cf23f0f348b884b26add12bf741e7ffc4d4ab2ab4d205" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" dependencies = [ "base16ct", "crypto-bigint", "digest 0.10.7", - "ff 0.13.0", + "ff", "generic-array", - "group 0.13.0", + "group", "pkcs8", "rand_core", "sec1", @@ -880,12 +864,12 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.9.3" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" +checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" dependencies = [ - "atty", "humantime", + "is-terminal", "log", "regex", "termcolor", @@ -899,12 +883,12 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -917,13 +901,13 @@ dependencies = [ "ctr", "digest 0.10.7", "hex", - "hmac 0.12.1", + "hmac", "pbkdf2 0.11.0", "rand", "scrypt", "serde", "serde_json", - "sha2 0.10.8", + "sha2", "sha3 0.10.8", "thiserror", "uuid", @@ -932,15 +916,15 @@ dependencies = [ [[package]] name = "eth-types" version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?rev=7d9bc181953cfc6e7baf82ff0ce651281fd70a8a#7d9bc181953cfc6e7baf82ff0ce651281fd70a8a" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?rev=d14464379107ca80b6280d4b9238eeb60e1fbf15#d14464379107ca80b6280d4b9238eeb60e1fbf15" dependencies = [ "ethers-core", "ethers-signers", + "halo2-base", "halo2_proofs", "hex", "itertools", "lazy_static", - "libsecp256k1", "num", "num-bigint", "once_cell", @@ -1044,7 +1028,7 @@ dependencies = [ "ethers-core", "hex", "rand", - "sha2 0.10.8", + "sha2", "thiserror", "tracing", ] @@ -1064,23 +1048,13 @@ dependencies = [ "simd-adler32", ] -[[package]] -name = "ff" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - [[package]] name = "ff" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ + "bitvec", "rand_core", "subtle", ] @@ -1221,30 +1195,18 @@ dependencies = [ [[package]] name = "gobuild" version = "0.1.0-alpha.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71e156a4ddbf3deb5e8116946c111413bd9a5679bdc1536c78a60618a7a9ac9e" +source = "git+https://github.com/scroll-tech/gobuild.git#24935c2b8f677841f22acd6710957621bb294e0e" dependencies = [ "cc", ] -[[package]] -name = "group" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" -dependencies = [ - "ff 0.12.1", - "rand_core", - "subtle", -] - [[package]] name = "group" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ - "ff 0.13.0", + "ff", "rand_core", "subtle", ] @@ -1255,6 +1217,21 @@ version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" +[[package]] +name = "halo2-base" +version = "0.2.2" +source = "git+https://github.com/scroll-tech/halo2-lib?branch=develop#b7c53bb7456063936f4ca6df8fa8e751d9c17d85" +dependencies = [ + "ff", + "halo2_proofs", + "itertools", + "num-bigint", + "num-integer", + "num-traits", + "rand_chacha", + "rustc-hash", +] + [[package]] name = "halo2-mpt-circuits" version = "0.1.0" @@ -1286,8 +1263,9 @@ dependencies = [ [[package]] name = "halo2-mpt-circuits" version = "0.1.0" -source = "git+https://github.com/scroll-tech/mpt-circuit.git?tag=v0.7.0#578c210ceb88d3c143ee2a013ad836d19285d9c1" +source = "git+https://github.com/scroll-tech/mpt-circuit.git?rev=a544844b071ee37ca54b7a266b8ffb7672277d76#a544844b071ee37ca54b7a266b8ffb7672277d76" dependencies = [ + "env_logger", "ethers-core", "halo2_proofs", "hex", @@ -1298,6 +1276,7 @@ dependencies = [ "num-traits", "poseidon-circuit", "rand", + "rand_chacha", "serde", "serde_json", "strum", @@ -1308,15 +1287,15 @@ dependencies = [ [[package]] name = "halo2_proofs" version = "0.2.0" -source = "git+https://github.com/scroll-tech/halo2.git?branch=develop#5cf9a3726525810af41ef416e0292ec999b34030" +source = "git+https://github.com/scroll-tech/halo2.git?branch=v1.0#2f5ee1040e3cdef22e13d35865ecddce4a6130c7" dependencies = [ "ark-std", "blake2b_simd", "cfg-if 0.1.10", "crossbeam", - "ff 0.12.1", - "group 0.12.1", - "halo2curves 0.3.1 (git+https://github.com/scroll-tech/halo2curves.git?branch=0.3.1-derive-serde)", + "ff", + "group", + "halo2curves", "log", "num-bigint", "num-integer", @@ -1332,28 +1311,13 @@ dependencies = [ [[package]] name = "halo2curves" -version = "0.3.1" -source = "git+https://github.com/privacy-scaling-explorations/halo2curves?tag=0.3.1#9b67e19bca30a35208b0c1b41c1723771e2c9f49" -dependencies = [ - "ff 0.12.1", - "group 0.12.1", - "lazy_static", - "num-bigint", - "num-traits", - "pasta_curves", - "rand", - "rand_core", - "static_assertions", - "subtle", -] - -[[package]] -name = "halo2curves" -version = "0.3.1" -source = "git+https://github.com/scroll-tech/halo2curves.git?branch=0.3.1-derive-serde#969f1e44d9713ee4cd552563bd0c762c5d53b56e" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6b1142bd1059aacde1b477e0c80c142910f1ceae67fc619311d6a17428007ab" dependencies = [ - "ff 0.12.1", - "group 0.12.1", + "blake2b_simd", + "ff", + "group", "lazy_static", "num-bigint", "num-traits", @@ -1362,6 +1326,7 @@ dependencies = [ "rand", "rand_core", "serde", + "serde_arrays", "static_assertions", "subtle", ] @@ -1374,9 +1339,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.14.2" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" [[package]] name = "heck" @@ -1394,20 +1359,16 @@ dependencies = [ ] [[package]] -name = "hex" -version = "0.4.3" +name = "hermit-abi" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] -name = "hmac" -version = "0.8.1" +name = "hex" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" -dependencies = [ - "crypto-mac", - "digest 0.9.0", -] +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hmac" @@ -1418,17 +1379,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "hmac-drbg" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" -dependencies = [ - "digest 0.9.0", - "generic-array", - "hmac 0.8.1", -] - [[package]] name = "humantime" version = "2.1.0" @@ -1534,7 +1484,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", - "hashbrown 0.14.2", + "hashbrown 0.14.3", ] [[package]] @@ -1546,6 +1496,17 @@ dependencies = [ "generic-array", ] +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi 0.3.3", + "rustix", + "windows-sys 0.48.0", +] + [[package]] name = "itertools" version = "0.10.5" @@ -1569,9 +1530,9 @@ checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e" [[package]] name = "js-sys" -version = "0.3.65" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" +checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" dependencies = [ "wasm-bindgen", ] @@ -1586,7 +1547,7 @@ dependencies = [ "ecdsa", "elliptic-curve", "once_cell", - "sha2 0.10.8", + "sha2", "signature", ] @@ -1604,6 +1565,9 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin", +] [[package]] name = "libc" @@ -1618,7 +1582,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" dependencies = [ "cfg-if 1.0.0", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1632,54 +1596,6 @@ dependencies = [ "redox_syscall", ] -[[package]] -name = "libsecp256k1" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b09eff1b35ed3b33b877ced3a691fc7a481919c7e29c53c906226fcf55e2a1" -dependencies = [ - "arrayref", - "base64 0.13.1", - "digest 0.9.0", - "hmac-drbg", - "libsecp256k1-core", - "libsecp256k1-gen-ecmult", - "libsecp256k1-gen-genmult", - "rand", - "serde", - "sha2 0.9.9", - "typenum", -] - -[[package]] -name = "libsecp256k1-core" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be9b9bb642d8522a44d533eab56c16c738301965504753b03ad1de3425d5451" -dependencies = [ - "crunchy", - "digest 0.9.0", - "subtle", -] - -[[package]] -name = "libsecp256k1-gen-ecmult" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3038c808c55c87e8a172643a7d87187fc6c4174468159cb3090659d55bcb4809" -dependencies = [ - "libsecp256k1-core", -] - -[[package]] -name = "libsecp256k1-gen-genmult" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3db8d6ba2cec9eacc40e6e8ccc98931840301f1006e95647ceb2dd5c3aa06f7c" -dependencies = [ - "libsecp256k1-core", -] - [[package]] name = "linux-raw-sys" version = "0.4.11" @@ -1720,10 +1636,10 @@ dependencies = [ [[package]] name = "mpt-zktrie" version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?rev=7d9bc181953cfc6e7baf82ff0ce651281fd70a8a#7d9bc181953cfc6e7baf82ff0ce651281fd70a8a" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?rev=d14464379107ca80b6280d4b9238eeb60e1fbf15#d14464379107ca80b6280d4b9238eeb60e1fbf15" dependencies = [ "eth-types", - "halo2-mpt-circuits 0.1.0 (git+https://github.com/scroll-tech/mpt-circuit.git?tag=v0.7.0)", + "halo2-mpt-circuits 0.1.0 (git+https://github.com/scroll-tech/mpt-circuit.git?rev=a544844b071ee37ca54b7a266b8ffb7672277d76)", "halo2_proofs", "hex", "lazy_static", @@ -1908,13 +1824,13 @@ dependencies = [ [[package]] name = "pasta_curves" -version = "0.4.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc65faf8e7313b4b1fbaa9f7ca917a0eed499a9663be71477f87993604341d8" +checksum = "d3e57598f73cc7e1b2ac63c79c517b31a0877cd7c402cdcaa311b5208de7a095" dependencies = [ "blake2b_simd", - "ff 0.12.1", - "group 0.12.1", + "ff", + "group", "lazy_static", "rand", "static_assertions", @@ -1962,7 +1878,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" dependencies = [ "digest 0.10.7", - "hmac 0.12.1", + "hmac", ] [[package]] @@ -2049,19 +1965,19 @@ dependencies = [ [[package]] name = "poseidon" version = "0.2.0" -source = "git+https://github.com/scroll-tech/poseidon.git?branch=scroll-dev-0220#2fb4a2385bada39b50dce12fe50cb80d2fd33476" +source = "git+https://github.com/scroll-tech/poseidon.git?branch=sync-ff-0.13#5787dd3d2ce7a9e9601a035c396ac0c03449b54d" dependencies = [ - "group 0.12.1", - "halo2curves 0.3.1 (git+https://github.com/privacy-scaling-explorations/halo2curves?tag=0.3.1)", + "halo2curves", "subtle", ] [[package]] name = "poseidon-circuit" version = "0.1.0" -source = "git+https://github.com/scroll-tech/poseidon-circuit.git?branch=scroll-dev-0901#69524f42bdc55c581088c2fe64c2ab9a2921146b" +source = "git+https://github.com/scroll-tech/poseidon-circuit.git?branch=scroll-dev-1201#c6f058bcf3bb0c7933d1979563c414f5cc480f25" dependencies = [ "bitvec", + "ff", "halo2_proofs", "lazy_static", "log", @@ -2126,9 +2042,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" dependencies = [ "unicode-ident", ] @@ -2262,7 +2178,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" dependencies = [ - "hmac 0.12.1", + "hmac", "subtle", ] @@ -2297,6 +2213,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc-hex" version = "2.1.0" @@ -2322,7 +2244,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2391,10 +2313,10 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f9e24d2b632954ded8ab2ef9fea0a0c769ea56ea98bddbafbad22caeeadf45d" dependencies = [ - "hmac 0.12.1", + "hmac", "pbkdf2 0.11.0", "salsa20", - "sha2 0.10.8", + "sha2", ] [[package]] @@ -2419,18 +2341,27 @@ checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" [[package]] name = "serde" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" dependencies = [ "serde_derive", ] +[[package]] +name = "serde_arrays" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38636132857f68ec3d5f3eb121166d2af33cb55174c4d5ff645db6165cbef0fd" +dependencies = [ + "serde", +] + [[package]] name = "serde_derive" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", @@ -2470,19 +2401,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "sha2" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if 1.0.0", - "cpufeatures", - "digest 0.9.0", - "opaque-debug", -] - [[package]] name = "sha2" version = "0.10.8" @@ -2532,6 +2450,12 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "spki" version = "0.7.2" @@ -2637,7 +2561,7 @@ dependencies = [ "fastrand", "redox_syscall", "rustix", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2827,9 +2751,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" +checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -2837,9 +2761,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" +checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" dependencies = [ "bumpalo", "log", @@ -2852,9 +2776,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" +checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2862,9 +2786,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" +checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", @@ -2875,9 +2799,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" +checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" [[package]] name = "web-sys" @@ -2932,7 +2856,7 @@ version = "0.51.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -2941,7 +2865,16 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", ] [[package]] @@ -2950,13 +2883,28 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", ] [[package]] @@ -2965,42 +2913,84 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" + [[package]] name = "winnow" version = "0.5.19" @@ -3049,7 +3039,7 @@ checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" [[package]] name = "zktrie" version = "0.2.0" -source = "git+https://github.com/scroll-tech/zktrie.git?branch=v0.7#a130ea543d291d4b71724f91cb8a49745c593a0c" +source = "git+https://github.com/scroll-tech/zktrie.git?tag=v0.7.1#a12f2f262ad3e82301e39ecdf9bfe235befc7074" dependencies = [ "gobuild", ] diff --git a/Cargo.toml b/Cargo.toml index 6e64903c..12c3f66b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] ethers-core = "2.0.7" itertools = "0.10.5" -hash-circuit = { package = "poseidon-circuit", git = "https://github.com/scroll-tech/poseidon-circuit.git", branch = "scroll-dev-0901"} +hash-circuit = { package = "poseidon-circuit", git = "https://github.com/scroll-tech/poseidon-circuit.git", branch = "scroll-dev-1201" } halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2022_09_10" } rand = "0.8" lazy_static = "1.4.0" @@ -21,15 +21,15 @@ num-bigint = "0.4" hex = "0.4" thiserror = "1.0" log = "0.4" -env_logger = "0.9.0" -mpt-zktrie = { git = "https://github.com/scroll-tech/zkevm-circuits.git", rev = "7d9bc181953cfc6e7baf82ff0ce651281fd70a8a" } +env_logger = "0.10" +# mpt-zktrie = { git = "https://github.com/scroll-tech/zkevm-circuits.git", rev = "7d9bc181953cfc6e7baf82ff0ce651281fd70a8a" } rand_chacha = "0.3.0" criterion = { version = "0.4", optional = true} [patch."https://github.com/privacy-scaling-explorations/halo2.git"] -halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "develop" } +halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "v1.0" } [patch.crates-io] -ethers-core = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" } +ethers-core = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7", features = ["scroll"] } [features] # printout the layout of circuits for demo and some unittests @@ -38,7 +38,8 @@ default = ["halo2_proofs/mock-batch-inv", "halo2_proofs/parallel_syn"] bench = ["dep:criterion"] [dev-dependencies] -# mpt-zktrie = { path = "../scroll-circuits/zktrie" } +mpt-zktrie = { git = "https://github.com/scroll-tech/zkevm-circuits.git", rev = "d14464379107ca80b6280d4b9238eeb60e1fbf15" } +# mpt-zktrie = { path = "../zkevm-circuits/zktrie" } plotters = "0.3" bencher = "0.1" subtle = "2" diff --git a/rust-toolchain b/rust-toolchain index 44b874bf..97a0c7b3 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2022-12-10 +nightly-2023-10-27 \ No newline at end of file diff --git a/src/constraint_builder.rs b/src/constraint_builder.rs index b653a5f7..2cee7a43 100644 --- a/src/constraint_builder.rs +++ b/src/constraint_builder.rs @@ -1,6 +1,6 @@ use crate::gadgets::poseidon::PoseidonLookup; use halo2_proofs::{ - arithmetic::FieldExt, + halo2curves::ff::FromUniformBytes, plonk::{ConstraintSystem, SecondPhase}, }; use itertools::Itertools; @@ -15,7 +15,7 @@ pub use binary_query::BinaryQuery; pub use column::{AdviceColumn, FixedColumn, SecondPhaseAdviceColumn, SelectorColumn}; pub use query::Query; -pub struct ConstraintBuilder { +pub struct ConstraintBuilder + Ord> { constraints: Vec<(&'static str, Query)>, #[allow(clippy::type_complexity)] lookups: Vec<(&'static str, Vec<(Query, Query)>)>, @@ -23,7 +23,7 @@ pub struct ConstraintBuilder { conditions: Vec>, } -impl ConstraintBuilder { +impl + Ord> ConstraintBuilder { pub fn new(every_row: SelectorColumn) -> Self { Self { constraints: vec![], @@ -79,7 +79,7 @@ impl ConstraintBuilder { let mut lookup: Vec<_> = left .into_iter() .map(|q| q * condition.clone()) - .zip(right.into_iter()) + .zip(right) .collect(); // If condition is true, every_row_selector must be enabled. lookup.push((condition.into(), self.every_row_selector().into())); diff --git a/src/constraint_builder/binary_column.rs b/src/constraint_builder/binary_column.rs index c414850f..c51062d9 100644 --- a/src/constraint_builder/binary_column.rs +++ b/src/constraint_builder/binary_column.rs @@ -1,7 +1,7 @@ use super::{BinaryQuery, ConstraintBuilder, Query}; use halo2_proofs::{ - arithmetic::FieldExt, circuit::{Region, Value}, + halo2curves::ff::FromUniformBytes, plonk::ConstraintSystem, plonk::{Advice, Column}, }; @@ -10,23 +10,23 @@ use halo2_proofs::{ pub struct BinaryColumn(pub Column); impl BinaryColumn { - pub fn rotation(&self, i: i32) -> BinaryQuery { + pub fn rotation + Ord>(&self, i: i32) -> BinaryQuery { BinaryQuery(Query::Advice(self.0, i)) } - pub fn current(&self) -> BinaryQuery { + pub fn current + Ord>(&self) -> BinaryQuery { self.rotation(0) } - pub fn previous(&self) -> BinaryQuery { + pub fn previous + Ord>(&self) -> BinaryQuery { self.rotation(-1) } - pub fn next(&self) -> BinaryQuery { + pub fn next + Ord>(&self) -> BinaryQuery { self.rotation(1) } - pub fn configure( + pub fn configure + Ord>( cs: &mut ConstraintSystem, cb: &mut ConstraintBuilder, ) -> Self { @@ -38,9 +38,19 @@ impl BinaryColumn { binary_column } - pub fn assign(&self, region: &mut Region<'_, F>, offset: usize, value: bool) { + pub fn assign + Ord>( + &self, + region: &mut Region<'_, F>, + offset: usize, + value: bool, + ) { region - .assign_advice(|| "binary", self.0, offset, || Value::known(F::from(value))) + .assign_advice( + || "binary", + self.0, + offset, + || Value::known(F::from(value as u64)), + ) .expect("failed assign_advice"); } } diff --git a/src/constraint_builder/binary_query.rs b/src/constraint_builder/binary_query.rs index 9c80f967..67d6c7b3 100644 --- a/src/constraint_builder/binary_query.rs +++ b/src/constraint_builder/binary_query.rs @@ -1,6 +1,7 @@ use super::Query; use halo2_proofs::{ - arithmetic::{Field, FieldExt}, + arithmetic::Field, + halo2curves::ff::FromUniformBytes, plonk::{Expression, VirtualCells}, }; // use std::iter::Sum; @@ -9,7 +10,7 @@ use halo2_proofs::{ #[derive(Clone)] pub struct BinaryQuery(pub Query); -impl BinaryQuery { +impl + Ord> BinaryQuery { pub fn zero() -> Self { Self(Query::from(0)) } @@ -35,13 +36,13 @@ impl BinaryQuery { } } -impl BinaryQuery { +impl + Ord> BinaryQuery { pub fn run(self, meta: &mut VirtualCells<'_, F>) -> Expression { self.0.run(meta) } } -impl std::ops::Not for BinaryQuery { +impl + Ord> std::ops::Not for BinaryQuery { type Output = Self; // In general this can cause a ConstraintPoisoned. You need to add a selector column that's all ones to be safe. diff --git a/src/constraint_builder/column.rs b/src/constraint_builder/column.rs index 75d472f3..fc88d8f7 100644 --- a/src/constraint_builder/column.rs +++ b/src/constraint_builder/column.rs @@ -1,8 +1,8 @@ use super::{BinaryQuery, Query}; use halo2_proofs::plonk::Assigned; use halo2_proofs::{ - arithmetic::FieldExt, circuit::{Region, Value}, + halo2curves::ff::FromUniformBytes, plonk::{Advice, Column, Fixed}, }; use std::fmt::Debug; @@ -11,17 +11,17 @@ use std::fmt::Debug; pub struct SelectorColumn(pub Column); impl SelectorColumn { - pub fn current(self) -> BinaryQuery { + pub fn current + Ord>(self) -> BinaryQuery { self.rotation(0) } - pub fn rotation(self, i: i32) -> BinaryQuery { + pub fn rotation + Ord>(self, i: i32) -> BinaryQuery { BinaryQuery(Query::Fixed(self.0, i)) } - pub fn enable(&self, region: &mut Region<'_, F>, offset: usize) { + pub fn enable + Ord>(&self, region: &mut Region<'_, F>, offset: usize) { region - .assign_fixed(|| "selector", self.0, offset, || Value::known(F::one())) + .assign_fixed(|| "selector", self.0, offset, || Value::known(F::ONE)) .expect("failed enable selector"); } } @@ -30,19 +30,19 @@ impl SelectorColumn { pub struct FixedColumn(pub Column); impl FixedColumn { - pub fn rotation(self, i: i32) -> Query { + pub fn rotation + Ord>(self, i: i32) -> Query { Query::Fixed(self.0, i) } - pub fn current(self) -> Query { + pub fn current + Ord>(self) -> Query { self.rotation(0) } - pub fn previous(self) -> Query { + pub fn previous + Ord>(self) -> Query { self.rotation(-1) } - pub fn assign>( + pub fn assign + Ord, T: Copy + TryInto>( &self, region: &mut Region<'_, F>, offset: usize, @@ -65,27 +65,27 @@ impl FixedColumn { pub struct AdviceColumn(pub Column); impl AdviceColumn { - pub fn rotation(self, i: i32) -> Query { + pub fn rotation + Ord>(self, i: i32) -> Query { Query::Advice(self.0, i) } - pub fn current(self) -> Query { + pub fn current + Ord>(self) -> Query { self.rotation(0) } - pub fn previous(self) -> Query { + pub fn previous + Ord>(self) -> Query { self.rotation(-1) } - pub fn next(self) -> Query { + pub fn next + Ord>(self) -> Query { self.rotation(1) } - pub fn delta(self) -> Query { + pub fn delta + Ord>(self) -> Query { self.current() - self.previous() } - pub fn assign>( + pub fn assign + Ord, T: Copy + TryInto>( &self, region: &mut Region<'_, F>, offset: usize, @@ -103,7 +103,7 @@ impl AdviceColumn { .expect("failed assign_advice"); } - pub fn assign_rational( + pub fn assign_rational + Ord>( &self, region: &mut Region<'_, F>, offset: usize, @@ -119,19 +119,24 @@ impl AdviceColumn { pub struct SecondPhaseAdviceColumn(pub Column); impl SecondPhaseAdviceColumn { - fn rotation(self, i: i32) -> Query { + fn rotation + Ord>(self, i: i32) -> Query { Query::Advice(self.0, i) } - pub fn current(self) -> Query { + pub fn current + Ord>(self) -> Query { self.rotation(0) } - pub fn previous(self) -> Query { + pub fn previous + Ord>(self) -> Query { self.rotation(-1) } - pub fn assign(&self, region: &mut Region<'_, F>, offset: usize, value: Value) { + pub fn assign + Ord>( + &self, + region: &mut Region<'_, F>, + offset: usize, + value: Value, + ) { region .assign_advice(|| "second phase advice", self.0, offset, || value) .expect("failed assign_advice"); diff --git a/src/constraint_builder/query.rs b/src/constraint_builder/query.rs index 11437fe1..f435b5eb 100644 --- a/src/constraint_builder/query.rs +++ b/src/constraint_builder/query.rs @@ -1,7 +1,7 @@ use super::BinaryQuery; use halo2_proofs::{ - arithmetic::{Field, FieldExt}, - halo2curves::{bn256::Fr, group::ff::PrimeField}, + arithmetic::Field, + halo2curves::{bn256::Fr, ff::FromUniformBytes, group::ff::PrimeField}, plonk::{Advice, Challenge, Column, Expression, Fixed, VirtualCells}, poly::Rotation, }; @@ -17,7 +17,7 @@ pub enum Query { Mul(Box, Box), } -impl Query { +impl + Ord> Query { pub fn zero() -> Self { Self::from(0) } @@ -36,7 +36,7 @@ impl Query { Query::Advice(c, r) => meta.query_advice(*c, Rotation(*r)), Query::Fixed(c, r) => meta.query_fixed(*c, Rotation(*r)), Query::Challenge(c) => meta.query_challenge(*c), - Query::Neg(q) => Expression::Constant(F::zero()) - q.run(meta), + Query::Neg(q) => Expression::Constant(F::ZERO) - q.run(meta), Query::Add(q, u) => q.run(meta) + u.run(meta), Query::Mul(q, u) => q.run(meta) * u.run(meta), } @@ -47,13 +47,13 @@ impl Query { } } -impl From for Query { +impl + Ord> From for Query { fn from(x: u64) -> Self { Self::Constant(F::from(x)) } } -impl From for Query { +impl + Ord> From for Query { fn from(x: Fr) -> Self { let little_endian_bytes = x.to_repr(); let little_endian_limbs = little_endian_bytes @@ -66,7 +66,7 @@ impl From for Query { } } -impl From> for Query { +impl + Ord> From> for Query { fn from(b: BinaryQuery) -> Self { b.0 } diff --git a/src/gadgets/byte_bit.rs b/src/gadgets/byte_bit.rs index 471fa2f8..0002b55f 100644 --- a/src/gadgets/byte_bit.rs +++ b/src/gadgets/byte_bit.rs @@ -1,5 +1,5 @@ use super::super::constraint_builder::{ConstraintBuilder, FixedColumn, Query}; -use halo2_proofs::{arithmetic::FieldExt, circuit::Region, plonk::ConstraintSystem}; +use halo2_proofs::{circuit::Region, halo2curves::ff::FromUniformBytes, plonk::ConstraintSystem}; // TODO: fix name to configggggggg #[derive(Clone)] @@ -10,19 +10,19 @@ pub struct ByteBitGadget { } pub trait RangeCheck8Lookup { - fn lookup(&self) -> [Query; 1]; + fn lookup + Ord>(&self) -> [Query; 1]; } pub trait RangeCheck256Lookup { - fn lookup(&self) -> [Query; 1]; + fn lookup + Ord>(&self) -> [Query; 1]; } pub trait ByteBitLookup { - fn lookup(&self) -> [Query; 3]; + fn lookup + Ord>(&self) -> [Query; 3]; } impl ByteBitGadget { - pub fn configure( + pub fn configure + Ord>( cs: &mut ConstraintSystem, cb: &mut ConstraintBuilder, ) -> Self { @@ -30,13 +30,14 @@ impl ByteBitGadget { Self { byte, index, bit } } - pub fn assign(&self, region: &mut Region<'_, F>) { + pub fn assign + Ord>(&self, region: &mut Region<'_, F>) { let mut offset = 1; for byte in 0..256 { for index in 0..8 { self.byte.assign(region, offset, byte); self.index.assign(region, offset, index); - self.bit.assign(region, offset, byte & (1 << index) != 0); + self.bit + .assign(region, offset, (byte & (1 << index) != 0) as u64); offset += 1; } } @@ -55,19 +56,19 @@ impl ByteBitGadget { } impl RangeCheck8Lookup for ByteBitGadget { - fn lookup(&self) -> [Query; 1] { + fn lookup + Ord>(&self) -> [Query; 1] { [self.index.current()] } } impl RangeCheck256Lookup for ByteBitGadget { - fn lookup(&self) -> [Query; 1] { + fn lookup + Ord>(&self) -> [Query; 1] { [self.byte.current()] } } impl ByteBitLookup for ByteBitGadget { - fn lookup(&self) -> [Query; 3] { + fn lookup + Ord>(&self) -> [Query; 3] { [ self.byte.current(), self.index.current(), diff --git a/src/gadgets/byte_representation.rs b/src/gadgets/byte_representation.rs index f7ff1047..d71dd6a7 100644 --- a/src/gadgets/byte_representation.rs +++ b/src/gadgets/byte_representation.rs @@ -3,18 +3,17 @@ use crate::constraint_builder::{ AdviceColumn, ConstraintBuilder, Query, SecondPhaseAdviceColumn, SelectorColumn, }; use halo2_proofs::{ - arithmetic::FieldExt, circuit::{Region, Value}, - halo2curves::bn256::Fr, + halo2curves::{bn256::Fr, ff::FromUniformBytes}, plonk::ConstraintSystem, }; pub trait RlcLookup { - fn lookup(&self) -> [Query; 3]; + fn lookup + Ord>(&self) -> [Query; 3]; } pub trait BytesLookup { - fn lookup(&self) -> [Query; 2]; + fn lookup + Ord>(&self) -> [Query; 2]; } // Right the byte order is big endian, which means that e.g. proving that 0x01 fits into 3 @@ -36,7 +35,7 @@ pub struct ByteRepresentationConfig { // WARNING: it is a soundness issue if the index lookup is >= 31 (i.e. the value can // overflow in the field if it has 32 or more bytes). impl RlcLookup for ByteRepresentationConfig { - fn lookup(&self) -> [Query; 3] { + fn lookup + Ord>(&self) -> [Query; 3] { [ self.value.current(), self.index.current(), @@ -46,13 +45,13 @@ impl RlcLookup for ByteRepresentationConfig { } impl BytesLookup for ByteRepresentationConfig { - fn lookup(&self) -> [Query; 2] { + fn lookup + Ord>(&self) -> [Query; 2] { [self.value.current(), self.index.current()] } } impl ByteRepresentationConfig { - pub fn configure( + pub fn configure + Ord>( cs: &mut ConstraintSystem, cb: &mut ConstraintBuilder, range_check: &impl RangeCheck256Lookup, @@ -92,7 +91,7 @@ impl ByteRepresentationConfig { } } - pub fn assign( + pub fn assign + Ord>( &self, region: &mut Region<'_, F>, u32s: &[u32], @@ -111,8 +110,8 @@ impl ByteRepresentationConfig { let mut offset = 1; for byte_representation in byte_representations { - let mut value = F::zero(); - let mut rlc = Value::known(F::zero()); + let mut value = F::ZERO; + let mut rlc = Value::known(F::ZERO); for (index, byte) in byte_representation.iter().enumerate() { let byte = F::from(u64::from(*byte)); self.byte.assign(region, offset, byte); diff --git a/src/gadgets/canonical_representation.rs b/src/gadgets/canonical_representation.rs index e96b6c48..c5635704 100644 --- a/src/gadgets/canonical_representation.rs +++ b/src/gadgets/canonical_representation.rs @@ -3,25 +3,25 @@ use super::super::constraint_builder::{ SelectorColumn, }; use super::{byte_bit::RangeCheck256Lookup, is_zero::IsZeroGadget, rlc_randomness::RlcRandomness}; +use ethers_core::k256::elliptic_curve::PrimeField; use ethers_core::types::U256; -use halo2_proofs::circuit::Layouter; -use halo2_proofs::plonk::Error; use halo2_proofs::{ - arithmetic::{Field, FieldExt}, + arithmetic::Field, circuit::{Region, Value}, halo2curves::bn256::Fr, plonk::ConstraintSystem, }; +use halo2_proofs::{circuit::Layouter, halo2curves::ff::FromUniformBytes, plonk::Error}; use itertools::Itertools; use num_traits::Zero; pub trait CanonicalRepresentationLookup { - fn lookup(&self) -> [Query; 3]; + fn lookup + Ord>(&self) -> [Query; 3]; } // Lookup to prove that Rlc(x: Fr) = y pub trait FrRlcLookup { - fn lookup(&self) -> [Query; 2]; + fn lookup + Ord>(&self) -> [Query; 2]; } #[derive(Clone)] @@ -312,7 +312,7 @@ impl CanonicalRepresentationConfig { } impl CanonicalRepresentationLookup for CanonicalRepresentationConfig { - fn lookup(&self) -> [Query; 3] { + fn lookup + Ord>(&self) -> [Query; 3] { [ self.value.current(), self.index.current(), @@ -322,7 +322,7 @@ impl CanonicalRepresentationLookup for CanonicalRepresentationConfig { } impl FrRlcLookup for CanonicalRepresentationConfig { - fn lookup(&self) -> [Query; 2] { + fn lookup + Ord>(&self) -> [Query; 2] { [ self.value.current() * self.index_is_31.current(), self.rlc.current() * self.index_is_31.current(), diff --git a/src/gadgets/is_zero.rs b/src/gadgets/is_zero.rs index 9ae835ee..34ecdd48 100644 --- a/src/gadgets/is_zero.rs +++ b/src/gadgets/is_zero.rs @@ -1,6 +1,7 @@ use crate::constraint_builder::{AdviceColumn, BinaryQuery, ConstraintBuilder, Query}; -use halo2_proofs::plonk::Assigned; -use halo2_proofs::{arithmetic::FieldExt, circuit::Region, plonk::ConstraintSystem}; +use halo2_proofs::{ + circuit::Region, halo2curves::ff::FromUniformBytes, plonk::Assigned, plonk::ConstraintSystem, +}; use std::fmt::Debug; #[derive(Clone, Copy)] @@ -10,15 +11,15 @@ pub struct IsZeroGadget { } impl IsZeroGadget { - pub fn current(self) -> BinaryQuery { + pub fn current + Ord>(self) -> BinaryQuery { BinaryQuery(Query::one() - self.value.current() * self.inverse_or_zero.current()) } - pub fn previous(self) -> BinaryQuery { + pub fn previous + Ord>(self) -> BinaryQuery { BinaryQuery(Query::one() - self.value.previous() * self.inverse_or_zero.previous()) } - pub fn assign>( + pub fn assign + Ord, T: Copy + TryInto>( &self, region: &mut Region<'_, F>, offset: usize, @@ -35,7 +36,7 @@ impl IsZeroGadget { } // TODO: get rid of assign method in favor of it. - pub fn assign_value_and_inverse>( + pub fn assign_value_and_inverse + Ord, T: Copy + TryInto>( &self, region: &mut Region<'_, F>, offset: usize, @@ -47,7 +48,7 @@ impl IsZeroGadget { self.assign(region, offset, value); } - pub fn configure( + pub fn configure + Ord>( cs: &mut ConstraintSystem, cb: &mut ConstraintBuilder, value: AdviceColumn, // TODO: make this a query once Query is clonable/copyable..... diff --git a/src/gadgets/key_bit.rs b/src/gadgets/key_bit.rs index aef0fa75..3c5679dd 100644 --- a/src/gadgets/key_bit.rs +++ b/src/gadgets/key_bit.rs @@ -5,12 +5,14 @@ use super::{ use crate::constraint_builder::{AdviceColumn, ConstraintBuilder, Query}; use halo2_proofs::circuit::Layouter; use halo2_proofs::{ - arithmetic::FieldExt, circuit::Region, halo2curves::bn256::Fr, plonk::ConstraintSystem, + circuit::Region, + halo2curves::{bn256::Fr, ff::FromUniformBytes}, + plonk::ConstraintSystem, }; use itertools::Itertools; pub trait KeyBitLookup { - fn lookup(&self) -> [Query; 3]; + fn lookup + Ord>(&self) -> [Query; 3]; } #[derive(Clone)] @@ -27,7 +29,7 @@ pub struct KeyBitConfig { } impl KeyBitConfig { - pub fn configure( + pub fn configure + Ord>( cs: &mut ConstraintSystem, cb: &mut ConstraintBuilder, representation: &impl CanonicalRepresentationLookup, @@ -165,7 +167,7 @@ impl KeyBitConfig { } impl KeyBitLookup for KeyBitConfig { - fn lookup(&self) -> [Query; 3] { + fn lookup + Ord>(&self) -> [Query; 3] { [ self.value.current(), self.index.current(), diff --git a/src/gadgets/mpt_update.rs b/src/gadgets/mpt_update.rs index 75da4ec5..6a7deb4a 100644 --- a/src/gadgets/mpt_update.rs +++ b/src/gadgets/mpt_update.rs @@ -30,9 +30,9 @@ use crate::{ use ethers_core::types::Address; use halo2_proofs::circuit::Layouter; use halo2_proofs::{ - arithmetic::{Field, FieldExt}, + arithmetic::Field, circuit::{Region, Value}, - halo2curves::bn256::Fr, + halo2curves::{bn256::Fr, ff::FromUniformBytes, group::ff::PrimeField}, plonk::ConstraintSystem, }; use itertools::{izip, Itertools}; @@ -45,7 +45,7 @@ lazy_static! { domain_hash(Fr::zero(), *ZERO_PAIR_HASH, HashDomain::AccountFields); } -pub trait MptUpdateLookup { +pub trait MptUpdateLookup + Ord> { fn lookup(&self) -> [Query; 7]; } @@ -77,7 +77,7 @@ pub struct MptUpdateConfig { is_zero_gadgets: [IsZeroGadget; 4], // can be 3 } -impl MptUpdateLookup for MptUpdateConfig { +impl + Ord> MptUpdateLookup for MptUpdateConfig { fn lookup(&self) -> [Query; 7] { let is_start = || self.segment_type.current_matches(&[SegmentType::Start]); // Note that one non-start rows, all 7 queries will be 0. This corresponds to a valid @@ -105,7 +105,7 @@ impl MptUpdateLookup for MptUpdateConfig { } impl MptUpdateConfig { - pub fn configure( + pub fn configure + Ord>( cs: &mut ConstraintSystem, cb: &mut ConstraintBuilder, poseidon: &impl PoseidonLookup, @@ -940,27 +940,27 @@ impl MptUpdateConfig { } } -fn old_left(config: &MptUpdateConfig) -> Query { +fn old_left + Ord>(config: &MptUpdateConfig) -> Query { config.direction.current() * config.sibling.current() + (Query::one() - config.direction.current()) * config.old_hash.current() } -fn old_right(config: &MptUpdateConfig) -> Query { +fn old_right + Ord>(config: &MptUpdateConfig) -> Query { config.direction.current() * config.old_hash.current() + (Query::one() - config.direction.current()) * config.sibling.current() } -fn new_left(config: &MptUpdateConfig) -> Query { +fn new_left + Ord>(config: &MptUpdateConfig) -> Query { config.direction.current() * config.sibling.current() + (Query::one() - config.direction.current()) * config.new_hash.current() } -fn new_right(config: &MptUpdateConfig) -> Query { +fn new_right + Ord>(config: &MptUpdateConfig) -> Query { config.direction.current() * config.new_hash.current() + (Query::one() - config.direction.current()) * config.sibling.current() } -fn configure_segment_transitions( +fn configure_segment_transitions + Ord>( cb: &mut ConstraintBuilder, segment: &OneHot, proof: MPTProofType, @@ -980,7 +980,7 @@ fn configure_segment_transitions( } } -fn configure_common_path( +fn configure_common_path + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, poseidon: &impl PoseidonLookup, @@ -1179,7 +1179,7 @@ fn configure_common_path( ); } -fn configure_extension_old( +fn configure_extension_old + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, poseidon: &impl PoseidonLookup, @@ -1266,7 +1266,7 @@ fn configure_extension_old( ); } -fn configure_extension_new( +fn configure_extension_new + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, poseidon: &impl PoseidonLookup, @@ -1353,7 +1353,7 @@ fn configure_extension_new( ); } -fn configure_nonce( +fn configure_nonce + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, bytes: &impl BytesLookup, @@ -1483,7 +1483,7 @@ fn configure_nonce( } } -fn configure_code_size( +fn configure_code_size + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, bytes: &impl BytesLookup, @@ -1567,7 +1567,7 @@ fn configure_code_size( } } -fn configure_balance( +fn configure_balance + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, poseidon: &impl PoseidonLookup, @@ -1696,7 +1696,7 @@ fn configure_balance( } } -fn configure_poseidon_code_hash( +fn configure_poseidon_code_hash + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, ) { @@ -1727,7 +1727,7 @@ fn configure_poseidon_code_hash( } } -fn configure_keccak_code_hash( +fn configure_keccak_code_hash + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, poseidon: &impl PoseidonLookup, @@ -1810,7 +1810,7 @@ fn configure_keccak_code_hash( } } -fn configure_storage( +fn configure_storage + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, poseidon: &impl PoseidonLookup, @@ -1903,7 +1903,7 @@ fn configure_storage( } } -fn configure_empty_storage( +fn configure_empty_storage + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, poseidon: &impl PoseidonLookup, @@ -1984,7 +1984,7 @@ fn configure_empty_storage( } } -fn configure_empty_account( +fn configure_empty_account + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, poseidon: &impl PoseidonLookup, diff --git a/src/gadgets/mpt_update/nonexistence_proof.rs b/src/gadgets/mpt_update/nonexistence_proof.rs index ad657814..d6677393 100644 --- a/src/gadgets/mpt_update/nonexistence_proof.rs +++ b/src/gadgets/mpt_update/nonexistence_proof.rs @@ -1,11 +1,12 @@ +use halo2_proofs::halo2curves::ff::FromUniformBytes; + use crate::{ constraint_builder::{AdviceColumn, ConstraintBuilder, Query, SecondPhaseAdviceColumn}, gadgets::{is_zero::IsZeroGadget, poseidon::PoseidonLookup}, types::HashDomain, }; -use halo2_proofs::arithmetic::FieldExt; -pub fn configure( +pub fn configure + Ord>( cb: &mut ConstraintBuilder, value: SecondPhaseAdviceColumn, key: AdviceColumn, diff --git a/src/gadgets/mpt_update/word_rlc.rs b/src/gadgets/mpt_update/word_rlc.rs index ec7f1153..bb2de094 100644 --- a/src/gadgets/mpt_update/word_rlc.rs +++ b/src/gadgets/mpt_update/word_rlc.rs @@ -7,14 +7,13 @@ use crate::{ types::HashDomain, util::{rlc, u256_hi_lo}, }; -use ethers_core::types::U256; +use ethers_core::{k256::elliptic_curve::PrimeField, types::U256}; use halo2_proofs::{ - arithmetic::FieldExt, circuit::{Region, Value}, - halo2curves::bn256::Fr, + halo2curves::{bn256::Fr, ff::FromUniformBytes}, }; -pub fn configure( +pub fn configure + Ord>( cb: &mut ConstraintBuilder, [word_hash, high, low]: [AdviceColumn; 3], [rlc_word, rlc_high, rlc_low]: [SecondPhaseAdviceColumn; 3], diff --git a/src/gadgets/one_hot.rs b/src/gadgets/one_hot.rs index d33dd0ad..1d5c9927 100644 --- a/src/gadgets/one_hot.rs +++ b/src/gadgets/one_hot.rs @@ -1,5 +1,5 @@ use crate::constraint_builder::{BinaryColumn, BinaryQuery, ConstraintBuilder, Query}; -use halo2_proofs::{arithmetic::FieldExt, circuit::Region, plonk::ConstraintSystem}; +use halo2_proofs::{circuit::Region, halo2curves::ff::FromUniformBytes, plonk::ConstraintSystem}; use std::{cmp::Eq, collections::BTreeMap, hash::Hash}; use strum::IntoEnumIterator; @@ -12,7 +12,7 @@ pub struct OneHot { } impl OneHot { - pub fn configure( + pub fn configure + Ord>( cs: &mut ConstraintSystem, cb: &mut ConstraintBuilder, ) -> Self { @@ -28,25 +28,30 @@ impl OneHot { config } - pub fn assign(&self, region: &mut Region<'_, F>, offset: usize, value: T) { + pub fn assign + Ord>( + &self, + region: &mut Region<'_, F>, + offset: usize, + value: T, + ) { if let Some(c) = self.columns.get(&value) { c.assign(region, offset, true) } } - pub fn previous_matches(&self, values: &[T]) -> BinaryQuery { + pub fn previous_matches + Ord>(&self, values: &[T]) -> BinaryQuery { self.matches(values, -1) } - pub fn current_matches(&self, values: &[T]) -> BinaryQuery { + pub fn current_matches + Ord>(&self, values: &[T]) -> BinaryQuery { self.matches(values, 0) } - pub fn next_matches(&self, values: &[T]) -> BinaryQuery { + pub fn next_matches + Ord>(&self, values: &[T]) -> BinaryQuery { self.matches(values, 1) } - fn matches(&self, values: &[T], r: i32) -> BinaryQuery { + fn matches + Ord>(&self, values: &[T], r: i32) -> BinaryQuery { let query = values .iter() .map(|v| { @@ -59,7 +64,7 @@ impl OneHot { BinaryQuery(query) } - pub fn current(&self) -> Query { + pub fn current + Ord>(&self) -> Query { T::iter().enumerate().fold(Query::zero(), |acc, (i, t)| { acc + Query::from(u64::try_from(i).unwrap()) * self @@ -69,7 +74,7 @@ impl OneHot { }) } - pub fn previous(&self) -> Query { + pub fn previous + Ord>(&self) -> Query { T::iter().enumerate().fold(Query::zero(), |acc, (i, t)| { acc + Query::from(u64::try_from(i).unwrap()) * self @@ -79,7 +84,7 @@ impl OneHot { }) } - fn sum(&self, r: i32) -> BinaryQuery { + fn sum + Ord>(&self, r: i32) -> BinaryQuery { BinaryQuery( self.columns .values() diff --git a/src/gadgets/poseidon.rs b/src/gadgets/poseidon.rs index e41661d1..d8c9f055 100644 --- a/src/gadgets/poseidon.rs +++ b/src/gadgets/poseidon.rs @@ -1,9 +1,7 @@ use crate::constraint_builder::{AdviceColumn, FixedColumn}; use halo2_proofs::plonk::{Advice, Column, Fixed}; #[cfg(any(test, feature = "bench"))] -use halo2_proofs::{ - arithmetic::FieldExt, circuit::Region, halo2curves::bn256::Fr, plonk::ConstraintSystem, -}; +use halo2_proofs::{circuit::Region, halo2curves::bn256::Fr, plonk::ConstraintSystem}; #[cfg(any(test, feature = "bench"))] use hash_circuit::hash::Hashable; @@ -36,7 +34,9 @@ pub struct PoseidonTable { #[cfg(any(test, feature = "bench"))] impl PoseidonTable { - pub fn configure(cs: &mut ConstraintSystem) -> Self { + pub fn configure + Ord>( + cs: &mut ConstraintSystem, + ) -> Self { let [hash, left, right, control, domain_spec, head_mark] = [0; 6].map(|_| AdviceColumn(cs.advice_column())); Self { diff --git a/src/gadgets/rlc_randomness.rs b/src/gadgets/rlc_randomness.rs index 84710221..d367448d 100644 --- a/src/gadgets/rlc_randomness.rs +++ b/src/gadgets/rlc_randomness.rs @@ -1,7 +1,7 @@ use crate::constraint_builder::Query; use halo2_proofs::{ - arithmetic::FieldExt, circuit::{Layouter, Value}, + halo2curves::ff::FromUniformBytes, plonk::{Challenge, ConstraintSystem, FirstPhase}, }; @@ -9,7 +9,7 @@ use halo2_proofs::{ pub struct RlcRandomness(pub Challenge); impl RlcRandomness { - pub fn configure(cs: &mut ConstraintSystem) -> Self { + pub fn configure + Ord>(cs: &mut ConstraintSystem) -> Self { // TODO: this is a hack so that we don't get a "'No Column is // used in phase Phase(0) while allocating a new "Challenge usable after // phase Phase(0)" error. @@ -19,11 +19,11 @@ impl RlcRandomness { Self(cs.challenge_usable_after(FirstPhase)) } - pub fn query(&self) -> Query { + pub fn query + Ord>(&self) -> Query { Query::Challenge(self.0) } - pub fn value(&self, layouter: &impl Layouter) -> Value { + pub fn value + Ord>(&self, layouter: &impl Layouter) -> Value { layouter.get_challenge(self.0) } } diff --git a/src/mpt.rs b/src/mpt.rs index 6ba36ca6..9dc4c23c 100644 --- a/src/mpt.rs +++ b/src/mpt.rs @@ -16,9 +16,8 @@ use crate::{ types::Proof, }; use halo2_proofs::{ - arithmetic::FieldExt, circuit::Layouter, - halo2curves::bn256::Fr, + halo2curves::{bn256::Fr, ff::FromUniformBytes}, plonk::{Challenge, ConstraintSystem, Error, Expression, VirtualCells}, }; use itertools::Itertools; @@ -254,9 +253,12 @@ impl MptCircuitConfig { ) } - pub fn lookup_exprs(&self, meta: &mut VirtualCells<'_, F>) -> [Expression; 8] { + pub fn lookup_exprs + Ord>( + &self, + meta: &mut VirtualCells<'_, F>, + ) -> [Expression; 8] { std::iter::once(Query::from(self.selector.current())) - .chain(self.mpt_update.lookup().into_iter()) + .chain(self.mpt_update.lookup()) .map(|q| q.run(meta)) .collect::>() .try_into() diff --git a/src/tests.rs b/src/tests.rs index 38a92797..da524ee4 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -75,7 +75,7 @@ fn verifying_key_constant() { N_ROWS, vec![( MPTProofType::BalanceChanged, - serde_json::from_str(&include_str!( + serde_json::from_str(include_str!( "traces/empty_account_type_1_balance_update.json" )) .unwrap(), @@ -164,8 +164,8 @@ fn empty_account_type_2() { #[test] fn empty_account_proofs_for_zero_value_updates() { let traces: [SMTTrace; 2] = [ - serde_json::from_str(&include_str!("traces/empty_account_type_1.json")).unwrap(), - serde_json::from_str(&include_str!("traces/empty_account_type_2.json")).unwrap(), + serde_json::from_str(include_str!("traces/empty_account_type_1.json")).unwrap(), + serde_json::from_str(include_str!("traces/empty_account_type_2.json")).unwrap(), ]; for trace in traces { for proof_type in [ @@ -769,26 +769,26 @@ fn multiple_updates() { let witness = vec![ ( MPTProofType::StorageChanged, - serde_json::from_str(&include_str!("traces/empty_storage_type_1_update_c.json")) + serde_json::from_str(include_str!("traces/empty_storage_type_1_update_c.json")) .unwrap(), ), ( MPTProofType::CodeHashExists, - serde_json::from_str(&include_str!( + serde_json::from_str(include_str!( "traces/existing_account_keccak_codehash_update.json" )) .unwrap(), ), ( MPTProofType::BalanceChanged, - serde_json::from_str(&include_str!( + serde_json::from_str(include_str!( "traces/empty_account_type_2_balance_update.json" )) .unwrap(), ), ( MPTProofType::AccountDoesNotExist, - serde_json::from_str(&include_str!("traces/empty_account_type_1.json")).unwrap(), + serde_json::from_str(include_str!("traces/empty_account_type_1.json")).unwrap(), ), ]; mock_prove(witness); @@ -853,7 +853,7 @@ fn depth_1_type_1_storage() { // because of an insertion or deletion. let trace: SMTTrace = - serde_json::from_str(&include_str!("traces/depth_1_type_1_storage.json")).unwrap(); + serde_json::from_str(include_str!("traces/depth_1_type_1_storage.json")).unwrap(); mock_prove(vec![(MPTProofType::StorageChanged, trace.clone())]); mock_prove(vec![(MPTProofType::StorageChanged, reverse(trace))]); } @@ -1020,7 +1020,7 @@ fn create_name_registrator_per_txs_not_enough_gas_d0_g0_v0() { // These mpt updates are by the test case at // https://github.com/ethereum/tests/blob/747a4828f36c5fc8ab4f288d1cf4f1fe6662f3d6/src/GeneralStateTestsFiller/stCallCreateCallCodeTest/createNameRegistratorPerTxsNotEnoughGasFiller.json mock_prove( - serde_json::from_str(&include_str!( + serde_json::from_str(include_str!( "traces/createNameRegistratorPerTxsNotEnoughGas_d0_g0_v0.json" )) .unwrap(), @@ -1062,7 +1062,7 @@ fn test_n_rows_required() { #[test] fn verify_benchmark_trace() { let witness: Vec<(MPTProofType, SMTTrace)> = - serde_json::from_str(&include_str!("../benches/traces.json")).unwrap(); + serde_json::from_str(include_str!("../benches/traces.json")).unwrap(); let proofs: Vec<_> = witness.clone().into_iter().map(Proof::from).collect(); let n_rows_required = MptCircuitConfig::n_rows_required(&proofs); diff --git a/src/types.rs b/src/types.rs index 7bda6afa..e39795fe 100644 --- a/src/types.rs +++ b/src/types.rs @@ -7,8 +7,11 @@ use crate::{ }, MPTProofType, }; -use ethers_core::types::{Address, U256}; -use halo2_proofs::{arithmetic::FieldExt, halo2curves::bn256::Fr}; +use ethers_core::{ + k256::elliptic_curve::PrimeField, + types::{Address, U256}, +}; +use halo2_proofs::halo2curves::bn256::Fr; use itertools::{EitherOrBoth, Itertools}; use num_bigint::BigUint; use num_traits::identities::Zero; @@ -822,12 +825,12 @@ impl Proof { assert_eq!( self.old_account_hash_traces[5][2], - self.address_hash_traces.get(0).unwrap().2 + self.address_hash_traces.first().unwrap().2 ); assert_eq!( self.new_account_hash_traces[5][2], - self.address_hash_traces.get(0).unwrap().3 + self.address_hash_traces.first().unwrap().3 ); if let Some(old_leaf) = self.leafs[0] { assert_eq!( diff --git a/src/types/storage.rs b/src/types/storage.rs index fa5b43e6..be841be3 100644 --- a/src/types/storage.rs +++ b/src/types/storage.rs @@ -5,8 +5,8 @@ use crate::{ types::{trie::TrieRows, HashDomain}, util::{domain_hash, fr, storage_key_hash, u256_from_hex, u256_hi_lo}, }; -use ethers_core::types::U256; -use halo2_proofs::{arithmetic::FieldExt, halo2curves::bn256::Fr}; +use ethers_core::{k256::elliptic_curve::PrimeField, types::U256}; +use halo2_proofs::halo2curves::bn256::Fr; #[derive(Clone, Debug)] pub enum StorageProof { diff --git a/src/types/trie.rs b/src/types/trie.rs index b948ef34..4ea7292d 100644 --- a/src/types/trie.rs +++ b/src/types/trie.rs @@ -255,18 +255,18 @@ impl TrieRows { ); } PathType::ExtensionOld => { - self.0 - .get(i + 1) - .map(|row| assert_eq!(row.path_type, PathType::ExtensionOld)); + if let Some(row) = self.0.get(i + 1) { + assert_eq!(row.path_type, PathType::ExtensionOld); + } assert_eq!( domain_hash(old_left, old_right, row.domain), expected_old_hash ); } PathType::ExtensionNew => { - self.0 - .get(i + 1) - .map(|row| assert_eq!(row.path_type, PathType::ExtensionNew)); + if let Some(row) = self.0.get(i + 1) { + assert_eq!(row.path_type, PathType::ExtensionNew); + } assert_eq!( domain_hash(new_left, new_right, row.domain), expected_new_hash diff --git a/src/util.rs b/src/util.rs index 9a366b38..29a63c05 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,8 +1,8 @@ use crate::{constraint_builder::Query, serde::HexBytes, types::HashDomain}; use ethers_core::types::{Address, U256}; use halo2_proofs::{ - arithmetic::{Field, FieldExt}, - halo2curves::bn256::Fr, + arithmetic::Field, + halo2curves::{bn256::Fr, ff::FromUniformBytes, group::ff::PrimeField}, }; use hash_circuit::hash::Hashable; use num_bigint::BigUint; @@ -112,7 +112,10 @@ pub fn check_domain_consistency(before: HashDomain, after: HashDomain, direction } } -pub fn lagrange_polynomial(argument: Query, points: &[(Fr, Query)]) -> Query { +pub fn lagrange_polynomial + Ord>( + argument: Query, + points: &[(Fr, Query)], +) -> Query { let x_coordinates = points.iter().map(|p| p.0); let mut basis_polynomials = vec![]; for (i, xi) in x_coordinates.clone().enumerate() {