diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 01fbf74..ab1d62f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-11] + os: [ubuntu-latest, macos-latest] toolchain: [stable, nightly] steps: diff --git a/Cargo.lock b/Cargo.lock index e6a55b0..25aed90 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" dependencies = [ "gimli", ] @@ -54,47 +54,48 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.13" +version = "0.6.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", + "is_terminal_polyfill", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" [[package]] name = "anstyle-parse" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.2" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" dependencies = [ "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.2" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" dependencies = [ "anstyle", "windows-sys 0.52.0", @@ -102,73 +103,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" - -[[package]] -name = "ark-ff" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" -dependencies = [ - "ark-ff-asm", - "ark-ff-macros", - "ark-serialize", - "ark-std", - "derivative", - "digest", - "itertools", - "num-bigint", - "num-traits", - "paste", - "rustc_version", - "zeroize", -] - -[[package]] -name = "ark-ff-asm" -version = "0.4.2" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" -dependencies = [ - "quote", - "syn 1.0.109", -] - -[[package]] -name = "ark-ff-macros" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" -dependencies = [ - "num-bigint", - "num-traits", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "ark-serialize" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" -dependencies = [ - "ark-std", - "digest", - "num-bigint", -] - -[[package]] -name = "ark-std" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" -dependencies = [ - "num-traits", - "rand", -] +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "arrayvec" @@ -184,7 +121,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.68", ] [[package]] @@ -195,20 +132,20 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.68", ] [[package]] name = "autocfg" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" -version = "0.3.71" +version = "0.3.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" dependencies = [ "addr2line", "cc", @@ -232,22 +169,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] -name = "bigdecimal" -version = "0.3.1" +name = "bitflags" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6773ddc0eafc0e509fb60e48dff7f450f8e674a0686ae8605e8d9901bd5eefa" -dependencies = [ - "num-bigint", - "num-integer", - "num-traits", - "serde", -] +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "1.3.2" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "bitvec" @@ -311,6 +242,7 @@ dependencies = [ "serde", "serde_json", "starknet", + "starknet-types-core", "thiserror", "tokio", "tracing", @@ -335,7 +267,7 @@ dependencies = [ "quote", "serde_json", "starknet", - "syn 2.0.60", + "syn 2.0.68", "thiserror", ] @@ -352,7 +284,7 @@ dependencies = [ "quote", "serde_json", "starknet", - "syn 2.0.60", + "syn 2.0.68", "thiserror", ] @@ -368,24 +300,24 @@ dependencies = [ "quote", "serde_json", "starknet", - "syn 2.0.60", + "syn 2.0.68", "thiserror", ] [[package]] name = "camino" -version = "1.1.6" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c59e92b5a388f549b863a7bea62612c09f24c8393560709a54558a9abdfb3b9c" +checksum = "e0ec6b951b160caa93cc0c7b209e5a3bff7aae9062213451ac99493cd844c239" dependencies = [ "serde", ] [[package]] name = "cc" -version = "1.0.95" +version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b" +checksum = "74b6a57f98764a267ff415d50a25e6e166f3831a5071af4995296ea97d210490" [[package]] name = "cfg-if" @@ -418,9 +350,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.4" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +checksum = "84b3edb18336f4df585bc9aa31dd99c036dfa5dc5e9a2939a722a188f3a8970d" dependencies = [ "clap_builder", "clap_derive", @@ -428,48 +360,48 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.2" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +checksum = "c1c09dd5ada6c6c78075d6fd0da3f90d8080651e2d6cc8eb2f1aaa4034ced708" dependencies = [ "anstream", "anstyle", "clap_lex", - "strsim 0.11.1", + "strsim", ] [[package]] name = "clap_complete" -version = "4.5.2" +version = "4.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd79504325bf38b10165b02e89b4347300f855f273c4cb30c4a3209e6583275e" +checksum = "1d598e88f6874d4b888ed40c71efbcbf4076f1dfbae128a08a8c9e45f710605d" dependencies = [ "clap", ] [[package]] name = "clap_derive" -version = "4.5.4" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.68", ] [[package]] name = "clap_lex" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" [[package]] name = "colorchoice" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" [[package]] name = "convert_case" @@ -507,9 +439,9 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.4.0" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" dependencies = [ "cfg-if", ] @@ -552,9 +484,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.20.8" +version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54e36fcd13ed84ffdfda6f5be89b31287cbb80c439841fe69e04841435464391" +checksum = "83b2eb4d90d12bdda5ed17de686c2acb4c57914f8f921b8da7e112b5a36f3fe1" dependencies = [ "darling_core", "darling_macro", @@ -562,27 +494,27 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.8" +version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c2cf1c23a687a1feeb728783b993c4e1ad83d99f351801977dd809b48d0a70f" +checksum = "622687fe0bac72a04e5599029151f5796111b90f1baaa9b544d807a5e31cd120" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", - "strsim 0.10.0", - "syn 2.0.60", + "strsim", + "syn 2.0.68", ] [[package]] name = "darling_macro" -version = "0.20.8" +version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" +checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178" dependencies = [ "darling_core", "quote", - "syn 2.0.60", + "syn 2.0.68", ] [[package]] @@ -595,17 +527,6 @@ dependencies = [ "serde", ] -[[package]] -name = "derivative" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "digest" version = "0.10.7" @@ -617,12 +538,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "either" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" - [[package]] name = "encoding_rs" version = "0.8.34" @@ -701,9 +616,9 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.28" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" dependencies = [ "crc32fast", "miniz_oxide", @@ -781,9 +696,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "js-sys", @@ -794,9 +709,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.1" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "h2" @@ -825,9 +740,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "heck" @@ -880,9 +795,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.8.0" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" [[package]] name = "httpdate" @@ -892,9 +807,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "0.14.28" +version = "0.14.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" +checksum = "f361cde2f109281a220d4307746cdfd5ee3f410da58a70377762396775634b33" dependencies = [ "bytes", "futures-channel", @@ -1023,7 +938,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown 0.14.3", + "hashbrown 0.14.5", ] [[package]] @@ -1042,13 +957,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] -name = "itertools" -version = "0.10.5" +name = "is_terminal_polyfill" +version = "1.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" [[package]] name = "itoa" @@ -1074,23 +986,45 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "lambdaworks-crypto" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fb5d4f22241504f7c7b8d2c3a7d7835d7c07117f10bff2a7d96a9ef6ef217c3" +dependencies = [ + "lambdaworks-math", + "serde", + "sha2", + "sha3", +] + +[[package]] +name = "lambdaworks-math" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "358e172628e713b80a530a59654154bfc45783a6ed70ea284839800cebdf8f97" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -1098,9 +1032,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.21" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "matchers" @@ -1113,9 +1047,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "mime" @@ -1125,9 +1059,9 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" dependencies = [ "adler", ] @@ -1155,11 +1089,10 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.4" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ - "autocfg", "num-integer", "num-traits", ] @@ -1181,9 +1114,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -1200,9 +1133,9 @@ dependencies = [ [[package]] name = "object" -version = "0.32.2" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce" dependencies = [ "memchr", ] @@ -1221,9 +1154,9 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "parity-scale-codec" -version = "3.6.9" +version = "3.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "881331e34fa842a2fb61cc2db9643a8fedc615e47cfcc52597d1af0db9a7e8fe" +checksum = "306800abfa29c7f16596b5970a588435e3d5b3149683d00c12b699cc19f895ee" dependencies = [ "arrayvec", "bitvec", @@ -1235,9 +1168,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.6.9" +version = "3.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be30eaf4b0a9fba5336683b38de57bb86d179a35862ba6bfcf57625d006bde5b" +checksum = "d830939c76d294956402033aee57a6da7b438f2294eb94864c37b0569053a42c" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1247,9 +1180,9 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", "parking_lot_core", @@ -1257,23 +1190,17 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-targets 0.48.5", + "windows-targets 0.52.5", ] -[[package]] -name = "paste" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" - [[package]] name = "pbkdf2" version = "0.11.0" @@ -1315,12 +1242,12 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "prettyplease" -version = "0.2.19" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ac2cf0f2e4f42b49f5ffd07dae8d746508ef7526c13940e5f524012ae6c6550" +checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" dependencies = [ "proc-macro2", - "syn 2.0.60", + "syn 2.0.68", ] [[package]] @@ -1338,19 +1265,18 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "2.0.2" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b00f26d3400549137f92511a46ac1cd8ce37cb5598a96d382381458b992a5d24" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" dependencies = [ - "toml_datetime", "toml_edit", ] [[package]] name = "proc-macro2" -version = "1.0.81" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -1402,23 +1328,23 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" dependencies = [ - "bitflags", + "bitflags 2.6.0", ] [[package]] name = "regex" -version = "1.10.4" +version = "1.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.6", - "regex-syntax 0.8.3", + "regex-automata 0.4.7", + "regex-syntax 0.8.4", ] [[package]] @@ -1432,13 +1358,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.3", + "regex-syntax 0.8.4", ] [[package]] @@ -1449,9 +1375,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "reqwest" @@ -1531,9 +1457,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc-hex" @@ -1541,20 +1467,11 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver", -] - [[package]] name = "rustls" -version = "0.21.11" +version = "0.21.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fecbfb7b1444f477b345853b1fce097a2c6fb637b2bfb87e6bc5db0f043fae4" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", "ring", @@ -1583,9 +1500,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "salsa20" @@ -1624,37 +1541,31 @@ dependencies = [ "untrusted", ] -[[package]] -name = "semver" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" - [[package]] name = "serde" -version = "1.0.198" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.198" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.68", ] [[package]] name = "serde_json" -version = "1.0.116" +version = "1.0.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" +checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" dependencies = [ "itoa", "ryu", @@ -1709,7 +1620,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.68", ] [[package]] @@ -1768,9 +1679,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", "windows-sys 0.52.0", @@ -1784,15 +1695,14 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "starknet" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20b9a7b7bfd87287af85854f7458b8170ba6aa59c39113436532b7ff3d2fcbd8" +checksum = "1e633a772f59214c296d5037c95c36b72792c9360323818da2b625c7b4ec4b49" dependencies = [ "starknet-accounts", "starknet-contract", "starknet-core", - "starknet-crypto", - "starknet-ff", + "starknet-crypto 0.7.1", "starknet-macros", "starknet-providers", "starknet-signers", @@ -1800,13 +1710,14 @@ dependencies = [ [[package]] name = "starknet-accounts" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2095d7584608ae1707bd1cf2889368ab3734d9f54e4fcef4765cba1f3b3f7618" +checksum = "eee8a6b588a22c7e79f5d8d4e33413387db63a8beb98be8610138541794cc0a5" dependencies = [ "async-trait", "auto_impl", "starknet-core", + "starknet-crypto 0.7.1", "starknet-providers", "starknet-signers", "thiserror", @@ -1814,9 +1725,9 @@ dependencies = [ [[package]] name = "starknet-contract" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb3b73d437b4d62241612d13fce612602de6684c149cccf696e76a20757e2156" +checksum = "a5f91344f1e0b81873b6dc235c50ae4d084c6ea4dd4a1e3e27ad895803adb610" dependencies = [ "serde", "serde_json", @@ -1829,11 +1740,11 @@ dependencies = [ [[package]] name = "starknet-core" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ed286d637e34fb8ae1cd2f9615120ec8ff38d1cffd311ed7fdd497cdd2bd01f" +version = "0.11.1" +source = "git+https://github.com/kariy/starknet-rs?rev=fffe8e9#fffe8e9af69e73ac5a0925fe49266aa9198fff4a" dependencies = [ "base64 0.21.7", + "crypto-bigint", "flate2", "hex", "serde", @@ -1841,15 +1752,34 @@ dependencies = [ "serde_json_pythonic", "serde_with", "sha3", - "starknet-crypto", - "starknet-ff", + "starknet-crypto 0.7.0", + "starknet-types-core", ] [[package]] name = "starknet-crypto" -version = "0.6.2" +version = "0.7.0" +source = "git+https://github.com/kariy/starknet-rs?rev=fffe8e9#fffe8e9af69e73ac5a0925fe49266aa9198fff4a" +dependencies = [ + "crypto-bigint", + "hex", + "hmac", + "num-bigint", + "num-integer", + "num-traits", + "rfc6979", + "sha2", + "starknet-crypto-codegen 0.4.0 (git+https://github.com/kariy/starknet-rs?rev=fffe8e9)", + "starknet-curve 0.5.0 (git+https://github.com/kariy/starknet-rs?rev=fffe8e9)", + "starknet-types-core", + "zeroize", +] + +[[package]] +name = "starknet-crypto" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e2c30c01e8eb0fc913c4ee3cf676389fffc1d1182bfe5bb9670e4e72e968064" +checksum = "ff2a821ad8d98c6c3e4d0e5097f3fe6e2ed120ada9d32be87cd1330c7923a2f0" dependencies = [ "crypto-bigint", "hex", @@ -1859,67 +1789,71 @@ dependencies = [ "num-traits", "rfc6979", "sha2", - "starknet-crypto-codegen", - "starknet-curve", - "starknet-ff", + "starknet-crypto-codegen 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-curve 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-types-core", "zeroize", ] [[package]] name = "starknet-crypto-codegen" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbc159a1934c7be9761c237333a57febe060ace2bc9e3b337a59a37af206d19f" +checksum = "2e179dedc3fa6da064e56811d3e05d446aa2f7459e4eb0e3e49378a337235437" dependencies = [ - "starknet-curve", - "starknet-ff", - "syn 2.0.60", + "starknet-curve 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-types-core", + "syn 2.0.68", +] + +[[package]] +name = "starknet-crypto-codegen" +version = "0.4.0" +source = "git+https://github.com/kariy/starknet-rs?rev=fffe8e9#fffe8e9af69e73ac5a0925fe49266aa9198fff4a" +dependencies = [ + "starknet-curve 0.5.0 (git+https://github.com/kariy/starknet-rs?rev=fffe8e9)", + "starknet-types-core", + "syn 2.0.68", ] [[package]] name = "starknet-curve" -version = "0.4.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1c383518bb312751e4be80f53e8644034aa99a0afb29d7ac41b89a997db875b" +checksum = "56935b306dcf0b8f14bb2a1257164b8478bb8be4801dfae0923f5b266d1b457c" dependencies = [ - "starknet-ff", + "starknet-types-core", ] [[package]] -name = "starknet-ff" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7abf1b44ec5b18d87c1ae5f54590ca9d0699ef4dd5b2ffa66fc97f24613ec585" +name = "starknet-curve" +version = "0.5.0" +source = "git+https://github.com/kariy/starknet-rs?rev=fffe8e9#fffe8e9af69e73ac5a0925fe49266aa9198fff4a" dependencies = [ - "ark-ff", - "bigdecimal", - "crypto-bigint", - "getrandom", - "hex", - "num-bigint", - "serde", + "starknet-types-core", ] [[package]] name = "starknet-macros" -version = "0.1.7" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95d549d3078bdbe775d0deaa8ddb57a19942989ce7c1f2dfd60beeb322bb4945" +checksum = "f4fe4f8d615329410578cbedcdbaa4a36c7f28f68c3f3ac56006cfbdaeaa2b41" dependencies = [ "starknet-core", - "syn 2.0.60", + "syn 2.0.68", ] [[package]] name = "starknet-providers" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6abf40ffcbe3b887b4d5cfc8ab73170c816b4aa78d1d4ad59abd3fb3b0f53cd" +checksum = "59c85e0a0f4563ae95dfeae14ea0f0c70610efc0ec2462505c64eff5765e7b97" dependencies = [ "async-trait", "auto_impl", "ethereum-types", "flate2", + "getrandom", "log", "reqwest", "serde", @@ -1932,31 +1866,40 @@ dependencies = [ [[package]] name = "starknet-signers" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e9a2bd4fd66090003c3b7f0d76476e5b63cd44f6a49ede2442673f4427d5a40" +checksum = "c17da2139119dbe3aacf1d5d4338798a5c489d17f424916ceb9d2efd83554f87" dependencies = [ "async-trait", "auto_impl", "crypto-bigint", "eth-keystore", + "getrandom", "rand", "starknet-core", - "starknet-crypto", + "starknet-crypto 0.7.1", "thiserror", ] [[package]] -name = "static_assertions" -version = "1.1.0" +name = "starknet-types-core" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +checksum = "ce6bacf0ba19bc721e518bc4bf389ff13daa8a7c5db5fd320600473b8aa9fcbd" +dependencies = [ + "lambdaworks-crypto", + "lambdaworks-math", + "num-bigint", + "num-integer", + "num-traits", + "serde", +] [[package]] -name = "strsim" -version = "0.10.0" +name = "static_assertions" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "strsim" @@ -1966,9 +1909,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "subtle" -version = "2.5.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" @@ -1983,9 +1926,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.60" +version = "2.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" dependencies = [ "proc-macro2", "quote", @@ -2004,7 +1947,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "system-configuration-sys", ] @@ -2027,22 +1970,22 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "thiserror" -version = "1.0.59" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.59" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.68", ] [[package]] @@ -2097,9 +2040,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "c55115c6fbe2d2bef26eb09ad74bde02d8255476fc0c7b515ef09fbb35742d82" dependencies = [ "tinyvec_macros", ] @@ -2112,9 +2055,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.37.0" +version = "1.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" dependencies = [ "backtrace", "bytes", @@ -2131,13 +2074,13 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.68", ] [[package]] @@ -2152,29 +2095,28 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" dependencies = [ "bytes", "futures-core", "futures-sink", "pin-project-lite", "tokio", - "tracing", ] [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" [[package]] name = "toml_edit" -version = "0.20.2" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ "indexmap 2.2.6", "toml_datetime", @@ -2206,7 +2148,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.68", ] [[package]] @@ -2320,9 +2262,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.5.0" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" dependencies = [ "form_urlencoded", "idna", @@ -2331,9 +2273,9 @@ dependencies = [ [[package]] name = "utf8parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" @@ -2393,7 +2335,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.68", "wasm-bindgen-shared", ] @@ -2427,7 +2369,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.68", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2654,20 +2596,6 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63381fa6624bf92130a6b87c0d07380116f80b565c42cf0d754136f0238359ef" -dependencies = [ - "zeroize_derive", -] - -[[package]] -name = "zeroize_derive" -version = "1.4.2" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.60", -] +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/Cargo.toml b/Cargo.toml index 496489e..670bb9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,11 +23,13 @@ camino = { version = "1.1.2", features = [ "serde1" ] } convert_case = "0.6.0" serde = { version = "1.0", default-features = false, features = ["alloc"] } serde_json = { version = "1.0", default-features = false, features = ["std"] } -starknet = "0.10.0" thiserror = "1.0" tracing = "0.1.34" tracing-subscriber = { version = "0.3.16", features = [ "env-filter", "json" ] } url = "2.4.0" +starknet = "0.11.0" +# This version ensures `Felt` can be converted using `FromStr` for command line parsing. +starknet-types-core = ">=0.1.4" [dependencies] camino.workspace = true @@ -44,12 +46,18 @@ convert_case.workspace = true serde.workspace = true serde_json.workspace = true starknet.workspace = true +starknet-types-core.workspace = true thiserror.workspace = true tracing.workspace = true tracing-subscriber.workspace = true url.workspace = true tokio = { version = "1.15.0", features = ["full"], optional = true } +[patch.crates-io] +# Remove this patch once the following PR is merged: +# To enable std feature on `starknet-types-core`. +starknet-core = { git = "https://github.com/kariy/starknet-rs", rev = "fffe8e9" } + [features] default = [] abigen-rs = ["cainome-rs-macro"] diff --git a/README.md b/README.md index 800396a..52ebe0b 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ for different languages (backends). - **cli**: inside `src/bin/cli`, the cainome CLI binary can be built using `cargo build`: [README](./src/bin/cli/README.md). - **lib**: inside `src/lib.rs`, the cainome library can be built using `cargo build --lib`. - **parser**: a run-time library to parse an ABI file into `Token`s [README](./crates/parser/README.md). -- **cairo-serde**: a compile-time library that implements serialization for native Rust types from `FieldElement` buffer [README](./crates/cairo-serde/README.md). +- **cairo-serde**: a compile-time library that implements serialization for native Rust types from `Felt` buffer [README](./crates/cairo-serde/README.md). - **rs-macro**: a compile-time library backend for the `abigen` macro to generate rust bindings [README](./crates/rs-macro/README.md). - **rs**: a a run-time library to generated rust bindings [README](./crates/rs/README.md). - **ts**: a compile-time library backend to generate `TypeScript` bindings (coming soon). diff --git a/crates/cairo-serde/README.md b/crates/cairo-serde/README.md index dc25646..fef299e 100644 --- a/crates/cairo-serde/README.md +++ b/crates/cairo-serde/README.md @@ -1,7 +1,7 @@ # Cairo Serde Cairo serde is a compile-time library that implement a trait `CairoSerde` on Rust native types. -By implementing this trait, the Rust type becomes (de)serializable from / into an array of `FieldElement`. +By implementing this trait, the Rust type becomes (de)serializable from / into an array of `Felt`. ## Built-in types @@ -27,7 +27,7 @@ All those types, even if they are represented in the ABI as an `enum` or a `stru Cairo Serde provides serialization support for the following types: - `boolean` -> `bool`. -- `felt252` -> `starknet::core::types::FieldElement`. +- `felt252` -> `starknet::core::types::Felt`. - `integers (signed and unsigned)` -> `u[8,16,32,64,128], i[8,16,32,64,128], usize`. - `Option` -> `Option` - `Result` -> `Result` @@ -48,8 +48,8 @@ pub trait CairoSerde { type RustType; fn serialized_size(_rust: &Self::RustType) -> usize; - fn serialize(rust: &Self::RustType) -> Vec; - fn deserialize(felts: &[FieldElement], offset: usize) -> Result; + fn serialize(rust: &Self::RustType) -> Vec; + fn deserialize(felts: &[Felt], offset: usize) -> Result; } ``` @@ -57,8 +57,8 @@ For now, while using the `deserilialize` method, you must provide the index in t Some work that is in the roadmap: -- Adding a `serialize_to(rust: &Self::RustType, out: &mut Vec)` to avoid allocating a new array for each type in a big felt buffer. -- Adding/modifying to `deserialize(felts: &[FieldElement]) -> Result` without the offset using rust slice. The motivation of using an explicit offset in the first version was to keep the context of the current deserialization operation in the global buffer. +- Adding a `serialize_to(rust: &Self::RustType, out: &mut Vec)` to avoid allocating a new array for each type in a big felt buffer. +- Adding/modifying to `deserialize(felts: &[Felt]) -> Result` without the offset using rust slice. The motivation of using an explicit offset in the first version was to keep the context of the current deserialization operation in the global buffer. ## Examples @@ -66,7 +66,7 @@ Some work that is in the roadmap: # Array/Span # The length is automatically inserted as the first element of the `Vec` -# and all the values are converted into `FieldElement`. +# and all the values are converted into `Felt`. let v: Vec = vec![1, 2, 3]; let felts = Vec::::serialize(&v); @@ -80,21 +80,21 @@ let values = Vec::::deserialize(&felts, 0).unwrap(); let o: Option = None; let felts = Option::::serialize(&o); -let felts = vec![FieldElement::ONE]; +let felts = vec![Felt::ONE]; let o = Option::::deserialize(&felts, 0).unwrap(); let o = Some(u32::MAX); let felts = Option::::serialize(&o); -let felts = vec![FieldElement::ZERO, FieldElement::from(u32::MAX)]; +let felts = vec![Felt::ZERO, Felt::from(u32::MAX)]; let o = Option::::deserialize(&felts, 0).unwrap(); ``` ```rust # Tuples -let v = (FieldElement::ONE, 128_u32); -let felts = <(FieldElement, u32)>::serialize(&v); +let v = (Felt::ONE, 128_u32); +let felts = <(Felt, u32)>::serialize(&v); -let felts = vec![FieldElement::THREE, 99_u32.into()]; -let vals = <(FieldElement, u32)>::deserialize(&felts, 0).unwrap(); +let felts = vec![Felt::THREE, 99_u32.into()]; +let vals = <(Felt, u32)>::deserialize(&felts, 0).unwrap(); ``` diff --git a/crates/cairo-serde/src/call.rs b/crates/cairo-serde/src/call.rs index 9c10b92..310bfa2 100644 --- a/crates/cairo-serde/src/call.rs +++ b/crates/cairo-serde/src/call.rs @@ -44,7 +44,7 @@ where T::cairo_deserialize(&r, 0) } - pub async fn raw_call(self) -> CairoResult> { + pub async fn raw_call(self) -> CairoResult> { self.provider .call(self.call_raw, self.block_id) .await diff --git a/crates/cairo-serde/src/error.rs b/crates/cairo-serde/src/error.rs index 62f689c..593069d 100644 --- a/crates/cairo-serde/src/error.rs +++ b/crates/cairo-serde/src/error.rs @@ -1,7 +1,6 @@ use super::CairoSerde; -use starknet::core::types::FieldElement; -use starknet::providers::ProviderError; +use starknet::{core::types::Felt, providers::ProviderError}; /// Cairo types result. pub type Result = core::result::Result; @@ -26,11 +25,11 @@ pub enum Error { impl CairoSerde for Error { type RustType = Self; - fn cairo_serialize(_rust: &Self::RustType) -> Vec { + fn cairo_serialize(_rust: &Self::RustType) -> Vec { vec![] } - fn cairo_deserialize(_felts: &[FieldElement], _offset: usize) -> Result { + fn cairo_deserialize(_felts: &[Felt], _offset: usize) -> Result { Ok(Error::Deserialize( "Error cairotype deserialized?".to_string(), )) diff --git a/crates/cairo-serde/src/lib.rs b/crates/cairo-serde/src/lib.rs index 73de809..0af9932 100644 --- a/crates/cairo-serde/src/lib.rs +++ b/crates/cairo-serde/src/lib.rs @@ -1,5 +1,5 @@ //! This crate contains the definition of traits and types -//! that map to Cairo types that can then be (de)serializable from an array of `FieldElement`. +//! that map to Cairo types that can then be (de)serializable from an array of `Felt`. //! //! Some of the Cairo types are provided in the ABI event if they are very generic //! like `Option`, `Result`, etc... @@ -18,7 +18,7 @@ pub use types::starknet::*; pub use types::u256::*; pub use types::*; -use ::starknet::core::types::FieldElement; +use ::starknet::core::types::Felt; /// Basic cairo structs that are already implemented inside /// this crate and hence skipped during ABI generation. @@ -56,12 +56,12 @@ pub trait CairoSerde { Self::SERIALIZED_SIZE.unwrap() } - /// Serializes the given type into a FieldElement sequence. - fn cairo_serialize(rust: &Self::RustType) -> Vec; + /// Serializes the given type into a Felt sequence. + fn cairo_serialize(rust: &Self::RustType) -> Vec; - /// TODO: add `serialize_to(rust: &Self::RustType, out: &mut Vec)`. + /// TODO: add `serialize_to(rust: &Self::RustType, out: &mut Vec)`. /// for large buffers optimization. /// Deserializes an array of felts into the given type. - fn cairo_deserialize(felts: &[FieldElement], offset: usize) -> Result; + fn cairo_deserialize(felts: &[Felt], offset: usize) -> Result; } diff --git a/crates/cairo-serde/src/types/array.rs b/crates/cairo-serde/src/types/array.rs index c4b5063..d7afb72 100644 --- a/crates/cairo-serde/src/types/array.rs +++ b/crates/cairo-serde/src/types/array.rs @@ -1,7 +1,7 @@ //! CairoSerde implementation for `Vec`. //! They are used for Array and Span cairo types. use crate::{CairoSerde, Error, Result}; -use starknet::core::types::FieldElement; +use starknet::core::types::Felt; impl CairoSerde for Vec where @@ -18,13 +18,13 @@ where 1 + data.iter().map(T::cairo_serialized_size).sum::() } - fn cairo_serialize(rust: &Self::RustType) -> Vec { - let mut out: Vec = vec![rust.len().into()]; + fn cairo_serialize(rust: &Self::RustType) -> Vec { + let mut out: Vec = vec![rust.len().into()]; rust.iter().for_each(|r| out.extend(T::cairo_serialize(r))); out } - fn cairo_deserialize(felts: &[FieldElement], offset: usize) -> Result { + fn cairo_deserialize(felts: &[Felt], offset: usize) -> Result { if offset >= felts.len() { return Err(Error::Deserialize(format!( "Buffer too short to deserialize an array: offset ({}) : buffer {:?}", @@ -70,19 +70,15 @@ mod tests { let v: Vec = vec![1, 2, 3]; let felts = Vec::::cairo_serialize(&v); assert_eq!(felts.len(), 4); - assert_eq!(felts[0], FieldElement::from(3_u32)); - assert_eq!(felts[1], FieldElement::ONE); - assert_eq!(felts[2], FieldElement::TWO); - assert_eq!(felts[3], FieldElement::THREE); + assert_eq!(felts[0], Felt::from(3_u32)); + assert_eq!(felts[1], Felt::ONE); + assert_eq!(felts[2], Felt::TWO); + assert_eq!(felts[3], Felt::THREE); } #[test] fn test_deserialize_array() { - let felts: Vec = vec![ - FieldElement::from(2_u32), - FieldElement::from(123_u32), - FieldElement::from(9988_u32), - ]; + let felts: Vec = vec![Felt::from(2_u32), Felt::from(123_u32), Felt::from(9988_u32)]; let vals = Vec::::cairo_deserialize(&felts, 0).unwrap(); assert_eq!(vals.len(), 2); @@ -95,23 +91,23 @@ mod tests { let v: Vec> = vec![vec![1, 2], vec![3]]; let felts = Vec::>::cairo_serialize(&v); assert_eq!(felts.len(), 6); - assert_eq!(felts[0], FieldElement::TWO); - assert_eq!(felts[1], FieldElement::TWO); - assert_eq!(felts[2], FieldElement::ONE); - assert_eq!(felts[3], FieldElement::TWO); - assert_eq!(felts[4], FieldElement::ONE); - assert_eq!(felts[5], FieldElement::THREE); + assert_eq!(felts[0], Felt::TWO); + assert_eq!(felts[1], Felt::TWO); + assert_eq!(felts[2], Felt::ONE); + assert_eq!(felts[3], Felt::TWO); + assert_eq!(felts[4], Felt::ONE); + assert_eq!(felts[5], Felt::THREE); } #[test] fn test_deserialize_array_nested() { - let felts: Vec = vec![ - FieldElement::TWO, - FieldElement::TWO, - FieldElement::ONE, - FieldElement::TWO, - FieldElement::ONE, - FieldElement::THREE, + let felts: Vec = vec![ + Felt::TWO, + Felt::TWO, + Felt::ONE, + Felt::TWO, + Felt::ONE, + Felt::THREE, ]; let vals = Vec::>::cairo_deserialize(&felts, 0).unwrap(); @@ -122,24 +118,20 @@ mod tests { #[test] fn test_serialize_array_tuple() { - let v: Vec<(u32, FieldElement)> = vec![(12, FieldElement::TWO)]; - let felts = Vec::<(u32, FieldElement)>::cairo_serialize(&v); + let v: Vec<(u32, Felt)> = vec![(12, Felt::TWO)]; + let felts = Vec::<(u32, Felt)>::cairo_serialize(&v); assert_eq!(felts.len(), 3); - assert_eq!(felts[0], FieldElement::from(1_u32)); - assert_eq!(felts[1], FieldElement::from(12_u32)); - assert_eq!(felts[2], FieldElement::TWO); + assert_eq!(felts[0], Felt::from(1_u32)); + assert_eq!(felts[1], Felt::from(12_u32)); + assert_eq!(felts[2], Felt::TWO); } #[test] fn test_deserialize_array_tuple() { - let felts: Vec = vec![ - FieldElement::from(1_u32), - FieldElement::from(12_u32), - FieldElement::TWO, - ]; + let felts: Vec = vec![Felt::from(1_u32), Felt::from(12_u32), Felt::TWO]; - let vals = Vec::<(u32, FieldElement)>::cairo_deserialize(&felts, 0).unwrap(); + let vals = Vec::<(u32, Felt)>::cairo_deserialize(&felts, 0).unwrap(); assert_eq!(vals.len(), 1); - assert_eq!(vals[0], (12, FieldElement::TWO)); + assert_eq!(vals[0], (12, Felt::TWO)); } } diff --git a/crates/cairo-serde/src/types/array_legacy.rs b/crates/cairo-serde/src/types/array_legacy.rs index db46fce..06e9be4 100644 --- a/crates/cairo-serde/src/types/array_legacy.rs +++ b/crates/cairo-serde/src/types/array_legacy.rs @@ -1,6 +1,6 @@ //! Dedicated struct for cairo 0 arrays, where len is not prefixed. use crate::{CairoSerde, Error, Result}; -use starknet::core::types::FieldElement; +use starknet::core::types::Felt; #[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] pub struct CairoArrayLegacy(pub Vec); @@ -40,15 +40,15 @@ where data.iter().map(T::cairo_serialized_size).sum::() } - fn cairo_serialize(rust: &Self::RustType) -> Vec { - let mut out: Vec = vec![]; + fn cairo_serialize(rust: &Self::RustType) -> Vec { + let mut out: Vec = vec![]; rust.0 .iter() .for_each(|r| out.extend(T::cairo_serialize(r))); out } - fn cairo_deserialize(felts: &[FieldElement], offset: usize) -> Result { + fn cairo_deserialize(felts: &[Felt], offset: usize) -> Result { if offset >= felts.len() { // As the length of cairo 0 arrays is not included in the serialized form of the array, // we don't have much choice here to return an empty array instead of an error. @@ -59,7 +59,7 @@ where let mut offset = offset; let len = felts[offset - 1]; - if FieldElement::from(offset) + len > FieldElement::from(felts.len()) { + if Felt::from(offset) + len > Felt::from(felts.len()) { return Err(Error::Deserialize(format!( "Buffer too short to deserialize an array of length {}: offset ({}) : buffer {:?}", len, offset, felts, @@ -67,7 +67,7 @@ where } loop { - if FieldElement::from(out.len()) == len { + if Felt::from(out.len()) == len { break; } @@ -88,7 +88,7 @@ mod tests { #[test] fn array_offset_len_ok() { let serialized = vec![felt!("4"), felt!("1"), felt!("2"), felt!("3"), felt!("4")]; - let a = CairoArrayLegacy::::cairo_deserialize(&serialized, 1).unwrap(); + let a = CairoArrayLegacy::::cairo_deserialize(&serialized, 1).unwrap(); assert_eq!(a.len(), 4); assert_eq!(a.0[0], felt!("1")); assert_eq!(a.0[1], felt!("2")); @@ -100,7 +100,7 @@ mod tests { fn empty_array() { // Array with only the length that is 0 (an other field as we're in cairo 0). // So the deserialization of the array starts at index 1. - let serialized = vec![FieldElement::ZERO]; - let _a = CairoArrayLegacy::::cairo_deserialize(&serialized, 1).unwrap(); + let serialized = vec![Felt::ZERO]; + let _a = CairoArrayLegacy::::cairo_deserialize(&serialized, 1).unwrap(); } } diff --git a/crates/cairo-serde/src/types/boolean.rs b/crates/cairo-serde/src/types/boolean.rs index 624b45d..58fd27d 100644 --- a/crates/cairo-serde/src/types/boolean.rs +++ b/crates/cairo-serde/src/types/boolean.rs @@ -1,15 +1,15 @@ //! CairoSerde implementation for bool. use crate::{CairoSerde, Error, Result}; -use starknet::core::types::FieldElement; +use starknet::core::types::Felt; impl CairoSerde for bool { type RustType = Self; - fn cairo_serialize(rust: &Self::RustType) -> Vec { - vec![FieldElement::from(*rust as u32)] + fn cairo_serialize(rust: &Self::RustType) -> Vec { + vec![Felt::from(*rust as u32)] } - fn cairo_deserialize(felts: &[FieldElement], offset: usize) -> Result { + fn cairo_deserialize(felts: &[Felt], offset: usize) -> Result { if offset >= felts.len() { return Err(Error::Deserialize(format!( "Buffer too short to deserialize a boolean: offset ({}) : buffer {:?}", @@ -17,7 +17,7 @@ impl CairoSerde for bool { ))); } - if felts[offset] == FieldElement::ONE { + if felts[offset] == Felt::ONE { Ok(true) } else { Ok(false) @@ -34,17 +34,17 @@ mod tests { let v = true; let felts = bool::cairo_serialize(&v); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::ONE); + assert_eq!(felts[0], Felt::ONE); let v = false; let felts = bool::cairo_serialize(&v); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::ZERO); + assert_eq!(felts[0], Felt::ZERO); } #[test] fn test_deserialize_bool() { - let felts = vec![FieldElement::ZERO, FieldElement::ONE, FieldElement::TWO]; + let felts = vec![Felt::ZERO, Felt::ONE, Felt::TWO]; assert!(!bool::cairo_deserialize(&felts, 0).unwrap()); assert!(bool::cairo_deserialize(&felts, 1).unwrap()); assert!(!bool::cairo_deserialize(&felts, 2).unwrap()); diff --git a/crates/cairo-serde/src/types/byte_array.rs b/crates/cairo-serde/src/types/byte_array.rs index 820ffdd..3e24971 100644 --- a/crates/cairo-serde/src/types/byte_array.rs +++ b/crates/cairo-serde/src/types/byte_array.rs @@ -14,27 +14,27 @@ use std::{ string::FromUtf8Error, }; -use starknet::core::types::FieldElement; +use starknet::core::types::Felt; use crate::error::{Error, Result as CainomeResult}; use crate::CairoSerde; const MAX_WORD_LEN: usize = 31; -pub const BYTES31_MAX: FieldElement = FieldElement::from_mont([ - 18446744062762287141, - 20123647, - 18446744073709514624, +pub const BYTES31_MAX: Felt = Felt::from_raw([ 576460566199927480, + 18446744073709514624, + 20123647, + 18446744062762287141, ]); #[derive( Debug, Clone, Eq, PartialEq, PartialOrd, Default, serde::Serialize, serde::Deserialize, )] -pub struct Bytes31(FieldElement); +pub struct Bytes31(Felt); impl Bytes31 { - pub fn new(felt: FieldElement) -> CainomeResult { + pub fn new(felt: Felt) -> CainomeResult { if felt > BYTES31_MAX { Err(Error::Bytes31OutOfRange) } else { @@ -42,21 +42,21 @@ impl Bytes31 { } } - pub fn felt(&self) -> FieldElement { + pub fn felt(&self) -> Felt { self.0 } } -impl From for FieldElement { +impl From for Felt { fn from(value: Bytes31) -> Self { value.felt() } } -impl TryFrom for Bytes31 { +impl TryFrom for Bytes31 { type Error = Error; - fn try_from(value: FieldElement) -> Result { + fn try_from(value: Felt) -> Result { Self::new(value) } } @@ -64,11 +64,11 @@ impl TryFrom for Bytes31 { impl CairoSerde for Bytes31 { type RustType = Self; - fn cairo_serialize(rust: &Self::RustType) -> Vec { + fn cairo_serialize(rust: &Self::RustType) -> Vec { vec![rust.felt()] } - fn cairo_deserialize(felts: &[FieldElement], offset: usize) -> CainomeResult { + fn cairo_deserialize(felts: &[Felt], offset: usize) -> CainomeResult { Self::new(felts[offset]) } } @@ -78,7 +78,7 @@ impl CairoSerde for Bytes31 { )] pub struct ByteArray { pub data: Vec, - pub pending_word: FieldElement, + pub pending_word: Felt, pub pending_word_len: usize, } @@ -90,25 +90,25 @@ impl CairoSerde for ByteArray { fn cairo_serialized_size(rust: &Self::RustType) -> usize { let mut size = 0; size += Vec::::cairo_serialized_size(&rust.data); - size += FieldElement::cairo_serialized_size(&rust.pending_word); + size += Felt::cairo_serialized_size(&rust.pending_word); size += u32::cairo_serialized_size(&(rust.pending_word_len as u32)); size } - fn cairo_serialize(rust: &Self::RustType) -> Vec { - let mut out: Vec = vec![]; + fn cairo_serialize(rust: &Self::RustType) -> Vec { + let mut out: Vec = vec![]; out.extend(Vec::::cairo_serialize(&rust.data)); - out.extend(FieldElement::cairo_serialize(&rust.pending_word)); + out.extend(Felt::cairo_serialize(&rust.pending_word)); out.extend(u32::cairo_serialize(&(rust.pending_word_len as u32))); out } - fn cairo_deserialize(felts: &[FieldElement], offset: usize) -> CainomeResult { + fn cairo_deserialize(felts: &[Felt], offset: usize) -> CainomeResult { let mut offset = offset; let data = Vec::::cairo_deserialize(felts, offset)?; offset += Vec::::cairo_serialized_size(&data); - let pending_word = FieldElement::cairo_deserialize(felts, offset)?; - offset += FieldElement::cairo_serialized_size(&pending_word); + let pending_word = Felt::cairo_deserialize(felts, offset)?; + offset += Felt::cairo_serialized_size(&pending_word); let pending_word_len = u32::cairo_deserialize(felts, offset)?; Ok(ByteArray { @@ -147,19 +147,18 @@ impl ByteArray { let len = r.len(); ( // Safe to unwrap as pending word always fit in a felt. - FieldElement::from_byte_slice_be(&r).unwrap(), + // Felt::from_byte_slice_be(&r).unwrap(), + Felt::from_bytes_be_slice(&r), len, ) } else { - (FieldElement::ZERO, 0) + (Felt::ZERO, 0) }; let mut data = Vec::new(); for chunk in full_chunks { // Safe to unwrap as full chunks are 31 bytes long, always fit in a felt. - data.push(Bytes31::new( - FieldElement::from_byte_slice_be(chunk).unwrap(), - )?) + data.push(Bytes31::new(Felt::from_bytes_be_slice(chunk))?) } Ok(Self { @@ -192,12 +191,12 @@ impl ByteArray { /// /// # Arguments /// -/// * `felt` - The `FieldElement` to convert. In the context of `ByteArray` this +/// * `felt` - The `Felt` to convert. In the context of `ByteArray` this /// felt always contains at most 31 bytes. /// * `len` - The number of bytes in the felt, at most 31. In the context /// of `ByteArray`, we don't need to check `len` as the `MAX_WORD_LEN` /// already protect against that. -fn felt_to_utf8(felt: &FieldElement, len: usize) -> Result { +fn felt_to_utf8(felt: &Felt, len: usize) -> Result { let mut buffer = Vec::new(); // ByteArray always enforce to have the first byte equal to 0. @@ -228,7 +227,7 @@ impl TryFrom<&str> for ByteArray { #[cfg(test)] mod tests { use super::ByteArray; - use starknet::core::types::FieldElement; + use starknet::core::types::Felt; #[test] fn test_from_string_empty_string_default() { @@ -243,7 +242,7 @@ mod tests { b, ByteArray { data: vec![], - pending_word: FieldElement::from_hex_be( + pending_word: Felt::from_hex( "0x0000000000000000000000000000000000000000000000000000000041424344" ) .unwrap(), @@ -261,7 +260,7 @@ mod tests { b, ByteArray { data: vec![], - pending_word: FieldElement::from_hex_be( + pending_word: Felt::from_hex( "0x00004142434445464748494a4b4c4d4e4f505152535455565758595a31323334" ) .unwrap(), @@ -277,13 +276,13 @@ mod tests { assert_eq!( b, ByteArray { - data: vec![FieldElement::from_hex_be( + data: vec![Felt::from_hex( "0x004142434445464748494a4b4c4d4e4f505152535455565758595a3132333435" ) .unwrap() .try_into() .unwrap()], - pending_word: FieldElement::ZERO, + pending_word: Felt::ZERO, pending_word_len: 0, } ); @@ -300,20 +299,20 @@ mod tests { b, ByteArray { data: vec![ - FieldElement::from_hex_be( + Felt::from_hex( "0x004142434445464748494a4b4c4d4e4f505152535455565758595a3132333435" ) .unwrap() .try_into() .unwrap(), - FieldElement::from_hex_be( + Felt::from_hex( "0x004142434445464748494a4b4c4d4e4f505152535455565758595a3132333435" ) .unwrap() .try_into() .unwrap(), ], - pending_word: FieldElement::ZERO, + pending_word: Felt::ZERO, pending_word_len: 0, } ); @@ -330,20 +329,20 @@ mod tests { b, ByteArray { data: vec![ - FieldElement::from_hex_be( + Felt::from_hex( "0x004142434445464748494a4b4c4d4e4f505152535455565758595a3132333435" ) .unwrap() .try_into() .unwrap(), - FieldElement::from_hex_be( + Felt::from_hex( "0x004142434445464748494a4b4c4d4e4f505152535455565758595a3132333435" ) .unwrap() .try_into() .unwrap(), ], - pending_word: FieldElement::from_hex_be( + pending_word: Felt::from_hex( "0x0000000000000000000000000000000000000000000000000000000041424344" ) .unwrap(), @@ -362,7 +361,7 @@ mod tests { fn test_to_string_only_pending_word() { let b = ByteArray { data: vec![], - pending_word: FieldElement::from_hex_be( + pending_word: Felt::from_hex( "0x0000000000000000000000000000000000000000000000000000000041424344", ) .unwrap(), @@ -376,7 +375,7 @@ mod tests { fn test_to_string_max_pending_word_len() { let b = ByteArray { data: vec![], - pending_word: FieldElement::from_hex_be( + pending_word: Felt::from_hex( "0x00004142434445464748494a4b4c4d4e4f505152535455565758595a31323334", ) .unwrap(), @@ -389,13 +388,13 @@ mod tests { #[test] fn test_to_string_data_only() { let b = ByteArray { - data: vec![FieldElement::from_hex_be( + data: vec![Felt::from_hex( "0x004142434445464748494a4b4c4d4e4f505152535455565758595a3132333435", ) .unwrap() .try_into() .unwrap()], - pending_word: FieldElement::ZERO, + pending_word: Felt::ZERO, pending_word_len: 0, }; @@ -406,20 +405,20 @@ mod tests { fn test_to_string_data_only_multiple() { let b = ByteArray { data: vec![ - FieldElement::from_hex_be( + Felt::from_hex( "0x004142434445464748494a4b4c4d4e4f505152535455565758595a3132333435", ) .unwrap() .try_into() .unwrap(), - FieldElement::from_hex_be( + Felt::from_hex( "0x004142434445464748494a4b4c4d4e4f505152535455565758595a3132333435", ) .unwrap() .try_into() .unwrap(), ], - pending_word: FieldElement::ZERO, + pending_word: Felt::ZERO, pending_word_len: 0, }; @@ -433,20 +432,20 @@ mod tests { fn test_to_string_data_and_pending_word() { let b = ByteArray { data: vec![ - FieldElement::from_hex_be( + Felt::from_hex( "0x004142434445464748494a4b4c4d4e4f505152535455565758595a3132333435", ) .unwrap() .try_into() .unwrap(), - FieldElement::from_hex_be( + Felt::from_hex( "0x004142434445464748494a4b4c4d4e4f505152535455565758595a3132333435", ) .unwrap() .try_into() .unwrap(), ], - pending_word: FieldElement::from_hex_be( + pending_word: Felt::from_hex( "0x0000000000000000000000000000000000000000000000000000000041424344", ) .unwrap(), @@ -464,7 +463,7 @@ mod tests { fn test_to_string_invalid_utf8() { let b = ByteArray { data: vec![], - pending_word: FieldElement::from_hex_be( + pending_word: Felt::from_hex( "0x00000000000000000000000000000000000000000000000000000000ffffffff", ) .unwrap(), @@ -482,7 +481,7 @@ mod tests { b, ByteArray { data: vec![], - pending_word: FieldElement::from_hex_be( + pending_word: Felt::from_hex( "0x000000000000000000000000000000000000000000000000f09fa680f09f8c9f", ) .unwrap(), diff --git a/crates/cairo-serde/src/types/felt.rs b/crates/cairo-serde/src/types/felt.rs index 92c50a4..d22090e 100644 --- a/crates/cairo-serde/src/types/felt.rs +++ b/crates/cairo-serde/src/types/felt.rs @@ -1,14 +1,14 @@ use crate::{CairoSerde, Error, Result}; -use starknet::core::types::FieldElement; +use starknet::core::types::Felt; -impl CairoSerde for FieldElement { +impl CairoSerde for Felt { type RustType = Self; - fn cairo_serialize(rust: &Self::RustType) -> Vec { + fn cairo_serialize(rust: &Self::RustType) -> Vec { vec![*rust] } - fn cairo_deserialize(felts: &[FieldElement], offset: usize) -> Result { + fn cairo_deserialize(felts: &[Felt], offset: usize) -> Result { if offset >= felts.len() { return Err(Error::Deserialize(format!( "Buffer too short to deserialize a felt: offset ({}) : buffer {:?}", @@ -26,26 +26,17 @@ mod tests { #[test] fn test_serialize_field_element() { - let f = FieldElement::ZERO; - let felts = FieldElement::cairo_serialize(&f); + let f = Felt::ZERO; + let felts = Felt::cairo_serialize(&f); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::ZERO); + assert_eq!(felts[0], Felt::ZERO); } #[test] fn test_deserialize_field_element() { - let felts = vec![FieldElement::ZERO, FieldElement::ONE, FieldElement::TWO]; - assert_eq!( - FieldElement::cairo_deserialize(&felts, 0).unwrap(), - FieldElement::ZERO - ); - assert_eq!( - FieldElement::cairo_deserialize(&felts, 1).unwrap(), - FieldElement::ONE - ); - assert_eq!( - FieldElement::cairo_deserialize(&felts, 2).unwrap(), - FieldElement::TWO - ); + let felts = vec![Felt::ZERO, Felt::ONE, Felt::TWO]; + assert_eq!(Felt::cairo_deserialize(&felts, 0).unwrap(), Felt::ZERO); + assert_eq!(Felt::cairo_deserialize(&felts, 1).unwrap(), Felt::ONE); + assert_eq!(Felt::cairo_deserialize(&felts, 2).unwrap(), Felt::TWO); } } diff --git a/crates/cairo-serde/src/types/integers.rs b/crates/cairo-serde/src/types/integers.rs index dc2decb..532fdc9 100644 --- a/crates/cairo-serde/src/types/integers.rs +++ b/crates/cairo-serde/src/types/integers.rs @@ -1,17 +1,17 @@ //! CairoSerde implementation for integers (signed/unsigned). use crate::{CairoSerde, Error, Result}; -use starknet::core::types::FieldElement; +use starknet::core::types::Felt; macro_rules! implement_trait_for_unsigned { ($type:ty) => { impl CairoSerde for $type { type RustType = Self; - fn cairo_serialize(rust: &Self::RustType) -> Vec { - vec![FieldElement::from(*rust)] + fn cairo_serialize(rust: &Self::RustType) -> Vec { + vec![Felt::from(*rust)] } - fn cairo_deserialize(felts: &[FieldElement], offset: usize) -> Result { + fn cairo_deserialize(felts: &[Felt], offset: usize) -> Result { if offset >= felts.len() { return Err(Error::Deserialize(format!( "Buffer too short to deserialize a unsigned integer: offset ({}) : buffer {:?}", @@ -20,7 +20,9 @@ macro_rules! implement_trait_for_unsigned { ))); } - let temp: u128 = felts[offset].try_into().unwrap(); + let f = felts[offset]; + let temp = u128::from_be_bytes(f.to_bytes_be()[16..].try_into().unwrap()); + Ok(temp as $type) } } @@ -32,11 +34,11 @@ macro_rules! implement_trait_for_signed { impl CairoSerde for $type { type RustType = Self; - fn cairo_serialize(rust: &Self::RustType) -> Vec { - vec![FieldElement::from(*rust as usize)] + fn cairo_serialize(rust: &Self::RustType) -> Vec { + vec![Felt::from(*rust as usize)] } - fn cairo_deserialize(felts: &[FieldElement], offset: usize) -> Result { + fn cairo_deserialize(felts: &[Felt], offset: usize) -> Result { if offset >= felts.len() { return Err(Error::Deserialize(format!( "Buffer too short to deserialize a signed integer: offset ({}) : buffer {:?}", @@ -45,7 +47,9 @@ macro_rules! implement_trait_for_signed { ))); } - let temp: u128 = felts[offset].try_into().unwrap(); + let f = felts[offset]; + let temp = u128::from_be_bytes(f.to_bytes_be()[16..].try_into().unwrap()); + Ok(temp as $type) } } @@ -75,12 +79,12 @@ mod tests { let v = 12_u8; let felts = u8::cairo_serialize(&v); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::from(12_u8)); + assert_eq!(felts[0], Felt::from(12_u8)); } #[test] fn test_deserialize_u8() { - let felts = vec![FieldElement::from(12_u8), FieldElement::from(10_u8)]; + let felts = vec![Felt::from(12_u8), Felt::from(10_u8)]; assert_eq!(u8::cairo_deserialize(&felts, 0).unwrap(), 12); assert_eq!(u8::cairo_deserialize(&felts, 1).unwrap(), 10); } @@ -90,12 +94,12 @@ mod tests { let v = 12_u16; let felts = u16::cairo_serialize(&v); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::from(12_u16)); + assert_eq!(felts[0], Felt::from(12_u16)); } #[test] fn test_deserialize_u16() { - let felts = vec![FieldElement::from(12_u16), FieldElement::from(10_u8)]; + let felts = vec![Felt::from(12_u16), Felt::from(10_u8)]; assert_eq!(u16::cairo_deserialize(&felts, 0).unwrap(), 12); assert_eq!(u16::cairo_deserialize(&felts, 1).unwrap(), 10); } @@ -105,12 +109,12 @@ mod tests { let v = 123_u32; let felts = u32::cairo_serialize(&v); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::from(123_u32)); + assert_eq!(felts[0], Felt::from(123_u32)); } #[test] fn test_deserialize_u32() { - let felts = vec![FieldElement::from(123_u32), FieldElement::from(99_u32)]; + let felts = vec![Felt::from(123_u32), Felt::from(99_u32)]; assert_eq!(u32::cairo_deserialize(&felts, 0).unwrap(), 123); assert_eq!(u32::cairo_deserialize(&felts, 1).unwrap(), 99); } @@ -120,12 +124,12 @@ mod tests { let v = 123_u64; let felts = u64::cairo_serialize(&v); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::from(123_u64)); + assert_eq!(felts[0], Felt::from(123_u64)); } #[test] fn test_deserialize_u64() { - let felts = vec![FieldElement::from(123_u64), FieldElement::from(99_u64)]; + let felts = vec![Felt::from(123_u64), Felt::from(99_u64)]; assert_eq!(u64::cairo_deserialize(&felts, 0).unwrap(), 123); assert_eq!(u64::cairo_deserialize(&felts, 1).unwrap(), 99); } @@ -135,12 +139,12 @@ mod tests { let v = 123_u128; let felts = u128::cairo_serialize(&v); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::from(123_u128)); + assert_eq!(felts[0], Felt::from(123_u128)); } #[test] fn test_deserialize_u128() { - let felts = vec![FieldElement::from(123_u128), FieldElement::from(99_u128)]; + let felts = vec![Felt::from(123_u128), Felt::from(99_u128)]; assert_eq!(u128::cairo_deserialize(&felts, 0).unwrap(), 123); assert_eq!(u128::cairo_deserialize(&felts, 1).unwrap(), 99); } @@ -150,12 +154,12 @@ mod tests { let v = 123; let felts = usize::cairo_serialize(&v); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::from(123_u128)); + assert_eq!(felts[0], Felt::from(123_u128)); } #[test] fn test_deserialize_usize() { - let felts = vec![FieldElement::from(123_u128), FieldElement::from(99_u64)]; + let felts = vec![Felt::from(123_u128), Felt::from(99_u64)]; assert_eq!(usize::cairo_deserialize(&felts, 0).unwrap(), 123); assert_eq!(usize::cairo_deserialize(&felts, 1).unwrap(), 99); } @@ -165,15 +169,12 @@ mod tests { let v = i8::MAX; let felts = i8::cairo_serialize(&v); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::from(i8::MAX as u8)); + assert_eq!(felts[0], Felt::from(i8::MAX as u8)); } #[test] fn test_deserialize_i8() { - let felts = vec![ - FieldElement::from(i8::MAX as u8), - FieldElement::from(i8::MAX as u8), - ]; + let felts = vec![Felt::from(i8::MAX as u8), Felt::from(i8::MAX as u8)]; assert_eq!(i8::cairo_deserialize(&felts, 0).unwrap(), i8::MAX); assert_eq!(i8::cairo_deserialize(&felts, 1).unwrap(), i8::MAX); } @@ -183,15 +184,12 @@ mod tests { let v = i16::MAX; let felts = i16::cairo_serialize(&v); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::from(i16::MAX as u16)); + assert_eq!(felts[0], Felt::from(i16::MAX as u16)); } #[test] fn test_deserialize_i16() { - let felts = vec![ - FieldElement::from(i16::MAX as u16), - FieldElement::from(i16::MAX as u16), - ]; + let felts = vec![Felt::from(i16::MAX as u16), Felt::from(i16::MAX as u16)]; assert_eq!(i16::cairo_deserialize(&felts, 0).unwrap(), i16::MAX); assert_eq!(i16::cairo_deserialize(&felts, 1).unwrap(), i16::MAX); } @@ -201,15 +199,12 @@ mod tests { let v = i32::MAX; let felts = i32::cairo_serialize(&v); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::from(i32::MAX as u32)); + assert_eq!(felts[0], Felt::from(i32::MAX as u32)); } #[test] fn test_deserialize_i32() { - let felts = vec![ - FieldElement::from(i32::MAX as u32), - FieldElement::from(i32::MAX as u32), - ]; + let felts = vec![Felt::from(i32::MAX as u32), Felt::from(i32::MAX as u32)]; assert_eq!(i32::cairo_deserialize(&felts, 0).unwrap(), i32::MAX); assert_eq!(i32::cairo_deserialize(&felts, 1).unwrap(), i32::MAX); } @@ -219,25 +214,19 @@ mod tests { let v = i64::MAX; let felts = i64::cairo_serialize(&v); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::from(i64::MAX as u64)); + assert_eq!(felts[0], Felt::from(i64::MAX as u64)); } #[test] fn test_deserialize_i64() { - let felts = vec![ - FieldElement::from(i64::MAX as u64), - FieldElement::from(i64::MAX as u64), - ]; + let felts = vec![Felt::from(i64::MAX as u64), Felt::from(i64::MAX as u64)]; assert_eq!(i64::cairo_deserialize(&felts, 0).unwrap(), i64::MAX); assert_eq!(i64::cairo_deserialize(&felts, 1).unwrap(), i64::MAX); } #[test] fn test_deserialize_i128() { - let felts = vec![ - FieldElement::from(i128::MAX as u128), - FieldElement::from(i128::MAX as u128), - ]; + let felts = vec![Felt::from(i128::MAX as u128), Felt::from(i128::MAX as u128)]; assert_eq!(i128::cairo_deserialize(&felts, 0).unwrap(), i128::MAX); assert_eq!(i128::cairo_deserialize(&felts, 1).unwrap(), i128::MAX); } diff --git a/crates/cairo-serde/src/types/mod.rs b/crates/cairo-serde/src/types/mod.rs index 6310b8a..3719775 100644 --- a/crates/cairo-serde/src/types/mod.rs +++ b/crates/cairo-serde/src/types/mod.rs @@ -14,28 +14,28 @@ pub mod u256; #[cfg(test)] mod tests { use crate::CairoSerde; - use ::starknet::core::types::FieldElement; + use ::starknet::core::types::Felt; #[test] fn test_serialize_several_values() { let o = Some(u32::MAX); - let r = Err(FieldElement::TWO); + let r = Err(Felt::TWO); let a: Vec = vec![1, 2, 3]; let mut felts = vec![]; felts.extend(Option::::cairo_serialize(&o)); - felts.extend(Result::::cairo_serialize(&r)); + felts.extend(Result::::cairo_serialize(&r)); felts.extend(Vec::::cairo_serialize(&a)); assert_eq!(felts.len(), 8); - assert_eq!(felts[0], FieldElement::ZERO); - assert_eq!(felts[1], FieldElement::from(u32::MAX)); - assert_eq!(felts[2], FieldElement::ONE); - assert_eq!(felts[3], FieldElement::TWO); - assert_eq!(felts[4], FieldElement::THREE); - assert_eq!(felts[5], FieldElement::ONE); - assert_eq!(felts[6], FieldElement::TWO); - assert_eq!(felts[7], FieldElement::THREE); + assert_eq!(felts[0], Felt::ZERO); + assert_eq!(felts[1], Felt::from(u32::MAX)); + assert_eq!(felts[2], Felt::ONE); + assert_eq!(felts[3], Felt::TWO); + assert_eq!(felts[4], Felt::THREE); + assert_eq!(felts[5], Felt::ONE); + assert_eq!(felts[6], Felt::TWO); + assert_eq!(felts[7], Felt::THREE); } #[test] @@ -46,30 +46,30 @@ mod tests { let mut felts = vec![]; felts.extend(Option::::cairo_serialize(&o)); - felts.extend(Result::<(), FieldElement>::cairo_serialize(&r)); + felts.extend(Result::<(), Felt>::cairo_serialize(&r)); felts.extend(Vec::::cairo_serialize(&a)); assert_eq!(felts.len(), 7); - assert_eq!(felts[0], FieldElement::ZERO); - assert_eq!(felts[1], FieldElement::from(u32::MAX)); - assert_eq!(felts[2], FieldElement::ZERO); - assert_eq!(felts[3], FieldElement::THREE); - assert_eq!(felts[4], FieldElement::ONE); - assert_eq!(felts[5], FieldElement::TWO); - assert_eq!(felts[6], FieldElement::THREE); + assert_eq!(felts[0], Felt::ZERO); + assert_eq!(felts[1], Felt::from(u32::MAX)); + assert_eq!(felts[2], Felt::ZERO); + assert_eq!(felts[3], Felt::THREE); + assert_eq!(felts[4], Felt::ONE); + assert_eq!(felts[5], Felt::TWO); + assert_eq!(felts[6], Felt::THREE); } #[test] fn test_deserialize_several_values() { let felts = vec![ - FieldElement::ZERO, - FieldElement::from(u32::MAX), - FieldElement::ONE, - FieldElement::TWO, - FieldElement::THREE, - FieldElement::ONE, - FieldElement::TWO, - FieldElement::THREE, + Felt::ZERO, + Felt::from(u32::MAX), + Felt::ONE, + Felt::TWO, + Felt::THREE, + Felt::ONE, + Felt::TWO, + Felt::THREE, ]; let mut offset = 0; @@ -77,14 +77,14 @@ mod tests { let o = Option::::cairo_deserialize(&felts, offset).unwrap(); offset += Option::::cairo_serialized_size(&o); - let r = Result::::cairo_deserialize(&felts, offset).unwrap(); - offset += Result::::cairo_serialized_size(&r); + let r = Result::::cairo_deserialize(&felts, offset).unwrap(); + offset += Result::::cairo_serialized_size(&r); let a = Vec::::cairo_deserialize(&felts, offset).unwrap(); offset += Vec::::cairo_serialized_size(&a); assert_eq!(o, Some(u32::MAX)); - assert_eq!(r, Err(FieldElement::TWO)); + assert_eq!(r, Err(Felt::TWO)); assert_eq!(a, vec![1, 2, 3]); assert_eq!(offset, felts.len()); } @@ -92,13 +92,13 @@ mod tests { #[test] fn test_deserialize_several_values_with_unit() { let felts = vec![ - FieldElement::ZERO, - FieldElement::from(u32::MAX), - FieldElement::ZERO, - FieldElement::THREE, - FieldElement::ONE, - FieldElement::TWO, - FieldElement::THREE, + Felt::ZERO, + Felt::from(u32::MAX), + Felt::ZERO, + Felt::THREE, + Felt::ONE, + Felt::TWO, + Felt::THREE, ]; let mut offset = 0; @@ -106,8 +106,8 @@ mod tests { let o = Option::::cairo_deserialize(&felts, offset).unwrap(); offset += Option::::cairo_serialized_size(&o); - let r = Result::<(), FieldElement>::cairo_deserialize(&felts, offset).unwrap(); - offset += Result::<(), FieldElement>::cairo_serialized_size(&r); + let r = Result::<(), Felt>::cairo_deserialize(&felts, offset).unwrap(); + offset += Result::<(), Felt>::cairo_serialized_size(&r); let a = Vec::::cairo_deserialize(&felts, offset).unwrap(); offset += Vec::::cairo_serialized_size(&a); diff --git a/crates/cairo-serde/src/types/non_zero.rs b/crates/cairo-serde/src/types/non_zero.rs index c9b38d6..0c66d14 100644 --- a/crates/cairo-serde/src/types/non_zero.rs +++ b/crates/cairo-serde/src/types/non_zero.rs @@ -4,7 +4,7 @@ //! //! use crate::{CairoSerde, ContractAddress, Result, U256}; -use starknet::core::types::FieldElement; +use starknet::core::types::Felt; #[derive(Debug, PartialEq, PartialOrd, Clone, serde::Serialize, serde::Deserialize)] pub struct NonZero(T); @@ -47,11 +47,11 @@ where T::cairo_serialized_size(&rust.0) } - fn cairo_serialize(rust: &Self::RustType) -> Vec { + fn cairo_serialize(rust: &Self::RustType) -> Vec { T::cairo_serialize(&rust.0) } - fn cairo_deserialize(felts: &[FieldElement], offset: usize) -> Result { + fn cairo_deserialize(felts: &[Felt], offset: usize) -> Result { NonZero::new(T::cairo_deserialize(felts, offset)?).ok_or(crate::Error::ZeroedNonZero) } } @@ -89,15 +89,15 @@ impl Zeroable for U256 { } } -impl Zeroable for FieldElement { +impl Zeroable for Felt { fn is_zero(&self) -> bool { - *self == FieldElement::ZERO + *self == Felt::ZERO } } impl Zeroable for ContractAddress { fn is_zero(&self) -> bool { - self.0 == FieldElement::ZERO + self.0 == Felt::ZERO } } @@ -112,19 +112,19 @@ mod tests { let non_zero = NonZero(1_u32); let felts = NonZero::::cairo_serialize(&non_zero); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::from(1_u32)); + assert_eq!(felts[0], Felt::from(1_u32)); } #[test] fn test_non_zero_cairo_deserialize() { - let felts = vec![FieldElement::from(1_u32)]; + let felts = vec![Felt::from(1_u32)]; let non_zero = NonZero::::cairo_deserialize(&felts, 0).unwrap(); assert_eq!(non_zero, NonZero(1_u32)) } #[test] fn test_non_zero_cairo_deserialize_zero() { - let felts = vec![FieldElement::ZERO, FieldElement::ZERO]; + let felts = vec![Felt::ZERO, Felt::ZERO]; let non_zero = NonZero::::cairo_deserialize(&felts, 0); match non_zero { Err(Error::ZeroedNonZero) => (), diff --git a/crates/cairo-serde/src/types/option.rs b/crates/cairo-serde/src/types/option.rs index b28b3f2..73d470f 100644 --- a/crates/cairo-serde/src/types/option.rs +++ b/crates/cairo-serde/src/types/option.rs @@ -5,7 +5,7 @@ //! //! use crate::{CairoSerde, Error, Result}; -use starknet::core::types::FieldElement; +use starknet::core::types::Felt; impl CairoSerde for Option where @@ -21,21 +21,21 @@ where } } - fn cairo_serialize(rust: &Self::RustType) -> Vec { + fn cairo_serialize(rust: &Self::RustType) -> Vec { let mut out = vec![]; match rust { Some(r) => { - out.push(FieldElement::ZERO); + out.push(Felt::ZERO); out.extend(T::cairo_serialize(r)); } - None => out.push(FieldElement::ONE), + None => out.push(Felt::ONE), }; out } - fn cairo_deserialize(felts: &[FieldElement], offset: usize) -> Result { + fn cairo_deserialize(felts: &[Felt], offset: usize) -> Result { if offset >= felts.len() { return Err(Error::Deserialize(format!( "Buffer too short to deserialize an Option: offset ({}) : buffer {:?}", @@ -45,10 +45,10 @@ where let idx = felts[offset]; - if idx == FieldElement::ZERO { + if idx == Felt::ZERO { // + 1 as the offset value is the index of the enum. Ok(Option::Some(T::cairo_deserialize(felts, offset + 1)?)) - } else if idx == FieldElement::ONE { + } else if idx == Felt::ONE { Ok(Option::None) } else { Err(Error::Deserialize( @@ -61,28 +61,24 @@ where #[cfg(test)] mod tests { use super::*; - use starknet::core::types::FieldElement; + use starknet::core::types::Felt; #[test] fn test_option_some_cairo_serialize() { let o = Some(u32::MAX); let felts = Option::::cairo_serialize(&o); assert_eq!(felts.len(), 2); - assert_eq!(felts[0], FieldElement::ZERO); - assert_eq!(felts[1], FieldElement::from(u32::MAX)); + assert_eq!(felts[0], Felt::ZERO); + assert_eq!(felts[1], Felt::from(u32::MAX)); } #[test] fn test_option_some_cairo_deserialize() { - let felts = vec![FieldElement::ZERO, FieldElement::from(u32::MAX)]; + let felts = vec![Felt::ZERO, Felt::from(u32::MAX)]; let o = Option::::cairo_deserialize(&felts, 0).unwrap(); assert_eq!(o, Some(u32::MAX)); - let felts = vec![ - FieldElement::THREE, - FieldElement::ZERO, - FieldElement::from(u32::MAX), - ]; + let felts = vec![Felt::THREE, Felt::ZERO, Felt::from(u32::MAX)]; let o = Option::::cairo_deserialize(&felts, 1).unwrap(); assert_eq!(o, Some(u32::MAX)); } @@ -92,12 +88,12 @@ mod tests { let o = Some(()); let felts = Option::<()>::cairo_serialize(&o); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::ZERO); + assert_eq!(felts[0], Felt::ZERO); } #[test] fn test_option_some_unit_cairo_deserialize() { - let felts = vec![FieldElement::ZERO]; + let felts = vec![Felt::ZERO]; let o = Option::<()>::cairo_deserialize(&felts, 0).unwrap(); assert_eq!(o, Some(())); } @@ -107,29 +103,29 @@ mod tests { let o = Some(vec![u32::MAX, u32::MAX]); let felts = Option::>::cairo_serialize(&o); assert_eq!(felts.len(), 4); - assert_eq!(felts[0], FieldElement::ZERO); - assert_eq!(felts[1], FieldElement::from(2_u32)); - assert_eq!(felts[2], FieldElement::from(u32::MAX)); - assert_eq!(felts[3], FieldElement::from(u32::MAX)); + assert_eq!(felts[0], Felt::ZERO); + assert_eq!(felts[1], Felt::from(2_u32)); + assert_eq!(felts[2], Felt::from(u32::MAX)); + assert_eq!(felts[3], Felt::from(u32::MAX)); } #[test] fn test_option_some_array_cairo_deserialize() { let felts = vec![ - FieldElement::ZERO, - FieldElement::from(2_u32), - FieldElement::from(u32::MAX), - FieldElement::from(u32::MAX), + Felt::ZERO, + Felt::from(2_u32), + Felt::from(u32::MAX), + Felt::from(u32::MAX), ]; let o = Option::>::cairo_deserialize(&felts, 0).unwrap(); assert_eq!(o, Some(vec![u32::MAX, u32::MAX])); let felts = vec![ - FieldElement::THREE, - FieldElement::ZERO, - FieldElement::from(2_u32), - FieldElement::from(u32::MAX), - FieldElement::from(u32::MAX), + Felt::THREE, + Felt::ZERO, + Felt::from(2_u32), + Felt::from(u32::MAX), + Felt::from(u32::MAX), ]; let o = Option::>::cairo_deserialize(&felts, 1).unwrap(); assert_eq!(o, Some(vec![u32::MAX, u32::MAX])); @@ -140,16 +136,16 @@ mod tests { let o: Option = None; let felts = Option::::cairo_serialize(&o); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::ONE); + assert_eq!(felts[0], Felt::ONE); } #[test] fn test_option_none_cairo_deserialize() { - let felts = vec![FieldElement::ONE]; + let felts = vec![Felt::ONE]; let o = Option::::cairo_deserialize(&felts, 0).unwrap(); assert_eq!(o, None); - let felts = vec![FieldElement::THREE, FieldElement::ONE]; + let felts = vec![Felt::THREE, Felt::ONE]; let o = Option::::cairo_deserialize(&felts, 1).unwrap(); assert_eq!(o, None); } diff --git a/crates/cairo-serde/src/types/result.rs b/crates/cairo-serde/src/types/result.rs index 90ae464..33a10ce 100644 --- a/crates/cairo-serde/src/types/result.rs +++ b/crates/cairo-serde/src/types/result.rs @@ -2,7 +2,7 @@ //! //! use crate::{CairoSerde, Error as CairoError, Result as CairoResult}; -use starknet::core::types::FieldElement; +use starknet::core::types::Felt; impl CairoSerde for Result where @@ -19,16 +19,16 @@ where } } - fn cairo_serialize(rust: &Self::RustType) -> Vec { + fn cairo_serialize(rust: &Self::RustType) -> Vec { let mut out = vec![]; match rust { Result::Ok(r) => { - out.push(FieldElement::ZERO); + out.push(Felt::ZERO); out.extend(T::cairo_serialize(r)); } Result::Err(e) => { - out.push(FieldElement::ONE); + out.push(Felt::ONE); out.extend(E::cairo_serialize(e)); } }; @@ -36,7 +36,7 @@ where out } - fn cairo_deserialize(felts: &[FieldElement], offset: usize) -> CairoResult { + fn cairo_deserialize(felts: &[Felt], offset: usize) -> CairoResult { if offset >= felts.len() { return Err(CairoError::Deserialize(format!( "Buffer too short to deserialize a Result: offset ({}) : buffer {:?}", @@ -46,10 +46,10 @@ where let idx = felts[offset]; - if idx == FieldElement::ZERO { + if idx == Felt::ZERO { // + 1 as the offset value is the index of the enum. CairoResult::Ok(Ok(T::cairo_deserialize(felts, offset + 1)?)) - } else if idx == FieldElement::ONE { + } else if idx == Felt::ONE { CairoResult::Ok(Err(E::cairo_deserialize(felts, offset + 1)?)) } else { Err(CairoError::Deserialize( @@ -62,52 +62,52 @@ where #[cfg(test)] mod tests { use super::*; - use starknet::core::types::FieldElement; + use starknet::core::types::Felt; #[test] fn test_result_ok_cairo_serialize() { let r = Ok(u32::MAX); - let felts = Result::::cairo_serialize(&r); + let felts = Result::::cairo_serialize(&r); assert_eq!(felts.len(), 2); - assert_eq!(felts[0], FieldElement::ZERO); - assert_eq!(felts[1], FieldElement::from(u32::MAX)); + assert_eq!(felts[0], Felt::ZERO); + assert_eq!(felts[1], Felt::from(u32::MAX)); } #[test] fn test_result_ok_cairo_deserialize() { - let felts = vec![FieldElement::ZERO, FieldElement::from(u32::MAX)]; - let r = Result::::cairo_deserialize(&felts, 0).unwrap(); + let felts = vec![Felt::ZERO, Felt::from(u32::MAX)]; + let r = Result::::cairo_deserialize(&felts, 0).unwrap(); assert_eq!(r, Ok(u32::MAX)); } #[test] fn test_result_ok_unit_cairo_serialize() { let r = Ok(()); - let felts = Result::<(), FieldElement>::cairo_serialize(&r); + let felts = Result::<(), Felt>::cairo_serialize(&r); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::ZERO); + assert_eq!(felts[0], Felt::ZERO); } #[test] fn test_result_ok_unit_cairo_deserialize() { - let felts = vec![FieldElement::ZERO]; - let r = Result::<(), FieldElement>::cairo_deserialize(&felts, 0).unwrap(); + let felts = vec![Felt::ZERO]; + let r = Result::<(), Felt>::cairo_deserialize(&felts, 0).unwrap(); assert_eq!(r, Ok(())); } #[test] fn test_result_err_cairo_serialize() { - let r = Err(FieldElement::ONE); - let felts = Result::::cairo_serialize(&r); + let r = Err(Felt::ONE); + let felts = Result::::cairo_serialize(&r); assert_eq!(felts.len(), 2); - assert_eq!(felts[0], FieldElement::ONE); - assert_eq!(felts[1], FieldElement::ONE); + assert_eq!(felts[0], Felt::ONE); + assert_eq!(felts[1], Felt::ONE); } #[test] fn test_result_err_cairo_deserialize() { - let felts = vec![FieldElement::ONE, FieldElement::ONE]; - let r = Result::::cairo_deserialize(&felts, 0).unwrap(); - assert_eq!(r, Err(FieldElement::ONE)); + let felts = vec![Felt::ONE, Felt::ONE]; + let r = Result::::cairo_deserialize(&felts, 0).unwrap(); + assert_eq!(r, Err(Felt::ONE)); } } diff --git a/crates/cairo-serde/src/types/starknet.rs b/crates/cairo-serde/src/types/starknet.rs index aab2882..269bd8f 100644 --- a/crates/cairo-serde/src/types/starknet.rs +++ b/crates/cairo-serde/src/types/starknet.rs @@ -1,20 +1,20 @@ //! CairoSerde implementation for starknet types. //! -//! They are alf `FieldElement` under the hood. +//! They are alf `Felt` under the hood. use crate::{CairoSerde, Error, Result}; -use starknet::core::types::FieldElement; +use starknet::core::types::Felt; /// ContractAddress. #[derive(Debug, Copy, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] -pub struct ContractAddress(pub FieldElement); +pub struct ContractAddress(pub Felt); -impl From for ContractAddress { - fn from(item: FieldElement) -> Self { +impl From for ContractAddress { + fn from(item: Felt) -> Self { Self(item) } } -impl From for FieldElement { +impl From for Felt { fn from(item: ContractAddress) -> Self { item.0 } @@ -23,11 +23,11 @@ impl From for FieldElement { impl CairoSerde for ContractAddress { type RustType = Self; - fn cairo_serialize(rust: &Self::RustType) -> Vec { - FieldElement::cairo_serialize(&rust.0) + fn cairo_serialize(rust: &Self::RustType) -> Vec { + Felt::cairo_serialize(&rust.0) } - fn cairo_deserialize(felts: &[FieldElement], offset: usize) -> Result { + fn cairo_deserialize(felts: &[Felt], offset: usize) -> Result { if offset >= felts.len() { return Err(Error::Deserialize(format!( "Buffer too short to deserialize a ContractAddress: offset ({}) : buffer {:?}", @@ -35,23 +35,21 @@ impl CairoSerde for ContractAddress { ))); } - Ok(ContractAddress(FieldElement::cairo_deserialize( - felts, offset, - )?)) + Ok(ContractAddress(Felt::cairo_deserialize(felts, offset)?)) } } /// ClassHash. #[derive(Debug, Copy, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] -pub struct ClassHash(pub FieldElement); +pub struct ClassHash(pub Felt); -impl From for ClassHash { - fn from(item: FieldElement) -> Self { +impl From for ClassHash { + fn from(item: Felt) -> Self { Self(item) } } -impl From for FieldElement { +impl From for Felt { fn from(item: ClassHash) -> Self { item.0 } @@ -60,11 +58,11 @@ impl From for FieldElement { impl CairoSerde for ClassHash { type RustType = Self; - fn cairo_serialize(rust: &Self::RustType) -> Vec { - FieldElement::cairo_serialize(&rust.0) + fn cairo_serialize(rust: &Self::RustType) -> Vec { + Felt::cairo_serialize(&rust.0) } - fn cairo_deserialize(felts: &[FieldElement], offset: usize) -> Result { + fn cairo_deserialize(felts: &[Felt], offset: usize) -> Result { if offset >= felts.len() { return Err(Error::Deserialize(format!( "Buffer too short to deserialize a ClassHash: offset ({}) : buffer {:?}", @@ -72,21 +70,21 @@ impl CairoSerde for ClassHash { ))); } - Ok(ClassHash(FieldElement::cairo_deserialize(felts, offset)?)) + Ok(ClassHash(Felt::cairo_deserialize(felts, offset)?)) } } /// EthAddress. #[derive(Debug, Copy, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] -pub struct EthAddress(pub FieldElement); +pub struct EthAddress(pub Felt); -impl From for EthAddress { - fn from(item: FieldElement) -> Self { +impl From for EthAddress { + fn from(item: Felt) -> Self { Self(item) } } -impl From for FieldElement { +impl From for Felt { fn from(item: EthAddress) -> Self { item.0 } @@ -95,11 +93,11 @@ impl From for FieldElement { impl CairoSerde for EthAddress { type RustType = Self; - fn cairo_serialize(rust: &Self::RustType) -> Vec { - FieldElement::cairo_serialize(&rust.0) + fn cairo_serialize(rust: &Self::RustType) -> Vec { + Felt::cairo_serialize(&rust.0) } - fn cairo_deserialize(felts: &[FieldElement], offset: usize) -> Result { + fn cairo_deserialize(felts: &[Felt], offset: usize) -> Result { if offset >= felts.len() { return Err(Error::Deserialize(format!( "Buffer too short to deserialize an EthAddress: offset ({}) : buffer {:?}", @@ -107,7 +105,7 @@ impl CairoSerde for EthAddress { ))); } - Ok(EthAddress(FieldElement::cairo_deserialize(felts, offset)?)) + Ok(EthAddress(Felt::cairo_deserialize(felts, offset)?)) } } @@ -117,64 +115,64 @@ mod tests { #[test] fn test_contract_address_cairo_serialize() { - let contract_address = ContractAddress(FieldElement::from(1_u32)); + let contract_address = ContractAddress(Felt::from(1_u32)); let felts = ContractAddress::cairo_serialize(&contract_address); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::from(1_u32)); + assert_eq!(felts[0], Felt::from(1_u32)); } #[test] fn test_contract_address_cairo_deserialize() { - let felts = vec![FieldElement::from(1_u32)]; + let felts = vec![Felt::from(1_u32)]; let contract_address = ContractAddress::cairo_deserialize(&felts, 0).unwrap(); - assert_eq!(contract_address, ContractAddress(FieldElement::from(1_u32))) + assert_eq!(contract_address, ContractAddress(Felt::from(1_u32))) } #[test] fn test_class_hash_cairo_serialize() { - let class_hash = ClassHash(FieldElement::from(1_u32)); + let class_hash = ClassHash(Felt::from(1_u32)); let felts = ClassHash::cairo_serialize(&class_hash); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::from(1_u32)); + assert_eq!(felts[0], Felt::from(1_u32)); } #[test] fn test_class_hash_cairo_deserialize() { - let felts = vec![FieldElement::from(1_u32)]; + let felts = vec![Felt::from(1_u32)]; let class_hash = ClassHash::cairo_deserialize(&felts, 0).unwrap(); - assert_eq!(class_hash, ClassHash(FieldElement::from(1_u32))) + assert_eq!(class_hash, ClassHash(Felt::from(1_u32))) } #[test] fn test_eth_address_cairo_serialize() { - let eth_address = EthAddress(FieldElement::from(1_u32)); + let eth_address = EthAddress(Felt::from(1_u32)); let felts = EthAddress::cairo_serialize(ð_address); assert_eq!(felts.len(), 1); - assert_eq!(felts[0], FieldElement::from(1_u32)); + assert_eq!(felts[0], Felt::from(1_u32)); } #[test] fn test_eth_address_cairo_deserialize() { - let felts = vec![FieldElement::from(1_u32)]; + let felts = vec![Felt::from(1_u32)]; let eth_address = EthAddress::cairo_deserialize(&felts, 0).unwrap(); - assert_eq!(eth_address, EthAddress(FieldElement::from(1_u32))) + assert_eq!(eth_address, EthAddress(Felt::from(1_u32))) } #[test] fn test_contract_address_from() { - let contract_address = ContractAddress::from(FieldElement::from(1_u32)); - assert_eq!(contract_address, ContractAddress(FieldElement::from(1_u32))) + let contract_address = ContractAddress::from(Felt::from(1_u32)); + assert_eq!(contract_address, ContractAddress(Felt::from(1_u32))) } #[test] fn test_class_hash_from() { - let class_hash = ClassHash::from(FieldElement::from(1_u32)); - assert_eq!(class_hash, ClassHash(FieldElement::from(1_u32))) + let class_hash = ClassHash::from(Felt::from(1_u32)); + assert_eq!(class_hash, ClassHash(Felt::from(1_u32))) } #[test] fn test_eth_address_from() { - let eth_address = EthAddress::from(FieldElement::from(1_u32)); - assert_eq!(eth_address, EthAddress(FieldElement::from(1_u32))) + let eth_address = EthAddress::from(Felt::from(1_u32)); + assert_eq!(eth_address, EthAddress(Felt::from(1_u32))) } } diff --git a/crates/cairo-serde/src/types/tuple.rs b/crates/cairo-serde/src/types/tuple.rs index dd4eb9b..482a4e1 100644 --- a/crates/cairo-serde/src/types/tuple.rs +++ b/crates/cairo-serde/src/types/tuple.rs @@ -1,6 +1,6 @@ //! CairoSerde implementation for tuples. use crate::{CairoSerde, Result}; -use starknet::core::types::FieldElement; +use starknet::core::types::Felt; impl CairoSerde for () { type RustType = Self; @@ -10,11 +10,11 @@ impl CairoSerde for () { 0 } - fn cairo_serialize(_rust: &Self::RustType) -> Vec { + fn cairo_serialize(_rust: &Self::RustType) -> Vec { vec![] } - fn cairo_deserialize(_felts: &[FieldElement], _offset: usize) -> Result { + fn cairo_deserialize(_felts: &[Felt], _offset: usize) -> Result { Ok(()) } } @@ -39,15 +39,15 @@ macro_rules! impl_tuples { size } - fn cairo_serialize(rust: &Self::RustType) -> Vec { - let mut out: Vec = vec![]; + fn cairo_serialize(rust: &Self::RustType) -> Vec { + let mut out: Vec = vec![]; $( out.extend($ty::cairo_serialize(& rust.$no)); )* out } - fn cairo_deserialize(felts: &[FieldElement], offset: usize) -> Result { + fn cairo_deserialize(felts: &[Felt], offset: usize) -> Result { let mut offset = offset; $( @@ -71,40 +71,42 @@ impl_tuples!(5, A:RA:r0:0, B:RB:r1:1, C:RC:r2:2, D:RD:r3:3, E:RE:r4:4); #[cfg(test)] mod tests { + use starknet::core::types::Felt; + use super::*; #[test] fn test_serialize_tuple2() { - let v = (FieldElement::ONE, 128_u32); - let felts = <(FieldElement, u32)>::cairo_serialize(&v); + let v = (Felt::ONE, 128_u32); + let felts = <(Felt, u32)>::cairo_serialize(&v); assert_eq!(felts.len(), 2); - assert_eq!(felts[0], FieldElement::ONE); - assert_eq!(felts[1], FieldElement::from(128_u32)); + assert_eq!(felts[0], Felt::ONE); + assert_eq!(felts[1], Felt::from(128_u32)); } #[test] fn test_deserialize_tuple2() { - let felts = vec![FieldElement::THREE, 99_u32.into()]; - let vals = <(FieldElement, u32)>::cairo_deserialize(&felts, 0).unwrap(); - assert_eq!(vals.0, FieldElement::THREE); + let felts = vec![Felt::THREE, 99_u32.into()]; + let vals = <(Felt, u32)>::cairo_deserialize(&felts, 0).unwrap(); + assert_eq!(vals.0, Felt::THREE); assert_eq!(vals.1, 99_u32); } #[test] fn test_serialize_tuple2_array() { - let v = (vec![FieldElement::ONE], 128_u32); - let felts = <(Vec, u32)>::cairo_serialize(&v); + let v = (vec![Felt::ONE], 128_u32); + let felts = <(Vec, u32)>::cairo_serialize(&v); assert_eq!(felts.len(), 3); - assert_eq!(felts[0], FieldElement::ONE); - assert_eq!(felts[1], FieldElement::ONE); - assert_eq!(felts[2], FieldElement::from(128_u32)); + assert_eq!(felts[0], Felt::ONE); + assert_eq!(felts[1], Felt::ONE); + assert_eq!(felts[2], Felt::from(128_u32)); } #[test] fn test_deserialize_tuple2_array() { - let felts = vec![FieldElement::ONE, FieldElement::ONE, 99_u32.into()]; - let vals = <(Vec, u32)>::cairo_deserialize(&felts, 0).unwrap(); - assert_eq!(vals.0, vec![FieldElement::ONE]); + let felts = vec![Felt::ONE, Felt::ONE, 99_u32.into()]; + let vals = <(Vec, u32)>::cairo_deserialize(&felts, 0).unwrap(); + assert_eq!(vals.0, vec![Felt::ONE]); assert_eq!(vals.1, 99_u32); } } diff --git a/crates/cairo-serde/src/types/u256.rs b/crates/cairo-serde/src/types/u256.rs index ab2ce35..f5e7f62 100644 --- a/crates/cairo-serde/src/types/u256.rs +++ b/crates/cairo-serde/src/types/u256.rs @@ -1,5 +1,5 @@ use crate::CairoSerde; -use starknet::core::types::{FieldElement, ValueOutOfRangeError}; +use starknet::core::types::Felt; use std::cmp::Ordering; #[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)] @@ -27,23 +27,28 @@ impl CairoSerde for U256 { fn cairo_serialized_size(this: &U256) -> usize { u128::cairo_serialized_size(&this.low) + u128::cairo_serialized_size(&this.high) } - fn cairo_serialize(this: &U256) -> Vec { + fn cairo_serialize(this: &U256) -> Vec { [ u128::cairo_serialize(&this.low), u128::cairo_serialize(&this.high), ] .concat() } - fn cairo_deserialize(felts: &[FieldElement], offset: usize) -> Result { + fn cairo_deserialize(felts: &[Felt], offset: usize) -> Result { let low = u128::cairo_deserialize(felts, offset)?; let high = u128::cairo_deserialize(felts, offset + u128::cairo_serialized_size(&low))?; Ok(U256 { low, high }) } } -/// FieldElement to U256 conversion as if the tuple was a cairo serialized U256 -impl TryFrom<(FieldElement, FieldElement)> for U256 { + +#[derive(Debug, thiserror::Error)] +#[error("Value out of range")] +pub struct ValueOutOfRangeError; + +/// Felt to U256 conversion as if the tuple was a cairo serialized U256 +impl TryFrom<(Felt, Felt)> for U256 { type Error = ValueOutOfRangeError; - fn try_from((a, b): (FieldElement, FieldElement)) -> Result { + fn try_from((a, b): (Felt, Felt)) -> Result { let U256 { low: a_low, high: a_high, @@ -90,7 +95,6 @@ impl U256 { #[cfg(test)] mod tests { use super::*; - use starknet::core::types::FieldElement; #[test] fn test_serialize_u256() { @@ -98,8 +102,8 @@ mod tests { let high = 8_u128; let felts = U256::cairo_serialize(&U256 { low, high }); assert_eq!(felts.len(), 2); - assert_eq!(felts[0], FieldElement::from(9_u128)); - assert_eq!(felts[1], FieldElement::from(8_u128)); + assert_eq!(felts[0], Felt::from(9_u128)); + assert_eq!(felts[1], Felt::from(8_u128)); } #[test] @@ -108,8 +112,8 @@ mod tests { let high = u128::MAX; let felts = U256::cairo_serialize(&U256 { low, high }); assert_eq!(felts.len(), 2); - assert_eq!(felts[0], FieldElement::from(u128::MAX)); - assert_eq!(felts[1], FieldElement::from(u128::MAX)); + assert_eq!(felts[0], Felt::from(u128::MAX)); + assert_eq!(felts[1], Felt::from(u128::MAX)); } #[test] @@ -118,13 +122,13 @@ mod tests { let high = u128::MIN; let felts = U256::cairo_serialize(&U256 { low, high }); assert_eq!(felts.len(), 2); - assert_eq!(felts[0], FieldElement::from(u128::MIN)); - assert_eq!(felts[1], FieldElement::from(u128::MIN)); + assert_eq!(felts[0], Felt::from(u128::MIN)); + assert_eq!(felts[1], Felt::from(u128::MIN)); } #[test] fn test_deserialize_u256() { - let felts = vec![FieldElement::from(9_u128), FieldElement::from(8_u128)]; + let felts = vec![Felt::from(9_u128), Felt::from(8_u128)]; let num_u256 = U256::cairo_deserialize(&felts, 0).unwrap(); assert_eq!(num_u256.low, 9_u128); assert_eq!(num_u256.high, 8_u128); @@ -191,7 +195,7 @@ mod tests { #[test] fn test_from_field_element() { - let felts = (FieldElement::from(9_u128), FieldElement::from(8_u128)); + let felts = (Felt::from(9_u128), Felt::from(8_u128)); let u256 = U256::try_from(felts).unwrap(); assert_eq!(u256.low, 9_u128); assert_eq!(u256.high, 8_u128); diff --git a/crates/rs-macro/README.md b/crates/rs-macro/README.md index 50d7632..93e5206 100644 --- a/crates/rs-macro/README.md +++ b/crates/rs-macro/README.md @@ -89,7 +89,7 @@ The expansion of the macros generates the following: // This will generate a rust struct with the make `MyStruct`: MyStruct { - a: starknet::core::types::FieldElement, + a: starknet::core::types::Felt, a: U256, // Note the `PascalCase` here. As `u256` is a struct, it follows the common rule. } ``` @@ -97,16 +97,16 @@ The expansion of the macros generates the following: - **Contract** type with the identifier of your choice (`MyContract` in the previous example). This type contains all the functions (externals and views) of your contract being exposed in the ABI. To initialize this type, you need the contract address and any type that implements `ConnectedAccount` from `starknet-rs`. Remember that `Arc` also implements `ConnectedAccount`. ```rust let account = SingleOwnerAccount::new(...); - let contract_address = FieldElement::from_hex_be("0x1234..."); + let contract_address = Felt::from_hex("0x1234..."); let contract = MyContract::new(contract_address, account); ``` - **Contract Reader** type with the identifier of your choice with the suffix `Reader` (`MyContractReader`) in the previous example. The reader contains only the views of your contract. To initialize a reader, you need the contract address and a provider from `starknet-rs`. ```rust let provider = AnyProvider::JsonRpcHttp(...); - let contract_address = FieldElement::from_hex_be("0x1234..."); + let contract_address = Felt::from_hex("0x1234..."); let contract_reader = MyContractReader::new(contract_address, &provider); ``` -- For each **view**, the contract type and the contract reader type contain a function with the exact same arguments. Calling the function returns a `cainome_cairo_serde::call::FCall` struct to allow you to customize how you want the function to be called. Currently, the only setting is the `block_id`. Finally, to actually do the RPC call, you have to use `call()` method on the `FCall` struct. +- For each **view**, the contract type and the contract reader type contain a function with the exact same arguments. Calling the function returns a `cainome_cairo_serde::call::FCall` struct to allow you to customize how you want the function to be called. Currently, the only setting is the `block_id`. Finally, to actually do the RPC call, you have to use `call()` method on the `FCall` struct. The default `block_id` value is `BlockTag::Pending`. ```rust let my_struct = contract @@ -116,11 +116,11 @@ The expansion of the macros generates the following: .await .expect("Call to `get_my_struct` failed"); ``` -- For each **external**, the contract type contains a function with the same arguments. Calling the function return a `starknet::accounts::Execution` type from `starknet-rs`, which allows you to completly customize the fees, doing only a simulation etc... To actually send the transaction, you use the `send()` method on the `Execution` struct. You can find the [associated methods with this struct on starknet-rs repo](https://github.com/xJonathanLEI/starknet-rs/blob/0df9ad3417a5f10d486348737fe75659ca4bcfdc/starknet-accounts/src/account/execution.rs#L118). +- For each **external**, the contract type contains a function with the same arguments. Calling the function return a `starknet::accounts::ExecutionV1` type from `starknet-rs`, which allows you to completly customize the fees, doing only a simulation etc... To actually send the transaction, you use the `send()` method on the `ExecutionV1` struct. You can find the [associated methods with this struct on starknet-rs repo](https://github.com/xJonathanLEI/starknet-rs/blob/0df9ad3417a5f10d486348737fe75659ca4bcfdc/starknet-accounts/src/account/execution.rs#L118). ```rust let my_struct = MyStruct { - a: FieldElement::ONE, + a: Felt::ONE, b: U256 { low: 1, high: 0, @@ -135,12 +135,12 @@ The expansion of the macros generates the following: .expect("Call to `set_my_struct` failed"); ``` - To support multicall, currently `Execution` type does not expose the `Call`s. + To support multicall, currently `ExecutionV1` type does not expose the `Call`s. To circumvey this, for each of the external function an other function with `_getcall` suffix is generated: ```rust // Gather the `Call`s. - let set_a_call = contract.set_a_getcall(&FieldElement::ONE); + let set_a_call = contract.set_a_getcall(&Felt::ONE); let set_b_call = contract.set_b_getcall(&U256 { low: 0xff, high: 0 }); // Then use the account exposed by the `MyContract` type to realize the multicall. @@ -191,7 +191,7 @@ The expansion of the macros generates the following: ```rust pub struct GetBlockhashRegistryOutput { - pub address: starknet::core::types::FieldElement, + pub address: starknet::core::types::Felt, } ``` diff --git a/crates/rs/src/expand/contract.rs b/crates/rs/src/expand/contract.rs index 63b8984..8405bc8 100644 --- a/crates/rs/src/expand/contract.rs +++ b/crates/rs/src/expand/contract.rs @@ -18,17 +18,17 @@ impl CairoContract { #[derive(Debug)] pub struct #contract_name { - pub address: #snrs_types::FieldElement, + pub address: #snrs_types::Felt, pub account: A, pub block_id: #snrs_types::BlockId, } impl #contract_name { - pub fn new(address: #snrs_types::FieldElement, account: A) -> Self { + pub fn new(address: #snrs_types::Felt, account: A) -> Self { Self { address, account, block_id: #snrs_types::BlockId::Tag(#snrs_types::BlockTag::Pending) } } - pub fn set_contract_address(&mut self, address: #snrs_types::FieldElement) { + pub fn set_contract_address(&mut self, address: #snrs_types::Felt) { self.address = address; } @@ -47,20 +47,20 @@ impl CairoContract { #[derive(Debug)] pub struct #reader { - pub address: #snrs_types::FieldElement, + pub address: #snrs_types::Felt, pub provider: P, pub block_id: #snrs_types::BlockId, } impl #reader

{ pub fn new( - address: #snrs_types::FieldElement, + address: #snrs_types::Felt, provider: P, ) -> Self { Self { address, provider, block_id: #snrs_types::BlockId::Tag(#snrs_types::BlockTag::Pending) } } - pub fn set_contract_address(&mut self, address: #snrs_types::FieldElement) { + pub fn set_contract_address(&mut self, address: #snrs_types::Felt) { self.address = address; } diff --git a/crates/rs/src/expand/enum.rs b/crates/rs/src/expand/enum.rs index 2b63d61..7f1ba66 100644 --- a/crates/rs/src/expand/enum.rs +++ b/crates/rs/src/expand/enum.rs @@ -162,14 +162,16 @@ impl CairoEnum { } } - fn cairo_serialize(__rust: &Self::RustType) -> Vec { + fn cairo_serialize(__rust: &Self::RustType) -> Vec { match __rust { #(#serializations),* } } - fn cairo_deserialize(__felts: &[starknet::core::types::FieldElement], __offset: usize) -> #ccs::Result { - let __index:u128 = __felts[__offset].try_into().unwrap(); + fn cairo_deserialize(__felts: &[starknet::core::types::Felt], __offset: usize) -> #ccs::Result { + let __f = __felts[__offset]; + let __index = u128::from_be_bytes(__f.to_bytes_be()[16..].try_into().unwrap()); + match __index as usize { #(#deserializations),* } diff --git a/crates/rs/src/expand/function.rs b/crates/rs/src/expand/function.rs index 88f3658..a360d8a 100644 --- a/crates/rs/src/expand/function.rs +++ b/crates/rs/src/expand/function.rs @@ -12,7 +12,7 @@ //! based on it's state mutability found in the ABI itself. //! //! * `FCall` - Struct for readonly functions. -//! * `Execution` - Struct from starknet-rs for transaction based functions. +//! * `ExecutionV1` - Struct from starknet-rs for transaction based functions. use cainome_parser::tokens::{Function, FunctionOutputKind, StateMutability, Token}; use proc_macro2::TokenStream as TokenStream2; use quote::quote; @@ -102,7 +102,7 @@ impl CairoFunction { } }, StateMutability::External => { - // For now, Execution can't return the list of calls. + // For now, ExecutionV1 can't return the list of calls. // This would be helpful to easily access the calls // without having to add `_getcall()` method. // If starknet-rs provides a way to get the calls, @@ -133,7 +133,7 @@ impl CairoFunction { pub fn #func_name_ident( &self, #(#inputs),* - ) -> starknet::accounts::Execution { + ) -> starknet::accounts::ExecutionV1 { use #ccs::CairoSerde; let mut __calldata = vec![]; @@ -145,7 +145,7 @@ impl CairoFunction { calldata: __calldata, }; - self.account.execute(vec![__call]) + self.account.execute_v1(vec![__call]) } } } diff --git a/crates/rs/src/expand/struct.rs b/crates/rs/src/expand/struct.rs index 748021c..c77edd5 100644 --- a/crates/rs/src/expand/struct.rs +++ b/crates/rs/src/expand/struct.rs @@ -184,13 +184,13 @@ impl CairoStruct { __size } - fn cairo_serialize(__rust: &Self::RustType) -> Vec { - let mut __out: Vec = vec![]; + fn cairo_serialize(__rust: &Self::RustType) -> Vec { + let mut __out: Vec = vec![]; #(#sers)* __out } - fn cairo_deserialize(__felts: &[starknet::core::types::FieldElement], __offset: usize) -> #ccs::Result { + fn cairo_deserialize(__felts: &[starknet::core::types::Felt], __offset: usize) -> #ccs::Result { let mut __offset = __offset; #(#desers)* Ok(#struct_name { diff --git a/crates/rs/src/expand/types.rs b/crates/rs/src/expand/types.rs index b637283..e400df2 100644 --- a/crates/rs/src/expand/types.rs +++ b/crates/rs/src/expand/types.rs @@ -121,8 +121,8 @@ fn basic_types_to_rust(type_name: &str) -> String { "ClassHash" => format!("{ccsp}::ClassHash"), "ContractAddress" => format!("{ccsp}::ContractAddress"), "EthAddress" => format!("{ccsp}::EthAddress"), - "felt252" => "starknet::core::types::FieldElement".to_string(), - "felt" => "starknet::core::types::FieldElement".to_string(), + "felt252" => "starknet::core::types::Felt".to_string(), + "felt" => "starknet::core::types::Felt".to_string(), "bytes31" => format!("{ccsp}::Bytes31"), "ByteArray" => format!("{ccsp}::ByteArray"), "NonZero" => format!("{ccsp}::NonZero"), diff --git a/examples/byte_array.rs b/examples/byte_array.rs index 74932b1..0c49fc5 100644 --- a/examples/byte_array.rs +++ b/examples/byte_array.rs @@ -2,7 +2,7 @@ use cainome::cairo_serde::ByteArray; use cainome::rs::abigen; use starknet::{ accounts::{ExecutionEncoding, SingleOwnerAccount}, - core::types::FieldElement, + core::types::Felt, providers::{jsonrpc::HttpTransport, AnyProvider, JsonRpcClient}, signers::{LocalWallet, SigningKey}, }; @@ -22,18 +22,18 @@ async fn main() { let provider = AnyProvider::JsonRpcHttp(JsonRpcClient::new(HttpTransport::new(rpc_url.clone()))); - let contract_address = FieldElement::from_hex_be(CONTRACT_ADDRESS).unwrap(); + let contract_address = Felt::from_hex(CONTRACT_ADDRESS).unwrap(); let signer = LocalWallet::from(SigningKey::from_secret_scalar( - FieldElement::from_hex_be(KATANA_PRIVKEY_0).unwrap(), + Felt::from_hex(KATANA_PRIVKEY_0).unwrap(), )); - let address = FieldElement::from_hex_be(KATANA_ACCOUNT_0).unwrap(); + let address = Felt::from_hex(KATANA_ACCOUNT_0).unwrap(); let account = Arc::new(SingleOwnerAccount::new( provider, signer, address, - FieldElement::from_hex_be(KATANA_CHAIN_ID).unwrap(), + Felt::from_hex(KATANA_CHAIN_ID).unwrap(), ExecutionEncoding::New, )); diff --git a/examples/components_events.rs b/examples/components_events.rs index 4082b6d..0c79da8 100644 --- a/examples/components_events.rs +++ b/examples/components_events.rs @@ -1,7 +1,7 @@ use cainome::rs::abigen; // use starknet::{ // accounts::{Account, ConnectedAccount, ExecutionEncoding, SingleOwnerAccount}, -// core::types::{BlockId, BlockTag, FieldElement}, +// core::types::{BlockId, BlockTag, Felt}, // providers::{jsonrpc::HttpTransport, AnyProvider, JsonRpcClient}, // signers::{LocalWallet, SigningKey}, // }; diff --git a/examples/opt_res.rs b/examples/opt_res.rs index 7badb43..93f4123 100644 --- a/examples/opt_res.rs +++ b/examples/opt_res.rs @@ -1,7 +1,7 @@ use cainome::rs::abigen; // use starknet::{ // accounts::{Account, ConnectedAccount, ExecutionEncoding, SingleOwnerAccount}, -// core::types::{BlockId, BlockTag, FieldElement}, +// core::types::{BlockId, BlockTag, Felt}, // providers::{jsonrpc::HttpTransport, AnyProvider, JsonRpcClient}, // signers::{LocalWallet, SigningKey}, // }; diff --git a/examples/simple_get_set.rs b/examples/simple_get_set.rs index cdabb4f..e6a8aa8 100644 --- a/examples/simple_get_set.rs +++ b/examples/simple_get_set.rs @@ -2,7 +2,7 @@ use cainome::cairo_serde::U256; use cainome::rs::abigen; use starknet::{ accounts::{Account, ConnectedAccount, ExecutionEncoding, SingleOwnerAccount}, - core::types::{BlockId, BlockTag, FieldElement}, + core::types::{BlockId, BlockTag, Felt}, providers::{jsonrpc::HttpTransport, AnyProvider, JsonRpcClient}, signers::{LocalWallet, SigningKey}, }; @@ -30,7 +30,7 @@ async fn main() { let provider = AnyProvider::JsonRpcHttp(JsonRpcClient::new(HttpTransport::new(rpc_url.clone()))); - let contract_address = FieldElement::from_hex_be(CONTRACT_ADDRESS).unwrap(); + let contract_address = Felt::from_hex(CONTRACT_ADDRESS).unwrap(); // If you only plan to call views functions, you can use the `Reader`, which // only requires a provider along with your contract address. @@ -62,15 +62,15 @@ async fn main() { // If you want to do some invoke for external functions, you must use an account. let signer = LocalWallet::from(SigningKey::from_secret_scalar( - FieldElement::from_hex_be(KATANA_PRIVKEY_0).unwrap(), + Felt::from_hex(KATANA_PRIVKEY_0).unwrap(), )); - let address = FieldElement::from_hex_be(KATANA_ACCOUNT_0).unwrap(); + let address = Felt::from_hex(KATANA_ACCOUNT_0).unwrap(); let account = Arc::new(SingleOwnerAccount::new( provider, signer, address, - FieldElement::from_hex_be(KATANA_CHAIN_ID).unwrap(), + Felt::from_hex(KATANA_CHAIN_ID).unwrap(), ExecutionEncoding::New, )); @@ -82,7 +82,7 @@ async fn main() { // You can before that configure the fees, or even only run an estimation of the // fees without actually sending the transaction. let _tx_res = contract - .set_a(&(a + FieldElement::ONE)) + .set_a(&(a + Felt::ONE)) .max_fee(1000000000000000_u128.into()) .send() .await @@ -101,7 +101,7 @@ async fn main() { // Now let's say we want to do multicall, and in one transaction we want to set a and b. // You can call the same function name with `_getcall` prefix to get the // call only, ready to be added in a multicall array. - let set_a_call = contract.set_a_getcall(&FieldElement::from_hex_be("0xee").unwrap()); + let set_a_call = contract.set_a_getcall(&Felt::from_hex("0xee").unwrap()); let set_b_call = contract.set_b_getcall(&U256 { low: 0xff, high: 0 }); // Then, we use the account exposed by the contract to execute the multicall. @@ -109,7 +109,7 @@ async fn main() { // the full control from starknet-rs library. let _tx_res = contract .account - .execute(vec![set_a_call, set_b_call]) + .execute_v1(vec![set_a_call, set_b_call]) .send() .await .expect("Multicall failed"); @@ -153,7 +153,7 @@ async fn other_func(contract: Arc(contract: Arc, + pub contract_address: Option, #[arg(long)] #[arg(value_name = "NAME")] diff --git a/src/bin/cli/contract/mod.rs b/src/bin/cli/contract/mod.rs index aa49196..128fe7a 100644 --- a/src/bin/cli/contract/mod.rs +++ b/src/bin/cli/contract/mod.rs @@ -6,7 +6,7 @@ use std::fs; use url::Url; use starknet::{ - core::types::{BlockId, BlockTag, ContractClass, FieldElement}, + core::types::{BlockId, BlockTag, ContractClass, Felt}, providers::{jsonrpc::HttpTransport, AnyProvider, JsonRpcClient, Provider}, }; @@ -18,7 +18,7 @@ pub enum ContractOrigin { /// with the given file name. SierraClassFile(String), /// Contract's ABI was fetched from the given address. - FetchedFromChain(FieldElement), + FetchedFromChain(Felt), } #[derive(Debug)] @@ -116,7 +116,7 @@ impl ContractParser { pub async fn from_chain( name: &str, - address: FieldElement, + address: Felt, rpc_url: Url, type_aliases: &HashMap, ) -> CainomeCliResult {