diff --git a/.github/workflows/check_lint.yml b/.github/workflows/check_lint.yml index 7500a11..e7a7969 100644 --- a/.github/workflows/check_lint.yml +++ b/.github/workflows/check_lint.yml @@ -5,51 +5,64 @@ on: - oss -name: Check and Lint +name: Check and Lint and wasm jobs: check: name: Check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - uses: actions-rs/cargo@v1 - with: - command: check - + - uses: actions/checkout@v3 + - name: Install rust + run: rustup show + - name: Check + run: cargo check + build-wasm: + name: Build wasm + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install rust + working-directory: ./ensure_no_std + run: rustup show + - name: Build wasm + run: cargo build + fmt: name: Rustfmt runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - run: rustup component add rustfmt - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check + - uses: actions/checkout@v3 + - name: Install rust + run: rustup show + - name: Check format + run: cargo fmt --check --all + + clippy-all-features: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install rust + run: rustup show + - name: Clippy all features + run: cargo clippy --all-features + clippy-default-features: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install rust + run: rustup show + - name: Clippy all features + run: cargo clippy - clippy: + clippy-wasm: name: Clippy runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - components: clippy - override: true - - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --all-features - name: Clippy Output \ No newline at end of file + - uses: actions/checkout@v3 + - name: Install rust + run: rustup show + - name: Clippy all features + run: cargo clippy diff --git a/Cargo.lock b/Cargo.lock index bf8dfc7..60660ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,16 +33,16 @@ version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd" dependencies = [ - "getrandom 0.2.11", + "getrandom 0.2.12", "once_cell", "version_check", ] [[package]] name = "ahash" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" dependencies = [ "cfg-if", "once_cell", @@ -91,9 +91,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" [[package]] name = "ark-bls12-377" @@ -348,9 +348,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.5" +version = "0.21.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +checksum = "c79fed4cdb43e993fcdadc7e58a09fd0e3e649c4436fa11da71c9f1f3ee7feb9" [[package]] name = "bigdecimal" @@ -399,7 +399,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.40", + "syn 2.0.48", ] [[package]] @@ -488,7 +488,7 @@ dependencies = [ [[package]] name = "blockifier" version = "0.1.0-rc2" -source = "git+https://github.com/keep-starknet-strange/blockifier?branch=no_std-support-7578442#e7a85edd7078eb25f3f56d82d45be56d617ccc85" +source = "git+https://github.com/keep-starknet-strange/blockifier?branch=no_std-support-7578442#8270582205fb7c2fb81b7e2de1dc46cd9b483d83" dependencies = [ "ark-ff", "ark-secp256k1", @@ -517,7 +517,7 @@ dependencies = [ "sha3", "sp-arithmetic", "spin 0.9.8", - "starknet-crypto", + "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=64ebc36)", "starknet_api", "strum", "strum_macros", @@ -528,21 +528,18 @@ dependencies = [ name = "bonsai-trie" version = "0.1.0" dependencies = [ - "bincode 1.3.3", "bitvec", "derive_more", - "env_logger", + "hashbrown 0.14.3", "log", - "lru 0.12.1", "mp-commitments", "mp-felt", "mp-hashers", "parity-scale-codec", "rand 0.8.5", "rocksdb", - "rustc-hex", "serde", - "smallvec", + "serde_derive", "starknet-types-core", "tempfile", ] @@ -732,7 +729,7 @@ dependencies = [ "serde_json", "sha2 0.10.8", "sha3", - "starknet-crypto", + "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=a35ce22)", "thiserror-no-std", ] @@ -776,9 +773,9 @@ dependencies = [ [[package]] name = "clang-sys" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f" +checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1" dependencies = [ "glob", "libc", @@ -813,12 +810,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd7e35aee659887cbfb97aaf227ac12cad1a9d7c71e55ff3376839ed4e282d08" -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - [[package]] name = "core-foundation-sys" version = "0.8.6" @@ -836,9 +827,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] @@ -861,38 +852,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crossbeam-deque" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fca89a0e215bab21874660c67903c5f143333cab1da83d041c7ded6053774751" -dependencies = [ - "cfg-if", - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d2fe95351b870527a5d09bf563ed3c97c0cffb87cf1c78a591bf48bb218d9aa" -dependencies = [ - "autocfg", - "cfg-if", - "crossbeam-utils", - "memoffset 0.9.0", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d96137f14f244c37f989d9fff8f95e6c18b918e71f36638f8c49112e4c78f" -dependencies = [ - "cfg-if", -] - [[package]] name = "crunchy" version = "0.2.2" @@ -977,7 +936,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.40", + "syn 2.0.48", ] [[package]] @@ -988,14 +947,14 @@ checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core", "quote", - "syn 2.0.40", + "syn 2.0.48", ] [[package]] name = "deranged" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eb30d70a07a3b04884d2677f06bec33509dc67ca60d92949e5535352d3191dc" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ "powerfmt", ] @@ -1017,10 +976,8 @@ version = "0.99.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ - "convert_case", "proc-macro2", "quote", - "rustc_version", "syn 1.0.109", ] @@ -1117,19 +1074,6 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" -[[package]] -name = "env_logger" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" -dependencies = [ - "humantime", - "is-terminal", - "log", - "regex", - "termcolor", -] - [[package]] name = "environmental" version = "1.1.4" @@ -1228,9 +1172,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" dependencies = [ "futures-channel", "futures-core", @@ -1243,9 +1187,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", "futures-sink", @@ -1253,15 +1197,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] name = "futures-executor" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" dependencies = [ "futures-core", "futures-task", @@ -1271,38 +1215,38 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-macro" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.40", + "syn 2.0.48", ] [[package]] name = "futures-sink" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" [[package]] name = "futures-task" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-util" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-channel", "futures-core", @@ -1348,9 +1292,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "js-sys", @@ -1415,7 +1359,7 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ - "ahash 0.8.6", + "ahash 0.8.7", ] [[package]] @@ -1424,7 +1368,7 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" dependencies = [ - "ahash 0.8.6", + "ahash 0.8.7", "allocator-api2", "serde", ] @@ -1466,17 +1410,11 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "iana-time-zone" -version = "0.1.58" +version = "0.1.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" +checksum = "b6a67363e2aa4443928ce15e57ebae94fd8949958fd1223c4cfc0cd473ad7539" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -1605,17 +1543,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "is-terminal" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" -dependencies = [ - "hermit-abi", - "rustix 0.38.28", - "windows-sys 0.48.0", -] - [[package]] name = "itertools" version = "0.10.5" @@ -1660,25 +1587,24 @@ dependencies = [ [[package]] name = "lambdaworks-crypto" -version = "0.3.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79e0b347cdcff23c4b1f2a14ca475f6214106130e8c1df955352ddb01a37b8e8" +checksum = "2d4c222d5b2fdc0faf702d3ab361d14589b097f40eac9dc550e27083483edc65" dependencies = [ "lambdaworks-math", "serde", "sha2 0.10.8", "sha3", - "thiserror", ] [[package]] name = "lambdaworks-math" -version = "0.3.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "540c0715d7da472edc421ceca702d3f3a716b3b9168b6211f2e3939cb14c863c" +checksum = "9ee7dcab3968c71896b8ee4dc829147acc918cffe897af6265b1894527fe3add" dependencies = [ - "rayon", - "thiserror", + "serde", + "serde_json", ] [[package]] @@ -1698,18 +1624,18 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.151" +version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" [[package]] name = "libloading" -version = "0.7.4" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" dependencies = [ "cfg-if", - "winapi", + "windows-sys 0.48.0", ] [[package]] @@ -1776,9 +1702,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.12" +version = "1.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d97137b25e321a73eef1418d1d5d2eda4d77e12813f8e6dead84bc52c5870a7b" +checksum = "295c17e837573c8c821dbaeb3cceb3d745ad082f7572191409e69cbc1b3fd050" dependencies = [ "cc", "pkg-config", @@ -1822,15 +1748,6 @@ dependencies = [ "hashbrown 0.12.3", ] -[[package]] -name = "lru" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2994eeba8ed550fd9b47a0b38f0242bc3344e496483c6180b69139cc2fa5d1d7" -dependencies = [ - "hashbrown 0.14.3", -] - [[package]] name = "lz4-sys" version = "1.9.4" @@ -1861,9 +1778,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.6.4" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "memfd" @@ -1883,15 +1800,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "memoffset" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" -dependencies = [ - "autocfg", -] - [[package]] name = "merlin" version = "2.0.1" @@ -1941,7 +1849,7 @@ dependencies = [ "mp-felt", "mp-hashers", "mp-transactions", - "starknet-crypto", + "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=a35ce22)", "starknet_api", ] @@ -1969,7 +1877,7 @@ dependencies = [ "scale-info", "serde", "sp-core", - "starknet-ff", + "starknet-ff 0.3.5 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=a35ce22)", "starknet_api", "thiserror-no-std", ] @@ -1984,7 +1892,7 @@ dependencies = [ "scale-info", "serde", "starknet-core", - "starknet-crypto", + "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=a35ce22)", ] [[package]] @@ -2015,8 +1923,8 @@ dependencies = [ "serde", "serde_json", "starknet-core", - "starknet-crypto", - "starknet-ff", + "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=a35ce22)", + "starknet-ff 0.3.5 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=a35ce22)", "starknet_api", ] @@ -2082,7 +1990,7 @@ checksum = "5f4e3bc495f6e95bc15a6c0c55ac00421504a5a43d09e3cc455d1fea7015581d" dependencies = [ "bitvec", "either", - "lru 0.7.8", + "lru", "num-bigint", "num-integer", "num-modular", @@ -2255,7 +2163,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.40", + "syn 2.0.48", ] [[package]] @@ -2281,9 +2189,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" [[package]] name = "powerfmt" @@ -2299,12 +2207,12 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "prettyplease" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" +checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" dependencies = [ "proc-macro2", - "syn 2.0.40", + "syn 2.0.48", ] [[package]] @@ -2342,9 +2250,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" dependencies = [ "unicode-ident", ] @@ -2360,9 +2268,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -2432,7 +2340,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.11", + "getrandom 0.2.12", ] [[package]] @@ -2444,26 +2352,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "rayon" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", -] - [[package]] name = "redox_syscall" version = "0.4.1" @@ -2475,22 +2363,22 @@ dependencies = [ [[package]] name = "ref-cast" -version = "1.0.20" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acde58d073e9c79da00f2b5b84eed919c8326832648a5b109b3fce1bb1175280" +checksum = "c4846d4c50d1721b1a3bef8af76924eef20d5e723647333798c1b519b3a9473f" dependencies = [ "ref-cast-impl", ] [[package]] name = "ref-cast-impl" -version = "1.0.20" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7473c2cfcf90008193dd0e3e16599455cb601a9fce322b5bb55de799664925" +checksum = "5fddb4f8d99b0a2ebafc65a87a69a7b9875e4b1ae1f00db265d300ef7f28bccc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.40", + "syn 2.0.48", ] [[package]] @@ -2718,35 +2606,35 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.40", + "syn 2.0.48", ] [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" dependencies = [ "itoa", "ryu", @@ -2788,7 +2676,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.40", + "syn 2.0.48", ] [[package]] @@ -2954,7 +2842,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "proc-macro2", "quote", - "syn 2.0.40", + "syn 2.0.48", ] [[package]] @@ -2995,7 +2883,7 @@ dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.40", + "syn 2.0.48", ] [[package]] @@ -3055,9 +2943,9 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "ss58-registry" -version = "1.44.0" +version = "1.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35935738370302d5e33963665b77541e4b990a3e919ec904c837a56cfc891de1" +checksum = "3c0c74081753a8ce1c8eb10b9f262ab6f7017e5ad3317c17a54c7ab65fcb3c6e" dependencies = [ "Inflector", "num-format", @@ -3079,7 +2967,7 @@ name = "starknet-core" version = "0.7.2" source = "git+https://github.com/xJonathanLEI/starknet-rs.git?rev=a35ce22#a35ce22be52bf33b8e544d0df926031b0ec7d761" dependencies = [ - "base64 0.21.5", + "base64 0.21.6", "flate2", "hex", "serde", @@ -3087,8 +2975,26 @@ dependencies = [ "serde_json_pythonic", "serde_with", "sha3", - "starknet-crypto", - "starknet-ff", + "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=a35ce22)", + "starknet-ff 0.3.5 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=a35ce22)", +] + +[[package]] +name = "starknet-crypto" +version = "0.6.1" +source = "git+https://github.com/xJonathanLEI/starknet-rs.git?rev=64ebc36#64ebc364c0c346e81b715c5b4a3b32ef37b055c8" +dependencies = [ + "crypto-bigint", + "hmac 0.12.1", + "num-bigint", + "num-integer", + "num-traits", + "rfc6979", + "sha2 0.10.8", + "starknet-crypto-codegen 0.3.2 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=64ebc36)", + "starknet-curve 0.4.0 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=64ebc36)", + "starknet-ff 0.3.5 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=64ebc36)", + "zeroize", ] [[package]] @@ -3104,20 +3010,38 @@ dependencies = [ "num-traits", "rfc6979", "sha2 0.10.8", - "starknet-crypto-codegen", - "starknet-curve", - "starknet-ff", + "starknet-crypto-codegen 0.3.2 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=a35ce22)", + "starknet-curve 0.4.0 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=a35ce22)", + "starknet-ff 0.3.5 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=a35ce22)", "zeroize", ] +[[package]] +name = "starknet-crypto-codegen" +version = "0.3.2" +source = "git+https://github.com/xJonathanLEI/starknet-rs.git?rev=64ebc36#64ebc364c0c346e81b715c5b4a3b32ef37b055c8" +dependencies = [ + "starknet-curve 0.4.0 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=64ebc36)", + "starknet-ff 0.3.5 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=64ebc36)", + "syn 2.0.48", +] + [[package]] name = "starknet-crypto-codegen" version = "0.3.2" source = "git+https://github.com/xJonathanLEI/starknet-rs.git?rev=a35ce22#a35ce22be52bf33b8e544d0df926031b0ec7d761" dependencies = [ - "starknet-curve", - "starknet-ff", - "syn 2.0.40", + "starknet-curve 0.4.0 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=a35ce22)", + "starknet-ff 0.3.5 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=a35ce22)", + "syn 2.0.48", +] + +[[package]] +name = "starknet-curve" +version = "0.4.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs.git?rev=64ebc36#64ebc364c0c346e81b715c5b4a3b32ef37b055c8" +dependencies = [ + "starknet-ff 0.3.5 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=64ebc36)", ] [[package]] @@ -3125,7 +3049,18 @@ name = "starknet-curve" version = "0.4.0" source = "git+https://github.com/xJonathanLEI/starknet-rs.git?rev=a35ce22#a35ce22be52bf33b8e544d0df926031b0ec7d761" dependencies = [ - "starknet-ff", + "starknet-ff 0.3.5 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=a35ce22)", +] + +[[package]] +name = "starknet-ff" +version = "0.3.5" +source = "git+https://github.com/xJonathanLEI/starknet-rs.git?rev=64ebc36#64ebc364c0c346e81b715c5b4a3b32ef37b055c8" +dependencies = [ + "ark-ff", + "crypto-bigint", + "getrandom 0.2.12", + "hex", ] [[package]] @@ -3136,16 +3071,16 @@ dependencies = [ "ark-ff", "bigdecimal", "crypto-bigint", - "getrandom 0.2.11", + "getrandom 0.2.12", "hex", "serde", ] [[package]] name = "starknet-types-core" -version = "0.0.5" +version = "0.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2441eb61d91a6bae832fda48e50b6ff09faa6cf63bfadd22dc16798d2cc024d" +checksum = "6d791c671fecde494f435170a01c6fcb2949d0dd61be0b31b7c410b041609f96" dependencies = [ "bitvec", "lambdaworks-crypto", @@ -3161,7 +3096,7 @@ dependencies = [ [[package]] name = "starknet_api" version = "0.4.1" -source = "git+https://github.com/keep-starknet-strange/starknet-api?branch=no_std-support-dc83f05#60e13594b5d3560ad3a6439c5dc6807e5f425866" +source = "git+https://github.com/keep-starknet-strange/starknet-api?branch=no_std-support-dc83f05#3415c832bb0cd72d1764dcd9ce803ddf932895ef" dependencies = [ "cairo-lang-casm-contract-class", "derive_more", @@ -3174,7 +3109,7 @@ dependencies = [ "scale-info", "serde", "serde_json", - "starknet-crypto", + "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=64ebc36)", "thiserror-no-std", ] @@ -3241,9 +3176,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.40" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13fa70a4ee923979ffb522cacce59d34421ebdea5625e1073c4326ef9d2dd42e" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -3258,50 +3193,41 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "target-lexicon" -version = "0.12.12" +version = "0.12.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a" +checksum = "69758bda2e78f098e4ccb393021a0963bb3442eac05f135c30f61b7370bbafae" [[package]] name = "tempfile" -version = "3.8.1" +version = "3.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" +checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" dependencies = [ "cfg-if", "fastrand", "redox_syscall", "rustix 0.38.28", - "windows-sys 0.48.0", -] - -[[package]] -name = "termcolor" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449" -dependencies = [ - "winapi-util", + "windows-sys 0.52.0", ] [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.40", + "syn 2.0.48", ] [[package]] @@ -3336,9 +3262,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" +checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" dependencies = [ "deranged", "powerfmt", @@ -3433,7 +3359,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.40", + "syn 2.0.48", ] [[package]] @@ -3632,7 +3558,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.40", + "syn 2.0.48", "wasm-bindgen-shared", ] @@ -3654,7 +3580,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", - "syn 2.0.40", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3785,7 +3711,7 @@ dependencies = [ "log", "mach", "memfd", - "memoffset 0.8.0", + "memoffset", "paste", "rand 0.8.5", "rustix 0.36.17", @@ -3823,15 +3749,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -3840,11 +3757,11 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-core" -version = "0.51.1" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.48.5", + "windows-targets 0.52.0", ] [[package]] @@ -4047,9 +3964,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.26" +version = "0.5.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67b5f0a4e7a27a64c651977932b9dc5667ca7fc31ac44b03ed37a0cf42fdfff" +checksum = "b7520bbdec7211caa7c4e682eb1fbe07abe20cee6756b6e00f537c82c11816aa" dependencies = [ "memchr", ] @@ -4065,22 +3982,22 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.30" +version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "306dca4455518f1f31635ec308b6b3e4eb1b11758cefafc782827d0aa7acb5c7" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.30" +version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be912bf68235a88fbefd1b73415cb218405958d1655b2ece9035a19920bdf6ba" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.40", + "syn 2.0.48", ] [[package]] @@ -4100,7 +4017,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.40", + "syn 2.0.48", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 2c6083a..b3a3df2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,29 +1,44 @@ [package] +edition = "2021" name = "bonsai-trie" version = "0.1.0" -edition = "2021" [features] -default = ["rocksdb"] +default = ["std", "rocksdb"] rocksdb = ["dep:rocksdb"] +std = ["parity-scale-codec/std", "bitvec/std", "starknet-types-core/std"] [dependencies] -parity-scale-codec = { version = "3.0.0", features = ["derive"] } -rocksdb = { optional = true, version = "0.21.0", features = ["multi-threaded-cf"] } -serde = { version = "1.0.193", features = ["derive"] } -bincode = "1.3.3" -log = "0.4.20" -smallvec = "1.11.2" -rustc-hex = "2.1.0" -env_logger = "0.10.1" -lru = "0.12.1" -bitvec = { version = "1" } -derive_more = { version = "0.99.17", features = ["constructor"] } -starknet-types-core = { version = "0.0.5", features=["hash", "parity-scale-codec"] } +bitvec = { version = "1", default-features = false, features = ["alloc"] } +derive_more = { version = "0.99.17", default-features = false, features = [ + "constructor", +] } +hashbrown = { version = "0.14.3", default-features = false, features = [ + "ahash", +] } +parity-scale-codec = { version = "3.0.0", default-features = false, features = [ + "derive", +] } +rocksdb = { optional = true, version = "0.21.0", features = [ + "multi-threaded-cf", +] } +serde = { version = "1.0.195", default-features = false, features = [ + "derive", + "alloc", +] } +serde_derive = "1.0.195" +starknet-types-core = { version = "0.0.7", default-features = false, features = [ + "hash", + "parity-scale-codec", +] } [dev-dependencies] -tempfile = "3.8.0" +log = "0.4.20" mp-commitments = { git = "https://github.com/keep-starknet-strange/madara.git", rev = "f30acea8af7e28e956e771928130e12bfc084832", package = "mp-commitments" } +mp-felt = { git = "https://github.com/keep-starknet-strange/madara.git", rev = "f30acea8af7e28e956e771928130e12bfc084832", package = "mp-felt", features = [ + "parity-scale-codec", + "serde", +] } mp-hashers = { git = "https://github.com/keep-starknet-strange/madara.git", rev = "f30acea8af7e28e956e771928130e12bfc084832", package = "mp-hashers" } -mp-felt = { git = "https://github.com/keep-starknet-strange/madara.git", rev = "f30acea8af7e28e956e771928130e12bfc084832", package = "mp-felt", features = ["parity-scale-codec", "serde"]} rand = "0.8.5" +tempfile = "3.8.0" diff --git a/ensure_no_std/.cargo/config.toml b/ensure_no_std/.cargo/config.toml new file mode 100644 index 0000000..f4e8c00 --- /dev/null +++ b/ensure_no_std/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target = "wasm32-unknown-unknown" diff --git a/ensure_no_std/Cargo.lock b/ensure_no_std/Cargo.lock new file mode 100644 index 0000000..761cfe5 --- /dev/null +++ b/ensure_no_std/Cargo.lock @@ -0,0 +1,524 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" +dependencies = [ + "cfg-if 1.0.0", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bonsai-trie" +version = "0.1.0" +dependencies = [ + "bitvec", + "derive_more", + "hashbrown", + "parity-scale-codec", + "serde", + "serde_derive", + "starknet-types-core", +] + +[[package]] +name = "byte-slice-cast" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "ensure_no_std" +version = "0.1.0" +dependencies = [ + "bonsai-trie", + "wee_alloc", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +dependencies = [ + "ahash", +] + +[[package]] +name = "impl-trait-for-tuples" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "indexmap" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "keccak" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" +dependencies = [ + "cpufeatures", +] + +[[package]] +name = "lambdaworks-crypto" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d4c222d5b2fdc0faf702d3ab361d14589b097f40eac9dc550e27083483edc65" +dependencies = [ + "lambdaworks-math", + "sha2", + "sha3", +] + +[[package]] +name = "lambdaworks-math" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ee7dcab3968c71896b8ee4dc829147acc918cffe897af6265b1894527fe3add" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin", +] + +[[package]] +name = "libc" +version = "0.2.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" + +[[package]] +name = "memchr" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" + +[[package]] +name = "memory_units" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" + +[[package]] +name = "num-bigint" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "parity-scale-codec" +version = "3.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "881331e34fa842a2fb61cc2db9643a8fedc615e47cfcc52597d1af0db9a7e8fe" +dependencies = [ + "arrayvec", + "byte-slice-cast", + "impl-trait-for-tuples", + "parity-scale-codec-derive", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "3.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be30eaf4b0a9fba5336683b38de57bb86d179a35862ba6bfcf57625d006bde5b" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "proc-macro-crate" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97dc5fea232fc28d2f597b37c4876b348a40e33f3b02cc975c8d006d78d94b1a" +dependencies = [ + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "proc-macro2" +version = "1.0.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "serde" +version = "1.0.195" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.195" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest", + "keccak", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "starknet-types-core" +version = "0.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d791c671fecde494f435170a01c6fcb2949d0dd61be0b31b7c410b041609f96" +dependencies = [ + "bitvec", + "lambdaworks-crypto", + "lambdaworks-math", + "lazy_static", + "num-bigint", + "num-integer", + "num-traits", + "parity-scale-codec", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "toml_datetime" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" + +[[package]] +name = "toml_edit" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wee_alloc" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "memory_units", + "winapi", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "winnow" +version = "0.5.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7520bbdec7211caa7c4e682eb1fbe07abe20cee6756b6e00f537c82c11816aa" +dependencies = [ + "memchr", +] + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] diff --git a/ensure_no_std/Cargo.toml b/ensure_no_std/Cargo.toml new file mode 100644 index 0000000..bff67b7 --- /dev/null +++ b/ensure_no_std/Cargo.toml @@ -0,0 +1,15 @@ +[package] +edition = "2021" +name = "ensure_no_std" +version = "0.1.0" + +[dependencies] +bonsai-trie = { path = "../", default-features = false } +wee_alloc = "0.4.5" + + +[profile.dev] +panic = "abort" + +[profile.release] +panic = "abort" diff --git a/ensure_no_std/rust-toolchain.toml b/ensure_no_std/rust-toolchain.toml new file mode 100644 index 0000000..ead536e --- /dev/null +++ b/ensure_no_std/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "stable" +targets = ["wasm32-unknown-unknown"] +profile = "minimal" diff --git a/ensure_no_std/src/main.rs b/ensure_no_std/src/main.rs new file mode 100644 index 0000000..05abacb --- /dev/null +++ b/ensure_no_std/src/main.rs @@ -0,0 +1,21 @@ +#![no_std] +#![no_main] + +use core::panic::PanicInfo; + +/// This function is called on panic. +#[panic_handler] +fn panic(_info: &PanicInfo) -> ! { + loop {} +} + +#[no_mangle] +pub extern "C" fn _start() -> ! { + loop {} +} + +#[global_allocator] +static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; + +#[allow(unused_imports)] +use bonsai_trie; diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..85f3606 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "stable" +components = ["rustfmt", "clippy"] +profile = "minimal" diff --git a/src/bonsai_database.rs b/src/bonsai_database.rs index 6317c78..5c6ddd3 100644 --- a/src/bonsai_database.rs +++ b/src/bonsai_database.rs @@ -1,6 +1,5 @@ -use std::error::Error; - use crate::{changes::ChangeKeyType, error::BonsaiStorageError, id::Id}; +use alloc::vec::Vec; #[derive(Debug, Hash, PartialEq, Eq)] pub enum KeyType<'a> { @@ -31,7 +30,7 @@ impl KeyType<'_> { /// Trait to be implemented on any type that can be used as a database. pub trait BonsaiDatabase { type Batch: Default; - type DatabaseError: Error + Into; + type DatabaseError: Into; /// Create a new empty batch of changes to be used in `insert`, `remove` and applied in database using `write_batch`. fn create_batch(&self) -> Self::Batch; @@ -78,7 +77,7 @@ pub trait BonsaiDatabase { } pub trait BonsaiPersistentDatabase { - type DatabaseError: Error + Into; + type DatabaseError: Into; type Transaction: BonsaiDatabase; /// Save a snapshot of the current database state /// This function returns a snapshot id that can be used to create a transaction diff --git a/src/changes.rs b/src/changes.rs index 1195e48..6617136 100644 --- a/src/changes.rs +++ b/src/changes.rs @@ -1,6 +1,13 @@ use crate::id::Id; +use alloc::vec::Vec; use serde::{Deserialize, Serialize}; -use std::collections::{HashMap, VecDeque}; +#[cfg(feature = "std")] +use std::collections::{hash_map::Entry, HashMap, VecDeque}; +#[cfg(not(feature = "std"))] +use { + alloc::collections::VecDeque, + hashbrown::{hash_map::Entry, HashMap}, +}; #[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct Change { @@ -48,14 +55,14 @@ const OLD_VALUE: u8 = 0x01; impl ChangeBatch { pub fn insert_in_place(&mut self, key: ChangeKeyType, change: Change) { match self.0.entry(key) { - std::collections::hash_map::Entry::Occupied(mut entry) => { + Entry::Occupied(mut entry) => { let e = entry.get_mut(); if e.old_value.is_none() { e.old_value = change.old_value; } e.new_value = change.new_value; } - std::collections::hash_map::Entry::Vacant(entry) => { + Entry::Vacant(entry) => { entry.insert(change); } } diff --git a/src/databases/hashmap_db.rs b/src/databases/hashmap_db.rs index 5a0b8d1..c20054b 100644 --- a/src/databases/hashmap_db.rs +++ b/src/databases/hashmap_db.rs @@ -1,8 +1,10 @@ -use std::{ - collections::{BTreeMap, HashMap}, - error::Error, - fmt::Display, -}; +use alloc::fmt::Display; +use alloc::vec::Vec; +use alloc::{collections::BTreeMap, string::ToString}; +#[cfg(not(feature = "std"))] +use hashbrown::HashMap; +#[cfg(feature = "std")] +use std::collections::HashMap; use crate::{ bonsai_database::BonsaiPersistentDatabase, error::BonsaiStorageError, id::Id, BonsaiDatabase, @@ -12,13 +14,11 @@ use crate::{ pub struct HashMapDbError {} impl Display for HashMapDbError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut alloc::fmt::Formatter<'_>) -> alloc::fmt::Result { write!(f, "") } } -impl Error for HashMapDbError {} - impl From for BonsaiStorageError { fn from(err: HashMapDbError) -> Self { Self::Database(err.to_string()) diff --git a/src/databases/rocks_db.rs b/src/databases/rocks_db.rs index 1739501..47b01b9 100644 --- a/src/databases/rocks_db.rs +++ b/src/databases/rocks_db.rs @@ -5,7 +5,6 @@ use std::{ path::Path, }; -use log::trace; use rocksdb::{ ColumnFamilyDescriptor, ColumnFamilyRef, Direction, Error, IteratorMode, MultiThreaded, OptimisticTransactionDB, OptimisticTransactionOptions, Options, ReadOptions, @@ -71,7 +70,6 @@ impl Default for RocksDBConfig { impl<'db, ID: Id> RocksDB<'db, ID> { /// Creates a new RocksDB wrapper from the given RocksDB database pub fn new(db: &'db OptimisticTransactionDB, config: RocksDBConfig) -> Self { - trace!("RockDB database opened"); Self { db, config, @@ -190,7 +188,6 @@ where value: &[u8], batch: Option<&mut Self::Batch>, ) -> Result>, Self::DatabaseError> { - trace!("Inserting into RocksDB: {:?} {:?}", key, value); let handle_cf = self.db.cf_handle(key.get_cf()).expect(CF_ERROR); let old_value = self.db.get_cf(&handle_cf, key.as_slice())?; if let Some(batch) = batch { @@ -202,7 +199,6 @@ where } fn get(&self, key: &KeyType) -> Result>, Self::DatabaseError> { - trace!("Getting from RocksDB: {:?}", key); let handle = self.db.cf_handle(key.get_cf()).expect(CF_ERROR); Ok(self.db.get_cf(&handle, key.as_slice())?) } @@ -211,7 +207,6 @@ where &self, prefix: &KeyType, ) -> Result, Vec)>, Self::DatabaseError> { - trace!("Getting from RocksDB: {:?}", prefix); let handle = self.db.cf_handle(prefix.get_cf()).expect(CF_ERROR); let iter = self.db.iterator_cf( &handle, @@ -233,7 +228,6 @@ where } fn contains(&self, key: &KeyType) -> Result { - trace!("Checking if RocksDB contains: {:?}", key); let handle = self.db.cf_handle(key.get_cf()).expect(CF_ERROR); Ok(self .db @@ -246,7 +240,6 @@ where key: &KeyType, batch: Option<&mut Self::Batch>, ) -> Result>, Self::DatabaseError> { - trace!("Removing from RocksDB: {:?}", key); let handle = self.db.cf_handle(key.get_cf()).expect(CF_ERROR); let old_value = self.db.get_cf(&handle, key.as_slice())?; if let Some(batch) = batch { @@ -258,7 +251,6 @@ where } fn remove_by_prefix(&mut self, prefix: &KeyType) -> Result<(), Self::DatabaseError> { - trace!("Getting from RocksDB: {:?}", prefix); let handle = self.db.cf_handle(prefix.get_cf()).expect(CF_ERROR); let iter = self.db.iterator_cf( &handle, @@ -332,7 +324,6 @@ impl<'db> BonsaiDatabase for RocksDBTransaction<'db> { value: &[u8], batch: Option<&mut Self::Batch>, ) -> Result>, Self::DatabaseError> { - trace!("Inserting into RocksDB: {:?} {:?}", key, value); let handle_cf = self.column_families.get(key.get_cf()).expect(CF_ERROR); let old_value = self .txn @@ -346,7 +337,6 @@ impl<'db> BonsaiDatabase for RocksDBTransaction<'db> { } fn get(&self, key: &KeyType) -> Result>, Self::DatabaseError> { - trace!("Getting from RocksDB: {:?}", key); let handle = self.column_families.get(key.get_cf()).expect(CF_ERROR); Ok(self .txn @@ -357,7 +347,6 @@ impl<'db> BonsaiDatabase for RocksDBTransaction<'db> { &self, prefix: &KeyType, ) -> Result, Vec)>, Self::DatabaseError> { - trace!("Getting from RocksDB: {:?}", prefix); let handle = self.column_families.get(prefix.get_cf()).expect(CF_ERROR); let iter = self.txn.iterator_cf( handle, @@ -379,7 +368,6 @@ impl<'db> BonsaiDatabase for RocksDBTransaction<'db> { } fn contains(&self, key: &KeyType) -> Result { - trace!("Checking if RocksDB contains: {:?}", key); let handle = self.column_families.get(key.get_cf()).expect(CF_ERROR); Ok(self .txn @@ -392,7 +380,6 @@ impl<'db> BonsaiDatabase for RocksDBTransaction<'db> { key: &KeyType, batch: Option<&mut Self::Batch>, ) -> Result>, Self::DatabaseError> { - trace!("Removing from RocksDB: {:?}", key); let handle = self.column_families.get(key.get_cf()).expect(CF_ERROR); let old_value = self .txn @@ -406,7 +393,6 @@ impl<'db> BonsaiDatabase for RocksDBTransaction<'db> { } fn remove_by_prefix(&mut self, prefix: &KeyType) -> Result<(), Self::DatabaseError> { - trace!("Getting from RocksDB: {:?}", prefix); let mut batch = self.create_batch(); { let handle = self.column_families.get(prefix.get_cf()).expect(CF_ERROR); @@ -443,7 +429,6 @@ where type DatabaseError = RocksDBError; fn snapshot(&mut self, id: ID) { - trace!("Generating RocksDB transaction"); let snapshot = self.db.snapshot(); self.snapshots.insert(id, snapshot); if let Some(max_number_snapshot) = self.config.max_saved_snapshots { @@ -454,7 +439,6 @@ where } fn transaction(&self, id: ID) -> Option { - trace!("Generating RocksDB transaction"); if let Some(snapshot) = self.snapshots.get(&id) { let write_opts = WriteOptions::default(); let mut txn_opts = OptimisticTransactionOptions::default(); diff --git a/src/error.rs b/src/error.rs index 8055cda..c4b9903 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,3 +1,4 @@ +use alloc::string::String; /// All errors that can be returned by BonsaiStorage. #[derive(Debug)] pub enum BonsaiStorageError { diff --git a/src/id.rs b/src/id.rs index 8945a01..7b1ae3d 100644 --- a/src/id.rs +++ b/src/id.rs @@ -1,4 +1,5 @@ -use std::{fmt::Debug, hash}; +use alloc::vec::Vec; +use core::{fmt::Debug, hash}; /// Trait to be implemented on any type that can be used as an ID. pub trait Id: hash::Hash + PartialEq + Eq + PartialOrd + Ord + Debug + Copy { diff --git a/src/key_value_db.rs b/src/key_value_db.rs index 9bd831a..c40fb25 100644 --- a/src/key_value_db.rs +++ b/src/key_value_db.rs @@ -1,5 +1,7 @@ -use log::trace; -use std::collections::BTreeSet; +use alloc::collections::BTreeSet; +use alloc::format; +use alloc::string::ToString; +use alloc::vec::Vec; use crate::{ bonsai_database::{BonsaiDatabase, BonsaiPersistentDatabase, KeyType}, @@ -67,7 +69,7 @@ impl KeyValueDB where DB: BonsaiDatabase, ID: Id, - BonsaiStorageError: std::convert::From<::DatabaseError>, + BonsaiStorageError: core::convert::From<::DatabaseError>, { pub(crate) fn new(underline_db: DB, config: KeyValueDBConfig, created_at: Option) -> Self { let mut changes_store = ChangeStore::new(); @@ -96,7 +98,7 @@ where // Insert flat db changes let mut batch = self.db.create_batch(); - let current_changes = std::mem::take(&mut self.changes_store.current_changes); + let current_changes = core::mem::take(&mut self.changes_store.current_changes); for (key, change) in current_changes.serialize(&id).iter() { self.db .insert(&KeyType::TrieLog(key), change, Some(&mut batch))?; @@ -122,12 +124,10 @@ where } pub(crate) fn get(&self, key: &TrieKeyType) -> Result>, BonsaiStorageError> { - trace!("Getting from KeyValueDB: {:?}", key); Ok(self.db.get(&key.into())?) } pub(crate) fn contains(&self, key: &TrieKeyType) -> Result { - trace!("Contains from KeyValueDB: {:?}", key); Ok(self.db.contains(&key.into())?) } @@ -137,7 +137,6 @@ where value: &[u8], batch: Option<&mut DB::Batch>, ) -> Result<(), BonsaiStorageError> { - trace!("Inserting into KeyValueDB: {:?} {:?}", key, value); let old_value = self.db.insert(&key.into(), value, batch)?; self.changes_store.current_changes.insert_in_place( key.into(), @@ -154,7 +153,6 @@ where key: &TrieKeyType, batch: Option<&mut DB::Batch>, ) -> Result<(), BonsaiStorageError> { - trace!("Removing from KeyValueDB: {:?}", key); let old_value = self.db.remove(&key.into(), batch)?; self.changes_store.current_changes.insert_in_place( key.into(), @@ -167,7 +165,6 @@ where } pub(crate) fn write_batch(&mut self, batch: DB::Batch) -> Result<(), BonsaiStorageError> { - trace!("Writing batch into KeyValueDB"); Ok(self.db.write_batch(batch)?) } } @@ -195,7 +192,7 @@ where id: ID, ) -> Result, BonsaiStorageError> where - BonsaiStorageError: std::convert::From<::DatabaseError>, + BonsaiStorageError: core::convert::From<::DatabaseError>, { let Some(change_id) = self.snap_holder.range(..=id).last() else { return Ok(None); @@ -254,7 +251,8 @@ where transaction: KeyValueDB, ) -> Result<(), BonsaiStorageError> where - BonsaiStorageError: std::convert::From<>::DatabaseError>, + BonsaiStorageError: + core::convert::From<>::DatabaseError>, { let Some(created_at) = transaction.created_at else { return Err(BonsaiStorageError::Merge( diff --git a/src/lib.rs b/src/lib.rs index 2208d36..d26dc3b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,7 +82,11 @@ //! .unwrap(); //! bonsai_storage.commit(id_builder.new_id()).unwrap(); //! ``` +#![cfg_attr(not(feature = "std"), no_std)] +extern crate alloc; +use alloc::format; +use alloc::vec::Vec; use bitvec::{order::Msb0, slice::BitSlice}; use bonsai_database::BonsaiPersistentDatabase; use bonsai_database::KeyType; @@ -155,7 +159,7 @@ impl BonsaiStorage where DB: BonsaiDatabase, ChangeID: id::Id, - BonsaiStorageError: std::convert::From<::DatabaseError>, + BonsaiStorageError: core::convert::From<::DatabaseError>, H: StarkHash, { /// Create a new bonsai storage instance @@ -300,7 +304,7 @@ impl BonsaiStorage where DB: BonsaiDatabase + BonsaiPersistentDatabase, ChangeID: id::Id, - BonsaiStorageError: std::convert::From<::DatabaseError>, + BonsaiStorageError: core::convert::From<::DatabaseError>, H: StarkHash, { /// Update trie and database using all changes since the last commit. @@ -321,7 +325,7 @@ where config: BonsaiStorageConfig, ) -> Result>, BonsaiStorageError> where - BonsaiStorageError: std::convert::From<::DatabaseError>, + BonsaiStorageError: core::convert::From<::DatabaseError>, { if let Some(transaction) = self.trie.db_ref().get_transaction(change_id)? { Ok(Some(BonsaiStorage::new_from_transactional_state( @@ -346,7 +350,7 @@ where ) -> Result<(), BonsaiStorageError> where BonsaiStorageError: - std::convert::From<>::DatabaseError>, + core::convert::From<>::DatabaseError>, { self.trie .db_mut() diff --git a/src/trie/merkle_tree.rs b/src/trie/merkle_tree.rs index 78474b1..aa0b2c3 100644 --- a/src/trie/merkle_tree.rs +++ b/src/trie/merkle_tree.rs @@ -1,14 +1,21 @@ -use core::iter::once; -use core::marker::PhantomData; - +use alloc::format; +use alloc::string::ToString; +use alloc::vec; +use alloc::vec::Vec; use bitvec::{ prelude::{BitSlice, BitVec, Msb0}, view::BitView, }; +use core::iter::once; +use core::marker::PhantomData; +use core::mem; use derive_more::Constructor; +#[cfg(not(feature = "std"))] +use hashbrown::HashMap; use parity_scale_codec::{Decode, Encode, Error, Input, Output}; use starknet_types_core::{felt::Felt, hash::StarkHash}; -use std::{collections::HashMap, mem}; +#[cfg(feature = "std")] +use std::collections::HashMap; use crate::{error::BonsaiStorageError, id::Id, BonsaiDatabase, KeyValueDB}; @@ -141,7 +148,7 @@ impl MerkleTree { /// transient ones. pub fn new(mut db: KeyValueDB) -> Result where - BonsaiStorageError: std::convert::From<::DatabaseError>, + BonsaiStorageError: core::convert::From<::DatabaseError>, { let nodes_mapping: HashMap = HashMap::new(); let root_node = db.get(&TrieKeyType::Trie(vec![]))?; @@ -178,7 +185,7 @@ impl MerkleTree { pub fn reset_root_from_db(&mut self) -> Result<(), BonsaiStorageError> where - BonsaiStorageError: std::convert::From<::DatabaseError>, + BonsaiStorageError: core::convert::From<::DatabaseError>, { let node = self .get_tree_branch_in_db_from_path(&BitVec::::new())? @@ -199,7 +206,7 @@ impl MerkleTree { /// Persists all changes to storage and returns the new root hash. pub fn commit(&mut self) -> Result where - BonsaiStorageError: std::convert::From<::DatabaseError>, + BonsaiStorageError: core::convert::From<::DatabaseError>, { let mut batch = self.db.create_batch(); for node_key in mem::take(&mut self.death_row) { @@ -242,7 +249,7 @@ impl MerkleTree { batch: &mut DB::Batch, ) -> Result where - BonsaiStorageError: std::convert::From<::DatabaseError>, + BonsaiStorageError: core::convert::From<::DatabaseError>, { use Node::*; let node_id = match node_handle { @@ -329,7 +336,7 @@ impl MerkleTree { /// * `value` - The value to set. pub fn set(&mut self, key: &BitSlice, value: Felt) -> Result<(), BonsaiStorageError> where - BonsaiStorageError: std::convert::From<::DatabaseError>, + BonsaiStorageError: core::convert::From<::DatabaseError>, { if value == Felt::ZERO { return self.delete_leaf(key); @@ -504,7 +511,7 @@ impl MerkleTree { /// * `key` - The key to delete. fn delete_leaf(&mut self, key: &BitSlice) -> Result<(), BonsaiStorageError> where - BonsaiStorageError: std::convert::From<::DatabaseError>, + BonsaiStorageError: core::convert::From<::DatabaseError>, { // Algorithm explanation: // @@ -558,8 +565,6 @@ impl MerkleTree { }); let branch_node = node_iter.next(); let parent_branch_node = node_iter.next(); - println!("path: {:?}", last_binary_path); - println!("branch_node: {:?}", branch_node); match branch_node { Some(node_id) => { let new_edge = @@ -567,7 +572,6 @@ impl MerkleTree { let node = self.storage_nodes.0.get_mut(&node_id).ok_or( BonsaiStorageError::Trie("Node not found in memory".to_string()), )?; - println!("node: {:?}", node); let (direction, height) = { // SAFETY: This node must be a binary node due to the iteration condition. let binary = node.as_binary().unwrap(); @@ -664,7 +668,7 @@ impl MerkleTree { /// The value of the key. pub fn get(&self, key: &BitSlice) -> Result, BonsaiStorageError> where - BonsaiStorageError: std::convert::From<::DatabaseError>, + BonsaiStorageError: core::convert::From<::DatabaseError>, { let key = &[&[key.len() as u8], key.to_bitvec().as_raw_slice()].concat(); if let Some(value) = self.cache_leaf_modified.get(key) { @@ -680,7 +684,7 @@ impl MerkleTree { pub fn contains(&self, key: &BitSlice) -> Result where - BonsaiStorageError: std::convert::From<::DatabaseError>, + BonsaiStorageError: core::convert::From<::DatabaseError>, { let key = &[&[key.len() as u8], key.to_bitvec().as_raw_slice()].concat(); if let Some(value) = self.cache_leaf_modified.get(key) { @@ -714,7 +718,7 @@ impl MerkleTree { /// The list of nodes along the path. fn preload_nodes(&mut self, dst: &BitSlice) -> Result, BonsaiStorageError> where - BonsaiStorageError: std::convert::From<::DatabaseError>, + BonsaiStorageError: core::convert::From<::DatabaseError>, { let mut nodes = Vec::with_capacity(251); let node_id = match self.root_handle { @@ -750,7 +754,7 @@ impl MerkleTree { nodes: &mut Vec, ) -> Result<(), BonsaiStorageError> where - BonsaiStorageError: std::convert::From<::DatabaseError>, + BonsaiStorageError: core::convert::From<::DatabaseError>, { let node = self .storage_nodes @@ -828,7 +832,7 @@ impl MerkleTree { path: &BitVec, ) -> Result, BonsaiStorageError> where - BonsaiStorageError: std::convert::From<::DatabaseError>, + BonsaiStorageError: core::convert::From<::DatabaseError>, { let key = if path.is_empty() { vec![] @@ -858,7 +862,7 @@ impl MerkleTree { /// * `parent` - The parent node to merge the child with. fn merge_edges(&self, parent: &mut EdgeNode) -> Result<(), BonsaiStorageError> where - BonsaiStorageError: std::convert::From<::DatabaseError>, + BonsaiStorageError: core::convert::From<::DatabaseError>, { //TODO: Add deletion of unused nodes let child_node = match parent.child { diff --git a/src/trie/trie_db.rs b/src/trie/trie_db.rs index 84bc876..4671c72 100644 --- a/src/trie/trie_db.rs +++ b/src/trie/trie_db.rs @@ -1,4 +1,5 @@ use crate::{bonsai_database::KeyType, changes::ChangeKeyType}; +use alloc::vec::Vec; #[derive(Debug, Hash, PartialEq, Eq)] pub enum TrieKeyType {