diff --git a/.gitignore b/.gitignore index 31a5ddfa..21ad0a9e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,4 @@ /layouts .vscode .cargo -Cargo.lock -*.png \ No newline at end of file +*.png diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 00000000..cab9efe6 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,2906 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aes" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac1f845298e95f983ff1944b728ae08b8cebab80d684f0a832ed0fc74dfa27e2" +dependencies = [ + "cfg-if 1.0.0", + "cipher", + "cpufeatures", +] + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" + +[[package]] +name = "ark-std" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df2c09229cbc5a028b1d70e00fdb2acee28b1055dfb5ca73eea49c5a25c4e7c" +dependencies = [ + "num-traits", + "rand", +] + +[[package]] +name = "arrayref" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[package]] +name = "async-trait" +version = "0.1.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "auto_impl" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fee3da8ef1276b0bee5dd1c7258010d8fffd31801447323115a25560e1327b89" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "base16ct" +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.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bech32" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" + +[[package]] +name = "bencher" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dfdb4953a096c551ce9ace855a604d702e6e62d77fac690575ae347571717f5" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "blake2b_simd" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23285ad32269793932e830392f2fe2f83e26488fd3ec778883a93c8323735780" +dependencies = [ + "arrayref", + "arrayvec", + "constant_time_eq", +] + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "block-padding", + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-padding" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" + +[[package]] +name = "bs58" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5353f36341f7451062466f0b755b96ac3a9547e4d7f6b70d603fc721a7d7896" +dependencies = [ + "sha2 0.10.8", + "tinyvec", +] + +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + +[[package]] +name = "byte-slice-cast" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" + +[[package]] +name = "bytemuck" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +dependencies = [ + "serde", +] + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets", +] + +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] +name = "cmake" +version = "0.1.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" +dependencies = [ + "cc", +] + +[[package]] +name = "coins-bip32" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b6be4a5df2098cd811f3194f64ddb96c267606bffd9689ac7b0160097b01ad3" +dependencies = [ + "bs58", + "coins-core", + "digest 0.10.7", + "hmac 0.12.1", + "k256", + "serde", + "sha2 0.10.8", + "thiserror", +] + +[[package]] +name = "coins-bip39" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db8fba409ce3dc04f7d804074039eb68b960b0829161f8e06c95fea3f122528" +dependencies = [ + "bitvec", + "coins-bip32", + "hmac 0.12.1", + "once_cell", + "pbkdf2 0.12.2", + "rand", + "sha2 0.10.8", + "thiserror", +] + +[[package]] +name = "coins-core" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5286a0843c21f8367f7be734f89df9b822e0321d8bcce8d6e735aadff7d74979" +dependencies = [ + "base64 0.21.4", + "bech32", + "bs58", + "digest 0.10.7", + "generic-array", + "hex", + "ripemd", + "serde", + "serde_derive", + "sha2 0.10.8", + "sha3 0.10.8", + "thiserror", +] + +[[package]] +name = "color_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + +[[package]] +name = "const-cstr" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed3d0b5ff30645a68f35ece8cea4556ca14ef8a1651455f789a099a0513532a6" + +[[package]] +name = "const-oid" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" + +[[package]] +name = "constant_time_eq" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" + +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" + +[[package]] +name = "core-graphics" +version = "0.22.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-graphics-types", + "foreign-types", + "libc", +] + +[[package]] +name = "core-graphics-types" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bb142d41022986c1d8ff29103a1411c8a3dfad3552f87a4f8dc50d61d4f4e33" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "libc", +] + +[[package]] +name = "core-text" +version = "19.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d74ada66e07c1cefa18f8abfba765b486f250de2e4a999e5727fc0dd4b4a25" +dependencies = [ + "core-foundation", + "core-graphics", + "foreign-types", + "libc", +] + +[[package]] +name = "cpufeatures" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "crossbeam" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2801af0d36612ae591caa9568261fddce32ce6e08a7275ea334a06a4ad021a2c" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +dependencies = [ + "autocfg", + "cfg-if 1.0.0", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-queue" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-bigint" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "740fe28e594155f10cfc383984cbefd529d7396050557148f79cb0f621204124" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" +dependencies = [ + "cipher", +] + +[[package]] +name = "darling" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" +dependencies = [ + "darling_core 0.10.2", + "darling_macro 0.10.2", +] + +[[package]] +name = "darling" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" +dependencies = [ + "darling_core 0.13.4", + "darling_macro 0.13.4", +] + +[[package]] +name = "darling_core" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.9.3", + "syn 1.0.109", +] + +[[package]] +name = "darling_core" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.10.0", + "syn 1.0.109", +] + +[[package]] +name = "darling_macro" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" +dependencies = [ + "darling_core 0.10.2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "darling_macro" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" +dependencies = [ + "darling_core 0.13.4", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "der" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "derive_builder" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2658621297f2cf68762a6f7dc0bb7e1ff2cfd6583daef8ee0fed6f7ec468ec0" +dependencies = [ + "darling 0.10.2", + "derive_builder_core", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "derive_builder_core" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2791ea3e372c8495c0bc2033991d76b512cd799d07491fbd6890124db9458bef" +dependencies = [ + "darling 0.10.2", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if 1.0.0", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "dlib" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" +dependencies = [ + "libloading", +] + +[[package]] +name = "dwrote" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439a1c2ba5611ad3ed731280541d36d2e9c4ac5e7fb818a27b604bdc5a6aa65b" +dependencies = [ + "lazy_static", + "libc", + "winapi", + "wio", +] + +[[package]] +name = "ecdsa" +version = "0.16.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4b1e0c257a9e9f25f90ff76d7a68360ed497ee519c8e428d1825ef0000799d4" +dependencies = [ + "der", + "digest 0.10.7", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "either" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" + +[[package]] +name = "elliptic-curve" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d97ca172ae9dc9f9b779a6e3a65d308f2af74e5b8c921299075bdb4a0370e914" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest 0.10.7", + "ff 0.13.0", + "generic-array", + "group 0.13.0", + "pkcs8", + "rand_core", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "env_logger" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "eth-keystore" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fda3bf123be441da5260717e0661c25a2fd9cb2b2c1d20bf2e05580047158ab" +dependencies = [ + "aes", + "ctr", + "digest 0.10.7", + "hex", + "hmac 0.12.1", + "pbkdf2 0.11.0", + "rand", + "scrypt", + "serde", + "serde_json", + "sha2 0.10.8", + "sha3 0.10.8", + "thiserror", + "uuid", +] + +[[package]] +name = "eth-types" +version = "0.1.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?rev=7d9bc181953cfc6e7baf82ff0ce651281fd70a8a#7d9bc181953cfc6e7baf82ff0ce651281fd70a8a" +dependencies = [ + "ethers-core", + "ethers-signers", + "halo2_proofs", + "hex", + "itertools", + "lazy_static", + "libsecp256k1", + "num", + "num-bigint", + "once_cell", + "poseidon-circuit", + "regex", + "serde", + "serde_json", + "serde_with", + "sha3 0.10.8", + "strum", + "strum_macros", + "subtle", + "uint", +] + +[[package]] +name = "ethabi" +version = "18.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7413c5f74cc903ea37386a8965a936cbeb334bd270862fdece542c1b2dcbc898" +dependencies = [ + "ethereum-types", + "hex", + "once_cell", + "regex", + "serde", + "serde_json", + "sha3 0.10.8", + "thiserror", + "uint", +] + +[[package]] +name = "ethbloom" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c22d4b5885b6aa2fe5e8b9329fb8d232bf739e434e6b87347c63bdd00c120f60" +dependencies = [ + "crunchy", + "fixed-hash", + "impl-codec", + "impl-rlp", + "impl-serde", + "scale-info", + "tiny-keccak", +] + +[[package]] +name = "ethereum-types" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d215cbf040552efcbe99a38372fe80ab9d00268e20012b79fcd0f073edd8ee" +dependencies = [ + "ethbloom", + "fixed-hash", + "impl-codec", + "impl-rlp", + "impl-serde", + "primitive-types", + "scale-info", + "uint", +] + +[[package]] +name = "ethers-core" +version = "2.0.7" +source = "git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7#e32dfd62e7cdec31160b91c5a646883594a586ba" +dependencies = [ + "arrayvec", + "bytes", + "chrono", + "elliptic-curve", + "ethabi", + "generic-array", + "hex", + "k256", + "num_enum", + "open-fastrlp", + "rand", + "rlp", + "serde", + "serde_json", + "strum", + "tempfile", + "thiserror", + "tiny-keccak", + "unicode-xid", +] + +[[package]] +name = "ethers-signers" +version = "2.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02c4b7e15f212fa7cc2e1251868320221d4ff77a3d48068e69f47ce1c491df2d" +dependencies = [ + "async-trait", + "coins-bip32", + "coins-bip39", + "elliptic-curve", + "eth-keystore", + "ethers-core", + "hex", + "rand", + "sha2 0.10.8", + "thiserror", + "tracing", +] + +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + +[[package]] +name = "fdeflate" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d329bdeac514ee06249dabc27877490f17f5d371ec693360768b838e19f3ae10" +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 = [ + "rand_core", + "subtle", +] + +[[package]] +name = "fixed-hash" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" +dependencies = [ + "byteorder", + "rand", + "rustc-hex", + "static_assertions", +] + +[[package]] +name = "flate2" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "float-ord" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bad48618fdb549078c333a7a8528acb57af271d0433bdecd523eb620628364e" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "font-kit" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21fe28504d371085fae9ac7a3450f0b289ab71e07c8e57baa3fb68b9e57d6ce5" +dependencies = [ + "bitflags 1.3.2", + "byteorder", + "core-foundation", + "core-graphics", + "core-text", + "dirs-next", + "dwrote", + "float-ord", + "freetype", + "lazy_static", + "libc", + "log", + "pathfinder_geometry", + "pathfinder_simd", + "walkdir", + "winapi", + "yeslogic-fontconfig-sys", +] + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "freetype" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bee38378a9e3db1cc693b4f88d166ae375338a0ff75cb8263e1c601d51f35dc6" +dependencies = [ + "freetype-sys", + "libc", +] + +[[package]] +name = "freetype-sys" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a37d4011c0cc628dfa766fcc195454f4b068d7afdc2adfd28861191d866e731a" +dependencies = [ + "cmake", + "libc", + "pkg-config", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "getrandom" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi", +] + +[[package]] +name = "gif" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80792593675e051cf94a4b111980da2ba60d4a83e43e0048c5693baab3977045" +dependencies = [ + "color_quant", + "weezl", +] + +[[package]] +name = "gobuild" +version = "0.1.0-alpha.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71e156a4ddbf3deb5e8116946c111413bd9a5679bdc1536c78a60618a7a9ac9e" +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", + "rand_core", + "subtle", +] + +[[package]] +name = "halo2-mpt-circuits" +version = "0.1.0" +dependencies = [ + "bencher", + "ethers-core", + "halo2_proofs", + "hex", + "itertools", + "lazy_static", + "log", + "mpt-zktrie", + "num-bigint", + "num-traits", + "plotters", + "poseidon-circuit", + "rand", + "rand_chacha", + "serde", + "serde_json", + "strum", + "strum_macros", + "subtle", + "thiserror", +] + +[[package]] +name = "halo2-mpt-circuits" +version = "0.1.0" +source = "git+https://github.com/scroll-tech/mpt-circuit.git?tag=v0.7.0#578c210ceb88d3c143ee2a013ad836d19285d9c1" +dependencies = [ + "ethers-core", + "halo2_proofs", + "hex", + "itertools", + "lazy_static", + "log", + "num-bigint", + "num-traits", + "poseidon-circuit", + "rand", + "serde", + "serde_json", + "strum", + "strum_macros", + "thiserror", +] + +[[package]] +name = "halo2_proofs" +version = "0.2.0" +source = "git+https://github.com/scroll-tech/halo2.git?branch=develop#e3fe25eadd714fd991f35190d17ff0b8fb031188" +dependencies = [ + "ark-std", + "blake2b_simd", + "cfg-if 0.1.10", + "crossbeam", + "env_logger", + "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)", + "log", + "num-bigint", + "num-integer", + "plotters", + "poseidon", + "rand_core", + "rayon", + "sha3 0.9.1", + "subtle", + "tabbycat", + "tracing", +] + +[[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" +dependencies = [ + "ff 0.12.1", + "group 0.12.1", + "lazy_static", + "num-bigint", + "num-traits", + "pasta_curves", + "paste", + "rand", + "rand_core", + "serde", + "static_assertions", + "subtle", +] + +[[package]] +name = "hashbrown" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hmac" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" +dependencies = [ + "crypto-mac", + "digest 0.9.0", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "iana-time-zone" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "image" +version = "0.24.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f3dfdbdd72063086ff443e297b61695500514b1e41095b6fb9a5ab48a70a711" +dependencies = [ + "bytemuck", + "byteorder", + "color_quant", + "jpeg-decoder", + "num-rational", + "num-traits", + "png", +] + +[[package]] +name = "impl-codec" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" +dependencies = [ + "parity-scale-codec", +] + +[[package]] +name = "impl-rlp" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28220f89297a075ddc7245cd538076ee98b01f2a9c23a53a4f1105d5a322808" +dependencies = [ + "rlp", +] + +[[package]] +name = "impl-serde" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc88fc67028ae3db0c853baa36269d398d5f45b6982f95549ff5def78c935cd" +dependencies = [ + "serde", +] + +[[package]] +name = "impl-trait-for-tuples" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "indexmap" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "generic-array", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + +[[package]] +name = "jpeg-decoder" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e" + +[[package]] +name = "js-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "k256" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" +dependencies = [ + "cfg-if 1.0.0", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2 0.10.8", + "signature", +] + +[[package]] +name = "keccak" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" +dependencies = [ + "cpufeatures", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" + +[[package]] +name = "libloading" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" +dependencies = [ + "cfg-if 1.0.0", + "windows-sys", +] + +[[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.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + +[[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", + "simd-adler32", +] + +[[package]] +name = "mpt-zktrie" +version = "0.1.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?rev=7d9bc181953cfc6e7baf82ff0ce651281fd70a8a#7d9bc181953cfc6e7baf82ff0ce651281fd70a8a" +dependencies = [ + "eth-types", + "halo2-mpt-circuits 0.1.0 (git+https://github.com/scroll-tech/mpt-circuit.git?tag=v0.7.0)", + "halo2_proofs", + "hex", + "lazy_static", + "log", + "num-bigint", + "poseidon-circuit", + "zktrie", +] + +[[package]] +name = "num" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", + "rand", +] + +[[package]] +name = "num-complex" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ba157ca0885411de85d6ca030ba7e2a83a28636056c7c699b07c8b6f7383214" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_enum" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" +dependencies = [ + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.38", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "open-fastrlp" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "786393f80485445794f6043fd3138854dd109cc6c4bd1a6383db304c9ce9b9ce" +dependencies = [ + "arrayvec", + "auto_impl", + "bytes", + "ethereum-types", + "open-fastrlp-derive", +] + +[[package]] +name = "open-fastrlp-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "003b2be5c6c53c1cfeb0a238b8a1c3915cd410feb684457a36c10038f764bb1c" +dependencies = [ + "bytes", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "parity-scale-codec" +version = "3.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dec8a8073036902368c2cdc0387e85ff9a37054d7e7c98e592145e0c92cd4fb" +dependencies = [ + "arrayvec", + "bitvec", + "byte-slice-cast", + "impl-trait-for-tuples", + "parity-scale-codec-derive", + "serde", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "3.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "312270ee71e1cd70289dacf597cab7b207aa107d2f28191c2ae45b2ece18a260" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "pasta_curves" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc65faf8e7313b4b1fbaa9f7ca917a0eed499a9663be71477f87993604341d8" +dependencies = [ + "blake2b_simd", + "ff 0.12.1", + "group 0.12.1", + "lazy_static", + "rand", + "static_assertions", + "subtle", +] + +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + +[[package]] +name = "pathfinder_geometry" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b7e7b4ea703700ce73ebf128e1450eb69c3a8329199ffbfb9b2a0418e5ad3" +dependencies = [ + "log", + "pathfinder_simd", +] + +[[package]] +name = "pathfinder_simd" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0444332826c70dc47be74a7c6a5fc44e23a7905ad6858d4162b658320455ef93" +dependencies = [ + "rustc_version", +] + +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "pbkdf2" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" +dependencies = [ + "digest 0.10.7", + "hmac 0.12.1", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" + +[[package]] +name = "plotters" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2c224ba00d7cadd4d5c660deaf2098e5e80e07846537c51f9cfa4be50c1fd45" +dependencies = [ + "chrono", + "font-kit", + "image", + "lazy_static", + "num-traits", + "pathfinder_geometry", + "plotters-backend", + "plotters-bitmap", + "plotters-svg", + "ttf-parser", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e76628b4d3a7581389a35d5b6e2139607ad7c75b17aed325f210aa91f4a9609" + +[[package]] +name = "plotters-bitmap" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cebbe1f70205299abc69e8b295035bb52a6a70ee35474ad10011f0a4efb8543" +dependencies = [ + "gif", + "image", + "plotters-backend", +] + +[[package]] +name = "plotters-svg" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38f6d39893cca0701371e3c27294f09797214b86f1fb951b89ade8ec04e2abab" +dependencies = [ + "plotters-backend", +] + +[[package]] +name = "png" +version = "0.17.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd75bf2d8dd3702b9707cdbc56a5b9ef42cec752eb8b3bafc01234558442aa64" +dependencies = [ + "bitflags 1.3.2", + "crc32fast", + "fdeflate", + "flate2", + "miniz_oxide", +] + +[[package]] +name = "poseidon" +version = "0.2.0" +source = "git+https://github.com/scroll-tech/poseidon.git?branch=scroll-dev-0220#2fb4a2385bada39b50dce12fe50cb80d2fd33476" +dependencies = [ + "group 0.12.1", + "halo2curves 0.3.1 (git+https://github.com/privacy-scaling-explorations/halo2curves?tag=0.3.1)", + "subtle", +] + +[[package]] +name = "poseidon-circuit" +version = "0.1.0" +source = "git+https://github.com/scroll-tech/poseidon-circuit.git?branch=scroll-dev-0901#69524f42bdc55c581088c2fe64c2ab9a2921146b" +dependencies = [ + "bitvec", + "halo2_proofs", + "lazy_static", + "log", + "rand", + "rand_xorshift", + "thiserror", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "primitive-types" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" +dependencies = [ + "fixed-hash", + "impl-codec", + "impl-rlp", + "impl-serde", + "scale-info", + "uint", +] + +[[package]] +name = "proc-macro-crate" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +dependencies = [ + "once_cell", + "toml_edit", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_xorshift" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" +dependencies = [ + "rand_core", +] + +[[package]] +name = "rayon" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "redox_syscall" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom", + "redox_syscall 0.2.16", + "thiserror", +] + +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac 0.12.1", + "subtle", +] + +[[package]] +name = "ripemd" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "rlp" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb919243f34364b6bd2fc10ef797edbfa75f33c252e7998527479c6d6b47e1ec" +dependencies = [ + "bytes", + "rlp-derive", + "rustc-hex", +] + +[[package]] +name = "rlp-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e33d7b2abe0c340d8797fe2907d3f20d3b5ea5908683618bfe80df7f621f672a" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "rustc-hex" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "745ecfa778e66b2b63c88a61cb36e0eea109e803b0b86bf9879fbc77c70e86ed" +dependencies = [ + "bitflags 2.4.1", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + +[[package]] +name = "ryu" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" + +[[package]] +name = "salsa20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213" +dependencies = [ + "cipher", +] + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scale-info" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35c0a159d0c45c12b20c5a844feb1fe4bea86e28f17b92a5f0c42193634d3782" +dependencies = [ + "cfg-if 1.0.0", + "derive_more", + "parity-scale-codec", + "scale-info-derive", +] + +[[package]] +name = "scale-info-derive" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "912e55f6d20e0e80d63733872b40e1227c0bce1e1ab81ba67d696339bfd7fd29" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scrypt" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f9e24d2b632954ded8ab2ef9fea0a0c769ea56ea98bddbafbad22caeeadf45d" +dependencies = [ + "hmac 0.12.1", + "pbkdf2 0.11.0", + "salsa20", + "sha2 0.10.8", +] + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "semver" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" + +[[package]] +name = "serde" +version = "1.0.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + +[[package]] +name = "serde_json" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_with" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff" +dependencies = [ + "serde", + "serde_with_macros", +] + +[[package]] +name = "serde_with_macros" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" +dependencies = [ + "darling 0.13.4", + "proc-macro2", + "quote", + "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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "sha3" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" +dependencies = [ + "block-buffer 0.9.0", + "digest 0.9.0", + "keccak", + "opaque-debug", +] + +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest 0.10.7", + "keccak", +] + +[[package]] +name = "signature" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" +dependencies = [ + "digest 0.10.7", + "rand_core", +] + +[[package]] +name = "simd-adler32" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" + +[[package]] +name = "spki" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strsim" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "strum" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 1.0.109", +] + +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tabbycat" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c45590f0f859197b4545be1b17b2bc3cc7bb075f7d1cc0ea1dc6521c0bf256a3" +dependencies = [ + "anyhow", + "derive_builder", + "regex", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "tempfile" +version = "3.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" +dependencies = [ + "cfg-if 1.0.0", + "fastrand", + "redox_syscall 0.3.5", + "rustix", + "windows-sys", +] + +[[package]] +name = "termcolor" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "toml_datetime" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" + +[[package]] +name = "toml_edit" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] +name = "tracing" +version = "0.1.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee2ef2af84856a50c1d430afce2fdded0a4ec7eda868db86409b4543df0797f9" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "ttf-parser" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "375812fa44dab6df41c195cd2f7fecb488f6c09fbaafb62807488cefab642bff" + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +dependencies = [ + "getrandom", + "serde", +] + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "walkdir" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.38", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" + +[[package]] +name = "web-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "weezl" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +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", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[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_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[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_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "winnow" +version = "0.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3b801d0e0a6726477cc207f60162da452f3a95adb368399bef20a946e06f65c" +dependencies = [ + "memchr", +] + +[[package]] +name = "wio" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d129932f4644ac2396cb456385cbf9e63b5b30c6e8dc4820bdca4eb082037a5" +dependencies = [ + "winapi", +] + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "yeslogic-fontconfig-sys" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2bbd69036d397ebbff671b1b8e4d918610c181c5a16073b96f984a38d08c386" +dependencies = [ + "const-cstr", + "dlib", + "once_cell", + "pkg-config", +] + +[[package]] +name = "zeroize" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" + +[[package]] +name = "zktrie" +version = "0.2.0" +source = "git+https://github.com/scroll-tech/zktrie.git?branch=v0.7#a130ea543d291d4b71724f91cb8a49745c593a0c" +dependencies = [ + "gobuild", +] diff --git a/Cargo.toml b/Cargo.toml index fb04fc42..18cecdd1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,9 +6,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ethers-core = "0.17.0" +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-0723"} +hash-circuit = { package = "poseidon-circuit", git = "https://github.com/scroll-tech/poseidon-circuit.git", branch = "scroll-dev-0901"} halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2022_09_10" } rand = "0.8" lazy_static = "1.4.0" @@ -24,13 +24,15 @@ log = "0.4" [patch."https://github.com/privacy-scaling-explorations/halo2.git"] halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "develop" } +[patch.crates-io] +ethers-core = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" } [features] # printout the layout of circuits for demo and some unittests print_layout = ["halo2_proofs/dev-graph"] [dev-dependencies] -mpt-zktrie = { git = "https://github.com/scroll-tech/zkevm-circuits.git" } +mpt-zktrie = { git = "https://github.com/scroll-tech/zkevm-circuits.git", rev = "7d9bc181953cfc6e7baf82ff0ce651281fd70a8a" } # mpt-zktrie = { path = "../scroll-circuits/zktrie" } rand_chacha = "0.3.0" plotters = "0.3" diff --git a/Makefile b/Makefile index beb636f4..cf38b795 100644 --- a/Makefile +++ b/Makefile @@ -5,4 +5,4 @@ fmt: @cargo fmt clippy: - @cargo clippy --all-features + @cargo clippy --all-features -- -D warnings diff --git a/src/constraint_builder.rs b/src/constraint_builder.rs index 7b146ddb..b653a5f7 100644 --- a/src/constraint_builder.rs +++ b/src/constraint_builder.rs @@ -1,7 +1,9 @@ +use crate::gadgets::poseidon::PoseidonLookup; use halo2_proofs::{ arithmetic::FieldExt, plonk::{ConstraintSystem, SecondPhase}, }; +use itertools::Itertools; mod binary_column; mod binary_query; @@ -73,35 +75,58 @@ impl ConstraintBuilder { let condition = self .conditions .iter() - .skip(1) // Save a degree by skipping every row selector .fold(BinaryQuery::one(), |a, b| a.and(b.clone())); - let lookup = left + let mut lookup: Vec<_> = left .into_iter() .map(|q| q * condition.clone()) .zip(right.into_iter()) .collect(); + // If condition is true, every_row_selector must be enabled. + lookup.push((condition.into(), self.every_row_selector().into())); self.lookups.push((name, lookup)) } - pub fn add_lookup_with_default( + pub fn poseidon_lookup( &mut self, name: &'static str, - left: [Query; N], - right: [Query; N], - default: [Query; N], + [left, right, domain, hash]: [Query; 4], + poseidon: &impl PoseidonLookup, ) { let condition = self .conditions .iter() .skip(1) // Save a degree by skipping every row selector .fold(BinaryQuery::one(), |a, b| a.and(b.clone())); - let lookup = left - .into_iter() - .zip(default.into_iter()) - .map(|(a, b)| condition.select(a, b)) - .zip(right.into_iter()) - .collect(); - self.lookups.push((name, lookup)) + let extended_queries = [ + Query::one(), + hash, + left, + right, + Query::zero(), + domain, + Query::one(), + ] + .map(|q| q * condition.clone()); + + let (q_enable, [hash, left, right, control, domain_spec, head_mark]) = + poseidon.lookup_columns(); + let poseidon_lookup_queries = [ + q_enable.current(), + hash.current(), + left.current(), + right.current(), + control.current(), + domain_spec.current(), + head_mark.current(), + ]; + + self.lookups.push(( + name, + extended_queries + .into_iter() + .zip_eq(poseidon_lookup_queries) + .collect(), + )) } pub fn build_columns( diff --git a/src/constraint_builder/binary_column.rs b/src/constraint_builder/binary_column.rs index 8e777d9a..c414850f 100644 --- a/src/constraint_builder/binary_column.rs +++ b/src/constraint_builder/binary_column.rs @@ -28,12 +28,14 @@ impl BinaryColumn { pub fn configure( cs: &mut ConstraintSystem, - _cb: &mut ConstraintBuilder, + cb: &mut ConstraintBuilder, ) -> Self { - let advice_column = cs.advice_column(); - // TODO: constrain to be binary here... - // cb.add_constraint() - Self(advice_column) + let binary_column = Self(cs.advice_column()); + cb.assert( + "binary column is 0 or 1", + binary_column.current().or(!binary_column.current()), + ); + binary_column } pub fn assign(&self, region: &mut Region<'_, F>, offset: usize, value: bool) { diff --git a/src/constraint_builder/column.rs b/src/constraint_builder/column.rs index b3dbfa03..45351e16 100644 --- a/src/constraint_builder/column.rs +++ b/src/constraint_builder/column.rs @@ -51,7 +51,7 @@ impl FixedColumn { { region .assign_fixed( - || "asdfasdfawe", + || "fixed", self.0, offset, || Value::known(value.try_into().unwrap()), diff --git a/src/constraint_builder/query.rs b/src/constraint_builder/query.rs index 670c852a..11437fe1 100644 --- a/src/constraint_builder/query.rs +++ b/src/constraint_builder/query.rs @@ -1,19 +1,11 @@ use super::BinaryQuery; -use ethers_core::k256::elliptic_curve::PrimeField; use halo2_proofs::{ arithmetic::{Field, FieldExt}, - halo2curves::bn256::Fr, + halo2curves::{bn256::Fr, group::ff::PrimeField}, plonk::{Advice, Challenge, Column, Expression, Fixed, VirtualCells}, poly::Rotation, }; -#[derive(Clone, Copy)] -pub enum ColumnType { - Advice, - Fixed, - Challenge, -} - #[derive(Clone)] pub enum Query { Constant(F), diff --git a/src/gadgets/byte_bit.rs b/src/gadgets/byte_bit.rs index 60474732..471fa2f8 100644 --- a/src/gadgets/byte_bit.rs +++ b/src/gadgets/byte_bit.rs @@ -31,7 +31,7 @@ impl ByteBitGadget { } pub fn assign(&self, region: &mut Region<'_, F>) { - let mut offset = 0; + let mut offset = 1; for byte in 0..256 { for index in 0..8 { self.byte.assign(region, offset, byte); @@ -40,6 +40,17 @@ impl ByteBitGadget { offset += 1; } } + + let expected_offset = Self::n_rows_required(); + debug_assert!( + offset == expected_offset, + "assign used {offset} rows but {expected_offset} rows expected from `n_rows_required`", + ); + } + + pub fn n_rows_required() -> usize { + // +1 because assigment starts on offset = 1 instead of offset = 0. + 256 * 8 + 1 } } diff --git a/src/gadgets/byte_representation.rs b/src/gadgets/byte_representation.rs index a60dd835..f7ff1047 100644 --- a/src/gadgets/byte_representation.rs +++ b/src/gadgets/byte_representation.rs @@ -1,6 +1,7 @@ use super::{byte_bit::RangeCheck256Lookup, is_zero::IsZeroGadget, rlc_randomness::RlcRandomness}; -use crate::constraint_builder::{AdviceColumn, ConstraintBuilder, Query, SecondPhaseAdviceColumn}; -use ethers_core::types::{Address, H256}; +use crate::constraint_builder::{ + AdviceColumn, ConstraintBuilder, Query, SecondPhaseAdviceColumn, SelectorColumn, +}; use halo2_proofs::{ arithmetic::FieldExt, circuit::{Region, Value}, @@ -27,6 +28,7 @@ pub struct ByteRepresentationConfig { index: AdviceColumn, // internal columns + is_first: SelectorColumn, byte: AdviceColumn, index_is_zero: IsZeroGadget, } @@ -56,21 +58,25 @@ impl ByteRepresentationConfig { range_check: &impl RangeCheck256Lookup, randomness: &RlcRandomness, ) -> Self { + let is_first = SelectorColumn(cs.fixed_column()); let [value, index, byte] = cb.advice_columns(cs); let [rlc] = cb.second_phase_advice_columns(cs); let index_is_zero = IsZeroGadget::configure(cs, cb, index); + cb.condition(is_first.current(), |cb| { + cb.assert_zero("index is 0 for first row", index.current()) + }); cb.assert_zero( - "index increases by 1 or resets to 0", + "index is 0 or increases by 1", index.current() * (index.current() - index.previous() - 1), ); cb.assert_equal( - "current value = previous value * 256 * (index == 0) + byte", + "current value = previous value * 256 * (index != 0) + byte", value.current(), value.previous() * 256 * !index_is_zero.current() + byte.current(), ); cb.assert_equal( - "current rlc = previous rlc * randomness * (index == 0) + byte", + "current rlc = previous rlc * randomness * (index != 0) + byte", rlc.current(), rlc.previous() * randomness.query() * !index_is_zero.current() + byte.current(), ); @@ -82,25 +88,28 @@ impl ByteRepresentationConfig { index, index_is_zero, byte, + is_first, } } - // can this we done with an Iterator instead? pub fn assign( &self, region: &mut Region<'_, F>, + u32s: &[u32], u64s: &[u64], u128s: &[u128], frs: &[Fr], randomness: Value, ) { - let byte_representations = u64s + self.is_first.enable(region, 0); + let byte_representations = u32s .iter() - .map(u64_to_big_endian) + .map(u32_to_big_endian) + .chain(u64s.iter().map(u64_to_big_endian)) .chain(u128s.iter().map(u128_to_big_endian)) .chain(frs.iter().map(fr_to_big_endian)); - let mut offset = 0; + let mut offset = 1; for byte_representation in byte_representations { let mut value = F::zero(); let mut rlc = Value::known(F::zero()); @@ -121,9 +130,23 @@ impl ByteRepresentationConfig { offset += 1; } } + + let expected_offset = Self::n_rows_required(u32s, u64s, u128s, frs); + debug_assert!( + offset == expected_offset, + "assign used {offset} rows but {expected_offset} rows expected from `n_rows_required`", + ); + } + + pub fn n_rows_required(u32s: &[u32], u64s: &[u64], u128s: &[u128], frs: &[Fr]) -> usize { + // +1 because assigment starts on offset = 1 instead of offset = 0. + 1 + u32s.len() * 4 + u64s.len() * 8 + u128s.len() * 16 + frs.len() * 31 } } +fn u32_to_big_endian(x: &u32) -> Vec { + x.to_be_bytes().to_vec() +} fn u64_to_big_endian(x: &u64) -> Vec { x.to_be_bytes().to_vec() } @@ -132,14 +155,6 @@ fn u128_to_big_endian(x: &u128) -> Vec { x.to_be_bytes().to_vec() } -fn address_to_big_endian(x: &Address) -> Vec { - x.0.to_vec() -} - -fn h256_to_big_endian(x: &H256) -> Vec { - x.0.to_vec() -} - fn fr_to_big_endian(x: &Fr) -> Vec { let mut bytes = x.to_bytes(); bytes.reverse(); @@ -164,6 +179,7 @@ mod test { #[derive(Clone, Default, Debug)] struct TestCircuit { + u32s: Vec, u64s: Vec, u128s: Vec, frs: Vec, @@ -204,12 +220,13 @@ mod test { layouter.assign_region( || "", |mut region| { - for offset in 0..1024 { + for offset in 0..(8 * 256) { selector.enable(&mut region, offset); } byte_bit.assign(&mut region); byte_representation.assign( &mut region, + &self.u32s, &self.u64s, &self.u128s, &self.frs, @@ -224,6 +241,7 @@ mod test { #[test] fn test_byte_representation() { let circuit = TestCircuit { + u32s: vec![0, 1, u32::MAX], u64s: vec![u64::MAX], u128s: vec![0, 1, u128::MAX], frs: vec![Fr::from(2342)], diff --git a/src/gadgets/canonical_representation.rs b/src/gadgets/canonical_representation.rs index 149d6d9b..e98f0132 100644 --- a/src/gadgets/canonical_representation.rs +++ b/src/gadgets/canonical_representation.rs @@ -2,10 +2,7 @@ use super::super::constraint_builder::{ AdviceColumn, BinaryColumn, ConstraintBuilder, FixedColumn, Query, SecondPhaseAdviceColumn, SelectorColumn, }; -use super::{ - byte_bit::RangeCheck256Lookup, byte_representation::RlcLookup, is_zero::IsZeroGadget, - rlc_randomness::RlcRandomness, -}; +use super::{byte_bit::RangeCheck256Lookup, is_zero::IsZeroGadget, rlc_randomness::RlcRandomness}; use ethers_core::types::U256; use halo2_proofs::{ arithmetic::{Field, FieldExt}, @@ -20,6 +17,11 @@ pub trait CanonicalRepresentationLookup { fn lookup(&self) -> [Query; 3]; } +// Lookup to prove that Rlc(x: Fr) = y +pub trait FrRlcLookup { + fn lookup(&self) -> [Query; 2]; +} + #[derive(Clone)] pub struct CanonicalRepresentationConfig { // Lookup columns @@ -30,9 +32,9 @@ pub struct CanonicalRepresentationConfig { // Witness columns index_is_zero: SelectorColumn, // (0..32).repeat().map(|i| i == 0) - // index_is_31: SelectorColumn, // (0..32).repeat().map(|i| i == 31) - modulus_byte: FixedColumn, // (0..32).repeat().map(|i| Fr::MODULUS.to_be_bytes()[i]) - difference: AdviceColumn, // modulus_byte - byte + index_is_31: SelectorColumn, // (0..32).repeat().map(|i| i == 31) + modulus_byte: FixedColumn, // (0..32).repeat().map(|i| Fr::MODULUS.to_be_bytes()[i]) + difference: AdviceColumn, // modulus_byte - byte difference_is_zero: IsZeroGadget, differences_are_zero_so_far: BinaryColumn, // difference[0] ... difference[index - 1] are all 0. } @@ -44,7 +46,7 @@ impl CanonicalRepresentationConfig { range_check: &impl RangeCheck256Lookup, randomness: &RlcRandomness, ) -> Self { - let ([index_is_zero], [index, modulus_byte], [value, byte, difference]) = + let ([index_is_zero, index_is_31], [index, modulus_byte], [value, byte, difference]) = cb.build_columns(cs); let [rlc] = cb.second_phase_advice_columns(cs); @@ -120,6 +122,7 @@ impl CanonicalRepresentationConfig { byte, rlc, index_is_zero, + index_is_31, modulus_byte, difference, difference_is_zero, @@ -127,19 +130,19 @@ impl CanonicalRepresentationConfig { } } - pub fn assign<'a>( + pub fn assign( &self, region: &mut Region<'_, Fr>, randomness: Value, - values: impl IntoIterator, + values: &[Fr], + n_rows: usize, ) { let modulus = U256::from_str_radix(Fr::MODULUS, 16).unwrap(); let mut modulus_bytes = [0u8; 32]; modulus.to_big_endian(&mut modulus_bytes); - let mut offset = 0; - // TODO: we add a final Fr::zero() to handle the always enabled selector. Add a default assignment instead? - for value in values.into_iter().copied().chain([Fr::zero()]) { + let mut offset = 1; + for value in values.iter() { let mut bytes = value.to_bytes(); bytes.reverse(); let mut differences_are_zero_so_far = true; @@ -153,6 +156,8 @@ impl CanonicalRepresentationConfig { .assign(region, offset, u64::try_from(index).unwrap()); if index.is_zero() { self.index_is_zero.enable(region, offset); + } else if index == 31 { + self.index_is_31.enable(region, offset); } let difference = Fr::from(u64::from(*modulus_byte)) - Fr::from(u64::from(*byte)); @@ -166,7 +171,7 @@ impl CanonicalRepresentationConfig { ); differences_are_zero_so_far &= difference.is_zero_vartime(); - self.value.assign(region, offset, value); + self.value.assign(region, offset, *value); rlc = rlc * randomness + Value::known(Fr::from(u64::from(*byte))); self.rlc.assign(region, offset, rlc); @@ -174,6 +179,42 @@ impl CanonicalRepresentationConfig { offset += 1 } } + + let expected_offset = Self::n_rows_required(values); + debug_assert!( + offset == expected_offset, + "assign used {offset} rows but {expected_offset} rows expected from `n_rows_required`", + ); + + let n_padding_values = n_rows / 32 - values.len(); + for _ in 0..n_padding_values { + for (index, modulus_byte) in modulus_bytes.iter().enumerate() { + self.modulus_byte + .assign(region, offset, u64::from(*modulus_byte)); + + self.index + .assign(region, offset, u64::try_from(index).unwrap()); + if index.is_zero() { + self.index_is_zero.enable(region, offset); + } else if index == 31 { + self.index_is_31.enable(region, offset); + } + + let difference = Fr::from(u64::from(*modulus_byte)); + self.difference.assign(region, offset, difference); + self.difference_is_zero.assign(region, offset, difference); + + self.differences_are_zero_so_far + .assign(region, offset, index == 0); + + offset += 1 + } + } + } + + pub fn n_rows_required(values: &[Fr]) -> usize { + // +1 because assigment starts on offset = 1 instead of offset = 0. + values.len() * 32 + 1 } } @@ -187,12 +228,11 @@ impl CanonicalRepresentationLookup for CanonicalRepresentationConfig { } } -impl RlcLookup for CanonicalRepresentationConfig { - fn lookup(&self) -> [Query; 3] { +impl FrRlcLookup for CanonicalRepresentationConfig { + fn lookup(&self) -> [Query; 2] { [ - self.value.current(), - self.rlc.current(), - self.index.current(), + self.value.current() * self.index_is_31.current(), + self.rlc.current() * self.index_is_31.current(), ] } } @@ -246,11 +286,11 @@ mod test { layouter.assign_region( || "", |mut region| { - for offset in 0..256 { + for offset in 1..(1 + 8 * 256) { selector.enable(&mut region, offset); } byte_bit.assign(&mut region); - canonical_representation.assign(&mut region, randomness, &self.values); + canonical_representation.assign(&mut region, randomness, &self.values, 256); Ok(()) }, ) diff --git a/src/gadgets/is_zero.rs b/src/gadgets/is_zero.rs index a4d9a210..9fe7163d 100644 --- a/src/gadgets/is_zero.rs +++ b/src/gadgets/is_zero.rs @@ -57,7 +57,8 @@ impl IsZeroGadget { ); cb.assert_zero( "inverse_or_zero is 0 or inverse_or_zero is inverse of value", - inverse_or_zero.current() * (Query::one() - value.current() * inverse_or_zero.current()), + inverse_or_zero.current() + * (Query::one() - value.current() * inverse_or_zero.current()), ); Self { value, diff --git a/src/gadgets/key_bit.rs b/src/gadgets/key_bit.rs index cc2299d3..abeece53 100644 --- a/src/gadgets/key_bit.rs +++ b/src/gadgets/key_bit.rs @@ -2,7 +2,7 @@ use super::{ byte_bit::{ByteBitLookup, RangeCheck256Lookup, RangeCheck8Lookup}, canonical_representation::CanonicalRepresentationLookup, }; -use crate::constraint_builder::{AdviceColumn, ConstraintBuilder, Query, SelectorColumn}; +use crate::constraint_builder::{AdviceColumn, ConstraintBuilder, Query}; use halo2_proofs::{ arithmetic::FieldExt, circuit::Region, halo2curves::bn256::Fr, plonk::ConstraintSystem, }; @@ -13,8 +13,6 @@ pub trait KeyBitLookup { #[derive(Clone)] pub struct KeyBitConfig { - selector: SelectorColumn, // always enabled selector for constraints we want always enabled. - // Lookup columns value: AdviceColumn, // We're proving value.bit(i) = bit in this gadget index: AdviceColumn, // 0 <= index < 256 @@ -35,8 +33,7 @@ impl KeyBitConfig { range_check_256: &impl RangeCheck256Lookup, byte_bit: &impl ByteBitLookup, ) -> Self { - let ([selector], [], [value, index, bit, index_div_8, index_mod_8, byte]) = - cb.build_columns(cs); + let ([], [], [value, index, bit, index_div_8, index_mod_8, byte]) = cb.build_columns(cs); cb.add_lookup( "0 <= index < 256", @@ -76,7 +73,6 @@ impl KeyBitConfig { ); Self { - selector, value, index, bit, @@ -89,6 +85,8 @@ impl KeyBitConfig { pub fn assign(&self, region: &mut Region<'_, Fr>, lookups: &[(Fr, usize, bool)]) { // TODO; dedup lookups for (offset, (value, index, bit)) in lookups.iter().enumerate() { + // TODO: either move the disabled row to the end of the assigment or get rid of it entirely. + let offset = offset + 1; // Start assigning at offet = 1 because the first row is disabled. let bytes = value.to_bytes(); let index_div_8 = index / 8; // index = (31 - index/8) * 8 @@ -108,6 +106,11 @@ impl KeyBitConfig { self.byte.assign(region, offset, u64::from(byte)); } } + + pub fn n_rows_required(lookups: &[(Fr, usize, bool)]) -> usize { + // +1 because assigment starts on offset = 1 instead of offset = 0. + 1 + lookups.len() + } } impl KeyBitLookup for KeyBitConfig { @@ -127,6 +130,7 @@ mod test { rlc_randomness::RlcRandomness, }; use super::*; + use crate::constraint_builder::SelectorColumn; use halo2_proofs::{ circuit::{Layouter, SimpleFloorPlanner}, dev::MockProver, @@ -191,13 +195,13 @@ mod test { layouter.assign_region( || "", |mut region| { - for offset in 0..32 { + for offset in 1..(1 + 8 * 256) { selector.enable(&mut region, offset); } key_bit.assign(&mut region, &self.lookups); byte_bit.assign(&mut region); - canonical_representation.assign(&mut region, randomness, &keys); + canonical_representation.assign(&mut region, randomness, &keys, 256); Ok(()) }, ) diff --git a/src/gadgets/mpt_update.rs b/src/gadgets/mpt_update.rs index 04049306..9e1b014e 100644 --- a/src/gadgets/mpt_update.rs +++ b/src/gadgets/mpt_update.rs @@ -8,6 +8,7 @@ use word_rlc::{assign as assign_word_rlc, configure as configure_word_rlc}; use super::{ byte_representation::{BytesLookup, RlcLookup}, + canonical_representation::FrRlcLookup, is_zero::IsZeroGadget, key_bit::KeyBitLookup, one_hot::OneHot, @@ -26,7 +27,7 @@ use crate::{ util::{account_key, domain_hash, lagrange_polynomial, rlc, u256_hi_lo, u256_to_big_endian}, MPTProofType, }; -use ethers_core::{k256::elliptic_curve::PrimeField, types::Address}; +use ethers_core::types::Address; use halo2_proofs::{ arithmetic::{Field, FieldExt}, circuit::{Region, Value}, @@ -83,7 +84,10 @@ impl MptUpdateLookup for MptUpdateConfig { let proof_type = self.proof_type.current() * is_start(); let old_value = self.old_value.current() * is_start(); let new_value = self.new_value.current() * is_start(); - let address = self.intermediate_values[0].current() * is_start(); + let [address_high, address_low, ..] = self.intermediate_values; + let address = (address_high.current() * Query::Constant(F::from_u128(1 << 32)) + + address_low.current()) + * is_start(); let storage_key_rlc = self.storage_key_rlc.current() * is_start(); [ is_start().into(), @@ -107,7 +111,7 @@ impl MptUpdateConfig { rlc: &impl RlcLookup, bytes: &impl BytesLookup, rlc_randomness: &RlcRandomness, - fr_rlc: &impl RlcLookup, + fr_rlc: &impl FrRlcLookup, ) -> Self { let proof_type: OneHot = OneHot::configure(cs, cb); let [storage_key_rlc, old_value, new_value] = cb.second_phase_advice_columns(cs); @@ -131,30 +135,36 @@ impl MptUpdateConfig { path_type.current_matches(&[PathType::Start]).into(), ); cb.condition(is_start.clone().and(cb.every_row_selector()), |cb| { - let [address, address_high, ..] = intermediate_values; + let [address_high, address_low, ..] = intermediate_values; let [old_hash_rlc, new_hash_rlc, ..] = second_phase_intermediate_values; - let address_low: Query = (address.current() - address_high.current() * (1 << 32)) - * (1 << 32) - * (1 << 32) - * (1 << 32); cb.poseidon_lookup( - "account mpt key = h(address_high, address_low)", + "account mpt key = h(address_high, address_low << 96)", [ address_high.current(), - address_low, + address_low.current() * Query::Constant(F::from_u128(1 << 96)), Query::from(u64::from(HashDomain::Pair)), key.current(), ], poseidon, ); + cb.add_lookup( + "address_high is 16 bytes", + [address_high.current(), Query::from(15)], + bytes.lookup(), + ); + cb.add_lookup( + "address_low is 4 bytes", + [address_low.current(), Query::from(3)], + bytes.lookup(), + ); cb.add_lookup( "rlc_old_root = rlc(old_root)", - [old_hash.current(), old_hash_rlc.current(), Query::from(31)], + [old_hash.current(), old_hash_rlc.current()], fr_rlc.lookup(), ); cb.add_lookup( "rlc_new_root = rlc(new_root)", - [new_hash.current(), new_hash_rlc.current(), Query::from(31)], + [new_hash.current(), new_hash_rlc.current()], fr_rlc.lookup(), ); }); @@ -175,7 +185,7 @@ impl MptUpdateConfig { old_value.previous(), ); cb.assert_equal( - "old_value does not change", + "new_value does not change", new_value.current(), new_value.previous(), ); @@ -388,12 +398,16 @@ impl MptUpdateConfig { self.other_key.assign(region, offset, other_key); self.domain.assign(region, offset, HashDomain::Pair); - self.intermediate_values[0].assign(region, offset, address_to_fr(proof.claim.address)); - self.intermediate_values[1].assign( + self.intermediate_values[0].assign( region, offset, Fr::from_u128(address_high(proof.claim.address)), ); + self.intermediate_values[1].assign( + region, + offset, + u64::from(address_low(proof.claim.address)), + ); let rlc_fr = |x: Fr| { let mut bytes = x.to_bytes(); @@ -435,7 +449,7 @@ impl MptUpdateConfig { }) .unwrap_or(PathType::Common); let (final_old_hash, final_new_hash) = match proof.address_hash_traces.first() { - None => unimplemented!("single account mpt not handled"), + None => (proof.old.hash(), proof.new.hash()), Some((_, _, old_hash, new_hash, _, _, _)) => (*old_hash, *new_hash), }; @@ -580,9 +594,21 @@ impl MptUpdateConfig { n_rows += proof.n_rows(); offset = 1 + n_rows; } + + let expected_offset = Self::n_rows_required(proofs); + debug_assert!( + offset == expected_offset, + "assign used {offset} rows but {expected_offset} rows expected from `n_rows_required`", + ); + n_rows } + pub fn n_rows_required(proofs: &[Proof]) -> usize { + // +1 because assigment starts on offset = 1 instead of offset = 0. + proofs.iter().map(Proof::n_rows).sum::() + 1 + } + fn assign_account_trie_rows( &self, region: &mut Region<'_, Fr>, @@ -876,13 +902,6 @@ fn new_right(config: &MptUpdateConfig) -> Query { + (Query::one() - config.direction.current()) * config.sibling.current() } -fn address_to_fr(a: Address) -> Fr { - let mut bytes = [0u8; 32]; - bytes[32 - 20..].copy_from_slice(a.as_bytes()); - bytes.reverse(); - Fr::from_repr(bytes).unwrap() -} - fn configure_segment_transitions( cb: &mut ConstraintBuilder, segment: &OneHot, @@ -1108,10 +1127,15 @@ fn configure_extension_old( poseidon: &impl PoseidonLookup, ) { cb.assert( - "can only delete existing nodes for storage proofs", + "can only delete existing storage trie nodes for storage proofs", config .proof_type - .current_matches(&[MPTProofType::StorageChanged]), + .current_matches(&[MPTProofType::StorageChanged]) + .and( + config + .segment_type + .current_matches(&[SegmentType::StorageTrie, SegmentType::StorageLeaf0]), + ), ); cb.assert_zero( "new value is 0 when deleting node", @@ -1283,7 +1307,7 @@ fn configure_nonce( ); for variant in SegmentType::iter() { let conditional_constraints = |cb: &mut ConstraintBuilder| match variant { - SegmentType::AccountTrie => { + SegmentType::Start | SegmentType::AccountTrie => { cb.condition( config.segment_type.next_matches(&[SegmentType::Start]), |cb| { @@ -1334,10 +1358,10 @@ fn configure_nonce( config.path_type.current_matches(&[PathType::ExtensionNew]), |cb| { cb.assert_equal( - "sibling is hash(0, hash(0, 0)) for nonce extension new at AccountLeaf2", - config.sibling.current(), - Query::from(*ZERO_STORAGE_ROOT_KECCAK_CODEHASH_HASH), - ); + "sibling is hash(0, hash(0, 0)) for nonce extension new at AccountLeaf2", + config.sibling.current(), + Query::from(*ZERO_STORAGE_ROOT_KECCAK_CODEHASH_HASH), + ); }, ); } @@ -1407,15 +1431,9 @@ fn configure_code_size( bytes: &impl BytesLookup, poseidon: &impl PoseidonLookup, ) { - cb.assert( - "new accounts have balance or nonce set first", - config - .path_type - .current_matches(&[PathType::Start, PathType::Common]), - ); for variant in SegmentType::iter() { let conditional_constraints = |cb: &mut ConstraintBuilder| match variant { - SegmentType::AccountTrie => { + SegmentType::Start | SegmentType::AccountTrie => { cb.condition( config.segment_type.next_matches(&[SegmentType::Start]), |cb| { @@ -1461,62 +1479,25 @@ fn configure_code_size( - config.old_value.current() * Query::Constant(F::from(1 << 32).square()); let new_nonce = config.new_hash.current() - config.new_value.current() * Query::Constant(F::from(1 << 32).square()); - cb.condition( - config.path_type.current_matches(&[PathType::Common]), - |cb| { - cb.add_lookup( - "old code size is 8 bytes", - [config.old_value.current(), Query::from(7)], - bytes.lookup(), - ); - cb.add_lookup( - "new code size is 8 bytes", - [config.new_value.current(), Query::from(7)], - bytes.lookup(), - ); - cb.assert_equal( - "old nonce = new nonce for code size update", - old_nonce.clone(), - new_nonce.clone(), - ); - cb.add_lookup( - "nonce is 8 bytes", - [old_nonce.clone(), Query::from(7)], - bytes.lookup(), - ); - }, + cb.add_lookup( + "old code size is 8 bytes", + [config.old_value.current(), Query::from(7)], + bytes.lookup(), ); - cb.condition( - config.path_type.current_matches(&[PathType::ExtensionNew]), - |cb| { - cb.add_lookup( - "new nonce is 8 bytes", - [config.old_value.current(), Query::from(7)], - bytes.lookup(), - ); - cb.assert_zero( - "new nonce is 0 for ExtensionNew code size update", - new_nonce, - ); - cb.assert_zero( - "nonce and code size are 0 for ExtensionNew balance update", - config.sibling.current(), - ); - }, + cb.add_lookup( + "new code size is 8 bytes", + [config.new_value.current(), Query::from(7)], + bytes.lookup(), ); - cb.condition( - config.path_type.current_matches(&[PathType::ExtensionOld]), - |cb| { - cb.add_lookup( - "old code size is 8 bytes", - [config.old_value.current(), Query::from(7)], - bytes.lookup(), - ); - cb.assert_zero( - "old nonce is 0 for ExtensionOld code size update", - old_nonce, - ); - }, + cb.assert_equal( + "old nonce = new nonce for code size update", + old_nonce.clone(), + new_nonce, + ); + cb.add_lookup( + "nonce is 8 bytes", + [old_nonce, Query::from(7)], + bytes.lookup(), ); } _ => {} @@ -1536,7 +1517,7 @@ fn configure_balance( ) { for variant in SegmentType::iter() { let conditional_constraints = |cb: &mut ConstraintBuilder| match variant { - SegmentType::AccountTrie => { + SegmentType::Start | SegmentType::AccountTrie => { cb.condition( config.segment_type.next_matches(&[SegmentType::Start]), |cb| { @@ -1607,9 +1588,7 @@ fn configure_balance( SegmentType::AccountLeaf3 => { cb.assert_equal("direction is 1", config.direction.current(), Query::one()); cb.condition( - config - .path_type - .current_matches(&[PathType::Common, PathType::ExtensionOld]), + config.path_type.current_matches(&[PathType::Common]), |cb| { cb.add_lookup( "old balance is rlc(old_hash) and fits into 31 bytes", @@ -1622,19 +1601,30 @@ fn configure_balance( ); }, ); + cb.add_lookup( + "new balance is rlc(new_hash) and fits into 31 bytes", + [ + config.new_hash.current(), + Query::from(30), + config.new_value.current(), + ], + rlc.lookup(), + ); cb.condition( - config - .path_type - .current_matches(&[PathType::Common, PathType::ExtensionNew]), + config.path_type.current_matches(&[PathType::ExtensionNew]), |cb| { - cb.add_lookup( - "new balance is rlc(new_hash) and fits into 31 bytes", - [ - config.new_hash.current(), - Query::from(30), - config.new_value.current(), - ], - rlc.lookup(), + cb.assert_zero( + "sibling (code_size + nonce << 64) is 0 for new account)", + config.sibling.current(), + ); + }, + ); + cb.condition( + config.path_type.current_matches(&[PathType::ExtensionNew]), + |cb| { + cb.assert_zero( + "nonce and code size are 0 for new account", + config.sibling.current(), ); }, ); @@ -1652,12 +1642,6 @@ fn configure_poseidon_code_hash( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, ) { - cb.assert( - "new accounts have balance or nonce set first", - config - .path_type - .current_matches(&[PathType::Start, PathType::Common]), - ); for variant in SegmentType::iter() { let conditional_constraints = |cb: &mut ConstraintBuilder| match variant { SegmentType::AccountLeaf0 => { @@ -1665,29 +1649,15 @@ fn configure_poseidon_code_hash( } SegmentType::AccountLeaf1 => { cb.assert_equal("direction is 1", config.direction.current(), Query::one()); - cb.condition( - config - .path_type - .current_matches(&[PathType::Common, PathType::ExtensionOld]), - |cb| { - cb.assert_equal( - "old_hash is old poseidon code hash", - config.old_value.current(), - config.old_hash.current(), - ); - }, + cb.assert_equal( + "old_hash is old poseidon code hash", + config.old_value.current(), + config.old_hash.current(), ); - cb.condition( - config - .path_type - .current_matches(&[PathType::Common, PathType::ExtensionNew]), - |cb| { - cb.assert_equal( - "new_hash is new poseidon code hash", - config.new_value.current(), - config.new_hash.current(), - ); - }, + cb.assert_equal( + "new_hash is new poseidon code hash", + config.new_value.current(), + config.new_hash.current(), ); } _ => {} @@ -1707,15 +1677,9 @@ fn configure_keccak_code_hash( rlc: &impl RlcLookup, randomness: Query, ) { - cb.assert( - "new accounts have balance or nonce set first", - config - .path_type - .current_matches(&[PathType::Start, PathType::Common]), - ); for variant in SegmentType::iter() { let conditional_constraints = |cb: &mut ConstraintBuilder| match variant { - SegmentType::AccountTrie => { + SegmentType::Start | SegmentType::AccountTrie => { cb.condition( config.segment_type.next_matches(&[SegmentType::Start]), |cb| { @@ -1808,10 +1772,6 @@ fn configure_storage( cb.assert_equal("direction is 1", config.direction.current(), Query::one()); } SegmentType::AccountLeaf3 => { - cb.assert( - "storage modifications must be on an existing account", - config.path_type.current_matches(&[PathType::Common]), - ); cb.assert_zero("direction is 0", config.direction.current()); let [key_high, key_low, ..] = config.intermediate_values; let [rlc_key_high, rlc_key_low, ..] = config.second_phase_intermediate_values; @@ -1831,11 +1791,8 @@ fn configure_storage( let [old_high, old_low, new_high, new_low, ..] = config.intermediate_values; let [rlc_old_high, rlc_old_low, rlc_new_high, rlc_new_low, ..] = config.second_phase_intermediate_values; - cb.condition( - config - .path_type - .current_matches(&[PathType::Common, PathType::ExtensionOld]), + config.path_type.current_matches(&[PathType::Common]), |cb| { configure_word_rlc( cb, @@ -1846,13 +1803,6 @@ fn configure_storage( rlc, randomness.clone(), ); - }, - ); - cb.condition( - config - .path_type - .current_matches(&[PathType::Common, PathType::ExtensionNew]), - |cb| { configure_word_rlc( cb, [config.new_hash, new_high, new_low], @@ -1921,19 +1871,14 @@ fn configure_empty_storage( .path_type .current_matches(&[PathType::Start, PathType::Common]), ); + cb.assert_equal( + "hash doesn't change for empty account", + config.old_hash.current(), + config.new_hash.current(), + ); let is_final_segment = config.segment_type.next_matches(&[SegmentType::Start]); cb.condition(is_final_segment, |cb| { - cb.assert_equal( - "old_hash = new_hash", - config.old_hash.current(), - config.new_hash.current(), - ); - cb.assert_equal( - "old value = new value for empty account proof", - config.old_value.current(), - config.new_value.current(), - ); nonexistence_proof::configure( cb, config.old_value, @@ -1960,6 +1905,8 @@ fn configure_empty_storage( } SegmentType::AccountLeaf3 => { cb.assert_zero("direction is 0", config.direction.current()); + // Note that this constraint doesn't apply if the account doesn't exist. This + // is ok, because every storage key for an empty account is empty. configure_word_rlc( cb, [config.key, key_high, key_low], @@ -1984,12 +1931,6 @@ fn configure_empty_account( config: &MptUpdateConfig, poseidon: &impl PoseidonLookup, ) { - cb.assert( - "path type is start or common for empty account proof", - config - .path_type - .current_matches(&[PathType::Start, PathType::Common]), - ); cb.assert_zero("old value is 0", config.old_value.current()); cb.assert_zero("new value is 0", config.new_value.current()); cb.assert_equal( @@ -2041,9 +1982,9 @@ fn address_high(a: Address) -> u128 { u128::from_be_bytes(high_bytes) } -fn address_low(a: Address) -> u128 { +fn address_low(a: Address) -> u32 { let low_bytes: [u8; 4] = a.0[16..].try_into().unwrap(); - u128::from(u32::from_be_bytes(low_bytes)) << 96 + u32::from_be_bytes(low_bytes) } // ... the return traces: ([inp;2], domain, hash) @@ -2070,7 +2011,7 @@ pub fn hash_traces(proofs: &[Proof]) -> Vec<([Fr; 2], Fr, Fr)> { hash_traces.push(( [ Fr::from_u128(address_high(proof.claim.address)), - Fr::from_u128(address_low(proof.claim.address)), + Fr::from_u128(u128::from(address_low(proof.claim.address)) << 96), ], HashDomain::Pair.into(), key, @@ -2105,6 +2046,8 @@ pub fn hash_traces(proofs: &[Proof]) -> Vec<([Fr; 2], Fr, Fr)> { } } } + hash_traces.sort(); + hash_traces.dedup(); hash_traces } @@ -2137,16 +2080,22 @@ pub fn key_bit_lookups(proofs: &[Proof]) -> Vec<(Fr, usize, bool)> { } lookups.extend(proof.storage.key_bit_lookups()); } + + lookups.sort(); + lookups.dedup(); lookups } /// ... -pub fn byte_representations(proofs: &[Proof]) -> (Vec, Vec, Vec) { +pub fn byte_representations(proofs: &[Proof]) -> (Vec, Vec, Vec, Vec) { + let mut u32s = vec![]; let mut u64s = vec![]; let mut u128s = vec![0]; let mut frs = vec![]; for proof in proofs { + u128s.push(address_high(proof.claim.address)); + u32s.push(address_low(proof.claim.address)); match MPTProofType::from(proof.claim) { MPTProofType::NonceChanged | MPTProofType::CodeSizeExists => { u128s.push(address_high(proof.claim.address)); @@ -2215,7 +2164,20 @@ pub fn byte_representations(proofs: &[Proof]) -> (Vec, Vec, Vec) _ => {} } } - (u64s, u128s, frs) + + u32s.sort(); + u32s.dedup(); + + u64s.sort(); + u64s.dedup(); + + u128s.sort(); + u128s.dedup(); + + frs.sort(); + frs.dedup(); + + (u32s, u64s, u128s, frs) } /// .. @@ -2229,5 +2191,7 @@ pub fn mpt_update_keys(proofs: &[Proof]) -> Vec { keys.push(proof.claim.old_root); keys.push(proof.claim.new_root); } + keys.sort(); + keys.dedup(); keys } diff --git a/src/gadgets/mpt_update/segment.rs b/src/gadgets/mpt_update/segment.rs index eb28a491..011c42ef 100644 --- a/src/gadgets/mpt_update/segment.rs +++ b/src/gadgets/mpt_update/segment.rs @@ -25,6 +25,7 @@ pub fn transitions(proof: MPTProofType) -> HashMap ( SegmentType::Start, vec![ + SegmentType::Start, // empty account proof in an empty mpt SegmentType::AccountTrie, // mpt has > 1 account SegmentType::AccountLeaf0, // mpt has <= 1 account ], @@ -106,6 +107,7 @@ pub fn transitions(proof: MPTProofType) -> HashMap ( SegmentType::Start, vec![ + SegmentType::Start, // empty account proof in an empty mpt SegmentType::AccountTrie, // mpt has > 1 account SegmentType::AccountLeaf0, // mpt has 1 account ], diff --git a/src/gadgets/poseidon.rs b/src/gadgets/poseidon.rs index 0d5ed41c..c216643e 100644 --- a/src/gadgets/poseidon.rs +++ b/src/gadgets/poseidon.rs @@ -1,13 +1,15 @@ -use crate::constraint_builder::{AdviceColumn, ConstraintBuilder, FixedColumn, Query}; +use crate::constraint_builder::{AdviceColumn, FixedColumn}; +use halo2_proofs::plonk::{Advice, Column, Fixed}; +#[cfg(test)] use halo2_proofs::{ - arithmetic::FieldExt, - plonk::{Advice, Column, Fixed}, + arithmetic::FieldExt, circuit::Region, halo2curves::bn256::Fr, plonk::ConstraintSystem, }; #[cfg(test)] -use halo2_proofs::{circuit::Region, halo2curves::bn256::Fr, plonk::ConstraintSystem}; -#[cfg(test)] use hash_circuit::hash::Hashable; +#[cfg(test)] +const MAX_POSEIDON_ROWS: usize = 200; + /// Lookup represent the poseidon table in zkevm circuit pub trait PoseidonLookup { fn lookup_columns(&self) -> (FixedColumn, [AdviceColumn; 6]) { @@ -20,42 +22,6 @@ pub trait PoseidonLookup { } } -impl ConstraintBuilder { - pub fn poseidon_lookup( - &mut self, - name: &'static str, - [left, right, domain, hash]: [Query; 4], - poseidon: &impl PoseidonLookup, - ) { - let extended_queries = [ - Query::one(), - hash, - left, - right, - Query::zero(), - domain, - Query::one(), - ]; - - let (q_enable, [hash, left, right, control, domain_spec, head_mark]) = - poseidon.lookup_columns(); - - self.add_lookup( - name, - extended_queries, - [ - q_enable.current(), - hash.current(), - left.current(), - right.current(), - control.current(), - domain_spec.current(), - head_mark.current(), - ], - ) - } -} - #[cfg(test)] #[derive(Clone, Copy)] pub struct PoseidonTable { @@ -85,6 +51,9 @@ impl PoseidonTable { } pub fn load(&self, region: &mut Region<'_, Fr>, hash_traces: &[([Fr; 2], Fr, Fr)]) { + // The test poseidon table starts assigning from the first row, which has a disabled + // selector, but this is fine because the poseidon_lookup in the ConstraintBuilder + // doesn't include the mpt circuit's selector column. for (offset, hash_trace) in hash_traces.iter().enumerate() { assert!( Hashable::hash_with_domain([hash_trace.0[0], hash_trace.0[1]], hash_trace.1) @@ -104,6 +73,12 @@ impl PoseidonTable { } self.q_enable.assign(region, offset, Fr::one()); } + + // We need to do this so that the fixed columns in the tests will not depend on the + // number of poseidon hashes that are looked up. + for offset in hash_traces.len()..MAX_POSEIDON_ROWS { + self.q_enable.assign(region, offset, Fr::one()); + } } } diff --git a/src/lib.rs b/src/lib.rs index aa76d409..4c353b6b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ -#![allow(dead_code)] #![allow(clippy::too_many_arguments)] #![deny(unsafe_code)] diff --git a/src/mpt.rs b/src/mpt.rs index f0212a7c..12ce206c 100644 --- a/src/mpt.rs +++ b/src/mpt.rs @@ -12,6 +12,7 @@ use crate::{ poseidon::PoseidonLookup, rlc_randomness::RlcRandomness, }, + mpt_table::MPTProofType, types::Proof, }; use halo2_proofs::{ @@ -20,11 +21,13 @@ use halo2_proofs::{ halo2curves::bn256::Fr, plonk::{Challenge, ConstraintSystem, Error, Expression, VirtualCells}, }; +use itertools::Itertools; /// Config for MptCircuit #[derive(Clone)] pub struct MptCircuitConfig { selector: SelectorColumn, + is_final_row: SelectorColumn, rlc_randomness: RlcRandomness, mpt_update: MptUpdateConfig, canonical_representation: CanonicalRepresentationConfig, @@ -68,10 +71,38 @@ impl MptCircuitConfig { &canonical_representation, ); + // This ensures that the final mpt update in the circuit is complete, since the padding + // for the mpt update is a valid proof that shows the account with address 0 does not + // exist in an mpt with root = 0 (i.e. the mpt is empty). + let is_final_row = SelectorColumn(cs.fixed_column()); + let padding_row_expressions = [ + 1.into(), + 0.into(), + 0.into(), + (MPTProofType::AccountDoesNotExist as u64).into(), + 0.into(), + 0.into(), + 0.into(), + 0.into(), + ]; + cb.condition(is_final_row.current(), |cb| { + for (padding_row_expression, lookup_expression) in padding_row_expressions + .into_iter() + .zip_eq(mpt_update.lookup()) + { + cb.assert_equal( + "final mpt update is padding", + padding_row_expression, + lookup_expression, + ) + } + }); + cb.build(cs); Self { selector, + is_final_row, rlc_randomness, mpt_update, key_bit, @@ -88,7 +119,7 @@ impl MptCircuitConfig { n_rows: usize, ) -> Result<(), Error> { let randomness = self.rlc_randomness.value(layouter); - let (u64s, u128s, frs) = byte_representations(proofs); + let (u32s, u64s, u128s, frs) = byte_representations(proofs); layouter.assign_region( || "mpt circuit", @@ -110,28 +141,31 @@ impl MptCircuitConfig { keys.len() ); - self.canonical_representation.assign( + self.canonical_representation + .assign(&mut region, randomness, &keys, n_rows); + self.key_bit.assign(&mut region, &key_bit_lookups(proofs)); + self.byte_bit.assign(&mut region); + self.byte_representation.assign( &mut region, + &u32s, + &u64s, + &u128s, + &frs, randomness, - keys.iter() - .chain(std::iter::repeat(&Fr::zero())) - .take(total_rep_size), ); - self.key_bit.assign(&mut region, &key_bit_lookups(proofs)); - self.byte_bit.assign(&mut region); - self.byte_representation - .assign(&mut region, &u64s, &u128s, &frs, randomness); let n_assigned_rows = self.mpt_update.assign(&mut region, proofs, randomness); assert!( - n_assigned_rows <= n_rows, - "mpt circuit requires {n_assigned_rows} rows > limit of {n_rows} rows" + 2 + n_assigned_rows <= n_rows, + "mpt circuit requires {n_assigned_rows} rows for mpt updates + 1 initial \ + all-zero row + at least 1 final padding row. Only {n_rows} rows available." ); for offset in 1 + n_assigned_rows..n_rows { self.mpt_update.assign_padding_row(&mut region, offset); } + self.is_final_row.enable(&mut region, n_rows - 1); Ok(()) }, @@ -141,4 +175,22 @@ impl MptCircuitConfig { pub fn lookup_exprs(&self, meta: &mut VirtualCells<'_, F>) -> [Expression; 8] { self.mpt_update.lookup().map(|q| q.run(meta)) } + + /// The number of minimum number of rows required for the mpt circuit. + pub fn n_rows_required(proofs: &[Proof]) -> usize { + let (u32s, u64s, u128s, frs) = byte_representations(proofs); + + // +1 for the final padding row to satisfy the "final mpt update is padding" constraint. + 1 + *[ + MptUpdateConfig::n_rows_required(proofs), + CanonicalRepresentationConfig::n_rows_required(&mpt_update_keys(proofs)), + KeyBitConfig::n_rows_required(&key_bit_lookups(proofs)), + // TODO: move rlc lookup for frs into CanonicalRepresentationConfig. + ByteRepresentationConfig::n_rows_required(&u32s, &u64s, &u128s, &frs), + ByteBitGadget::n_rows_required(), + ] + .iter() + .max() + .unwrap() + } } diff --git a/src/tests.rs b/src/tests.rs index d8d460a3..0ea9df52 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -6,12 +6,14 @@ use ethers_core::types::{Address, U256}; use halo2_proofs::{ circuit::{Layouter, SimpleFloorPlanner}, dev::MockProver, - halo2curves::bn256::Fr, - plonk::{Circuit, ConstraintSystem, Error, FirstPhase}, + halo2curves::bn256::{Bn256, Fr}, + plonk::{keygen_vk, Circuit, ConstraintSystem, Error, FirstPhase}, + poly::kzg::commitment::ParamsKZG, }; use mpt_zktrie::state::{builder::HASH_SCHEME_DONE, witness::WitnessGenerator, ZktrieState}; +use rand_chacha::rand_core::SeedableRng; -const N_ROWS: usize = 1024; +const N_ROWS: usize = 8 * 256 + 1; const STORAGE_ADDRESS: Address = Address::repeat_byte(1); fn initial_generator() -> WitnessGenerator { @@ -115,6 +117,34 @@ fn degree() { assert_eq!(meta.degree(), 9); } +#[test] +fn verifying_key_constant() { + let params = ParamsKZG::::setup(17, rand_chacha::ChaCha20Rng::seed_from_u64(2)); + + let no_updates = TestCircuit::new(N_ROWS, vec![]); + let one_update = TestCircuit::new( + N_ROWS, + vec![( + MPTProofType::BalanceChanged, + serde_json::from_str(&include_str!( + "traces/empty_account_type_1_balance_update.json" + )) + .unwrap(), + )], + ); + let vk_no_updates = keygen_vk(¶ms, &no_updates).unwrap(); + let vk_one_update = keygen_vk(¶ms, &one_update).unwrap(); + + assert_eq!( + vk_no_updates.fixed_commitments(), + vk_one_update.fixed_commitments() + ); + assert_eq!( + vk_no_updates.permutation().commitments(), + vk_one_update.permutation().commitments() + ); +} + #[test] fn all_padding() { mock_prove(vec![]); @@ -194,12 +224,59 @@ fn empty_account_proofs_for_zero_value_updates() { MPTProofType::NonceChanged, MPTProofType::CodeSizeExists, MPTProofType::CodeHashExists, + // poseidon code hash is not in this list because the state (rw) circuit will + // translate mpt lookups where the old and new poseidon code hash = 0 in account + // nonexistence proof lookups. ] { mock_prove(vec![(proof_type, trace.clone())]); } } } +#[test] +fn empty_mpt_empty_account_proofs_for_zero_value_updates() { + assert!(*HASH_SCHEME_DONE); + let mut generator = WitnessGenerator::from(&ZktrieState::default()); + let trace = generator.handle_new_state( + mpt_zktrie::mpt_circuits::MPTProofType::AccountDoesNotExist, + Address::repeat_byte(232), + U256::zero(), + U256::zero(), + None, + ); + let json = serde_json::to_string_pretty(&trace).unwrap(); + let type_1_trace: SMTTrace = serde_json::from_str(&json).unwrap(); + + let mut generator = WitnessGenerator::from(&ZktrieState::default()); + generator.handle_new_state( + mpt_zktrie::mpt_circuits::MPTProofType::BalanceChanged, + Address::repeat_byte(1), + U256::from(23), + U256::zero(), + None, + ); + + let trace = generator.handle_new_state( + mpt_zktrie::mpt_circuits::MPTProofType::AccountDoesNotExist, + Address::repeat_byte(2), + U256::zero(), + U256::zero(), + None, + ); + let json = serde_json::to_string_pretty(&trace).unwrap(); + let type_2_trace: SMTTrace = serde_json::from_str(&json).unwrap(); + + for proof_type in [ + MPTProofType::BalanceChanged, + MPTProofType::NonceChanged, + MPTProofType::CodeSizeExists, + MPTProofType::CodeHashExists, + ] { + mock_prove(vec![(proof_type, type_1_trace.clone())]); + mock_prove(vec![(proof_type, type_2_trace.clone())]); + } +} + #[test] fn empty_account_proofs_for_empty_storage_updates() { let type_1_address = Address::zero(); @@ -903,3 +980,131 @@ fn empty_storage_type_2() { mock_prove(vec![(MPTProofType::StorageDoesNotExist, trace)]); } + +#[test] +fn empty_mpt() { + assert!(*HASH_SCHEME_DONE); + let mut generator = WitnessGenerator::from(&ZktrieState::default()); + let trace = generator.handle_new_state( + mpt_zktrie::mpt_circuits::MPTProofType::BalanceChanged, + Address::repeat_byte(2), + U256::from(1231412), + U256::zero(), + None, + ); + let json = serde_json::to_string_pretty(&trace).unwrap(); + let trace: SMTTrace = serde_json::from_str(&json).unwrap(); + + mock_prove(vec![(MPTProofType::BalanceChanged, trace)]); +} + +#[test] +fn empty_mpt_empty_account() { + assert!(*HASH_SCHEME_DONE); + let mut generator = WitnessGenerator::from(&ZktrieState::default()); + let trace = generator.handle_new_state( + mpt_zktrie::mpt_circuits::MPTProofType::AccountDoesNotExist, + Address::repeat_byte(232), + U256::zero(), + U256::zero(), + None, + ); + let json = serde_json::to_string_pretty(&trace).unwrap(); + let trace: SMTTrace = serde_json::from_str(&json).unwrap(); + + mock_prove(vec![(MPTProofType::AccountDoesNotExist, trace)]); +} + +#[test] +fn singleton_mpt() { + assert!(*HASH_SCHEME_DONE); + let mut generator = WitnessGenerator::from(&ZktrieState::default()); + generator.handle_new_state( + mpt_zktrie::mpt_circuits::MPTProofType::BalanceChanged, + Address::repeat_byte(1), + U256::from(23), + U256::zero(), + None, + ); + + let trace = generator.handle_new_state( + mpt_zktrie::mpt_circuits::MPTProofType::BalanceChanged, + Address::repeat_byte(2), + U256::from(15), + U256::zero(), + None, + ); + let json = serde_json::to_string_pretty(&trace).unwrap(); + let trace: SMTTrace = serde_json::from_str(&json).unwrap(); + + mock_prove(vec![(MPTProofType::BalanceChanged, trace)]); +} + +#[test] +fn singleton_mpt_empty_account() { + assert!(*HASH_SCHEME_DONE); + let mut generator = WitnessGenerator::from(&ZktrieState::default()); + generator.handle_new_state( + mpt_zktrie::mpt_circuits::MPTProofType::BalanceChanged, + Address::repeat_byte(1), + U256::from(23), + U256::zero(), + None, + ); + + let trace = generator.handle_new_state( + mpt_zktrie::mpt_circuits::MPTProofType::AccountDoesNotExist, + Address::repeat_byte(2), + U256::zero(), + U256::zero(), + None, + ); + let json = serde_json::to_string_pretty(&trace).unwrap(); + let trace: SMTTrace = serde_json::from_str(&json).unwrap(); + + mock_prove(vec![(MPTProofType::AccountDoesNotExist, trace)]); +} + +#[test] +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!( + "traces/createNameRegistratorPerTxsNotEnoughGas_d0_g0_v0.json" + )) + .unwrap(), + ); +} + +#[test] +fn test_n_rows_required() { + assert!(*HASH_SCHEME_DONE); + let mut generator = WitnessGenerator::from(&ZktrieState::default()); + generator.handle_new_state( + mpt_zktrie::mpt_circuits::MPTProofType::BalanceChanged, + Address::repeat_byte(1), + U256::from(23), + U256::zero(), + None, + ); + + let trace = generator.handle_new_state( + mpt_zktrie::mpt_circuits::MPTProofType::AccountDoesNotExist, + Address::repeat_byte(2), + U256::zero(), + U256::zero(), + None, + ); + let json = serde_json::to_string_pretty(&trace).unwrap(); + let trace: SMTTrace = serde_json::from_str(&json).unwrap(); + + let witness = vec![(MPTProofType::AccountDoesNotExist, trace); 3000]; + let proofs: Vec<_> = witness.clone().into_iter().map(Proof::from).collect(); + + let n_rows_required = MptCircuitConfig::n_rows_required(&proofs); + + let circuit = TestCircuit::new(n_rows_required, witness); + let prover = MockProver::::run(14, &circuit, vec![]).unwrap(); + assert_eq!(prover.verify(), Ok(())); +} diff --git a/src/traces/createNameRegistratorPerTxsNotEnoughGas_d0_g0_v0.json b/src/traces/createNameRegistratorPerTxsNotEnoughGas_d0_g0_v0.json new file mode 100644 index 00000000..33a88d07 --- /dev/null +++ b/src/traces/createNameRegistratorPerTxsNotEnoughGas_d0_g0_v0.json @@ -0,0 +1,463 @@ +[ + [ + "AccountDoesNotExist", + { + "address": "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "accountKey": "0x0c2b7a2233683ca3fdf4cb670d06fffdeb11ad0592b1e7cad87e3e3cc7bcf805", + "accountPath": [ + { + "root": "0x252e31fcfd8f15f35cf1db8a250dc2f9920414047047f8263f509b2ec9d7dd03", + "leaf": { + "value": "0x0fd348b83e56090b7525967291ba6ae3c06f43cb926a41018b279747d702d329", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + }, + { + "root": "0x252e31fcfd8f15f35cf1db8a250dc2f9920414047047f8263f509b2ec9d7dd03", + "leaf": { + "value": "0x0fd348b83e56090b7525967291ba6ae3c06f43cb926a41018b279747d702d329", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + } + ], + "accountUpdate": [ + null, + null + ], + "statePath": [ + null, + null + ], + "commonStateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000" + } + ], + [ + "NonceChanged", + { + "address": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", + "accountKey": "0x293ccdc4280a75784fbdf8c7ae69b76e0852a88b140a7f330f49783d1347f626", + "accountPath": [ + { + "root": "0x252e31fcfd8f15f35cf1db8a250dc2f9920414047047f8263f509b2ec9d7dd03", + "leaf": { + "value": "0x0fd348b83e56090b7525967291ba6ae3c06f43cb926a41018b279747d702d329", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + }, + { + "root": "0x252e31fcfd8f15f35cf1db8a250dc2f9920414047047f8263f509b2ec9d7dd03", + "leaf": { + "value": "0x0fd348b83e56090b7525967291ba6ae3c06f43cb926a41018b279747d702d329", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + } + ], + "accountUpdate": [ + null, + null + ], + "statePath": [ + null, + null + ], + "commonStateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000" + } + ], + [ + "BalanceChanged", + { + "address": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", + "accountKey": "0x293ccdc4280a75784fbdf8c7ae69b76e0852a88b140a7f330f49783d1347f626", + "accountPath": [ + { + "root": "0x252e31fcfd8f15f35cf1db8a250dc2f9920414047047f8263f509b2ec9d7dd03", + "leaf": { + "value": "0x0fd348b83e56090b7525967291ba6ae3c06f43cb926a41018b279747d702d329", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + }, + { + "root": "0x252e31fcfd8f15f35cf1db8a250dc2f9920414047047f8263f509b2ec9d7dd03", + "leaf": { + "value": "0x0fd348b83e56090b7525967291ba6ae3c06f43cb926a41018b279747d702d329", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + } + ], + "accountUpdate": [ + null, + null + ], + "statePath": [ + null, + null + ], + "commonStateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000" + } + ], + [ + "CodeHashExists", + { + "address": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", + "accountKey": "0x293ccdc4280a75784fbdf8c7ae69b76e0852a88b140a7f330f49783d1347f626", + "accountPath": [ + { + "root": "0x252e31fcfd8f15f35cf1db8a250dc2f9920414047047f8263f509b2ec9d7dd03", + "leaf": { + "value": "0x0fd348b83e56090b7525967291ba6ae3c06f43cb926a41018b279747d702d329", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + }, + { + "root": "0x252e31fcfd8f15f35cf1db8a250dc2f9920414047047f8263f509b2ec9d7dd03", + "leaf": { + "value": "0x0fd348b83e56090b7525967291ba6ae3c06f43cb926a41018b279747d702d329", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + } + ], + "accountUpdate": [ + null, + null + ], + "statePath": [ + null, + null + ], + "commonStateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000" + } + ], + [ + "AccountDoesNotExist", + { + "address": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", + "accountKey": "0x293ccdc4280a75784fbdf8c7ae69b76e0852a88b140a7f330f49783d1347f626", + "accountPath": [ + { + "root": "0x252e31fcfd8f15f35cf1db8a250dc2f9920414047047f8263f509b2ec9d7dd03", + "leaf": { + "value": "0x0fd348b83e56090b7525967291ba6ae3c06f43cb926a41018b279747d702d329", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + }, + { + "root": "0x252e31fcfd8f15f35cf1db8a250dc2f9920414047047f8263f509b2ec9d7dd03", + "leaf": { + "value": "0x0fd348b83e56090b7525967291ba6ae3c06f43cb926a41018b279747d702d329", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + } + ], + "accountUpdate": [ + null, + null + ], + "statePath": [ + null, + null + ], + "commonStateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000" + } + ], + [ + "NonceChanged", + { + "address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "accountKey": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "accountPath": [ + { + "root": "0x252e31fcfd8f15f35cf1db8a250dc2f9920414047047f8263f509b2ec9d7dd03", + "leaf": { + "value": "0x0fd348b83e56090b7525967291ba6ae3c06f43cb926a41018b279747d702d329", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + }, + { + "root": "0x21c93afa043be744e054aa90a3021bc3c28df7eb73686826fdb1af882db68d00", + "leaf": { + "value": "0x01a0cb636f821145c93f3fe1c01ef770710634b11442e684e9b2a3a5661ea11c", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + } + ], + "accountUpdate": [ + { + "nonce": 0, + "balance": "0xde0b6b3a7640000", + "codeHash": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", + "poseidonCodeHash": "0x2098f5fb9e239eab3ceac3f27b81e481dc3124d55ffed523a839ee8446b64864", + "codeSize": 0 + }, + { + "nonce": 1, + "balance": "0xde0b6b3a7640000", + "codeHash": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", + "poseidonCodeHash": "0x2098f5fb9e239eab3ceac3f27b81e481dc3124d55ffed523a839ee8446b64864", + "codeSize": 0 + } + ], + "statePath": [ + null, + null + ], + "commonStateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000" + } + ], + [ + "BalanceChanged", + { + "address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "accountKey": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "accountPath": [ + { + "root": "0x21c93afa043be744e054aa90a3021bc3c28df7eb73686826fdb1af882db68d00", + "leaf": { + "value": "0x01a0cb636f821145c93f3fe1c01ef770710634b11442e684e9b2a3a5661ea11c", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + }, + { + "root": "0xb6a81800a5caa2576fc916d7b53dd7abc0439a6b80d177394b3fe0e00b8bbf2e", + "leaf": { + "value": "0xf90e9fb8011123e5fe020cd4d65c150902658a2ef051090d46c6f48de6d2d405", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + } + ], + "accountUpdate": [ + { + "nonce": 1, + "balance": "0xde0b6b3a7640000", + "codeHash": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", + "poseidonCodeHash": "0x2098f5fb9e239eab3ceac3f27b81e481dc3124d55ffed523a839ee8446b64864", + "codeSize": 0 + }, + { + "nonce": 1, + "balance": "0xde0b6b3a75b6e5e", + "codeHash": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", + "poseidonCodeHash": "0x2098f5fb9e239eab3ceac3f27b81e481dc3124d55ffed523a839ee8446b64864", + "codeSize": 0 + } + ], + "statePath": [ + null, + null + ], + "commonStateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000" + } + ], + [ + "StorageDoesNotExist", + { + "address": "0x5300000000000000000000000000000000000000", + "accountKey": "0x0e246ded53daafa183c0d7b6ff1427e8318b63f416ac264dd3ea5ff3dc9b3808", + "accountPath": [ + { + "root": "0xb6a81800a5caa2576fc916d7b53dd7abc0439a6b80d177394b3fe0e00b8bbf2e", + "leaf": { + "value": "0xf90e9fb8011123e5fe020cd4d65c150902658a2ef051090d46c6f48de6d2d405", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + }, + { + "root": "0xb6a81800a5caa2576fc916d7b53dd7abc0439a6b80d177394b3fe0e00b8bbf2e", + "leaf": { + "value": "0xf90e9fb8011123e5fe020cd4d65c150902658a2ef051090d46c6f48de6d2d405", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + } + ], + "accountUpdate": [ + null, + null + ], + "statePath": [ + null, + null + ], + "commonStateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "stateKey": "0x0000000000000000000000000000000000000000000000000000000000000000" + } + ], + [ + "StorageDoesNotExist", + { + "address": "0x5300000000000000000000000000000000000002", + "accountKey": "0xc964ea4804d91b686d3213d75187b806cca56a03a8e669c905fbd1e415689a13", + "accountPath": [ + { + "root": "0xb6a81800a5caa2576fc916d7b53dd7abc0439a6b80d177394b3fe0e00b8bbf2e", + "leaf": { + "value": "0xf90e9fb8011123e5fe020cd4d65c150902658a2ef051090d46c6f48de6d2d405", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + }, + { + "root": "0xb6a81800a5caa2576fc916d7b53dd7abc0439a6b80d177394b3fe0e00b8bbf2e", + "leaf": { + "value": "0xf90e9fb8011123e5fe020cd4d65c150902658a2ef051090d46c6f48de6d2d405", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + } + ], + "accountUpdate": [ + null, + null + ], + "statePath": [ + null, + null + ], + "commonStateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "stateKey": "0x0000000000000000000000000000000000000000000000000000000000000001" + } + ], + [ + "StorageDoesNotExist", + { + "address": "0x5300000000000000000000000000000000000002", + "accountKey": "0xc964ea4804d91b686d3213d75187b806cca56a03a8e669c905fbd1e415689a13", + "accountPath": [ + { + "root": "0xb6a81800a5caa2576fc916d7b53dd7abc0439a6b80d177394b3fe0e00b8bbf2e", + "leaf": { + "value": "0xf90e9fb8011123e5fe020cd4d65c150902658a2ef051090d46c6f48de6d2d405", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + }, + { + "root": "0xb6a81800a5caa2576fc916d7b53dd7abc0439a6b80d177394b3fe0e00b8bbf2e", + "leaf": { + "value": "0xf90e9fb8011123e5fe020cd4d65c150902658a2ef051090d46c6f48de6d2d405", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + } + ], + "accountUpdate": [ + null, + null + ], + "statePath": [ + null, + null + ], + "commonStateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "stateKey": "0x0000000000000000000000000000000000000000000000000000000000000002" + } + ], + [ + "StorageDoesNotExist", + { + "address": "0x5300000000000000000000000000000000000002", + "accountKey": "0xc964ea4804d91b686d3213d75187b806cca56a03a8e669c905fbd1e415689a13", + "accountPath": [ + { + "root": "0xb6a81800a5caa2576fc916d7b53dd7abc0439a6b80d177394b3fe0e00b8bbf2e", + "leaf": { + "value": "0xf90e9fb8011123e5fe020cd4d65c150902658a2ef051090d46c6f48de6d2d405", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + }, + { + "root": "0xb6a81800a5caa2576fc916d7b53dd7abc0439a6b80d177394b3fe0e00b8bbf2e", + "leaf": { + "value": "0xf90e9fb8011123e5fe020cd4d65c150902658a2ef051090d46c6f48de6d2d405", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + } + ], + "accountUpdate": [ + null, + null + ], + "statePath": [ + null, + null + ], + "commonStateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "stateKey": "0x0000000000000000000000000000000000000000000000000000000000000003" + } + ], + [ + "StorageDoesNotExist", + { + "address": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", + "accountKey": "0x293ccdc4280a75784fbdf8c7ae69b76e0852a88b140a7f330f49783d1347f626", + "accountPath": [ + { + "root": "0xb6a81800a5caa2576fc916d7b53dd7abc0439a6b80d177394b3fe0e00b8bbf2e", + "leaf": { + "value": "0xf90e9fb8011123e5fe020cd4d65c150902658a2ef051090d46c6f48de6d2d405", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + }, + { + "root": "0xb6a81800a5caa2576fc916d7b53dd7abc0439a6b80d177394b3fe0e00b8bbf2e", + "leaf": { + "value": "0xf90e9fb8011123e5fe020cd4d65c150902658a2ef051090d46c6f48de6d2d405", + "sibling": "0x44ef89daadd3a70d440f9af05579a1f73d2d9407710c524f21903ee56f3f3f1a", + "node_type": 4 + }, + "pathPart": "0x0" + } + ], + "accountUpdate": [ + null, + null + ], + "statePath": [ + null, + null + ], + "commonStateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "stateKey": "0x0000000000000000000000000000000000000000000000000000000000000001" + } + ] +] diff --git a/src/types.rs b/src/types.rs index 5569980f..7bda6afa 100644 --- a/src/types.rs +++ b/src/types.rs @@ -13,7 +13,6 @@ use itertools::{EitherOrBoth, Itertools}; use num_bigint::BigUint; use num_traits::identities::Zero; -// mod account; pub mod storage; pub mod trie; use storage::StorageProof; @@ -186,7 +185,6 @@ pub struct Proof { pub struct EthAccount { pub nonce: u64, pub code_size: u64, - poseidon_codehash: Fr, pub balance: Fr, pub keccak_codehash: U256, pub storage_root: Fr, @@ -197,7 +195,6 @@ impl From for EthAccount { Self { nonce: account_data.nonce, code_size: account_data.code_size, - poseidon_codehash: fr_from_biguint(&account_data.poseidon_code_hash), balance: fr_from_biguint(&account_data.balance), keccak_codehash: u256_from_biguint(&account_data.code_hash), storage_root: Fr::zero(), // TODO: fixmeeee!!! @@ -230,6 +227,15 @@ pub struct Path { pub leaf_data_hash: Option, // leaf data hash for type 0 and type 1, None for type 2. } +impl Path { + pub fn hash(&self) -> Fr { + match self.leaf_data_hash { + None => Fr::zero(), + Some(data_hash) => domain_hash(self.key, data_hash, HashDomain::Leaf), + } + } +} + impl From<(&MPTProofType, &SMTTrace)> for Claim { fn from((proof_type, trace): (&MPTProofType, &SMTTrace)) -> Self { let [old_root, new_root] = trace.account_path.clone().map(|path| fr(path.root)); @@ -254,7 +260,11 @@ impl From<(&MPTProofType, &SMTTrace)> for ClaimKind { match update { [None, None] => (), [Some(old), Some(new)] => { - // The account must exist, because only contracts with bytecode can modify their own storage slots. + // Accesses to the MPT happen in the order defined in the state (aka rw) circuit, which is not the + // same as the order they occur in the EVM. In the state circuit, nonce and balance modifications + // will precede storage modifications for a given address, which means that the MPT circuit only + // needs to handle storage modifications for existing accounts, even though this is not true in the + // EVM, where the storage of an account can be modified during its construction. if !(account_old == account_new || (account_old.is_none() && account_new == &Some(Default::default()))) { @@ -947,39 +957,10 @@ fn check_hash_traces_new(traces: &[(bool, HashDomain, Fr, Fr, Fr, bool, bool)]) } } -fn bits(x: usize, len: usize) -> Vec { - let mut bits = vec![]; - let mut x = x; - while x != 0 { - bits.push(x % 2 == 1); - x /= 2; - } - bits.resize(len, false); - bits.reverse(); - bits -} - fn fr(x: HexBytes<32>) -> Fr { Fr::from_bytes(&x.0).unwrap() } -fn split_word(x: U256) -> (Fr, Fr) { - let mut bytes = [0; 32]; - x.to_big_endian(&mut bytes); - let high_bytes: [u8; 16] = bytes[..16].try_into().unwrap(); - let low_bytes: [u8; 16] = bytes[16..].try_into().unwrap(); - - let high = Fr::from_u128(u128::from_be_bytes(high_bytes)); - let low = Fr::from_u128(u128::from_be_bytes(low_bytes)); - (high, low) - - // TODO: what's wrong with this? - // let [limb_0, limb_1, limb_2, limb_3] = key.0; - // let key_high = Fr::from_u128(u128::from(limb_2) + u128::from(limb_3) << 64); - // let key_low = Fr::from_u128(u128::from(limb_0) + u128::from(limb_1) << 64); - // hash(key_high, key_low) -} - fn big_uint_to_fr(i: &BigUint) -> Fr { i.to_u64_digits() .iter() diff --git a/src/types/account.rs b/src/types/account.rs deleted file mode 100644 index 28bc3186..00000000 --- a/src/types/account.rs +++ /dev/null @@ -1,166 +0,0 @@ -use crate::{ - serde::{AccountData as SerdeAccountData, SMTNode, SMTTrace}, - types::{storage::StorageProof, trie::TrieRows}, - util::{account_key, fr, fr_from_biguint, hash, split_word, u256_from_biguint}, -}; -use ethers_core::types::{Address, U256}; -use halo2_proofs::halo2curves::bn256::Fr; - -#[derive(Clone, Debug)] -pub struct AccountProof { - account_key: Fr, - trie_rows: TrieRows, - old_leaf: AccountLeaf, - new_leaf: AccountLeaf, - storage: StorageProof, -} - -#[derive(Clone, Debug)] -pub enum AccountLeaf { - Empty { - account_key: Fr, - }, - Leaf { - account_key: Fr, - account_hash: Fr, - }, - Account { - address: Address, - account_data: AccountData, - }, -} - -#[derive(Clone, Copy, Debug, Default)] -pub struct AccountData { - balance: Fr, // We assume that all account balances can fit into 1 field element. - keccak_codehash: U256, - poseidon_codehash: Fr, - code_size: u64, - nonce: u64, -} - -impl AccountData { - fn hash(&self, storage_root: Fr) -> Fr { - hash( - self.poseidon_codehash_sibling(storage_root), - self.poseidon_codehash, - ) - } - - fn packed_nonce_and_codesize(&self) -> Fr { - Fr::from(self.nonce) + Fr::from(self.code_size) * Fr::from(1 << 32).square() - } - - fn hashed_nonce_codesize_balance(&self) -> Fr { - hash(self.packed_nonce_and_codesize(), self.balance) - } - - fn hashed_keccak_codehash(&self) -> Fr { - let (high, low) = split_word(self.keccak_codehash); - hash(high, low) - } - - fn hashed_storage_root_keccak_codehash(&self, storage_root: Fr) -> Fr { - hash(storage_root, self.hashed_keccak_codehash()) - } - - fn poseidon_codehash_sibling(&self, storage_root: Fr) -> Fr { - hash( - self.hashed_nonce_codesize_balance(), - self.hashed_storage_root_keccak_codehash(storage_root), - ) - } -} - -impl AccountProof { - pub fn old_root(&self) -> Fr { - self.trie_rows - .old_root(|| self.old_leaf.hash(self.storage.new_root())) - } - - pub fn new_root(&self) -> Fr { - self.trie_rows - .new_root(|| self.new_leaf.hash(self.storage.old_root())) - } -} - -impl AccountLeaf { - fn new(address: Address, node: &Option, data: &Option) -> Self { - let account_key = account_key(address); - match (node, data) { - (None, None) => Self::Empty { account_key }, - (Some(node), Some(data)) => { - assert_eq!(account_key, fr(node.sibling)); - Self::Account { - address, - account_data: AccountData { - balance: fr_from_biguint(&data.balance), - keccak_codehash: u256_from_biguint(&data.code_hash), - poseidon_codehash: fr_from_biguint(&data.poseidon_code_hash), - code_size: data.code_size, - nonce: data.nonce, - }, - } - } - (Some(node), None) => { - assert_eq!(account_key, fr(node.sibling)); - Self::Leaf { - account_key, - account_hash: fr(node.value), - } - } - (None, Some(_)) => { - unreachable!(); - } - } - } - - fn hash(&self, storage_root: Fr) -> Fr { - match self { - Self::Empty { .. } => Fr::zero(), - Self::Leaf { - account_key, - account_hash, - } => hash(hash(Fr::one(), *account_key), *account_hash), - Self::Account { - address, - account_data, - } => hash( - hash(Fr::one(), account_key(*address)), - account_data.hash(storage_root), - ), - } - } -} - -impl From<&SMTTrace> for AccountProof { - fn from(trace: &SMTTrace) -> Self { - let address = Address::from(trace.address.0); - - let [old_path, new_path] = &trace.account_path; - let old_leaf = old_path.leaf; - let new_leaf = new_path.leaf; - let trie_rows = TrieRows::new( - account_key(address), - &new_path.path, - &new_path.path, - old_path.leaf, - new_path.leaf, - ); - - let [old_entry, new_entry] = &trace.account_update; - let old_leaf = AccountLeaf::new(address, &old_leaf, old_entry); - let new_leaf = AccountLeaf::new(address, &new_leaf, new_entry); - - let account_proof = Self { - account_key: account_key(address), - trie_rows, - old_leaf, - new_leaf, - storage: StorageProof::from(trace), - }; - assert_eq!(account_proof.old_root(), fr(old_path.root)); - assert_eq!(account_proof.new_root(), fr(new_path.root)); - account_proof - } -} diff --git a/src/util.rs b/src/util.rs index 93eafb46..9a366b38 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,8 +1,5 @@ use crate::{constraint_builder::Query, serde::HexBytes, types::HashDomain}; -use ethers_core::{ - k256::elliptic_curve::PrimeField, - types::{Address, U256}, -}; +use ethers_core::types::{Address, U256}; use halo2_proofs::{ arithmetic::{Field, FieldExt}, halo2curves::bn256::Fr, @@ -53,15 +50,6 @@ pub(crate) fn split_word(x: U256) -> (Fr, Fr) { // hash(key_high, key_low) } -pub(crate) fn hi_lo(x: &BigUint) -> (Fr, Fr) { - let mut u64_digits = x.to_u64_digits(); - u64_digits.resize(4, 0); - ( - Fr::from_u128((u128::from(u64_digits[3]) << 64) + u128::from(u64_digits[2])), - Fr::from_u128((u128::from(u64_digits[1]) << 64) + u128::from(u64_digits[0])), - ) -} - pub(crate) fn u256_hi_lo(x: &U256) -> (u128, u128) { let u64_digits = x.0; ( @@ -89,12 +77,6 @@ pub fn u256_from_biguint(x: &BigUint) -> U256 { U256::from_big_endian(&x.to_bytes_be()) } -pub fn u256_to_fr(x: U256) -> Fr { - let mut bytes = [0u8; 32]; - x.to_little_endian(&mut bytes); - Fr::from_repr(bytes).unwrap() -} - pub fn u256_to_big_endian(x: &U256) -> Vec { let mut bytes = [0; 32]; x.to_big_endian(&mut bytes);