diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a1ce468d..811782e9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,15 +69,12 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master - name: "Rust Toolchain Setup" with: toolchain: nightly-2024-01-12 - uses: Swatinem/rust-cache@v2 - id: "cache-cargo" - - if: ${{ steps.cache-cargo.outputs.cache-hit != 'true' }} - name: "Download and run cargo-udeps" - run: | - wget -O - -c https://github.com/est31/cargo-udeps/releases/download/v0.1.45/cargo-udeps-v0.1.45-x86_64-unknown-linux-gnu.tar.gz | tar -xz - cargo-udeps-*/cargo-udeps udeps - env: - RUSTUP_TOOLCHAIN: nightly-2024-01-12 + - name: Install udeps (cached) + uses: baptiste0928/cargo-install@v3 + with: + crate: cargo-udeps + - name: run udeps + run: cargo udeps diff --git a/Cargo.lock b/Cargo.lock index f121524a..140a249a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,17 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + [[package]] name = "ahash" version = "0.8.11" @@ -98,6 +109,23 @@ version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" +[[package]] +name = "ark-ec" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba" +dependencies = [ + "ark-ff", + "ark-poly", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", + "itertools 0.10.5", + "num-traits 0.2.18", + "zeroize", +] + [[package]] name = "ark-ff" version = "0.4.2" @@ -141,17 +169,64 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "ark-poly" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", +] + +[[package]] +name = "ark-secp256k1" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c02e954eaeb4ddb29613fee20840c2bbc85ca4396d53e33837e11905363c5f2" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-std", +] + +[[package]] +name = "ark-secp256r1" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3975a01b0a6e3eae0f72ec7ca8598a6620fc72fa5981f6f5cca33b7cd788f633" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-std", +] + [[package]] name = "ark-serialize" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" dependencies = [ + "ark-serialize-derive", "ark-std", "digest", "num-bigint", ] +[[package]] +name = "ark-serialize-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae3281bc6d0fd7e549af32b52511e1302185bd688fd3359fa36423346ff682ea" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "ark-std" version = "0.4.0" @@ -264,6 +339,15 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "bincode" +version = "2.0.0-rc.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f11ea1a0346b94ef188834a65c068a03aec181c94896d481d7a0a40d85b0ce95" +dependencies = [ + "serde", +] + [[package]] name = "bit-set" version = "0.5.3" @@ -312,6 +396,45 @@ dependencies = [ "generic-array", ] +[[package]] +name = "blockifier" +version = "0.7.0-dev.1" +source = "git+https://github.com/starkware-libs/blockifier.git?rev=ba72c863#ba72c8631da01711d785d0b69981301bbb6e6507" +dependencies = [ + "anyhow", + "ark-ec", + "ark-ff", + "ark-secp256k1", + "ark-secp256r1", + "cached", + "cairo-felt", + "cairo-lang-casm", + "cairo-lang-runner", + "cairo-lang-starknet-classes", + "cairo-lang-utils", + "cairo-vm", + "derive_more", + "indexmap 2.2.5", + "itertools 0.10.5", + "keccak", + "log", + "num-bigint", + "num-integer", + "num-rational", + "num-traits 0.2.18", + "once_cell", + "phf", + "rstest", + "serde", + "serde_json", + "sha3", + "starknet-crypto 0.5.2", + "starknet_api", + "strum", + "strum_macros 0.24.3", + "thiserror", +] + [[package]] name = "bumpalo" version = "3.15.4" @@ -336,6 +459,42 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +[[package]] +name = "cached" +version = "0.44.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b195e4fbc4b6862bbd065b991a34750399c119797efff72492f28a5864de8700" +dependencies = [ + "async-trait", + "cached_proc_macro", + "cached_proc_macro_types", + "futures", + "hashbrown 0.13.2", + "instant", + "once_cell", + "thiserror", + "tokio", +] + +[[package]] +name = "cached_proc_macro" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b48814962d2fd604c50d2b9433c2a41a0ab567779ee2c02f7fba6eca1221f082" +dependencies = [ + "cached_proc_macro_types", + "darling", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "cached_proc_macro_types" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade8366b8bd5ba243f0a58f036cc0ca8a2f069cff1a2351ef1cac6b083e16fc0" + [[package]] name = "cairo-felt" version = "0.9.1" @@ -363,6 +522,67 @@ dependencies = [ "serde", ] +[[package]] +name = "cairo-lang-compiler" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7148cb2d72a3db24a6d2ef2b2602102cc5099cb9f6b913e5047fb009cb3a22a1" +dependencies = [ + "anyhow", + "cairo-lang-defs", + "cairo-lang-diagnostics", + "cairo-lang-filesystem", + "cairo-lang-lowering", + "cairo-lang-parser", + "cairo-lang-project", + "cairo-lang-semantic", + "cairo-lang-sierra", + "cairo-lang-sierra-generator", + "cairo-lang-syntax", + "cairo-lang-utils", + "salsa", + "smol_str", + "thiserror", +] + +[[package]] +name = "cairo-lang-debug" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a761eb8e31ea65a2dd45f729c74f1770315f97124dad93d1f6853a10d460c6b" +dependencies = [ + "cairo-lang-utils", +] + +[[package]] +name = "cairo-lang-defs" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6d60bc5d72fe7a95ba34e041dcbdf1cf3bfccb87008a515514b74913fa8ff05" +dependencies = [ + "cairo-lang-debug", + "cairo-lang-diagnostics", + "cairo-lang-filesystem", + "cairo-lang-parser", + "cairo-lang-syntax", + "cairo-lang-utils", + "itertools 0.11.0", + "salsa", + "smol_str", +] + +[[package]] +name = "cairo-lang-diagnostics" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "356089e1b0a0ba9e115566191745613b3806a20259ad76764df82ab534d5412a" +dependencies = [ + "cairo-lang-debug", + "cairo-lang-filesystem", + "cairo-lang-utils", + "itertools 0.11.0", +] + [[package]] name = "cairo-lang-eq-solver" version = "2.6.3" @@ -373,6 +593,165 @@ dependencies = [ "good_lp", ] +[[package]] +name = "cairo-lang-filesystem" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bcb9a4a40e53fa099774bd08bbcc3430f51213cc7fb1b50c2e9d01155731798" +dependencies = [ + "cairo-lang-debug", + "cairo-lang-utils", + "path-clean", + "salsa", + "serde", + "smol_str", +] + +[[package]] +name = "cairo-lang-lowering" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ba60e1e2477aa0f610ccf29189097d580464607c94b51741e1c18e64d6cee5f" +dependencies = [ + "cairo-lang-debug", + "cairo-lang-defs", + "cairo-lang-diagnostics", + "cairo-lang-filesystem", + "cairo-lang-parser", + "cairo-lang-proc-macros", + "cairo-lang-semantic", + "cairo-lang-syntax", + "cairo-lang-utils", + "id-arena", + "itertools 0.11.0", + "log", + "num-bigint", + "num-traits 0.2.18", + "once_cell", + "salsa", + "smol_str", +] + +[[package]] +name = "cairo-lang-parser" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f16ba1535e0cc5e79c2eff6592859bbdac03dc53d4dcdd26dbdbc04a77c3f5c" +dependencies = [ + "cairo-lang-diagnostics", + "cairo-lang-filesystem", + "cairo-lang-syntax", + "cairo-lang-syntax-codegen", + "cairo-lang-utils", + "colored", + "itertools 0.11.0", + "num-bigint", + "num-traits 0.2.18", + "salsa", + "smol_str", + "unescaper", +] + +[[package]] +name = "cairo-lang-plugins" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81c8cf6e0ee3d6b19429cc1663738b22f1ecea7d51bf7452e8e1086f08798baf" +dependencies = [ + "cairo-lang-defs", + "cairo-lang-diagnostics", + "cairo-lang-filesystem", + "cairo-lang-parser", + "cairo-lang-syntax", + "cairo-lang-utils", + "indent", + "indoc", + "itertools 0.11.0", + "salsa", + "smol_str", +] + +[[package]] +name = "cairo-lang-proc-macros" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67f9da66325ce7ed6c002360f26106fe79deb9f8a2fca30abdbb8d388da7bb46" +dependencies = [ + "cairo-lang-debug", + "quote", + "syn 2.0.53", +] + +[[package]] +name = "cairo-lang-project" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e198af1ab3d05c7fb8b6a9a7a2e9bce245a6c855df5f770b751d29874a23b152" +dependencies = [ + "cairo-lang-filesystem", + "cairo-lang-utils", + "serde", + "smol_str", + "thiserror", + "toml", +] + +[[package]] +name = "cairo-lang-runner" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf211f5431e2a6f4802b1b6483bf8e998e506a3be5369ed54a8807aae6e4dbf" +dependencies = [ + "ark-ff", + "ark-secp256k1", + "ark-secp256r1", + "ark-std", + "cairo-felt", + "cairo-lang-casm", + "cairo-lang-lowering", + "cairo-lang-sierra", + "cairo-lang-sierra-ap-change", + "cairo-lang-sierra-generator", + "cairo-lang-sierra-to-casm", + "cairo-lang-sierra-type-size", + "cairo-lang-starknet", + "cairo-lang-utils", + "cairo-vm", + "itertools 0.11.0", + "keccak", + "num-bigint", + "num-integer", + "num-traits 0.2.18", + "smol_str", + "starknet-crypto 0.6.1", + "thiserror", +] + +[[package]] +name = "cairo-lang-semantic" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d7df81521c2125e3e95b683cc99374db1aebd7ddb317c5ca3dd92a235a9eb13" +dependencies = [ + "cairo-lang-debug", + "cairo-lang-defs", + "cairo-lang-diagnostics", + "cairo-lang-filesystem", + "cairo-lang-parser", + "cairo-lang-plugins", + "cairo-lang-proc-macros", + "cairo-lang-syntax", + "cairo-lang-utils", + "id-arena", + "indoc", + "itertools 0.11.0", + "num-bigint", + "num-traits 0.2.18", + "once_cell", + "salsa", + "smol_str", +] + [[package]] name = "cairo-lang-sierra" version = "2.6.3" @@ -429,6 +808,29 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cairo-lang-sierra-generator" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e1d75e0830279ca1bd0189e3326720d6e081225f7d81ed060bbd22c6b37e980" +dependencies = [ + "cairo-lang-debug", + "cairo-lang-defs", + "cairo-lang-diagnostics", + "cairo-lang-filesystem", + "cairo-lang-lowering", + "cairo-lang-parser", + "cairo-lang-semantic", + "cairo-lang-sierra", + "cairo-lang-syntax", + "cairo-lang-utils", + "itertools 0.11.0", + "num-traits 0.2.18", + "once_cell", + "salsa", + "smol_str", +] + [[package]] name = "cairo-lang-sierra-to-casm" version = "2.6.3" @@ -460,6 +862,37 @@ dependencies = [ "cairo-lang-utils", ] +[[package]] +name = "cairo-lang-starknet" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9ffa8b3b8c47138c36b1907cebb5047dfc4de29ec10ece5bd6d6853243ec50" +dependencies = [ + "anyhow", + "cairo-felt", + "cairo-lang-compiler", + "cairo-lang-defs", + "cairo-lang-diagnostics", + "cairo-lang-filesystem", + "cairo-lang-lowering", + "cairo-lang-plugins", + "cairo-lang-semantic", + "cairo-lang-sierra", + "cairo-lang-sierra-generator", + "cairo-lang-starknet-classes", + "cairo-lang-syntax", + "cairo-lang-utils", + "const_format", + "indent", + "indoc", + "itertools 0.11.0", + "once_cell", + "serde", + "serde_json", + "smol_str", + "thiserror", +] + [[package]] name = "cairo-lang-starknet-classes" version = "2.6.3" @@ -485,6 +918,32 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cairo-lang-syntax" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8262c426a57e1e5ec297db24278464841500613445e2cb1c43d5f71ad91ee8d6" +dependencies = [ + "cairo-lang-debug", + "cairo-lang-filesystem", + "cairo-lang-utils", + "num-bigint", + "num-traits 0.2.18", + "salsa", + "smol_str", + "unescaper", +] + +[[package]] +name = "cairo-lang-syntax-codegen" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70e2d692eae4bb4179a4a1148fd5eb738a91653d86750c813658ffad4a99fa97" +dependencies = [ + "genco", + "xshell", +] + [[package]] name = "cairo-lang-utils" version = "2.6.3" @@ -496,10 +955,42 @@ dependencies = [ "itertools 0.11.0", "num-bigint", "num-traits 0.2.18", + "parity-scale-codec", "schemars", "serde", ] +[[package]] +name = "cairo-vm" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd569684da80d747273613d5c809e4f81bf6f6b1b64d0301b12bac8f2fb8ffb1" +dependencies = [ + "anyhow", + "bincode", + "bitvec", + "cairo-felt", + "generic-array", + "hashbrown 0.14.3", + "hex", + "keccak", + "lazy_static", + "mimalloc", + "nom", + "num-bigint", + "num-integer", + "num-prime", + "num-traits 0.2.18", + "rand", + "serde", + "serde_json", + "sha2", + "sha3", + "starknet-crypto 0.6.1", + "starknet-curve 0.4.1", + "thiserror-no-std", +] + [[package]] name = "cc" version = "1.0.90" @@ -530,7 +1021,7 @@ dependencies = [ "anstream", "anstyle", "clap_lex", - "strsim", + "strsim 0.11.1", ] [[package]] @@ -545,6 +1036,16 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "colored" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" +dependencies = [ + "lazy_static", + "windows-sys 0.48.0", +] + [[package]] name = "const-fnv1a-hash" version = "1.1.0" @@ -628,6 +1129,41 @@ dependencies = [ "typenum", ] +[[package]] +name = "darling" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.10.0", + "syn 1.0.109", +] + +[[package]] +name = "darling_macro" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" +dependencies = [ + "darling_core", + "quote", + "syn 1.0.109", +] + [[package]] name = "derivative" version = "2.2.0" @@ -851,6 +1387,28 @@ dependencies = [ "slab", ] +[[package]] +name = "genco" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98d7af598790738fee616426e669360fa361273b1b9c9b7f30c92fa627605cad" +dependencies = [ + "genco-macros", + "relative-path", + "smallvec", +] + +[[package]] +name = "genco-macros" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4cf186fea4af17825116f72932fe52cce9a13bae39ff63b4dc0cfdb3fb4bde1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.53", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -895,6 +1453,18 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash 0.7.8", +] + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash 0.8.11", +] [[package]] name = "hashbrown" @@ -902,7 +1472,7 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" dependencies = [ - "ahash", + "ahash 0.8.11", "allocator-api2", "serde", ] @@ -1033,6 +1603,18 @@ dependencies = [ "tokio", ] +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "0.2.3" @@ -1089,6 +1671,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "indent" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9f1a0777d972970f204fdf8ef319f1f4f8459131636d7e3c96c5d59570d0fa6" + [[package]] name = "indexmap" version = "1.9.3" @@ -1245,6 +1833,16 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "libmimalloc-sys" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81eb4061c0582dedea1cbc7aff2240300dd6982e0239d1c99e65c1dbf4a30ba7" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "libredox" version = "0.0.1" @@ -1272,6 +1870,15 @@ version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +[[package]] +name = "lru" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999beba7b6e8345721bd280141ed958096a2e4abdf74f67ff4ce49b4b54e47a" +dependencies = [ + "hashbrown 0.12.3", +] + [[package]] name = "matches" version = "0.1.10" @@ -1319,6 +1926,15 @@ dependencies = [ "validator", ] +[[package]] +name = "mimalloc" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f41a2280ded0da56c8cf898babb86e8f10651a34adcfff190ae9a1159c6908d" +dependencies = [ + "libmimalloc-sys", +] + [[package]] name = "mime" version = "0.3.17" @@ -1335,6 +1951,12 @@ dependencies = [ "sprs", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.2" @@ -1374,6 +1996,16 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "num-bigint" version = "0.4.4" @@ -1383,6 +2015,7 @@ dependencies = [ "autocfg", "num-integer", "num-traits 0.2.18", + "rand", "serde", ] @@ -1405,6 +2038,46 @@ dependencies = [ "num-traits 0.2.18", ] +[[package]] +name = "num-modular" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a5fe11d4135c3bcdf3a95b18b194afa9608a5f6ff034f5d857bc9a27fb0119" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits 0.2.18", +] + +[[package]] +name = "num-prime" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f4e3bc495f6e95bc15a6c0c55ac00421504a5a43d09e3cc455d1fea7015581d" +dependencies = [ + "bitvec", + "either", + "lru", + "num-bigint", + "num-integer", + "num-modular", + "num-traits 0.2.18", + "rand", +] + +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits 0.2.18", + "serde", +] + [[package]] name = "num-traits" version = "0.1.43" @@ -1549,6 +2222,12 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +[[package]] +name = "path-clean" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17359afc20d7ab31fdb42bb844c8b3bb1dabd7dcf7e68428492da7f16966fcef" + [[package]] name = "percent-encoding" version = "2.3.1" @@ -1565,6 +2244,39 @@ dependencies = [ "indexmap 2.2.5", ] +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn 2.0.53", +] + [[package]] name = "phf_shared" version = "0.10.0" @@ -1574,6 +2286,15 @@ dependencies = [ "siphasher", ] +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + [[package]] name = "pico-args" version = "0.5.0" @@ -1648,12 +2369,11 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "2.0.2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b00f26d3400549137f92511a46ac1cd8ce37cb5598a96d382381458b992a5d24" +checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" dependencies = [ - "toml_datetime", - "toml_edit", + "toml_edit 0.20.2", ] [[package]] @@ -1798,6 +2518,12 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +[[package]] +name = "relative-path" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e898588f33fdd5b9420719948f9f2a32c922a246964576f71ba7f24f80610fbc" + [[package]] name = "rfc6979" version = "0.4.0" @@ -2000,6 +2726,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -2199,7 +2934,7 @@ dependencies = [ [[package]] name = "starknet_api" version = "0.12.0-dev.1" -source = "git+https://github.com/starkware-libs/starknet-api.git?rev=98153e9#98153e99ffe881c93fdc2846485223d4973ead30" +source = "git+https://github.com/starkware-libs/starknet-api.git?rev=1b46b42#1b46b42086f3161738a71f87efb49b62dde4b841" dependencies = [ "cairo-lang-starknet-classes", "derive_more", @@ -2223,6 +2958,7 @@ version = "0.0.0" dependencies = [ "assert_matches", "axum", + "blockifier", "clap", "hyper 1.2.0", "papyrus_config", @@ -2262,10 +2998,16 @@ dependencies = [ "new_debug_unreachable", "once_cell", "parking_lot 0.12.1", - "phf_shared", + "phf_shared 0.10.0", "precomputed-hash", ] +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "strsim" version = "0.11.1" @@ -2375,6 +3117,26 @@ dependencies = [ "syn 2.0.53", ] +[[package]] +name = "thiserror-impl-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58e6318948b519ba6dc2b442a6d0b904ebfb8d411a3ad3e07843615a72249758" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "thiserror-no-std" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3ad459d94dd517257cc96add8a43190ee620011bb6e6cdc82dafd97dfafafea" +dependencies = [ + "thiserror-impl-no-std", +] + [[package]] name = "tiny-keccak" version = "2.0.2" @@ -2429,11 +3191,26 @@ dependencies = [ "syn 2.0.53", ] +[[package]] +name = "toml" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit 0.22.12", +] + [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] [[package]] name = "toml_edit" @@ -2443,7 +3220,20 @@ checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" dependencies = [ "indexmap 2.2.5", "toml_datetime", - "winnow", + "winnow 0.5.40", +] + +[[package]] +name = "toml_edit" +version = "0.22.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef" +dependencies = [ + "indexmap 2.2.5", + "serde", + "serde_spanned", + "toml_datetime", + "winnow 0.6.7", ] [[package]] @@ -2518,6 +3308,15 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "unescaper" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0adf6ad32eb5b3cadff915f7b770faaac8f7ff0476633aa29eb0d9584d889d34" +dependencies = [ + "thiserror", +] + [[package]] name = "unicode-bidi" version = "0.3.15" @@ -2864,6 +3663,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14b9415ee827af173ebb3f15f9083df5a122eb93572ec28741fb153356ea2578" +dependencies = [ + "memchr", +] + [[package]] name = "wyz" version = "0.5.1" @@ -2873,6 +3681,21 @@ dependencies = [ "tap", ] +[[package]] +name = "xshell" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db0ab86eae739efd1b054a8d3d16041914030ac4e01cd1dca0cf252fd8b6437" +dependencies = [ + "xshell-macros", +] + +[[package]] +name = "xshell-macros" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d422e8e38ec76e2f06ee439ccc765e9c6a9638b9e7c9f2e8255e4d41e8bd852" + [[package]] name = "yansi" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 4703fab0..b0357dac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,9 @@ as_conversions = "deny" [workspace.dependencies] assert_matches = "1.5.0" async-trait = "0.1.79" -axum = "0.6.12" +axum = "0.7.5" +# TODO(YaelD, 1/5/2024): Use a fixed version once the StarkNet API is stable. +blockifier = { git = "https://github.com/starkware-libs/blockifier.git", rev = "ba72c863", features = ["testing"] } clap = "4.3.10" derive_more = "0.99" const_format = "0.2.30" @@ -32,7 +34,7 @@ rstest = "0.17.0" serde = { version = "1.0.193", features = ["derive"] } serde_json = "1.0" # TODO(Arni, 1/5/2024): Use a fixed version once the StarkNet API is stable. -starknet_api = { git = "https://github.com/starkware-libs/starknet-api.git", rev = "98153e9" } +starknet_api = { git = "https://github.com/starkware-libs/starknet-api.git", rev = "1b46b42" } thiserror = "1.0" tokio = { version = "1", features = ["full"] } tower = "0.4.13" diff --git a/crates/gateway/Cargo.toml b/crates/gateway/Cargo.toml index 87c3aebc..37c2508c 100644 --- a/crates/gateway/Cargo.toml +++ b/crates/gateway/Cargo.toml @@ -10,6 +10,7 @@ workspace = true [dependencies] axum.workspace = true +blockifier.workspace = true clap.workspace = true hyper.workspace = true papyrus_config.workspace = true diff --git a/crates/gateway/src/errors.rs b/crates/gateway/src/errors.rs index deaa11e1..7bfd7f01 100644 --- a/crates/gateway/src/errors.rs +++ b/crates/gateway/src/errors.rs @@ -1,4 +1,12 @@ -use starknet_api::transaction::{Resource, ResourceBounds}; +use blockifier::{ + blockifier::stateful_validator::StatefulValidatorError, + transaction::errors::TransactionExecutionError, +}; +use starknet_api::{ + block::BlockNumber, + transaction::{Resource, ResourceBounds}, + StarknetApiError, +}; use thiserror::Error; @@ -43,3 +51,17 @@ pub enum StatelessTransactionValidatorError { } pub type StatelessTransactionValidatorResult = Result; + +#[derive(Debug, Error)] +pub enum StatefulTransactionValidatorError { + #[error("Block number {block_number:?} is out of range.")] + OutOfRangeBlockNumber { block_number: BlockNumber }, + #[error(transparent)] + StarknetApiError(#[from] StarknetApiError), + #[error(transparent)] + StatefulValidatorError(#[from] StatefulValidatorError), + #[error(transparent)] + TransactionExecutionError(#[from] TransactionExecutionError), +} + +pub type StatefulTransactionValidatorResult = Result; diff --git a/crates/gateway/src/lib.rs b/crates/gateway/src/lib.rs index 1e07f65e..7676e6e7 100644 --- a/crates/gateway/src/lib.rs +++ b/crates/gateway/src/lib.rs @@ -1,6 +1,7 @@ pub mod errors; pub mod gateway; pub mod starknet_api_test_utils; +pub mod stateful_transaction_validator; pub mod stateless_transaction_validator; pub mod utils; diff --git a/crates/gateway/src/stateful_transaction_validator.rs b/crates/gateway/src/stateful_transaction_validator.rs new file mode 100644 index 00000000..fee3aac9 --- /dev/null +++ b/crates/gateway/src/stateful_transaction_validator.rs @@ -0,0 +1,72 @@ +use blockifier::blockifier::block::BlockInfo; +use blockifier::blockifier::stateful_validator::StatefulValidator as BlockifierStatefulValidator; +use blockifier::bouncer::BouncerConfig; +use blockifier::context::BlockContext; +use blockifier::context::ChainInfo; +use blockifier::execution::contract_class::ClassInfo; +use blockifier::state::cached_state::CachedState; +use blockifier::state::state_api::StateReader; + +use blockifier::versioned_constants::VersionedConstants; +use starknet_api::core::Nonce; +use starknet_api::external_transaction::ExternalTransaction; +use starknet_api::transaction::TransactionHash; + +use crate::errors::StatefulTransactionValidatorError; +use crate::errors::StatefulTransactionValidatorResult; +use crate::utils::external_tx_to_account_tx; + +pub struct StatefulTransactionValidator { + pub config: StatefulTransactionValidatorConfig, +} + +impl StatefulTransactionValidator { + pub fn run_validate( + &self, + // TODO(yael 17/4/24): the state_reader should be created inside the function taking + // latest_block_number. + state_reader: impl StateReader, + //TODO(yael 17/4/24): the latest_block_info should be read from the storage. + latest_block_info: BlockInfo, + external_tx: &ExternalTransaction, + deploy_account_tx_hash: Option, + optional_class_info: Option, + ) -> StatefulTransactionValidatorResult<()> { + let state = CachedState::new(state_reader); + let versioned_constants = VersionedConstants::latest_constants_with_overrides( + self.config.validate_max_n_steps, + self.config.max_recursion_depth, + ); + let mut block_info = latest_block_info; + block_info.block_number = block_info.block_number.next().ok_or( + StatefulTransactionValidatorError::OutOfRangeBlockNumber { + block_number: block_info.block_number, + }, + )?; + // TODO(yael 21/4/24): create the block context using pre_process_block once we will be + // able to read the block_hash of 10 blocks ago from papyrus. + let block_context = + BlockContext::new_unchecked(&block_info, &self.config.chain_info, &versioned_constants); + + let mut validator = BlockifierStatefulValidator::create( + state, + block_context, + self.config.max_nonce_for_validation_skip, + BouncerConfig::max(), + ); + let account_tx = external_tx_to_account_tx( + external_tx, + optional_class_info, + &self.config.chain_info.chain_id, + )?; + validator.perform_validations(account_tx, deploy_account_tx_hash)?; + Ok(()) + } +} + +pub struct StatefulTransactionValidatorConfig { + pub max_nonce_for_validation_skip: Nonce, + pub validate_max_n_steps: u32, + pub max_recursion_depth: usize, + pub chain_info: ChainInfo, +} diff --git a/crates/gateway/src/utils.rs b/crates/gateway/src/utils.rs index b26ae0ae..8c1f7b91 100644 --- a/crates/gateway/src/utils.rs +++ b/crates/gateway/src/utils.rs @@ -1,4 +1,21 @@ -use starknet_api::external_transaction::ExternalTransaction; +use crate::errors::StatefulTransactionValidatorResult; +use blockifier::execution::contract_class::ClassInfo; +use blockifier::transaction::account_transaction::AccountTransaction; +use blockifier::transaction::transactions::DeclareTransaction as BlockifierDeclareTransaction; +use blockifier::transaction::transactions::DeployAccountTransaction as BlockifierDeployAccountTransaction; +use blockifier::transaction::transactions::InvokeTransaction as BlockifierInvokeTransaction; +use starknet_api::core::ChainId; +use starknet_api::core::{calculate_contract_address, ClassHash, ContractAddress}; +use starknet_api::external_transaction::{ + ExternalDeclareTransaction, ExternalDeployAccountTransaction, ExternalInvokeTransaction, + ExternalTransaction, +}; +use starknet_api::transaction::DeclareTransaction; +use starknet_api::transaction::TransactionHasher; +use starknet_api::transaction::{ + DeclareTransactionV3, DeployAccountTransaction, DeployAccountTransactionV3, InvokeTransaction, + InvokeTransactionV3, +}; use starknet_api::transaction::{ResourceBoundsMapping, TransactionSignature}; macro_rules! implement_ref_getters { @@ -31,3 +48,78 @@ pub trait ExternalTransactionExt { fn resource_bounds(&self) -> &ResourceBoundsMapping; fn signature(&self) -> &TransactionSignature; } + +pub fn external_tx_to_account_tx( + external_tx: &ExternalTransaction, + //FIXME(yael 15/4/24): calculate class_info inside the function once compilation code is ready + optional_class_info: Option, + chain_id: &ChainId, +) -> StatefulTransactionValidatorResult { + match external_tx { + ExternalTransaction::Declare(ExternalDeclareTransaction::V3(tx)) => { + let declare_tx = DeclareTransaction::V3(DeclareTransactionV3 { + class_hash: ClassHash::default(), //FIXME(yael 15/4/24): call the starknet-api function once ready + resource_bounds: tx.resource_bounds.clone(), + tip: tx.tip, + signature: tx.signature.clone(), + nonce: tx.nonce, + compiled_class_hash: tx.compiled_class_hash, + sender_address: tx.sender_address, + nonce_data_availability_mode: tx.nonce_data_availability_mode, + fee_data_availability_mode: tx.fee_data_availability_mode, + paymaster_data: tx.paymaster_data.clone(), + account_deployment_data: tx.account_deployment_data.clone(), + }); + let tx_hash = declare_tx.calculate_transaction_hash(chain_id, &declare_tx.version())?; + let class_info = + optional_class_info.expect("declare transaction should contain class info"); + let declare_tx = BlockifierDeclareTransaction::new(declare_tx, tx_hash, class_info)?; + Ok(AccountTransaction::Declare(declare_tx)) + } + ExternalTransaction::DeployAccount(ExternalDeployAccountTransaction::V3(tx)) => { + let deploy_account_tx = DeployAccountTransaction::V3(DeployAccountTransactionV3 { + resource_bounds: tx.resource_bounds.clone(), + tip: tx.tip, + signature: tx.signature.clone(), + nonce: tx.nonce, + class_hash: tx.class_hash, + contract_address_salt: tx.contract_address_salt, + constructor_calldata: tx.constructor_calldata.clone(), + nonce_data_availability_mode: tx.nonce_data_availability_mode, + fee_data_availability_mode: tx.fee_data_availability_mode, + paymaster_data: tx.paymaster_data.clone(), + }); + let contract_address = calculate_contract_address( + deploy_account_tx.contract_address_salt(), + deploy_account_tx.class_hash(), + &deploy_account_tx.constructor_calldata(), + ContractAddress::default(), + )?; + let tx_hash = deploy_account_tx + .calculate_transaction_hash(chain_id, &deploy_account_tx.version())?; + let deploy_account_tx = BlockifierDeployAccountTransaction::new( + deploy_account_tx, + tx_hash, + contract_address, + ); + Ok(AccountTransaction::DeployAccount(deploy_account_tx)) + } + ExternalTransaction::Invoke(ExternalInvokeTransaction::V3(tx)) => { + let invoke_tx = InvokeTransaction::V3(InvokeTransactionV3 { + resource_bounds: tx.resource_bounds.clone(), + tip: tx.tip, + signature: tx.signature.clone(), + nonce: tx.nonce, + sender_address: tx.sender_address, + calldata: tx.calldata.clone(), + nonce_data_availability_mode: tx.nonce_data_availability_mode, + fee_data_availability_mode: tx.fee_data_availability_mode, + paymaster_data: tx.paymaster_data.clone(), + account_deployment_data: tx.account_deployment_data.clone(), + }); + let tx_hash = invoke_tx.calculate_transaction_hash(chain_id, &invoke_tx.version())?; + let invoke_tx = BlockifierInvokeTransaction::new(invoke_tx, tx_hash); + Ok(AccountTransaction::Invoke(invoke_tx)) + } + } +}