diff --git a/Cargo.lock b/Cargo.lock index 2d70922a6..7de813f34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -94,6 +94,30 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +[[package]] +name = "alloy" +version = "0.5.4" +source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" +dependencies = [ + "alloy-consensus", + "alloy-contract", + "alloy-core", + "alloy-eips", + "alloy-genesis", + "alloy-network", + "alloy-provider", + "alloy-pubsub", + "alloy-rpc-client", + "alloy-rpc-types", + "alloy-serde", + "alloy-signer", + "alloy-signer-local", + "alloy-transport", + "alloy-transport-http", + "alloy-transport-ipc", + "alloy-transport-ws", +] + [[package]] name = "alloy-chains" version = "0.1.46" @@ -141,6 +165,19 @@ dependencies = [ "thiserror", ] +[[package]] +name = "alloy-core" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eeb750349efda145ca6aada68d0336067f7f364d7d44ef09e2cf000b040c5e99" +dependencies = [ + "alloy-dyn-abi", + "alloy-json-abi", + "alloy-primitives", + "alloy-rlp", + "alloy-sol-types", +] + [[package]] name = "alloy-dyn-abi" version = "0.8.11" @@ -448,7 +485,7 @@ dependencies = [ "alloy-rlp", "alloy-serde", "derive_more 1.0.0", - "jsonwebtoken 9.3.0", + "jsonwebtoken", "rand 0.8.5", "serde", "strum", @@ -584,8 +621,8 @@ dependencies = [ "alloy-primitives", "alloy-signer", "async-trait", - "coins-bip32 0.12.0", - "coins-bip39 0.12.0", + "coins-bip32", + "coins-bip39", "eth-keystore", "k256 0.13.4", "rand 0.8.5", @@ -703,7 +740,7 @@ dependencies = [ [[package]] name = "alloy-transport-http" version = "0.5.4" -source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#31bccc864525b5ba64fefb8211363807c7a43d2d" +source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ "alloy-json-rpc", "alloy-transport", @@ -717,7 +754,7 @@ dependencies = [ [[package]] name = "alloy-transport-ipc" version = "0.5.4" -source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#31bccc864525b5ba64fefb8211363807c7a43d2d" +source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ "alloy-json-rpc", "alloy-pubsub", @@ -737,7 +774,7 @@ dependencies = [ [[package]] name = "alloy-transport-ws" version = "0.5.4" -source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#31bccc864525b5ba64fefb8211363807c7a43d2d" +source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ "alloy-pubsub", "alloy-transport", @@ -746,7 +783,7 @@ dependencies = [ "rustls 0.23.16", "serde_json", "tokio", - "tokio-tungstenite 0.24.0", + "tokio-tungstenite", "tracing", "ws_stream_wasm", ] @@ -766,6 +803,25 @@ dependencies = [ "tracing", ] +[[package]] +name = "alloy-zksync" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65f279833c27d8116f15d9a294c0529a716b3303ae1296063c71729a74c2e8b5" +dependencies = [ + "alloy", + "async-trait", + "chrono", + "futures-utils-wasm", + "k256 0.13.4", + "rand 0.8.5", + "reqwest 0.12.9", + "serde", + "thiserror", + "tracing", + "url", +] + [[package]] name = "ammonia" version = "4.0.0" @@ -919,7 +975,7 @@ dependencies = [ "tracing", "tracing-subscriber", "vergen", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -996,7 +1052,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44055e597c674aef7cb903b2b9f6e4cba1277ed0d2d61dae7cd52d7ffa81f8e2" dependencies = [ "unicode-width 0.1.14", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -1336,7 +1392,7 @@ dependencies = [ "fastrand", "hex", "http 0.2.12", - "ring 0.17.8", + "ring", "time", "tokio", "tracing", @@ -1690,7 +1746,7 @@ dependencies = [ "sha1", "sync_wrapper 1.0.1", "tokio", - "tokio-tungstenite 0.24.0", + "tokio-tungstenite", "tower 0.5.1", "tower-layer", "tower-service", @@ -2320,6 +2376,7 @@ dependencies = [ "alloy-signer-local", "alloy-sol-types", "alloy-transport", + "alloy-zksync", "anvil", "async-trait", "aws-sdk-kms", @@ -2356,8 +2413,8 @@ dependencies = [ "tokio", "tracing", "vergen", - "yansi 1.0.1", - "zksync-web3-rs", + "yansi", + "zksync_types", ] [[package]] @@ -2453,7 +2510,7 @@ dependencies = [ "tracing", "tracing-subscriber", "vergen", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -2742,22 +2799,6 @@ dependencies = [ "cc", ] -[[package]] -name = "coins-bip32" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b6be4a5df2098cd811f3194f64ddb96c267606bffd9689ac7b0160097b01ad3" -dependencies = [ - "bs58", - "coins-core 0.8.7", - "digest 0.10.7", - "hmac", - "k256 0.13.4", - "serde", - "sha2 0.10.8", - "thiserror", -] - [[package]] name = "coins-bip32" version = "0.12.0" @@ -2765,7 +2806,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2073678591747aed4000dd468b97b14d7007f7936851d3f2f01846899f5ebf08" dependencies = [ "bs58", - "coins-core 0.12.0", + "coins-core", "digest 0.10.7", "hmac", "k256 0.13.4", @@ -2774,22 +2815,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "coins-bip39" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3db8fba409ce3dc04f7d804074039eb68b960b0829161f8e06c95fea3f122528" -dependencies = [ - "bitvec 1.0.1", - "coins-bip32 0.8.7", - "hmac", - "once_cell", - "pbkdf2 0.12.2", - "rand 0.8.5", - "sha2 0.10.8", - "thiserror", -] - [[package]] name = "coins-bip39" version = "0.12.0" @@ -2797,7 +2822,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74b169b26623ff17e9db37a539fe4f15342080df39f129ef7631df7683d6d9d4" dependencies = [ "bitvec 1.0.1", - "coins-bip32 0.12.0", + "coins-bip32", "hmac", "once_cell", "pbkdf2 0.12.2", @@ -2806,26 +2831,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "coins-core" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5286a0843c21f8367f7be734f89df9b822e0321d8bcce8d6e735aadff7d74979" -dependencies = [ - "base64 0.21.7", - "bech32", - "bs58", - "digest 0.10.7", - "generic-array", - "hex", - "ripemd", - "serde", - "serde_derive", - "sha2 0.10.8", - "sha3 0.10.8", - "thiserror", -] - [[package]] name = "coins-core" version = "0.12.0" @@ -3881,24 +3886,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" -[[package]] -name = "enr" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a3d8dc56e02f954cac8eb489772c552c473346fc34f67412bb6244fd647f7e4" -dependencies = [ - "base64 0.21.7", - "bytes", - "hex", - "k256 0.13.4", - "log", - "rand 0.8.5", - "rlp", - "serde", - "sha3 0.10.8", - "zeroize", -] - [[package]] name = "enum_dispatch" version = "0.3.13" @@ -3932,19 +3919,6 @@ dependencies = [ "regex", ] -[[package]] -name = "env_logger" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" -dependencies = [ - "humantime", - "is-terminal", - "log", - "regex", - "termcolor", -] - [[package]] name = "env_logger" version = "0.11.5" @@ -4161,53 +4135,6 @@ dependencies = [ "uint", ] -[[package]] -name = "ethers" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "816841ea989f0c69e459af1cf23a6b0033b19a55424a1ea3a30099becdb8dec0" -dependencies = [ - "ethers-addressbook", - "ethers-contract", - "ethers-core", - "ethers-etherscan", - "ethers-middleware", - "ethers-providers", - "ethers-signers", - "ethers-solc", -] - -[[package]] -name = "ethers-addressbook" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5495afd16b4faa556c3bba1f21b98b4983e53c1755022377051a975c3b021759" -dependencies = [ - "ethers-core", - "once_cell", - "serde", - "serde_json", -] - -[[package]] -name = "ethers-contract" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fceafa3578c836eeb874af87abacfb041f92b4da0a78a5edd042564b8ecdaaa" -dependencies = [ - "const-hex", - "ethers-contract-abigen", - "ethers-contract-derive", - "ethers-core", - "ethers-providers", - "futures-util", - "once_cell", - "pin-project 1.1.7", - "serde", - "serde_json", - "thiserror", -] - [[package]] name = "ethers-contract-abigen" version = "2.0.14" @@ -4218,13 +4145,11 @@ dependencies = [ "const-hex", "dunce", "ethers-core", - "ethers-etherscan", "eyre", "prettyplease", "proc-macro2 1.0.89", "quote 1.0.37", "regex", - "reqwest 0.11.27", "serde", "serde_json", "syn 2.0.87", @@ -4232,22 +4157,6 @@ dependencies = [ "walkdir", ] -[[package]] -name = "ethers-contract-derive" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87689dcabc0051cde10caaade298f9e9093d65f6125c14575db3fd8c669a168f" -dependencies = [ - "Inflector", - "const-hex", - "ethers-contract-abigen", - "ethers-core", - "proc-macro2 1.0.89", - "quote 1.0.37", - "serde_json", - "syn 2.0.87", -] - [[package]] name = "ethers-core" version = "2.0.14" @@ -4278,137 +4187,6 @@ dependencies = [ "unicode-xid 0.2.6", ] -[[package]] -name = "ethers-etherscan" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e79e5973c26d4baf0ce55520bd732314328cabe53193286671b47144145b9649" -dependencies = [ - "chrono", - "ethers-core", - "reqwest 0.11.27", - "semver 1.0.23", - "serde", - "serde_json", - "thiserror", - "tracing", -] - -[[package]] -name = "ethers-middleware" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48f9fdf09aec667c099909d91908d5eaf9be1bd0e2500ba4172c1d28bfaa43de" -dependencies = [ - "async-trait", - "auto_impl", - "ethers-contract", - "ethers-core", - "ethers-etherscan", - "ethers-providers", - "ethers-signers", - "futures-channel", - "futures-locks", - "futures-util", - "instant", - "reqwest 0.11.27", - "serde", - "serde_json", - "thiserror", - "tokio", - "tracing", - "tracing-futures", - "url", -] - -[[package]] -name = "ethers-providers" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6434c9a33891f1effc9c75472e12666db2fa5a0fec4b29af6221680a6fe83ab2" -dependencies = [ - "async-trait", - "auto_impl", - "base64 0.21.7", - "bytes", - "const-hex", - "enr", - "ethers-core", - "futures-core", - "futures-timer", - "futures-util", - "hashers", - "http 0.2.12", - "instant", - "jsonwebtoken 8.3.0", - "once_cell", - "pin-project 1.1.7", - "reqwest 0.11.27", - "serde", - "serde_json", - "thiserror", - "tokio", - "tokio-tungstenite 0.20.1", - "tracing", - "tracing-futures", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "ws_stream_wasm", -] - -[[package]] -name = "ethers-signers" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "228875491c782ad851773b652dd8ecac62cda8571d3bc32a5853644dd26766c2" -dependencies = [ - "async-trait", - "coins-bip32 0.8.7", - "coins-bip39 0.8.7", - "const-hex", - "elliptic-curve 0.13.8", - "eth-keystore", - "ethers-core", - "rand 0.8.5", - "sha2 0.10.8", - "thiserror", - "tracing", -] - -[[package]] -name = "ethers-solc" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66244a771d9163282646dbeffe0e6eca4dda4146b6498644e678ac6089b11edd" -dependencies = [ - "cfg-if 1.0.0", - "const-hex", - "dirs 5.0.1", - "dunce", - "ethers-core", - "glob", - "home", - "md-5", - "num_cpus", - "once_cell", - "path-slash", - "rayon", - "regex", - "semver 1.0.23", - "serde", - "serde_json", - "solang-parser", - "svm-rs 0.3.5", - "thiserror", - "tiny-keccak 2.0.2", - "tokio", - "tracing", - "walkdir", - "yansi 0.5.1", -] - [[package]] name = "event-listener" version = "4.0.3" @@ -4625,7 +4403,7 @@ checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" dependencies = [ "futures-core", "futures-sink", - "spin 0.9.8", + "spin", ] [[package]] @@ -4673,6 +4451,7 @@ dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", "alloy-transport", + "alloy-zksync", "anvil", "async-trait", "axum", @@ -4732,7 +4511,7 @@ dependencies = [ "solang-parser", "soldeer-commands", "strum", - "svm-rs 0.5.8", + "svm-rs", "tempfile", "thiserror", "tikv-jemallocator", @@ -4746,8 +4525,7 @@ dependencies = [ "watchexec", "watchexec-events", "watchexec-signals", - "yansi 1.0.1", - "zksync-web3-rs", + "yansi", "zksync_types", ] @@ -4805,6 +4583,7 @@ dependencies = [ "alloy-serde", "alloy-signer", "alloy-transport", + "alloy-zksync", "async-recursion", "clap", "dialoguer", @@ -4834,8 +4613,7 @@ dependencies = [ "tempfile", "tokio", "tracing", - "yansi 1.0.1", - "zksync-web3-rs", + "yansi", ] [[package]] @@ -4904,7 +4682,7 @@ dependencies = [ "tempfile", "tokio", "tracing", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -4982,7 +4760,6 @@ dependencies = [ "tracing", "vergen", "walkdir", - "zksync-web3-rs", "zksync_types", ] @@ -5017,6 +4794,7 @@ dependencies = [ "alloy-provider", "alloy-rlp", "alloy-transport", + "alloy-zksync", "clap", "color-eyre", "dotenvy", @@ -5040,8 +4818,7 @@ dependencies = [ "tracing", "tracing-subscriber", "tracing-tracy", - "yansi 1.0.1", - "zksync-web3-rs", + "yansi", ] [[package]] @@ -5064,6 +4841,7 @@ dependencies = [ "alloy-transport-http", "alloy-transport-ipc", "alloy-transport-ws", + "alloy-zksync", "anstream", "anstyle", "async-trait", @@ -5089,7 +4867,7 @@ dependencies = [ "tracing", "url", "walkdir", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -5109,7 +4887,7 @@ dependencies = [ "serde", "serde_json", "similar-asserts", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -5141,7 +4919,7 @@ dependencies = [ "serde_json", "sha2 0.10.8", "solang-parser", - "svm-rs 0.5.8", + "svm-rs", "svm-rs-builds", "tempfile", "thiserror", @@ -5149,7 +4927,7 @@ dependencies = [ "tracing", "walkdir", "winnow 0.6.20", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -5182,7 +4960,7 @@ dependencies = [ "tokio", "tracing", "walkdir", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -5217,7 +4995,7 @@ dependencies = [ "thiserror", "tracing", "walkdir", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -5235,7 +5013,7 @@ dependencies = [ "semver 1.0.23", "serde", "serde_json", - "svm-rs 0.5.8", + "svm-rs", "tempfile", "thiserror", "tokio", @@ -5275,7 +5053,7 @@ dependencies = [ "toml_edit 0.22.22", "tracing", "walkdir", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -5561,16 +5339,11 @@ dependencies = [ name = "foundry-zksync-core" version = "0.0.2" dependencies = [ - "alloy-consensus", - "alloy-dyn-abi", "alloy-network", "alloy-primitives", - "alloy-provider", - "alloy-rpc-types", - "alloy-serde", - "alloy-signer", "alloy-sol-types", "alloy-transport", + "alloy-zksync", "ansiterm", "era_test_node", "eyre", @@ -5580,10 +5353,8 @@ dependencies = [ "itertools 0.13.0", "revm", "serde", - "serde_json", "tracing", "url", - "zksync-web3-rs", "zksync_basic_types", "zksync_contracts", "zksync_multivm", @@ -5642,16 +5413,6 @@ dependencies = [ "zksync_bellman", ] -[[package]] -name = "fs2" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "fs4" version = "0.8.4" @@ -5781,16 +5542,6 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" -[[package]] -name = "futures-locks" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45ec6fe3675af967e67c5536c0b9d44e34e6c52f86bedc4ea49c5317b8e94d06" -dependencies = [ - "futures-channel", - "futures-task", -] - [[package]] name = "futures-macro" version = "0.3.31" @@ -5849,15 +5600,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42012b0f064e01aa58b545fe3727f90f7dd4020f4a3ea735b50344965f5a57e9" -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - [[package]] name = "gcloud-sdk" version = "0.25.7" @@ -5869,7 +5611,7 @@ dependencies = [ "chrono", "futures 0.3.31", "hyper 1.5.0", - "jsonwebtoken 9.3.0", + "jsonwebtoken", "once_cell", "prost 0.13.3", "prost-types 0.13.3", @@ -6239,7 +5981,7 @@ dependencies = [ "google-cloud-metadata", "google-cloud-token", "home", - "jsonwebtoken 9.3.0", + "jsonwebtoken", "reqwest 0.12.9", "serde", "serde_json", @@ -6283,7 +6025,7 @@ dependencies = [ "regex", "reqwest 0.12.9", "reqwest-middleware", - "ring 0.17.8", + "ring", "serde", "serde_json", "sha2 0.10.8", @@ -6438,15 +6180,6 @@ dependencies = [ "serde", ] -[[package]] -name = "hashers" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2bca93b15ea5a746f220e56587f71e73c6165eab783df9e26590069953e3c30" -dependencies = [ - "fxhash", -] - [[package]] name = "hashlink" version = "0.9.1" @@ -6721,7 +6454,7 @@ dependencies = [ "tokio", "tokio-rustls 0.26.0", "tower-service", - "webpki-roots 0.26.6", + "webpki-roots", ] [[package]] @@ -7459,20 +7192,6 @@ dependencies = [ "url", ] -[[package]] -name = "jsonwebtoken" -version = "8.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6971da4d9c3aa03c3d8f3ff0f4155b534aad021292003895a469716b2a230378" -dependencies = [ - "base64 0.21.7", - "pem 1.1.1", - "ring 0.16.20", - "serde", - "serde_json", - "simple_asn1", -] - [[package]] name = "jsonwebtoken" version = "9.3.0" @@ -7481,8 +7200,8 @@ checksum = "b9ae10193d25051e74945f1ea2d0b42e03cc3b890f7e4cc5faa44997d808193f" dependencies = [ "base64 0.21.7", "js-sys", - "pem 3.0.4", - "ring 0.17.8", + "pem", + "ring", "serde", "serde_json", "simple_asn1", @@ -7589,7 +7308,7 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" dependencies = [ - "spin 0.9.8", + "spin", ] [[package]] @@ -7852,7 +7571,7 @@ dependencies = [ "clap", "clap_complete", "elasticlunr-rs", - "env_logger 0.11.5", + "env_logger", "handlebars 5.1.2", "log", "memchr", @@ -8472,7 +8191,7 @@ dependencies = [ "alloy-serde", "derive_more 1.0.0", "serde", - "spin 0.9.8", + "spin", ] [[package]] @@ -8849,17 +8568,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "password-hash" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" -dependencies = [ - "base64ct", - "rand_core 0.6.4", - "subtle", -] - [[package]] name = "paste" version = "1.0.15" @@ -8879,9 +8587,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" dependencies = [ "digest 0.10.7", - "hmac", - "password-hash", - "sha2 0.10.8", ] [[package]] @@ -8902,7 +8607,7 @@ checksum = "bdeeaa00ce488657faba8ebf44ab9361f9365a97bd39ffb8a60663f57ff4b467" dependencies = [ "inlinable_string", "pear_codegen", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -8923,15 +8628,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" -[[package]] -name = "pem" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8835c273a76a90455d7344889b0964598e3316e2a79ede8e36f16bdcf2228b8" -dependencies = [ - "base64 0.13.1", -] - [[package]] name = "pem" version = "3.0.4" @@ -9242,7 +8938,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d" dependencies = [ "diff", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -9399,7 +9095,7 @@ dependencies = [ "quote 1.0.37", "syn 2.0.87", "version_check", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -9773,7 +9469,7 @@ checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" dependencies = [ "bytes", "rand 0.8.5", - "ring 0.17.8", + "ring", "rustc-hash 2.0.0", "rustls 0.23.16", "slab", @@ -10104,7 +9800,6 @@ dependencies = [ "http 0.2.12", "http-body 0.4.6", "hyper 0.14.31", - "hyper-rustls 0.24.2", "hyper-tls 0.5.0", "ipnet", "js-sys", @@ -10114,7 +9809,6 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls 0.21.12", "rustls-pemfile 1.0.4", "serde", "serde_json", @@ -10123,13 +9817,11 @@ dependencies = [ "system-configuration 0.5.1", "tokio", "tokio-native-tls", - "tokio-rustls 0.24.1", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots 0.25.4", "winreg", ] @@ -10184,7 +9876,7 @@ dependencies = [ "wasm-bindgen-futures", "wasm-streams", "web-sys", - "webpki-roots 0.26.6", + "webpki-roots", "windows-registry", ] @@ -10341,21 +10033,6 @@ dependencies = [ "bytemuck", ] -[[package]] -name = "ring" -version = "0.16.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" -dependencies = [ - "cc", - "libc", - "once_cell", - "spin 0.5.2", - "untrusted 0.7.1", - "web-sys", - "winapi", -] - [[package]] name = "ring" version = "0.17.8" @@ -10366,8 +10043,8 @@ dependencies = [ "cfg-if 1.0.0", "getrandom 0.2.15", "libc", - "spin 0.9.8", - "untrusted 0.9.0", + "spin", + "untrusted", "windows-sys 0.52.0", ] @@ -10610,7 +10287,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", - "ring 0.17.8", + "ring", "rustls-webpki 0.101.7", "sct", ] @@ -10624,7 +10301,7 @@ dependencies = [ "aws-lc-rs", "log", "once_cell", - "ring 0.17.8", + "ring", "rustls-pki-types", "rustls-webpki 0.102.8", "subtle", @@ -10710,7 +10387,7 @@ dependencies = [ "rustls-webpki 0.102.8", "security-framework", "security-framework-sys", - "webpki-roots 0.26.6", + "webpki-roots", "winapi", ] @@ -10726,8 +10403,8 @@ version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", + "ring", + "untrusted", ] [[package]] @@ -10737,9 +10414,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ "aws-lc-rs", - "ring 0.17.8", + "ring", "rustls-pki-types", - "untrusted 0.9.0", + "untrusted", ] [[package]] @@ -10923,8 +10600,8 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", + "ring", + "untrusted", ] [[package]] @@ -11731,16 +11408,10 @@ dependencies = [ "tokio", "toml_edit 0.22.22", "uuid 1.11.0", - "zip 2.2.0", + "zip", "zip-extract", ] -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - [[package]] name = "spin" version = "0.9.8" @@ -12111,26 +11782,6 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" -[[package]] -name = "svm-rs" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11297baafe5fa0c99d5722458eac6a5e25c01eb1b8e5cd137f54079093daa7a4" -dependencies = [ - "dirs 5.0.1", - "fs2", - "hex", - "once_cell", - "reqwest 0.11.27", - "semver 1.0.23", - "serde", - "serde_json", - "sha2 0.10.8", - "thiserror", - "url", - "zip 0.6.6", -] - [[package]] name = "svm-rs" version = "0.5.8" @@ -12148,7 +11799,7 @@ dependencies = [ "tempfile", "thiserror", "url", - "zip 2.2.0", + "zip", ] [[package]] @@ -12161,7 +11812,7 @@ dependencies = [ "const-hex", "semver 1.0.23", "serde_json", - "svm-rs 0.5.8", + "svm-rs", ] [[package]] @@ -12325,15 +11976,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - [[package]] name = "terminal_size" version = "0.4.0" @@ -12583,21 +12225,6 @@ dependencies = [ "tokio-util 0.7.12", ] -[[package]] -name = "tokio-tungstenite" -version = "0.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c" -dependencies = [ - "futures-util", - "log", - "rustls 0.21.12", - "tokio", - "tokio-rustls 0.24.1", - "tungstenite 0.20.1", - "webpki-roots 0.25.4", -] - [[package]] name = "tokio-tungstenite" version = "0.24.0" @@ -12610,8 +12237,8 @@ dependencies = [ "rustls-pki-types", "tokio", "tokio-rustls 0.26.0", - "tungstenite 0.24.0", - "webpki-roots 0.26.6", + "tungstenite", + "webpki-roots", ] [[package]] @@ -12864,16 +12491,6 @@ dependencies = [ "tracing-subscriber", ] -[[package]] -name = "tracing-futures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project 1.1.7", - "tracing", -] - [[package]] name = "tracing-log" version = "0.2.0" @@ -12992,26 +12609,6 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" -[[package]] -name = "tungstenite" -version = "0.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9" -dependencies = [ - "byteorder", - "bytes", - "data-encoding", - "http 0.2.12", - "httparse", - "log", - "rand 0.8.5", - "rustls 0.21.12", - "sha1", - "thiserror", - "url", - "utf-8", -] - [[package]] name = "tungstenite" version = "0.24.0" @@ -13194,12 +12791,6 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" -[[package]] -name = "untrusted" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" - [[package]] name = "untrusted" version = "0.9.0" @@ -13586,12 +13177,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webpki-roots" -version = "0.25.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" - [[package]] name = "webpki-roots" version = "0.26.6" @@ -13663,7 +13248,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] @@ -14031,12 +13616,6 @@ version = "0.13.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" -[[package]] -name = "yansi" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" - [[package]] name = "yansi" version = "1.0.1" @@ -14087,26 +13666,6 @@ dependencies = [ "syn 2.0.87", ] -[[package]] -name = "zip" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" -dependencies = [ - "aes", - "byteorder", - "bzip2", - "constant_time_eq", - "crc32fast", - "crossbeam-utils", - "flate2", - "hmac", - "pbkdf2 0.11.0", - "sha1", - "time", - "zstd", -] - [[package]] name = "zip" version = "2.2.0" @@ -14133,7 +13692,7 @@ checksum = "25a8c9e90f27d1435088a7b540b6cc8ae6ee525d992a695f16012d2f365b3d3c" dependencies = [ "log", "thiserror", - "zip 2.2.0", + "zip", ] [[package]] @@ -14379,27 +13938,6 @@ dependencies = [ "sha3 0.10.8", ] -[[package]] -name = "zksync-web3-rs" -version = "0.2.1" -source = "git+https://github.com/jrigada/zksync-web3-rs.git?rev=bc3e6d3e75b7ff3747ff2dccefa9fb74d770931b#bc3e6d3e75b7ff3747ff2dccefa9fb74d770931b" -dependencies = [ - "anyhow", - "async-trait", - "clap", - "env_logger 0.10.2", - "ethers", - "ethers-contract", - "hex", - "lazy_static", - "log", - "serde", - "serde_json", - "sha2 0.9.9", - "thiserror", - "tokio", -] - [[package]] name = "zksync_basic_types" version = "0.1.0" @@ -15077,25 +14615,6 @@ dependencies = [ "simd-adler32", ] -[[package]] -name = "zstd" -version = "0.11.2+zstd.1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" -dependencies = [ - "zstd-safe", -] - -[[package]] -name = "zstd-safe" -version = "5.0.2+zstd.1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" -dependencies = [ - "libc", - "zstd-sys", -] - [[package]] name = "zstd-sys" version = "2.0.13+zstd.1.5.6" diff --git a/Cargo.toml b/Cargo.toml index 13bbde1c7..cad9fb0db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -230,6 +230,7 @@ syn-solidity = "0.8.11" alloy-chains = "0.1" alloy-rlp = "0.3" alloy-trie = "0.6.0" +alloy-zksync = "0.5" ## op-alloy op-alloy-rpc-types = "0.5.0" @@ -241,9 +242,7 @@ anstyle = "1.0" terminal_size = "0.4" ## zksync -era_test_node = { git="https://github.com/matter-labs/era-test-node.git" , rev = "94503847b402f0161c3372d5f357a4cb16a2d66d" } -zksync-web3-rs = {git = "https://github.com/jrigada/zksync-web3-rs.git", rev = "bc3e6d3e75b7ff3747ff2dccefa9fb74d770931b"} -# zksync-web3-rs = {git = "https://github.com/lambdaclass/zksync-web3-rs.git", rev = "56653345d14331e0865a6785c77cdda63c94eeba"} +era_test_node = { git = "https://github.com/matter-labs/era-test-node.git", rev = "94503847b402f0161c3372d5f357a4cb16a2d66d" } zksync_basic_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "6c034f6e180cc92e99766f14c8840c90efa56cec" } zksync_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "6c034f6e180cc92e99766f14c8840c90efa56cec" } zksync_state = { git = "https://github.com/matter-labs/zksync-era.git", rev = "6c034f6e180cc92e99766f14c8840c90efa56cec" } @@ -351,27 +350,31 @@ yansi = { version = "1.0", features = ["detect-tty", "detect-env"] } # alloy-transport-ipc = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" } # alloy-transport-ws = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" } +alloy-rpc-client = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-signer-ledger = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-rpc-types-txpool = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-signer-trezor = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-json-rpc = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-signer = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } alloy-consensus = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-contract = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-eips = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-transport-http = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-rpc-types-anvil = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-serde = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-transport-ws = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-signer-local = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } alloy-genesis = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-json-rpc = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-network = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-network-primitives = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-contract = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } alloy-provider = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-signer-aws = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-rpc-types-eth = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-network-primitives = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-transport-ipc = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } alloy-pubsub = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-rpc-client = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-transport = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } alloy-rpc-types = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-eips = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-network = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-rpc-types-engine = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } alloy-rpc-types-trace = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-rpc-types-eth = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-serde = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-signer = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-signer-aws = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } alloy-signer-gcp = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-signer-ledger = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-signer-local = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-signer-trezor = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-transport = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-transport-http = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-transport-ipc = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-transport-ws = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } diff --git a/crates/cast/Cargo.toml b/crates/cast/Cargo.toml index 5eb1e45b7..3e9c35256 100644 --- a/crates/cast/Cargo.toml +++ b/crates/cast/Cargo.toml @@ -36,7 +36,6 @@ foundry-config.workspace = true foundry-evm.workspace = true foundry-wallets.workspace = true foundry-zksync-core.workspace = true -zksync-web3-rs.workspace = true alloy-chains.workspace = true alloy-consensus = { workspace = true, features = ["serde", "kzg"] } @@ -59,6 +58,9 @@ alloy-signer-local = { workspace = true, features = ["mnemonic", "keystore"] } alloy-signer.workspace = true alloy-sol-types.workspace = true alloy-transport.workspace = true +alloy-zksync.workspace = true + +zksync_types.workspace = true chrono.workspace = true eyre.workspace = true diff --git a/crates/cast/bin/cmd/send.rs b/crates/cast/bin/cmd/send.rs index c05ce513d..930db113d 100644 --- a/crates/cast/bin/cmd/send.rs +++ b/crates/cast/bin/cmd/send.rs @@ -6,7 +6,15 @@ use alloy_rpc_types::TransactionRequest; use alloy_serde::WithOtherFields; use alloy_signer::Signer; use alloy_transport::Transport; -use cast::Cast; +use alloy_zksync::{ + network::{ + transaction_request::TransactionRequest as ZkTransactionRequest, + unsigned_tx::eip712::PaymasterParams, Zksync, + }, + provider::ZksyncProvider, + wallet::ZksyncWallet, +}; +use cast::{Cast, ZkCast}; use clap::{builder::ArgPredicate, Parser}; use eyre::Result; use foundry_cli::{ @@ -15,10 +23,7 @@ use foundry_cli::{ }; use foundry_common::ens::NameOrAddress; use foundry_config::Config; -use foundry_wallets::WalletSigner; -use foundry_zksync_core::{self, convert::ConvertAddress}; use std::{path::PathBuf, str::FromStr}; -use zksync_web3_rs::eip712::PaymasterParams; /// ZkSync-specific paymaster parameters for transactions #[derive(Debug, Parser)] @@ -144,6 +149,7 @@ impl SendTxArgs { config.zksync.compile = zksync_params.zksync; let provider = utils::get_provider(&config)?; + let zk_provider = utils::get_provider_zksync(&config)?; let builder = CastTxBuilder::new(&provider, tx, &config) .await? @@ -187,25 +193,43 @@ impl SendTxArgs { // If we cannot successfully instantiate a local signer, then we will assume we don't have // enough information to sign and we must bail. } else { - // Retrieve the signer, and bail if it can't be constructed. - let signer = eth.wallet.signer().await?; - let from = signer.address(); + // NOTE(zk): Avoid initializing `signer` twice as it will error out with Ledger, so we + // move the signers to their respective blocks. + if zksync_params.zksync { + // Retrieve the signer, and bail if it can't be constructed. + let zk_signer: foundry_wallets::WalletSigner = eth.wallet.signer().await?; + let from = zk_signer.address(); - tx::validate_from_address(eth.wallet.from, from)?; + tx::validate_from_address(eth.wallet.from, from)?; + + // Zksync transaction + let (tx, _) = builder.build(&zk_signer).await?; + + let zk_wallet = ZksyncWallet::from(zk_signer); + let zk_provider = ProviderBuilder::<_, _, Zksync>::default() + .wallet(zk_wallet.clone()) + .on_provider(&zk_provider); + let provider = ProviderBuilder::<_, _, AnyNetwork>::default() + .wallet(zk_wallet) + .on_provider(&provider); - if zksync_params.zksync { - let (tx, _) = builder.build(&signer).await?; cast_send_zk( - &provider, - zksync_params, + provider, + zk_provider, tx, + zksync_params, cast_async, confirmations, timeout, - signer, ) .await } else { + // Retrieve the signer, and bail if it can't be constructed. + let signer = eth.wallet.signer().await?; + let from = signer.address(); + + tx::validate_from_address(eth.wallet.from, from)?; + // Standard transaction let (tx, _) = builder.build(&signer).await?; @@ -235,40 +259,37 @@ async fn cast_send, T: Transport + Clone>( handle_transaction_result(&cast, tx_hash, cast_async, confs, timeout).await } -#[allow(clippy::too_many_arguments)] -async fn cast_send_zk, T: Transport + Clone>( +async fn cast_send_zk, Z: ZksyncProvider, T: Transport + Clone>( provider: P, - zksync_params: ZksyncParams, + zk_provider: Z, tx: WithOtherFields, + zksync_params: ZksyncParams, cast_async: bool, confs: u64, timeout: u64, - signer: WalletSigner, ) -> Result<()> { // ZkSync transaction let paymaster_params = zksync_params .paymaster_address .and_then(|addr| zksync_params.paymaster_input.map(|input| (addr, input))) .map(|(addr, input)| PaymasterParams { - paymaster: Address::from_str(&addr).expect("Invalid paymaster address").to_h160(), - paymaster_input: Bytes::from_str(&input).expect("Invalid paymaster input").to_vec(), + paymaster: Address::from_str(&addr).expect("Invalid paymaster address"), + paymaster_input: Bytes::from_str(&input).expect("Invalid paymaster input"), }); - // Build EIP712 transaction for ZKSync - let tx = foundry_zksync_core::new_eip712_transaction( - tx, - Vec::new(), // Empty factory_deps - paymaster_params, - &provider, - signer, - ) - .await - .map_err(|e| eyre::eyre!("Failed to create EIP712 transaction: {}", e))?; - - // Use send_raw_transaction for ZKSync - let tx_hash = provider.send_raw_transaction(&tx).await?.tx_hash().to_owned(); - let cast = Cast::new(provider); - handle_transaction_result(&cast, &tx_hash, cast_async, confs, timeout).await + let mut zk_tx: ZkTransactionRequest = tx.inner.clone().into(); + if let Some(paymaster_params) = paymaster_params { + zk_tx.set_paymaster(paymaster_params); + } + + foundry_zksync_core::estimate_gas(&mut zk_tx, &zk_provider).await?; + + let cast = ZkCast::new(zk_provider, Cast::new(provider)); + let pending_tx = cast.send_zk(zk_tx).await?; + + let tx_hash = pending_tx.inner().tx_hash(); + + handle_transaction_result(cast.as_ref(), tx_hash, cast_async, confs, timeout).await } async fn handle_transaction_result, T: Transport + Clone>( diff --git a/crates/cast/src/lib.rs b/crates/cast/src/lib.rs index 75272b3b1..d8776e3b5 100644 --- a/crates/cast/src/lib.rs +++ b/crates/cast/src/lib.rs @@ -19,6 +19,9 @@ use alloy_rpc_types::{BlockId, BlockNumberOrTag, Filter, TransactionRequest}; use alloy_serde::WithOtherFields; use alloy_sol_types::sol; use alloy_transport::Transport; +use alloy_zksync::network::{ + transaction_request::TransactionRequest as ZkTransactionRequest, Zksync, +}; use base::{Base, NumberWithBase, ToBase}; use chrono::DateTime; use eyre::{Context, ContextCompat, Result}; @@ -69,6 +72,59 @@ sol! { } } +pub struct ZkCast { + provider: Z, + inner: Cast, +} + +impl AsRef> for ZkCast +where + P: Provider, + T: Transport + Clone, + Z: Provider, +{ + fn as_ref(&self) -> &Cast { + &self.inner + } +} + +impl ZkCast +where + P: Provider, + T: Transport + Clone, + Z: Provider, +{ + /// Creates a new ZkCast instance from the provided client and Cast instance + /// + /// # Example + /// + /// ``` + /// use alloy_provider::{network::AnyNetwork, ProviderBuilder, RootProvider}; + /// use cast::Cast; + /// + /// # async fn foo() -> eyre::Result<()> { + /// let provider = + /// ProviderBuilder::<_, _, AnyNetwork>::default().on_builtin("http://localhost:8545").await?; + /// let cast = Cast::new(provider); + /// let zk_provider = + /// ProviderBuilder::<_, _, Zksync>::default().on_builtin("http://localhost:8011").await?; + /// let zk_cast = ZkCast::new(provider, cast); + /// # Ok(()) + /// # } + /// ``` + pub fn new(provider: Z, cast: Cast) -> Self { + Self { provider, inner: cast } + } + + pub async fn send_zk( + &self, + tx: ZkTransactionRequest, + ) -> Result> { + let res = self.provider.send_transaction(tx).await?; + + Ok(res) + } +} pub struct Cast { provider: P, transport: PhantomData, diff --git a/crates/cheatcodes/Cargo.toml b/crates/cheatcodes/Cargo.toml index 2ddec87d3..e817e1598 100644 --- a/crates/cheatcodes/Cargo.toml +++ b/crates/cheatcodes/Cargo.toml @@ -34,7 +34,6 @@ forge-script-sequence.workspace = true foundry-zksync-core.workspace = true foundry-zksync-compiler.workspace = true foundry-zksync-inspectors.workspace = true -zksync-web3-rs.workspace = true zksync_types.workspace = true diff --git a/crates/cheatcodes/src/inspector.rs b/crates/cheatcodes/src/inspector.rs index 654644ce7..4d4f937b4 100644 --- a/crates/cheatcodes/src/inspector.rs +++ b/crates/cheatcodes/src/inspector.rs @@ -76,12 +76,12 @@ use std::{ }; use zksync_types::{ block::{pack_block_info, unpack_block_info}, + transaction_request::PaymasterParams, utils::{decompose_full_nonce, nonces_to_full_nonce}, ACCOUNT_CODE_STORAGE_ADDRESS, CONTRACT_DEPLOYER_ADDRESS, CURRENT_VIRTUAL_BLOCK_INFO_POSITION, H256, KNOWN_CODES_STORAGE_ADDRESS, L2_BASE_TOKEN_ADDRESS, NONCE_HOLDER_ADDRESS, SYSTEM_CONTEXT_ADDRESS, }; -use zksync_web3_rs::eip712::PaymasterParams; mod utils; diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index ccc29777c..89af3647f 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -19,7 +19,6 @@ foundry-config.workspace = true foundry-debugger.workspace = true foundry-evm.workspace = true foundry-wallets.workspace = true -zksync-web3-rs.workspace = true foundry-compilers = { workspace = true, features = ["full"] } @@ -31,6 +30,7 @@ alloy-provider.workspace = true alloy-rlp.workspace = true alloy-transport.workspace = true alloy-chains.workspace = true +alloy-zksync.workspace = true clap = { version = "4", features = ["derive", "env", "unicode", "wrap_help"] } color-eyre.workspace = true diff --git a/crates/cli/src/opts/build/zksync.rs b/crates/cli/src/opts/build/zksync.rs index a463975e8..d6a0e1c2b 100644 --- a/crates/cli/src/opts/build/zksync.rs +++ b/crates/cli/src/opts/build/zksync.rs @@ -1,10 +1,10 @@ use std::{collections::HashSet, path::PathBuf}; +use alloy_primitives::{Address, Bytes}; use clap::Parser; use foundry_compilers::zksolc::settings::{ZkSolcError, ZkSolcWarning}; use foundry_config::ZkSyncConfig; use serde::Serialize; -use zksync_web3_rs::types::{Address, Bytes}; #[derive(Clone, Debug, Default, Serialize, Parser)] #[clap(next_help_heading = "ZKSync configuration")] diff --git a/crates/cli/src/utils/mod.rs b/crates/cli/src/utils/mod.rs index 2d8471e62..a66923de9 100644 --- a/crates/cli/src/utils/mod.rs +++ b/crates/cli/src/utils/mod.rs @@ -2,6 +2,7 @@ use alloy_json_abi::JsonAbi; use alloy_primitives::U256; use alloy_provider::{network::AnyNetwork, Provider}; use alloy_transport::Transport; +use alloy_zksync::network::Zksync; use eyre::{ContextCompat, Result}; use foundry_common::{ provider::{ProviderBuilder, RetryProvider}, @@ -90,6 +91,12 @@ pub fn get_provider(config: &Config) -> Result { get_provider_builder(config)?.build() } +/// Returns a [RetryProvider] instantiated using [Config]'s +/// RPC for ZKsync +pub fn get_provider_zksync(config: &Config) -> Result> { + get_provider_builder(config)?.build_zksync() +} + /// Returns a [ProviderBuilder] instantiated using [Config] values. /// /// Defaults to `http://localhost:8545` and `Mainnet`. diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index 2009506f5..ea8f0e46e 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -43,6 +43,7 @@ alloy-transport-ipc.workspace = true alloy-transport-ws.workspace = true alloy-transport.workspace = true alloy-consensus = { workspace = true, features = ["k256"] } +alloy-zksync.workspace = true tower.workspace = true diff --git a/crates/common/src/provider/mod.rs b/crates/common/src/provider/mod.rs index 4fb9e29ae..b88d9c00f 100644 --- a/crates/common/src/provider/mod.rs +++ b/crates/common/src/provider/mod.rs @@ -15,6 +15,7 @@ use alloy_transport::{ layers::{RetryBackoffLayer, RetryBackoffService}, utils::guess_local_url, }; +use alloy_zksync::network::Zksync; use eyre::{Result, WrapErr}; use foundry_config::NamedChain; use reqwest::Url; @@ -86,6 +87,12 @@ pub fn try_get_http_provider(builder: impl AsRef) -> Result ProviderBuilder::new(builder.as_ref()).build() } +/// Constructs a ZKsync provider with a 100 millisecond interval poll if it's a localhost URL (most +/// likely an anvil or other dev node) and with the default, or 7 second otherwise. +#[inline] +pub fn try_get_zksync_http_provider(builder: impl AsRef) -> Result> { + ProviderBuilder::new(builder.as_ref()).build_zksync() +} /// Helper type to construct a `RetryProvider` #[derive(Debug)] pub struct ProviderBuilder { @@ -284,6 +291,46 @@ impl ProviderBuilder { Ok(provider) } + /// Constructs the `RetryProvider` taking all configs into account for ZKsync network. + pub fn build_zksync(self) -> Result> { + let Self { + url, + chain, + max_retry, + initial_backoff, + timeout, + compute_units_per_second, + jwt, + headers, + is_local, + } = self; + let url = url?; + + let retry_layer = + RetryBackoffLayer::new(max_retry, initial_backoff, compute_units_per_second); + + let transport = RuntimeTransportBuilder::new(url) + .with_timeout(timeout) + .with_headers(headers) + .with_jwt(jwt) + .build(); + let client = ClientBuilder::default().layer(retry_layer).transport(transport, is_local); + + if !is_local { + client.set_poll_interval( + chain + .average_blocktime_hint() + .unwrap_or(DEFAULT_UNKNOWN_CHAIN_BLOCK_TIME) + .mul_f32(POLL_INTERVAL_BLOCK_TIME_SCALE_FACTOR), + ); + } + + let provider = + AlloyProviderBuilder::<_, _, Zksync>::default().on_provider(RootProvider::new(client)); + + Ok(provider) + } + /// Constructs the `RetryProvider` with a wallet. pub fn build_with_wallet(self, wallet: EthereumWallet) -> Result { let Self { diff --git a/crates/evm/core/src/backend/cow.rs b/crates/evm/core/src/backend/cow.rs index e4a2734b1..41b28ed75 100644 --- a/crates/evm/core/src/backend/cow.rs +++ b/crates/evm/core/src/backend/cow.rs @@ -13,6 +13,7 @@ use alloy_primitives::{map::HashMap, Address, B256, U256}; use alloy_rpc_types::TransactionRequest; use eyre::WrapErr; use foundry_fork_db::DatabaseError; +use foundry_zksync_core::PaymasterParams; use revm::{ db::DatabaseRef, primitives::{ @@ -66,7 +67,7 @@ impl<'a> CowBackend<'a> { env: &mut Env, persisted_factory_deps: &mut HashMap>, factory_deps: Option>>, - paymaster_data: Option, + paymaster_data: Option, ) -> eyre::Result { // this is a new call to inspect with a new env, so even if we've cloned the backend // already, we reset the initialized state diff --git a/crates/evm/core/src/backend/mod.rs b/crates/evm/core/src/backend/mod.rs index aa2fdbc76..e0042f9d7 100644 --- a/crates/evm/core/src/backend/mod.rs +++ b/crates/evm/core/src/backend/mod.rs @@ -15,8 +15,9 @@ use eyre::Context; use foundry_common::{is_known_system_sender, SYSTEM_TRANSACTION_TYPE}; pub use foundry_fork_db::{cache::BlockchainDbMeta, BlockchainDb, SharedBackend}; use foundry_zksync_core::{ - convert::ConvertH160, ACCOUNT_CODE_STORAGE_ADDRESS, IMMUTABLE_SIMULATOR_STORAGE_ADDRESS, - KNOWN_CODES_STORAGE_ADDRESS, L2_BASE_TOKEN_ADDRESS, NONCE_HOLDER_ADDRESS, + convert::ConvertH160, PaymasterParams, ACCOUNT_CODE_STORAGE_ADDRESS, + IMMUTABLE_SIMULATOR_STORAGE_ADDRESS, KNOWN_CODES_STORAGE_ADDRESS, L2_BASE_TOKEN_ADDRESS, + NONCE_HOLDER_ADDRESS, }; use itertools::Itertools; use revm::{ @@ -840,7 +841,7 @@ impl Backend { env: &mut EnvWithHandlerCfg, persisted_factory_deps: &mut HashMap>, factory_deps: Option>>, - paymaster_data: Option, + paymaster_data: Option, ) -> eyre::Result { self.initialize(env); diff --git a/crates/forge/Cargo.toml b/crates/forge/Cargo.toml index c6f8f9aba..cd30adeb6 100644 --- a/crates/forge/Cargo.toml +++ b/crates/forge/Cargo.toml @@ -75,6 +75,7 @@ alloy-signer.workspace = true alloy-sol-macro-expander = { workspace = true, features = ["json"] } alloy-sol-macro-input.workspace = true alloy-transport.workspace = true +alloy-zksync.workspace = true async-trait.workspace = true clap = { version = "4", features = ["derive", "env", "unicode", "wrap_help"] } @@ -115,7 +116,6 @@ soldeer-commands.workspace = true quick-junit = "0.5.0" # zk -zksync-web3-rs.workspace = true zksync_types.workspace = true [target.'cfg(unix)'.dependencies] diff --git a/crates/forge/bin/cmd/create.rs b/crates/forge/bin/cmd/create.rs index 20d7c1978..2cdb55890 100644 --- a/crates/forge/bin/cmd/create.rs +++ b/crates/forge/bin/cmd/create.rs @@ -8,6 +8,10 @@ use alloy_rpc_types::{AnyTransactionReceipt, TransactionRequest}; use alloy_serde::WithOtherFields; use alloy_signer::Signer; use alloy_transport::{Transport, TransportError}; +use alloy_zksync::{ + network::{unsigned_tx::eip712::PaymasterParams, Zksync}, + wallet::ZksyncWallet, +}; use clap::{Parser, ValueHint}; use eyre::{Context, Result}; use forge_verify::{zk_provider::CompilerVerificationContext, RetryArgs}; @@ -32,7 +36,6 @@ use foundry_config::{ }, merge_impl_figment_convert, Config, }; -use foundry_wallets::WalletSigner; use foundry_zksync_core::convert::ConvertH160; use serde_json::json; use std::{ @@ -44,7 +47,6 @@ use std::{ sync::Arc, }; use zksync_types::H256; -use zksync_web3_rs::eip712::PaymasterParams; merge_impl_figment_convert!(CreateArgs, opts, eth); @@ -110,6 +112,7 @@ pub struct CreateArgs { /// Data used to deploy a contract on zksync pub struct ZkSyncData { + #[allow(dead_code)] bytecode: Vec, bytecode_hash: H256, factory_deps: Vec>, @@ -135,8 +138,7 @@ impl CreateArgs { .zk .paymaster_input .clone() - .unwrap_or_default() - .to_vec(), + .unwrap_or_default(), }) } else { None @@ -183,7 +185,7 @@ impl CreateArgs { // Add arguments to constructor let config = self.eth.try_load_config_emit_warnings()?; - let provider = utils::get_provider(&config)?; + let provider = utils::get_provider_zksync(&config)?; let params = match abi.constructor { Some(ref v) => { let constructor_args = @@ -256,7 +258,7 @@ impl CreateArgs { }; let zk_data = ZkSyncData { bytecode, bytecode_hash, factory_deps, paymaster_params }; - let result = if self.unlocked { + return if self.unlocked { // Deploy with unlocked account let sender = self.eth.wallet.from.expect("required"); self.deploy_zk( @@ -268,7 +270,6 @@ impl CreateArgs { sender, config.transaction_timeout, zk_data, - None, ) .await } else { @@ -277,7 +278,9 @@ impl CreateArgs { // and potentially other devices that rely on HID too let zk_signer = self.eth.wallet.signer().await?; let deployer = zk_signer.address(); - let provider = ProviderBuilder::<_, _, AnyNetwork>::default().on_provider(provider); + let provider = ProviderBuilder::<_, _, Zksync>::default() + .wallet(ZksyncWallet::new(zk_signer)) + .on_provider(provider); self.deploy_zk( abi, bin.object(), @@ -287,12 +290,9 @@ impl CreateArgs { deployer, config.transaction_timeout, zk_data, - Some(zk_signer), ) .await - }; - - return result; + } } let target_path = if let Some(ref mut path) = self.contract.path { @@ -563,9 +563,9 @@ impl CreateArgs { verify.run().await } - // Deploys the zk contract + /// Deploys the contract using ZKsync provider. #[allow(clippy::too_many_arguments)] - async fn deploy_zk, T: Transport + Clone>( + async fn deploy_zk, T: Transport + Clone>( self, abi: JsonAbi, bin: BytecodeObject, @@ -575,29 +575,34 @@ impl CreateArgs { deployer_address: Address, timeout: u64, zk_data: ZkSyncData, - zk_signer: Option, ) -> Result<()> { let bin = bin.into_bytes().unwrap_or_else(|| { panic!("no bytecode found in bin object for {}", self.contract.name) }); let provider = Arc::new(provider); - let factory = ContractFactory::new(abi.clone(), bin.clone(), provider.clone(), timeout); + let factory = ContractFactory::new_zk(abi.clone(), bin.clone(), provider.clone(), timeout); let is_args_empty = args.is_empty(); let mut deployer = - factory.deploy_tokens_zk(args.clone(), &zk_data).context("failed to deploy contract") - .map(|deployer| deployer.set_zk_factory_deps(zk_data.factory_deps.clone()).set_zk_paymaster_params(zk_data.paymaster_params.clone())).map_err(|e| { + factory.deploy_tokens_zk(args.clone(), &zk_data).context("failed to deploy contract").map_err(|e| { if is_args_empty { e.wrap_err("no arguments provided for contract constructor; consider --constructor-args or --constructor-args-path") } else { e } })?; + let is_legacy = self.tx.legacy || Chain::from(chain).is_legacy(); + deployer.tx = deployer.tx.with_factory_deps( + zk_data.factory_deps.clone().into_iter().map(|dep| dep.into()).collect(), + ); + if let Some(paymaster_params) = zk_data.paymaster_params { + deployer.tx.set_paymaster(paymaster_params); + } deployer.tx.set_from(deployer_address); deployer.tx.set_chain_id(chain); // `to` field must be set explicitly, cannot be None. - if deployer.tx.to.is_none() { + if deployer.tx.to().is_none() { deployer.tx.set_create(); } deployer.tx.set_nonce(if let Some(nonce) = self.tx.nonce { @@ -618,33 +623,31 @@ impl CreateArgs { }; deployer.tx.set_gas_price(gas_price); - let estimated_gas = foundry_zksync_core::estimate_gas( - &deployer.tx, - zk_data.factory_deps.clone(), - &provider, - ) - .await?; + // estimate fee + foundry_zksync_core::estimate_gas(&mut deployer.tx, &provider).await?; - deployer.tx.set_gas_limit(if let Some(gas_limit) = self.tx.gas_limit { - gas_limit.to::() - } else { - estimated_gas.limit - }); + if !is_legacy { + let estimate = provider.estimate_eip1559_fees(None).await.wrap_err("Failed to estimate EIP1559 fees. This chain might not support EIP1559, try adding --legacy to your command.")?; + let priority_fee = if let Some(priority_fee) = self.tx.priority_gas_price { + priority_fee.to() + } else { + estimate.max_priority_fee_per_gas + }; + let max_fee = if let Some(max_fee) = self.tx.gas_price { + max_fee.to() + } else { + estimate.max_fee_per_gas + }; - let zk_constructor_args = match abi.constructor() { - None => Default::default(), - Some(constructor) => constructor.abi_encode_input(&args).unwrap_or_default(), - }; - let data = foundry_zksync_core::encode_create_params( - &forge::revm::primitives::CreateScheme::Create, - zk_data.bytecode_hash, - zk_constructor_args, - ); - let data = Bytes::from(data); - deployer.tx.set_input(data); + deployer.tx.set_max_fee_per_gas(max_fee); + deployer.tx.set_max_priority_fee_per_gas(priority_fee); + } - deployer.tx.set_to(foundry_zksync_core::CONTRACT_DEPLOYER_ADDRESS.to_address()); + if let Some(gas_limit) = self.tx.gas_limit { + deployer.tx.set_gas_limit(gas_limit.to::()); + }; + // Before we actually deploy the contract we try check if the verify settings are valid let mut constructor_args = None; if self.verify { if !args.is_empty() { @@ -652,14 +655,14 @@ impl CreateArgs { .constructor() .ok_or_else(|| eyre::eyre!("could not find constructor"))? .abi_encode_input(&args)?; - constructor_args = Some(hex::encode(encoded_args)); + constructor_args = Some(hex::encode_prefixed(encoded_args)); } self.verify_preflight_check(constructor_args.clone(), chain).await?; } // Deploy the actual contract - let (deployed_contract, receipt) = deployer.send_with_receipt_zk(zk_signer).await?; + let (deployed_contract, receipt) = deployer.send_with_receipt().await?; let address = deployed_contract; if shell::is_json() { @@ -707,7 +710,7 @@ impl CreateArgs { evm_version: self.opts.compiler.evm_version, show_standard_json_input: self.show_standard_json_input, guess_constructor_args: false, - zksync: true, + zksync: self.opts.compiler.zk.enabled(), }; sh_println!("Waiting for {} to detect contract deployment...", verify.verifier.verifier)?; verify.run().await @@ -841,40 +844,17 @@ where P: Provider, T: Transport + Clone, { - /// Set zksync's factory deps. - pub fn set_zk_factory_deps(mut self, deps: Vec>) -> Self { - self.zk_factory_deps = Some(deps); - self - } - - /// Set zksync's paymaster params. - pub fn set_zk_paymaster_params(mut self, params: Option) -> Self { - self.zk_paymaster_params = params; - self - } - - /// Broadcasts the zk contract deployment transaction and after waiting for it to + /// Broadcasts the contract deployment transaction and after waiting for it to /// be sufficiently confirmed (default: 1), it returns a tuple with /// the [`Contract`](crate::Contract) struct at the deployed contract's address /// and the corresponding [`AnyReceipt`]. - pub async fn send_with_receipt_zk( + pub async fn send_with_receipt( self, - signer: Option, ) -> Result<(Address, AnyTransactionReceipt), ContractDeploymentError> { - let factory_deps = self.zk_factory_deps.unwrap_or_default(); - let tx = foundry_zksync_core::new_eip712_transaction( - self.tx, - factory_deps, - self.zk_paymaster_params.clone(), - self.client.borrow(), - signer.expect("No signer was found"), - ) - .await - .map_err(|_| ContractDeploymentError::ContractNotDeployed)?; let receipt = self .client .borrow() - .send_raw_transaction(&tx) + .send_transaction(self.tx) .await? .with_required_confirmations(self.confs as u64) .get_receipt() @@ -885,7 +865,47 @@ where Ok((address, receipt)) } +} + +/// Helper which manages the deployment transaction of a smart contract +#[derive(Debug)] +#[must_use = "Deployer does nothing unless you `send` it"] +pub struct ZkDeployer { + /// The deployer's transaction, exposed for overriding the defaults + pub tx: alloy_zksync::network::transaction_request::TransactionRequest, + abi: JsonAbi, + client: B, + confs: usize, + timeout: u64, + zk_factory_deps: Option>>, + _p: PhantomData

, + _t: PhantomData, +} + +impl Clone for ZkDeployer +where + B: Clone, +{ + fn clone(&self) -> Self { + Self { + tx: self.tx.clone(), + abi: self.abi.clone(), + client: self.client.clone(), + confs: self.confs, + timeout: self.timeout, + zk_factory_deps: self.zk_factory_deps.clone(), + _p: PhantomData, + _t: PhantomData, + } + } +} +impl ZkDeployer +where + B: Borrow

+ Clone, + P: Provider, + T: Transport + Clone, +{ /// Broadcasts the contract deployment transaction and after waiting for it to /// be sufficiently confirmed (default: 1), it returns a tuple with /// the [`Contract`](crate::Contract) struct at the deployed contract's address @@ -1022,6 +1042,20 @@ where _t: PhantomData, }) } +} + +impl DeploymentTxFactory +where + B: Borrow

+ Clone, + P: Provider, + T: Transport + Clone, +{ + /// Creates a factory for deployment of the Contract with bytecode, and the + /// constructor defined in the abi. The client will be used to send any deployment + /// transaction. + pub fn new_zk(abi: JsonAbi, bytecode: Bytes, client: B, timeout: u64) -> Self { + Self { client, abi, bytecode, timeout, _p: PhantomData, _t: PhantomData } + } /// Create a deployment tx using the provided tokens as constructor /// arguments @@ -1029,10 +1063,11 @@ where self, params: Vec, zk_data: &ZkSyncData, - ) -> Result, ContractDeploymentError> + ) -> Result, ContractDeploymentError> where B: Clone, { + // Encode the constructor args & concatenate with the bytecode if necessary if self.abi.constructor().is_none() && !params.is_empty() { return Err(ContractDeploymentError::ConstructorError) } @@ -1049,20 +1084,21 @@ where ) .into(); - // create the tx object. - let tx = WithOtherFields::new( + // create the tx object. Since we're deploying a contract, `to` is + // `CONTRACT_DEPLOYER_ADDRESS` + let tx: alloy_zksync::network::transaction_request::TransactionRequest = TransactionRequest::default() .to(foundry_zksync_core::CONTRACT_DEPLOYER_ADDRESS.to_address()) - .input(data.into()), - ); - Ok(Deployer { + .input(data.into()) + .into(); + + Ok(ZkDeployer { client: self.client.clone(), abi: self.abi, tx, confs: 1, timeout: self.timeout, - zk_factory_deps: Some(vec![zk_data.bytecode.clone()]), - zk_paymaster_params: zk_data.paymaster_params.clone(), + zk_factory_deps: None, _p: PhantomData, _t: PhantomData, }) diff --git a/crates/script/Cargo.toml b/crates/script/Cargo.toml index 2f33e8887..96d00e09d 100644 --- a/crates/script/Cargo.toml +++ b/crates/script/Cargo.toml @@ -58,9 +58,7 @@ alloy-primitives.workspace = true alloy-eips.workspace = true alloy-transport.workspace = true alloy-consensus.workspace = true - -# zksync -zksync-web3-rs.workspace = true +alloy-zksync.workspace = true [dev-dependencies] tempfile.workspace = true diff --git a/crates/script/src/broadcast.rs b/crates/script/src/broadcast.rs index d837abde5..7253cddbb 100644 --- a/crates/script/src/broadcast.rs +++ b/crates/script/src/broadcast.rs @@ -3,35 +3,36 @@ use crate::{ verify::BroadcastedState, ScriptArgs, ScriptConfig, }; use alloy_chains::Chain; -use alloy_consensus::{Transaction, TxEnvelope}; +use alloy_consensus::TxEnvelope; use alloy_eips::eip2718::Encodable2718; use alloy_network::{AnyNetwork, EthereumWallet, TransactionBuilder}; use alloy_primitives::{ map::{AddressHashMap, AddressHashSet}, utils::format_units, - Address, TxHash, + Address, Bytes, TxHash, }; use alloy_provider::{utils::Eip1559Estimation, Provider}; use alloy_rpc_types::TransactionRequest; use alloy_serde::WithOtherFields; use alloy_transport::Transport; +use alloy_zksync::network::{ + transaction_request::TransactionRequest as ZkTransactionRequest, Zksync, +}; use eyre::{bail, Context, Result}; use forge_verify::provider::VerificationProviderType; use foundry_cheatcodes::Wallets; use foundry_cli::utils::{has_batch_support, has_different_gas_calc}; use foundry_common::{ - provider::{get_http_provider, try_get_http_provider, RetryProvider}, + provider::{ + get_http_provider, try_get_http_provider, try_get_zksync_http_provider, RetryProvider, + }, TransactionMaybeSigned, }; use foundry_config::Config; -use foundry_zksync_core::{ - convert::{ConvertAddress, ConvertBytes, ConvertSignature, ToSignable}, - ZkTransactionMetadata, -}; +use foundry_zksync_core::{convert::ConvertH160, ZkTransactionMetadata}; use futures::{future::join_all, StreamExt}; use itertools::Itertools; use std::{cmp::Ordering, sync::Arc}; -use zksync_web3_rs::eip712::{Eip712Meta, Eip712Transaction, Eip712TransactionRequest}; pub async fn estimate_gas( tx: &mut WithOtherFields, @@ -60,53 +61,10 @@ pub async fn next_nonce(caller: Address, provider_url: &str) -> eyre::Result, - tx: WithOtherFields, - zk: &ZkTransactionMetadata, -) -> Result<(Eip712TransactionRequest, Eip712Transaction)> { - let mut custom_data = Eip712Meta::new().factory_deps(zk.factory_deps.clone()); - - if let Some(paymaster_params) = &zk.paymaster_data { - custom_data = custom_data.paymaster_params(paymaster_params.clone()); - } - - let gas_price = match tx.gas_price() { - Some(price) => price, - None => provider.get_gas_price().await?, - }; - - let mut deploy_request = Eip712TransactionRequest::new() - .r#type(zksync_web3_rs::zks_utils::EIP712_TX_TYPE) - .from(Address(*tx.from().unwrap()).to_h160()) - .to(tx.to().map(|to| to.to_h160()).unwrap()) - .chain_id(tx.chain_id().unwrap()) - .nonce(tx.nonce().unwrap()) - .data(tx.input().cloned().unwrap_or_default().to_ethers()) - .gas_price(gas_price) - .custom_data(custom_data); - - let fee: zksync_web3_rs::zks_provider::types::Fee = - provider.raw_request("zks_estimateFee".into(), [deploy_request.clone()]).await.unwrap(); - deploy_request = deploy_request - .gas_limit(fee.gas_limit) - .max_fee_per_gas(fee.max_fee_per_gas) - .max_priority_fee_per_gas(fee.max_priority_fee_per_gas); - deploy_request.custom_data.gas_per_pubdata = fee.gas_per_pubdata_limit; - - // TODO: This is a work around as try_into is not propagating - // gas_per_pubdata_byte_limit. It always set the default We would need to - // fix that library or add EIP712 to alloy with correct implementation. - let mut signable: Eip712Transaction = - deploy_request.clone().try_into().wrap_err("converting deploy request")?; - signable.gas_per_pubdata_byte_limit = deploy_request.custom_data.gas_per_pubdata; - - Ok((deploy_request, signable)) -} - #[allow(clippy::too_many_arguments)] pub async fn send_transaction( provider: Arc, + zk_provider: Arc>, mut kind: SendTransactionKind<'_>, zk: Option<&ZkTransactionMetadata>, sequential_broadcast: bool, @@ -143,63 +101,55 @@ pub async fn send_transaction( // Chains which use `eth_estimateGas` are being sent sequentially and require their // gas to be re-estimated right before broadcasting. if !is_fixed_gas_limit && estimate_via_rpc { - // manually add factory_deps to estimate_gas - if let Some(zk) = zk { - tx.other.insert( - "eip712Meta".into(), - serde_json::to_value(&Eip712Meta { - factory_deps: zk.factory_deps.clone(), - ..Default::default() - }) - .expect("failed serializing json"), - ); + // We skip estimating gas for zk transactions as the fee is estimated manually later. + if zk.is_none() { + estimate_gas(tx, &provider, estimate_multiplier).await?; } - estimate_gas(tx, &provider, estimate_multiplier).await?; } } - let pending = match kind { + let pending_tx_hash = match kind { SendTransactionKind::Unlocked(tx) => { debug!("sending transaction from unlocked account {:?}", tx); // Submit the transaction - provider.send_transaction(tx).await? + *provider.send_transaction(tx).await?.tx_hash() } SendTransactionKind::Raw(tx, signer) => { debug!("sending transaction: {:?}", tx); - let signed = if let Some(zk) = zk { - let signer = signer - .signer_by_address(tx.from.expect("no sender")) - .ok_or(eyre::eyre!("Signer not found"))?; - - let (deploy_request, signable) = convert_to_zksync(&provider, tx, zk).await?; - let mut signable = signable.to_signable_tx(); - - let signature = signer - .sign_transaction(&mut signable) - .await - .wrap_err("Failed to sign typed data")?; + if let Some(zk) = zk { + let mut zk_tx: ZkTransactionRequest = tx.inner.clone().into(); + if !zk.factory_deps.is_empty() { + zk_tx.set_factory_deps(zk.factory_deps.iter().map(Bytes::from_iter).collect()); + } + if let Some(paymaster_data) = &zk.paymaster_data { + zk_tx.set_paymaster( + alloy_zksync::network::unsigned_tx::eip712::PaymasterParams { + paymaster: paymaster_data.paymaster.to_address(), + paymaster_input: paymaster_data.paymaster_input.clone().into(), + }, + ); + } + foundry_zksync_core::estimate_gas(&mut zk_tx, &zk_provider).await?; - let encoded = &*deploy_request - .rlp_signed(signature.to_ethers()) - .wrap_err("able to rlp encode deploy request")?; + let zk_signer = alloy_zksync::wallet::ZksyncWallet::new(signer.default_signer()); + let signed = zk_tx.build(&zk_signer).await?.encoded_2718(); - [&[signable.ty()], encoded].concat() + *zk_provider.send_raw_transaction(signed.as_ref()).await?.tx_hash() } else { - tx.build(signer).await?.encoded_2718() - }; - - // Submit the raw transaction - provider.send_raw_transaction(signed.as_ref()).await? + let signed = tx.build(signer).await?.encoded_2718(); + // Submit the raw transaction + *provider.send_raw_transaction(signed.as_ref()).await?.tx_hash() + } } SendTransactionKind::Signed(tx) => { debug!("sending transaction: {:?}", tx); - provider.send_raw_transaction(tx.encoded_2718().as_ref()).await? + *provider.send_raw_transaction(tx.encoded_2718().as_ref()).await?.tx_hash() } }; - Ok(*pending.tx_hash()) + Ok(pending_tx_hash) } /// How to send a single transaction @@ -339,6 +289,7 @@ impl BundledState { let mut sequence = self.sequence.sequences_mut().get_mut(i).unwrap(); let provider = Arc::new(try_get_http_provider(sequence.rpc_url())?); + let zk_provider = Arc::new(try_get_zksync_http_provider(sequence.rpc_url())?); let already_broadcasted = sequence.receipts.len(); let seq_progress = progress.get_sequence_progress(i, sequence); @@ -446,6 +397,7 @@ impl BundledState { for (kind, zk, is_fixed_gas_limit) in batch { let fut = send_transaction( provider.clone(), + zk_provider.clone(), kind.clone(), zk.as_ref(), sequential_broadcast, diff --git a/crates/zksync/core/Cargo.toml b/crates/zksync/core/Cargo.toml index e3532b466..0ab76fa90 100644 --- a/crates/zksync/core/Cargo.toml +++ b/crates/zksync/core/Cargo.toml @@ -16,15 +16,10 @@ foundry-common.workspace = true foundry-evm-abi.workspace = true foundry-cheatcodes-common.workspace = true alloy-primitives.workspace = true -alloy-signer.workspace = true alloy-network.workspace = true alloy-sol-types.workspace = true -alloy-dyn-abi.workspace = true -alloy-serde.workspace = true -alloy-provider.workspace = true alloy-transport.workspace = true -alloy-rpc-types.workspace = true -alloy-consensus.workspace = true +alloy-zksync.workspace = true itertools.workspace = true revm = { workspace = true, default-features = false, features = [ "std", @@ -38,13 +33,11 @@ revm = { workspace = true, default-features = false, features = [ ] } tracing.workspace = true serde.workspace = true -serde_json.workspace = true # zk zksync_multivm.workspace = true zksync_basic_types.workspace = true zksync_types.workspace = true -zksync-web3-rs.workspace = true era_test_node.workspace = true zksync_utils.workspace = true zksync_contracts.workspace = true diff --git a/crates/zksync/core/src/convert.rs b/crates/zksync/core/src/convert.rs index c6f84a6f9..0702b332f 100644 --- a/crates/zksync/core/src/convert.rs +++ b/crates/zksync/core/src/convert.rs @@ -5,12 +5,6 @@ use revm::primitives::{Address, B256}; use zksync_basic_types::{H160, H256, U256}; use zksync_utils::{address_to_h256, h256_to_u256, u256_to_h256}; -use alloy_primitives::{Bytes as AlloyBytes, Signature as AlloySignature}; -use zksync_web3_rs::types::{Bytes as ZkBytes, Signature as ZkSignature}; - -mod eip712; -pub use eip712::*; - /// Conversions from [U256] pub trait ConvertU256 { /// Convert to [rU256] @@ -136,67 +130,6 @@ impl ConvertAddress for Address { } } -/// Conversions to/from [`ZkSignature`] & [`AlloySignature`] -pub trait ConvertSignature { - /// Cast to [`ZkSignature`] - fn to_ethers(self) -> ZkSignature; - /// Cast to [`AlloySignature`] - fn to_alloy(self) -> AlloySignature; -} - -impl ConvertSignature for ZkSignature { - fn to_ethers(self) -> ZkSignature { - self - } - - fn to_alloy(self) -> AlloySignature { - AlloySignature::from_rs_and_parity(self.r.to_ru256(), self.s.to_ru256(), self.v).unwrap() - } -} - -impl ConvertSignature for AlloySignature { - fn to_ethers(self) -> ZkSignature { - let v = self.v(); - ZkSignature { - r: self.r().to_u256(), - s: self.s().to_u256(), - v: v.y_parity_byte_non_eip155().unwrap_or(v.y_parity_byte()) as u64, - } - } - - fn to_alloy(self) -> AlloySignature { - self - } -} - -/// Convert to/from [`AlloyBytes`] & [`ZkBytes`] -pub trait ConvertBytes { - /// Convert to [`AlloyBytes`] - fn to_alloy(self) -> AlloyBytes; - /// Convert to [`ZkBytes`] - fn to_ethers(self) -> ZkBytes; -} - -impl ConvertBytes for AlloyBytes { - fn to_alloy(self) -> AlloyBytes { - self - } - - fn to_ethers(self) -> ZkBytes { - ZkBytes(self.0) - } -} - -impl ConvertBytes for ZkBytes { - fn to_alloy(self) -> AlloyBytes { - AlloyBytes(self.0) - } - - fn to_ethers(self) -> ZkBytes { - self - } -} - #[cfg(test)] mod test { use std::str::FromStr; diff --git a/crates/zksync/core/src/convert/eip712.rs b/crates/zksync/core/src/convert/eip712.rs deleted file mode 100644 index 228d598fd..000000000 --- a/crates/zksync/core/src/convert/eip712.rs +++ /dev/null @@ -1,242 +0,0 @@ -use alloy_consensus::{SignableTransaction, Transaction}; -use alloy_dyn_abi::TypedData; -use alloy_primitives::{bytes::BufMut, Signature, B256}; -/// Conversion between ethers and alloy for EIP712 items -use alloy_sol_types::Eip712Domain as AlloyEip712Domain; -use zksync_web3_rs::{ - eip712::Eip712Transaction, - types::transaction::eip712::{ - encode_type, EIP712Domain as EthersEip712Domain, Eip712 as EthersEip712, Eip712DomainType, - Types, - }, - zks_utils::EIP712_TX_TYPE, -}; - -use super::{ConvertAddress, ConvertH160, ConvertRU256, ConvertU256}; - -/// Convert between Eip712Domain types -pub trait ConvertEIP712Domain { - /// Cast to ethers-rs's Eip712Domain - fn to_ethers(self) -> EthersEip712Domain; - - /// Cast to alloy-rs's Eip712Domain - fn to_alloy(self) -> AlloyEip712Domain; -} - -impl ConvertEIP712Domain for AlloyEip712Domain { - fn to_ethers(self) -> EthersEip712Domain { - EthersEip712Domain { - name: self.name.map(Into::into), - version: self.version.map(Into::into), - chain_id: self.chain_id.map(ConvertRU256::to_u256), - verifying_contract: self.verifying_contract.map(ConvertAddress::to_h160), - salt: self.salt.map(Into::into), - } - } - - fn to_alloy(self) -> AlloyEip712Domain { - self - } -} - -impl ConvertEIP712Domain for EthersEip712Domain { - fn to_ethers(self) -> EthersEip712Domain { - self - } - - fn to_alloy(self) -> AlloyEip712Domain { - AlloyEip712Domain::new( - self.name.map(Into::into), - self.version.map(Into::into), - self.chain_id.map(ConvertU256::to_ru256), - self.verifying_contract.map(ConvertH160::to_address), - self.salt.map(Into::into), - ) - } -} - -/// Wrapper around [`Eip712Transaction`] implementing [`SignableTransaction`] -#[derive(Debug)] -pub struct Eip712SignableTransaction { - inner: Eip712Transaction, - input: alloy_primitives::Bytes, -} - -impl Eip712SignableTransaction { - /// Creates a new `Eip712SignableTransaction` from an existing `Eip712Transaction`. - pub fn new(inner: Eip712Transaction) -> Self { - Self { input: alloy_primitives::Bytes::from_iter(inner.data.iter()), inner } - } -} - -impl Transaction for Eip712SignableTransaction { - fn chain_id(&self) -> Option { - Some(self.inner.chain_id.as_u64()) - } - - fn nonce(&self) -> u64 { - self.inner.nonce.as_u64() - } - - fn gas_limit(&self) -> u64 { - self.inner.gas_limit.as_u64() - } - - fn gas_price(&self) -> Option { - None - } - - fn to(&self) -> Option { - Some(self.inner.to.to_address()) - } - - fn value(&self) -> alloy_primitives::U256 { - self.inner.value.to_ru256() - } - - fn input(&self) -> &alloy_primitives::Bytes { - &self.input - } - - fn max_fee_per_gas(&self) -> u128 { - self.inner.max_fee_per_gas.low_u128() - } - - fn max_priority_fee_per_gas(&self) -> Option { - Some(self.priority_fee_or_price()) - } - - fn max_fee_per_blob_gas(&self) -> Option { - None - } - - fn priority_fee_or_price(&self) -> u128 { - self.inner.max_priority_fee_per_gas.low_u128() - } - - fn ty(&self) -> u8 { - EIP712_TX_TYPE - } - - fn access_list(&self) -> Option<&alloy_rpc_types::AccessList> { - None - } - - fn blob_versioned_hashes(&self) -> Option<&[B256]> { - None - } - - fn authorization_list(&self) -> Option<&[revm::primitives::SignedAuthorization]> { - None - } - - fn kind(&self) -> alloy_primitives::TxKind { - alloy_primitives::TxKind::Call(self.inner.to.to_address()) - } -} - -impl SignableTransaction for Eip712SignableTransaction { - fn set_chain_id(&mut self, chain_id: alloy_primitives::ChainId) { - self.inner.chain_id = chain_id.into(); - } - - fn encode_for_signing(&self, out: &mut dyn BufMut) { - out.put_u8(0x19); - out.put_u8(0x01); - - let domain_separator = self.inner.domain_separator().expect("able to get domain separator"); - out.put_slice(&domain_separator); - - let struct_hash = self.inner.struct_hash().expect("able to get struct hash"); - out.put_slice(&struct_hash); - } - - fn payload_len_for_signature(&self) -> usize { - 2 + 32 + 32 - } - - fn into_signed(self, signature: Signature) -> alloy_consensus::Signed - where - Self: Sized, - { - let hash = self.inner.encode_eip712().map(B256::from).expect("able to encode EIP712 hash"); - alloy_consensus::Signed::new_unchecked(self, signature, hash) - } -} - -/// Convert to [`SignableTransaction`] -pub trait ToSignable { - /// Type to convert to - type Signable: SignableTransaction; - - /// Perform conversion - fn to_signable_tx(self) -> Self::Signable; -} - -impl ToSignable for Eip712Transaction { - type Signable = Eip712SignableTransaction; - - fn to_signable_tx(self) -> Self::Signable { - Eip712SignableTransaction::new(self) - } -} - -/// Convert to [`TypedData`] -pub trait ToTypedData { - /// Convert item to [`TypedData`] - fn to_typed_data(self) -> TypedData; -} - -impl ToTypedData for Eip712Transaction { - fn to_typed_data(self) -> TypedData { - use alloy_dyn_abi::*; - - let types = eip712_transaction_types(); - let primary_type = types.first_key_value().unwrap().0.clone(); - - let domain = EthersEip712::domain(&self).expect("Eip712Transaction has domain").to_alloy(); - - let message = serde_json::to_value(&self).expect("able to serialize as json"); - - let encode_type = encode_type(&primary_type, &types).expect("able to encodeType"); - - let resolver = { - let mut resolver = Resolver::default(); - resolver.ingest_string(&encode_type).expect("able to ingest encodeType"); - resolver - }; - - TypedData { domain, resolver, primary_type, message } - } -} - -//zksync_web3_rs::eip712::transaction -fn eip712_transaction_types() -> Types { - let mut types = Types::new(); - - types.insert( - "Transaction".to_owned(), - vec![ - Eip712DomainType { name: "txType".to_owned(), r#type: "uint256".to_owned() }, - Eip712DomainType { name: "from".to_owned(), r#type: "uint256".to_owned() }, - Eip712DomainType { name: "to".to_owned(), r#type: "uint256".to_owned() }, - Eip712DomainType { name: "gasLimit".to_owned(), r#type: "uint256".to_owned() }, - Eip712DomainType { - name: "gasPerPubdataByteLimit".to_owned(), - r#type: "uint256".to_owned(), - }, - Eip712DomainType { name: "maxFeePerGas".to_owned(), r#type: "uint256".to_owned() }, - Eip712DomainType { - name: "maxPriorityFeePerGas".to_owned(), - r#type: "uint256".to_owned(), - }, - Eip712DomainType { name: "paymaster".to_owned(), r#type: "uint256".to_owned() }, - Eip712DomainType { name: "nonce".to_owned(), r#type: "uint256".to_owned() }, - Eip712DomainType { name: "value".to_owned(), r#type: "uint256".to_owned() }, - Eip712DomainType { name: "data".to_owned(), r#type: "bytes".to_owned() }, - Eip712DomainType { name: "factoryDeps".to_owned(), r#type: "bytes32[]".to_owned() }, - Eip712DomainType { name: "paymasterInput".to_owned(), r#type: "bytes".to_owned() }, - ], - ); - types -} diff --git a/crates/zksync/core/src/lib.rs b/crates/zksync/core/src/lib.rs index 7275c1b53..7218ff60e 100644 --- a/crates/zksync/core/src/lib.rs +++ b/crates/zksync/core/src/lib.rs @@ -18,18 +18,15 @@ pub mod vm; /// ZKSync Era State implementation. pub mod state; -use alloy_network::{AnyNetwork, TxSigner}; +use alloy_network::TransactionBuilder; use alloy_primitives::{address, hex, keccak256, Address, Bytes, U256 as rU256}; -use alloy_provider::Provider; -use alloy_rpc_types::TransactionRequest; -use alloy_serde::WithOtherFields; -use alloy_signer::Signature; use alloy_transport::Transport; -use convert::{ - ConvertAddress, ConvertBytes, ConvertH160, ConvertH256, ConvertRU256, ConvertSignature, - ConvertU256, ToSignable, +use alloy_zksync::{ + network::transaction_request::TransactionRequest as ZkTransactionRequest, + provider::ZksyncProvider, }; -use eyre::{eyre, OptionExt}; +use convert::{ConvertAddress, ConvertH160, ConvertH256, ConvertRU256, ConvertU256}; +use eyre::eyre; use revm::{Database, InnerEvmContext}; use serde::{Deserialize, Serialize}; use std::fmt::Debug; @@ -40,20 +37,15 @@ pub use vm::{balance, encode_create_params, nonce}; pub use vm::{SELECTOR_CONTRACT_DEPLOYER_CREATE, SELECTOR_CONTRACT_DEPLOYER_CREATE2}; pub use zksync_multivm::interface::{Call, CallType}; pub use zksync_types::{ - ethabi, ACCOUNT_CODE_STORAGE_ADDRESS, CONTRACT_DEPLOYER_ADDRESS, H256, - IMMUTABLE_SIMULATOR_STORAGE_ADDRESS, KNOWN_CODES_STORAGE_ADDRESS, L2_BASE_TOKEN_ADDRESS, - NONCE_HOLDER_ADDRESS, + ethabi, transaction_request::PaymasterParams, ACCOUNT_CODE_STORAGE_ADDRESS, + CONTRACT_DEPLOYER_ADDRESS, H256, IMMUTABLE_SIMULATOR_STORAGE_ADDRESS, + KNOWN_CODES_STORAGE_ADDRESS, L2_BASE_TOKEN_ADDRESS, NONCE_HOLDER_ADDRESS, }; use zksync_types::{ utils::{decompose_full_nonce, nonces_to_full_nonce, storage_key_for_eth_balance}, U256, }; pub use zksync_utils::bytecode::hash_bytecode; -pub use zksync_web3_rs::{ - eip712::{Eip712Meta, Eip712Transaction, Eip712TransactionRequest, PaymasterParams}, - zks_provider::types::Fee, - zks_utils::EIP712_TX_TYPE, -}; type Result = std::result::Result; @@ -107,78 +99,6 @@ impl ZkTransactionMetadata { Self { factory_deps, paymaster_data } } } - -/// Creates a new signed EIP-712 transaction with the provided factory deps. -pub async fn new_eip712_transaction< - P: Provider, - S: TxSigner + Sync, - T: Transport + Clone, ->( - tx: WithOtherFields, - factory_deps: Vec>, - paymaster_data: Option, - provider: P, - signer: S, -) -> Result { - let from = tx.from.ok_or_eyre("`from` cannot be empty")?; - let to = tx - .to - .and_then(|to| match to { - alloy_primitives::TxKind::Create => None, - alloy_primitives::TxKind::Call(to) => Some(to), - }) - .ok_or_eyre("`to` cannot be empty")?; - let chain_id = tx.chain_id.ok_or_eyre("`chain_id` cannot be empty")?; - let nonce = tx.nonce.ok_or_eyre("`nonce` cannot be empty")?; - let gas_price = tx.gas_price.ok_or_eyre("`gas_price` cannot be empty")?; - - let data = tx.input.clone().into_input().unwrap_or_default(); - let mut custom_data = Eip712Meta::new().factory_deps(factory_deps); - if let Some(params) = paymaster_data { - custom_data = custom_data.paymaster_params(params); - } - - let mut deploy_request = Eip712TransactionRequest::new() - .r#type(EIP712_TX_TYPE) - .from(from.to_h160()) - .to(to.to_h160()) - .chain_id(chain_id) - .nonce(nonce) - .gas_price(gas_price) - .data(data.to_ethers()) - .custom_data(custom_data); - - let gas_price = provider - .get_gas_price() - .await - .map_err(|err| eyre!("failed retrieving gas_price {:?}", err))?; - let fee: Fee = provider - .raw_request("zks_estimateFee".into(), [deploy_request.clone()]) - .await - .map_err(|err| eyre!("failed estimating fee {:?}", err))?; - deploy_request = deploy_request - .gas_limit(fee.gas_limit) - .max_fee_per_gas(fee.max_fee_per_gas) - .max_priority_fee_per_gas(fee.max_priority_fee_per_gas) - .gas_price(gas_price); - - let signable: Eip712Transaction = deploy_request - .clone() - .try_into() - .map_err(|err| eyre!("failed converting deploy request to eip-712 tx {:?}", err))?; - - let mut signable = signable.to_signable_tx(); - let signature = - signer.sign_transaction(&mut signable).await.expect("Failed to sign typed data"); - let encoded_rlp = deploy_request - .rlp_signed(signature.to_ethers()) - .map_err(|err| eyre!("failed encoding deployment request {:?}", err))?; - - let tx = [&[EIP712_TX_TYPE], encoded_rlp.to_vec().as_slice()].concat().into(); - - Ok(tx) -} - /// Estimated gas from a ZK network. pub struct EstimatedGas { /// Estimated gas price. @@ -188,47 +108,18 @@ pub struct EstimatedGas { } /// Estimates the gas parameters for the provided transaction. -pub async fn estimate_gas, T: Transport + Clone>( - tx: &WithOtherFields, - factory_deps: Vec>, +/// This will call `estimateFee` method on the rpc and set the gas parameters on the transaction. +pub async fn estimate_gas, T: Transport + Clone>( + tx: &mut ZkTransactionRequest, provider: P, -) -> Result { - let to = tx - .to - .and_then(|to| match to { - alloy_primitives::TxKind::Create => None, - alloy_primitives::TxKind::Call(to) => Some(to), - }) - .ok_or_eyre("`to` cannot be empty")?; - let chain_id = tx.chain_id.ok_or_eyre("`chain_id` cannot be empty")?; - let nonce = tx.nonce.ok_or_eyre("`nonce` cannot be empty")?; - let gas_price = if let Some(gas_price) = tx.gas_price { - gas_price - } else { - provider.get_gas_price().await? - }; - let data = tx.input.clone().into_input().unwrap_or_default(); - let custom_data = Eip712Meta::new().factory_deps(factory_deps); - - let mut deploy_request = Eip712TransactionRequest::new() - .r#type(EIP712_TX_TYPE) - .to(to.to_h160()) - .chain_id(chain_id) - .nonce(nonce) - .gas_price(gas_price) - .data(data.to_ethers()) - .custom_data(custom_data); - if let Some(from) = tx.from { - deploy_request = deploy_request.from(from.to_h160()) - } - - let gas_price = provider.get_gas_price().await.unwrap(); - let fee: Fee = provider - .raw_request("zks_estimateFee".into(), [deploy_request.clone()]) - .await - .map_err(|err| eyre!("failed rpc call for estimating fee: {:?}", err))?; - - Ok(EstimatedGas { price: gas_price, limit: fee.gas_limit.low_u64() }) +) -> Result<()> { + let fee = provider.estimate_fee(tx.clone()).await?; + tx.set_gas_limit(fee.gas_limit); + tx.set_max_fee_per_gas(fee.max_fee_per_gas); + tx.set_max_priority_fee_per_gas(fee.max_priority_fee_per_gas); + tx.set_gas_per_pubdata(fee.gas_per_pubdata_limit); + + Ok(()) } /// Returns true if the provided address is a reserved zkSync system address diff --git a/crates/zksync/core/src/utils.rs b/crates/zksync/core/src/utils.rs index 191db267f..0f58aa4cc 100644 --- a/crates/zksync/core/src/utils.rs +++ b/crates/zksync/core/src/utils.rs @@ -32,7 +32,7 @@ use alloy_primitives::hex; use eyre::Result; use url::Url; use zksync_basic_types::U256; -use zksync_web3_rs::types::H256; +use zksync_types::H256; /// Gets the RPC URL for Ethereum. /// diff --git a/crates/zksync/core/src/vm/runner.rs b/crates/zksync/core/src/vm/runner.rs index 92dd49090..01af26d4d 100644 --- a/crates/zksync/core/src/vm/runner.rs +++ b/crates/zksync/core/src/vm/runner.rs @@ -28,7 +28,7 @@ use crate::{ pub fn transact<'a, DB>( persisted_factory_deps: Option<&'a mut HashMap>>, factory_deps: Option>>, - paymaster_data: Option, + paymaster_data: Option, env: &'a mut Env, db: &'a mut DB, ) -> eyre::Result diff --git a/deny.toml b/deny.toml index ef0dd7003..68838bae4 100644 --- a/deny.toml +++ b/deny.toml @@ -115,9 +115,7 @@ allow-git = [ "https://github.com/alloy-rs/alloy", "https://github.com/paradigmxyz/revm-inspectors", "https://github.com/bluealloy/revm", - "https://github.com/lambdaclass/zksync-web3-rs", "https://github.com/RustCrypto/hashes", - "https://github.com/jrigada/zksync-web3-rs.git", "https://github.com/Karrq/alloy", ]