diff --git a/Cargo.lock b/Cargo.lock index 7c4e3c25d16d..d98b52070031 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -223,6 +223,16 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aead" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" +dependencies = [ + "crypto-common", + "generic-array 0.14.7", +] + [[package]] name = "aes" version = "0.6.0" @@ -231,7 +241,18 @@ checksum = "884391ef1066acaa41e766ba8f596341b96e93ce34f9a43e7d24bf0a0eaf0561" dependencies = [ "aes-soft", "aesni", - "cipher", + "cipher 0.2.5", +] + +[[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 0.4.4", + "cpufeatures", ] [[package]] @@ -242,8 +263,22 @@ checksum = "7729c3cde54d67063be556aeac75a81330d802f0259500ca40cb52967f975763" dependencies = [ "aes-soft", "aesni", - "cipher", - "ctr", + "cipher 0.2.5", + "ctr 0.6.0", +] + +[[package]] +name = "aes-gcm" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" +dependencies = [ + "aead", + "aes 0.8.3", + "cipher 0.4.4", + "ctr 0.9.2", + "ghash", + "subtle", ] [[package]] @@ -252,7 +287,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be14c7498ea50828a38d0e24a765ed2effe92a705885b57d029cd67d45744072" dependencies = [ - "cipher", + "cipher 0.2.5", "opaque-debug 0.3.0", ] @@ -262,7 +297,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea2e11f5e94c2f7d386164cc2aa1f97823fed6f259e486940a71c174dd01b0ce" dependencies = [ - "cipher", + "cipher 0.2.5", "opaque-debug 0.3.0", ] @@ -762,6 +797,15 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +[[package]] +name = "bitmaps" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031043d04099746d8db04daf1fa424b2bc8bd69d92b25962dcde24da39ab64a2" +dependencies = [ + "typenum", +] + [[package]] name = "bitvec" version = "0.20.4" @@ -894,7 +938,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57a0e8073e8baa88212fb5823574c02ebccb395136ba9a164ab89379ec6072f0" dependencies = [ "block-padding 0.2.1", - "cipher", + "cipher 0.2.5", ] [[package]] @@ -928,6 +972,18 @@ dependencies = [ "zksync_types", ] +[[package]] +name = "blst" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c94087b935a822949d3291a9989ad2b2051ea141eda0fd4e478a75f6aa3e604b" +dependencies = [ + "cc", + "glob", + "threadpool", + "zeroize", +] + [[package]] name = "boojum" version = "0.1.0" @@ -1124,6 +1180,30 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chacha20" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" +dependencies = [ + "cfg-if 1.0.0", + "cipher 0.4.4", + "cpufeatures", +] + +[[package]] +name = "chacha20poly1305" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" +dependencies = [ + "aead", + "chacha20", + "cipher 0.4.4", + "poly1305", + "zeroize", +] + [[package]] name = "chrono" version = "0.4.31" @@ -1175,6 +1255,17 @@ dependencies = [ "generic-array 0.14.7", ] +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", + "zeroize", +] + [[package]] name = "circuit_definitions" version = "0.1.0" @@ -1696,6 +1787,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array 0.14.7", + "rand_core 0.6.4", "typenum", ] @@ -1748,7 +1840,16 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb4a30d54f7443bf3d6191dcd486aca19e67cb3c49fa7a06a319966346707e7f" dependencies = [ - "cipher", + "cipher 0.2.5", +] + +[[package]] +name = "ctr" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" +dependencies = [ + "cipher 0.4.4", ] [[package]] @@ -1761,6 +1862,34 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "curve25519-dalek" +version = "4.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89b8c6a2e4b1f45971ad09761aafb85514a84744b67a95e32c3cc1352d1f65c" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "curve25519-dalek-derive", + "digest 0.10.7", + "fiat-crypto", + "platforms", + "rustc_version", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2 1.0.69", + "quote 1.0.33", + "syn 2.0.38", +] + [[package]] name = "darling" version = "0.13.4" @@ -1840,6 +1969,16 @@ dependencies = [ "zeroize", ] +[[package]] +name = "der" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +dependencies = [ + "const-oid 0.9.5", + "zeroize", +] + [[package]] name = "deranged" version = "0.3.9" @@ -1944,7 +2083,31 @@ dependencies = [ "der 0.6.1", "elliptic-curve", "rfc6979", - "signature", + "signature 1.6.4", +] + +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "pkcs8 0.10.2", + "signature 2.2.0", +] + +[[package]] +name = "ed25519-dalek" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7277392b266383ef8396db7fdeb1e77b6c52fed775f5df15bb24f35b72156980" +dependencies = [ + "curve25519-dalek", + "ed25519", + "rand_core 0.6.4", + "serde", + "sha2 0.10.8", + "zeroize", ] [[package]] @@ -2196,6 +2359,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "fiat-crypto" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f69037fe1b785e84986b4f2cbcf647381876a00671d25ceef715d7812dd7e1dd" + [[package]] name = "findshlibs" version = "0.10.2" @@ -2244,6 +2413,12 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + [[package]] name = "flate2" version = "1.0.28" @@ -2539,6 +2714,16 @@ dependencies = [ "wasi 0.11.0+wasi-snapshot-preview1", ] +[[package]] +name = "ghash" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d930750de5717d2dd0b8c0d42c076c0e884c81a73e6cab859bbd2339c71e3e40" +dependencies = [ + "opaque-debug 0.3.0", + "polyval", +] + [[package]] name = "gimli" version = "0.28.0" @@ -3053,6 +3238,20 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "im" +version = "15.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0acd33ff0285af998aaf9b57342af478078f53492322fafc47450e09397e0e9" +dependencies = [ + "bitmaps", + "rand_core 0.6.4", + "rand_xoshiro", + "sized-chunks", + "typenum", + "version_check", +] + [[package]] name = "impl-codec" version = "0.5.1" @@ -3129,6 +3328,15 @@ dependencies = [ "hashbrown 0.14.2", ] +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "generic-array 0.14.7", +] + [[package]] name = "insta" version = "1.34.0" @@ -3724,6 +3932,38 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "logos" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c000ca4d908ff18ac99b93a062cb8958d331c3220719c52e77cb19cc6ac5d2c1" +dependencies = [ + "logos-derive", +] + +[[package]] +name = "logos-codegen" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc487311295e0002e452025d6b580b77bb17286de87b57138f3b5db711cded68" +dependencies = [ + "beef", + "fnv", + "proc-macro2 1.0.69", + "quote 1.0.33", + "regex-syntax 0.6.29", + "syn 2.0.38", +] + +[[package]] +name = "logos-derive" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbfc0d229f1f42d790440136d941afd806bc9e949e2bcb8faa813b0f00d1267e" +dependencies = [ + "logos-codegen", +] + [[package]] name = "mach" version = "0.3.2" @@ -3873,6 +4113,29 @@ dependencies = [ "sketches-ddsketch", ] +[[package]] +name = "miette" +version = "5.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e" +dependencies = [ + "miette-derive", + "once_cell", + "thiserror", + "unicode-width", +] + +[[package]] +name = "miette-derive" +version = "5.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" +dependencies = [ + "proc-macro2 1.0.69", + "quote 1.0.33", + "syn 2.0.38", +] + [[package]] name = "mime" version = "0.3.17" @@ -3974,6 +4237,12 @@ dependencies = [ "ws2_32-sys", ] +[[package]] +name = "multimap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" + [[package]] name = "multivm" version = "0.1.0" @@ -4361,6 +4630,15 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "ordered-float" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c" +dependencies = [ + "num-traits", +] + [[package]] name = "os_info" version = "3.7.0" @@ -4407,6 +4685,18 @@ dependencies = [ "serde", ] +[[package]] +name = "pairing_ce" +version = "0.28.5" +source = "git+https://github.com/matter-labs/pairing.git?rev=f55393f#f55393fd366596eac792d78525d26e9c4d6ed1ca" +dependencies = [ + "byteorder", + "cfg-if 1.0.0", + "ff_ce", + "rand 0.4.6", + "serde", +] + [[package]] name = "pairing_ce" version = "0.28.5" @@ -4425,7 +4715,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b92ea9ddac0d6e1db7c49991e7d397d34a9fd814b4c93cda53788e8eef94e35" dependencies = [ - "aes", + "aes 0.6.0", "aes-ctr", "block-modes", "digest 0.9.0", @@ -4674,6 +4964,16 @@ dependencies = [ "sha2 0.10.8", ] +[[package]] +name = "petgraph" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" +dependencies = [ + "fixedbitset", + "indexmap 2.0.2", +] + [[package]] name = "pin-project" version = "1.1.3" @@ -4738,12 +5038,28 @@ dependencies = [ "spki 0.6.0", ] +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der 0.7.8", + "spki 0.7.2", +] + [[package]] name = "pkg-config" version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +[[package]] +name = "platforms" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14e6ab3f592e6fb464fc9712d8d6e6912de6473954635fd76a589d832cffcbb0" + [[package]] name = "plotters" version = "0.3.5" @@ -4772,6 +5088,29 @@ dependencies = [ "plotters-backend", ] +[[package]] +name = "poly1305" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" +dependencies = [ + "cpufeatures", + "opaque-debug 0.3.0", + "universal-hash", +] + +[[package]] +name = "polyval" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52cff9d1d4dee5fe6d03729099f4a310a41179e0a10dbf542039873f2e826fb" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "opaque-debug 0.3.0", + "universal-hash", +] + [[package]] name = "portable-atomic" version = "1.5.0" @@ -4929,28 +5268,125 @@ dependencies = [ ] [[package]] -name = "pulldown-cmark" -version = "0.9.3" +name = "prost" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a1a2f1f0a7ecff9c31abbe177637be0e97a0aef46cf8738ece09327985d998" +checksum = "f4fdd22f3b9c31b53c060df4a0613a1c7f062d4115a2b984dd15b1858f7e340d" dependencies = [ - "bitflags 1.3.2", - "memchr", - "unicase", + "bytes 1.5.0", + "prost-derive", ] [[package]] -name = "quanta" -version = "0.9.3" +name = "prost-build" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20afe714292d5e879d8b12740aa223c6a88f118af41870e8b6196e39a02238a8" +checksum = "8bdf592881d821b83d471f8af290226c8d51402259e9bb5be7f9f8bdebbb11ac" dependencies = [ - "crossbeam-utils 0.8.16", - "libc", - "mach", - "once_cell", - "raw-cpuid", - "wasi 0.10.2+wasi-snapshot-preview1", + "bytes 1.5.0", + "heck 0.4.1", + "itertools", + "log", + "multimap", + "once_cell", + "petgraph", + "prettyplease", + "prost", + "prost-types", + "regex", + "syn 2.0.38", + "tempfile", + "which", +] + +[[package]] +name = "prost-derive" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "265baba7fabd416cf5078179f7d2cbeca4ce7a9041111900675ea7c4cb8a4c32" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2 1.0.69", + "quote 1.0.33", + "syn 2.0.38", +] + +[[package]] +name = "prost-reflect" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "057237efdb71cf4b3f9396302a3d6599a92fa94063ba537b66130980ea9909f3" +dependencies = [ + "base64 0.21.5", + "logos", + "miette", + "once_cell", + "prost", + "prost-types", + "serde", + "serde-value", +] + +[[package]] +name = "prost-types" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e081b29f63d83a4bc75cfc9f3fe424f9156cf92d8a4f0c9407cce9a1b67327cf" +dependencies = [ + "prost", +] + +[[package]] +name = "protox" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00bb76c5f6221de491fe2c8f39b106330bbd9762c6511119c07940e10eb9ff11" +dependencies = [ + "bytes 1.5.0", + "miette", + "prost", + "prost-reflect", + "prost-types", + "protox-parse", + "thiserror", +] + +[[package]] +name = "protox-parse" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4581f441c58863525a3e6bec7b8de98188cf75239a56c725a3e7288450a33f" +dependencies = [ + "logos", + "miette", + "prost-types", + "thiserror", +] + +[[package]] +name = "pulldown-cmark" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a1a2f1f0a7ecff9c31abbe177637be0e97a0aef46cf8738ece09327985d998" +dependencies = [ + "bitflags 1.3.2", + "memchr", + "unicase", +] + +[[package]] +name = "quanta" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20afe714292d5e879d8b12740aa223c6a88f118af41870e8b6196e39a02238a8" +dependencies = [ + "crossbeam-utils 0.8.16", + "libc", + "mach", + "once_cell", + "raw-cpuid", + "wasi 0.10.2+wasi-snapshot-preview1", "web-sys", "winapi 0.3.9", ] @@ -4971,6 +5407,15 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "quick-protobuf" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d6da84cc204722a989e01ba2f6e1e276e190f22263d0cb6ce8526fcdb0d2e1f" +dependencies = [ + "byteorder", +] + [[package]] name = "quote" version = "0.6.13" @@ -5191,6 +5636,15 @@ dependencies = [ "rand_core 0.3.1", ] +[[package]] +name = "rand_xoshiro" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" +dependencies = [ + "rand_core 0.6.4", +] + [[package]] name = "raw-cpuid" version = "10.7.0" @@ -5598,7 +6052,7 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "399f290ffc409596022fce5ea5d4138184be4784f2b28c62c59f0d8389059a15" dependencies = [ - "cipher", + "cipher 0.2.5", ] [[package]] @@ -5857,6 +6311,16 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-value" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c" +dependencies = [ + "ordered-float", + "serde", +] + [[package]] name = "serde_derive" version = "1.0.189" @@ -6071,6 +6535,15 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "rand_core 0.6.4", +] + [[package]] name = "similar" version = "2.3.0" @@ -6089,6 +6562,16 @@ dependencies = [ "time", ] +[[package]] +name = "sized-chunks" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16d69225bde7a69b235da73377861095455d298f2b970996eec25ddbb42b3d1e" +dependencies = [ + "bitmaps", + "typenum", +] + [[package]] name = "skeptic" version = "0.13.7" @@ -6138,6 +6621,22 @@ dependencies = [ "rescue_poseidon 0.4.1 (git+https://github.com/matter-labs/rescue-poseidon.git?branch=poseidon2)", ] +[[package]] +name = "snow" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58021967fd0a5eeeb23b08df6cc244a4d4a5b4aec1d27c9e02fad1a58b4cd74e" +dependencies = [ + "aes-gcm", + "blake2 0.10.6 (registry+https://github.com/rust-lang/crates.io-index)", + "chacha20poly1305", + "curve25519-dalek", + "rand_core 0.6.4", + "rustc_version", + "sha2 0.10.8", + "subtle", +] + [[package]] name = "socket2" version = "0.4.10" @@ -6200,6 +6699,16 @@ dependencies = [ "der 0.6.1", ] +[[package]] +name = "spki" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" +dependencies = [ + "base64ct", + "der 0.7.8", +] + [[package]] name = "splitmut" version = "0.2.1" @@ -6555,6 +7064,26 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "test-casing" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2378d657757969a2cec9ec4eb616be8f01be98c21c6467991f91cb182e4653b" +dependencies = [ + "test-casing-macro", +] + +[[package]] +name = "test-casing-macro" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cfbe7811249c4c914b06141b8ac0f2cee2733fb883d05eb19668a45fc60c3d5" +dependencies = [ + "proc-macro2 1.0.69", + "quote 1.0.33", + "syn 2.0.38", +] + [[package]] name = "test-log" version = "0.2.13" @@ -6611,6 +7140,15 @@ dependencies = [ "once_cell", ] +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + [[package]] name = "tikv-jemalloc-sys" version = "0.5.4+5.3.0-patched" @@ -6705,9 +7243,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.33.0" +version = "1.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653" +checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9" dependencies = [ "backtrace", "bytes 1.5.0", @@ -6724,9 +7262,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2 1.0.69", "quote 1.0.33", @@ -7074,6 +7612,16 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" +[[package]] +name = "universal-hash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" +dependencies = [ + "crypto-common", + "subtle", +] + [[package]] name = "unroll" version = "0.1.5" @@ -7418,6 +7966,18 @@ version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc" +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + [[package]] name = "whoami" version = "1.4.1" @@ -7690,6 +8250,20 @@ name = "zeroize" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2 1.0.69", + "quote 1.0.33", + "syn 2.0.38", +] [[package]] name = "zk_evm" @@ -7937,6 +8511,24 @@ dependencies = [ "zksync_utils", ] +[[package]] +name = "zksync_concurrency" +version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=bdf9ed0af965cc7fa32d6c46a35ea065779ede8b#bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" +dependencies = [ + "anyhow", + "once_cell", + "pin-project", + "rand 0.8.5", + "sha3 0.10.8", + "thiserror", + "time", + "tokio", + "tracing", + "tracing-subscriber", + "vise", +] + [[package]] name = "zksync_config" version = "0.1.0" @@ -7946,6 +8538,150 @@ dependencies = [ "zksync_basic_types", ] +[[package]] +name = "zksync_consensus_bft" +version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=bdf9ed0af965cc7fa32d6c46a35ea065779ede8b#bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" +dependencies = [ + "anyhow", + "once_cell", + "rand 0.8.5", + "thiserror", + "tracing", + "vise", + "zksync_concurrency", + "zksync_consensus_crypto", + "zksync_consensus_network", + "zksync_consensus_roles", + "zksync_consensus_storage", + "zksync_consensus_utils", + "zksync_protobuf", +] + +[[package]] +name = "zksync_consensus_crypto" +version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=bdf9ed0af965cc7fa32d6c46a35ea065779ede8b#bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" +dependencies = [ + "anyhow", + "blst", + "ed25519-dalek", + "ff_ce", + "hex", + "pairing_ce 0.28.5 (git+https://github.com/matter-labs/pairing.git?rev=f55393f)", + "rand 0.4.6", + "rand 0.8.5", + "sha3 0.10.8", + "thiserror", + "tracing", +] + +[[package]] +name = "zksync_consensus_executor" +version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=bdf9ed0af965cc7fa32d6c46a35ea065779ede8b#bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" +dependencies = [ + "anyhow", + "prost", + "rand 0.8.5", + "tracing", + "vise", + "zksync_concurrency", + "zksync_consensus_bft", + "zksync_consensus_crypto", + "zksync_consensus_network", + "zksync_consensus_roles", + "zksync_consensus_storage", + "zksync_consensus_sync_blocks", + "zksync_consensus_utils", + "zksync_protobuf", + "zksync_protobuf_build", +] + +[[package]] +name = "zksync_consensus_network" +version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=bdf9ed0af965cc7fa32d6c46a35ea065779ede8b#bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" +dependencies = [ + "anyhow", + "async-trait", + "im", + "once_cell", + "pin-project", + "prost", + "rand 0.8.5", + "snow", + "thiserror", + "tracing", + "vise", + "zksync_concurrency", + "zksync_consensus_crypto", + "zksync_consensus_roles", + "zksync_consensus_utils", + "zksync_protobuf", + "zksync_protobuf_build", +] + +[[package]] +name = "zksync_consensus_roles" +version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=bdf9ed0af965cc7fa32d6c46a35ea065779ede8b#bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" +dependencies = [ + "anyhow", + "bit-vec", + "hex", + "prost", + "rand 0.8.5", + "serde", + "tracing", + "zksync_concurrency", + "zksync_consensus_crypto", + "zksync_consensus_utils", + "zksync_protobuf", + "zksync_protobuf_build", +] + +[[package]] +name = "zksync_consensus_storage" +version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=bdf9ed0af965cc7fa32d6c46a35ea065779ede8b#bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" +dependencies = [ + "anyhow", + "async-trait", + "prost", + "rand 0.8.5", + "thiserror", + "tracing", + "zksync_concurrency", + "zksync_consensus_roles", + "zksync_protobuf", + "zksync_protobuf_build", +] + +[[package]] +name = "zksync_consensus_sync_blocks" +version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=bdf9ed0af965cc7fa32d6c46a35ea065779ede8b#bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" +dependencies = [ + "anyhow", + "thiserror", + "tracing", + "zksync_concurrency", + "zksync_consensus_network", + "zksync_consensus_roles", + "zksync_consensus_storage", + "zksync_consensus_utils", +] + +[[package]] +name = "zksync_consensus_utils" +version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=bdf9ed0af965cc7fa32d6c46a35ea065779ede8b#bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" +dependencies = [ + "thiserror", + "zksync_concurrency", +] + [[package]] name = "zksync_contract_verifier" version = "0.1.0" @@ -8020,11 +8756,13 @@ dependencies = [ "num 0.3.1", "once_cell", "prometheus_exporter", + "prost", "rand 0.8.5", "reqwest", "serde", "serde_json", "tempfile", + "test-casing", "thiserror", "tokio", "tower", @@ -8034,7 +8772,11 @@ dependencies = [ "vlog", "zksync_circuit_breaker", "zksync_commitment_utils", + "zksync_concurrency", "zksync_config", + "zksync_consensus_executor", + "zksync_consensus_roles", + "zksync_consensus_storage", "zksync_contracts", "zksync_dal", "zksync_eth_client", @@ -8044,6 +8786,8 @@ dependencies = [ "zksync_merkle_tree", "zksync_mini_merkle_tree", "zksync_object_store", + "zksync_protobuf", + "zksync_protobuf_build", "zksync_prover_utils", "zksync_queued_job_processor", "zksync_state", @@ -8254,6 +8998,43 @@ dependencies = [ "zksync_types", ] +[[package]] +name = "zksync_protobuf" +version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=bdf9ed0af965cc7fa32d6c46a35ea065779ede8b#bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" +dependencies = [ + "anyhow", + "bit-vec", + "once_cell", + "prost", + "prost-reflect", + "quick-protobuf", + "rand 0.8.5", + "serde", + "serde_json", + "tokio", + "tracing", + "tracing-subscriber", + "zksync_concurrency", + "zksync_protobuf_build", +] + +[[package]] +name = "zksync_protobuf_build" +version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=bdf9ed0af965cc7fa32d6c46a35ea065779ede8b#bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" +dependencies = [ + "anyhow", + "heck 0.4.1", + "prettyplease", + "proc-macro2 1.0.69", + "prost-build", + "prost-reflect", + "protox", + "quote 1.0.33", + "syn 2.0.38", +] + [[package]] name = "zksync_prover_utils" version = "0.1.0" @@ -8368,6 +9149,7 @@ dependencies = [ name = "zksync_types" version = "0.1.0" dependencies = [ + "anyhow", "blake2 0.10.6 (registry+https://github.com/rust-lang/crates.io-index)", "chrono", "codegen 0.1.0", @@ -8377,6 +9159,7 @@ dependencies = [ "num_enum", "once_cell", "parity-crypto", + "prost", "rlp", "secp256k1 0.27.0", "serde", @@ -8389,8 +9172,11 @@ dependencies = [ "zk_evm 1.4.0", "zkevm_test_harness 1.3.3", "zksync_basic_types", + "zksync_consensus_roles", "zksync_contracts", "zksync_mini_merkle_tree", + "zksync_protobuf", + "zksync_protobuf_build", "zksync_system_constants", "zksync_utils", ] diff --git a/core/lib/dal/migrations/20231102144901_add_consensus_fields_for_miniblocks.down.sql b/core/lib/dal/migrations/20231102144901_add_consensus_fields_for_miniblocks.down.sql new file mode 100644 index 000000000000..701c5e608548 --- /dev/null +++ b/core/lib/dal/migrations/20231102144901_add_consensus_fields_for_miniblocks.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE miniblocks + DROP COLUMN IF EXISTS consensus; diff --git a/core/lib/dal/migrations/20231102144901_add_consensus_fields_for_miniblocks.up.sql b/core/lib/dal/migrations/20231102144901_add_consensus_fields_for_miniblocks.up.sql new file mode 100644 index 000000000000..cdfd74990eaf --- /dev/null +++ b/core/lib/dal/migrations/20231102144901_add_consensus_fields_for_miniblocks.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE miniblocks + ADD COLUMN consensus JSONB NULL; diff --git a/core/lib/dal/sqlx-data.json b/core/lib/dal/sqlx-data.json index b69e48b178e2..e031fe7d6715 100644 --- a/core/lib/dal/sqlx-data.json +++ b/core/lib/dal/sqlx-data.json @@ -4410,98 +4410,6 @@ }, "query": "UPDATE contract_verification_requests SET status = 'failed', updated_at = now(), error = $2, compilation_errors = $3, panic_message = $4 WHERE id = $1" }, - "5190fad25f0c476380af4013761d42ae97dbd55f87e38ceec33f8e148c5cbb14": { - "describe": { - "columns": [ - { - "name": "number", - "ordinal": 0, - "type_info": "Int8" - }, - { - "name": "l1_batch_number!", - "ordinal": 1, - "type_info": "Int8" - }, - { - "name": "last_batch_miniblock?", - "ordinal": 2, - "type_info": "Int8" - }, - { - "name": "timestamp", - "ordinal": 3, - "type_info": "Int8" - }, - { - "name": "root_hash?", - "ordinal": 4, - "type_info": "Bytea" - }, - { - "name": "l1_gas_price", - "ordinal": 5, - "type_info": "Int8" - }, - { - "name": "l2_fair_gas_price", - "ordinal": 6, - "type_info": "Int8" - }, - { - "name": "bootloader_code_hash", - "ordinal": 7, - "type_info": "Bytea" - }, - { - "name": "default_aa_code_hash", - "ordinal": 8, - "type_info": "Bytea" - }, - { - "name": "virtual_blocks", - "ordinal": 9, - "type_info": "Int8" - }, - { - "name": "hash", - "ordinal": 10, - "type_info": "Bytea" - }, - { - "name": "protocol_version!", - "ordinal": 11, - "type_info": "Int4" - }, - { - "name": "fee_account_address?", - "ordinal": 12, - "type_info": "Bytea" - } - ], - "nullable": [ - false, - null, - null, - false, - false, - false, - false, - true, - true, - false, - false, - true, - false - ], - "parameters": { - "Left": [ - "Int8" - ] - } - }, - "query": "\n SELECT miniblocks.number,\n COALESCE(miniblocks.l1_batch_number, (SELECT (max(number) + 1) FROM l1_batches)) as \"l1_batch_number!\",\n (SELECT max(m2.number) FROM miniblocks m2 WHERE miniblocks.l1_batch_number = m2.l1_batch_number) as \"last_batch_miniblock?\",\n miniblocks.timestamp,\n miniblocks.hash as \"root_hash?\",\n miniblocks.l1_gas_price,\n miniblocks.l2_fair_gas_price,\n miniblocks.bootloader_code_hash,\n miniblocks.default_aa_code_hash,\n miniblocks.virtual_blocks,\n miniblocks.hash,\n miniblocks.protocol_version as \"protocol_version!\",\n l1_batches.fee_account_address as \"fee_account_address?\"\n FROM miniblocks\n LEFT JOIN l1_batches ON miniblocks.l1_batch_number = l1_batches.number\n WHERE miniblocks.number = $1\n " - }, "51cb712685991ffd600dce59f5ed8b5a1bfce8feed46ebd02471c43802e6e65a": { "describe": { "columns": [ @@ -6178,6 +6086,104 @@ }, "query": "SELECT * FROM call_traces WHERE tx_hash IN (SELECT hash FROM transactions WHERE miniblock_number = $1)" }, + "7947dd8e7d6c138146f7ebe6b1e89fcd494b2679ac4e9fcff6aa2b2944aeed50": { + "describe": { + "columns": [ + { + "name": "number", + "ordinal": 0, + "type_info": "Int8" + }, + { + "name": "l1_batch_number!", + "ordinal": 1, + "type_info": "Int8" + }, + { + "name": "last_batch_miniblock?", + "ordinal": 2, + "type_info": "Int8" + }, + { + "name": "timestamp", + "ordinal": 3, + "type_info": "Int8" + }, + { + "name": "root_hash?", + "ordinal": 4, + "type_info": "Bytea" + }, + { + "name": "l1_gas_price", + "ordinal": 5, + "type_info": "Int8" + }, + { + "name": "l2_fair_gas_price", + "ordinal": 6, + "type_info": "Int8" + }, + { + "name": "bootloader_code_hash", + "ordinal": 7, + "type_info": "Bytea" + }, + { + "name": "default_aa_code_hash", + "ordinal": 8, + "type_info": "Bytea" + }, + { + "name": "virtual_blocks", + "ordinal": 9, + "type_info": "Int8" + }, + { + "name": "hash", + "ordinal": 10, + "type_info": "Bytea" + }, + { + "name": "consensus", + "ordinal": 11, + "type_info": "Jsonb" + }, + { + "name": "protocol_version!", + "ordinal": 12, + "type_info": "Int4" + }, + { + "name": "fee_account_address?", + "ordinal": 13, + "type_info": "Bytea" + } + ], + "nullable": [ + false, + null, + null, + false, + false, + false, + false, + true, + true, + false, + false, + true, + true, + false + ], + "parameters": { + "Left": [ + "Int8" + ] + } + }, + "query": "SELECT miniblocks.number, COALESCE(miniblocks.l1_batch_number, (SELECT (max(number) + 1) FROM l1_batches)) as \"l1_batch_number!\", (SELECT max(m2.number) FROM miniblocks m2 WHERE miniblocks.l1_batch_number = m2.l1_batch_number) as \"last_batch_miniblock?\", miniblocks.timestamp, miniblocks.hash as \"root_hash?\", miniblocks.l1_gas_price, miniblocks.l2_fair_gas_price, miniblocks.bootloader_code_hash, miniblocks.default_aa_code_hash, miniblocks.virtual_blocks, miniblocks.hash, miniblocks.consensus, miniblocks.protocol_version as \"protocol_version!\", l1_batches.fee_account_address as \"fee_account_address?\" FROM miniblocks LEFT JOIN l1_batches ON miniblocks.l1_batch_number = l1_batches.number WHERE miniblocks.number = $1" + }, "79cdb4cdd3c47b3654e6240178985fb4b4420e0634f9482a6ef8169e90200b84": { "describe": { "columns": [ @@ -12321,6 +12327,19 @@ }, "query": "SELECT * FROM eth_txs WHERE id = $1" }, + "fcca1961f34082f7186de607b922fd608166c5af98031e4dcc8a056b89696dbe": { + "describe": { + "columns": [], + "nullable": [], + "parameters": { + "Left": [ + "Int8", + "Jsonb" + ] + } + }, + "query": "UPDATE miniblocks SET consensus = $2 WHERE number = $1" + }, "ff7ff36b86b0e8d1cd7280aa447baef172cb054ffe7e1d742c59bf09b4f414cb": { "describe": { "columns": [ diff --git a/core/lib/dal/src/blocks_dal.rs b/core/lib/dal/src/blocks_dal.rs index 662cdf7b5012..cd894212c3c3 100644 --- a/core/lib/dal/src/blocks_dal.rs +++ b/core/lib/dal/src/blocks_dal.rs @@ -10,7 +10,7 @@ use sqlx::Row; use zksync_types::{ aggregated_operations::AggregatedActionType, - block::{BlockGasCount, L1BatchHeader, MiniblockHeader}, + block::{BlockGasCount, ConsensusBlockFields, L1BatchHeader, MiniblockHeader}, commitment::{L1BatchMetadata, L1BatchWithMetadata}, Address, L1BatchNumber, LogQuery, MiniblockNumber, ProtocolVersionId, H256, MAX_GAS_PER_PUBDATA_BYTE, U256, @@ -466,6 +466,27 @@ impl BlocksDal<'_, '_> { Ok(()) } + /// Sets consensus-related fields for the specified miniblock. + pub async fn set_miniblock_consensus_fields( + &mut self, + miniblock_number: MiniblockNumber, + consensus: &ConsensusBlockFields, + ) -> anyhow::Result<()> { + let result = sqlx::query!( + "UPDATE miniblocks SET consensus = $2 WHERE number = $1", + miniblock_number.0 as i64, + serde_json::to_value(consensus).unwrap(), + ) + .execute(self.storage.conn()) + .await?; + + anyhow::ensure!( + result.rows_affected() == 1, + "Miniblock #{miniblock_number} is not present in Postgres" + ); + Ok(()) + } + pub async fn update_hashes( &mut self, number_and_hashes: &[(MiniblockNumber, H256)], diff --git a/core/lib/dal/src/models/storage_sync.rs b/core/lib/dal/src/models/storage_sync.rs index 052fadcf60a3..b49cfd98acc5 100644 --- a/core/lib/dal/src/models/storage_sync.rs +++ b/core/lib/dal/src/models/storage_sync.rs @@ -2,8 +2,7 @@ use std::convert::TryInto; use zksync_contracts::BaseSystemContractsHashes; use zksync_types::api::en::SyncBlock; -use zksync_types::Transaction; -use zksync_types::{Address, L1BatchNumber, MiniblockNumber, H256}; +use zksync_types::{Address, L1BatchNumber, MiniblockNumber, Transaction, H256}; #[derive(Debug, Clone, sqlx::FromRow)] pub struct StorageSyncBlock { @@ -22,6 +21,7 @@ pub struct StorageSyncBlock { pub protocol_version: i32, pub virtual_blocks: i64, pub hash: Vec, + pub consensus: Option, } impl StorageSyncBlock { @@ -30,12 +30,14 @@ impl StorageSyncBlock { current_operator_address: Address, transactions: Option>, ) -> SyncBlock { + let number = self.number; + SyncBlock { number: MiniblockNumber(self.number as u32), l1_batch_number: L1BatchNumber(self.l1_batch_number as u32), last_in_batch: self .last_batch_miniblock - .map(|n| n == self.number) + .map(|n| n == number) .unwrap_or(false), timestamp: self.timestamp as u64, root_hash: self.root_hash.as_deref().map(H256::from_slice), @@ -60,6 +62,7 @@ impl StorageSyncBlock { virtual_blocks: Some(self.virtual_blocks as u32), hash: Some(H256::from_slice(&self.hash)), protocol_version: (self.protocol_version as u16).try_into().unwrap(), + consensus: self.consensus.map(|v| serde_json::from_value(v).unwrap()), } } } diff --git a/core/lib/dal/src/sync_dal.rs b/core/lib/dal/src/sync_dal.rs index ab905dd5cb22..7b7c13594140 100644 --- a/core/lib/dal/src/sync_dal.rs +++ b/core/lib/dal/src/sync_dal.rs @@ -23,24 +23,23 @@ impl SyncDal<'_, '_> { let latency = MethodLatency::new("sync_dal_sync_block"); let storage_block_details = sqlx::query_as!( StorageSyncBlock, - r#" - SELECT miniblocks.number, - COALESCE(miniblocks.l1_batch_number, (SELECT (max(number) + 1) FROM l1_batches)) as "l1_batch_number!", - (SELECT max(m2.number) FROM miniblocks m2 WHERE miniblocks.l1_batch_number = m2.l1_batch_number) as "last_batch_miniblock?", - miniblocks.timestamp, - miniblocks.hash as "root_hash?", - miniblocks.l1_gas_price, - miniblocks.l2_fair_gas_price, - miniblocks.bootloader_code_hash, - miniblocks.default_aa_code_hash, - miniblocks.virtual_blocks, - miniblocks.hash, - miniblocks.protocol_version as "protocol_version!", - l1_batches.fee_account_address as "fee_account_address?" - FROM miniblocks - LEFT JOIN l1_batches ON miniblocks.l1_batch_number = l1_batches.number - WHERE miniblocks.number = $1 - "#, + "SELECT miniblocks.number, \ + COALESCE(miniblocks.l1_batch_number, (SELECT (max(number) + 1) FROM l1_batches)) as \"l1_batch_number!\", \ + (SELECT max(m2.number) FROM miniblocks m2 WHERE miniblocks.l1_batch_number = m2.l1_batch_number) as \"last_batch_miniblock?\", \ + miniblocks.timestamp, \ + miniblocks.hash as \"root_hash?\", \ + miniblocks.l1_gas_price, \ + miniblocks.l2_fair_gas_price, \ + miniblocks.bootloader_code_hash, \ + miniblocks.default_aa_code_hash, \ + miniblocks.virtual_blocks, \ + miniblocks.hash, \ + miniblocks.consensus, \ + miniblocks.protocol_version as \"protocol_version!\", \ + l1_batches.fee_account_address as \"fee_account_address?\" \ + FROM miniblocks \ + LEFT JOIN l1_batches ON miniblocks.l1_batch_number = l1_batches.number \ + WHERE miniblocks.number = $1", block_number.0 as i64 ) .instrument("sync_dal_sync_block.block") diff --git a/core/lib/types/Cargo.toml b/core/lib/types/Cargo.toml index 35ccb4a93702..117cbdcec8dc 100644 --- a/core/lib/types/Cargo.toml +++ b/core/lib/types/Cargo.toml @@ -10,6 +10,8 @@ keywords = ["blockchain", "zksync"] categories = ["cryptography"] readme = "README.md" +links = "zksync_types_proto" + [dependencies] zksync_system_constants = { path = "../constants" } zksync_utils = { path = "../utils" } @@ -21,10 +23,14 @@ codegen = { git = "https://github.com/matter-labs/solidity_plonk_verifier.git", zkevm_test_harness = { git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.3.3" } zk_evm_1_4_0 = { git = "https://github.com/matter-labs/era-zk_evm.git", branch = "v1.4.0", package = "zk_evm" } zk_evm = { git = "https://github.com/matter-labs/era-zk_evm.git", tag = "v1.3.3-rc2" } +zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" } +zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" } +anyhow = "1.0.75" chrono = { version = "0.4", features = ["serde"] } num = { version = "0.3.1", features = ["serde"] } once_cell = "1.7" +prost = "0.12.1" rlp = "0.5" serde = "1.0.90" serde_json = "1.0.0" @@ -47,3 +53,6 @@ ethereum_types_old = { package = "ethereum-types", version = "0.12.0" } secp256k1 = { version = "0.27", features = ["recovery"] } tokio = { version = "1", features = ["rt", "macros"] } serde_with = { version = "1", features = ["hex"] } + +[build-dependencies] +zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" } diff --git a/core/lib/types/build.rs b/core/lib/types/build.rs new file mode 100644 index 000000000000..464a905e47aa --- /dev/null +++ b/core/lib/types/build.rs @@ -0,0 +1,12 @@ +//! Generates rust code from protobufs. +fn main() { + zksync_protobuf_build::Config { + input_root: "src/proto".into(), + proto_root: "zksync/types".into(), + dependencies: vec!["::zksync_consensus_roles::proto".parse().unwrap()], + protobuf_crate: "::zksync_protobuf".parse().unwrap(), + is_public: true, + } + .generate() + .expect("generate()"); +} diff --git a/core/lib/types/src/api/en.rs b/core/lib/types/src/api/en.rs index 18a83f9f821b..aa3d2955e2e0 100644 --- a/core/lib/types/src/api/en.rs +++ b/core/lib/types/src/api/en.rs @@ -5,7 +5,7 @@ use zk_evm::ethereum_types::Address; use zksync_basic_types::{L1BatchNumber, MiniblockNumber, H256}; use zksync_contracts::BaseSystemContractsHashes; -use crate::ProtocolVersionId; +use crate::{block::ConsensusBlockFields, ProtocolVersionId}; /// Representation of the L2 block, as needed for the EN synchronization. /// This structure has several fields that describe *L1 batch* rather than @@ -44,4 +44,7 @@ pub struct SyncBlock { pub hash: Option, /// Version of the protocol used for this block. pub protocol_version: ProtocolVersionId, + /// Consensus-related information about the block. Not present if consensus is not enabled + /// for the environment. + pub consensus: Option, } diff --git a/core/lib/types/src/block.rs b/core/lib/types/src/block.rs index 1896fe0eb50c..762733f8e214 100644 --- a/core/lib/types/src/block.rs +++ b/core/lib/types/src/block.rs @@ -1,10 +1,13 @@ +use anyhow::Context as _; use serde::{Deserialize, Serialize}; use zksync_system_constants::SYSTEM_BLOCK_INFO_BLOCK_NUMBER_MULTIPLIER; use std::{fmt, ops}; use zksync_basic_types::{H2048, H256, U256}; +use zksync_consensus_roles::validator; use zksync_contracts::BaseSystemContractsHashes; +use zksync_protobuf::{read_required, ProtoFmt}; use crate::{ l2_to_l1_log::{SystemL2ToL1Log, UserL2ToL1Log}, @@ -85,6 +88,43 @@ pub struct MiniblockHeader { pub virtual_blocks: u32, } +/// Consensus-related L2 block (= miniblock) fields. +#[derive(Debug, Clone)] +pub struct ConsensusBlockFields { + /// Hash of the previous consensus block. + pub parent: validator::BlockHeaderHash, + /// Quorum certificate for the block. + pub justification: validator::CommitQC, +} + +impl ProtoFmt for ConsensusBlockFields { + type Proto = crate::proto::ConsensusBlockFields; + fn read(r: &Self::Proto) -> anyhow::Result { + Ok(Self { + parent: read_required(&r.parent).context("parent")?, + justification: read_required(&r.justification).context("justification")?, + }) + } + fn build(&self) -> Self::Proto { + Self::Proto { + parent: Some(self.parent.build()), + justification: Some(self.justification.build()), + } + } +} + +impl Serialize for ConsensusBlockFields { + fn serialize(&self, s: S) -> Result { + zksync_protobuf::serde::serialize(self, s) + } +} + +impl<'de> Deserialize<'de> for ConsensusBlockFields { + fn deserialize>(d: D) -> Result { + zksync_protobuf::serde::deserialize(d) + } +} + /// Data needed to execute a miniblock in the VM. #[derive(Debug)] pub struct MiniblockExecutionData { diff --git a/core/lib/types/src/lib.rs b/core/lib/types/src/lib.rs index 4715a2f86dac..22904eb71b8c 100644 --- a/core/lib/types/src/lib.rs +++ b/core/lib/types/src/lib.rs @@ -62,6 +62,8 @@ pub mod utils; pub mod vk_transform; pub mod vm_version; +mod proto; + /// Denotes the first byte of the special zkSync's EIP-712-signed transaction. pub const EIP_712_TX_TYPE: u8 = 0x71; diff --git a/core/lib/types/src/proto/mod.proto b/core/lib/types/src/proto/mod.proto new file mode 100644 index 000000000000..2fc03e285d35 --- /dev/null +++ b/core/lib/types/src/proto/mod.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package zksync.types; + +import "zksync/roles/validator.proto"; + +message ConsensusBlockFields { + optional roles.validator.BlockHeaderHash parent = 1; + optional roles.validator.CommitQC justification = 2; +} diff --git a/core/lib/types/src/proto/mod.rs b/core/lib/types/src/proto/mod.rs new file mode 100644 index 000000000000..660bf4c5b4cc --- /dev/null +++ b/core/lib/types/src/proto/mod.rs @@ -0,0 +1,2 @@ +#![allow(warnings)] +include!(concat!(env!("OUT_DIR"), "/src/proto/gen.rs")); diff --git a/core/lib/zksync_core/Cargo.toml b/core/lib/zksync_core/Cargo.toml index 4d84757b6fa1..6c8e43763fd1 100644 --- a/core/lib/zksync_core/Cargo.toml +++ b/core/lib/zksync_core/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "zksync_core" version = "0.1.0" -edition = "2018" +edition = "2021" authors = ["The Matter Labs Team "] homepage = "https://zksync.io/" repository = "https://github.com/matter-labs/zksync-era" @@ -39,7 +39,14 @@ zksync_health_check = { path = "../health_check" } vlog = { path = "../vlog" } multivm = { path = "../multivm" } +# Consensus dependenices +zksync_concurrency = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" } +zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" } +zksync_consensus_storage = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" } +zksync_consensus_executor = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" } +zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" } +prost = "0.12.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" itertools = "0.10.3" @@ -84,8 +91,11 @@ actix-web = "4.0.0-beta.8" tracing = "0.1.26" [dev-dependencies] - -assert_matches = "1.5" zksync_test_account = { path = "../test_account" } +assert_matches = "1.5" tempfile = "3.0.2" +test-casing = "0.1.2" + +[build-dependencies] +zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "bdf9ed0af965cc7fa32d6c46a35ea065779ede8b" } diff --git a/core/lib/zksync_core/build.rs b/core/lib/zksync_core/build.rs new file mode 100644 index 000000000000..7e8cc45bb8ce --- /dev/null +++ b/core/lib/zksync_core/build.rs @@ -0,0 +1,12 @@ +//! Generates rust code from protobufs. +fn main() { + zksync_protobuf_build::Config { + input_root: "src/consensus/proto".into(), + proto_root: "zksync/core/consensus".into(), + dependencies: vec![], + protobuf_crate: "::zksync_protobuf".parse().unwrap(), + is_public: false, + } + .generate() + .expect("generate()"); +} diff --git a/core/lib/zksync_core/src/consensus/mod.rs b/core/lib/zksync_core/src/consensus/mod.rs new file mode 100644 index 000000000000..08a02e1dd2a4 --- /dev/null +++ b/core/lib/zksync_core/src/consensus/mod.rs @@ -0,0 +1,10 @@ +use anyhow::Context as _; +use zksync_concurrency::{ctx, time}; +use zksync_consensus_roles::validator; +use zksync_types::block::ConsensusBlockFields; +use zksync_types::{Address, MiniblockNumber}; + +mod payload; +mod proto; + +pub(crate) use payload::Payload; diff --git a/core/lib/zksync_core/src/consensus/payload.rs b/core/lib/zksync_core/src/consensus/payload.rs new file mode 100644 index 000000000000..818d63d74146 --- /dev/null +++ b/core/lib/zksync_core/src/consensus/payload.rs @@ -0,0 +1,92 @@ +use anyhow::Context as _; +use zksync_consensus_roles::validator; +use zksync_protobuf::{required, ProtoFmt}; +use zksync_types::api::en::SyncBlock; +use zksync_types::{Address, L1BatchNumber, Transaction, H256}; + +pub(crate) struct Payload { + pub hash: H256, + pub l1_batch_number: L1BatchNumber, + pub timestamp: u64, + pub l1_gas_price: u64, + pub l2_fair_gas_price: u64, + pub virtual_blocks: u32, + pub operator_address: Address, + pub transactions: Vec, +} + +impl ProtoFmt for Payload { + type Proto = super::proto::Payload; + fn read(r: &Self::Proto) -> anyhow::Result { + let mut transactions = vec![]; + for (i, t) in r.transactions.iter().enumerate() { + transactions.push( + required(&t.json) + .and_then(|s| Ok(serde_json::from_str(&*s)?)) + .with_context(|| format!("transaction[{i}]"))?, + ); + } + Ok(Self { + hash: required(&r.hash) + .and_then(|h| Ok(<[u8; 32]>::try_from(h.as_slice())?.into())) + .context("hash")?, + l1_batch_number: L1BatchNumber( + *required(&r.l1_batch_number).context("l1_batch_number")?, + ), + timestamp: *required(&r.timestamp).context("timestamp")?, + l1_gas_price: *required(&r.l1_gas_price).context("l1_gas_price")?, + l2_fair_gas_price: *required(&r.l2_fair_gas_price).context("l2_fair_gas_price")?, + virtual_blocks: *required(&r.virtual_blocks).context("virtual_blocks")?, + operator_address: required(&r.operator_address) + .and_then(|a| Ok(<[u8; 20]>::try_from(a.as_slice())?.into())) + .context("operator_address")?, + transactions, + }) + } + fn build(&self) -> Self::Proto { + Self::Proto { + hash: Some(self.hash.as_bytes().into()), + l1_batch_number: Some(self.l1_batch_number.0), + timestamp: Some(self.timestamp), + l1_gas_price: Some(self.l1_gas_price), + l2_fair_gas_price: Some(self.l2_fair_gas_price), + virtual_blocks: Some(self.virtual_blocks), + operator_address: Some(self.operator_address.as_bytes().into()), + // Transactions are stored in execution order, therefore order is deterministic. + transactions: self + .transactions + .iter() + .map(|t| super::proto::Transaction { + // TODO: There is no guarantee that json encoding here will be deterministic. + json: Some(serde_json::to_string(t).unwrap()), + }) + .collect(), + } + } +} + +impl TryFrom for Payload { + type Error = anyhow::Error; + fn try_from(block: SyncBlock) -> anyhow::Result { + Ok(Self { + hash: block.hash.unwrap_or_default(), + l1_batch_number: block.l1_batch_number, + timestamp: block.timestamp, + l1_gas_price: block.l1_gas_price, + l2_fair_gas_price: block.l2_fair_gas_price, + virtual_blocks: block.virtual_blocks.unwrap_or(0), + operator_address: block.operator_address, + transactions: block.transactions.context("Transactions are required")?, + }) + } +} + +impl Payload { + pub fn decode(p: &validator::Payload) -> anyhow::Result { + zksync_protobuf::decode(&p.0) + } + + pub fn encode(&self) -> validator::Payload { + validator::Payload(zksync_protobuf::encode(self)) + } +} diff --git a/core/lib/zksync_core/src/consensus/proto/mod.proto b/core/lib/zksync_core/src/consensus/proto/mod.proto new file mode 100644 index 000000000000..6199585899de --- /dev/null +++ b/core/lib/zksync_core/src/consensus/proto/mod.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; + +package zksync.core.consensus; + +message Transaction { + // Default derive(serde::Serialize) encoding of the zksync_types::Transaction. + // TODO(gprusak): it is neither efficient, unique, nor suitable for version control. + // replace with a more robust encoding. + optional string json = 1; // required +} + +message Payload { + optional bytes hash = 1; // required; H256 + optional uint32 l1_batch_number = 2; // required + optional uint64 timestamp = 3; // required; seconds since UNIX epoch + optional uint64 l1_gas_price = 4; // required; gwei + optional uint64 l2_fair_gas_price = 5; // required; gwei + optional uint32 virtual_blocks = 6; // required + optional bytes operator_address = 7; // required; H160 + repeated Transaction transactions = 8; +} diff --git a/core/lib/zksync_core/src/consensus/proto/mod.rs b/core/lib/zksync_core/src/consensus/proto/mod.rs new file mode 100644 index 000000000000..e6ac37696c21 --- /dev/null +++ b/core/lib/zksync_core/src/consensus/proto/mod.rs @@ -0,0 +1,2 @@ +#![allow(warnings)] +include!(concat!(env!("OUT_DIR"), "/src/consensus/proto/gen.rs")); diff --git a/core/lib/zksync_core/src/sync_layer/tests.rs b/core/lib/zksync_core/src/sync_layer/tests.rs index 89b8ce86e739..576cb56dd7dd 100644 --- a/core/lib/zksync_core/src/sync_layer/tests.rs +++ b/core/lib/zksync_core/src/sync_layer/tests.rs @@ -73,6 +73,7 @@ impl MockMainNodeClient { virtual_blocks: Some(!is_fictive as u32), hash: Some(H256::repeat_byte(1)), protocol_version: ProtocolVersionId::latest(), + consensus: None, } });