From f7d2ccb9dc4741d7bda8c875f27d6523554d9bc1 Mon Sep 17 00:00:00 2001 From: dimazhornyk Date: Wed, 25 Sep 2024 17:33:30 +0200 Subject: [PATCH] feat(da-clients): add Celestia client --- Cargo.lock | 872 ++++++++++++++++-- Cargo.toml | 4 + core/bin/zksync_server/src/main.rs | 2 - core/bin/zksync_server/src/node_builder.rs | 18 +- core/lib/basic_types/src/lib.rs | 2 +- .../src/{seed_phrase.rs => secrets.rs} | 17 + .../lib/config/src/configs/da_client/avail.rs | 8 +- .../config/src/configs/da_client/celestia.rs | 15 + core/lib/config/src/configs/da_client/mod.rs | 5 +- core/lib/config/src/configs/mod.rs | 2 +- core/lib/config/src/configs/secrets.rs | 8 +- core/lib/config/src/lib.rs | 4 +- core/lib/config/src/testonly.rs | 13 +- core/lib/env_config/src/da_client.rs | 103 ++- core/lib/protobuf_config/src/da_client.rs | 63 +- core/lib/protobuf_config/src/da_secrets.rs | 37 + core/lib/protobuf_config/src/lib.rs | 1 + .../src/proto/config/da_client.proto | 18 + .../src/proto/config/secrets.proto | 11 - core/lib/protobuf_config/src/secrets.rs | 62 +- core/node/da_clients/Cargo.toml | 8 +- core/node/da_clients/src/avail/client.rs | 25 +- core/node/da_clients/src/avail/sdk.rs | 2 +- core/node/da_clients/src/celestia/client.rs | 97 ++ core/node/da_clients/src/celestia/mod.rs | 3 + core/node/da_clients/src/lib.rs | 2 + core/node/da_clients/src/utils.rs | 8 + .../layers/da_clients/avail.rs | 9 +- .../layers/da_clients/celestia.rs | 45 + .../implementations/layers/da_clients/mod.rs | 1 + .../commands/external_node/prepare_configs.rs | 1 - 31 files changed, 1217 insertions(+), 249 deletions(-) rename core/lib/basic_types/src/{seed_phrase.rs => secrets.rs} (53%) create mode 100644 core/lib/config/src/configs/da_client/celestia.rs create mode 100644 core/lib/protobuf_config/src/da_secrets.rs create mode 100644 core/node/da_clients/src/celestia/client.rs create mode 100644 core/node/da_clients/src/celestia/mod.rs create mode 100644 core/node/da_clients/src/utils.rs create mode 100644 core/node/node_framework/src/implementations/layers/da_clients/celestia.rs diff --git a/Cargo.lock b/Cargo.lock index 8cf76eb7c1c..65706f3f964 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,6 +101,16 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +[[package]] +name = "alloy-rlp" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26154390b1d205a4a7ac7352aa2eb4f81f391399d4e2f546fb81a2f8bb383f62" +dependencies = [ + "arrayvec 0.7.4", + "bytes", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -181,9 +191,133 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.80" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "ark-ff" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1" +checksum = "6b3235cc41ee7a12aaaf2c575a2ad7b46713a8a50bda2fc3b003a04845c05dd6" +dependencies = [ + "ark-ff-asm 0.3.0", + "ark-ff-macros 0.3.0", + "ark-serialize 0.3.0", + "ark-std 0.3.0", + "derivative", + "num-bigint 0.4.6", + "num-traits", + "paste", + "rustc_version 0.3.3", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" +dependencies = [ + "ark-ff-asm 0.4.2", + "ark-ff-macros 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", + "derivative", + "digest 0.10.7", + "itertools 0.10.5", + "num-bigint 0.4.6", + "num-traits", + "paste", + "rustc_version 0.4.0", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db02d390bf6643fb404d3d22d31aee1c4bc4459600aef9113833d17e786c6e44" +dependencies = [ + "quote 1.0.36", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-asm" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" +dependencies = [ + "quote 1.0.36", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fd794a08ccb318058009eefdf15bcaaaaf6f8161eb3345f907222bac38b20" +dependencies = [ + "num-bigint 0.4.6", + "num-traits", + "quote 1.0.36", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" +dependencies = [ + "num-bigint 0.4.6", + "num-traits", + "proc-macro2 1.0.86", + "quote 1.0.36", + "syn 1.0.109", +] + +[[package]] +name = "ark-serialize" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6c2b318ee6e10f8c2853e73a83adc0ccb88995aa978d8a3408d492ab2ee671" +dependencies = [ + "ark-std 0.3.0", + "digest 0.9.0", +] + +[[package]] +name = "ark-serialize" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +dependencies = [ + "ark-std 0.4.0", + "digest 0.10.7", + "num-bigint 0.4.6", +] + +[[package]] +name = "ark-std" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df2c09229cbc5a028b1d70e00fdb2acee28b1055dfb5ca73eea49c5a25c4e7c" +dependencies = [ + "num-traits", + "rand 0.8.5", +] + +[[package]] +name = "ark-std" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" +dependencies = [ + "num-traits", + "rand 0.8.5", +] [[package]] name = "arr_macro" @@ -395,9 +529,9 @@ checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" [[package]] name = "async-trait" -version = "0.1.74" +version = "0.1.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.36", @@ -436,6 +570,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "auto_impl" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" +dependencies = [ + "proc-macro2 1.0.86", + "quote 1.0.36", + "syn 2.0.72", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -552,6 +697,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base-x" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" + [[package]] name = "base16ct" version = "0.1.1" @@ -603,6 +754,12 @@ dependencies = [ "serde", ] +[[package]] +name = "bech32" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" + [[package]] name = "beef" version = "0.5.2" @@ -650,7 +807,7 @@ dependencies = [ "proc-macro2 1.0.86", "quote 1.0.36", "regex", - "rustc-hash", + "rustc-hash 1.1.0", "shlex", "syn 2.0.72", ] @@ -672,7 +829,7 @@ dependencies = [ "proc-macro2 1.0.86", "quote 1.0.36", "regex", - "rustc-hash", + "rustc-hash 1.1.0", "shlex", "syn 2.0.72", "which", @@ -869,6 +1026,18 @@ dependencies = [ "piper", ] +[[package]] +name = "blockstore" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7679095248a6dc7555fae81154ed1baef264383c16621ef881a219576c72a9be" +dependencies = [ + "cid", + "dashmap 6.1.0", + "multihash", + "thiserror", +] + [[package]] name = "blst" version = "0.3.13" @@ -1002,6 +1171,9 @@ name = "bytes" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +dependencies = [ + "serde", +] [[package]] name = "bytesize" @@ -1046,7 +1218,7 @@ checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" dependencies = [ "camino", "cargo-platform", - "semver", + "semver 1.0.23", "serde", "serde_json", ] @@ -1068,6 +1240,111 @@ dependencies = [ "shlex", ] +[[package]] +name = "celestia-proto" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cde2c574760f88d5a6da8dfc55dbb79d91f4da15aa87b9e0d57d4d3a8fa5687" +dependencies = [ + "anyhow", + "celestia-tendermint-proto", + "prost 0.12.6", + "prost-build", + "prost-types", + "serde", +] + +[[package]] +name = "celestia-rpc" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d646d10aab818ffd785f841f42e16ed5875358f4e51d98a47a14ce07f093b3fc" +dependencies = [ + "async-trait", + "celestia-types", + "http 1.1.0", + "jsonrpsee 0.24.4", + "serde", + "thiserror", + "tracing", +] + +[[package]] +name = "celestia-tendermint" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce8c92a01145f79a0f3ac7c44a43a9b5ee58e8a4c716b56d98833a3848db1afd" +dependencies = [ + "bytes", + "celestia-tendermint-proto", + "digest 0.10.7", + "ed25519", + "ed25519-consensus", + "flex-error", + "futures 0.3.30", + "num-traits", + "once_cell", + "prost 0.12.6", + "prost-types", + "serde", + "serde_bytes", + "serde_json", + "serde_repr", + "sha2 0.10.8", + "signature 2.2.0", + "subtle", + "subtle-encoding", + "time", + "zeroize", +] + +[[package]] +name = "celestia-tendermint-proto" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a95746c5221a74d7b913a415fdbb9e7c90e1b4d818dbbff59bddc034cfce2ec" +dependencies = [ + "bytes", + "flex-error", + "num-derive 0.3.3", + "num-traits", + "prost 0.12.6", + "prost-types", + "serde", + "serde_bytes", + "subtle-encoding", + "time", +] + +[[package]] +name = "celestia-types" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368ef03ae3e0ee840d5629414d58cfe822cef0d4ab92e04f4441b39f658d87d9" +dependencies = [ + "base64 0.22.1", + "bech32", + "blockstore", + "bytes", + "celestia-proto", + "celestia-tendermint", + "celestia-tendermint-proto", + "cid", + "const_format", + "enum_dispatch", + "leopard-codec", + "libp2p-identity", + "multiaddr", + "multihash", + "nmt-rs", + "ruint", + "serde", + "serde_repr", + "sha2 0.10.8", + "thiserror", + "time", +] + [[package]] name = "cesu8" version = "1.1.0" @@ -1161,6 +1438,18 @@ dependencies = [ "half", ] +[[package]] +name = "cid" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3147d8272e8fa0ccd29ce51194dd98f79ddfb8191ba9e3409884e751798acf3a" +dependencies = [ + "core2", + "multibase", + "multihash", + "unsigned-varint 0.8.0", +] + [[package]] name = "cipher" version = "0.4.4" @@ -1505,6 +1794,15 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +[[package]] +name = "core2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49ba7ef1ad6107f8824dbe97de947cbaac53c44e7f9756a1fba0d37c1eec505" +dependencies = [ + "memchr", +] + [[package]] name = "cpufeatures" version = "0.2.10" @@ -1733,7 +2031,7 @@ dependencies = [ "curve25519-dalek-derive", "digest 0.10.7", "fiat-crypto", - "rustc_version", + "rustc_version 0.4.0", "subtle", "zeroize", ] @@ -1749,6 +2047,19 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "curve25519-dalek-ng" +version = "4.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c359b7249347e46fb28804470d071c921156ad62b3eef5d34e2ba867533dec8" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.6.4", + "subtle-ng", + "zeroize", +] + [[package]] name = "darling" version = "0.13.4" @@ -1867,6 +2178,46 @@ dependencies = [ "parking_lot_core", ] +[[package]] +name = "dashmap" +version = "6.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" +dependencies = [ + "cfg-if", + "crossbeam-utils", + "hashbrown 0.14.5", + "lock_api", + "once_cell", + "parking_lot_core", +] + +[[package]] +name = "data-encoding" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" + +[[package]] +name = "data-encoding-macro" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1559b6cba622276d6d63706db152618eeb15b89b3e4041446b05876e352e639" +dependencies = [ + "data-encoding", + "data-encoding-macro-internal", +] + +[[package]] +name = "data-encoding-macro-internal" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "332d754c0af53bc87c108fed664d121ecf59207ec4196041f04d6ab9002ad33f" +dependencies = [ + "data-encoding", + "syn 1.0.109", +] + [[package]] name = "debugid" version = "0.8.0" @@ -1928,7 +2279,7 @@ dependencies = [ "convert_case 0.4.0", "proc-macro2 1.0.86", "quote 1.0.36", - "rustc_version", + "rustc_version 0.4.0", "syn 2.0.72", ] @@ -2040,6 +2391,19 @@ dependencies = [ "signature 2.2.0", ] +[[package]] +name = "ed25519-consensus" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c8465edc8ee7436ffea81d21a019b16676ee3db267aa8d5a8d729581ecf998b" +dependencies = [ + "curve25519-dalek-ng", + "hex", + "rand_core 0.6.4", + "sha2 0.9.9", + "zeroize", +] + [[package]] name = "ed25519-dalek" version = "2.0.0" @@ -2293,12 +2657,33 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "eyre" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" +dependencies = [ + "indenter", + "once_cell", +] + [[package]] name = "fastrand" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +[[package]] +name = "fastrlp" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139834ddba373bbdd213dffe02c8d110508dcf1726c2be27e8d1f7d7e1856418" +dependencies = [ + "arrayvec 0.7.4", + "auto_impl", + "bytes", +] + [[package]] name = "ff" version = "0.12.1" @@ -2389,6 +2774,16 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "flex-error" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c606d892c9de11507fa0dcffc116434f94e105d0bbdc4e405b61519464c49d7b" +dependencies = [ + "eyre", + "paste", +] + [[package]] name = "flume" version = "0.11.0" @@ -2483,7 +2878,7 @@ dependencies = [ "itertools 0.10.5", "lazy_static", "num-bigint 0.4.6", - "num-derive", + "num-derive 0.2.5", "num-integer", "num-traits", "rand 0.4.6", @@ -2852,7 +3247,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19775995ee20209163239355bc3ad2f33f83da35d9ef72dea26e5af753552c87" dependencies = [ - "dashmap", + "dashmap 5.5.3", "futures 0.3.30", "futures-timer", "no-std-compat", @@ -3022,9 +3417,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hkdf" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" dependencies = [ "hmac 0.12.1", ] @@ -3385,6 +3780,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + [[package]] name = "indexmap" version = "1.9.3" @@ -3541,15 +3942,29 @@ dependencies = [ "jsonrpsee-client-transport 0.23.2", "jsonrpsee-core 0.23.2", "jsonrpsee-http-client 0.23.2", - "jsonrpsee-proc-macros", + "jsonrpsee-proc-macros 0.23.2", "jsonrpsee-server", "jsonrpsee-types 0.23.2", "jsonrpsee-wasm-client", - "jsonrpsee-ws-client", + "jsonrpsee-ws-client 0.23.2", "tokio", "tracing", ] +[[package]] +name = "jsonrpsee" +version = "0.24.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd1ead9fb95614e8dc5556d12a8681c2f6d352d0c1d3efc8708c7ccbba47bc6" +dependencies = [ + "jsonrpsee-core 0.24.4", + "jsonrpsee-http-client 0.24.4", + "jsonrpsee-proc-macros 0.24.4", + "jsonrpsee-types 0.24.4", + "jsonrpsee-ws-client 0.24.4", + "tracing", +] + [[package]] name = "jsonrpsee-client-transport" version = "0.21.0" @@ -3560,12 +3975,37 @@ dependencies = [ "http 0.2.9", "jsonrpsee-core 0.21.0", "pin-project", - "rustls-native-certs 0.7.0", + "rustls-native-certs 0.7.0", + "rustls-pki-types", + "soketto 0.7.1", + "thiserror", + "tokio", + "tokio-rustls 0.25.0", + "tokio-util", + "tracing", + "url", +] + +[[package]] +name = "jsonrpsee-client-transport" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08163edd8bcc466c33d79e10f695cdc98c00d1e6ddfb95cec41b6b0279dd5432" +dependencies = [ + "base64 0.22.1", + "futures-channel", + "futures-util", + "gloo-net", + "http 1.1.0", + "jsonrpsee-core 0.23.2", + "pin-project", + "rustls 0.23.10", "rustls-pki-types", - "soketto 0.7.1", + "rustls-platform-verifier", + "soketto 0.8.0", "thiserror", "tokio", - "tokio-rustls 0.25.0", + "tokio-rustls 0.26.0", "tokio-util", "tracing", "url", @@ -3573,16 +4013,14 @@ dependencies = [ [[package]] name = "jsonrpsee-client-transport" -version = "0.23.2" +version = "0.24.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08163edd8bcc466c33d79e10f695cdc98c00d1e6ddfb95cec41b6b0279dd5432" +checksum = "89841d4f03a14c055eb41d4f41901819573ef948e8ee0d5c86466fd286b2ce7f" dependencies = [ "base64 0.22.1", - "futures-channel", "futures-util", - "gloo-net", "http 1.1.0", - "jsonrpsee-core 0.23.2", + "jsonrpsee-core 0.24.4", "pin-project", "rustls 0.23.10", "rustls-pki-types", @@ -3611,7 +4049,7 @@ dependencies = [ "hyper 0.14.29", "jsonrpsee-types 0.21.0", "pin-project", - "rustc-hash", + "rustc-hash 1.1.0", "serde", "serde_json", "thiserror", @@ -3639,7 +4077,7 @@ dependencies = [ "parking_lot", "pin-project", "rand 0.8.5", - "rustc-hash", + "rustc-hash 1.1.0", "serde", "serde_json", "thiserror", @@ -3649,6 +4087,30 @@ dependencies = [ "wasm-bindgen-futures", ] +[[package]] +name = "jsonrpsee-core" +version = "0.24.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff79651479f69ada7bda604ef2acf3f1aa50755d97cc36d25ff04c2664f9d96f" +dependencies = [ + "async-trait", + "bytes", + "futures-timer", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "jsonrpsee-types 0.24.4", + "pin-project", + "rustc-hash 2.0.0", + "serde", + "serde_json", + "thiserror", + "tokio", + "tokio-stream", + "tracing", +] + [[package]] name = "jsonrpsee-http-client" version = "0.21.0" @@ -3694,6 +4156,31 @@ dependencies = [ "url", ] +[[package]] +name = "jsonrpsee-http-client" +version = "0.24.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ed8b301b19f4dad8ddc66ed956a70fc227def5c19b3898e0a29ce8f0edee06" +dependencies = [ + "async-trait", + "base64 0.22.1", + "http-body 1.0.0", + "hyper 1.3.1", + "hyper-rustls 0.27.2", + "hyper-util", + "jsonrpsee-core 0.24.4", + "jsonrpsee-types 0.24.4", + "rustls 0.23.10", + "rustls-platform-verifier", + "serde", + "serde_json", + "thiserror", + "tokio", + "tower", + "tracing", + "url", +] + [[package]] name = "jsonrpsee-proc-macros" version = "0.23.2" @@ -3707,6 +4194,19 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "jsonrpsee-proc-macros" +version = "0.24.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0d4c6bec4909c966f59f52db3655c0e9d4685faae8b49185973d9d7389bb884" +dependencies = [ + "heck 0.5.0", + "proc-macro-crate 3.1.0", + "proc-macro2 1.0.86", + "quote 1.0.36", + "syn 2.0.72", +] + [[package]] name = "jsonrpsee-server" version = "0.23.2" @@ -3761,6 +4261,18 @@ dependencies = [ "thiserror", ] +[[package]] +name = "jsonrpsee-types" +version = "0.24.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "531e386460425e49679587871a056f2895a47dade21457324ad1262cd78ef6d9" +dependencies = [ + "http 1.1.0", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "jsonrpsee-wasm-client" version = "0.23.2" @@ -3785,6 +4297,19 @@ dependencies = [ "url", ] +[[package]] +name = "jsonrpsee-ws-client" +version = "0.24.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87bc869e143d430e748988261d19b630e8f1692074e68f1a7f0eb4c521d2fc58" +dependencies = [ + "http 1.1.0", + "jsonrpsee-client-transport 0.24.4", + "jsonrpsee-core 0.24.4", + "jsonrpsee-types 0.24.4", + "url", +] + [[package]] name = "jsonwebtoken" version = "9.3.0" @@ -3856,6 +4381,17 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" +[[package]] +name = "leopard-codec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee58dbc414bd23885d7da915e0457618b36d1fc950a6169ef2cb29829d1b1a1d" +dependencies = [ + "bytes", + "lazy_static", + "thiserror", +] + [[package]] name = "libc" version = "0.2.155" @@ -3878,6 +4414,21 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "libp2p-identity" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cca1eb2bc1fd29f099f3daaab7effd01e1a54b7c577d0ed082521034d912e8" +dependencies = [ + "bs58", + "hkdf", + "multihash", + "quick-protobuf", + "sha2 0.10.8", + "thiserror", + "tracing", +] + [[package]] name = "librocksdb-sys" version = "0.11.0+8.1.1" @@ -4195,7 +4746,7 @@ checksum = "23e0b72e7c9042467008b10279fc732326bd605459ae03bda88825909dd19b56" dependencies = [ "crossbeam-channel", "crossbeam-utils", - "dashmap", + "dashmap 5.5.3", "skeptic", "smallvec", "tagptr", @@ -4252,6 +4803,46 @@ dependencies = [ "version_check", ] +[[package]] +name = "multiaddr" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe6351f60b488e04c1d21bc69e56b89cb3f5e8f5d22557d6e8031bdfd79b6961" +dependencies = [ + "arrayref", + "byteorder", + "data-encoding", + "libp2p-identity", + "multibase", + "multihash", + "percent-encoding", + "serde", + "static_assertions", + "unsigned-varint 0.8.0", + "url", +] + +[[package]] +name = "multibase" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b3539ec3c1f04ac9748a260728e855f261b4977f5c3406612c884564f329404" +dependencies = [ + "base-x", + "data-encoding", + "data-encoding-macro", +] + +[[package]] +name = "multihash" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "076d548d76a0e2a0d4ab471d0b1c36c577786dfc4471242035d97a12a735c492" +dependencies = [ + "core2", + "unsigned-varint 0.7.2", +] + [[package]] name = "multimap" version = "0.8.3" @@ -4287,6 +4878,18 @@ dependencies = [ "libc", ] +[[package]] +name = "nmt-rs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e408e823bdc9b4bb525a61b44e846239833a8f9bd86c03a43e4ca314a5497582" +dependencies = [ + "borsh", + "bytes", + "serde", + "sha2 0.10.8", +] + [[package]] name = "no-std-compat" version = "0.4.1" @@ -4411,6 +5014,17 @@ dependencies = [ "syn 0.15.44", ] +[[package]] +name = "num-derive" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +dependencies = [ + "proc-macro2 1.0.86", + "quote 1.0.36", + "syn 1.0.109", +] + [[package]] name = "num-integer" version = "0.1.46" @@ -5184,14 +5798,30 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "proptest" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4c2511913b88df1637da85cc8d96ec8e43a3f8bb8ccb71ee1ac240d6f3df58d" +dependencies = [ + "bitflags 2.6.0", + "lazy_static", + "num-traits", + "rand 0.8.5", + "rand_chacha", + "rand_xorshift", + "regex-syntax 0.8.2", + "unarray", +] + [[package]] name = "prost" -version = "0.12.1" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fdd22f3b9c31b53c060df4a0613a1c7f062d4115a2b984dd15b1858f7e340d" +checksum = "deb1435c188b76130da55f17a466d252ff7b1418b2ad3e037d127b94e3411f29" dependencies = [ "bytes", - "prost-derive 0.12.1", + "prost-derive 0.12.6", ] [[package]] @@ -5206,34 +5836,33 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.12.1" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bdf592881d821b83d471f8af290226c8d51402259e9bb5be7f9f8bdebbb11ac" +checksum = "22505a5c94da8e3b7c2996394d1c933236c4d743e81a410bcca4e6989fc066a4" dependencies = [ "bytes", - "heck 0.4.1", - "itertools 0.10.5", + "heck 0.5.0", + "itertools 0.12.0", "log", "multimap", "once_cell", "petgraph", "prettyplease", - "prost 0.12.1", + "prost 0.12.6", "prost-types", "regex", "syn 2.0.72", "tempfile", - "which", ] [[package]] name = "prost-derive" -version = "0.12.1" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "265baba7fabd416cf5078179f7d2cbeca4ce7a9041111900675ea7c4cb8a4c32" +checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" dependencies = [ "anyhow", - "itertools 0.10.5", + "itertools 0.12.0", "proc-macro2 1.0.86", "quote 1.0.36", "syn 2.0.72", @@ -5262,7 +5891,7 @@ dependencies = [ "logos", "miette", "once_cell", - "prost 0.12.1", + "prost 0.12.6", "prost-types", "serde", "serde-value", @@ -5270,11 +5899,11 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.12.1" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e081b29f63d83a4bc75cfc9f3fe424f9156cf92d8a4f0c9407cce9a1b67327cf" +checksum = "9091c90b0a32608e984ff2fa4091273cbdd755d54935c51d520887f4a1dbd5b0" dependencies = [ - "prost 0.12.1", + "prost 0.12.6", ] [[package]] @@ -5285,7 +5914,7 @@ checksum = "00bb76c5f6221de491fe2c8f39b106330bbd9762c6511119c07940e10eb9ff11" dependencies = [ "bytes", "miette", - "prost 0.12.1", + "prost 0.12.6", "prost-reflect", "prost-types", "protox-parse", @@ -5448,6 +6077,15 @@ 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 0.6.4", +] + [[package]] name = "rand_xoshiro" version = "0.6.0" @@ -5792,6 +6430,36 @@ dependencies = [ "zeroize", ] +[[package]] +name = "ruint" +version = "1.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c3cc4c2511671f327125da14133d0c5c5d137f006a1017a16f557bc85b16286" +dependencies = [ + "alloy-rlp", + "ark-ff 0.3.0", + "ark-ff 0.4.2", + "bytes", + "fastrlp", + "num-bigint 0.4.6", + "num-traits", + "parity-scale-codec", + "primitive-types", + "proptest", + "rand 0.8.5", + "rlp", + "ruint-macro", + "serde", + "valuable", + "zeroize", +] + +[[package]] +name = "ruint-macro" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" + [[package]] name = "rust_decimal" version = "1.33.1" @@ -5820,19 +6488,34 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[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.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" +dependencies = [ + "semver 0.11.0", +] + [[package]] name = "rustc_version" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver", + "semver 1.0.23", ] [[package]] @@ -6291,6 +6974,15 @@ dependencies = [ "tokio", ] +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser", +] + [[package]] name = "semver" version = "1.0.23" @@ -6300,6 +6992,15 @@ dependencies = [ "serde", ] +[[package]] +name = "semver-parser" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +dependencies = [ + "pest", +] + [[package]] name = "send_wrapper" version = "0.4.0" @@ -6346,7 +7047,7 @@ dependencies = [ "hostname", "libc", "os_info", - "rustc_version", + "rustc_version 0.4.0", "sentry-core", "uname", ] @@ -6481,6 +7182,17 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_repr" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" +dependencies = [ + "proc-macro2 1.0.86", + "quote 1.0.36", + "syn 2.0.72", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -6878,7 +7590,7 @@ dependencies = [ "chacha20poly1305", "curve25519-dalek", "rand_core 0.6.4", - "rustc_version", + "rustc_version 0.4.0", "sha2 0.10.8", "subtle", ] @@ -7285,6 +7997,21 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +[[package]] +name = "subtle-encoding" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dcb1ed7b8330c5eed5441052651dd7a12c75e2ed88f2ec024ae1fa3a5e59945" +dependencies = [ + "zeroize", +] + +[[package]] +name = "subtle-ng" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "734676eb262c623cec13c3155096e08d1f8f29adce39ba17948b18dad1e54142" + [[package]] name = "subxt" version = "0.34.0" @@ -8132,6 +8859,12 @@ dependencies = [ "libc", ] +[[package]] +name = "unarray" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" + [[package]] name = "unicase" version = "2.7.0" @@ -8218,6 +8951,18 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab4c90930b95a82d00dc9e9ac071b4991924390d46cbd0dfe566148667605e4b" +[[package]] +name = "unsigned-varint" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6889a77d49f1f013504cec6bf97a2c730394adedaeb1deb5ea08949a50541105" + +[[package]] +name = "unsigned-varint" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb066959b24b5196ae73cb057f45598450d2c5f71460e98c49b738086eff9c06" + [[package]] name = "untrusted" version = "0.9.0" @@ -9406,7 +10151,7 @@ dependencies = [ "anyhow", "async-trait", "rand 0.8.5", - "semver", + "semver 1.0.23", "tracing", "vise", "zksync_concurrency", @@ -9436,9 +10181,9 @@ dependencies = [ "im", "once_cell", "pin-project", - "prost 0.12.1", + "prost 0.12.6", "rand 0.8.5", - "semver", + "semver 1.0.23", "snow", "thiserror", "tls-listener", @@ -9465,7 +10210,7 @@ dependencies = [ "bit-vec", "hex", "num-bigint 0.4.6", - "prost 0.12.1", + "prost 0.12.6", "rand 0.8.5", "serde", "thiserror", @@ -9485,7 +10230,7 @@ checksum = "7b9dbcb923fa201af03f49f70c11a923b416915d2ddf8b2de3a2e861f22898a4" dependencies = [ "anyhow", "async-trait", - "prost 0.12.1", + "prost 0.12.6", "rand 0.8.5", "thiserror", "tracing", @@ -9581,7 +10326,7 @@ dependencies = [ "hex", "lazy_static", "regex", - "semver", + "semver 1.0.23", "serde", "serde_json", "tempfile", @@ -9669,8 +10414,11 @@ dependencies = [ "anyhow", "async-trait", "base58", + "bincode", "blake2 0.10.6", "blake2b_simd", + "celestia-rpc", + "celestia-types", "flate2", "futures 0.3.30", "hex", @@ -9718,7 +10466,7 @@ dependencies = [ "chrono", "hex", "itertools 0.10.5", - "prost 0.12.1", + "prost 0.12.6", "rand 0.8.5", "serde", "serde_json", @@ -9864,7 +10612,7 @@ dependencies = [ "clap 4.4.6", "envy", "futures 0.3.30", - "rustc_version", + "rustc_version 0.4.0", "serde", "serde_json", "tempfile", @@ -10228,7 +10976,7 @@ dependencies = [ "async-trait", "rand 0.8.5", "secrecy", - "semver", + "semver 1.0.23", "tempfile", "test-casing", "thiserror", @@ -10315,7 +11063,7 @@ dependencies = [ "ctrlc", "futures 0.3.30", "pin-project-lite", - "semver", + "semver 1.0.23", "thiserror", "tokio", "tracing", @@ -10478,7 +11226,7 @@ dependencies = [ "google-cloud-auth", "google-cloud-storage", "http 1.1.0", - "prost 0.12.1", + "prost 0.12.6", "rand 0.8.5", "reqwest 0.12.5", "serde_json", @@ -10536,7 +11284,7 @@ dependencies = [ "anyhow", "bit-vec", "once_cell", - "prost 0.12.1", + "prost 0.12.6", "prost-reflect", "quick-protobuf", "rand 0.8.5", @@ -10571,7 +11319,7 @@ version = "0.1.0" dependencies = [ "anyhow", "hex", - "prost 0.12.1", + "prost 0.12.6", "rand 0.8.5", "secrecy", "serde_json", @@ -10669,7 +11417,7 @@ dependencies = [ name = "zksync_shared_metrics" version = "0.1.0" dependencies = [ - "rustc_version", + "rustc_version 0.4.0", "tracing", "vise", "zksync_dal", @@ -10895,7 +11643,7 @@ dependencies = [ "num", "num_enum 0.7.2", "once_cell", - "prost 0.12.1", + "prost 0.12.6", "rlp", "secp256k1", "serde", @@ -11028,7 +11776,7 @@ dependencies = [ "assert_matches", "async-trait", "backon", - "dashmap", + "dashmap 5.5.3", "futures 0.3.30", "once_cell", "rand 0.8.5", diff --git a/Cargo.toml b/Cargo.toml index 5a8a507b034..7f19107fabb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -208,6 +208,10 @@ subxt-metadata = "0.34.0" parity-scale-codec = { version = "3.6.9", default-features = false } subxt-signer = { version = "0.34", default-features = false } +# Celestia +celestia-rpc = "0.4.1" +celestia-types = "0.5.0" + # Here and below: # We *always* pin the latest version of protocol to disallow accidental changes in the execution logic. # However, for the historical version of protocol crates, we have lax requirements. Otherwise, diff --git a/core/bin/zksync_server/src/main.rs b/core/bin/zksync_server/src/main.rs index c518684b0e3..84898d6da06 100644 --- a/core/bin/zksync_server/src/main.rs +++ b/core/bin/zksync_server/src/main.rs @@ -11,7 +11,6 @@ use zksync_config::{ }, fri_prover_group::FriProverGroupConfig, house_keeper::HouseKeeperConfig, - secrets::DataAvailabilitySecrets, BasicWitnessInputProducerConfig, ContractsConfig, DatabaseSecrets, ExperimentalVmConfig, ExternalPriceApiClientConfig, FriProofCompressorConfig, FriProverConfig, FriProverGatewayConfig, FriWitnessGeneratorConfig, FriWitnessVectorGeneratorConfig, @@ -127,7 +126,6 @@ fn main() -> anyhow::Result<()> { consensus: config::read_consensus_secrets().context("read_consensus_secrets()")?, database: DatabaseSecrets::from_env().ok(), l1: L1Secrets::from_env().ok(), - data_availability: DataAvailabilitySecrets::from_env().ok(), }, }; diff --git a/core/bin/zksync_server/src/node_builder.rs b/core/bin/zksync_server/src/node_builder.rs index 4600b0f9e54..21840cc710d 100644 --- a/core/bin/zksync_server/src/node_builder.rs +++ b/core/bin/zksync_server/src/node_builder.rs @@ -4,8 +4,8 @@ use anyhow::Context; use zksync_config::{ configs::{ - da_client::DAClientConfig, eth_sender::PubdataSendingMode, - secrets::DataAvailabilitySecrets, wallets::Wallets, GeneralConfig, Secrets, + da_client::DAClientConfig, eth_sender::PubdataSendingMode, wallets::Wallets, GeneralConfig, + Secrets, }, ContractsConfig, GenesisConfig, }; @@ -28,7 +28,7 @@ use zksync_node_framework::{ consensus::MainNodeConsensusLayer, contract_verification_api::ContractVerificationApiLayer, da_clients::{ - avail::AvailWiringLayer, no_da::NoDAClientWiringLayer, + avail::AvailWiringLayer, celestia::CelestiaWiringLayer, no_da::NoDAClientWiringLayer, object_store::ObjectStorageClientWiringLayer, }, da_dispatcher::DataAvailabilityDispatcherLayer, @@ -509,14 +509,16 @@ impl MainNodeBuilder { return Ok(self); }; - let secrets = try_load_config!(self.secrets.data_availability); + match da_client_config { + DAClientConfig::Avail(config) => { + self.node.add_layer(AvailWiringLayer::new(config)); + } - match (da_client_config, secrets) { - (DAClientConfig::Avail(config), DataAvailabilitySecrets::Avail(secret)) => { - self.node.add_layer(AvailWiringLayer::new(config, secret)); + DAClientConfig::Celestia(config) => { + self.node.add_layer(CelestiaWiringLayer::new(config)); } - (DAClientConfig::ObjectStore(config), _) => { + DAClientConfig::ObjectStore(config) => { self.node .add_layer(ObjectStorageClientWiringLayer::new(config)); } diff --git a/core/lib/basic_types/src/lib.rs b/core/lib/basic_types/src/lib.rs index 8b6a7f949dd..9c7127c27ba 100644 --- a/core/lib/basic_types/src/lib.rs +++ b/core/lib/basic_types/src/lib.rs @@ -28,7 +28,7 @@ pub mod commitment; pub mod network; pub mod protocol_version; pub mod prover_dal; -pub mod seed_phrase; +pub mod secrets; pub mod settlement; pub mod tee_types; pub mod url; diff --git a/core/lib/basic_types/src/seed_phrase.rs b/core/lib/basic_types/src/secrets.rs similarity index 53% rename from core/lib/basic_types/src/seed_phrase.rs rename to core/lib/basic_types/src/secrets.rs index 332bfd58594..c6313ec2aa0 100644 --- a/core/lib/basic_types/src/seed_phrase.rs +++ b/core/lib/basic_types/src/secrets.rs @@ -18,3 +18,20 @@ impl FromStr for SeedPhrase { Ok(SeedPhrase(s.parse()?)) } } + +#[derive(Debug, Clone)] +pub struct PrivateKey(pub Secret); + +impl PartialEq for PrivateKey { + fn eq(&self, other: &Self) -> bool { + self.0.expose_secret().eq(other.0.expose_secret()) + } +} + +impl FromStr for PrivateKey { + type Err = anyhow::Error; + + fn from_str(s: &str) -> Result { + Ok(PrivateKey(s.parse()?)) + } +} diff --git a/core/lib/config/src/configs/da_client/avail.rs b/core/lib/config/src/configs/da_client/avail.rs index 590dc5fef18..a76e26ccd18 100644 --- a/core/lib/config/src/configs/da_client/avail.rs +++ b/core/lib/config/src/configs/da_client/avail.rs @@ -1,16 +1,18 @@ use serde::Deserialize; -use zksync_basic_types::seed_phrase::SeedPhrase; +use zksync_basic_types::secrets::SeedPhrase; -#[derive(Clone, Debug, PartialEq, Deserialize)] +#[derive(Clone, Debug, Default, PartialEq, Deserialize)] pub struct AvailConfig { pub api_node_url: String, pub bridge_api_url: String, pub app_id: u32, pub timeout: usize, pub max_retries: usize, + #[serde(skip)] + pub secrets: Option, } #[derive(Clone, Debug, PartialEq)] pub struct AvailSecrets { - pub seed_phrase: Option, + pub seed_phrase: SeedPhrase, } diff --git a/core/lib/config/src/configs/da_client/celestia.rs b/core/lib/config/src/configs/da_client/celestia.rs new file mode 100644 index 00000000000..22170166db3 --- /dev/null +++ b/core/lib/config/src/configs/da_client/celestia.rs @@ -0,0 +1,15 @@ +use serde::Deserialize; +use zksync_basic_types::secrets::PrivateKey; + +#[derive(Clone, Debug, Default, PartialEq, Deserialize)] +pub struct CelestiaConfig { + pub api_node_url: String, + pub namespace: String, + #[serde(skip)] + pub secrets: Option, +} + +#[derive(Clone, Debug, PartialEq)] +pub struct CelestiaSecrets { + pub private_key: PrivateKey, +} diff --git a/core/lib/config/src/configs/da_client/mod.rs b/core/lib/config/src/configs/da_client/mod.rs index 406305a77b1..4806d7ed099 100644 --- a/core/lib/config/src/configs/da_client/mod.rs +++ b/core/lib/config/src/configs/da_client/mod.rs @@ -1,12 +1,15 @@ -use crate::{AvailConfig, ObjectStoreConfig}; +use crate::{AvailConfig, CelestiaConfig, ObjectStoreConfig}; pub mod avail; +pub mod celestia; pub const AVAIL_CLIENT_CONFIG_NAME: &str = "Avail"; +pub const CELESTIA_CLIENT_CONFIG_NAME: &str = "Celestia"; pub const OBJECT_STORE_CLIENT_CONFIG_NAME: &str = "ObjectStore"; #[derive(Debug, Clone, PartialEq)] pub enum DAClientConfig { Avail(AvailConfig), + Celestia(CelestiaConfig), ObjectStore(ObjectStoreConfig), } diff --git a/core/lib/config/src/configs/mod.rs b/core/lib/config/src/configs/mod.rs index 1ad503e0687..75f4b87df7d 100644 --- a/core/lib/config/src/configs/mod.rs +++ b/core/lib/config/src/configs/mod.rs @@ -5,7 +5,7 @@ pub use self::{ commitment_generator::CommitmentGeneratorConfig, contract_verifier::ContractVerifierConfig, contracts::{ContractsConfig, EcosystemContracts}, - da_client::{avail::AvailConfig, DAClientConfig}, + da_client::{avail::AvailConfig, celestia::CelestiaConfig, DAClientConfig}, da_dispatcher::DADispatcherConfig, database::{DBConfig, PostgresConfig}, eth_sender::{EthConfig, GasAdjusterConfig}, diff --git a/core/lib/config/src/configs/secrets.rs b/core/lib/config/src/configs/secrets.rs index 779bad37065..71197f5d930 100644 --- a/core/lib/config/src/configs/secrets.rs +++ b/core/lib/config/src/configs/secrets.rs @@ -1,7 +1,7 @@ use anyhow::Context; use zksync_basic_types::url::SensitiveUrl; -use crate::configs::{consensus::ConsensusSecrets, da_client::avail::AvailSecrets}; +use crate::configs::consensus::ConsensusSecrets; #[derive(Debug, Clone, PartialEq)] pub struct DatabaseSecrets { @@ -15,17 +15,11 @@ pub struct L1Secrets { pub l1_rpc_url: SensitiveUrl, } -#[derive(Debug, Clone, PartialEq)] -pub enum DataAvailabilitySecrets { - Avail(AvailSecrets), -} - #[derive(Debug, Clone, PartialEq)] pub struct Secrets { pub consensus: Option, pub database: Option, pub l1: Option, - pub data_availability: Option, } impl DatabaseSecrets { diff --git a/core/lib/config/src/lib.rs b/core/lib/config/src/lib.rs index 9191edc3982..c02f3e531b3 100644 --- a/core/lib/config/src/lib.rs +++ b/core/lib/config/src/lib.rs @@ -1,8 +1,8 @@ #![allow(clippy::upper_case_acronyms, clippy::derive_partial_eq_without_eq)] pub use crate::configs::{ - ApiConfig, AvailConfig, BaseTokenAdjusterConfig, ContractVerifierConfig, ContractsConfig, - DAClientConfig, DADispatcherConfig, DBConfig, EthConfig, EthWatchConfig, + ApiConfig, AvailConfig, BaseTokenAdjusterConfig, CelestiaConfig, ContractVerifierConfig, + ContractsConfig, DAClientConfig, DADispatcherConfig, DBConfig, EthConfig, EthWatchConfig, ExternalProofIntegrationApiConfig, GasAdjusterConfig, GenesisConfig, ObjectStoreConfig, PostgresConfig, SnapshotsCreatorConfig, }; diff --git a/core/lib/config/src/testonly.rs b/core/lib/config/src/testonly.rs index dbcccfe52ca..9c953045afc 100644 --- a/core/lib/config/src/testonly.rs +++ b/core/lib/config/src/testonly.rs @@ -7,7 +7,7 @@ use zksync_basic_types::{ commitment::L1BatchCommitmentMode, network::Network, protocol_version::{ProtocolSemanticVersion, ProtocolVersionId, VersionPatch}, - seed_phrase::SeedPhrase, + secrets::SeedPhrase, vm::FastVmMode, L1BatchNumber, L1ChainId, L2ChainId, }; @@ -865,7 +865,6 @@ impl Distribution for EncodeDist { consensus: self.sample_opt(|| self.sample(rng)), database: self.sample_opt(|| self.sample(rng)), l1: self.sample_opt(|| self.sample(rng)), - data_availability: self.sample_opt(|| self.sample(rng)), } } } @@ -943,14 +942,10 @@ impl Distribution for EncodeDist { app_id: self.sample(rng), timeout: self.sample(rng), max_retries: self.sample(rng), - }) - } -} -impl Distribution for EncodeDist { - fn sample(&self, rng: &mut R) -> configs::secrets::DataAvailabilitySecrets { - configs::secrets::DataAvailabilitySecrets::Avail(configs::da_client::avail::AvailSecrets { - seed_phrase: Some(SeedPhrase(Secret::new(self.sample(rng)))), + secrets: Some(configs::da_client::avail::AvailSecrets { + seed_phrase: SeedPhrase(Secret::new(self.sample(rng))), + }), }) } } diff --git a/core/lib/env_config/src/da_client.rs b/core/lib/env_config/src/da_client.rs index 0fc3ad216f8..171cfa181bb 100644 --- a/core/lib/env_config/src/da_client.rs +++ b/core/lib/env_config/src/da_client.rs @@ -1,20 +1,39 @@ use std::env; -use zksync_config::configs::{ - da_client::{ - avail::AvailSecrets, DAClientConfig, AVAIL_CLIENT_CONFIG_NAME, - OBJECT_STORE_CLIENT_CONFIG_NAME, +use zksync_config::{ + configs::da_client::{ + avail::AvailSecrets, celestia::CelestiaSecrets, DAClientConfig, AVAIL_CLIENT_CONFIG_NAME, + CELESTIA_CLIENT_CONFIG_NAME, OBJECT_STORE_CLIENT_CONFIG_NAME, }, - secrets::DataAvailabilitySecrets, + AvailConfig, CelestiaConfig, }; use crate::{envy_load, FromEnv}; impl FromEnv for DAClientConfig { fn from_env() -> anyhow::Result { - let client_tag = std::env::var("DA_CLIENT")?; + let client_tag = env::var("DA_CLIENT")?; let config = match client_tag.as_str() { - AVAIL_CLIENT_CONFIG_NAME => Self::Avail(envy_load("da_avail_config", "DA_")?), + AVAIL_CLIENT_CONFIG_NAME => { + let mut avail: AvailConfig = envy_load("da_avail_config", "DA_")?; + if let Ok(seed) = env::var("DA_SECRETS_SEED_PHRASE") { + avail.secrets = Some(AvailSecrets { + seed_phrase: seed.parse()?, + }); + } + + Self::Avail(avail) + } + CELESTIA_CLIENT_CONFIG_NAME => { + let mut celestia: CelestiaConfig = envy_load("da_celestia_config", "DA_")?; + if let Ok(pk) = env::var("DA_SECRETS_PRIVATE_KEY") { + celestia.secrets = Some(CelestiaSecrets { + private_key: pk.parse()?, + }); + } + + Self::Celestia(celestia) + } OBJECT_STORE_CLIENT_CONFIG_NAME => { Self::ObjectStore(envy_load("da_object_store", "DA_")?) } @@ -25,32 +44,14 @@ impl FromEnv for DAClientConfig { } } -impl FromEnv for DataAvailabilitySecrets { - fn from_env() -> anyhow::Result { - let client_tag = std::env::var("DA_CLIENT")?; - let secrets = match client_tag.as_str() { - AVAIL_CLIENT_CONFIG_NAME => { - let seed_phrase = env::var("DA_SECRETS_SEED_PHRASE") - .ok() - .map(|s| s.parse()) - .transpose()?; - Self::Avail(AvailSecrets { seed_phrase }) - } - _ => anyhow::bail!("Unknown DA client name: {}", client_tag), - }; - - Ok(secrets) - } -} - #[cfg(test)] mod tests { use zksync_config::{ configs::{ - da_client::{DAClientConfig, DAClientConfig::ObjectStore}, + da_client::{celestia::CelestiaSecrets, DAClientConfig, DAClientConfig::ObjectStore}, object_store::ObjectStoreMode::GCS, }, - AvailConfig, ObjectStoreConfig, + AvailConfig, CelestiaConfig, ObjectStoreConfig, }; use super::*; @@ -92,6 +93,7 @@ mod tests { app_id: u32, timeout: usize, max_retries: usize, + seed: &str, ) -> DAClientConfig { DAClientConfig::Avail(AvailConfig { api_node_url: api_node_url.to_string(), @@ -99,6 +101,10 @@ mod tests { app_id, timeout, max_retries, + + secrets: Some(AvailSecrets { + seed_phrase: seed.parse().unwrap(), + }), }) } @@ -112,6 +118,8 @@ mod tests { DA_APP_ID="1" DA_TIMEOUT="2" DA_MAX_RETRIES="3" + + DA_SECRETS_SEED_PHRASE="bottom drive obey lake curtain smoke basket hold race lonely fit walk" "#; lock.set_env(config); @@ -125,29 +133,46 @@ mod tests { "1".parse::().unwrap(), "2".parse::().unwrap(), "3".parse::().unwrap(), + "bottom drive obey lake curtain smoke basket hold race lonely fit walk" ) ); } + fn expected_celestia_da_layer_config( + pk: &str, + api_node_url: &str, + namespace: &str, + ) -> DAClientConfig { + DAClientConfig::Celestia(CelestiaConfig { + api_node_url: api_node_url.to_string(), + namespace: namespace.to_string(), + + secrets: Some(CelestiaSecrets { + private_key: pk.parse().unwrap(), + }), + }) + } + #[test] - fn from_env_avail_secrets() { + fn from_env_celestia_client() { let mut lock = MUTEX.lock(); let config = r#" - DA_CLIENT="Avail" - DA_SECRETS_SEED_PHRASE="bottom drive obey lake curtain smoke basket hold race lonely fit walk" - "#; + DA_CLIENT="Celestia" + DA_API_NODE_URL="localhost:12345" + DA_NAMESPACE="0x1234567890abcdef" + DA_SECRETS_PRIVATE_KEY="0xf55baf7c0e4e33b1d78fbf52f069c426bc36cff1aceb9bc8f45d14c07f034d73" + "#; lock.set_env(config); - let actual = match DataAvailabilitySecrets::from_env().unwrap() { - DataAvailabilitySecrets::Avail(avail) => avail.seed_phrase, - }; - + let actual = DAClientConfig::from_env().unwrap(); assert_eq!( - actual.unwrap(), - "bottom drive obey lake curtain smoke basket hold race lonely fit walk" - .parse() - .unwrap() + actual, + expected_celestia_da_layer_config( + "0xf55baf7c0e4e33b1d78fbf52f069c426bc36cff1aceb9bc8f45d14c07f034d73", + "localhost:12345", + "0x1234567890abcdef" + ) ); } } diff --git a/core/lib/protobuf_config/src/da_client.rs b/core/lib/protobuf_config/src/da_client.rs index 1499e88efb4..736fd41d9b0 100644 --- a/core/lib/protobuf_config/src/da_client.rs +++ b/core/lib/protobuf_config/src/da_client.rs @@ -1,14 +1,17 @@ use anyhow::Context; use zksync_config::{ configs::{ - da_client::DAClientConfig::{Avail, ObjectStore}, + da_client::DAClientConfig::{Avail, Celestia, ObjectStore}, {self}, }, - AvailConfig, + AvailConfig, CelestiaConfig, }; use zksync_protobuf::{required, ProtoRepr}; -use crate::proto::{da_client as proto, object_store as object_store_proto}; +use crate::{ + proto::{da_client as proto, object_store as object_store_proto}, + read_optional_repr, +}; impl ProtoRepr for proto::DataAvailabilityClient { type Type = configs::DAClientConfig; @@ -27,6 +30,13 @@ impl ProtoRepr for proto::DataAvailabilityClient { app_id: *required(&conf.app_id).context("app_id")?, timeout: *required(&conf.timeout).context("timeout")? as usize, max_retries: *required(&conf.max_retries).context("max_retries")? as usize, + + secrets: read_optional_repr(&conf.secrets), + }), + proto::data_availability_client::Config::Celestia(conf) => Celestia(CelestiaConfig { + api_node_url: required(&conf.api_node_url).context("namespace")?.clone(), + namespace: required(&conf.namespace).context("namespace")?.clone(), + secrets: read_optional_repr(&conf.secrets), }), proto::data_availability_client::Config::ObjectStore(conf) => { ObjectStore(object_store_proto::ObjectStore::read(conf)?) @@ -37,23 +47,36 @@ impl ProtoRepr for proto::DataAvailabilityClient { } fn build(this: &Self::Type) -> Self { - match &this { - Avail(config) => Self { - config: Some(proto::data_availability_client::Config::Avail( - proto::AvailConfig { - api_node_url: Some(config.api_node_url.clone()), - bridge_api_url: Some(config.bridge_api_url.clone()), - app_id: Some(config.app_id), - timeout: Some(config.timeout as u64), - max_retries: Some(config.max_retries as u64), - }, - )), - }, - ObjectStore(config) => Self { - config: Some(proto::data_availability_client::Config::ObjectStore( - object_store_proto::ObjectStore::build(config), - )), - }, + let config = match &this { + Avail(config) => proto::data_availability_client::Config::Avail(proto::AvailConfig { + api_node_url: Some(config.api_node_url.clone()), + bridge_api_url: Some(config.bridge_api_url.clone()), + app_id: Some(config.app_id), + timeout: Some(config.timeout as u64), + max_retries: Some(config.max_retries as u64), + secrets: config + .secrets + .as_ref() + .map(|s| proto::AvailSecrets::build(s)), + }), + + Celestia(config) => { + proto::data_availability_client::Config::Celestia(proto::CelestiaConfig { + api_node_url: Some(config.api_node_url.clone()), + namespace: Some(config.namespace.clone()), + secrets: config + .secrets + .as_ref() + .map(|s| proto::CelestiaSecrets::build(s)), + }) + } + ObjectStore(config) => proto::data_availability_client::Config::ObjectStore( + object_store_proto::ObjectStore::build(config), + ), + }; + + Self { + config: Some(config), } } } diff --git a/core/lib/protobuf_config/src/da_secrets.rs b/core/lib/protobuf_config/src/da_secrets.rs new file mode 100644 index 00000000000..dec66fcee5d --- /dev/null +++ b/core/lib/protobuf_config/src/da_secrets.rs @@ -0,0 +1,37 @@ +use secrecy::ExposeSecret; +use zksync_config::configs; +use zksync_protobuf::{required, ProtoRepr}; + +use crate::proto::da_client as proto; + +impl ProtoRepr for proto::AvailSecrets { + type Type = configs::da_client::avail::AvailSecrets; + + fn read(&self) -> anyhow::Result { + Ok(configs::da_client::avail::AvailSecrets { + seed_phrase: required(&self.seed_phrase).expect("seed_phrase").parse()?, + }) + } + + fn build(this: &Self::Type) -> Self { + Self { + seed_phrase: Some(this.seed_phrase.0.expose_secret().to_string()), + } + } +} + +impl ProtoRepr for proto::CelestiaSecrets { + type Type = configs::da_client::celestia::CelestiaSecrets; + + fn read(&self) -> anyhow::Result { + Ok(configs::da_client::celestia::CelestiaSecrets { + private_key: required(&self.private_key).expect("private_key").parse()?, + }) + } + + fn build(this: &Self::Type) -> Self { + Self { + private_key: Some(this.private_key.0.expose_secret().to_string()), + } + } +} diff --git a/core/lib/protobuf_config/src/lib.rs b/core/lib/protobuf_config/src/lib.rs index a4822edbe8e..ef536dbc969 100644 --- a/core/lib/protobuf_config/src/lib.rs +++ b/core/lib/protobuf_config/src/lib.rs @@ -30,6 +30,7 @@ mod secrets; mod snapshots_creator; mod da_client; +mod da_secrets; mod external_price_api_client; mod external_proof_integration_api; mod prover_job_monitor; diff --git a/core/lib/protobuf_config/src/proto/config/da_client.proto b/core/lib/protobuf_config/src/proto/config/da_client.proto index d01bda2c847..8ba18c51e9a 100644 --- a/core/lib/protobuf_config/src/proto/config/da_client.proto +++ b/core/lib/protobuf_config/src/proto/config/da_client.proto @@ -4,19 +4,37 @@ package zksync.config.da_client; import "zksync/config/object_store.proto"; +message AvailSecrets { + optional string seed_phrase = 1; +} + message AvailConfig { optional string api_node_url = 1; optional string bridge_api_url = 2; optional uint32 app_id = 4; optional uint64 timeout = 5; optional uint64 max_retries = 6; + + optional AvailSecrets secrets = 7; reserved 3; reserved "seed"; } +message CelestiaSecrets { + optional string private_key = 1; +} + +message CelestiaConfig { + optional string api_node_url = 1; + optional string namespace = 2; + + optional CelestiaSecrets secrets = 3; +} + message DataAvailabilityClient { // oneof in protobuf allows for None oneof config { AvailConfig avail = 1; object_store.ObjectStore object_store = 2; + CelestiaConfig celestia = 3; } } diff --git a/core/lib/protobuf_config/src/proto/config/secrets.proto b/core/lib/protobuf_config/src/proto/config/secrets.proto index 17b915b3f08..e6e0e9a346a 100644 --- a/core/lib/protobuf_config/src/proto/config/secrets.proto +++ b/core/lib/protobuf_config/src/proto/config/secrets.proto @@ -19,19 +19,8 @@ message ConsensusSecrets { optional string attester_key = 3; // required for attester nodes; AttesterSecretKey } -message AvailSecret { - optional string seed_phrase = 1; -} - -message DataAvailabilitySecrets { - oneof da_secrets { - AvailSecret avail = 1; - } -} - message Secrets { optional DatabaseSecrets database = 1; // optional secrets for database optional L1Secrets l1 = 2; // optional secrets for l1 communication optional ConsensusSecrets consensus = 3; // optional secrets for consensus - optional DataAvailabilitySecrets da = 4; // optional secrets for data availability } diff --git a/core/lib/protobuf_config/src/secrets.rs b/core/lib/protobuf_config/src/secrets.rs index 58735148007..7d10bef88a5 100644 --- a/core/lib/protobuf_config/src/secrets.rs +++ b/core/lib/protobuf_config/src/secrets.rs @@ -2,22 +2,15 @@ use std::str::FromStr; use anyhow::Context; use secrecy::ExposeSecret; -use zksync_basic_types::{seed_phrase::SeedPhrase, url::SensitiveUrl}; +use zksync_basic_types::url::SensitiveUrl; use zksync_config::configs::{ consensus::{AttesterSecretKey, ConsensusSecrets, NodeSecretKey, ValidatorSecretKey}, - da_client::avail::AvailSecrets, - secrets::{DataAvailabilitySecrets, Secrets}, + secrets::Secrets, DatabaseSecrets, L1Secrets, }; use zksync_protobuf::{required, ProtoRepr}; -use crate::{ - proto::{ - secrets as proto, - secrets::{data_availability_secrets::DaSecrets, AvailSecret}, - }, - read_optional_repr, -}; +use crate::{proto::secrets as proto, read_optional_repr}; impl ProtoRepr for proto::Secrets { type Type = Secrets; @@ -27,7 +20,6 @@ impl ProtoRepr for proto::Secrets { consensus: read_optional_repr(&self.consensus), database: read_optional_repr(&self.database), l1: read_optional_repr(&self.l1), - data_availability: read_optional_repr(&self.da), }) } @@ -36,7 +28,6 @@ impl ProtoRepr for proto::Secrets { database: this.database.as_ref().map(ProtoRepr::build), l1: this.l1.as_ref().map(ProtoRepr::build), consensus: this.consensus.as_ref().map(ProtoRepr::build), - da: this.data_availability.as_ref().map(ProtoRepr::build), } } } @@ -96,53 +87,6 @@ impl ProtoRepr for proto::L1Secrets { } } -impl ProtoRepr for proto::DataAvailabilitySecrets { - type Type = DataAvailabilitySecrets; - - fn read(&self) -> anyhow::Result { - let secrets = required(&self.da_secrets).context("config")?; - - let client = match secrets { - DaSecrets::Avail(avail_secret) => DataAvailabilitySecrets::Avail(AvailSecrets { - seed_phrase: Some( - SeedPhrase::from_str( - required(&avail_secret.seed_phrase).context("seed_phrase")?, - ) - .unwrap(), - ), - }), - }; - - Ok(client) - } - - fn build(this: &Self::Type) -> Self { - let secrets = match &this { - DataAvailabilitySecrets::Avail(config) => { - let seed_phrase = if config.seed_phrase.is_some() { - Some( - config - .clone() - .seed_phrase - .unwrap() - .0 - .expose_secret() - .to_string(), - ) - } else { - None - }; - - Some(DaSecrets::Avail(AvailSecret { seed_phrase })) - } - }; - - Self { - da_secrets: secrets, - } - } -} - impl ProtoRepr for proto::ConsensusSecrets { type Type = ConsensusSecrets; fn read(&self) -> anyhow::Result { diff --git a/core/node/da_clients/Cargo.toml b/core/node/da_clients/Cargo.toml index 60b65067f48..15d4cca3e98 100644 --- a/core/node/da_clients/Cargo.toml +++ b/core/node/da_clients/Cargo.toml @@ -33,7 +33,11 @@ base58.workspace = true serde_json.workspace = true hex.workspace = true blake2b_simd.workspace = true - -jsonrpsee = { workspace = true, features = ["ws-client"] } parity-scale-codec = { workspace = true, features = ["derive"] } subxt-signer = { workspace = true, features = ["sr25519", "native"] } +jsonrpsee = { workspace = true, features = ["ws-client"] } + +# Celestia dependencies +celestia-rpc.workspace = true +celestia-types.workspace = true +bincode.workspace = true diff --git a/core/node/da_clients/src/avail/client.rs b/core/node/da_clients/src/avail/client.rs index 7718691bf18..9e6883c732e 100644 --- a/core/node/da_clients/src/avail/client.rs +++ b/core/node/da_clients/src/avail/client.rs @@ -3,13 +3,13 @@ use std::{fmt::Debug, sync::Arc}; use async_trait::async_trait; use jsonrpsee::ws_client::WsClientBuilder; use subxt_signer::ExposeSecret; -use zksync_config::configs::da_client::avail::{AvailConfig, AvailSecrets}; +use zksync_config::configs::da_client::avail::AvailConfig; use zksync_da_client::{ types::{DAError, DispatchResponse, InclusionData}, DataAvailabilityClient, }; -use crate::avail::sdk::RawAvailClient; +use crate::{avail::sdk::RawAvailClient, utils::to_non_retriable_da_error}; /// An implementation of the `DataAvailabilityClient` trait that interacts with the Avail network. #[derive(Debug, Clone)] @@ -19,14 +19,16 @@ pub struct AvailClient { } impl AvailClient { - pub async fn new(config: AvailConfig, secrets: AvailSecrets) -> anyhow::Result { - let seed_phrase = secrets - .seed_phrase - .ok_or_else(|| anyhow::anyhow!("seed phrase"))?; - let sdk_client = RawAvailClient::new(config.app_id, seed_phrase.0.expose_secret()).await?; + pub async fn new(config: AvailConfig) -> anyhow::Result { + let Some(secrets) = config.clone().secrets else { + return Err(anyhow::anyhow!("Avail secrets are empty")); + }; + + let sdk_client = + RawAvailClient::new(config.app_id, secrets.seed_phrase.0.expose_secret()).await?; Ok(Self { - config, + config: config.clone(), sdk_client: Arc::new(sdk_client), }) } @@ -80,10 +82,3 @@ impl DataAvailabilityClient for AvailClient { Some(RawAvailClient::MAX_BLOB_SIZE) } } - -pub fn to_non_retriable_da_error(error: impl Into) -> DAError { - DAError { - error: error.into(), - is_retriable: false, - } -} diff --git a/core/node/da_clients/src/avail/sdk.rs b/core/node/da_clients/src/avail/sdk.rs index 750e45e0452..09f434a51e3 100644 --- a/core/node/da_clients/src/avail/sdk.rs +++ b/core/node/da_clients/src/avail/sdk.rs @@ -14,7 +14,7 @@ use subxt_signer::{ sr25519::{Keypair, Signature}, }; -use crate::avail::client::to_non_retriable_da_error; +use crate::utils::to_non_retriable_da_error; const PROTOCOL_VERSION: u8 = 4; diff --git a/core/node/da_clients/src/celestia/client.rs b/core/node/da_clients/src/celestia/client.rs new file mode 100644 index 00000000000..0ad7ab2ee46 --- /dev/null +++ b/core/node/da_clients/src/celestia/client.rs @@ -0,0 +1,97 @@ +use std::{ + fmt::{Debug, Formatter}, + sync::Arc, +}; + +use async_trait::async_trait; +use celestia_rpc::{BlobClient, Client}; +use celestia_types::{blob::Commitment, nmt::Namespace, Blob, TxConfig}; +use serde::{Deserialize, Serialize}; +use subxt_signer::ExposeSecret; +use zksync_config::configs::da_client::celestia::CelestiaConfig; +use zksync_da_client::{ + types::{DAError, DispatchResponse, InclusionData}, + DataAvailabilityClient, +}; + +use crate::utils::to_non_retriable_da_error; + +/// An implementation of the `DataAvailabilityClient` trait that interacts with the Avail network. +#[derive(Clone)] +pub struct CelestiaClient { + config: CelestiaConfig, + client: Arc, +} + +impl CelestiaClient { + pub async fn new(config: CelestiaConfig) -> anyhow::Result { + let Some(secrets) = config.clone().secrets else { + return Err(anyhow::anyhow!("Celestia secrets are empty")); + }; + + let client = Client::new( + &config.api_node_url, + Some(secrets.private_key.0.expose_secret()), + ) + .await + .expect("could not create client"); + + Ok(Self { + config: config.clone(), + client: Arc::new(client), + }) + } +} +#[derive(Serialize, Deserialize)] +pub struct BlobId { + pub commitment: Commitment, + pub height: u64, +} + +#[async_trait] +impl DataAvailabilityClient for CelestiaClient { + async fn dispatch_blob( + &self, + _: u32, // batch number + data: Vec, + ) -> Result { + let namespace = Namespace::new_v0(self.config.namespace.as_bytes()) + .map_err(to_non_retriable_da_error)?; + let blob = Blob::new(namespace, data).map_err(to_non_retriable_da_error)?; + + let commitment = blob.commitment.clone(); + let height = self + .client + .blob_submit(&[blob], TxConfig::default()) + .await + .map_err(to_non_retriable_da_error)?; + + let blob_id = BlobId { commitment, height }; + let blob_bytes = bincode::serialize(&blob_id).map_err(to_non_retriable_da_error)?; + + Ok(DispatchResponse { + blob_id: hex::encode(&blob_bytes), + }) + } + + async fn get_inclusion_data(&self, _: &str) -> Result, DAError> { + Ok(Some(InclusionData { data: vec![] })) + } + + fn clone_boxed(&self) -> Box { + Box::new(self.clone()) + } + + fn blob_size_limit(&self) -> Option { + Some(1973786) // almost 2MB + } +} + +impl Debug for CelestiaClient { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.debug_struct("CelestiaClient") + .field("config.api_node_url", &self.config.api_node_url) + .field("config.namespace", &self.config.namespace) + .finish() + } +} diff --git a/core/node/da_clients/src/celestia/mod.rs b/core/node/da_clients/src/celestia/mod.rs new file mode 100644 index 00000000000..862e6e4c390 --- /dev/null +++ b/core/node/da_clients/src/celestia/mod.rs @@ -0,0 +1,3 @@ +mod client; + +pub use self::client::CelestiaClient; diff --git a/core/node/da_clients/src/lib.rs b/core/node/da_clients/src/lib.rs index 48311ce4c3f..8515c128ff3 100644 --- a/core/node/da_clients/src/lib.rs +++ b/core/node/da_clients/src/lib.rs @@ -1,3 +1,5 @@ pub mod avail; +pub mod celestia; pub mod no_da; pub mod object_store; +mod utils; diff --git a/core/node/da_clients/src/utils.rs b/core/node/da_clients/src/utils.rs new file mode 100644 index 00000000000..69ee5ca6b67 --- /dev/null +++ b/core/node/da_clients/src/utils.rs @@ -0,0 +1,8 @@ +use zksync_da_client::types::DAError; + +pub fn to_non_retriable_da_error(error: impl Into) -> DAError { + DAError { + error: error.into(), + is_retriable: false, + } +} diff --git a/core/node/node_framework/src/implementations/layers/da_clients/avail.rs b/core/node/node_framework/src/implementations/layers/da_clients/avail.rs index 06f5dbb72eb..7c3d82b6d25 100644 --- a/core/node/node_framework/src/implementations/layers/da_clients/avail.rs +++ b/core/node/node_framework/src/implementations/layers/da_clients/avail.rs @@ -1,4 +1,4 @@ -use zksync_config::{configs::da_client::avail::AvailSecrets, AvailConfig}; +use zksync_config::AvailConfig; use zksync_da_client::DataAvailabilityClient; use zksync_da_clients::avail::AvailClient; @@ -11,12 +11,11 @@ use crate::{ #[derive(Debug)] pub struct AvailWiringLayer { config: AvailConfig, - secrets: AvailSecrets, } impl AvailWiringLayer { - pub fn new(config: AvailConfig, secrets: AvailSecrets) -> Self { - Self { config, secrets } + pub fn new(config: AvailConfig) -> Self { + Self { config } } } @@ -37,7 +36,7 @@ impl WiringLayer for AvailWiringLayer { async fn wire(self, _input: Self::Input) -> Result { let client: Box = - Box::new(AvailClient::new(self.config, self.secrets).await?); + Box::new(AvailClient::new(self.config).await?); Ok(Self::Output { client: DAClientResource(client), diff --git a/core/node/node_framework/src/implementations/layers/da_clients/celestia.rs b/core/node/node_framework/src/implementations/layers/da_clients/celestia.rs new file mode 100644 index 00000000000..741b2386803 --- /dev/null +++ b/core/node/node_framework/src/implementations/layers/da_clients/celestia.rs @@ -0,0 +1,45 @@ +use zksync_config::CelestiaConfig; +use zksync_da_client::DataAvailabilityClient; +use zksync_da_clients::celestia::CelestiaClient; + +use crate::{ + implementations::resources::da_client::DAClientResource, + wiring_layer::{WiringError, WiringLayer}, + IntoContext, +}; + +#[derive(Debug)] +pub struct CelestiaWiringLayer { + config: CelestiaConfig, +} + +impl CelestiaWiringLayer { + pub fn new(config: CelestiaConfig) -> Self { + Self { config } + } +} + +#[derive(Debug, IntoContext)] +#[context(crate = crate)] +pub struct Output { + pub client: DAClientResource, +} + +#[async_trait::async_trait] +impl WiringLayer for CelestiaWiringLayer { + type Input = (); + type Output = Output; + + fn layer_name(&self) -> &'static str { + "celestia_client_layer" + } + + async fn wire(self, _input: Self::Input) -> Result { + let client: Box = + Box::new(CelestiaClient::new(self.config).await?); + + Ok(Self::Output { + client: DAClientResource(client), + }) + } +} diff --git a/core/node/node_framework/src/implementations/layers/da_clients/mod.rs b/core/node/node_framework/src/implementations/layers/da_clients/mod.rs index 48311ce4c3f..6bb6ce4fb87 100644 --- a/core/node/node_framework/src/implementations/layers/da_clients/mod.rs +++ b/core/node/node_framework/src/implementations/layers/da_clients/mod.rs @@ -1,3 +1,4 @@ pub mod avail; +pub mod celestia; pub mod no_da; pub mod object_store; diff --git a/zk_toolbox/crates/zk_inception/src/commands/external_node/prepare_configs.rs b/zk_toolbox/crates/zk_inception/src/commands/external_node/prepare_configs.rs index 38523db4dac..89e08418c6e 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/external_node/prepare_configs.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/external_node/prepare_configs.rs @@ -121,7 +121,6 @@ fn prepare_configs( l1: Some(L1Secrets { l1_rpc_url: SensitiveUrl::from_str(&args.l1_rpc_url).context("l1_rpc_url")?, }), - data_availability: None, }; secrets.save_with_base_path(shell, en_configs_path)?; let dirs = recreate_rocksdb_dirs(shell, &config.rocks_db_path, RocksDBDirOption::ExternalNode)?;