diff --git a/.github/workflows/publish-rust.yml b/.github/workflows/publish-rust.yml index 9884fdcd1..b010b9046 100644 --- a/.github/workflows/publish-rust.yml +++ b/.github/workflows/publish-rust.yml @@ -91,10 +91,43 @@ jobs: - name: Run clippy run: ./scripts/check-clippy.sh + detached-minimal-versions: + name: Check minimal-versions on detached crate + runs-on: ubuntu-latest + needs: [sanity] + steps: + - name: Git Checkout + uses: actions/checkout@v4 + + - name: Setup Environment + uses: ./.github/actions/setup + with: + nightly-toolchain: true + cargo-cache-key: cargo-nightly-minimal-versions + cargo-cache-fallback-key: cargo-nightly + + - name: Install cargo-hack + uses: taiki-e/cache-cargo-install-action@v2 + with: + tool: cargo-hack + + - name: Install cargo-minimal-versions + uses: taiki-e/cache-cargo-install-action@v2 + with: + tool: cargo-minimal-versions + + - name: Install toml-cli + uses: taiki-e/cache-cargo-install-action@v2 + with: + tool: toml-cli + + - name: Run minimal-versions check + run: ./scripts/check-detached-minimal-versions.sh "${{ inputs.package_path }}" + publish-crate: name: Publish crate runs-on: ubuntu-latest - needs: [format, clippy] + needs: [format, clippy, detached-minimal-versions] permissions: contents: write steps: @@ -154,13 +187,10 @@ jobs: - name: Generate a changelog if: github.event.inputs.create_release == 'true' - uses: orhun/git-cliff-action@v3 + uses: orhun/git-cliff-action@v4 with: config: "scripts/cliff.toml" - args: | - "${{ steps.publish.outputs.old_git_tag }}"..master - --include-path "${{ inputs.package_path }}/**" - --github-repo "${{ github.repository }}" + args: ${{ steps.publish.outputs.old_git_tag }}..master --include-path "${{ inputs.package_path }}/**" --github-repo ${{ github.repository }} env: OUTPUT: TEMP_CHANGELOG.md GITHUB_REPO: ${{ github.repository }} diff --git a/Cargo.lock b/Cargo.lock index 6729ead51..41d5941fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,15 +62,15 @@ checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] name = "anstyle" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" +checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" [[package]] name = "anyhow" -version = "1.0.96" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b964d184e89d9b6b67dd2715bc8e74cf3107fb2b529990c90cf517326150bf4" +checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" [[package]] name = "arbitrary" @@ -319,6 +319,18 @@ dependencies = [ "typenum", ] +[[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 = "blake3" version = "1.5.5" @@ -351,6 +363,34 @@ dependencies = [ "generic-array", ] +[[package]] +name = "blst" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47c79a94619fade3c0b887670333513a67ac28a6a7e653eb260bf0d4103db38d" +dependencies = [ + "cc", + "glob", + "threadpool", + "zeroize", +] + +[[package]] +name = "blstrs" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a8a8ed6fefbeef4a8c7b460e4110e12c5e22a5b7cf32621aae6ad650c4dcf29" +dependencies = [ + "blst", + "byte-slice-cast", + "ff", + "group", + "pairing", + "rand_core 0.6.4", + "serde", + "subtle", +] + [[package]] name = "borsh" version = "0.10.4" @@ -419,6 +459,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "boxcar" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66bb12751a83493ef4b8da1120451a262554e216a247f14b48cb5e8fe7ed8bdf" + [[package]] name = "brotli" version = "7.0.0" @@ -465,11 +511,17 @@ dependencies = [ "serde", ] +[[package]] +name = "byte-slice-cast" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7575182f7272186991736b70173b0ea045398f984bf5ebbb3804736ce1330c9d" + [[package]] name = "bytemuck" -version = "1.21.0" +version = "1.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef657dfab802224e671f5818e9a4935f9b1957ed18e58292690cc39e7a4092a3" +checksum = "9134a6ef01ce4b366b50689c94f82c14bc72bc5d0386829828a2e2752ef7958c" dependencies = [ "bytemuck_derive", ] @@ -573,18 +625,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.27" +version = "4.5.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "769b0145982b4b48713e01ec42d61614425f27b7058bda7180a3a41f30104796" +checksum = "fd60e63e9be68e5fb56422e397cf9baddded06dae1d2e523401542383bc72a9f" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.27" +version = "4.5.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b26884eb4b57140e4d2d93652abfa49498b938b3c9179f9fc487b0acc3edad7" +checksum = "89cc6392a1f72bbeb820d71f32108f61fdaf18bc526e1d23954168a67759ef51" dependencies = [ "anstyle", "clap_lex", @@ -843,6 +895,7 @@ dependencies = [ "lock_api", "once_cell", "parking_lot_core", + "serde", ] [[package]] @@ -979,12 +1032,39 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + +[[package]] +name = "fastrand" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" + [[package]] name = "feature-probe" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "835a3dc7d1ec9e75e2b5fb4ba75396837112d2060b03f7d43bc1897c7f7211da" +[[package]] +name = "ff" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393" +dependencies = [ + "bitvec", + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "fiat-crypto" version = "0.2.9" @@ -1055,6 +1135,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + [[package]] name = "futures" version = "0.3.31" @@ -1168,12 +1254,43 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "getrandom" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasi 0.14.2+wasi-0.2.4", +] + [[package]] name = "gimli" version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +[[package]] +name = "glob" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand 0.8.5", + "rand_core 0.6.4", + "rand_xorshift", + "subtle", +] + [[package]] name = "h2" version = "0.3.26" @@ -1195,9 +1312,9 @@ dependencies = [ [[package]] name = "half" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" +checksum = "459196ed295495a68f7d7fe1d84f6c4b7ff0e21fe3017b2f283c6fac3ad803c9" dependencies = [ "cfg-if", "crunchy", @@ -1241,9 +1358,15 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.4.0" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "hermit-abi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f154ce46856750ed433c8649605bf7ed2de3bc35fd9d2a9f30cddd873c80cb08" [[package]] name = "hex" @@ -1551,13 +1674,13 @@ checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" [[package]] name = "is-terminal" -version = "0.4.15" +version = "0.4.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e19b23d53f35ce9f56aebc7d1bb4e6ac1e9c0db7ac85c8d1760c04379edced37" +checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9" dependencies = [ - "hermit-abi 0.4.0", + "hermit-abi 0.5.1", "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1663,6 +1786,12 @@ dependencies = [ "libsecp256k1-core", ] +[[package]] +name = "linux-raw-sys" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" + [[package]] name = "litemap" version = "0.7.4" @@ -1774,6 +1903,16 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi 0.3.9", + "libc", +] + [[package]] name = "num_enum" version = "0.7.3" @@ -1818,9 +1957,9 @@ checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "oorandom" -version = "11.1.4" +version = "11.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" +checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" [[package]] name = "opaque-debug" @@ -1876,6 +2015,15 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "pairing" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" +dependencies = [ + "group", +] + [[package]] name = "parking_lot" version = "0.12.3" @@ -2046,6 +2194,18 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + [[package]] name = "rand" version = "0.7.3" @@ -2117,6 +2277,15 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_xorshift" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" +dependencies = [ + "rand_core 0.6.4", +] + [[package]] name = "rand_xoshiro" version = "0.6.0" @@ -2262,6 +2431,19 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" +dependencies = [ + "bitflags 2.8.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.59.0", +] + [[package]] name = "rustls" version = "0.21.12" @@ -2338,9 +2520,9 @@ checksum = "f79dfe2d285b0488816f30e700a7438c5a73d816b5b7d3ac72fbc48b0d185e03" [[package]] name = "serde" -version = "1.0.217" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" dependencies = [ "serde_derive", ] @@ -2365,9 +2547,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.217" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", @@ -2388,9 +2570,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.8" +version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" dependencies = [ "serde", ] @@ -2584,7 +2766,7 @@ dependencies = [ [[package]] name = "solana-account-info" -version = "2.2.1" +version = "2.3.0" dependencies = [ "bincode", "serde", @@ -2659,6 +2841,33 @@ dependencies = [ "solana-sanitize", ] +[[package]] +name = "solana-bls-signatures" +version = "0.1.0" +dependencies = [ + "base64 0.22.1", + "bincode", + "blst", + "blstrs", + "bytemuck", + "cfg_eval", + "ff", + "group", + "rand 0.8.5", + "serde", + "serde_json", + "serde_with", + "solana-bls-signatures", + "solana-frozen-abi", + "solana-frozen-abi-macro", + "solana-keypair", + "solana-signature", + "solana-signer", + "subtle", + "tempfile", + "thiserror 2.0.12", +] + [[package]] name = "solana-bn254" version = "2.2.2" @@ -2674,7 +2883,7 @@ dependencies = [ "serde_derive", "serde_json", "solana-define-syscall", - "thiserror 2.0.11", + "thiserror 2.0.12", ] [[package]] @@ -2706,7 +2915,7 @@ dependencies = [ [[package]] name = "solana-clock" -version = "2.2.1" +version = "2.2.2" dependencies = [ "serde", "serde_derive", @@ -2767,7 +2976,7 @@ dependencies = [ [[package]] name = "solana-decode-error" -version = "2.2.1" +version = "2.3.0" dependencies = [ "num-derive", "num-traits", @@ -2775,7 +2984,7 @@ dependencies = [ [[package]] name = "solana-define-syscall" -version = "2.2.1" +version = "2.3.0" [[package]] name = "solana-derivation-path" @@ -2789,7 +2998,7 @@ dependencies = [ [[package]] name = "solana-ed25519-program" -version = "2.2.2" +version = "2.2.3" dependencies = [ "bytemuck", "bytemuck_derive", @@ -2871,12 +3080,12 @@ dependencies = [ "solana-pubkey", "solana-sdk-ids", "solana-system-interface", - "thiserror 2.0.11", + "thiserror 2.0.12", ] [[package]] name = "solana-feature-gate-interface" -version = "2.2.1" +version = "2.2.2" dependencies = [ "bincode", "serde", @@ -2894,7 +3103,7 @@ dependencies = [ [[package]] name = "solana-feature-set" -version = "2.2.4" +version = "2.2.5" dependencies = [ "ahash", "lazy_static", @@ -2932,7 +3141,7 @@ dependencies = [ [[package]] name = "solana-fee-structure" -version = "2.2.1" +version = "2.3.0" dependencies = [ "serde", "serde_derive", @@ -2943,7 +3152,7 @@ dependencies = [ [[package]] name = "solana-file-download" -version = "2.2.1" +version = "2.2.2" dependencies = [ "console", "indicatif", @@ -2953,12 +3162,14 @@ dependencies = [ [[package]] name = "solana-frozen-abi" -version = "2.2.2" +version = "2.3.0" dependencies = [ "bitflags 2.8.0", + "boxcar", "bs58", "bv", "bytes", + "dashmap", "im", "log", "memmap2", @@ -2969,7 +3180,7 @@ dependencies = [ "sha2 0.10.8", "solana-frozen-abi-macro", "solana-logger", - "thiserror 2.0.11", + "thiserror 2.0.12", ] [[package]] @@ -2983,7 +3194,7 @@ dependencies = [ [[package]] name = "solana-genesis-config" -version = "2.2.1" +version = "2.3.0" dependencies = [ "bincode", "chrono", @@ -3002,7 +3213,6 @@ dependencies = [ "solana-inflation", "solana-keypair", "solana-logger", - "solana-native-token", "solana-poh-config", "solana-pubkey", "solana-rent", @@ -3025,7 +3235,7 @@ dependencies = [ [[package]] name = "solana-hash" -version = "2.2.1" +version = "2.3.0" dependencies = [ "borsh 1.5.5", "bs58", @@ -3054,7 +3264,7 @@ dependencies = [ [[package]] name = "solana-instruction" -version = "2.2.1" +version = "2.3.0" dependencies = [ "bincode", "borsh 1.5.5", @@ -3073,7 +3283,7 @@ dependencies = [ [[package]] name = "solana-instructions-sysvar" -version = "2.2.1" +version = "2.2.2" dependencies = [ "bitflags 2.8.0", "qualifier_attr", @@ -3104,7 +3314,7 @@ dependencies = [ [[package]] name = "solana-keypair" -version = "2.2.1" +version = "2.2.3" dependencies = [ "ed25519-dalek", "ed25519-dalek-bip32", @@ -3147,7 +3357,7 @@ dependencies = [ [[package]] name = "solana-loader-v3-interface" -version = "3.0.0" +version = "5.0.0" dependencies = [ "bincode", "serde", @@ -3192,7 +3402,7 @@ dependencies = [ [[package]] name = "solana-message" -version = "2.3.0" +version = "2.4.0" dependencies = [ "anyhow", "bincode", @@ -3234,7 +3444,7 @@ dependencies = [ [[package]] name = "solana-native-token" -version = "2.2.2" +version = "2.3.0" [[package]] name = "solana-nonce" @@ -3294,7 +3504,7 @@ dependencies = [ "proc-macro2", "quote", "syn 2.0.98", - "toml 0.8.20", + "toml 0.8.23", ] [[package]] @@ -3327,7 +3537,7 @@ dependencies = [ [[package]] name = "solana-precompile-error" -version = "2.2.1" +version = "2.2.2" dependencies = [ "num-traits", "solana-decode-error", @@ -3335,7 +3545,7 @@ dependencies = [ [[package]] name = "solana-precompiles" -version = "2.2.1" +version = "2.2.2" dependencies = [ "lazy_static", "solana-ed25519-program", @@ -3360,37 +3570,28 @@ dependencies = [ [[package]] name = "solana-program" -version = "2.2.1" +version = "2.3.0" dependencies = [ "arbitrary", - "array-bytes", - "assert_matches", "bincode", "blake3", "borsh 0.10.4", "borsh 1.5.5", - "bs58", "bytemuck", "console_error_panic_hook", "console_log", "getrandom 0.2.15", - "itertools 0.12.1", "lazy_static", "log", "memoffset", "num-bigint", - "num-derive", "num-traits", - "rand 0.8.5", "serde", - "serde_bytes", "serde_derive", - "serde_json", "solana-account-info", "solana-address-lookup-table-interface", "solana-atomic-u64", "solana-big-mod-exp", - "solana-bincode", "solana-blake3-hasher", "solana-borsh", "solana-clock", @@ -3400,7 +3601,6 @@ dependencies = [ "solana-epoch-rewards", "solana-epoch-schedule", "solana-example-mocks", - "solana-feature-gate-interface", "solana-fee-calculator", "solana-frozen-abi", "solana-frozen-abi-macro", @@ -3409,14 +3609,8 @@ dependencies = [ "solana-instructions-sysvar", "solana-keccak-hasher", "solana-last-restart-slot", - "solana-loader-v2-interface", - "solana-loader-v3-interface", - "solana-loader-v4-interface", - "solana-logger", - "solana-message", "solana-msg", "solana-native-token", - "solana-nonce", "solana-program-entrypoint", "solana-program-error", "solana-program-memory", @@ -3424,7 +3618,6 @@ dependencies = [ "solana-program-pack", "solana-pubkey", "solana-rent", - "solana-sanitize", "solana-sdk-ids", "solana-sdk-macro", "solana-secp256k1-recover", @@ -3435,20 +3628,18 @@ dependencies = [ "solana-slot-hashes", "solana-slot-history", "solana-stable-layout", - "solana-stake-interface", - "solana-system-interface", "solana-sysvar", "solana-sysvar-id", - "solana-vote-interface", - "thiserror 2.0.11", + "thiserror 2.0.12", "wasm-bindgen", ] [[package]] name = "solana-program-entrypoint" -version = "2.2.1" +version = "2.3.0" dependencies = [ "solana-account-info", + "solana-define-syscall", "solana-msg", "solana-program-error", "solana-pubkey", @@ -3456,10 +3647,11 @@ dependencies = [ [[package]] name = "solana-program-error" -version = "2.2.1" +version = "2.2.2" dependencies = [ "borsh 1.5.5", "num-traits", + "num_enum", "serde", "serde_derive", "solana-decode-error", @@ -3470,7 +3662,7 @@ dependencies = [ [[package]] name = "solana-program-memory" -version = "2.2.1" +version = "2.3.1" dependencies = [ "solana-define-syscall", ] @@ -3488,7 +3680,7 @@ dependencies = [ [[package]] name = "solana-pubkey" -version = "2.3.0" +version = "2.4.0" dependencies = [ "anyhow", "arbitrary", @@ -3522,7 +3714,7 @@ dependencies = [ [[package]] name = "solana-quic-definitions" -version = "2.2.1" +version = "2.3.0" dependencies = [ "solana-keypair", ] @@ -3571,7 +3763,7 @@ dependencies = [ [[package]] name = "solana-reserved-account-keys" -version = "2.2.1" +version = "2.2.2" dependencies = [ "lazy_static", "solana-feature-set", @@ -3599,64 +3791,34 @@ version = "2.2.1" [[package]] name = "solana-sdk" -version = "2.2.2" +version = "2.3.0" dependencies = [ "bincode", "bs58", - "curve25519-dalek 4.1.3", - "ed25519-dalek", "getrandom 0.1.16", "js-sys", - "libsecp256k1", - "openssl", - "rand 0.7.3", "serde", - "serde_derive", - "serde_json", - "serde_with", "solana-account", - "solana-bn254", - "solana-client-traits", - "solana-cluster-type", - "solana-commitment-config", - "solana-compute-budget-interface", - "solana-decode-error", "solana-derivation-path", - "solana-ed25519-program", "solana-epoch-info", "solana-epoch-rewards-hasher", - "solana-feature-set", "solana-fee-structure", - "solana-genesis-config", - "solana-hard-forks", "solana-inflation", "solana-instruction", "solana-instructions-sysvar", "solana-keypair", "solana-message", "solana-native-token", - "solana-nonce-account", "solana-offchain-message", - "solana-packet", - "solana-poh-config", "solana-precompile-error", - "solana-precompiles", "solana-presigner", "solana-program", "solana-program-memory", "solana-pubkey", - "solana-quic-definitions", - "solana-rent-collector", - "solana-rent-debits", - "solana-reserved-account-keys", - "solana-reward-info", "solana-sanitize", "solana-sdk", "solana-sdk-ids", "solana-sdk-macro", - "solana-secp256k1-program", - "solana-secp256k1-recover", - "solana-secp256r1-program", "solana-seed-derivable", "solana-seed-phrase", "solana-serde", @@ -3665,13 +3827,10 @@ dependencies = [ "solana-shred-version", "solana-signature", "solana-signer", - "solana-system-transaction", "solana-time-utils", "solana-transaction", - "solana-transaction-context", "solana-transaction-error", - "solana-validator-exit", - "thiserror 2.0.11", + "thiserror 2.0.12", "wasm-bindgen", ] @@ -3694,7 +3853,7 @@ dependencies = [ [[package]] name = "solana-secp256k1-program" -version = "2.2.1" +version = "2.2.3" dependencies = [ "anyhow", "bincode", @@ -3734,12 +3893,12 @@ dependencies = [ "solana-frozen-abi", "solana-frozen-abi-macro", "solana-program", - "thiserror 2.0.11", + "thiserror 2.0.12", ] [[package]] name = "solana-secp256r1-program" -version = "2.2.2" +version = "2.2.4" dependencies = [ "bytemuck", "openssl", @@ -3778,7 +3937,7 @@ dependencies = [ [[package]] name = "solana-serde-varint" -version = "2.2.1" +version = "2.2.2" dependencies = [ "bincode", "rand 0.8.5", @@ -3832,7 +3991,7 @@ dependencies = [ [[package]] name = "solana-signature" -version = "2.2.1" +version = "2.3.0" dependencies = [ "bincode", "bs58", @@ -3899,8 +4058,6 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5269e89fde216b4d7e1d1739cf5303f8398a1ff372a81232abbee80e554a838c" dependencies = [ - "borsh 0.10.4", - "borsh 1.5.5", "num-traits", "serde", "serde_derive", @@ -3947,7 +4104,7 @@ dependencies = [ [[package]] name = "solana-sysvar" -version = "2.2.1" +version = "2.2.2" dependencies = [ "anyhow", "base64 0.22.1", @@ -4004,7 +4161,7 @@ version = "2.2.1" [[package]] name = "solana-transaction" -version = "2.2.2" +version = "2.2.3" dependencies = [ "anyhow", "bincode", @@ -4024,7 +4181,6 @@ dependencies = [ "solana-packet", "solana-precompiles", "solana-presigner", - "solana-program", "solana-pubkey", "solana-sanitize", "solana-sdk", @@ -4036,26 +4192,11 @@ dependencies = [ "solana-system-interface", "solana-transaction", "solana-transaction-error", + "solana-vote-interface", "static_assertions", "wasm-bindgen", ] -[[package]] -name = "solana-transaction-context" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5022de04cbba05377f68bf848c8c1322ead733f88a657bf792bb40f3257b8218" -dependencies = [ - "bincode", - "serde", - "serde_derive", - "solana-account", - "solana-instruction", - "solana-pubkey", - "solana-rent", - "solana-signature", -] - [[package]] name = "solana-transaction-error" version = "2.2.1" @@ -4074,7 +4215,7 @@ version = "2.2.1" [[package]] name = "solana-vote-interface" -version = "2.2.4" +version = "2.2.5" dependencies = [ "arbitrary", "bincode", @@ -4205,6 +4346,25 @@ dependencies = [ "libc", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "tempfile" +version = "3.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1" +dependencies = [ + "fastrand", + "getrandom 0.3.3", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + [[package]] name = "termcolor" version = "1.4.1" @@ -4258,11 +4418,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.11" +version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" dependencies = [ - "thiserror-impl 2.0.11", + "thiserror-impl 2.0.12", ] [[package]] @@ -4278,15 +4438,24 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.11" +version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" dependencies = [ "proc-macro2", "quote", "syn 2.0.98", ] +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + [[package]] name = "tiny-bip39" version = "0.8.2" @@ -4390,9 +4559,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.20" +version = "0.8.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" dependencies = [ "serde", "serde_spanned", @@ -4402,26 +4571,33 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.8" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.22.23" +version = "0.22.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02a8b472d1a3d7c18e2d61a489aee3453fd9031c33e4f55bd533f4a7adca1bee" +checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" dependencies = [ "indexmap", "serde", "serde_spanned", "toml_datetime", + "toml_write", "winnow", ] +[[package]] +name = "toml_write" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" + [[package]] name = "tower-service" version = "0.3.3" @@ -4562,6 +4738,15 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasi" +version = "0.14.2+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" +dependencies = [ + "wit-bindgen-rt", +] + [[package]] name = "wasm-bindgen" version = "0.2.100" @@ -4681,7 +4866,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.48.0", ] [[package]] @@ -4840,9 +5025,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.7.0" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e49d2d35d3fad69b39b94139037ecfb4f359f08958b9c11e7315ce770462419" +checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec" dependencies = [ "memchr", ] @@ -4857,6 +5042,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "wit-bindgen-rt" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" +dependencies = [ + "bitflags 2.8.0", +] + [[package]] name = "write16" version = "1.0.0" @@ -4869,6 +5063,15 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + [[package]] name = "yoke" version = "0.7.5" diff --git a/Cargo.toml b/Cargo.toml index 521cc5da7..2e94c8168 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,3 @@ -[profile.release] -split-debuginfo = "unpacked" -lto = "thin" - -# Enable basic optimizations for unittests -[profile.test] -opt-level = 1 - -# Enable optimizations for procmacros for faster recompile -[profile.dev.build-override] -opt-level = 1 - [workspace] members = [ "account", @@ -19,6 +7,7 @@ members = [ "big-mod-exp", "bincode", "blake3-hasher", + "bls-signatures", "bn254", "borsh", "client-traits", @@ -134,7 +123,7 @@ tag-message = "Publish {{crate_name}} v{{version}}" consolidate-commits = false [workspace.metadata.cli] -solana = "2.2.7" +solana = "2.2.11" [workspace.dependencies] ahash = "0.8.11" @@ -150,8 +139,11 @@ base64 = "0.22.1" bincode = "1.3.3" bitflags = { version = "2.8.0" } blake3 = "1.5.5" +blst = "0.3.14" +blstrs = "0.7.1" borsh = { version = "1.5.5", features = ["derive", "unstable__schema"] } borsh0-10 = { package = "borsh", version = "0.10.3" } +boxcar = "0.2.12" bs58 = { version = "0.5.1", default-features = false } bv = "0.11.1" bytemuck = "1.21.0" @@ -164,14 +156,17 @@ console_error_panic_hook = "0.1.7" console_log = "0.2.2" criterion = "0.5.1" curve25519-dalek = { version = "4.1.3", features = ["digest", "rand_core"] } +dashmap = { version = "5.5.3", features = ["serde"] } derivation-path = { version = "0.2.0", default-features = false } digest = "0.10.7" ed25519-dalek = "=1.0.1" ed25519-dalek-bip32 = "0.2.0" env_logger = "0.9.3" +ff = "0.13.1" five8 = "0.2.1" five8_const = "0.1.3" getrandom = "0.2.10" +group = "0.13.0" hex = "0.4.3" hmac = "0.12.1" im = "15.1.0" @@ -220,6 +215,7 @@ solana-atomic-u64 = { path = "atomic-u64", version = "2.2.1" } solana-big-mod-exp = { path = "big-mod-exp", version = "2.2.1" } solana-bincode = { path = "bincode", version = "2.2.1" } solana-blake3-hasher = { path = "blake3-hasher", version = "2.2.1" } +solana-bls-signatures = { path = "bls-signatures", version = "0.1.1" } solana-bn254 = { path = "bn254", version = "2.2.2" } solana-borsh = { path = "borsh", version = "2.2.1" } solana-client-traits = { path = "client-traits", version = "2.2.1" } @@ -232,7 +228,6 @@ solana-decode-error = { path = "decode-error", version = "2.2.1" } solana-define-syscall = { path = "define-syscall", version = "2.2.1" } solana-derivation-path = { path = "derivation-path", version = "2.2.1" } solana-ed25519-program = { path = "ed25519-program", version = "2.2.1" } -solana-program-entrypoint = { path = "program-entrypoint", version = "2.2.1" } solana-epoch-info = { path = "epoch-info", version = "2.2.1" } solana-epoch-rewards = { path = "epoch-rewards", version = "2.2.1" } solana-epoch-rewards-hasher = { path = "epoch-rewards-hasher", version = "2.2.1" } @@ -243,20 +238,20 @@ solana-feature-set = { path = "feature-set", version = "2.2.1" } solana-feature-set-interface = { path = "feature-set-interface", version = "4.0.1" } solana-fee-calculator = { path = "fee-calculator", version = "2.2.1" } solana-fee-structure = { path = "fee-structure", version = "2.2.1" } +solana-file-download = { path = "file-download", version = "2.2.1" } solana-frozen-abi = { path = "frozen-abi", version = "2.2.1" } solana-frozen-abi-macro = { path = "frozen-abi-macro", version = "2.2.1" } -solana-file-download = { path = "file-download", version = "2.2.1" } solana-genesis-config = { path = "genesis-config", version = "2.2.1" } solana-hard-forks = { path = "hard-forks", version = "2.2.1", default-features = false } solana-hash = { path = "hash", version = "2.2.1", default-features = false } solana-inflation = { path = "inflation", version = "2.2.1" } -solana-instruction = { path = "instruction", version = "2.2.1", default-features = false } +solana-instruction = { path = "instruction", version = "2.3.0", default-features = false } solana-instructions-sysvar = { path = "instructions-sysvar", version = "2.2.1" } solana-keccak-hasher = { path = "keccak-hasher", version = "2.2.1" } solana-keypair = { path = "keypair", version = "2.2.1" } solana-last-restart-slot = { path = "last-restart-slot", version = "2.2.1" } solana-loader-v2-interface = { path = "loader-v2-interface", version = "2.2.1" } -solana-loader-v3-interface = { path = "loader-v3-interface", version = "3.0.0" } +solana-loader-v3-interface = { path = "loader-v3-interface", version = "5.0.0" } solana-loader-v4-interface = { path = "loader-v4-interface", version = "2.2.1" } solana-logger = { path = "logger", version = "2.2.1" } solana-message = { path = "message", version = "2.2.1" } @@ -273,6 +268,7 @@ solana-precompile-error = { path = "precompile-error", version = "2.2.1" } solana-precompiles = { path = "precompiles", version = "2.2.1" } solana-presigner = { path = "presigner", version = "2.2.1" } solana-program = { path = "program", version = "2.2.1", default-features = false } +solana-program-entrypoint = { path = "program-entrypoint", version = "2.2.1" } solana-program-error = { path = "program-error", version = "2.2.1" } solana-program-memory = { path = "program-memory", version = "2.2.1" } solana-program-option = { path = "program-option", version = "2.2.1" } @@ -285,6 +281,11 @@ solana-rent-debits = { path = "rent-debits", version = "2.2.1" } solana-reserved-account-keys = { path = "reserved-account-keys", version = "2.2.1", default-features = false } solana-reward-info = { path = "reward-info", version = "2.2.1" } solana-sanitize = { path = "sanitize", version = "2.2.1" } +solana-sdk = { path = "sdk", version = "2.2.1" } +solana-sdk-ids = { path = "sdk-ids", version = "2.2.1" } +solana-sdk-macro = { path = "sdk-macro", version = "2.2.1" } +solana-secp256k1-program = { path = "secp256k1-program", version = "2.2.1" } +solana-secp256k1-recover = { path = "secp256k1-recover", version = "2.2.1" } solana-secp256r1-program = { path = "secp256r1-program", version = "2.2.1", default-features = false } solana-seed-derivable = { path = "seed-derivable", version = "2.2.1" } solana-seed-phrase = { path = "seed-phrase", version = "2.2.1" } @@ -292,40 +293,48 @@ solana-serde = { path = "serde", version = "2.2.1" } solana-serde-varint = { path = "serde-varint", version = "2.2.1" } solana-serialize-utils = { path = "serialize-utils", version = "2.2.1" } solana-sha256-hasher = { path = "sha256-hasher", version = "2.2.1" } -solana-signature = { path = "signature", version = "2.2.1", default-features = false } +solana-short-vec = { path = "short-vec", version = "2.2.1" } +solana-shred-version = { path = "shred-version", version = "2.2.1" } +solana-signature = { path = "signature", version = "2.3.0", default-features = false } solana-signer = { path = "signer", version = "2.2.1" } solana-slot-hashes = { path = "slot-hashes", version = "2.2.1" } solana-slot-history = { path = "slot-history", version = "2.2.1" } -solana-time-utils = { path = "time-utils", version = "2.2.1" } -solana-sdk = { path = "sdk", version = "2.2.1" } -solana-sdk-ids = { path = "sdk-ids", version = "2.2.1" } -solana-sdk-macro = { path = "sdk-macro", version = "2.2.1" } -solana-secp256k1-program = { path = "secp256k1-program", version = "2.2.1" } -solana-secp256k1-recover = { path = "secp256k1-recover", version = "2.2.1" } -solana-short-vec = { path = "short-vec", version = "2.2.1" } -solana-shred-version = { path = "shred-version", version = "2.2.1" } solana-stable-layout = { path = "stable-layout", version = "2.2.1" } solana-stake-interface = { version = "1.2.1" } solana-system-interface = "1.0" solana-system-transaction = { path = "system-transaction", version = "2.2.1" } solana-sysvar = { path = "sysvar", version = "2.2.1" } solana-sysvar-id = { path = "sysvar-id", version = "2.2.1" } +solana-time-utils = { path = "time-utils", version = "2.2.1" } solana-transaction = { path = "transaction", version = "2.2.1" } solana-transaction-error = { path = "transaction-error", version = "2.2.1" } -solana-transaction-context = { version = "2.2.1" } solana-validator-exit = { path = "validator-exit", version = "2.2.1" } solana-vote-interface = { path = "vote-interface", version = "2.2.1" } static_assertions = "1.1.0" strum = "0.24" strum_macros = "0.24" +subtle = "2.6.1" syn = "2.0.87" +tempfile = "3.20.0" test-case = "3.3.1" thiserror = "2.0.11" tiny-bip39 = "0.8.2" -toml = "0.8.20" +toml = "0.8.23" uriparse = "0.6.4" wasm-bindgen = "0.2.100" +[profile.release] +split-debuginfo = "unpacked" +lto = "thin" + +# Enable basic optimizations for unittests +[profile.test] +opt-level = 1 + +# Enable optimizations for procmacros for faster recompile +[profile.dev.build-override] +opt-level = 1 + [patch.crates-io] # We include the following crates as our dependencies above from crates.io: # diff --git a/README.md b/README.md index cc2a22a49..4abb9a644 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,78 @@ Rust SDK for the Solana blockchain, used by on-chain programs and the Agave validator. +## Upgrading from v2 to v3 + +### solana-sdk + +The following modules have been removed, please use their component crates +directly: + +* [`address_lookup_table`](https://docs.rs/solana-sdk/latest/solana_sdk/address_lookup_table) -> [`solana_address_lookup_table_interface`](https://docs.rs/solana-address-lookup-table-interface/latest/solana_address_lookup_table_interface/) +* [`alt_bn128`](https://docs.rs/solana-sdk/latest/solana_sdk/alt_bn128) -> [`solana_bn254`](https://docs.rs/solana-bn254/latest/solana_bn254) +* [`bpf_loader_upgradeable`](https://docs.rs/solana-sdk/latest/solana_sdk/bpf_loader_upgradeable) -> [`solana_loader_v3_interface`](https://docs.rs/solana-loader-v3-interface/latest/solana_loader_v3_interface) +* [`client`](https://docs.rs/solana-sdk/latest/solana_sdk/client) -> [`solana_client_traits`](https://docs.rs/solana-client-traits/latest/solana_client_traits) +* [`commitment_config`](https://docs.rs/solana-sdk/latest/solana_sdk/commitment_config) -> [`solana_commitment_config`](https://docs.rs/solana-commitment-config/latest/solana_commitment_config) +* [`compute_budget`](https://docs.rs/solana-sdk/latest/solana_sdk/compute_budget) -> [`solana_compute_budget_interface`](https://docs.rs/solana-compute-budget-interface/latest/solana_compute_budget_interface) +* [`decode_error`](https://docs.rs/solana-sdk/latest/solana_sdk/decode_error) -> [`solana_decode_error`](https://docs.rs/solana-decode-error/latest/solana_decode_error) +* [`derivation_path`](https://docs.rs/solana-sdk/latest/solana_sdk/derivation_path) -> [`solana_derivation_path`](https://docs.rs/solana-derivation-path/latest/solana_derivation_path) +* [`ed25519_instruction`](https://docs.rs/solana-sdk/latest/solana_sdk/ed25519_instruction) -> [`solana_ed25519_program`](https://docs.rs/solana-ed25519-program/latest/solana_ed25519_program) +* [`exit`](https://docs.rs/solana-sdk/latest/solana_sdk/exit) -> [`solana_validator_exit`](https://docs.rs/solana-validator-exit/latest/solana_validator_exit) +* [`feature_set`](https://docs.rs/solana-sdk/latest/solana_sdk/feature_set) -> [`agave_feature_set`](https://docs.rs/agave-feature-set/latest/agave_feature_set) +* [`feature`](https://docs.rs/solana-sdk/latest/solana_sdk/feature) -> [`solana_feature_gate_interface`](https://docs.rs/solana-feature-gate-interface/latest/solana_feature_gate_interface) +* [`genesis_config`](https://docs.rs/solana-sdk/latest/solana_sdk/genesis_config) -> [`solana_genesis_config`](https://docs.rs/solana-genesis-config/latest/solana_genesis_config) +* [`hard_forks`](https://docs.rs/solana-sdk/latest/solana_sdk/hard_forks) -> [`solana_hard_forks`](https://docs.rs/solana-hard-forks/latest/solana_hard_forks) +* [`loader_instruction`](https://docs.rs/solana-sdk/latest/solana_sdk/loader_instruction) -> [`solana_loader_v2_interface`](https://docs.rs/solana-loader-v2-interface/latest/solana_loader_v2_interface) +* [`loader_upgradeable_instruction`](https://docs.rs/solana-sdk/latest/solana_sdk/loader_upgradeable_instruction) -> [`solana_loader_v3_interface::instruction`](https://docs.rs/solana-loader-v3-interface/latest/solana_loader_v3_interface/instruction) +* [`loader_v4`](https://docs.rs/solana-sdk/latest/solana_sdk/loader_v4) -> [`solana_loader_v4_interface`](https://docs.rs/solana-loader-v4-interface/latest/solana_loader_v4_interface) +* [`loader_v4_instruction`](https://docs.rs/solana-sdk/latest/solana_sdk/loader_v4_instruction) -> [`solana_loader_v4_interface::instruction`](https://docs.rs/solana-loader-v4-interface/latest/solana_loader_v4_interface/instruction) +* [`nonce`](https://docs.rs/solana-sdk/latest/solana_sdk/nonce) -> [`solana_nonce`](https://docs.rs/solana-nonce/latest/solana_nonce) +* [`nonce_account`](https://docs.rs/solana-sdk/latest/solana_sdk/nonce_account) -> [`solana_nonce_account`](https://docs.rs/solana-nonce-account/latest/solana_nonce_account) +* [`packet`](https://docs.rs/solana-sdk/latest/solana_sdk/packet) -> [`solana_packet`](https://docs.rs/solana-packet/latest/solana_packet) +* [`poh_config`](https://docs.rs/solana-sdk/latest/solana_sdk/poh_config) -> [`solana_poh_config`](https://docs.rs/solana-poh-config/latest/solana_poh_config) +* [`precompiles`](https://docs.rs/solana-sdk/latest/solana_sdk/precompiles) -> [`agave_precompiles`](https://docs.rs/agave-precompiles/latest/agave_precompiles) +* [`program_utils`](https://docs.rs/solana-sdk/latest/solana_sdk/program_utils) -> [`solana_bincode::limited_deserialize`](https://docs.rs/solana-bincode/latest/solana_bincode) +* [`quic`](https://docs.rs/solana-sdk/latest/solana_sdk/quic) -> [`solana_quic_definitions`](https://docs.rs/solana-quic-definitions/latest/solana_quic_definitions) +* [`rent_collector`](https://docs.rs/solana-sdk/latest/solana_sdk/rent_collector) -> [`solana_rent_collector`](https://docs.rs/solana-rent-collector/latest/solana_rent_collector) +* [`rent_debits`](https://docs.rs/solana-sdk/latest/solana_sdk/rent_debits) -> [`solana_rent_debits`](https://docs.rs/solana-rent-debits/latest/solana_rent_debits) +* [`reserved_account_keys`](https://docs.rs/solana-sdk/latest/solana_sdk/reserved_account_keys) -> [`agave_reserved_account_keys`](https://docs.rs/agave-reserved-account-keys/latest/agave_reserved_account_keys) +* [`reward_info`](https://docs.rs/solana-sdk/latest/solana_sdk/reward_info) -> [`solana_reward_info`](https://docs.rs/solana-reward-info/latest/solana_reward_info) +* [`reward_type`](https://docs.rs/solana-sdk/latest/solana_sdk/reward_type) -> [`solana_reward_info`](https://docs.rs/solana-reward-info/latest/solana_reward_info) +* [`sdk_ids`](https://docs.rs/solana-sdk/latest/solana_sdk/sdk_ids) -> [`solana_sdk_ids`](https://docs.rs/solana-sdk-ids/latest/solana_sdk_ids) +* [`secp256k1_instruction`](https://docs.rs/solana-sdk/latest/solana_sdk/secp256k1_instruction) -> [`solana_secp256k1_program`](https://docs.rs/solana-secp256k1-program/latest/solana_secp256k1_program) +* [`secp256k1_recover`](https://docs.rs/solana-sdk/latest/solana_sdk/secp256k1_recover) -> [`solana_secp256k1_recover`](https://docs.rs/solana-secp256k1-recover/latest/solana_secp256k1_recover) +* [`stake`](https://docs.rs/solana-sdk/latest/solana_sdk/stake) -> [`solana_stake_interface`](https://docs.rs/solana-stake-interface/latest/solana_stake_interface) +* [`stake_history`](https://docs.rs/solana-sdk/latest/solana_sdk/stake_history) -> [`solana_stake_interface::stake_history`](https://docs.rs/solana-stake-interface/latest/solana_stake_interface/stake_history) +* [`system_instruction`](https://docs.rs/solana-sdk/latest/solana_sdk/system_instruction) -> [`solana_system_interface::instruction`](https://docs.rs/solana-system-interface/latest/solana_system_interface/instruction) +* [`system_program`](https://docs.rs/solana-sdk/latest/solana_sdk/system_program) -> [`solana_system_interface::program`](https://docs.rs/solana-system-interface/latest/solana_system_interface/program) +* [`system_transaction`](https://docs.rs/solana-sdk/latest/solana_sdk/system_transaction) -> [`solana_system_transaction`](https://docs.rs/solana-system-transaction/latest/solana_system_transaction) +* [`transaction_context`](https://docs.rs/solana-sdk/latest/solana_sdk/transaction_context) -> [`solana_transaction_context`](https://docs.rs/solana-transaction-context/latest/solana_transaction_context) +* [`vote`](https://docs.rs/solana-sdk/latest/solana_sdk/vote) -> [`solana_vote_interface`](https://docs.rs/solana-vote-interface/latest/solana_vote_interface) + +### solana-program + +The following modules have been removed, please use their component crates +directly: + +* [`address_lookup_table`](https://docs.rs/solana-program/latest/solana_program/address_lookup_table) -> [`solana_address_lookup_table_interface`](https://docs.rs/solana-address-lookup-table-interface/latest/solana_address_lookup_table_interface/) +* [`bpf_loader_upgradeable`](https://docs.rs/solana-program/latest/solana_program/bpf_loader_upgradeable) -> [`solana_loader_v3_interface`](https://docs.rs/solana-loader-v3-interface/latest/solana_loader_v3_interface) +* [`decode_error`](https://docs.rs/solana-program/latest/solana_program/decode_error) -> [`solana_decode_error`](https://docs.rs/solana-decode-error/latest/solana_decode_error) +* [`feature`](https://docs.rs/solana-program/latest/solana_program/feature) -> [`solana_feature_gate_interface`](https://docs.rs/solana-feature-gate-interface/latest/solana_feature_gate_interface) +* [`loader_instruction`](https://docs.rs/solana-program/latest/solana_program/loader_instruction) -> [`solana_loader_v2_interface`](https://docs.rs/solana-loader-v2-interface/latest/solana_loader_v2_interface) +* [`loader_upgradeable_instruction`](https://docs.rs/solana-program/latest/solana_program/loader_upgradeable_instruction) -> [`solana_loader_v3_interface::instruction`](https://docs.rs/solana-loader-v3-interface/latest/solana_loader_v3_interface/instruction) +* [`loader_v4`](https://docs.rs/solana-program/latest/solana_program/loader_v4) -> [`solana_loader_v4_interface`](https://docs.rs/solana-loader-v4-interface/latest/solana_loader_v4_interface) +* [`loader_v4_instruction`](https://docs.rs/solana-program/latest/solana_program/loader_v4_instruction) -> [`solana_loader_v4_interface::instruction`](https://docs.rs/solana-loader-v4-interface/latest/solana_loader_v4_interface/instruction) +* [`message`](https://docs.rs/solana-program/latest/solana_program/message) -> [`solana_message`](https://docs.rs/solana-message/latest/solana_message) +* [`nonce`](https://docs.rs/solana-program/latest/solana_program/nonce) -> [`solana_nonce`](https://docs.rs/solana-nonce/latest/solana_nonce) +* [`program_utils`](https://docs.rs/solana-program/latest/solana_program/program_utils) -> [`solana_bincode::limited_deserialize`](https://docs.rs/solana-bincode/latest/solana_bincode) +* [`sanitize`](https://docs.rs/solana-program/latest/solana_program/sanitize) -> [`solana_sanitize`](https://docs.rs/solana-sanitize/latest/solana_sanitize) +* [`sdk_ids`](https://docs.rs/solana-program/latest/solana_program/sdk_ids) -> [`solana_sdk_ids`](https://docs.rs/solana-sdk-ids/latest/solana_sdk_ids) +* [`stake`](https://docs.rs/solana-program/latest/solana_program/stake) -> [`solana_stake_interface`](https://docs.rs/solana-stake-interface/latest/solana_stake_interface) +* [`stake_history`](https://docs.rs/solana-program/latest/solana_program/stake_history) -> [`solana_stake_interface::stake_history`](https://docs.rs/solana-stake-interface/latest/solana_stake_interface/stake_history) +* [`system_instruction`](https://docs.rs/solana-program/latest/solana_program/system_instruction) -> [`solana_system_interface::instruction`](https://docs.rs/solana-system-interface/latest/solana_system_interface/instruction) +* [`system_program`](https://docs.rs/solana-program/latest/solana_program/system_program) -> [`solana_system_interface::program`](https://docs.rs/solana-system-interface/latest/solana_system_interface/program) +* [`vote`](https://docs.rs/solana-program/latest/solana_program/vote) -> [`solana_vote_interface`](https://docs.rs/solana-vote-interface/latest/solana_vote_interface) + ## Building ### **1. Install rustc, cargo and rustfmt.** diff --git a/account-info/Cargo.toml b/account-info/Cargo.toml index f27e1d6b9..35c991255 100644 --- a/account-info/Cargo.toml +++ b/account-info/Cargo.toml @@ -2,24 +2,24 @@ name = "solana-account-info" description = "Solana AccountInfo and related definitions." documentation = "https://docs.rs/solana-account-info" -version = "2.2.1" +version = "2.3.0" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +bincode = ["dep:bincode", "dep:serde"] + [dependencies] bincode = { workspace = true, optional = true } serde = { workspace = true, optional = true } solana-program-error = { workspace = true } solana-program-memory = { workspace = true } solana-pubkey = { workspace = true, default-features = false } - -[features] -bincode = ["dep:bincode", "dep:serde"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] diff --git a/account-info/src/lib.rs b/account-info/src/lib.rs index b3656e415..9d1f31219 100644 --- a/account-info/src/lib.rs +++ b/account-info/src/lib.rs @@ -136,11 +136,8 @@ impl<'a> AccountInfo<'a> { /// Note: Account data can be increased within a single call by up to /// `solana_program::entrypoint::MAX_PERMITTED_DATA_INCREASE` bytes. /// - /// Note: Memory used to grow is already zero-initialized upon program - /// entrypoint and re-zeroing it wastes compute units. If within the same - /// call a program reallocs from larger to smaller and back to larger again - /// the new space could contain stale data. Pass `true` for `zero_init` in - /// this case, otherwise compute units will be wasted re-zero-initializing. + /// Note: `zero_init` being `false` will no longer be supported by the + /// program runtime. /// /// # Safety /// @@ -148,6 +145,7 @@ impl<'a> AccountInfo<'a> { /// referenced by `AccountInfo` fields. It should only be called for /// instances of `AccountInfo` that were created by the runtime and received /// in the `process_instruction` entrypoint of a program. + #[deprecated(since = "2.3.0", note = "Use AccountInfo::resize() instead")] pub fn realloc(&self, new_len: usize, zero_init: bool) -> Result<(), ProgramError> { let mut data = self.try_borrow_mut_data()?; let old_len = data.len(); @@ -178,13 +176,29 @@ impl<'a> AccountInfo<'a> { if zero_init { let len_increase = new_len.saturating_sub(old_len); if len_increase > 0 { - sol_memset(&mut data[old_len..], 0, len_increase); + unsafe { sol_memset(&mut data[old_len..], 0, len_increase) }; } } Ok(()) } + /// Resize the account's data: Either truncating or zero extending. + /// + /// Note: Account data can be increased within a single call by up to + /// `solana_program::entrypoint::MAX_PERMITTED_DATA_INCREASE` bytes. + /// + /// # Safety + /// + /// This method makes assumptions about the layout and location of memory + /// referenced by `AccountInfo` fields. It should only be called for + /// instances of `AccountInfo` that were created by the runtime and received + /// in the `process_instruction` entrypoint of a program. + pub fn resize(&self, new_len: usize) -> Result<(), ProgramError> { + #[allow(deprecated)] + self.realloc(new_len, true) + } + #[allow(invalid_reference_casting)] pub fn assign(&self, new_owner: &Pubkey) { // Set the non-mut owner field diff --git a/account/Cargo.toml b/account/Cargo.toml index df88055d3..1534c8c38 100644 --- a/account/Cargo.toml +++ b/account/Cargo.toml @@ -9,24 +9,10 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } -[dependencies] -bincode = { workspace = true, optional = true } -qualifier_attr = { workspace = true, optional = true } -serde = { workspace = true, optional = true } -serde_bytes = { workspace = true, optional = true } -serde_derive = { workspace = true, optional = true } -solana-account-info = { workspace = true } -solana-clock = { workspace = true } -solana-frozen-abi = { workspace = true, optional = true } -solana-frozen-abi-macro = { workspace = true, optional = true } -solana-instruction = { workspace = true } -solana-logger = { workspace = true, optional = true } -solana-pubkey = { workspace = true } -solana-sdk-ids = { workspace = true } -solana-sysvar = { workspace = true, features = ["bincode"], optional = true } - -[dev-dependencies] -solana-account = { path = ".", features = ["dev-context-only-utils"] } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] [features] bincode = [ @@ -49,7 +35,21 @@ serde = [ "solana-pubkey/serde", ] -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] +[dependencies] +bincode = { workspace = true, optional = true } +qualifier_attr = { workspace = true, optional = true } +serde = { workspace = true, optional = true } +serde_bytes = { workspace = true, optional = true } +serde_derive = { workspace = true, optional = true } +solana-account-info = { workspace = true } +solana-clock = { workspace = true } +solana-frozen-abi = { workspace = true, optional = true } +solana-frozen-abi-macro = { workspace = true, optional = true } +solana-instruction = { workspace = true } +solana-logger = { workspace = true, optional = true } +solana-pubkey = { workspace = true } +solana-sdk-ids = { workspace = true } +solana-sysvar = { workspace = true, features = ["bincode"], optional = true } + +[dev-dependencies] +solana-account = { path = ".", features = ["dev-context-only-utils"] } diff --git a/address-lookup-table-interface/Cargo.toml b/address-lookup-table-interface/Cargo.toml index c4deae08c..814480e2c 100644 --- a/address-lookup-table-interface/Cargo.toml +++ b/address-lookup-table-interface/Cargo.toml @@ -9,6 +9,23 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +bincode = [ + "dep:bincode", + "dep:solana-instruction", + "serde", + "solana-instruction/bincode", +] +bytemuck = ["dep:bytemuck", "solana-pubkey/bytemuck"] +dev-context-only-utils = ["bincode", "bytemuck"] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "serde"] +serde = ["dep:serde", "dep:serde_derive", "solana-pubkey/serde"] + [dependencies] bincode = { workspace = true, optional = true } bytemuck = { workspace = true, optional = true } @@ -35,22 +52,5 @@ solana-address-lookup-table-interface = { path = ".", features = [ ] } solana-hash = { workspace = true } -[features] -bincode = [ - "dep:bincode", - "dep:solana-instruction", - "serde", - "solana-instruction/bincode", -] -bytemuck = ["dep:bytemuck", "solana-pubkey/bytemuck"] -dev-context-only-utils = ["bincode", "bytemuck"] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "serde"] -serde = ["dep:serde", "dep:serde_derive", "solana-pubkey/serde"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/atomic-u64/Cargo.toml b/atomic-u64/Cargo.toml index 43fcd4ca3..548c5d486 100644 --- a/atomic-u64/Cargo.toml +++ b/atomic-u64/Cargo.toml @@ -9,8 +9,8 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } -[target.'cfg(not(target_pointer_width = "64"))'.dependencies] -parking_lot = { workspace = true } - [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] + +[target.'cfg(not(target_pointer_width = "64"))'.dependencies] +parking_lot = { workspace = true } diff --git a/big-mod-exp/Cargo.toml b/big-mod-exp/Cargo.toml index a6b1fa66c..3cbd70115 100644 --- a/big-mod-exp/Cargo.toml +++ b/big-mod-exp/Cargo.toml @@ -9,21 +9,21 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } -[target.'cfg(target_os = "solana")'.dependencies] -solana-define-syscall = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] [target.'cfg(not(target_os = "solana"))'.dependencies] num-bigint = { workspace = true } num-traits = { workspace = true } +[target.'cfg(target_os = "solana")'.dependencies] +solana-define-syscall = { workspace = true } + [dev-dependencies] array-bytes = { workspace = true } serde = { workspace = true } serde_derive = { workspace = true } serde_json = { workspace = true } -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - [lints] workspace = true diff --git a/bincode/Cargo.toml b/bincode/Cargo.toml index 70201f15a..a2d55f13f 100644 --- a/bincode/Cargo.toml +++ b/bincode/Cargo.toml @@ -9,6 +9,9 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [dependencies] bincode = { workspace = true } serde = { workspace = true } @@ -19,8 +22,5 @@ solana-instruction = { workspace = true, default-features = false, features = [ [dev-dependencies] solana-system-interface = { workspace = true, features = ["bincode"] } -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - [lints] workspace = true diff --git a/blake3-hasher/Cargo.toml b/blake3-hasher/Cargo.toml index 295b5ac27..59e969ce7 100644 --- a/blake3-hasher/Cargo.toml +++ b/blake3-hasher/Cargo.toml @@ -14,6 +14,14 @@ targets = ["x86_64-unknown-linux-gnu"] all-features = true rustdoc-args = ["--cfg=docsrs"] +[features] +borsh = ["dep:borsh", "std"] +dev-context-only-utils = ["std"] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "std"] +serde = ["dep:serde", "dep:serde_derive"] +blake3 = ["dep:blake3"] +std = ["solana-hash/std"] + [dependencies] borsh = { workspace = true, optional = true } serde = { workspace = true, optional = true } @@ -41,13 +49,5 @@ solana-define-syscall = { workspace = true } bs58 = { workspace = true, features = ["std"] } solana-blake3-hasher = { path = ".", features = ["dev-context-only-utils"] } -[features] -borsh = ["dep:borsh", "std"] -dev-context-only-utils = ["std"] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "std"] -serde = ["dep:serde", "dep:serde_derive"] -blake3 = ["dep:blake3"] -std = ["solana-hash/std"] - [lints] workspace = true diff --git a/bls-signatures/Cargo.toml b/bls-signatures/Cargo.toml new file mode 100644 index 000000000..e680dcff1 --- /dev/null +++ b/bls-signatures/Cargo.toml @@ -0,0 +1,55 @@ +[package] +name = "solana-bls-signatures" +description = "Solana BLS Signatures" +documentation = "https://docs.rs/solana-bls-signatures" +version = "0.1.0" +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[lib] +crate-type = ["rlib"] + +[features] +bytemuck = ["dep:bytemuck"] +default = ["std"] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "std"] +serde = ["dep:cfg_eval", "dep:serde", "dep:serde_with"] +solana-signer-derive = ["dep:solana-signer", "dep:solana-signature", "dep:subtle"] +std = ["dep:serde_json"] + +[dependencies] +base64 = { workspace = true } +bytemuck = { workspace = true, optional = true } +cfg_eval = { workspace = true, optional = true } +serde = { workspace = true, features = ["derive"], optional = true } +serde_json = { workspace = true, optional = true } +serde_with = { workspace = true, features = ["macros"], optional = true } +solana-frozen-abi = { workspace = true, optional = true, features = [ + "frozen-abi", +] } +solana-frozen-abi-macro = { workspace = true, optional = true, features = [ + "frozen-abi", +] } +thiserror = { workspace = true } + +[target.'cfg(not(target_os = "solana"))'.dependencies] +blst = { workspace = true } +blstrs = { workspace = true } +ff = { workspace = true } +group = { workspace = true } +rand = { workspace = true } +solana-signature = { workspace = true, optional = true } +solana-signer = { workspace = true, optional = true } +subtle = { workspace = true, optional = true } + +[dev-dependencies] +bincode = { workspace = true } +solana-bls-signatures = { path = ".", features = ["std"] } +solana-keypair = { workspace = true } +tempfile = { workspace = true } + +[lints] +workspace = true diff --git a/bls-signatures/src/error.rs b/bls-signatures/src/error.rs new file mode 100644 index 000000000..897d25923 --- /dev/null +++ b/bls-signatures/src/error.rs @@ -0,0 +1,17 @@ +use thiserror::Error; + +#[derive(Error, Clone, Debug, Eq, PartialEq)] +pub enum BlsError { + #[error("Field decode failed")] + FieldDecode, + #[error("Empty aggregation attempted")] + EmptyAggregation, + #[error("Key derivation failed")] + KeyDerivation, + #[error("Point representation conversion failed")] + PointConversion, // TODO: could be more specific here + #[error("Failed to parse from string")] + ParseFromString, // TODO: update after more precise error handling + #[error("Failed to parse from bytes")] + ParseFromBytes, +} diff --git a/bls-signatures/src/hash.rs b/bls-signatures/src/hash.rs new file mode 100644 index 000000000..43af1b91a --- /dev/null +++ b/bls-signatures/src/hash.rs @@ -0,0 +1,21 @@ +use { + crate::{proof_of_possession::POP_DST, pubkey::PubkeyProjective}, + blstrs::G2Projective, +}; + +/// Domain separation tag used for hashing messages to curve points to prevent +/// potential conflicts between different BLS implementations. This is defined +/// as the ciphersuite ID string as recommended in the standard +/// https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-bls-signature-05#section-4.2.1. +pub const HASH_TO_POINT_DST: &[u8] = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_"; + +/// Hash a message to a G2 point +pub fn hash_message_to_point(message: &[u8]) -> G2Projective { + G2Projective::hash_to_curve(message, HASH_TO_POINT_DST, &[]) +} + +/// Hash a pubkey to a G2 point +pub(crate) fn hash_pubkey_to_g2(public_key: &PubkeyProjective) -> G2Projective { + let pubkey_bytes = public_key.0.to_compressed(); + G2Projective::hash_to_curve(&pubkey_bytes, POP_DST, &[]) +} diff --git a/bls-signatures/src/keypair.rs b/bls-signatures/src/keypair.rs new file mode 100644 index 000000000..e504d442b --- /dev/null +++ b/bls-signatures/src/keypair.rs @@ -0,0 +1,183 @@ +use crate::{ + error::BlsError, + proof_of_possession::ProofOfPossessionProjective, + pubkey::{PubkeyProjective, BLS_PUBLIC_KEY_AFFINE_SIZE}, + secret_key::{SecretKey, BLS_SECRET_KEY_SIZE}, + signature::SignatureProjective, +}; +#[cfg(feature = "solana-signer-derive")] +use solana_signer::Signer; +#[cfg(feature = "std")] +use std::{ + boxed::Box, + error, + fs::{self, File, OpenOptions}, + io::{Read, Write}, + path::Path, + string::String, + vec::Vec, +}; + +/// Size of BLS keypair in bytes +pub const BLS_KEYPAIR_SIZE: usize = BLS_SECRET_KEY_SIZE + BLS_PUBLIC_KEY_AFFINE_SIZE; + +/// A BLS keypair +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct Keypair { + pub secret: SecretKey, + pub public: PubkeyProjective, +} + +impl Keypair { + /// Constructs a new, random `Keypair` using `OsRng` + #[allow(clippy::new_without_default)] + pub fn new() -> Self { + let secret = SecretKey::new(); + let public = PubkeyProjective::from_secret(&secret); + Self { secret, public } + } + + /// Derive a `Keypair` from a seed (input key material) + pub fn derive(ikm: &[u8]) -> Result { + let secret = SecretKey::derive(ikm)?; + let public = PubkeyProjective::from_secret(&secret); + Ok(Self { secret, public }) + } + + /// Derive a `BlsSecretKey` from a Solana signer + #[cfg(feature = "solana-signer-derive")] + pub fn derive_from_signer(signer: &dyn Signer, public_seed: &[u8]) -> Result { + let secret = SecretKey::derive_from_signer(signer, public_seed)?; + let public = PubkeyProjective::from_secret(&secret); + Ok(Self { secret, public }) + } + + /// Generate a proof of possession for the given keypair + pub fn proof_of_possession(&self) -> ProofOfPossessionProjective { + self.secret.proof_of_possession() + } + + /// Sign a message using the provided secret key + pub fn sign(&self, message: &[u8]) -> SignatureProjective { + self.secret.sign(message) + } + + /// Verify a signature against a message and a public key + pub fn verify(&self, signature: &SignatureProjective, message: &[u8]) -> bool { + self.public.verify(signature, message) + } +} + +impl TryFrom<&[u8]> for Keypair { + type Error = BlsError; + fn try_from(bytes: &[u8]) -> Result { + if bytes.len() != BLS_KEYPAIR_SIZE { + return Err(BlsError::ParseFromBytes); + } + Ok(Self { + secret: SecretKey::try_from(&bytes[..BLS_SECRET_KEY_SIZE])?, + public: PubkeyProjective::try_from(&bytes[BLS_SECRET_KEY_SIZE..])?, + }) + } +} + +impl From<&Keypair> for [u8; BLS_KEYPAIR_SIZE] { + fn from(keypair: &Keypair) -> Self { + let mut bytes = [0u8; BLS_KEYPAIR_SIZE]; + bytes[..BLS_SECRET_KEY_SIZE] + .copy_from_slice(&Into::<[u8; BLS_SECRET_KEY_SIZE]>::into(&keypair.secret)); + bytes[BLS_SECRET_KEY_SIZE..].copy_from_slice( + &Into::<[u8; BLS_PUBLIC_KEY_AFFINE_SIZE]>::into(&keypair.public), + ); + bytes + } +} + +#[cfg(feature = "std")] +impl Keypair { + pub fn read_json(reader: &mut R) -> Result> { + let bytes: Vec = serde_json::from_reader(reader)?; + Self::try_from(bytes.as_slice()) + .ok() + .ok_or_else(|| std::io::Error::other("Invalid BLS keypair").into()) + } + + pub fn read_json_file>(path: F) -> Result> { + let mut file = File::open(path.as_ref())?; + Self::read_json(&mut file) + } + + pub fn write_json(&self, writer: &mut W) -> Result> { + let json = serde_json::to_string(&Into::<[u8; BLS_KEYPAIR_SIZE]>::into(self).as_slice())?; + writer.write_all(&json.clone().into_bytes())?; + Ok(json) + } + + pub fn write_json_file>( + &self, + outfile: F, + ) -> Result> { + let outfile = outfile.as_ref(); + + if let Some(outdir) = outfile.parent() { + fs::create_dir_all(outdir)?; + } + + let mut f = { + #[cfg(not(unix))] + { + OpenOptions::new() + } + #[cfg(unix)] + { + use std::os::unix::fs::OpenOptionsExt; + OpenOptions::new().mode(0o600) + } + } + .write(true) + .truncate(true) + .create(true) + .open(outfile)?; + + self.write_json(&mut f) + } +} + +#[cfg(test)] +mod tests { + use {super::*, tempfile::NamedTempFile}; + + #[test] + fn test_keygen_derive() { + let ikm = b"test_ikm"; + let secret = SecretKey::derive(ikm).unwrap(); + let public = PubkeyProjective::from_secret(&secret); + let keypair = Keypair::derive(ikm).unwrap(); + assert_eq!(keypair.secret, secret); + assert_eq!(keypair.public, public); + } + + #[test] + #[cfg(feature = "solana-signer-derive")] + fn test_keygen_derive_from_signer() { + let solana_keypair = solana_keypair::Keypair::new(); + let secret = SecretKey::derive_from_signer(&solana_keypair, b"alpenglow-vote").unwrap(); + let public = PubkeyProjective::from_secret(&secret); + let keypair = Keypair::derive_from_signer(&solana_keypair, b"alpenglow-vote").unwrap(); + + assert_eq!(keypair.secret, secret); + assert_eq!(keypair.public, public); + } + + #[test] + #[cfg(feature = "std")] + fn test_keypair_file() { + let temp_keypair_file = NamedTempFile::new().unwrap(); + let original_keypair = Keypair::new(); + original_keypair + .write_json_file(&temp_keypair_file) + .unwrap(); + let read_keypair = Keypair::read_json_file(&temp_keypair_file).unwrap(); + assert_eq!(original_keypair, read_keypair); + } +} diff --git a/bls-signatures/src/lib.rs b/bls-signatures/src/lib.rs new file mode 100644 index 000000000..46b8da084 --- /dev/null +++ b/bls-signatures/src/lib.rs @@ -0,0 +1,42 @@ +#![no_std] +#![cfg_attr(feature = "frozen-abi", feature(min_specialization))] + +#[cfg(feature = "std")] +extern crate std; +#[cfg(not(target_os = "solana"))] +pub use crate::{ + error::BlsError, + keypair::Keypair, + proof_of_possession::ProofOfPossessionProjective, + pubkey::PubkeyProjective, + secret_key::{SecretKey, BLS_SECRET_KEY_SIZE}, + signature::SignatureProjective, +}; +pub use crate::{ + proof_of_possession::{ + ProofOfPossession, ProofOfPossessionCompressed, BLS_PROOF_OF_POSSESSION_AFFINE_SIZE, + BLS_PROOF_OF_POSSESSION_COMPRESSED_SIZE, + }, + pubkey::{ + Pubkey, PubkeyCompressed, BLS_PUBLIC_KEY_AFFINE_SIZE, BLS_PUBLIC_KEY_COMPRESSED_SIZE, + }, + signature::{ + Signature, SignatureCompressed, BLS_SIGNATURE_AFFINE_SIZE, BLS_SIGNATURE_COMPRESSED_SIZE, + }, +}; + +// TODO: add conversion between compressed and uncompressed representation of +// signatures, pubkeys, and proof of possessions + +pub mod error; +#[cfg(not(target_os = "solana"))] +pub mod keypair; +#[macro_use] +pub(crate) mod macros; +#[cfg(not(target_os = "solana"))] +pub mod hash; +pub mod proof_of_possession; +pub mod pubkey; +#[cfg(not(target_os = "solana"))] +pub mod secret_key; +pub mod signature; diff --git a/bls-signatures/src/macros.rs b/bls-signatures/src/macros.rs new file mode 100644 index 000000000..d7e7398dc --- /dev/null +++ b/bls-signatures/src/macros.rs @@ -0,0 +1,24 @@ +macro_rules! impl_from_str { + (TYPE = $type:ident, BYTES_LEN = $bytes_len:expr, BASE64_LEN = $base64_len:expr) => { + impl core::str::FromStr for $type { + type Err = crate::error::BlsError; + + fn from_str(s: &str) -> Result { + use base64::Engine; + + if s.len() > $base64_len { + return Err(Self::Err::ParseFromString); + } + let mut bytes = [0u8; $bytes_len]; + let decoded_len = base64::prelude::BASE64_STANDARD + .decode_slice(s, &mut bytes) + .map_err(|_| Self::Err::ParseFromString)?; + if decoded_len != $bytes_len { + Err(Self::Err::ParseFromString) + } else { + Ok($type(bytes)) + } + } + } + }; +} diff --git a/bls-signatures/src/proof_of_possession.rs b/bls-signatures/src/proof_of_possession.rs new file mode 100644 index 000000000..5a9205584 --- /dev/null +++ b/bls-signatures/src/proof_of_possession.rs @@ -0,0 +1,214 @@ +#[cfg(feature = "bytemuck")] +use bytemuck::{Pod, PodInOption, Zeroable, ZeroableInOption}; +#[cfg(not(target_os = "solana"))] +use { + crate::{error::BlsError, pubkey::PubkeyProjective}, + blstrs::{G2Affine, G2Projective}, +}; +use { + base64::{prelude::BASE64_STANDARD, Engine}, + core::fmt, +}; +#[cfg(feature = "serde")] +use { + serde::{Deserialize, Serialize}, + serde_with::serde_as, +}; + +/// Domain separation tag used when hashing public keys to G2 in the proof of +/// possession signing and verification functions. See +/// https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-bls-signature-05#section-4.2.3. +pub const POP_DST: &[u8] = b"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_POP_"; + +/// Size of a BLS proof of possession in a compressed point representation +pub const BLS_PROOF_OF_POSSESSION_COMPRESSED_SIZE: usize = 96; + +/// Size of a BLS proof of possession in a compressed point representation in base64 +pub const BLS_PROOF_OF_POSSESSION_COMPRESSED_BASE64_SIZE: usize = 128; + +/// Size of a BLS proof of possession in an affine point representation +pub const BLS_PROOF_OF_POSSESSION_AFFINE_SIZE: usize = 192; + +/// Size of a BLS proof of possession in an affine point representation in base64 +pub const BLS_PROOF_OF_POSSESSKON_AFFINE_BASE64_SIZE: usize = 256; + +/// A BLS proof of possession in a projective point representation +#[cfg(not(target_os = "solana"))] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct ProofOfPossessionProjective(pub(crate) G2Projective); +#[cfg(not(target_os = "solana"))] +impl ProofOfPossessionProjective { + /// Verify a proof of possession against a public key + pub fn verify(&self, public_key: &PubkeyProjective) -> bool { + public_key.verify_proof_of_possession(self) + } +} + +#[cfg(not(target_os = "solana"))] +impl From for ProofOfPossession { + fn from(proof: ProofOfPossessionProjective) -> Self { + Self(proof.0.to_uncompressed()) + } +} + +#[cfg(not(target_os = "solana"))] +impl TryFrom for ProofOfPossessionProjective { + type Error = BlsError; + + fn try_from(proof: ProofOfPossession) -> Result { + (&proof).try_into() + } +} + +#[cfg(not(target_os = "solana"))] +impl TryFrom<&ProofOfPossession> for ProofOfPossessionProjective { + type Error = BlsError; + + fn try_from(proof: &ProofOfPossession) -> Result { + let maybe_uncompressed: Option = G2Affine::from_uncompressed(&proof.0).into(); + let uncompressed = maybe_uncompressed.ok_or(BlsError::PointConversion)?; + Ok(Self(uncompressed.into())) + } +} + +/// A serialized BLS signature in a compressed point representation +#[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))] +#[cfg_attr(feature = "serde", cfg_eval::cfg_eval, serde_as)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)] +#[repr(transparent)] +pub struct ProofOfPossessionCompressed( + #[cfg_attr( + feature = "serde", + serde_as(as = "[_; BLS_PROOF_OF_POSSESSION_COMPRESSED_SIZE]") + )] + pub [u8; BLS_PROOF_OF_POSSESSION_COMPRESSED_SIZE], +); + +impl Default for ProofOfPossessionCompressed { + fn default() -> Self { + Self([0; BLS_PROOF_OF_POSSESSION_COMPRESSED_SIZE]) + } +} + +impl fmt::Display for ProofOfPossessionCompressed { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", BASE64_STANDARD.encode(self.0)) + } +} + +impl_from_str!( + TYPE = ProofOfPossessionCompressed, + BYTES_LEN = BLS_PROOF_OF_POSSESSION_COMPRESSED_SIZE, + BASE64_LEN = BLS_PROOF_OF_POSSESSION_COMPRESSED_BASE64_SIZE +); + +/// A serialized BLS signature in an affine point representation +#[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))] +#[cfg_attr(feature = "serde", cfg_eval::cfg_eval, serde_as)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)] +#[repr(transparent)] +pub struct ProofOfPossession( + #[cfg_attr( + feature = "serde", + serde_as(as = "[_; BLS_PROOF_OF_POSSESSION_AFFINE_SIZE]") + )] + pub [u8; BLS_PROOF_OF_POSSESSION_AFFINE_SIZE], +); + +impl Default for ProofOfPossession { + fn default() -> Self { + Self([0; BLS_PROOF_OF_POSSESSION_AFFINE_SIZE]) + } +} + +impl fmt::Display for ProofOfPossession { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", BASE64_STANDARD.encode(self.0)) + } +} + +impl_from_str!( + TYPE = ProofOfPossession, + BYTES_LEN = BLS_PROOF_OF_POSSESSION_AFFINE_SIZE, + BASE64_LEN = BLS_PROOF_OF_POSSESSKON_AFFINE_BASE64_SIZE +); + +// Byte arrays are both `Pod` and `Zeraoble`, but the traits `bytemuck::Pod` and +// `bytemuck::Zeroable` can only be derived for power-of-two length byte arrays. +// Directly implement these traits for types that are simple wrappers around +// byte arrays. +#[cfg(feature = "bytemuck")] +mod bytemuck_impls { + use super::*; + + unsafe impl Zeroable for ProofOfPossessionCompressed {} + unsafe impl Pod for ProofOfPossessionCompressed {} + unsafe impl ZeroableInOption for ProofOfPossessionCompressed {} + unsafe impl PodInOption for ProofOfPossessionCompressed {} + + unsafe impl Zeroable for ProofOfPossession {} + unsafe impl Pod for ProofOfPossession {} + unsafe impl ZeroableInOption for ProofOfPossession {} + unsafe impl PodInOption for ProofOfPossession {} +} + +#[cfg(test)] +mod tests { + use {super::*, crate::keypair::Keypair, core::str::FromStr, std::string::ToString}; + + #[test] + fn test_proof_of_possession() { + let keypair = Keypair::new(); + let proof = keypair.proof_of_possession(); + assert!(keypair.public.verify_proof_of_possession(&proof)); + } + + #[test] + fn proof_of_possession_from_str() { + let proof_of_possession = ProofOfPossession([1; BLS_PROOF_OF_POSSESSION_AFFINE_SIZE]); + let proof_of_possession_string = proof_of_possession.to_string(); + let proof_of_possession_from_string = + ProofOfPossession::from_str(&proof_of_possession_string).unwrap(); + assert_eq!(proof_of_possession, proof_of_possession_from_string); + + let proof_of_possession_compressed = + ProofOfPossessionCompressed([1; BLS_PROOF_OF_POSSESSION_COMPRESSED_SIZE]); + let proof_of_possession_compressed_string = proof_of_possession_compressed.to_string(); + let proof_of_possession_compressed_from_string = + ProofOfPossessionCompressed::from_str(&proof_of_possession_compressed_string).unwrap(); + assert_eq!( + proof_of_possession_compressed, + proof_of_possession_compressed_from_string + ); + } + + #[cfg(feature = "serde")] + #[test] + fn serialize_and_deserialize_proof_of_possession() { + let original = ProofOfPossession::default(); + let serialized = bincode::serialize(&original).unwrap(); + let deserialized: ProofOfPossession = bincode::deserialize(&serialized).unwrap(); + assert_eq!(original, deserialized); + + let original = ProofOfPossession([1; BLS_PROOF_OF_POSSESSION_AFFINE_SIZE]); + let serialized = bincode::serialize(&original).unwrap(); + let deserialized: ProofOfPossession = bincode::deserialize(&serialized).unwrap(); + assert_eq!(original, deserialized); + } + + #[cfg(feature = "serde")] + #[test] + fn serialize_and_deserialize_proof_of_possession_compressed() { + let original = ProofOfPossessionCompressed::default(); + let serialized = bincode::serialize(&original).unwrap(); + let deserialized: ProofOfPossessionCompressed = bincode::deserialize(&serialized).unwrap(); + assert_eq!(original, deserialized); + + let original = ProofOfPossessionCompressed([1; BLS_PROOF_OF_POSSESSION_COMPRESSED_SIZE]); + let serialized = bincode::serialize(&original).unwrap(); + let deserialized: ProofOfPossessionCompressed = bincode::deserialize(&serialized).unwrap(); + assert_eq!(original, deserialized); + } +} diff --git a/bls-signatures/src/pubkey.rs b/bls-signatures/src/pubkey.rs new file mode 100644 index 000000000..7c84f6949 --- /dev/null +++ b/bls-signatures/src/pubkey.rs @@ -0,0 +1,286 @@ +#[cfg(feature = "bytemuck")] +use bytemuck::{Pod, PodInOption, Zeroable, ZeroableInOption}; +#[cfg(not(target_os = "solana"))] +use { + crate::{ + error::BlsError, + hash::{hash_message_to_point, hash_pubkey_to_g2}, + proof_of_possession::ProofOfPossessionProjective, + secret_key::SecretKey, + signature::SignatureProjective, + }, + blstrs::{pairing, G1Affine, G1Projective}, + group::{prime::PrimeCurveAffine, Group}, +}; +use { + base64::{prelude::BASE64_STANDARD, Engine}, + core::fmt, +}; +#[cfg(feature = "serde")] +use { + serde::{Deserialize, Serialize}, + serde_with::serde_as, +}; + +/// Size of a BLS public key in a compressed point representation +pub const BLS_PUBLIC_KEY_COMPRESSED_SIZE: usize = 48; + +/// Size of a BLS public key in a compressed point representation in base64 +pub const BLS_PUBLIC_KEY_COMPRESSED_BASE64_SIZE: usize = 128; + +/// Size of a BLS public key in an affine point representation +pub const BLS_PUBLIC_KEY_AFFINE_SIZE: usize = 96; + +/// Size of a BLS public key in an affine point representation in base64 +pub const BLS_PUBLIC_KEY_AFFINE_BASE64_SIZE: usize = 256; + +/// A BLS public key in a projective point representation +#[cfg(not(target_os = "solana"))] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub struct PubkeyProjective(pub(crate) G1Projective); + +#[cfg(not(target_os = "solana"))] +impl Default for PubkeyProjective { + fn default() -> Self { + Self(G1Projective::identity()) + } +} + +#[cfg(not(target_os = "solana"))] +impl PubkeyProjective { + /// Construct a corresponding `BlsPubkey` for a `BlsSecretKey` + #[allow(clippy::arithmetic_side_effects)] + pub fn from_secret(secret: &SecretKey) -> Self { + Self(G1Projective::generator() * secret.0) + } + + /// Verify a signature against a message and a public key + /// + /// TODO: Verify by invoking pairing just once + pub fn verify(&self, signature: &SignatureProjective, message: &[u8]) -> bool { + let hashed_message = hash_message_to_point(message); + pairing(&self.0.into(), &hashed_message.into()) + == pairing(&G1Affine::generator(), &signature.0.into()) + } + + /// Verify a proof of possession against a public key + pub fn verify_proof_of_possession(&self, proof: &ProofOfPossessionProjective) -> bool { + let hashed_pubkey_bytes = hash_pubkey_to_g2(self); + pairing(&self.0.into(), &hashed_pubkey_bytes.into()) + == pairing(&G1Affine::generator(), &proof.0.into()) + } + + /// Aggregate a list of public keys into an existing aggregate + #[allow(clippy::arithmetic_side_effects)] + pub fn aggregate_with<'a, I>(&mut self, pubkeys: I) + where + I: IntoIterator, + { + self.0 = pubkeys.into_iter().fold(self.0, |mut acc, pubkey| { + acc += &pubkey.0; + acc + }); + } + + /// Aggregate a list of public keys + #[allow(clippy::arithmetic_side_effects)] + pub fn aggregate<'a, I>(pubkeys: I) -> Result + where + I: IntoIterator, + { + let mut iter = pubkeys.into_iter(); + if let Some(acc) = iter.next() { + let aggregate_point = iter.fold(acc.0, |mut acc, pubkey| { + acc += &pubkey.0; + acc + }); + Ok(Self(aggregate_point)) + } else { + Err(BlsError::EmptyAggregation) + } + } +} + +#[cfg(not(target_os = "solana"))] +impl From for Pubkey { + fn from(proof: PubkeyProjective) -> Self { + Self(proof.0.to_uncompressed()) + } +} + +#[cfg(not(target_os = "solana"))] +impl TryFrom for PubkeyProjective { + type Error = BlsError; + + fn try_from(proof: Pubkey) -> Result { + (&proof).try_into() + } +} + +#[cfg(not(target_os = "solana"))] +impl TryFrom<&Pubkey> for PubkeyProjective { + type Error = BlsError; + + fn try_from(proof: &Pubkey) -> Result { + let maybe_uncompressed: Option = G1Affine::from_uncompressed(&proof.0).into(); + let uncompressed = maybe_uncompressed.ok_or(BlsError::PointConversion)?; + Ok(Self(uncompressed.into())) + } +} + +#[cfg(not(target_os = "solana"))] +impl TryFrom<&[u8]> for PubkeyProjective { + type Error = BlsError; + fn try_from(bytes: &[u8]) -> Result { + if bytes.len() != BLS_PUBLIC_KEY_AFFINE_SIZE { + return Err(BlsError::ParseFromBytes); + } + // unwrap safe due to the length check above + let public_affine = Pubkey(bytes.try_into().unwrap()); + + public_affine.try_into() + } +} + +#[cfg(not(target_os = "solana"))] +impl From<&PubkeyProjective> for [u8; BLS_PUBLIC_KEY_AFFINE_SIZE] { + fn from(pubkey: &PubkeyProjective) -> Self { + let pubkey_affine: Pubkey = (*pubkey).into(); + pubkey_affine.0 + } +} + +/// A serialized BLS public key in a compressed point representation +#[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))] +#[cfg_attr(feature = "serde", cfg_eval::cfg_eval, serde_as)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[repr(transparent)] +pub struct PubkeyCompressed( + #[cfg_attr( + feature = "serde", + serde_as(as = "[_; BLS_PUBLIC_KEY_COMPRESSED_SIZE]") + )] + pub [u8; BLS_PUBLIC_KEY_COMPRESSED_SIZE], +); + +impl Default for PubkeyCompressed { + fn default() -> Self { + Self([0; BLS_PUBLIC_KEY_COMPRESSED_SIZE]) + } +} + +impl fmt::Display for PubkeyCompressed { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", BASE64_STANDARD.encode(self.0)) + } +} + +impl_from_str!( + TYPE = PubkeyCompressed, + BYTES_LEN = BLS_PUBLIC_KEY_COMPRESSED_SIZE, + BASE64_LEN = BLS_PUBLIC_KEY_COMPRESSED_BASE64_SIZE +); + +/// A serialized BLS public key in an affine point representation +#[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))] +#[cfg_attr(feature = "serde", cfg_eval::cfg_eval, serde_as)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)] +#[repr(transparent)] +pub struct Pubkey( + #[cfg_attr(feature = "serde", serde_as(as = "[_; BLS_PUBLIC_KEY_AFFINE_SIZE]"))] + pub [u8; BLS_PUBLIC_KEY_AFFINE_SIZE], +); + +impl Default for Pubkey { + fn default() -> Self { + Self([0; BLS_PUBLIC_KEY_AFFINE_SIZE]) + } +} + +impl fmt::Display for Pubkey { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", BASE64_STANDARD.encode(self.0)) + } +} + +impl_from_str!( + TYPE = Pubkey, + BYTES_LEN = BLS_PUBLIC_KEY_AFFINE_SIZE, + BASE64_LEN = BLS_PUBLIC_KEY_AFFINE_BASE64_SIZE +); + +// Byte arrays are both `Pod` and `Zeraoble`, but the traits `bytemuck::Pod` and +// `bytemuck::Zeroable` can only be derived for power-of-two length byte arrays. +// Directly implement these traits for types that are simple wrappers around +// byte arrays. +#[cfg(feature = "bytemuck")] +mod bytemuck_impls { + use super::*; + unsafe impl Zeroable for PubkeyCompressed {} + unsafe impl Pod for PubkeyCompressed {} + unsafe impl ZeroableInOption for PubkeyCompressed {} + unsafe impl PodInOption for PubkeyCompressed {} + + unsafe impl Zeroable for Pubkey {} + unsafe impl Pod for Pubkey {} + unsafe impl ZeroableInOption for Pubkey {} + unsafe impl PodInOption for Pubkey {} +} + +#[cfg(test)] +mod tests { + use {super::*, crate::keypair::Keypair, core::str::FromStr, std::string::ToString}; + + #[test] + fn test_verify() { + let keypair = Keypair::new(); + let test_message = b"test message"; + let signature = keypair.sign(test_message); + assert!(keypair.public.verify(&signature, test_message)); + } + + #[test] + fn pubkey_from_str() { + let pubkey = Keypair::new().public; + let pubkey_affine: Pubkey = pubkey.into(); + let pubkey_affine_string = pubkey_affine.to_string(); + let pubkey_affine_from_string = Pubkey::from_str(&pubkey_affine_string).unwrap(); + assert_eq!(pubkey_affine, pubkey_affine_from_string); + + let pubkey_compressed = PubkeyCompressed([1; BLS_PUBLIC_KEY_COMPRESSED_SIZE]); + let pubkey_compressed_string = pubkey_compressed.to_string(); + let pubkey_compressed_from_string = + PubkeyCompressed::from_str(&pubkey_compressed_string).unwrap(); + assert_eq!(pubkey_compressed, pubkey_compressed_from_string); + } + + #[cfg(feature = "serde")] + #[test] + fn serialize_and_deserialize_pubkey() { + let original = Pubkey::default(); + let serialized = bincode::serialize(&original).unwrap(); + let deserialized: Pubkey = bincode::deserialize(&serialized).unwrap(); + assert_eq!(original, deserialized); + + let original = Pubkey([1; BLS_PUBLIC_KEY_AFFINE_SIZE]); + let serialized = bincode::serialize(&original).unwrap(); + let deserialized: Pubkey = bincode::deserialize(&serialized).unwrap(); + assert_eq!(original, deserialized); + } + + #[cfg(feature = "serde")] + #[test] + fn serialize_and_deserialize_pubkey_compressed() { + let original = PubkeyCompressed::default(); + let serialized = bincode::serialize(&original).unwrap(); + let deserialized: PubkeyCompressed = bincode::deserialize(&serialized).unwrap(); + assert_eq!(original, deserialized); + + let original = PubkeyCompressed([1; BLS_PUBLIC_KEY_COMPRESSED_SIZE]); + let serialized = bincode::serialize(&original).unwrap(); + let deserialized: PubkeyCompressed = bincode::deserialize(&serialized).unwrap(); + assert_eq!(original, deserialized); + } +} diff --git a/bls-signatures/src/secret_key.rs b/bls-signatures/src/secret_key.rs new file mode 100644 index 000000000..789cd6129 --- /dev/null +++ b/bls-signatures/src/secret_key.rs @@ -0,0 +1,100 @@ +use { + crate::{ + error::BlsError, + hash::{hash_message_to_point, hash_pubkey_to_g2}, + proof_of_possession::ProofOfPossessionProjective, + pubkey::PubkeyProjective, + signature::SignatureProjective, + }, + blst::{blst_keygen, blst_scalar}, + blstrs::Scalar, + core::ptr, + ff::Field, + rand::rngs::OsRng, +}; +#[cfg(feature = "solana-signer-derive")] +use {solana_signature::Signature, solana_signer::Signer, subtle::ConstantTimeEq}; + +/// Size of BLS secret key in bytes +pub const BLS_SECRET_KEY_SIZE: usize = 32; + +/// A BLS secret key +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct SecretKey(pub(crate) Scalar); + +impl SecretKey { + /// Constructs a new, random `BlsSecretKey` using `OsRng` + #[allow(clippy::new_without_default)] + pub fn new() -> Self { + let mut rng = OsRng; + Self(Scalar::random(&mut rng)) + } + + /// Derive a `BlsSecretKey` from a seed (input key material) + pub fn derive(ikm: &[u8]) -> Result { + let mut scalar = blst_scalar::default(); + unsafe { + blst_keygen( + &mut scalar as *mut blst_scalar, + ikm.as_ptr(), + ikm.len(), + ptr::null(), + 0, + ); + } + scalar + .try_into() + .map(Self) + .map_err(|_| BlsError::FieldDecode) + } + + /// Derive a `BlsSecretKey` from a Solana signer + #[cfg(feature = "solana-signer-derive")] + pub fn derive_from_signer(signer: &dyn Signer, public_seed: &[u8]) -> Result { + let message = [b"bls-key-derive-", public_seed].concat(); + let signature = signer + .try_sign_message(&message) + .map_err(|_| BlsError::KeyDerivation)?; + + // Some `Signer` implementations return the default signature, which is not suitable for + // use as key material + if bool::from(signature.as_ref().ct_eq(Signature::default().as_ref())) { + return Err(BlsError::KeyDerivation); + } + + Self::derive(signature.as_ref()) + } + + /// Generate a proof of possession for the corresponding pubkey + #[allow(clippy::arithmetic_side_effects)] + pub fn proof_of_possession(&self) -> ProofOfPossessionProjective { + let pubkey = PubkeyProjective::from_secret(self); + let hashed_pubkey_bytes = hash_pubkey_to_g2(&pubkey); + ProofOfPossessionProjective(hashed_pubkey_bytes * self.0) + } + + /// Sign a message using the provided secret key + #[allow(clippy::arithmetic_side_effects)] + pub fn sign(&self, message: &[u8]) -> SignatureProjective { + let hashed_message = hash_message_to_point(message); + SignatureProjective(hashed_message * self.0) + } +} + +impl TryFrom<&[u8]> for SecretKey { + type Error = BlsError; + fn try_from(bytes: &[u8]) -> Result { + if bytes.len() != BLS_SECRET_KEY_SIZE { + return Err(BlsError::ParseFromBytes); + } + // unwrap safe due to the length check above + let scalar: Option = Scalar::from_bytes_le(bytes.try_into().unwrap()).into(); + scalar.ok_or(BlsError::FieldDecode).map(Self) + } +} + +impl From<&SecretKey> for [u8; BLS_SECRET_KEY_SIZE] { + fn from(secret_key: &SecretKey) -> Self { + secret_key.0.to_bytes_le() + } +} diff --git a/bls-signatures/src/signature.rs b/bls-signatures/src/signature.rs new file mode 100644 index 000000000..94a8bbf71 --- /dev/null +++ b/bls-signatures/src/signature.rs @@ -0,0 +1,302 @@ +#[cfg(feature = "bytemuck")] +use bytemuck::{Pod, PodInOption, Zeroable, ZeroableInOption}; +#[cfg(not(target_os = "solana"))] +use { + crate::{error::BlsError, pubkey::PubkeyProjective}, + blstrs::{G2Affine, G2Projective}, + group::Group, +}; +use { + base64::{prelude::BASE64_STANDARD, Engine}, + core::fmt, +}; +#[cfg(feature = "serde")] +use { + serde::{Deserialize, Serialize}, + serde_with::serde_as, +}; + +/// Size of a BLS signature in a compressed point representation +pub const BLS_SIGNATURE_COMPRESSED_SIZE: usize = 96; + +/// Size of a BLS signature in a compressed point representation in base64 +pub const BLS_SIGNATURE_COMPRESSED_BASE64_SIZE: usize = 128; + +/// Size of a BLS signature in an affine point representation +pub const BLS_SIGNATURE_AFFINE_SIZE: usize = 192; + +/// Size of a BLS signature in an affine point representation in base64 +pub const BLS_SIGNATURE_AFFINE_BASE64_SIZE: usize = 256; + +/// A BLS signature in a projective point representation +#[cfg(not(target_os = "solana"))] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct SignatureProjective(pub(crate) G2Projective); + +#[cfg(not(target_os = "solana"))] +impl Default for SignatureProjective { + fn default() -> Self { + Self(G2Projective::identity()) + } +} + +#[cfg(not(target_os = "solana"))] +impl SignatureProjective { + /// Verify a signature against a message and a public key + pub fn verify(&self, pubkey: &PubkeyProjective, message: &[u8]) -> bool { + pubkey.verify(self, message) + } + + /// Aggregate a list of signatures into an existing aggregate + #[allow(clippy::arithmetic_side_effects)] + pub fn aggregate_with<'a, I>(&mut self, signatures: I) + where + I: IntoIterator, + { + self.0 = signatures.into_iter().fold(self.0, |mut acc, signature| { + acc += &signature.0; + acc + }); + } + + /// Aggregate a list of public keys + #[allow(clippy::arithmetic_side_effects)] + pub fn aggregate<'a, I>(signatures: I) -> Result + where + I: IntoIterator, + { + let mut iter = signatures.into_iter(); + if let Some(acc) = iter.next() { + let aggregate_point = iter.fold(acc.0, |mut acc, signature| { + acc += &signature.0; + acc + }); + Ok(Self(aggregate_point)) + } else { + Err(BlsError::EmptyAggregation) + } + } + + /// Verify a list of signatures against a message and a list of public keys + pub fn aggregate_verify<'a, I, J>( + public_keys: I, + signatures: J, + message: &[u8], + ) -> Result + where + I: IntoIterator, + J: IntoIterator, + { + let aggregate_pubkey = PubkeyProjective::aggregate(public_keys)?; + let aggregate_signature = SignatureProjective::aggregate(signatures)?; + + Ok(aggregate_pubkey.verify(&aggregate_signature, message)) + } +} + +#[cfg(not(target_os = "solana"))] +impl From for Signature { + fn from(proof: SignatureProjective) -> Self { + Self(proof.0.to_uncompressed()) + } +} + +#[cfg(not(target_os = "solana"))] +impl TryFrom for SignatureProjective { + type Error = BlsError; + + fn try_from(proof: Signature) -> Result { + let maybe_uncompressed: Option = G2Affine::from_uncompressed(&proof.0).into(); + let uncompressed = maybe_uncompressed.ok_or(BlsError::PointConversion)?; + Ok(Self(uncompressed.into())) + } +} + +#[cfg(not(target_os = "solana"))] +impl TryFrom<&Signature> for SignatureProjective { + type Error = BlsError; + + fn try_from(proof: &Signature) -> Result { + let maybe_uncompressed: Option = G2Affine::from_uncompressed(&proof.0).into(); + let uncompressed = maybe_uncompressed.ok_or(BlsError::PointConversion)?; + Ok(Self(uncompressed.into())) + } +} + +/// A serialized BLS signature in a compressed point representation +#[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))] +#[cfg_attr(feature = "serde", cfg_eval::cfg_eval, serde_as)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)] +#[repr(transparent)] +pub struct SignatureCompressed( + #[cfg_attr(feature = "serde", serde_as(as = "[_; BLS_SIGNATURE_COMPRESSED_SIZE]"))] + pub [u8; BLS_SIGNATURE_COMPRESSED_SIZE], +); + +impl Default for SignatureCompressed { + fn default() -> Self { + Self([0; BLS_SIGNATURE_COMPRESSED_SIZE]) + } +} + +impl fmt::Display for SignatureCompressed { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", BASE64_STANDARD.encode(self.0)) + } +} + +impl_from_str!( + TYPE = SignatureCompressed, + BYTES_LEN = BLS_SIGNATURE_COMPRESSED_SIZE, + BASE64_LEN = BLS_SIGNATURE_COMPRESSED_BASE64_SIZE +); + +/// A serialized BLS signature in an affine point representation +#[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))] +#[cfg_attr(feature = "serde", cfg_eval::cfg_eval, serde_as)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)] +#[repr(transparent)] +pub struct Signature( + #[cfg_attr(feature = "serde", serde_as(as = "[_; BLS_SIGNATURE_AFFINE_SIZE]"))] + pub [u8; BLS_SIGNATURE_AFFINE_SIZE], +); + +impl Default for Signature { + fn default() -> Self { + Self([0; BLS_SIGNATURE_AFFINE_SIZE]) + } +} + +impl fmt::Display for Signature { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", BASE64_STANDARD.encode(self.0)) + } +} + +impl_from_str!( + TYPE = Signature, + BYTES_LEN = BLS_SIGNATURE_AFFINE_SIZE, + BASE64_LEN = BLS_SIGNATURE_AFFINE_BASE64_SIZE +); + +// Byte arrays are both `Pod` and `Zeraoble`, but the traits `bytemuck::Pod` and +// `bytemuck::Zeroable` can only be derived for power-of-two length byte arrays. +// Directly implement these traits for types that are simple wrappers around +// byte arrays. +#[cfg(feature = "bytemuck")] +mod bytemuck_impls { + use super::*; + + unsafe impl Zeroable for Signature {} + unsafe impl Pod for Signature {} + unsafe impl ZeroableInOption for Signature {} + unsafe impl PodInOption for Signature {} + + unsafe impl Zeroable for SignatureCompressed {} + unsafe impl Pod for SignatureCompressed {} + unsafe impl ZeroableInOption for SignatureCompressed {} + unsafe impl PodInOption for SignatureCompressed {} +} + +#[cfg(test)] +mod tests { + use { + super::*, + crate::keypair::Keypair, + core::str::FromStr, + std::{string::ToString, vec}, + }; + + #[test] + fn test_signature_aggregate() { + let test_message = b"test message"; + let keypair0 = Keypair::new(); + let signature0 = keypair0.sign(test_message); + + let test_message = b"test message"; + let keypair1 = Keypair::new(); + let signature1 = keypair1.sign(test_message); + + let aggregate_signature = + SignatureProjective::aggregate([&signature0, &signature1]).unwrap(); + + let mut aggregate_signature_with = signature0; + aggregate_signature_with.aggregate_with([&signature1]); + + assert_eq!(aggregate_signature, aggregate_signature_with); + } + + #[test] + fn test_aggregate_verify() { + let test_message = b"test message"; + + let keypair0 = Keypair::new(); + let signature0 = keypair0.sign(test_message); + assert!(keypair0.public.verify(&signature0, test_message)); + + let keypair1 = Keypair::new(); + let signature1 = keypair1.secret.sign(test_message); + assert!(keypair1.public.verify(&signature1, test_message)); + + // basic case + assert!(SignatureProjective::aggregate_verify( + vec![&keypair0.public, &keypair1.public], + vec![&signature0, &signature1], + test_message, + ) + .unwrap()); + + // pre-aggregate the signatures + let aggregate_signature = + SignatureProjective::aggregate([&signature0, &signature1]).unwrap(); + assert!(SignatureProjective::aggregate_verify( + vec![&keypair0.public, &keypair1.public], + vec![&aggregate_signature], + test_message, + ) + .unwrap()); + + // pre-aggregate the public keys + let aggregate_pubkey = + PubkeyProjective::aggregate([&keypair0.public, &keypair1.public]).unwrap(); + assert!(SignatureProjective::aggregate_verify( + vec![&aggregate_pubkey], + vec![&signature0, &signature1], + test_message, + ) + .unwrap()); + + // empty set of public keys or signatures + let err = SignatureProjective::aggregate_verify( + vec![], + vec![&signature0, &signature1], + test_message, + ) + .unwrap_err(); + assert_eq!(err, BlsError::EmptyAggregation); + + let err = SignatureProjective::aggregate_verify( + vec![&keypair0.public, &keypair1.public], + vec![], + test_message, + ) + .unwrap_err(); + assert_eq!(err, BlsError::EmptyAggregation); + } + + #[test] + fn signature_from_str() { + let signature_affine = Signature([1; BLS_SIGNATURE_AFFINE_SIZE]); + let signature_affine_string = signature_affine.to_string(); + let signature_affine_from_string = Signature::from_str(&signature_affine_string).unwrap(); + assert_eq!(signature_affine, signature_affine_from_string); + + let signature_compressed = SignatureCompressed([1; BLS_SIGNATURE_COMPRESSED_SIZE]); + let signature_compressed_string = signature_compressed.to_string(); + let signature_compressed_from_string = + SignatureCompressed::from_str(&signature_compressed_string).unwrap(); + assert_eq!(signature_compressed, signature_compressed_from_string); + } +} diff --git a/borsh/Cargo.toml b/borsh/Cargo.toml index 426767bba..1a25cc7c1 100644 --- a/borsh/Cargo.toml +++ b/borsh/Cargo.toml @@ -9,12 +9,12 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [dependencies] borsh = { workspace = true } borsh0-10 = { workspace = true } -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - [lints] workspace = true diff --git a/client-traits/Cargo.toml b/client-traits/Cargo.toml index abfcd8759..a1edbf483 100644 --- a/client-traits/Cargo.toml +++ b/client-traits/Cargo.toml @@ -9,6 +9,9 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [dependencies] solana-account = { workspace = true } solana-commitment-config = { workspace = true } @@ -23,6 +26,3 @@ solana-signer = { workspace = true } solana-system-interface = { workspace = true } solana-transaction = { workspace = true, features = ["bincode"] } solana-transaction-error = { workspace = true } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] diff --git a/clock/Cargo.toml b/clock/Cargo.toml index e22459cc5..3f7fde3c0 100644 --- a/clock/Cargo.toml +++ b/clock/Cargo.toml @@ -2,13 +2,22 @@ name = "solana-clock" description = "Solana Clock and Time Definitions" documentation = "https://docs.rs/solana-clock" -version = "2.2.1" +version = "2.2.2" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +serde = ["dep:serde", "dep:serde_derive"] +sysvar = ["dep:solana-sdk-ids", "dep:solana-sysvar-id"] + [dependencies] serde = { workspace = true, optional = true } serde_derive = { workspace = true, optional = true } @@ -19,12 +28,3 @@ solana-sysvar-id = { workspace = true, optional = true } [dev-dependencies] solana-clock = { path = ".", features = ["sysvar"] } static_assertions = { workspace = true } - -[features] -serde = ["dep:serde", "dep:serde_derive"] -sysvar = ["dep:solana-sdk-ids", "dep:solana-sysvar-id"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] diff --git a/clock/src/lib.rs b/clock/src/lib.rs index da27edc4a..8596923d7 100644 --- a/clock/src/lib.rs +++ b/clock/src/lib.rs @@ -44,45 +44,49 @@ pub const MS_PER_TICK: u64 = 1000 / DEFAULT_TICKS_PER_SECOND; // every 400 ms. A fast voting cadence ensures faster finality and convergence pub const DEFAULT_TICKS_PER_SLOT: u64 = 64; -// GCP n1-standard hardware and also a xeon e5-2520 v4 are about this rate of hashes/s -pub const DEFAULT_HASHES_PER_SECOND: u64 = 2_000_000; +pub const DEFAULT_HASHES_PER_SECOND: u64 = 10_000_000; // Empirical sampling of mainnet validator hash rate showed the following stake // percentages can exceed the designated hash rates as of July 2023: // 97.6% +#[deprecated(since = "2.2.2", note = "Use 'DEFAULT_HASHES_PER_SECOND' instead")] pub const UPDATED_HASHES_PER_SECOND_2: u64 = 2_800_000; // 96.2% +#[deprecated(since = "2.2.2", note = "Use 'DEFAULT_HASHES_PER_SECOND' instead")] pub const UPDATED_HASHES_PER_SECOND_3: u64 = 4_400_000; // 96.2% +#[deprecated(since = "2.2.2", note = "Use 'DEFAULT_HASHES_PER_SECOND' instead")] pub const UPDATED_HASHES_PER_SECOND_4: u64 = 7_600_000; // 96.2% +#[deprecated(since = "2.2.2", note = "Use 'DEFAULT_HASHES_PER_SECOND' instead")] pub const UPDATED_HASHES_PER_SECOND_5: u64 = 9_200_000; // 96.2% +#[deprecated(since = "2.2.2", note = "Use 'DEFAULT_HASHES_PER_SECOND' instead")] pub const UPDATED_HASHES_PER_SECOND_6: u64 = 10_000_000; #[cfg(test)] -static_assertions::const_assert_eq!(DEFAULT_HASHES_PER_TICK, 12_500); +static_assertions::const_assert_eq!(DEFAULT_HASHES_PER_TICK, 62_500); pub const DEFAULT_HASHES_PER_TICK: u64 = DEFAULT_HASHES_PER_SECOND / DEFAULT_TICKS_PER_SECOND; #[cfg(test)] -static_assertions::const_assert_eq!(UPDATED_HASHES_PER_TICK2, 17_500); -pub const UPDATED_HASHES_PER_TICK2: u64 = UPDATED_HASHES_PER_SECOND_2 / DEFAULT_TICKS_PER_SECOND; +#[deprecated(since = "2.2.2", note = "Use 'DEFAULT_HASHES_PER_TICK' instead")] +pub const UPDATED_HASHES_PER_TICK2: u64 = DEFAULT_HASHES_PER_SECOND / DEFAULT_TICKS_PER_SECOND; #[cfg(test)] -static_assertions::const_assert_eq!(UPDATED_HASHES_PER_TICK3, 27_500); -pub const UPDATED_HASHES_PER_TICK3: u64 = UPDATED_HASHES_PER_SECOND_3 / DEFAULT_TICKS_PER_SECOND; +#[deprecated(since = "2.2.2", note = "Use 'DEFAULT_HASHES_PER_TICK' instead")] +pub const UPDATED_HASHES_PER_TICK3: u64 = DEFAULT_HASHES_PER_SECOND / DEFAULT_TICKS_PER_SECOND; #[cfg(test)] -static_assertions::const_assert_eq!(UPDATED_HASHES_PER_TICK4, 47_500); -pub const UPDATED_HASHES_PER_TICK4: u64 = UPDATED_HASHES_PER_SECOND_4 / DEFAULT_TICKS_PER_SECOND; +#[deprecated(since = "2.2.2", note = "Use 'DEFAULT_HASHES_PER_TICK' instead")] +pub const UPDATED_HASHES_PER_TICK4: u64 = DEFAULT_HASHES_PER_SECOND / DEFAULT_TICKS_PER_SECOND; #[cfg(test)] -static_assertions::const_assert_eq!(UPDATED_HASHES_PER_TICK5, 57_500); -pub const UPDATED_HASHES_PER_TICK5: u64 = UPDATED_HASHES_PER_SECOND_5 / DEFAULT_TICKS_PER_SECOND; +#[deprecated(since = "2.2.2", note = "Use 'DEFAULT_HASHES_PER_TICK' instead")] +pub const UPDATED_HASHES_PER_TICK5: u64 = DEFAULT_HASHES_PER_SECOND / DEFAULT_TICKS_PER_SECOND; #[cfg(test)] -static_assertions::const_assert_eq!(UPDATED_HASHES_PER_TICK6, 62_500); -pub const UPDATED_HASHES_PER_TICK6: u64 = UPDATED_HASHES_PER_SECOND_6 / DEFAULT_TICKS_PER_SECOND; +#[deprecated(since = "2.2.2", note = "Use 'DEFAULT_HASHES_PER_TICK' instead")] +pub const UPDATED_HASHES_PER_TICK6: u64 = DEFAULT_HASHES_PER_SECOND / DEFAULT_TICKS_PER_SECOND; // 1 Dev Epoch = 400 ms * 8192 ~= 55 minutes pub const DEFAULT_DEV_SLOTS_PER_EPOCH: u64 = 8192; diff --git a/cluster-type/Cargo.toml b/cluster-type/Cargo.toml index 21a1bee89..ea14e6a4b 100644 --- a/cluster-type/Cargo.toml +++ b/cluster-type/Cargo.toml @@ -9,18 +9,18 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] +serde = ["dep:serde", "dep:serde_derive"] + [dependencies] serde = { workspace = true, optional = true } serde_derive = { workspace = true, optional = true } solana-frozen-abi = { workspace = true, optional = true } solana-frozen-abi-macro = { workspace = true, optional = true } solana-hash = { workspace = true, default-features = false } - -[features] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] -serde = ["dep:serde", "dep:serde_derive"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] diff --git a/commitment-config/Cargo.toml b/commitment-config/Cargo.toml index 6224c03dc..cba27c057 100644 --- a/commitment-config/Cargo.toml +++ b/commitment-config/Cargo.toml @@ -9,12 +9,12 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } -[dependencies] -serde = { workspace = true, optional = true } -serde_derive = { workspace = true, optional = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] [features] serde = ["dep:serde", "dep:serde_derive"] -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] +[dependencies] +serde = { workspace = true, optional = true } +serde_derive = { workspace = true, optional = true } diff --git a/compute-budget-interface/Cargo.toml b/compute-budget-interface/Cargo.toml index ce5cc36f9..9d3ca8f93 100644 --- a/compute-budget-interface/Cargo.toml +++ b/compute-budget-interface/Cargo.toml @@ -9,6 +9,17 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +borsh = ["dep:borsh"] +dev-context-only-utils = ["borsh"] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "serde"] +serde = ["dep:serde", "dep:serde_derive"] + [dependencies] borsh = { workspace = true, optional = true } serde = { workspace = true, optional = true } @@ -22,16 +33,5 @@ solana-frozen-abi-macro = { workspace = true, features = [ solana-instruction = { workspace = true, features = ["std"] } solana-sdk-ids = { workspace = true } -[features] -borsh = ["dep:borsh"] -dev-context-only-utils = ["borsh"] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "serde"] -serde = ["dep:serde", "dep:serde_derive"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/cpi/Cargo.toml b/cpi/Cargo.toml index 66205741a..dcdd67133 100644 --- a/cpi/Cargo.toml +++ b/cpi/Cargo.toml @@ -9,6 +9,9 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [dependencies] solana-account-info = { workspace = true } solana-instruction = { workspace = true } @@ -26,8 +29,5 @@ solana-sdk-ids = { workspace = true } solana-system-interface = { workspace = true, features = ["bincode"] } static_assertions = { workspace = true } -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - [lints] workspace = true diff --git a/decode-error/Cargo.toml b/decode-error/Cargo.toml index 623dde239..d2ffbce28 100644 --- a/decode-error/Cargo.toml +++ b/decode-error/Cargo.toml @@ -2,7 +2,7 @@ name = "solana-decode-error" description = "Solana DecodeError Trait" documentation = "https://docs.rs/solana-decode-error" -version = "2.2.1" +version = "2.3.0" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } diff --git a/decode-error/src/lib.rs b/decode-error/src/lib.rs index bcdf5ad5a..fb4aa992b 100644 --- a/decode-error/src/lib.rs +++ b/decode-error/src/lib.rs @@ -21,6 +21,10 @@ use num_traits::FromPrimitive; /// [`ProgramError`]: https://docs.rs/solana-program-error/latest/solana_program_error/enum.ProgramError.html /// [`ProgramError::Custom`]: https://docs.rs/solana-program-error/latest/solana_program_error/enum.ProgramError.html#variant.Custom /// [`ToPrimitive`]: num_traits::ToPrimitive +#[deprecated( + since = "2.3.0", + note = "Implement `solana_program_error::ToStr` and `TryFrom` by hand or with `num_enum::TryFromPrimitive` instead" +)] pub trait DecodeError { fn decode_custom_error_to_enum(custom: u32) -> Option where @@ -32,6 +36,7 @@ pub trait DecodeError { } #[cfg(test)] +#[allow(deprecated)] mod tests { use {super::*, num_derive::FromPrimitive}; diff --git a/define-syscall/Cargo.toml b/define-syscall/Cargo.toml index eaa55cd68..53466082e 100644 --- a/define-syscall/Cargo.toml +++ b/define-syscall/Cargo.toml @@ -2,7 +2,7 @@ name = "solana-define-syscall" description = "Solana define_syscall macro and core syscall definitions." documentation = "https://docs.rs/solana-define-syscall" -version = "2.2.1" +version = "2.3.0" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } diff --git a/define-syscall/src/definitions.rs b/define-syscall/src/definitions.rs index 0f75edb13..e6586ae5c 100644 --- a/define-syscall/src/definitions.rs +++ b/define-syscall/src/definitions.rs @@ -31,6 +31,7 @@ define_syscall!(fn sol_remaining_compute_units() -> u64); define_syscall!(fn sol_alt_bn128_compression(op: u64, input: *const u8, input_size: u64, result: *mut u8) -> u64); define_syscall!(fn sol_get_sysvar(sysvar_id_addr: *const u8, result: *mut u8, offset: u64, length: u64) -> u64); define_syscall!(fn sol_get_epoch_stake(vote_address: *const u8) -> u64); +define_syscall!(fn sol_panic_(filename: *const u8, filename_len: u64, line: u64, column: u64)); // these are to be deprecated once they are superceded by sol_get_sysvar define_syscall!(fn sol_get_clock_sysvar(addr: *mut u8) -> u64); diff --git a/define-syscall/src/lib.rs b/define-syscall/src/lib.rs index 119afea0e..fe4bf4e39 100644 --- a/define-syscall/src/lib.rs +++ b/define-syscall/src/lib.rs @@ -1,3 +1,5 @@ +#![no_std] + pub mod definitions; #[cfg(target_feature = "static-syscalls")] diff --git a/derivation-path/Cargo.toml b/derivation-path/Cargo.toml index 321049f48..21092e4fa 100644 --- a/derivation-path/Cargo.toml +++ b/derivation-path/Cargo.toml @@ -9,6 +9,9 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [dependencies] derivation-path = { workspace = true } qstring = { workspace = true } @@ -16,6 +19,3 @@ uriparse = { workspace = true } [dev-dependencies] assert_matches = { workspace = true } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] diff --git a/ed25519-program/Cargo.toml b/ed25519-program/Cargo.toml index d59deed97..98567f3e8 100644 --- a/ed25519-program/Cargo.toml +++ b/ed25519-program/Cargo.toml @@ -2,13 +2,16 @@ name = "solana-ed25519-program" description = "Instructions for the Solana ed25519 native program" documentation = "https://docs.rs/solana-ed25519-program" -version = "2.2.2" +version = "2.2.3" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [dependencies] bytemuck = { workspace = true } bytemuck_derive = { workspace = true } @@ -27,8 +30,5 @@ solana-logger = { workspace = true } solana-sdk = { path = "../sdk" } solana-signer = { workspace = true } -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - [lints] workspace = true diff --git a/epoch-info/Cargo.toml b/epoch-info/Cargo.toml index 757c2347e..48430f4b6 100644 --- a/epoch-info/Cargo.toml +++ b/epoch-info/Cargo.toml @@ -9,15 +9,15 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } -[dependencies] -serde = { workspace = true, optional = true } -serde_derive = { workspace = true, optional = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] [features] serde = ["dep:serde", "dep:serde_derive"] -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] +[dependencies] +serde = { workspace = true, optional = true } +serde_derive = { workspace = true, optional = true } [lints] workspace = true diff --git a/epoch-rewards-hasher/Cargo.toml b/epoch-rewards-hasher/Cargo.toml index d641044ef..40356c274 100644 --- a/epoch-rewards-hasher/Cargo.toml +++ b/epoch-rewards-hasher/Cargo.toml @@ -9,13 +9,13 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [dependencies] siphasher = { workspace = true } solana-hash = { workspace = true } solana-pubkey = { workspace = true } -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - [lints] workspace = true diff --git a/epoch-rewards/Cargo.toml b/epoch-rewards/Cargo.toml index 256ec18ea..6e9f2f42c 100644 --- a/epoch-rewards/Cargo.toml +++ b/epoch-rewards/Cargo.toml @@ -9,6 +9,22 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "solana-hash/frozen-abi", + "std", +] +serde = ["dep:serde", "dep:serde_derive", "solana-hash/serde"] +std = [] +sysvar = ["dep:solana-sysvar-id"] + [dependencies] serde = { workspace = true, optional = true } serde_derive = { workspace = true, optional = true } @@ -22,16 +38,5 @@ solana-sysvar-id = { workspace = true, optional = true } [dev-dependencies] solana-epoch-rewards = { path = ".", features = ["sysvar"] } -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - -[features] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "solana-hash/frozen-abi", "std"] -serde = ["dep:serde", "dep:serde_derive", "solana-hash/serde"] -std = [] -sysvar = ["dep:solana-sysvar-id"] - [lints] workspace = true diff --git a/epoch-schedule/Cargo.toml b/epoch-schedule/Cargo.toml index 7c8e62a94..ef833bcef 100644 --- a/epoch-schedule/Cargo.toml +++ b/epoch-schedule/Cargo.toml @@ -9,6 +9,14 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[features] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] +serde = ["dep:serde", "dep:serde_derive"] +sysvar = ["dep:solana-sdk-ids", "dep:solana-sysvar-id"] + [dependencies] serde = { workspace = true, optional = true } serde_derive = { workspace = true, optional = true } @@ -18,18 +26,10 @@ solana-sdk-ids = { workspace = true, optional = true } solana-sdk-macro = { workspace = true } solana-sysvar-id = { workspace = true, optional = true } -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - [dev-dependencies] solana-clock = { workspace = true } solana-epoch-schedule = { path = ".", features = ["sysvar"] } static_assertions = { workspace = true } -[features] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] -serde = ["dep:serde", "dep:serde_derive"] -sysvar = ["dep:solana-sdk-ids", "dep:solana-sysvar-id"] - [lints] workspace = true diff --git a/example-mocks/Cargo.toml b/example-mocks/Cargo.toml index 1cf787147..17ae55910 100644 --- a/example-mocks/Cargo.toml +++ b/example-mocks/Cargo.toml @@ -9,6 +9,9 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [dependencies] serde = { workspace = true } serde_derive = { workspace = true } @@ -23,6 +26,3 @@ solana-pubkey = { workspace = true } solana-sdk-ids = { workspace = true } solana-system-interface = { workspace = true } thiserror = { workspace = true } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] diff --git a/feature-gate-interface/Cargo.toml b/feature-gate-interface/Cargo.toml index 2093a142b..9e6684c1c 100644 --- a/feature-gate-interface/Cargo.toml +++ b/feature-gate-interface/Cargo.toml @@ -2,13 +2,30 @@ name = "solana-feature-gate-interface" description = "Solana feature gate program interface." documentation = "https://docs.rs/solana-feature-gate-interface" -version = "2.2.1" +version = "2.2.2" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[features] +bincode = [ + "dep:bincode", + "dep:solana-account", + "dep:solana-account-info", + "dep:solana-instruction", + "dep:solana-program-error", + "dep:solana-rent", + "dep:solana-system-interface", + "serde", +] +dev-context-only-utils = ["bincode"] +serde = ["dep:serde", "dep:serde_derive"] + [dependencies] bincode = { workspace = true, optional = true } serde = { workspace = true, optional = true } @@ -27,22 +44,5 @@ solana-system-interface = { workspace = true, optional = true, features = [ [dev-dependencies] solana-feature-gate-interface = { path = ".", features = ["dev-context-only-utils"] } -[features] -bincode = [ - "dep:bincode", - "dep:solana-account", - "dep:solana-account-info", - "dep:solana-instruction", - "dep:solana-program-error", - "dep:solana-rent", - "dep:solana-system-interface", - "serde" -] -dev-context-only-utils = ["bincode"] -serde = ["dep:serde", "dep:serde_derive"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - [lints] workspace = true diff --git a/feature-gate-interface/src/lib.rs b/feature-gate-interface/src/lib.rs index 51ab13899..e431a90a2 100644 --- a/feature-gate-interface/src/lib.rs +++ b/feature-gate-interface/src/lib.rs @@ -42,6 +42,9 @@ impl Feature { if *account_info.owner != id() { return Err(ProgramError::InvalidAccountOwner); } + if account_info.data_len() < Feature::size_of() { + return Err(ProgramError::InvalidAccountData); + } bincode::deserialize(&account_info.data.borrow()) .map_err(|_| ProgramError::InvalidAccountData) } @@ -72,7 +75,7 @@ pub fn activate_with_lamports( #[cfg(feature = "bincode")] pub fn from_account(account: &T) -> Option { - if account.owner() != &id() { + if account.owner() != &id() || account.data().len() < Feature::size_of() { None } else { bincode::deserialize(account.data()).ok() @@ -125,12 +128,76 @@ mod test { } } + #[test] + fn feature_from_account_info_none() { + let key = Pubkey::new_unique(); + let mut lamports = 42; + + let mut good_data = vec![0; Feature::size_of()]; + let mut small_data = vec![0; Feature::size_of() - 1]; // Too small + + assert_eq!( + Feature::from_account_info(&AccountInfo::new( + &key, + false, + false, + &mut lamports, + &mut good_data, + &id(), + false, + u64::MAX, + )), + Ok(Feature { activated_at: None }) + ); + assert_eq!( + Feature::from_account_info(&AccountInfo::new( + &key, + false, + false, + &mut lamports, + &mut small_data, // Too small + &id(), + false, + u64::MAX, + )), + Err(ProgramError::InvalidAccountData), + ); + assert_eq!( + Feature::from_account_info(&AccountInfo::new( + &key, + false, + false, + &mut lamports, + &mut good_data, + &Pubkey::new_unique(), // Wrong owner + false, + u64::MAX, + )), + Err(ProgramError::InvalidAccountOwner), + ); + } + #[test] fn feature_deserialize_none() { - let just_initialized = AccountSharedData::new(42, Feature::size_of(), &id()); assert_eq!( - from_account(&just_initialized), + from_account(&AccountSharedData::new(42, Feature::size_of(), &id())), Some(Feature { activated_at: None }) ); + assert_eq!( + from_account(&AccountSharedData::new( + 42, + Feature::size_of() - 1, // Too small + &id() + )), + None, + ); + assert_eq!( + from_account(&AccountSharedData::new( + 42, + Feature::size_of(), + &Pubkey::new_unique(), // Wrong owner + )), + None, + ); } } diff --git a/feature-set-interface/Cargo.toml b/feature-set-interface/Cargo.toml index de35f2ad7..c57d888ff 100644 --- a/feature-set-interface/Cargo.toml +++ b/feature-set-interface/Cargo.toml @@ -9,6 +9,12 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[features] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] + [dependencies] ahash = { workspace = true } solana-frozen-abi = { workspace = true, optional = true, features = [ @@ -19,11 +25,5 @@ solana-frozen-abi-macro = { workspace = true, optional = true, features = [ ] } solana-pubkey = { workspace = true } -[features] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - [lints] workspace = true diff --git a/feature-set/Cargo.toml b/feature-set/Cargo.toml index c160b2cb0..a3c33405f 100644 --- a/feature-set/Cargo.toml +++ b/feature-set/Cargo.toml @@ -2,13 +2,19 @@ name = "solana-feature-set" description = "Solana runtime features." documentation = "https://docs.rs/solana-feature-set" -version = "2.2.4" +version = "2.2.5" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[features] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] + [dependencies] ahash = { workspace = true } lazy_static = { workspace = true } @@ -23,11 +29,5 @@ solana-hash = { workspace = true } solana-pubkey = { workspace = true } solana-sha256-hasher = { workspace = true } -[features] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - [lints] workspace = true diff --git a/fee-calculator/Cargo.toml b/fee-calculator/Cargo.toml index a50dae551..b66c4da1d 100644 --- a/fee-calculator/Cargo.toml +++ b/fee-calculator/Cargo.toml @@ -9,6 +9,15 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] +serde = ["dep:serde", "dep:serde_derive"] + [dependencies] log = { workspace = true } serde = { workspace = true, optional = true } @@ -20,12 +29,3 @@ solana-frozen-abi-macro = { workspace = true, optional = true } solana-clock = { workspace = true } solana-logger = { workspace = true } static_assertions = { workspace = true } - -[features] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] -serde = ["dep:serde", "dep:serde_derive"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] diff --git a/fee-structure/Cargo.toml b/fee-structure/Cargo.toml index e14bf3e27..40b943617 100644 --- a/fee-structure/Cargo.toml +++ b/fee-structure/Cargo.toml @@ -2,13 +2,22 @@ name = "solana-fee-structure" description = "Solana fee structures." documentation = "https://docs.rs/solana-fee-structure" -version = "2.2.1" +version = "2.3.0" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +frozen-abi = ["dep:solana-frozen-abi"] +serde = ["dep:serde", "dep:serde_derive"] + [dependencies] serde = { workspace = true, optional = true } serde_derive = { workspace = true, optional = true } @@ -17,17 +26,8 @@ solana-frozen-abi = { workspace = true, optional = true, features = [ ] } solana-native-token = { workspace = true } -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [target.'cfg(not(target_os = "solana"))'.dependencies] solana-message = { workspace = true } -[features] -frozen-abi = ["dep:solana-frozen-abi"] -serde = ["dep:serde", "dep:serde_derive"] - [lints] workspace = true diff --git a/fee-structure/src/lib.rs b/fee-structure/src/lib.rs index 17dae1e53..5f458c14d 100644 --- a/fee-structure/src/lib.rs +++ b/fee-structure/src/lib.rs @@ -4,7 +4,7 @@ #[cfg(not(target_os = "solana"))] use solana_message::SanitizedMessage; -use {solana_native_token::sol_to_lamports, std::num::NonZeroU32}; +use std::num::NonZeroU32; /// A fee and its associated compute unit limit #[derive(Debug, Default, Clone, Eq, PartialEq)] @@ -76,6 +76,11 @@ impl FeeDetails { pub const ACCOUNT_DATA_COST_PAGE_SIZE: u64 = 32_u64.saturating_mul(1024); impl FeeStructure { + #[deprecated( + since = "2.3.0", + note = "Use FeeStructure::default() and modify fields as needed" + )] + #[allow(deprecated)] pub fn new( sol_per_signature: f64, sol_per_write_lock: f64, @@ -85,12 +90,12 @@ impl FeeStructure { .iter() .map(|(limit, sol)| FeeBin { limit: *limit, - fee: sol_to_lamports(*sol), + fee: solana_native_token::sol_to_lamports(*sol), }) .collect::>(); FeeStructure { - lamports_per_signature: sol_to_lamports(sol_per_signature), - lamports_per_write_lock: sol_to_lamports(sol_per_write_lock), + lamports_per_signature: solana_native_token::sol_to_lamports(sol_per_signature), + lamports_per_write_lock: solana_native_token::sol_to_lamports(sol_per_write_lock), compute_fee_bins, } } @@ -201,7 +206,14 @@ impl FeeStructure { impl Default for FeeStructure { fn default() -> Self { - Self::new(0.000005, 0.0, vec![(1_400_000, 0.0)]) + Self { + lamports_per_signature: 5000, + lamports_per_write_lock: 0, + compute_fee_bins: vec![FeeBin { + limit: 1_400_000, + fee: 0, + }], + } } } diff --git a/file-download/Cargo.toml b/file-download/Cargo.toml index 8b82c502c..112200964 100644 --- a/file-download/Cargo.toml +++ b/file-download/Cargo.toml @@ -2,18 +2,18 @@ name = "solana-file-download" description = "Solana File Download Utility" documentation = "https://docs.rs/solana-file-download" -version = "2.2.1" +version = "2.2.2" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [dependencies] console = { workspace = true } indicatif = { workspace = true } log = { workspace = true } reqwest = { workspace = true, features = ["blocking", "brotli", "deflate", "gzip", "rustls-tls", "json"] } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] diff --git a/frozen-abi-macro/Cargo.toml b/frozen-abi-macro/Cargo.toml index accceb719..fcb6ff2db 100644 --- a/frozen-abi-macro/Cargo.toml +++ b/frozen-abi-macro/Cargo.toml @@ -12,16 +12,16 @@ edition = { workspace = true } [lib] proc-macro = true -[dependencies] -proc-macro2 = { workspace = true } -quote = { workspace = true } -syn = { workspace = true, features = ["full", "extra-traits"] } - [features] default = [] # activate the frozen-abi feature when we actually want to do frozen-abi testing, # otherwise leave it off because it requires nightly Rust frozen-abi = [] +[dependencies] +proc-macro2 = { workspace = true } +quote = { workspace = true } +syn = { workspace = true, features = ["full", "extra-traits"] } + [lints] workspace = true diff --git a/frozen-abi/Cargo.toml b/frozen-abi/Cargo.toml index 9261ba51f..d1cbe4c68 100644 --- a/frozen-abi/Cargo.toml +++ b/frozen-abi/Cargo.toml @@ -2,17 +2,25 @@ name = "solana-frozen-abi" description = "Solana Frozen ABI" documentation = "https://docs.rs/solana-frozen-abi" -version = "2.2.2" +version = "2.3.0" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[features] +default = [] +# activate the frozen-abi feature when we actually want to do frozen-abi testing, +# otherwise leave it off because it requires nightly Rust +frozen-abi = [] + [dependencies] +boxcar = { workspace = true } bs58 = { workspace = true, features = ["alloc"] } bv = { workspace = true, features = ["serde"] } bytes = { workspace = true } +dashmap = { workspace = true } log = { workspace = true, features = ["std"] } serde = { workspace = true, features = ["rc"] } serde_derive = { workspace = true } @@ -28,14 +36,8 @@ memmap2 = { workspace = true } [target.'cfg(not(target_os = "solana"))'.dev-dependencies] bitflags = { workspace = true, features = ["serde"] } serde_bytes = { workspace = true } -solana-logger = { workspace = true } serde_with = { workspace = true, features = ["macros"] } - -[features] -default = [] -# activate the frozen-abi feature when we actually want to do frozen-abi testing, -# otherwise leave it off because it requires nightly Rust -frozen-abi = [] +solana-logger = { workspace = true } [lints] workspace = true diff --git a/frozen-abi/src/abi_example.rs b/frozen-abi/src/abi_example.rs index c844b3a11..d3d272692 100644 --- a/frozen-abi/src/abi_example.rs +++ b/frozen-abi/src/abi_example.rs @@ -619,3 +619,28 @@ impl AbiExample for std::sync::OnceLock { Self::from(T::example()) } } + +#[cfg(not(target_os = "solana"))] +impl< + T: std::cmp::Eq + std::hash::Hash + AbiExample, + S: AbiExample, + H: std::hash::BuildHasher + Default + std::clone::Clone, + > AbiExample for dashmap::DashMap +{ + fn example() -> Self { + info!("AbiExample for (DashMap): {}", type_name::()); + let map = dashmap::DashMap::default(); + map.insert(T::example(), S::example()); + map + } +} + +#[cfg(not(target_os = "solana"))] +impl AbiExample for boxcar::Vec { + fn example() -> Self { + info!("AbiExample for (boxcar::Vec): {}", type_name::()); + let vec = boxcar::Vec::new(); + vec.push(T::example()); + vec + } +} diff --git a/genesis-config/Cargo.toml b/genesis-config/Cargo.toml index 0e8819c94..bedf50875 100644 --- a/genesis-config/Cargo.toml +++ b/genesis-config/Cargo.toml @@ -2,13 +2,33 @@ name = "solana-genesis-config" description = "A Solana network's genesis config." documentation = "https://docs.rs/solana-genesis-config" -version = "2.2.1" +version = "2.3.0" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] +serde = [ + "dep:serde", + "dep:serde_derive", + "solana-account/serde", + "solana-clock/serde", + "solana-cluster-type/serde", + "solana-epoch-schedule/serde", + "solana-fee-calculator/serde", + "solana-inflation/serde", + "solana-poh-config/serde", + "solana-rent/serde", +] + [dependencies] bincode = { workspace = true } chrono = { workspace = true, features = ["alloc"] } @@ -26,7 +46,6 @@ solana-hash = { workspace = true } solana-inflation = { workspace = true } solana-keypair = { workspace = true } solana-logger = { workspace = true } -solana-native-token = { workspace = true } solana-poh-config = { workspace = true } solana-pubkey = { workspace = true } solana-rent = { workspace = true } @@ -40,25 +59,5 @@ solana-time-utils = { workspace = true } solana-genesis-config = { path = ".", features = ["serde"] } solana-pubkey = { workspace = true, features = ["rand"] } -[features] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] -serde = [ - "dep:serde", - "dep:serde_derive", - "solana-account/serde", - "solana-clock/serde", - "solana-cluster-type/serde", - "solana-epoch-schedule/serde", - "solana-fee-calculator/serde", - "solana-inflation/serde", - "solana-poh-config/serde", - "solana-rent/serde", -] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/genesis-config/src/lib.rs b/genesis-config/src/lib.rs index a265fe954..4ba1cf46a 100644 --- a/genesis-config/src/lib.rs +++ b/genesis-config/src/lib.rs @@ -15,7 +15,6 @@ use { chrono::{TimeZone, Utc}, memmap2::Mmap, solana_hash::Hash, - solana_native_token::lamports_to_sol, solana_sha256_hasher::hash, solana_shred_version::compute_shred_version, std::{ @@ -236,7 +235,7 @@ impl fmt::Display for GenesisConfig { {:?}\n\ {:?}\n\ {:?}\n\ - Capitalization: {} SOL in {} accounts\n\ + Capitalization: {} lamports in {} accounts\n\ Native instruction processors: {:#?}\n\ Rewards pool: {:#?}\n\ ", @@ -259,15 +258,13 @@ impl fmt::Display for GenesisConfig { self.inflation, self.rent, self.fee_rate_governor, - lamports_to_sol( - self.accounts - .iter() - .map(|(pubkey, account)| { - assert!(account.lamports > 0, "{:?}", (pubkey, account)); - account.lamports - }) - .sum::() - ), + self.accounts + .iter() + .map(|(pubkey, account)| { + assert!(account.lamports > 0, "{:?}", (pubkey, account)); + account.lamports + }) + .sum::(), self.accounts.len(), self.native_instruction_processors, self.rewards_pools, diff --git a/hard-forks/Cargo.toml b/hard-forks/Cargo.toml index 659ebc8fa..5823fd932 100644 --- a/hard-forks/Cargo.toml +++ b/hard-forks/Cargo.toml @@ -9,18 +9,18 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } -[dependencies] -serde = { workspace = true, optional = true } -serde_derive = { workspace = true, optional = true } -solana-frozen-abi = { workspace = true, optional = true, features = ["frozen-abi"] } -solana-frozen-abi-macro = { workspace = true, optional = true, features = ["frozen-abi"] } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] [features] frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] serde = ["dep:serde", "dep:serde_derive"] -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] +[dependencies] +serde = { workspace = true, optional = true } +serde_derive = { workspace = true, optional = true } +solana-frozen-abi = { workspace = true, optional = true, features = ["frozen-abi"] } +solana-frozen-abi-macro = { workspace = true, optional = true, features = ["frozen-abi"] } [lints] workspace = true diff --git a/hash/Cargo.toml b/hash/Cargo.toml index e7bab379f..127764685 100644 --- a/hash/Cargo.toml +++ b/hash/Cargo.toml @@ -2,7 +2,7 @@ name = "solana-hash" description = "Solana wrapper for the 32-byte output of a hashing algorithm." documentation = "https://docs.rs/solana-hash" -version = "2.2.1" +version = "2.3.0" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } @@ -14,6 +14,14 @@ targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] all-features = true rustdoc-args = ["--cfg=docsrs"] +[features] +borsh = ["dep:borsh", "std"] +bytemuck = ["dep:bytemuck", "dep:bytemuck_derive"] +default = ["std"] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "std"] +serde = ["dep:serde", "dep:serde_derive"] +std = [] + [dependencies] borsh = { workspace = true, optional = true } bytemuck = { workspace = true, optional = true } @@ -30,24 +38,12 @@ solana-frozen-abi-macro = { workspace = true, optional = true, features = [ ] } solana-sanitize = { workspace = true } -[dev-dependencies] -bs58 = { workspace = true, default-features = false, features = ["alloc"] } - [target.'cfg(target_arch = "wasm32")'.dependencies] js-sys = { workspace = true } wasm-bindgen = { workspace = true } -[features] -borsh = ["dep:borsh", "std"] -bytemuck = ["dep:bytemuck", "dep:bytemuck_derive"] -default = ["std"] -frozen-abi = [ - "dep:solana-frozen-abi", - "dep:solana-frozen-abi-macro", - "std" -] -serde = ["dep:serde", "dep:serde_derive"] -std = [] +[dev-dependencies] +bs58 = { workspace = true, default-features = false, features = ["alloc"] } [lints] workspace = true diff --git a/inflation/Cargo.toml b/inflation/Cargo.toml index c593d1926..693938bff 100644 --- a/inflation/Cargo.toml +++ b/inflation/Cargo.toml @@ -9,15 +9,15 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } -[dependencies] -serde = { workspace = true, optional = true } -serde_derive = { workspace = true, optional = true } -solana-frozen-abi = { workspace = true, optional = true } -solana-frozen-abi-macro = { workspace = true, optional = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] [features] frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] serde = ["dep:serde", "dep:serde_derive"] -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] +[dependencies] +serde = { workspace = true, optional = true } +serde_derive = { workspace = true, optional = true } +solana-frozen-abi = { workspace = true, optional = true } +solana-frozen-abi-macro = { workspace = true, optional = true } diff --git a/instruction/Cargo.toml b/instruction/Cargo.toml index dcf12d638..199f03fed 100644 --- a/instruction/Cargo.toml +++ b/instruction/Cargo.toml @@ -2,13 +2,32 @@ name = "solana-instruction" description = "Types for directing the execution of Solana programs." documentation = "https://docs.rs/solana-instruction" -version = "2.2.1" +version = "2.3.0" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +bincode = ["dep:bincode", "dep:serde"] +borsh = ["dep:borsh"] +default = ["std"] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "serde", + "std", +] +serde = ["dep:serde", "dep:serde_derive", "solana-pubkey/serde"] +std = [] +syscalls = ["std"] + [dependencies] bincode = { workspace = true, optional = true } borsh = { workspace = true, optional = true } @@ -19,38 +38,16 @@ solana-frozen-abi = { workspace = true, optional = true } solana-frozen-abi-macro = { workspace = true, optional = true } solana-pubkey = { workspace = true, default-features = false } -[target.'cfg(target_os = "solana")'.dependencies] -solana-define-syscall = { workspace = true } - [target.'cfg(target_arch = "wasm32")'.dependencies] getrandom = { workspace = true, features = ["js", "wasm-bindgen"] } js-sys = { workspace = true } wasm-bindgen = { workspace = true } +[target.'cfg(target_os = "solana")'.dependencies] +solana-define-syscall = { workspace = true } + [dev-dependencies] solana-instruction = { path = ".", features = ["borsh"] } -[features] -bincode = ["dep:bincode", "dep:serde"] -borsh = ["dep:borsh"] -default = ["std"] -frozen-abi = [ - "dep:solana-frozen-abi", - "dep:solana-frozen-abi-macro", - "serde", - "std", -] -serde = [ - "dep:serde", - "dep:serde_derive", - "solana-pubkey/serde", -] -std = [] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/instruction/src/lib.rs b/instruction/src/lib.rs index 673d379c7..899cf9d2a 100644 --- a/instruction/src/lib.rs +++ b/instruction/src/lib.rs @@ -24,7 +24,7 @@ pub mod account_meta; #[cfg(feature = "std")] pub use account_meta::AccountMeta; pub mod error; -#[cfg(target_os = "solana")] +#[cfg(any(feature = "syscalls", target_os = "solana"))] pub mod syscalls; #[cfg(all(feature = "std", target_arch = "wasm32"))] pub mod wasm; diff --git a/instruction/src/syscalls.rs b/instruction/src/syscalls.rs index f811f00d8..2fd3bc0d5 100644 --- a/instruction/src/syscalls.rs +++ b/instruction/src/syscalls.rs @@ -1,8 +1,85 @@ -pub use solana_define_syscall::definitions::sol_get_stack_height; -use { +#[cfg(feature = "syscalls")] +use crate::Instruction; +#[cfg(target_os = "solana")] +pub use { crate::{AccountMeta, ProcessedSiblingInstruction}, - solana_define_syscall::define_syscall, + solana_define_syscall::{define_syscall, definitions::sol_get_stack_height}, solana_pubkey::Pubkey, }; +#[cfg(target_os = "solana")] define_syscall!(fn sol_get_processed_sibling_instruction(index: u64, meta: *mut ProcessedSiblingInstruction, program_id: *mut Pubkey, data: *mut u8, accounts: *mut AccountMeta) -> u64); + +/// Returns a sibling instruction from the processed sibling instruction list. +/// +/// The processed sibling instruction list is a reverse-ordered list of +/// successfully processed sibling instructions. For example, given the call flow: +/// +/// A +/// B -> C -> D +/// B -> E +/// B -> F +/// +/// Then B's processed sibling instruction list is: `[A]` +/// Then F's processed sibling instruction list is: `[E, C]` +#[cfg(feature = "syscalls")] +pub fn get_processed_sibling_instruction(index: usize) -> Option { + #[cfg(target_os = "solana")] + { + let mut meta = ProcessedSiblingInstruction::default(); + let mut program_id = solana_pubkey::Pubkey::default(); + + if 1 == unsafe { + sol_get_processed_sibling_instruction( + index as u64, + &mut meta, + &mut program_id, + &mut u8::default(), + &mut AccountMeta::default(), + ) + } { + let mut data = std::vec::Vec::new(); + let mut accounts = std::vec::Vec::new(); + data.resize_with(meta.data_len as usize, u8::default); + accounts.resize_with(meta.accounts_len as usize, AccountMeta::default); + + let _ = unsafe { + sol_get_processed_sibling_instruction( + index as u64, + &mut meta, + &mut program_id, + data.as_mut_ptr(), + accounts.as_mut_ptr(), + ) + }; + + Some(Instruction::new_with_bytes(program_id, &data, accounts)) + } else { + None + } + } + + #[cfg(not(target_os = "solana"))] + { + core::hint::black_box(index); + // Same value used in `solana_sysvar::program_stubs`. + None + } +} + +/// Get the current stack height. +/// +/// Transaction-level instructions are height [`TRANSACTION_LEVEL_STACK_HEIGHT`]`, +/// fist invoked inner instruction is height `TRANSACTION_LEVEL_STACK_HEIGHT + 1`, +/// and so forth. +#[cfg(feature = "syscalls")] +pub fn get_stack_height() -> usize { + #[cfg(target_os = "solana")] + unsafe { + sol_get_stack_height() as usize + } + + #[cfg(not(target_os = "solana"))] + // Same value used in `solana_sysvar::program_stubs`. + 0 +} diff --git a/instructions-sysvar/Cargo.toml b/instructions-sysvar/Cargo.toml index a12bfea34..4516436d5 100644 --- a/instructions-sysvar/Cargo.toml +++ b/instructions-sysvar/Cargo.toml @@ -2,13 +2,21 @@ name = "solana-instructions-sysvar" description = "Type for instruction introspection during execution of Solana programs." documentation = "https://docs.rs/solana-instructions-sysvar" -version = "2.2.1" +version = "2.2.2" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +dev-context-only-utils = ["dep:qualifier_attr"] + [dependencies] qualifier_attr = { workspace = true, optional = true } solana-account-info = { workspace = true } @@ -23,13 +31,5 @@ solana-sysvar-id = { workspace = true } [target.'cfg(not(target_os = "solana"))'.dependencies] bitflags = { workspace = true } -[features] -dev-context-only-utils = ["dep:qualifier_attr"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/instructions-sysvar/src/lib.rs b/instructions-sysvar/src/lib.rs index 1525245a4..17e6c877d 100644 --- a/instructions-sysvar/src/lib.rs +++ b/instructions-sysvar/src/lib.rs @@ -41,7 +41,7 @@ use { }; use { solana_account_info::AccountInfo, - solana_instruction::{AccountMeta, Instruction}, + solana_instruction::{error::InstructionError, AccountMeta, Instruction}, solana_program_error::ProgramError, solana_sanitize::SanitizeError, solana_serialize_utils::{read_pubkey, read_slice, read_u16, read_u8}, @@ -161,11 +161,25 @@ pub fn load_current_index_checked( } /// Store the current `Instruction`'s index in the instructions sysvar data. +#[deprecated(since = "2.2.1", note = "Use store_current_index_checked instead")] pub fn store_current_index(data: &mut [u8], instruction_index: u16) { let last_index = data.len() - 2; data[last_index..last_index + 2].copy_from_slice(&instruction_index.to_le_bytes()); } +/// Store the current `Instruction`'s index in the instructions sysvar data. +pub fn store_current_index_checked( + data: &mut [u8], + instruction_index: u16, +) -> Result<(), InstructionError> { + if data.len() < 2 { + return Err(InstructionError::AccountDataTooSmall); + } + let last_index = data.len() - 2; + data[last_index..last_index + 2].copy_from_slice(&instruction_index.to_le_bytes()); + Ok(()) +} + #[cfg_attr(feature = "dev-context-only-utils", qualifiers(pub))] fn deserialize_instruction(index: usize, data: &[u8]) -> Result { const IS_SIGNER_BIT: usize = 0; @@ -289,13 +303,21 @@ mod tests { #[test] fn test_load_store_instruction() { let mut data = [4u8; 10]; - store_current_index(&mut data, 3); + let res = store_current_index_checked(&mut data, 3); + assert!(res.is_ok()); #[allow(deprecated)] let index = load_current_index(&data); assert_eq!(index, 3); assert_eq!([4u8; 8], data[0..8]); } + #[test] + fn test_store_instruction_too_small_data() { + let mut data = [4u8; 1]; + let res = store_current_index_checked(&mut data, 3); + assert!(res.is_err()); + } + #[derive(Copy, Clone)] struct MakeInstructionParams { program_id: Pubkey, @@ -422,7 +444,8 @@ mod tests { let key = id(); let mut lamports = 0; let mut data = construct_instructions_data(&[borrowed_instruction0, borrowed_instruction1]); - store_current_index(&mut data, 1); + let res = store_current_index_checked(&mut data, 1); + assert!(res.is_ok()); let owner = solana_sdk_ids::sysvar::id(); let mut account_info = AccountInfo::new( &key, @@ -438,7 +461,8 @@ mod tests { assert_eq!(1, load_current_index_checked(&account_info).unwrap()); { let mut data = account_info.try_borrow_mut_data().unwrap(); - store_current_index(&mut data, 0); + let res = store_current_index_checked(&mut data, 0); + assert!(res.is_ok()); } assert_eq!(0, load_current_index_checked(&account_info).unwrap()); @@ -490,7 +514,8 @@ mod tests { borrowed_instruction1, borrowed_instruction2, ]); - store_current_index(&mut data, 1); + let res = store_current_index_checked(&mut data, 1); + assert!(res.is_ok()); let owner = solana_sdk_ids::sysvar::id(); let mut account_info = AccountInfo::new( &key, @@ -525,7 +550,8 @@ mod tests { ); { let mut data = account_info.try_borrow_mut_data().unwrap(); - store_current_index(&mut data, 0); + let res = store_current_index_checked(&mut data, 0); + assert!(res.is_ok()); } assert_eq!( Err(ProgramError::InvalidArgument), diff --git a/keccak-hasher/Cargo.toml b/keccak-hasher/Cargo.toml index 8f66863fb..01faff511 100644 --- a/keccak-hasher/Cargo.toml +++ b/keccak-hasher/Cargo.toml @@ -14,6 +14,13 @@ targets = ["x86_64-unknown-linux-gnu"] all-features = true rustdoc-args = ["--cfg=docsrs"] +[features] +borsh = ["dep:borsh", "std"] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "std"] +serde = ["dep:serde", "dep:serde_derive"] +sha3 = ["dep:sha3"] +std = ["solana-hash/std"] + [dependencies] borsh = { workspace = true, optional = true } serde = { workspace = true, optional = true } @@ -37,12 +44,5 @@ sha3 = { workspace = true } sha3 = { workspace = true, optional = true } solana-define-syscall = { workspace = true } -[features] -borsh = ["dep:borsh", "std"] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "std"] -serde = ["dep:serde", "dep:serde_derive"] -sha3 = ["dep:sha3"] -std = ["solana-hash/std"] - [lints] workspace = true diff --git a/keypair/Cargo.toml b/keypair/Cargo.toml index 80eb596af..d70683b3f 100644 --- a/keypair/Cargo.toml +++ b/keypair/Cargo.toml @@ -2,13 +2,25 @@ name = "solana-keypair" description = "Concrete implementation of a Solana `Signer`." documentation = "https://docs.rs/solana-keypair" -version = "2.2.1" +version = "2.2.3" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +seed-derivable = [ + "dep:solana-derivation-path", + "dep:solana-seed-derivable", + "dep:ed25519-dalek-bip32", +] + [dependencies] ed25519-dalek = { workspace = true } ed25519-dalek-bip32 = { workspace = true, optional = true } @@ -28,11 +40,3 @@ wasm-bindgen = { workspace = true } serde_json = { workspace = true } static_assertions = { workspace = true } tiny-bip39 = { workspace = true } - -[features] -seed-derivable = ["dep:solana-derivation-path", "dep:solana-seed-derivable", "dep:ed25519-dalek-bip32"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] diff --git a/keypair/src/lib.rs b/keypair/src/lib.rs index 11c2fdd03..3ce31bec2 100644 --- a/keypair/src/lib.rs +++ b/keypair/src/lib.rs @@ -32,6 +32,10 @@ impl Keypair { pub const SECRET_KEY_LENGTH: usize = 32; /// Constructs a new, random `Keypair` using a caller-provided RNG + #[deprecated( + since = "2.2.2", + note = "Use `Keypair::new()` instead or generate 32 random bytes and use `Keypair::new_from_array`" + )] pub fn generate(csprng: &mut R) -> Self where R: CryptoRng + RngCore, @@ -42,7 +46,15 @@ impl Keypair { /// Constructs a new, random `Keypair` using `OsRng` pub fn new() -> Self { let mut rng = OsRng; - Self::generate(&mut rng) + Self(ed25519_dalek::Keypair::generate(&mut rng)) + } + + /// Constructs a new `Keypair` using secret key bytes + pub fn new_from_array(secret_key: [u8; 32]) -> Self { + // unwrap is safe because the only error condition is an incorrect length + let secret = ed25519_dalek::SecretKey::from_bytes(&secret_key).unwrap(); + let public = ed25519_dalek::PublicKey::from(&secret); + Self(ed25519_dalek::Keypair { secret, public }) } /// Recovers a `Keypair` from a byte array diff --git a/loader-v2-interface/Cargo.toml b/loader-v2-interface/Cargo.toml index 682089f3e..95a49b0bd 100644 --- a/loader-v2-interface/Cargo.toml +++ b/loader-v2-interface/Cargo.toml @@ -9,6 +9,15 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +bincode = ["dep:solana-instruction", "serde"] +serde = ["dep:serde", "dep:serde_bytes", "dep:serde_derive"] + [dependencies] serde = { workspace = true, optional = true } serde_bytes = { workspace = true, optional = true } @@ -17,14 +26,5 @@ solana-instruction = { workspace = true, features = ["bincode", "std"], optional solana-pubkey = { workspace = true } solana-sdk-ids = { workspace = true } -[features] -bincode = ["dep:solana-instruction", "serde"] -serde = ["dep:serde", "dep:serde_bytes", "dep:serde_derive"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/loader-v3-interface/Cargo.toml b/loader-v3-interface/Cargo.toml index bfc052f4f..a54352e29 100644 --- a/loader-v3-interface/Cargo.toml +++ b/loader-v3-interface/Cargo.toml @@ -2,13 +2,24 @@ name = "solana-loader-v3-interface" description = "Solana loader V3 interface." documentation = "https://docs.rs/solana-loader-v3-interface" -version = "3.0.0" +version = "5.0.0" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +bincode = ["dep:solana-system-interface", "serde", "solana-instruction/bincode"] +dev-context-only-utils = ["bincode"] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "serde"] +serde = ["dep:serde", "dep:serde_bytes", "dep:serde_derive", "solana-pubkey/serde"] + [dependencies] serde = { workspace = true, optional = true } serde_bytes = { workspace = true, optional = true } @@ -28,16 +39,5 @@ solana-system-interface = { workspace = true, features = ["bincode"], optional = bincode = { workspace = true } solana-loader-v3-interface = { path = ".", features = ["dev-context-only-utils"] } -[features] -bincode = ["dep:solana-system-interface", "serde", "solana-instruction/bincode"] -dev-context-only-utils = ["bincode"] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "serde"] -serde = ["dep:serde", "dep:serde_bytes", "dep:serde_derive", "solana-pubkey/serde"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/loader-v3-interface/src/instruction.rs b/loader-v3-interface/src/instruction.rs index 93336f373..d0de845f9 100644 --- a/loader-v3-interface/src/instruction.rs +++ b/loader-v3-interface/src/instruction.rs @@ -140,7 +140,7 @@ pub enum UpgradeableLoaderInstruction { Close, /// Extend a program's ProgramData account by the specified number of bytes. - /// Only upgradeable program's can be extended. + /// Only upgradeable programs can be extended. /// /// The payer account must contain sufficient lamports to fund the /// ProgramData account to be rent-exempt. If the ProgramData account @@ -179,6 +179,25 @@ pub enum UpgradeableLoaderInstruction { /// 1. `[writable]` The Program account. /// 2. `[signer]` The current authority. Migrate, + + /// Extend a program's ProgramData account by the specified number of bytes. + /// Only upgradeable programs can be extended. + /// + /// This instruction differs from ExtendProgram in that the authority is a + /// required signer. + /// + /// # Account references + /// 0. `[writable]` The ProgramData account. + /// 1. `[writable]` The ProgramData account's associated Program account. + /// 2. `[signer]` The authority. + /// 3. `[]` System program (`solana_sdk::system_program::id()`), optional, used to transfer + /// lamports from the payer to the ProgramData account. + /// 4. `[signer]` The payer account, optional, that will pay necessary rent exemption costs + /// for the increased storage size. + ExtendProgramChecked { + /// Number of bytes to extend the program data. + additional_bytes: u32, + }, } #[cfg(feature = "bincode")] @@ -311,6 +330,10 @@ pub fn is_migrate_instruction(instruction_data: &[u8]) -> bool { !instruction_data.is_empty() && 8 == instruction_data[0] } +pub fn is_extend_program_checked_instruction(instruction_data: &[u8]) -> bool { + !instruction_data.is_empty() && 9 == instruction_data[0] +} + #[cfg(feature = "bincode")] /// Returns the instructions required to set a buffers's authority. pub fn set_buffer_authority( @@ -469,6 +492,35 @@ pub fn migrate_program( Instruction::new_with_bincode(id(), &UpgradeableLoaderInstruction::Migrate, accounts) } +/// Returns the instruction required to extend the size of a program's +/// executable data account +#[cfg(feature = "bincode")] +pub fn extend_program_checked( + program_address: &Pubkey, + authority_address: &Pubkey, + payer_address: Option<&Pubkey>, + additional_bytes: u32, +) -> Instruction { + let program_data_address = get_program_data_address(program_address); + let mut metas = vec![ + AccountMeta::new(program_data_address, false), + AccountMeta::new(*program_address, false), + AccountMeta::new(*authority_address, true), + ]; + if let Some(payer_address) = payer_address { + metas.push(AccountMeta::new_readonly( + solana_sdk_ids::system_program::id(), + false, + )); + metas.push(AccountMeta::new(*payer_address, true)); + } + Instruction::new_with_bincode( + id(), + &UpgradeableLoaderInstruction::ExtendProgramChecked { additional_bytes }, + metas, + ) +} + #[cfg(test)] mod tests { use super::*; @@ -571,4 +623,15 @@ mod tests { UpgradeableLoaderInstruction::Migrate {}, ); } + + #[test] + fn test_is_extend_program_checked_instruction() { + assert!(!is_extend_program_checked_instruction(&[])); + assert_is_instruction( + is_extend_program_checked_instruction, + UpgradeableLoaderInstruction::ExtendProgramChecked { + additional_bytes: 0, + }, + ); + } } diff --git a/loader-v4-interface/Cargo.toml b/loader-v4-interface/Cargo.toml index 0a97f7ec6..98166dcfd 100644 --- a/loader-v4-interface/Cargo.toml +++ b/loader-v4-interface/Cargo.toml @@ -9,6 +9,17 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +bincode = ["dep:solana-system-interface", "serde", "solana-instruction/bincode"] +dev-context-only-utils = ["bincode"] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "serde"] +serde = ["dep:serde", "dep:serde_bytes", "dep:serde_derive", "solana-pubkey/serde"] + [dependencies] serde = { workspace = true, optional = true } serde_bytes = { workspace = true, optional = true } @@ -28,16 +39,5 @@ solana-system-interface = { workspace = true, features = ["bincode"], optional = memoffset = { workspace = true } solana-loader-v4-interface = { path = ".", features = ["dev-context-only-utils"] } -[features] -bincode = ["dep:solana-system-interface", "serde", "solana-instruction/bincode"] -dev-context-only-utils = ["bincode"] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "serde"] -serde = ["dep:serde", "dep:serde_bytes", "dep:serde_derive", "solana-pubkey/serde"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/logger/Cargo.toml b/logger/Cargo.toml index adb1b614a..914e18265 100644 --- a/logger/Cargo.toml +++ b/logger/Cargo.toml @@ -9,6 +9,12 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[lib] +name = "solana_logger" + [dependencies] env_logger = { workspace = true } lazy_static = { workspace = true } @@ -17,9 +23,3 @@ log = { workspace = true } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] libc = { workspace = true } signal-hook = { workspace = true } - -[lib] -name = "solana_logger" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] diff --git a/message/Cargo.toml b/message/Cargo.toml index de60556dc..1670abd22 100644 --- a/message/Cargo.toml +++ b/message/Cargo.toml @@ -2,13 +2,43 @@ name = "solana-message" description = "Solana transaction message types." documentation = "https://docs.rs/solana-message" -version = "2.3.0" +version = "2.4.0" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +bincode = [ + "dep:bincode", + "dep:solana-bincode", + "dep:solana-system-interface", + "serde", +] +blake3 = ["dep:blake3"] +dev-context-only-utils = ["bincode", "blake3"] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "dep:solana-logger", + "solana-hash/frozen-abi", + "solana-pubkey/frozen-abi", + "serde", +] +serde = [ + "dep:serde", + "dep:serde_derive", + "dep:solana-short-vec", + "solana-hash/serde", + "solana-pubkey/serde", +] + [dependencies] bincode = { workspace = true, optional = true } blake3 = { workspace = true, features = ["traits-preview"], optional = true } @@ -46,35 +76,5 @@ solana-sha256-hasher = { workspace = true } solana-sysvar = { workspace = true } static_assertions = { workspace = true } -[features] -bincode = [ - "dep:bincode", - "dep:solana-bincode", - "dep:solana-system-interface", - "serde", -] -blake3 = ["dep:blake3"] -dev-context-only-utils = ["bincode", "blake3"] -frozen-abi = [ - "dep:solana-frozen-abi", - "dep:solana-frozen-abi-macro", - "dep:solana-logger", - "solana-hash/frozen-abi", - "solana-pubkey/frozen-abi", - "serde", -] -serde = [ - "dep:serde", - "dep:serde_derive", - "dep:solana-short-vec", - "solana-hash/serde", - "solana-pubkey/serde", -] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/message/src/legacy.rs b/message/src/legacy.rs index 1c467e9b7..3b2f7def3 100644 --- a/message/src/legacy.rs +++ b/message/src/legacy.rs @@ -646,11 +646,13 @@ impl Message { /// Returns true if the account at the specified index was requested to be /// writable. This method should not be used directly. pub(super) fn is_writable_index(&self, i: usize) -> bool { - i < (self.header.num_required_signatures - self.header.num_readonly_signed_accounts) - as usize + i < (self.header.num_required_signatures as usize) + .saturating_sub(self.header.num_readonly_signed_accounts as usize) || (i >= self.header.num_required_signatures as usize - && i < self.account_keys.len() - - self.header.num_readonly_unsigned_accounts as usize) + && i < self + .account_keys + .len() + .saturating_sub(self.header.num_readonly_unsigned_accounts as usize)) } /// Returns true if the account at the specified index is writable by the @@ -1023,4 +1025,81 @@ mod tests { fn test_inline_all_ids() { assert_eq!(solana_sysvar::ALL_IDS.to_vec(), ALL_IDS.to_vec()); } + + #[test] + fn test_is_writable_index_saturating_behavior() { + // Directly matching issue #150 PoC 1: + // num_readonly_signed_accounts > num_required_signatures + // This now results in the first part of the OR condition in is_writable_index effectively becoming `i < 0`. + let key0 = Pubkey::new_unique(); + let message1 = Message { + header: MessageHeader { + num_required_signatures: 1, + num_readonly_signed_accounts: 2, // 2 > 1 + num_readonly_unsigned_accounts: 0, + }, + account_keys: vec![key0], + recent_blockhash: Hash::default(), + instructions: vec![], + }; + assert!(!message1.is_writable_index(0)); + + // Matching issue #150 PoC 2 - num_readonly_unsigned_accounts > account_keys.len() + let key_for_poc2 = Pubkey::new_unique(); + let message2 = Message { + header: MessageHeader { + num_required_signatures: 0, + num_readonly_signed_accounts: 0, + num_readonly_unsigned_accounts: 2, // 2 > account_keys.len() (1) + }, + account_keys: vec![key_for_poc2], + recent_blockhash: Hash::default(), + instructions: vec![], + }; + assert!(!message2.is_writable_index(0)); + + // Scenario 3: num_readonly_unsigned_accounts > account_keys.len() with writable signed account + // This should result in the first condition being true for the signed account + let message3 = Message { + header: MessageHeader { + num_required_signatures: 1, // Writable range starts before index 1 + num_readonly_signed_accounts: 0, + num_readonly_unsigned_accounts: 2, // 2 > account_keys.len() (1) + }, + account_keys: vec![key0], + recent_blockhash: Hash::default(), + instructions: vec![], + }; + assert!(message3.is_writable_index(0)); + + // Scenario 4: Both conditions, and testing an index that would rely on the second part of OR + let key1 = Pubkey::new_unique(); + let message4 = Message { + header: MessageHeader { + num_required_signatures: 1, // Writable range starts before index 1 for signed accounts + num_readonly_signed_accounts: 0, + num_readonly_unsigned_accounts: 3, // 3 > account_keys.len() (2) + }, + account_keys: vec![key0, key1], + recent_blockhash: Hash::default(), + instructions: vec![], + }; + assert!(message4.is_writable_index(0)); + assert!(!message4.is_writable_index(1)); + + // Scenario 5: num_required_signatures is 0 due to saturating_sub + // and num_readonly_unsigned_accounts makes the second range empty + let message5 = Message { + header: MessageHeader { + num_required_signatures: 1, + num_readonly_signed_accounts: 2, // 1.saturating_sub(2) = 0 + num_readonly_unsigned_accounts: 3, // account_keys.len().saturating_sub(3) potentially 0 + }, + account_keys: vec![key0, key1], // len is 2 + recent_blockhash: Hash::default(), + instructions: vec![], + }; + assert!(!message5.is_writable_index(0)); + assert!(!message5.is_writable_index(1)); + } } diff --git a/msg/Cargo.toml b/msg/Cargo.toml index eadd984b0..b5c428fcc 100644 --- a/msg/Cargo.toml +++ b/msg/Cargo.toml @@ -9,11 +9,15 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } -[target.'cfg(target_os = "solana")'.dependencies] -solana-define-syscall = { workspace = true } - [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] +[features] +default = ["std"] +std = [] + +[target.'cfg(target_os = "solana")'.dependencies] +solana-define-syscall = { workspace = true } + [lints] workspace = true diff --git a/msg/src/lib.rs b/msg/src/lib.rs index 860a4486b..b686e74a3 100644 --- a/msg/src/lib.rs +++ b/msg/src/lib.rs @@ -1,3 +1,6 @@ +#![no_std] +#[cfg(feature = "std")] +extern crate std; /// Print a message to the log. /// /// Supports simple strings as well as Rust [format strings][fs]. When passed a @@ -25,6 +28,7 @@ /// let err = "not enough signers"; /// msg!("multisig failed: {}", err); /// ``` +#[cfg(feature = "std")] #[macro_export] macro_rules! msg { ($msg:expr) => { @@ -44,6 +48,9 @@ pub fn sol_log(message: &str) { syscalls::sol_log_(message.as_ptr(), message.len() as u64); } - #[cfg(not(target_os = "solana"))] - println!("{message}"); + #[cfg(all(not(target_os = "solana"), feature = "std"))] + std::println!("{message}"); + + #[cfg(all(not(target_os = "solana"), not(feature = "std")))] + core::hint::black_box(message); } diff --git a/native-token/Cargo.toml b/native-token/Cargo.toml index 1e412d5e9..a38bb3951 100644 --- a/native-token/Cargo.toml +++ b/native-token/Cargo.toml @@ -2,7 +2,7 @@ name = "solana-native-token" description = "Definitions for the native SOL token and its fractional lamports." documentation = "https://docs.rs/solana-native-token" -version = "2.2.2" +version = "2.3.0" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } diff --git a/native-token/src/lib.rs b/native-token/src/lib.rs index 98bbac2a8..1763c35b4 100644 --- a/native-token/src/lib.rs +++ b/native-token/src/lib.rs @@ -5,19 +5,47 @@ /// There are 10^9 lamports in one SOL pub const LAMPORTS_PER_SOL: u64 = 1_000_000_000; const LAMPORTS_PER_SOL_F64: f64 = LAMPORTS_PER_SOL as f64; +const SOL_DECIMALS: usize = 9; /// Approximately convert fractional native tokens (lamports) into native tokens (SOL) +#[deprecated( + since = "2.3.0", + note = "solana_cli_output::display::build_balance_message" +)] pub fn lamports_to_sol(lamports: u64) -> f64 { lamports as f64 / LAMPORTS_PER_SOL_F64 } /// Approximately convert native tokens (SOL) into fractional native tokens (lamports) +#[deprecated(since = "2.3.0", note = "sol_str_to_lamports")] pub fn sol_to_lamports(sol: f64) -> u64 { // NaNs return zero, negative values saturate to u64::MIN (i.e. zero), positive values saturate to u64::MAX // https://doc.rust-lang.org/reference/expressions/operator-expr.html#r-expr.as.numeric.float-as-int (sol * LAMPORTS_PER_SOL_F64).round() as u64 } +/// Convert native tokens (SOL) into fractional native tokens (lamports) +pub fn sol_str_to_lamports(sol_str: &str) -> Option { + if sol_str == "." { + None + } else { + let (sol, lamports) = sol_str.split_once('.').unwrap_or((sol_str, "")); + let sol = if sol.is_empty() { + 0 + } else { + sol.parse::().ok()? + }; + let lamports = if lamports.is_empty() { + 0 + } else { + format!("{:0<9}", lamports)[..SOL_DECIMALS].parse().ok()? + }; + LAMPORTS_PER_SOL + .checked_mul(sol) + .and_then(|x| x.checked_add(lamports)) + } +} + use std::fmt::{Debug, Display, Formatter, Result}; pub struct Sol(pub u64); @@ -50,6 +78,7 @@ mod tests { #[test] #[allow(clippy::excessive_precision)] + #[allow(deprecated)] fn test_lamports_to_sol() { assert_eq!(0.0, lamports_to_sol(0)); assert_eq!(0.000000001, lamports_to_sol(1)); @@ -86,6 +115,7 @@ mod tests { #[test] #[allow(clippy::excessive_precision)] + #[allow(deprecated)] fn test_sol_to_lamports() { assert_eq!(0, sol_to_lamports(0.0)); assert_eq!(1, sol_to_lamports(0.000000001)); @@ -115,4 +145,33 @@ mod tests { sol_to_lamports(18446744073.70954513549804687500) ); } + + #[test] + fn test_sol_str_to_lamports() { + assert_eq!(0, sol_str_to_lamports("0.0").unwrap()); + assert_eq!(1, sol_str_to_lamports("0.000000001").unwrap()); + assert_eq!(10, sol_str_to_lamports("0.00000001").unwrap()); + assert_eq!(100, sol_str_to_lamports("0.0000001").unwrap()); + assert_eq!(1000, sol_str_to_lamports("0.000001").unwrap()); + assert_eq!(10000, sol_str_to_lamports("0.00001").unwrap()); + assert_eq!(100000, sol_str_to_lamports("0.0001").unwrap()); + assert_eq!(1000000, sol_str_to_lamports("0.001").unwrap()); + assert_eq!(10000000, sol_str_to_lamports("0.01").unwrap()); + assert_eq!(100000000, sol_str_to_lamports("0.1").unwrap()); + assert_eq!(1000000000, sol_str_to_lamports("1").unwrap()); + assert_eq!(4_100_000_000, sol_str_to_lamports("4.1").unwrap()); + assert_eq!(8_200_000_000, sol_str_to_lamports("8.2").unwrap()); + assert_eq!(8_502_282_880, sol_str_to_lamports("8.50228288").unwrap()); + + assert_eq!( + u64::MAX, + sol_str_to_lamports("18446744073.709551615").unwrap() + ); + // bigger than u64::MAX, error + assert_eq!(None, sol_str_to_lamports("18446744073.709551616")); + // Negative, error + assert_eq!(None, sol_str_to_lamports("-0.000000001")); + // i64::MIN as string, error + assert_eq!(None, sol_str_to_lamports("-9223372036.854775808")); + } } diff --git a/nonce/Cargo.toml b/nonce/Cargo.toml index 5943a3f25..8b053d170 100644 --- a/nonce/Cargo.toml +++ b/nonce/Cargo.toml @@ -9,17 +9,10 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } -[dependencies] -serde = { workspace = true, optional = true } -serde_derive = { workspace = true, optional = true } -solana-fee-calculator = { workspace = true } -solana-hash = { workspace = true, default-features = false } -solana-pubkey = { workspace = true, default-features = false } -solana-sha256-hasher = { workspace = true } - -[dev-dependencies] -bincode = { workspace = true } -solana-nonce = { path = ".", features = ["dev-context-only-utils"] } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] [features] dev-context-only-utils = ["serde"] @@ -31,7 +24,14 @@ serde = [ "solana-pubkey/serde", ] -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] +[dependencies] +serde = { workspace = true, optional = true } +serde_derive = { workspace = true, optional = true } +solana-fee-calculator = { workspace = true } +solana-hash = { workspace = true, default-features = false } +solana-pubkey = { workspace = true, default-features = false } +solana-sha256-hasher = { workspace = true } + +[dev-dependencies] +bincode = { workspace = true } +solana-nonce = { path = ".", features = ["dev-context-only-utils"] } diff --git a/offchain-message/Cargo.toml b/offchain-message/Cargo.toml index fcf2ddf3e..0933cc009 100644 --- a/offchain-message/Cargo.toml +++ b/offchain-message/Cargo.toml @@ -9,6 +9,15 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +dev-context-only-utils = ["verify"] +verify = ["dep:solana-pubkey", "solana-signature/verify"] + [dependencies] num_enum = { workspace = true } solana-hash = { workspace = true } @@ -23,12 +32,3 @@ solana-signer = { workspace = true } solana-keypair = { workspace = true } solana-offchain-message = { path = ".", features = ["dev-context-only-utils"] } static_assertions = { workspace = true } - -[features] -dev-context-only-utils = ["verify"] -verify = ["dep:solana-pubkey", "solana-signature/verify"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] diff --git a/package-metadata-macro/Cargo.toml b/package-metadata-macro/Cargo.toml index a26f44970..ba756b4b9 100644 --- a/package-metadata-macro/Cargo.toml +++ b/package-metadata-macro/Cargo.toml @@ -9,6 +9,9 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [lib] proc-macro = true @@ -17,6 +20,3 @@ proc-macro2 = { workspace = true } quote = { workspace = true } syn = { workspace = true, features = ["full"] } toml = { workspace = true } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] diff --git a/package-metadata/Cargo.toml b/package-metadata/Cargo.toml index 3a55b383a..459751a0b 100644 --- a/package-metadata/Cargo.toml +++ b/package-metadata/Cargo.toml @@ -9,9 +9,9 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [dependencies] solana-package-metadata-macro = { workspace = true } solana-pubkey = { workspace = true } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] diff --git a/packet/Cargo.toml b/packet/Cargo.toml index 2817b9b6e..92b3f5feb 100644 --- a/packet/Cargo.toml +++ b/packet/Cargo.toml @@ -9,6 +9,23 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +bincode = ["dep:bincode", "serde"] +dev-context-only-utils = ["bincode"] +serde = [ + "bitflags/serde", + "dep:cfg_eval", + "dep:serde", + "dep:serde_derive", + "dep:serde_with", +] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] + [dependencies] bincode = { workspace = true, optional = true } bitflags = { workspace = true } @@ -23,22 +40,5 @@ solana-frozen-abi-macro = { workspace = true, optional = true, features = ["froz solana-packet = { path = ".", features = ["dev-context-only-utils"] } static_assertions = { workspace = true } -[features] -bincode = ["dep:bincode", "serde"] -dev-context-only-utils = ["bincode"] -serde = [ - "bitflags/serde", - "dep:cfg_eval", - "dep:serde", - "dep:serde_derive", - "dep:serde_with" -] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/poh-config/Cargo.toml b/poh-config/Cargo.toml index 2d2b63ca6..943a2876d 100644 --- a/poh-config/Cargo.toml +++ b/poh-config/Cargo.toml @@ -14,6 +14,10 @@ targets = ["x86_64-unknown-linux-gnu"] all-features = true rustdoc-args = ["--cfg=docsrs"] +[features] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] +serde = ["dep:serde", "dep:serde_derive"] + [dependencies] serde = { workspace = true, optional = true } serde_derive = { workspace = true, optional = true } @@ -28,12 +32,5 @@ solana-frozen-abi-macro = { workspace = true, optional = true, features = [ solana-clock = { workspace = true } static_assertions = { workspace = true } -[features] -frozen-abi = [ - "dep:solana-frozen-abi", - "dep:solana-frozen-abi-macro", -] -serde = ["dep:serde", "dep:serde_derive"] - [lints] workspace = true diff --git a/precompile-error/Cargo.toml b/precompile-error/Cargo.toml index 931fddb4c..21d5e58dc 100644 --- a/precompile-error/Cargo.toml +++ b/precompile-error/Cargo.toml @@ -2,16 +2,16 @@ name = "solana-precompile-error" description = "Solana PrecompileError type" documentation = "https://docs.rs/solana-precompile-error" -version = "2.2.1" +version = "2.2.2" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [dependencies] num-traits = { workspace = true } solana-decode-error = { workspace = true } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] diff --git a/precompile-error/src/lib.rs b/precompile-error/src/lib.rs index 7bf619586..c315cb405 100644 --- a/precompile-error/src/lib.rs +++ b/precompile-error/src/lib.rs @@ -1,5 +1,5 @@ /// Precompile errors -use {core::fmt, solana_decode_error::DecodeError}; +use core::fmt; /// Precompile errors #[derive(Debug, Clone, PartialEq, Eq)] @@ -69,7 +69,8 @@ impl fmt::Display for PrecompileError { } } -impl DecodeError for PrecompileError { +#[allow(deprecated)] +impl solana_decode_error::DecodeError for PrecompileError { fn type_of() -> &'static str { "PrecompileError" } diff --git a/precompiles/Cargo.toml b/precompiles/Cargo.toml index acd533ae6..1f8153dfe 100644 --- a/precompiles/Cargo.toml +++ b/precompiles/Cargo.toml @@ -2,13 +2,22 @@ name = "solana-precompiles" description = "Solana precompiled programs." documentation = "https://docs.rs/solana-precompiles" -version = "2.2.1" +version = "2.2.2" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +# Enables the "vendored" feature of openssl inside of secp256r1-program +openssl-vendored = ["solana-secp256r1-program/openssl-vendored"] + [dependencies] lazy_static = { workspace = true } solana-ed25519-program = { workspace = true } @@ -20,14 +29,5 @@ solana-sdk-ids = { workspace = true } solana-secp256k1-program = { workspace = true, features = ["bincode"] } solana-secp256r1-program = { workspace = true, default-features = false } -[features] -# Enables the "vendored" feature of openssl inside of secp256r1-program -openssl-vendored = ["solana-secp256r1-program/openssl-vendored"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/presigner/Cargo.toml b/presigner/Cargo.toml index 5f9929b04..89ced3b1d 100644 --- a/presigner/Cargo.toml +++ b/presigner/Cargo.toml @@ -9,6 +9,9 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [dependencies] solana-pubkey = { workspace = true } solana-signature = { workspace = true, features = ["verify"] } @@ -16,6 +19,3 @@ solana-signer = { workspace = true } [dev-dependencies] solana-keypair = { workspace = true } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] diff --git a/program-entrypoint/Cargo.toml b/program-entrypoint/Cargo.toml index 5d5fbc458..90a059a5d 100644 --- a/program-entrypoint/Cargo.toml +++ b/program-entrypoint/Cargo.toml @@ -2,18 +2,21 @@ name = "solana-program-entrypoint" description = "The Solana BPF program entrypoint supported by the latest BPF loader." documentation = "https://docs.rs/solana-program-entrypoint" -version = "2.2.1" +version = "2.3.0" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +rust-version = "1.81.0" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [dependencies] solana-account-info = { workspace = true } +solana-define-syscall = { workspace = true } solana-msg = { workspace = true } solana-program-error = { workspace = true } solana-pubkey = { workspace = true, default-features = false } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] diff --git a/program-entrypoint/src/lib.rs b/program-entrypoint/src/lib.rs index cda6a56cc..ca0fd0e7c 100644 --- a/program-entrypoint/src/lib.rs +++ b/program-entrypoint/src/lib.rs @@ -22,8 +22,12 @@ use { // entrypoint_no_alloc macro pub use { solana_account_info::AccountInfo as __AccountInfo, - solana_account_info::MAX_PERMITTED_DATA_INCREASE, solana_msg::msg as __msg, - solana_program_error::ProgramResult, solana_pubkey::Pubkey as __Pubkey, + solana_account_info::MAX_PERMITTED_DATA_INCREASE, + // Re-exporting for custom_panic + solana_define_syscall::definitions::{sol_log_ as __log, sol_panic_ as __panic}, + solana_msg::msg as __msg, + solana_program_error::ProgramResult, + solana_pubkey::Pubkey as __Pubkey, }; /// User implemented function to process an instruction @@ -223,6 +227,7 @@ macro_rules! custom_heap_default { () => { #[cfg(all(not(feature = "custom-heap"), target_os = "solana"))] #[global_allocator] + #[allow(deprecated)] //we get to use deprecated pub fields static A: $crate::BumpAllocator = $crate::BumpAllocator { start: $crate::HEAP_START_ADDRESS as usize, len: $crate::HEAP_LENGTH, @@ -233,8 +238,8 @@ macro_rules! custom_heap_default { /// Define the default global panic handler. /// /// This must be used if the [`entrypoint`] macro is not used, and no other -/// panic handler has been defined; otherwise compilation will fail with a -/// missing `custom_panic` symbol. +/// panic handler has been defined; otherwise a program will crash without an +/// explicit panic message. /// /// The default global allocator is enabled only if the calling crate has not /// disabled it using [Cargo features] as described below. It is only defined @@ -272,16 +277,28 @@ macro_rules! custom_heap_default { /// $crate::msg!("{}", info); /// } /// ``` -/// -/// The above is how Solana defines the default panic handler. #[macro_export] macro_rules! custom_panic_default { () => { #[cfg(all(not(feature = "custom-panic"), target_os = "solana"))] #[no_mangle] fn custom_panic(info: &core::panic::PanicInfo<'_>) { - // Full panic reporting - $crate::__msg!("{}", info); + if let Some(mm) = info.message().as_str() { + unsafe { + $crate::__log(mm.as_ptr(), mm.len() as u64); + } + } + + if let Some(loc) = info.location() { + unsafe { + $crate::__panic( + loc.file().as_ptr(), + loc.file().len() as u64, + loc.line() as u64, + loc.column() as u64, + ) + } + } } }; } diff --git a/program-error/Cargo.toml b/program-error/Cargo.toml index 88f24a9db..736c496a0 100644 --- a/program-error/Cargo.toml +++ b/program-error/Cargo.toml @@ -2,13 +2,22 @@ name = "solana-program-error" description = "Solana ProgramError type and related definitions." documentation = "https://docs.rs/solana-program-error" -version = "2.2.1" +version = "2.2.2" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +borsh = ["dep:borsh"] +serde = ["dep:serde", "dep:serde_derive"] + [dependencies] borsh = { workspace = true, optional = true } num-traits = { workspace = true } @@ -21,11 +30,5 @@ solana-instruction = { workspace = true, default-features = false, features = [ solana-msg = { workspace = true } solana-pubkey = { workspace = true, default-features = false } -[features] -borsh = ["dep:borsh"] -serde = ["dep:serde", "dep:serde_derive"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] +[dev-dependencies] +num_enum = { workspace = true } diff --git a/program-error/src/lib.rs b/program-error/src/lib.rs index 30b86c6ab..e9680e5ff 100644 --- a/program-error/src/lib.rs +++ b/program-error/src/lib.rs @@ -9,7 +9,6 @@ use serde_derive::{Deserialize, Serialize}; use { core::fmt, num_traits::FromPrimitive, - solana_decode_error::DecodeError, solana_instruction::error::{ InstructionError, ACCOUNT_ALREADY_INITIALIZED, ACCOUNT_BORROW_FAILED, ACCOUNT_DATA_TOO_SMALL, ACCOUNT_NOT_RENT_EXEMPT, ARITHMETIC_OVERFLOW, BORSH_IO_ERROR, @@ -126,17 +125,26 @@ impl fmt::Display for ProgramError { since = "2.2.2", note = "Use `ToStr` instead with `solana_msg::msg!` or any other logging" )] +#[allow(deprecated)] pub trait PrintProgramError { fn print(&self) where - E: 'static + std::error::Error + DecodeError + PrintProgramError + FromPrimitive; + E: 'static + + std::error::Error + + solana_decode_error::DecodeError + + PrintProgramError + + FromPrimitive; } #[allow(deprecated)] impl PrintProgramError for ProgramError { fn print(&self) where - E: 'static + std::error::Error + DecodeError + PrintProgramError + FromPrimitive, + E: 'static + + std::error::Error + + solana_decode_error::DecodeError + + PrintProgramError + + FromPrimitive, { match self { Self::Custom(error) => { @@ -181,22 +189,54 @@ impl PrintProgramError for ProgramError { } } -/// A trait for converting a program error to a `&str`. +/// A trait for converting a program's specific error type to a `&str`. +/// +/// Can be used with `ProgramError::to_str::()` to get an error string +/// belonging to a specific program's error if the variant is +/// `ProgramError::Custom(...)`, or generic strings from the contained +/// `ProgramError` for all other variants. +/// +/// The `ProgramError::to_str::()` function also requires implementing +/// `TryFrom` on an error type, which can be done easily using +/// `num_enum::TryFromPrimitive`. pub trait ToStr { - fn to_str(&self) -> &'static str - where - E: 'static + ToStr + TryFrom; + fn to_str(&self) -> &'static str; } -impl ToStr for ProgramError { - fn to_str(&self) -> &'static str +impl ProgramError { + /// Get an appropriate error string given a program error and an expected + /// error type, if the error implements `TryFrom` and `ToStr`. + /// + /// # Example + /// + /// ``` + /// #[derive(num_enum::TryFromPrimitive)] + /// #[repr(u32)] + /// enum MyError { + /// A, + /// B, + /// } + /// + /// impl solana_program_error::ToStr for MyError { + /// fn to_str(&self) -> &'static str { + /// match self { + /// MyError::A => "Message for A", + /// MyError::B => "Some other message for B", + /// } + /// } + /// } + /// + /// let program_error = solana_program_error::ProgramError::Custom(1); + /// assert_eq!("Some other message for B", program_error.to_str::()); + /// ``` + pub fn to_str(&self) -> &'static str where E: 'static + ToStr + TryFrom, { match self { Self::Custom(error) => { if let Ok(custom_error) = E::try_from(*error) { - custom_error.to_str::() + custom_error.to_str() } else { "Error: Unknown" } diff --git a/program-memory/Cargo.toml b/program-memory/Cargo.toml index a807743b6..3a37e1143 100644 --- a/program-memory/Cargo.toml +++ b/program-memory/Cargo.toml @@ -2,7 +2,7 @@ name = "solana-program-memory" description = "Basic low-level memory operations for Solana." documentation = "https://docs.rs/solana-program-memory" -version = "2.2.1" +version = "2.3.1" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } diff --git a/program-memory/src/lib.rs b/program-memory/src/lib.rs index f4c79eef7..c1f6a39da 100644 --- a/program-memory/src/lib.rs +++ b/program-memory/src/lib.rs @@ -1,8 +1,12 @@ +#![no_std] + //! Basic low-level memory operations. //! //! Within the SBF environment, these are implemented as syscalls and executed by //! the runtime in native code. +use core::mem::MaybeUninit; + #[cfg(target_os = "solana")] pub mod syscalls { pub use solana_define_syscall::definitions::{ @@ -11,6 +15,7 @@ pub mod syscalls { } /// Check that two regions do not overlap. +#[cfg(any(test, not(target_os = "solana")))] fn is_nonoverlapping(src: usize, src_len: usize, dst: usize, dst_len: usize) -> bool { // If the absolute distance between the ptrs is at least as big as the size of the other, // they do not overlap. @@ -32,11 +37,11 @@ pub mod stubs { is_nonoverlapping(src as usize, n, dst as usize, n), "memcpy does not support overlapping regions" ); - std::ptr::copy_nonoverlapping(src, dst, n); + core::ptr::copy_nonoverlapping(src, dst, n); } /// # Safety pub unsafe fn sol_memmove(dst: *mut u8, src: *const u8, n: usize) { - std::ptr::copy(src, dst, n); + core::ptr::copy(src, dst, n); } /// # Safety pub unsafe fn sol_memcmp(s1: *const u8, s2: *const u8, n: usize, result: *mut i32) { @@ -54,7 +59,7 @@ pub mod stubs { } /// # Safety pub unsafe fn sol_memset(s: *mut u8, c: u8, n: usize) { - let s = std::slice::from_raw_parts_mut(s, n); + let s = core::slice::from_raw_parts_mut(s, n); for val in s.iter_mut().take(n) { *val = c; } @@ -81,8 +86,6 @@ pub mod stubs { /// /// # Safety /// -/// __This function is incorrectly missing an `unsafe` declaration.__ -/// /// This function does not verify that `n` is less than or equal to the /// lengths of the `dst` and `src` slices passed to it — it will copy /// bytes to and from beyond the slices. @@ -90,16 +93,12 @@ pub mod stubs { /// Specifying an `n` greater than either the length of `dst` or `src` will /// likely introduce undefined behavior. #[inline] -pub fn sol_memcpy(dst: &mut [u8], src: &[u8], n: usize) { +pub unsafe fn sol_memcpy(dst: &mut [u8], src: &[u8], n: usize) { #[cfg(target_os = "solana")] - unsafe { - syscalls::sol_memcpy_(dst.as_mut_ptr(), src.as_ptr(), n as u64); - } + syscalls::sol_memcpy_(dst.as_mut_ptr(), src.as_ptr(), n as u64); #[cfg(not(target_os = "solana"))] - unsafe { - stubs::sol_memcpy(dst.as_mut_ptr(), src.as_ptr(), n); - } + stubs::sol_memcpy(dst.as_mut_ptr(), src.as_ptr(), n); } /// Like C `memmove`. @@ -120,7 +119,7 @@ pub fn sol_memcpy(dst: &mut [u8], src: &[u8], n: usize) { /// /// The same safety rules apply as in [`ptr::copy`]. /// -/// [`ptr::copy`]: https://doc.rust-lang.org/std/ptr/fn.copy.html +/// [`ptr::copy`]: https://doc.rust-lang.org/core/ptr/fn.copy.html #[inline] pub unsafe fn sol_memmove(dst: *mut u8, src: *const u8, n: usize) { #[cfg(target_os = "solana")] @@ -146,8 +145,6 @@ pub unsafe fn sol_memmove(dst: *mut u8, src: *const u8, n: usize) { /// /// # Safety /// -/// __This function is incorrectly missing an `unsafe` declaration.__ -/// /// It does not verify that `n` is less than or equal to the lengths of the /// `dst` and `src` slices passed to it — it will read bytes beyond the /// slices. @@ -155,20 +152,16 @@ pub unsafe fn sol_memmove(dst: *mut u8, src: *const u8, n: usize) { /// Specifying an `n` greater than either the length of `dst` or `src` will /// likely introduce undefined behavior. #[inline] -pub fn sol_memcmp(s1: &[u8], s2: &[u8], n: usize) -> i32 { - let mut result = 0; +pub unsafe fn sol_memcmp(s1: &[u8], s2: &[u8], n: usize) -> i32 { + let mut result: MaybeUninit = MaybeUninit::uninit(); #[cfg(target_os = "solana")] - unsafe { - syscalls::sol_memcmp_(s1.as_ptr(), s2.as_ptr(), n as u64, &mut result as *mut i32); - } + syscalls::sol_memcmp_(s1.as_ptr(), s2.as_ptr(), n as u64, result.as_mut_ptr()); #[cfg(not(target_os = "solana"))] - unsafe { - stubs::sol_memcmp(s1.as_ptr(), s2.as_ptr(), n, &mut result as *mut i32); - } + stubs::sol_memcmp(s1.as_ptr(), s2.as_ptr(), n, result.as_mut_ptr()); - result + result.assume_init() } /// Like C `memset`. @@ -187,8 +180,6 @@ pub fn sol_memcmp(s1: &[u8], s2: &[u8], n: usize) -> i32 { /// /// # Safety /// -/// __This function is incorrectly missing an `unsafe` declaration.__ -/// /// This function does not verify that `n` is less than or equal to the length /// of the `s` slice passed to it — it will write bytes beyond the /// slice. @@ -196,16 +187,12 @@ pub fn sol_memcmp(s1: &[u8], s2: &[u8], n: usize) -> i32 { /// Specifying an `n` greater than the length of `s` will likely introduce /// undefined behavior. #[inline] -pub fn sol_memset(s: &mut [u8], c: u8, n: usize) { +pub unsafe fn sol_memset(s: &mut [u8], c: u8, n: usize) { #[cfg(target_os = "solana")] - unsafe { - syscalls::sol_memset_(s.as_mut_ptr(), c, n as u64); - } + syscalls::sol_memset_(s.as_mut_ptr(), c, n as u64); #[cfg(not(target_os = "solana"))] - unsafe { - stubs::sol_memset(s.as_mut_ptr(), c, n); - } + stubs::sol_memset(s.as_mut_ptr(), c, n); } #[cfg(test)] diff --git a/program-pack/Cargo.toml b/program-pack/Cargo.toml index 298715799..a0ddf5519 100644 --- a/program-pack/Cargo.toml +++ b/program-pack/Cargo.toml @@ -9,8 +9,8 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } -[dependencies] -solana-program-error = { workspace = true } - [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +solana-program-error = { workspace = true } diff --git a/program/Cargo.toml b/program/Cargo.toml index a8f8e271d..c99dc1bbc 100644 --- a/program/Cargo.toml +++ b/program/Cargo.toml @@ -3,35 +3,65 @@ name = "solana-program" description = "Solana Program" documentation = "https://docs.rs/solana-program" readme = "README.md" -version = "2.2.1" +version = "2.3.0" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } -rust-version = "1.79.0" # solana platform-tools rust version +rust-version = "1.81.0" # solana platform-tools rust version include = ["src/**/*", "README.md"] +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +default = ["borsh"] +borsh = [ + "dep:borsh", + "dep:borsh0-10", + "dep:solana-borsh", + "solana-hash/borsh", + "solana-instruction/borsh", + "solana-program-error/borsh", + "solana-pubkey/borsh", +] +dev-context-only-utils = ["solana-instructions-sysvar/dev-context-only-utils"] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "solana-epoch-rewards/frozen-abi", + "solana-epoch-schedule/frozen-abi", + "solana-fee-calculator/frozen-abi", + "solana-hash/frozen-abi", + "solana-instruction/frozen-abi", + "solana-pubkey/frozen-abi", + "solana-rent/frozen-abi", + "solana-short-vec/frozen-abi", + "solana-sysvar/frozen-abi", +] + [dependencies] bincode = { workspace = true } blake3 = { workspace = true, features = ["traits-preview"] } borsh = { workspace = true, optional = true } borsh0-10 = { workspace = true, optional = true } -bs58 = { workspace = true, features = ["alloc"] } bytemuck = { workspace = true } lazy_static = { workspace = true } log = { workspace = true } memoffset = { workspace = true } -num-derive = { workspace = true } num-traits = { workspace = true, features = ["i128"] } serde = { workspace = true } -serde_bytes = { workspace = true } serde_derive = { workspace = true } solana-account-info = { workspace = true, features = ["bincode"] } solana-address-lookup-table-interface = { workspace = true, features = ["bincode", "bytemuck"] } solana-atomic-u64 = { workspace = true } solana-big-mod-exp = { workspace = true } -solana-bincode = { workspace = true } solana-blake3-hasher = { workspace = true, features = ["blake3"] } solana-borsh = { workspace = true, optional = true } solana-clock = { workspace = true, features = ["serde", "sysvar"] } @@ -39,7 +69,6 @@ solana-cpi = { workspace = true } solana-decode-error = { workspace = true } solana-epoch-rewards = { workspace = true, features = ["serde", "sysvar"] } solana-epoch-schedule = { workspace = true, features = ["serde", "sysvar"] } -solana-feature-gate-interface = { workspace = true, features = ["bincode"] } solana-fee-calculator = { workspace = true, features = ["serde"] } solana-frozen-abi = { workspace = true, optional = true, features = ["frozen-abi"] } solana-frozen-abi-macro = { workspace = true, optional = true, features = ["frozen-abi"] } @@ -52,17 +81,13 @@ solana-instruction = { workspace = true, default-features = false, features = [ "bincode", "serde", "std", + "syscalls", ] } solana-instructions-sysvar = { workspace = true } solana-keccak-hasher = { workspace = true, features = ["sha3"] } solana-last-restart-slot = { workspace = true, features = ["serde", "sysvar"] } -solana-loader-v2-interface = { workspace = true, features = ["bincode"] } -solana-loader-v3-interface = { workspace = true, features = ["bincode"] } -solana-loader-v4-interface = { workspace = true, features = ["bincode"] } -solana-message = { workspace = true, features = ["bincode", "blake3"] } solana-msg = { workspace = true } solana-native-token = { workspace = true } -solana-nonce = { workspace = true, features = ["serde"] } solana-program-entrypoint = { workspace = true } solana-program-error = { workspace = true, features = ["serde"] } solana-program-memory = { workspace = true } @@ -70,7 +95,6 @@ solana-program-option = { workspace = true } solana-program-pack = { workspace = true } solana-pubkey = { workspace = true, features = ["bytemuck", "curve25519", "serde", "std"] } solana-rent = { workspace = true, features = ["serde", "sysvar"] } -solana-sanitize = { workspace = true } solana-sdk-ids = { workspace = true } solana-sdk-macro = { workspace = true } solana-secp256k1-recover = { workspace = true } @@ -81,82 +105,36 @@ solana-short-vec = { workspace = true } solana-slot-hashes = { workspace = true, features = ["serde", "sysvar"] } solana-slot-history = { workspace = true, features = ["serde", "sysvar"] } solana-stable-layout = { workspace = true } -solana-stake-interface = { workspace = true, features = ["bincode"] } -solana-system-interface = { workspace = true, features = ["bincode"] } solana-sysvar = { workspace = true, features = ["bincode", "bytemuck"] } solana-sysvar-id = { workspace = true } -solana-vote-interface = { workspace = true, features = ["bincode"] } thiserror = { workspace = true } -# This is currently needed to build on-chain programs reliably. -# Borsh 0.10 may pull in hashbrown 0.13, which uses ahash 0.8, which uses -# getrandom 0.2 underneath. This explicit dependency allows for no-std if cargo -# upgrades Borsh's dependency to hashbrown 0.13. -# Remove this once borsh 0.11 or 1.0 is released, which correctly declares the -# hashbrown dependency as optional. -[target.'cfg(target_os = "solana")'.dependencies] -getrandom = { workspace = true, features = ["custom"] } -solana-define-syscall = { workspace = true } - [target.'cfg(not(target_os = "solana"))'.dependencies] num-bigint = { workspace = true } -rand = { workspace = true } solana-example-mocks = { workspace = true } -[target.'cfg(not(target_os = "solana"))'.dev-dependencies] -arbitrary = { workspace = true, features = ["derive"] } -solana-logger = { workspace = true } - [target.'cfg(target_arch = "wasm32")'.dependencies] console_error_panic_hook = { workspace = true } console_log = { workspace = true } getrandom = { workspace = true, features = ["js", "wasm-bindgen"] } wasm-bindgen = { workspace = true } +# This is currently needed to build on-chain programs reliably. +# Borsh 0.10 may pull in hashbrown 0.13, which uses ahash 0.8, which uses +# getrandom 0.2 underneath. This explicit dependency allows for no-std if cargo +# upgrades Borsh's dependency to hashbrown 0.13. +# Remove this once borsh 0.11 or 1.0 is released, which correctly declares the +# hashbrown dependency as optional. +[target.'cfg(target_os = "solana")'.dependencies] +getrandom = { workspace = true, features = ["custom"] } +solana-define-syscall = { workspace = true } + [dev-dependencies] -array-bytes = { workspace = true } -assert_matches = { workspace = true } -itertools = { workspace = true } -serde_json = { workspace = true } solana-pubkey = { workspace = true, features = ["dev-context-only-utils"] } solana-sysvar = { workspace = true, features = ["dev-context-only-utils"] } -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - -[lib] -crate-type = ["cdylib", "rlib"] - -[features] -default = ["borsh"] -borsh = [ - "dep:borsh", - "dep:borsh0-10", - "dep:solana-borsh", - "solana-hash/borsh", - "solana-instruction/borsh", - "solana-program-error/borsh", - "solana-pubkey/borsh", - "solana-stake-interface/borsh", -] -dev-context-only-utils = ["solana-instructions-sysvar/dev-context-only-utils"] -frozen-abi = [ - "dep:solana-frozen-abi", - "dep:solana-frozen-abi-macro", - "solana-epoch-rewards/frozen-abi", - "solana-epoch-schedule/frozen-abi", - "solana-fee-calculator/frozen-abi", - "solana-hash/frozen-abi", - "solana-instruction/frozen-abi", - "solana-message/frozen-abi", - "solana-pubkey/frozen-abi", - "solana-rent/frozen-abi", - "solana-short-vec/frozen-abi", - "solana-stake-interface/frozen-abi", - "solana-sysvar/frozen-abi" -] +[target.'cfg(not(target_os = "solana"))'.dev-dependencies] +arbitrary = { workspace = true, features = ["derive"] } [lints] workspace = true diff --git a/program/src/address_lookup_table.rs b/program/src/address_lookup_table.rs deleted file mode 100644 index e216b1460..000000000 --- a/program/src/address_lookup_table.rs +++ /dev/null @@ -1,6 +0,0 @@ -#[deprecated( - since = "2.2.0", - note = "Use solana-address-lookup-table interface instead" -)] -pub use solana_address_lookup_table_interface::{error, instruction, program, state}; -pub use solana_message::AddressLookupTableAccount; diff --git a/program/src/bpf_loader_upgradeable.rs b/program/src/bpf_loader_upgradeable.rs deleted file mode 100644 index eb898f53d..000000000 --- a/program/src/bpf_loader_upgradeable.rs +++ /dev/null @@ -1,13 +0,0 @@ -#[deprecated(since = "2.2.0", note = "Use solana-loader-v3-interface instead")] -#[allow(deprecated)] -pub use solana_loader_v3_interface::{ - get_program_data_address, - instruction::{ - close, close_any, create_buffer, deploy_with_max_program_len, extend_program, - is_close_instruction, is_set_authority_checked_instruction, is_set_authority_instruction, - is_upgrade_instruction, set_buffer_authority, set_buffer_authority_checked, - set_upgrade_authority, set_upgrade_authority_checked, upgrade, write, - }, - state::UpgradeableLoaderState, -}; -pub use solana_sdk_ids::bpf_loader_upgradeable::{check_id, id, ID}; diff --git a/program/src/instruction.rs b/program/src/instruction.rs index 971bbc0e0..38fb5131d 100644 --- a/program/src/instruction.rs +++ b/program/src/instruction.rs @@ -1,9 +1,6 @@ -pub use { - crate::message::compiled_instruction::CompiledInstruction, - solana_instruction::{ - error::InstructionError, AccountMeta, Instruction, ProcessedSiblingInstruction, - TRANSACTION_LEVEL_STACK_HEIGHT, - }, +pub use solana_instruction::{ + error::InstructionError, AccountMeta, Instruction, ProcessedSiblingInstruction, + TRANSACTION_LEVEL_STACK_HEIGHT, }; /// Returns a sibling instruction from the processed sibling instruction list. @@ -21,41 +18,13 @@ pub use { pub fn get_processed_sibling_instruction(index: usize) -> Option { #[cfg(target_os = "solana")] { - let mut meta = ProcessedSiblingInstruction::default(); - let mut program_id = solana_pubkey::Pubkey::default(); - - if 1 == unsafe { - solana_instruction::syscalls::sol_get_processed_sibling_instruction( - index as u64, - &mut meta, - &mut program_id, - &mut u8::default(), - &mut AccountMeta::default(), - ) - } { - let mut data = Vec::new(); - let mut accounts = Vec::new(); - data.resize_with(meta.data_len as usize, u8::default); - accounts.resize_with(meta.accounts_len as usize, AccountMeta::default); - - let _ = unsafe { - solana_instruction::syscalls::sol_get_processed_sibling_instruction( - index as u64, - &mut meta, - &mut program_id, - data.as_mut_ptr(), - accounts.as_mut_ptr(), - ) - }; - - Some(Instruction::new_with_bytes(program_id, &data, accounts)) - } else { - None - } + solana_instruction::syscalls::get_processed_sibling_instruction(index) } #[cfg(not(target_os = "solana"))] - crate::program_stubs::sol_get_processed_sibling_instruction(index) + { + crate::program_stubs::sol_get_processed_sibling_instruction(index) + } } /// Get the current stack height, transaction-level instructions are height @@ -63,8 +32,8 @@ pub fn get_processed_sibling_instruction(index: usize) -> Option { /// TRANSACTION_LEVEL_STACK_HEIGHT + 1, etc... pub fn get_stack_height() -> usize { #[cfg(target_os = "solana")] - unsafe { - solana_instruction::syscalls::sol_get_stack_height() as usize + { + solana_instruction::syscalls::get_stack_height() } #[cfg(not(target_os = "solana"))] diff --git a/program/src/lib.rs b/program/src/lib.rs index 6f5e36beb..c148b4daf 100644 --- a/program/src/lib.rs +++ b/program/src/lib.rs @@ -470,10 +470,8 @@ // Allows macro expansion of `use ::solana_program::*` to work within this crate extern crate self as solana_program; -pub mod address_lookup_table; pub mod bpf_loader; pub mod bpf_loader_deprecated; -pub mod bpf_loader_upgradeable; pub mod compute_units; pub mod ed25519_program; pub mod entrypoint_deprecated; @@ -483,34 +481,13 @@ pub mod hash; pub mod incinerator; pub mod instruction; pub mod lamports; -pub mod loader_upgradeable_instruction { - #[deprecated( - since = "2.2.0", - note = "Use solana_loader_v3_interface::instruction instead" - )] - pub use solana_loader_v3_interface::instruction::UpgradeableLoaderInstruction; -} -pub mod loader_v4; -pub mod loader_v4_instruction { - #[deprecated( - since = "2.2.0", - note = "Use solana_loader_v4_interface::instruction instead" - )] - pub use solana_loader_v4_interface::instruction::LoaderV4Instruction; -} pub mod log; -pub mod nonce; pub mod program; pub mod program_error; -pub mod program_utils; pub mod secp256k1_program; pub mod slot_hashes; pub mod slot_history; -pub mod stake; -pub mod stake_history; pub mod syscalls; -pub mod system_instruction; -pub mod system_program; pub mod sysvar; pub mod wasm; @@ -529,30 +506,16 @@ pub use solana_borsh::v0_10 as borsh0_10; pub use solana_borsh::v1 as borsh1; #[deprecated(since = "2.1.0", note = "Use `solana-epoch-rewards` crate instead")] pub use solana_epoch_rewards as epoch_rewards; -#[deprecated( - since = "2.2.0", - note = "Use `solana-feature-gate-interface` crate instead" -)] -pub use solana_feature_gate_interface as feature; #[deprecated(since = "2.1.0", note = "Use `solana-fee-calculator` crate instead")] pub use solana_fee_calculator as fee_calculator; #[deprecated(since = "2.2.0", note = "Use `solana-keccak-hasher` crate instead")] pub use solana_keccak_hasher as keccak; #[deprecated(since = "2.1.0", note = "Use `solana-last-restart-slot` crate instead")] pub use solana_last_restart_slot as last_restart_slot; -#[deprecated( - since = "2.2.0", - note = "Use `solana-loader-v2-interface` crate instead" -)] -pub use solana_loader_v2_interface as loader_instruction; -#[deprecated(since = "2.2.0", note = "Use `solana-message` crate instead")] -pub use solana_message as message; #[deprecated(since = "2.1.0", note = "Use `solana-program-memory` crate instead")] pub use solana_program_memory as program_memory; #[deprecated(since = "2.1.0", note = "Use `solana-program-pack` crate instead")] pub use solana_program_pack as program_pack; -#[deprecated(since = "2.1.0", note = "Use `solana-sanitize` crate instead")] -pub use solana_sanitize as sanitize; #[deprecated(since = "2.1.0", note = "Use `solana-secp256k1-recover` crate instead")] pub use solana_secp256k1_recover as secp256k1_recover; #[deprecated(since = "2.1.0", note = "Use `solana-serde-varint` crate instead")] @@ -565,8 +528,6 @@ pub use solana_short_vec as short_vec; pub use solana_stable_layout as stable_layout; #[cfg(not(target_os = "solana"))] pub use solana_sysvar::program_stubs; -#[deprecated(since = "2.2.0", note = "Use `solana-vote-interface` crate instead")] -pub use solana_vote_interface as vote; #[cfg(target_arch = "wasm32")] pub use wasm_bindgen::prelude::wasm_bindgen; pub use { @@ -590,50 +551,6 @@ pub mod config { } } -/// A vector of Solana SDK IDs. -#[deprecated( - since = "2.0.0", - note = "Please use `solana_sdk::reserved_account_keys::ReservedAccountKeys` instead" -)] -#[allow(deprecated)] -pub mod sdk_ids { - use { - crate::{ - address_lookup_table, bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, - config, ed25519_program, feature, incinerator, loader_v4, secp256k1_program, - solana_program::pubkey::Pubkey, stake, system_program, sysvar, vote, - }, - lazy_static::lazy_static, - }; - - lazy_static! { - pub static ref SDK_IDS: Vec = { - let mut sdk_ids = vec![ - ed25519_program::id(), - secp256k1_program::id(), - system_program::id(), - sysvar::id(), - bpf_loader::id(), - bpf_loader_upgradeable::id(), - incinerator::id(), - config::program::id(), - vote::program::id(), - feature::id(), - bpf_loader_deprecated::id(), - address_lookup_table::program::id(), - loader_v4::id(), - stake::program::id(), - #[allow(deprecated)] - stake::config::id(), - ]; - sdk_ids.extend(sysvar::ALL_IDS.iter()); - sdk_ids - }; - } -} - -#[deprecated(since = "2.1.0", note = "Use `solana-decode-error` crate instead")] -pub use solana_decode_error as decode_error; pub use solana_pubkey::{declare_deprecated_id, declare_id, pubkey}; #[deprecated(since = "2.1.0", note = "Use `solana-sysvar-id` crate instead")] pub use solana_sysvar_id::{declare_deprecated_sysvar_id, declare_sysvar_id}; diff --git a/program/src/loader_v4.rs b/program/src/loader_v4.rs deleted file mode 100644 index 9b81d7e61..000000000 --- a/program/src/loader_v4.rs +++ /dev/null @@ -1,14 +0,0 @@ -#[deprecated(since = "2.2.0", note = "Use solana-loader-v4-interface instead")] -pub use solana_loader_v4_interface::{ - instruction::{ - create_buffer, deploy, deploy_from_source, finalize, is_deploy_instruction, - is_finalize_instruction, is_retract_instruction, is_set_program_length_instruction, - is_set_program_length_instruction as is_truncate_instruction, - is_transfer_authority_instruction, is_write_instruction, retract, - set_program_length as truncate, set_program_length as truncate_uninitialized, - set_program_length, transfer_authority, write, - }, - state::{LoaderV4State, LoaderV4Status}, - DEPLOYMENT_COOLDOWN_IN_SLOTS, -}; -pub use solana_sdk_ids::loader_v4::{check_id, id, ID}; diff --git a/program/src/nonce.rs b/program/src/nonce.rs deleted file mode 100644 index 5dc9f571f..000000000 --- a/program/src/nonce.rs +++ /dev/null @@ -1,7 +0,0 @@ -pub use solana_nonce::{state::State, NONCED_TX_MARKER_IX_INDEX}; -pub mod state { - pub use solana_nonce::{ - state::{Data, DurableNonce, State}, - versions::{AuthorizeNonceError, Versions}, - }; -} diff --git a/program/src/program_utils.rs b/program/src/program_utils.rs deleted file mode 100644 index 823cd9881..000000000 --- a/program/src/program_utils.rs +++ /dev/null @@ -1 +0,0 @@ -pub use solana_bincode::limited_deserialize; diff --git a/program/src/stake.rs b/program/src/stake.rs deleted file mode 100644 index 5b9a1c289..000000000 --- a/program/src/stake.rs +++ /dev/null @@ -1,13 +0,0 @@ -#[deprecated(since = "2.2.0", note = "Use solana-stake-interface instead")] -pub use solana_stake_interface::{ - config, stake_flags, state, tools, MINIMUM_DELINQUENT_EPOCHS_FOR_DEACTIVATION, -}; - -pub mod instruction { - #[deprecated(since = "2.2.0", note = "Use solana-stake-interface instead")] - pub use solana_stake_interface::{error::StakeError, instruction::*}; -} - -pub mod program { - pub use solana_sdk_ids::stake::{check_id, id, ID}; -} diff --git a/program/src/stake_history.rs b/program/src/stake_history.rs deleted file mode 100644 index a046f7827..000000000 --- a/program/src/stake_history.rs +++ /dev/null @@ -1,6 +0,0 @@ -pub use { - crate::sysvar::stake_history::{ - StakeHistory, StakeHistoryEntry, StakeHistoryGetEntry, MAX_ENTRIES, - }, - solana_clock::Epoch, -}; diff --git a/program/src/system_instruction.rs b/program/src/system_instruction.rs deleted file mode 100644 index ec316c2d3..000000000 --- a/program/src/system_instruction.rs +++ /dev/null @@ -1,11 +0,0 @@ -#[deprecated(since = "2.2.0", note = "Use `solana_system_interface` crate instead")] -pub use solana_system_interface::{ - error::SystemError, - instruction::{ - advance_nonce_account, allocate, allocate_with_seed, assign, assign_with_seed, - authorize_nonce_account, create_account, create_account_with_seed, create_nonce_account, - create_nonce_account_with_seed, transfer, transfer_many, transfer_with_seed, - upgrade_nonce_account, withdraw_nonce_account, SystemInstruction, - }, - MAX_PERMITTED_ACCOUNTS_DATA_ALLOCATIONS_PER_TRANSACTION, MAX_PERMITTED_DATA_LENGTH, -}; diff --git a/program/src/system_program.rs b/program/src/system_program.rs deleted file mode 100644 index d7315a63e..000000000 --- a/program/src/system_program.rs +++ /dev/null @@ -1,4 +0,0 @@ -//! The [system native program][np]. -//! -//! [np]: https://docs.solanalabs.com/runtime/programs#system-program -pub use solana_sdk_ids::system_program::{check_id, id, ID}; diff --git a/program/src/sysvar.rs b/program/src/sysvar.rs index f53ae69ca..9de44e9ce 100644 --- a/program/src/sysvar.rs +++ b/program/src/sysvar.rs @@ -24,6 +24,7 @@ pub mod instructions { #[deprecated(since = "2.2.0", note = "Use solana-instructions-sysvar crate instead")] pub use solana_instructions_sysvar::{deserialize_instruction, load_instruction_at}; #[deprecated(since = "2.2.0", note = "Use solana-instructions-sysvar crate instead")] + #[allow(deprecated)] pub use solana_instructions_sysvar::{ get_instruction_relative, load_current_index_checked, load_instruction_at_checked, store_current_index, Instructions, diff --git a/pubkey/Cargo.toml b/pubkey/Cargo.toml index 8bdb4d562..91dad8ad4 100644 --- a/pubkey/Cargo.toml +++ b/pubkey/Cargo.toml @@ -2,13 +2,30 @@ name = "solana-pubkey" description = "Solana account addresses" documentation = "https://docs.rs/solana-pubkey" -version = "2.3.0" +version = "2.4.0" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +borsh = ["dep:borsh", "dep:borsh0-10", "std"] +bytemuck = ["dep:bytemuck", "dep:bytemuck_derive"] +curve25519 = ["dep:curve25519-dalek", "sha2"] +default = ["std"] +dev-context-only-utils = ["dep:arbitrary", "rand"] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "std"] +rand = ["dep:rand", "std"] +serde = ["dep:serde", "dep:serde_derive"] +sha2 = ["dep:solana-sha256-hasher", "solana-sha256-hasher/sha2"] +std = [] + [dependencies] arbitrary = { workspace = true, features = ["derive"], optional = true } borsh = { workspace = true, optional = true } @@ -31,10 +48,6 @@ solana-frozen-abi-macro = { workspace = true, optional = true, features = [ ] } solana-sanitize = { workspace = true } -[target.'cfg(target_os = "solana")'.dependencies] -solana-define-syscall = { workspace = true } -solana-sha256-hasher = { workspace = true } - [target.'cfg(not(target_os = "solana"))'.dependencies] curve25519-dalek = { workspace = true, optional = true } solana-sha256-hasher = { workspace = true, optional = true } @@ -44,6 +57,10 @@ getrandom = { workspace = true, features = ["js", "wasm-bindgen"] } js-sys = { workspace = true } wasm-bindgen = { workspace = true } +[target.'cfg(target_os = "solana")'.dependencies] +solana-define-syscall = { workspace = true } +solana-sha256-hasher = { workspace = true } + [dev-dependencies] anyhow = { workspace = true } arbitrary = { workspace = true, features = ["derive"] } @@ -60,26 +77,5 @@ solana-pubkey = { path = ".", features = [ strum = { workspace = true } strum_macros = { workspace = true } -[features] -borsh = ["dep:borsh", "dep:borsh0-10", "std"] -bytemuck = ["dep:bytemuck", "dep:bytemuck_derive"] -curve25519 = ["dep:curve25519-dalek", "sha2"] -default = ["std"] -dev-context-only-utils = ["dep:arbitrary", "rand"] -frozen-abi = [ - "dep:solana-frozen-abi", - "dep:solana-frozen-abi-macro", - "std", -] -rand = ["dep:rand", "std"] -serde = ["dep:serde", "dep:serde_derive"] -sha2 = ["dep:solana-sha256-hasher", "solana-sha256-hasher/sha2"] -std = [] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/pubkey/src/lib.rs b/pubkey/src/lib.rs index 3cd29c5c0..ca143d865 100644 --- a/pubkey/src/lib.rs +++ b/pubkey/src/lib.rs @@ -29,7 +29,6 @@ use { str::{from_utf8_unchecked, FromStr}, }, num_traits::{FromPrimitive, ToPrimitive}, - solana_decode_error::DecodeError, }; #[cfg(target_arch = "wasm32")] use { @@ -120,7 +119,8 @@ impl fmt::Display for PubkeyError { } } -impl DecodeError for PubkeyError { +#[allow(deprecated)] +impl solana_decode_error::DecodeError for PubkeyError { fn type_of() -> &'static str { "PubkeyError" } @@ -381,7 +381,8 @@ impl From for ParsePubkeyError { } } -impl DecodeError for ParsePubkeyError { +#[allow(deprecated)] +impl solana_decode_error::DecodeError for ParsePubkeyError { fn type_of() -> &'static str { "ParsePubkeyError" } diff --git a/quic-definitions/Cargo.toml b/quic-definitions/Cargo.toml index fece1f45c..e932aef59 100644 --- a/quic-definitions/Cargo.toml +++ b/quic-definitions/Cargo.toml @@ -2,18 +2,18 @@ name = "solana-quic-definitions" description = "Definitions related to Solana over QUIC." documentation = "https://docs.rs/solana-quic-definitions" -version = "2.2.1" +version = "2.3.0" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } -[dependencies] -solana-keypair = { workspace = true } - [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] +[dependencies] +solana-keypair = { workspace = true } + [lints] workspace = true diff --git a/rent-collector/Cargo.toml b/rent-collector/Cargo.toml index 01d68205b..b664c6351 100644 --- a/rent-collector/Cargo.toml +++ b/rent-collector/Cargo.toml @@ -9,6 +9,20 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] +serde = [ + "dep:serde", + "dep:serde_derive", + "solana-epoch-schedule/serde", + "solana-rent/serde", +] + [dependencies] serde = { workspace = true, optional = true } serde_derive = { workspace = true, optional = true } @@ -27,19 +41,5 @@ assert_matches = { workspace = true } solana-logger = { workspace = true } solana-pubkey = { workspace = true, features = ["rand"] } -[features] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] -serde = [ - "dep:serde", - "dep:serde_derive", - "solana-epoch-schedule/serde", - "solana-rent/serde", -] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/rent-debits/Cargo.toml b/rent-debits/Cargo.toml index e9d155f70..d2b2b5e9c 100644 --- a/rent-debits/Cargo.toml +++ b/rent-debits/Cargo.toml @@ -9,17 +9,17 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } -[dependencies] -solana-pubkey = { workspace = true } -solana-reward-info = { workspace = true } - -[features] -dev-context-only-utils = [] - [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] all-features = true rustdoc-args = ["--cfg=docsrs"] +[features] +dev-context-only-utils = [] + +[dependencies] +solana-pubkey = { workspace = true } +solana-reward-info = { workspace = true } + [lints] workspace = true diff --git a/rent/Cargo.toml b/rent/Cargo.toml index 418a9e3f9..7dfa013c7 100644 --- a/rent/Cargo.toml +++ b/rent/Cargo.toml @@ -9,6 +9,14 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[features] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] +serde = ["dep:serde", "dep:serde_derive"] +sysvar = ["dep:solana-sdk-ids", "dep:solana-sysvar-id"] + [dependencies] serde = { workspace = true, optional = true } serde_derive = { workspace = true, optional = true } @@ -22,13 +30,5 @@ solana-sysvar-id = { workspace = true, optional = true } solana-clock = { workspace = true } static_assertions = { workspace = true } -[features] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] -serde = ["dep:serde", "dep:serde_derive"] -sysvar = ["dep:solana-sdk-ids", "dep:solana-sysvar-id"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - [lints] workspace = true diff --git a/reserved-account-keys/Cargo.toml b/reserved-account-keys/Cargo.toml index c99cba983..9b31aea8d 100644 --- a/reserved-account-keys/Cargo.toml +++ b/reserved-account-keys/Cargo.toml @@ -2,13 +2,21 @@ name = "solana-reserved-account-keys" description = "Reserved Solana account keys" documentation = "https://docs.rs/solana-reserved-account-keys" -version = "2.2.1" +version = "2.2.2" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] + [dependencies] lazy_static = { workspace = true } solana-feature-set = { workspace = true } @@ -25,13 +33,5 @@ solana-sdk-ids = { workspace = true } solana-message = { workspace = true } solana-sysvar = { workspace = true } -[features] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/reward-info/Cargo.toml b/reward-info/Cargo.toml index 5dfc77732..a332d0260 100644 --- a/reward-info/Cargo.toml +++ b/reward-info/Cargo.toml @@ -9,15 +9,15 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[features] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "serde"] +serde = ["dep:serde", "dep:serde_derive"] + [dependencies] serde = { workspace = true, optional = true } serde_derive = { workspace = true, optional = true } solana-frozen-abi = { workspace = true, optional = true } solana-frozen-abi-macro = { workspace = true, optional = true } - -[features] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] -serde = ["dep:serde", "dep:serde_derive"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] diff --git a/scripts/build-sbf.sh b/scripts/build-sbf.sh index 7d9780bd0..700caea42 100755 --- a/scripts/build-sbf.sh +++ b/scripts/build-sbf.sh @@ -31,6 +31,6 @@ exclude_list=( for dir in $(git ls-tree -d --name-only HEAD .); do if [[ ! " ${exclude_list[*]} " =~ [[:space:]]${dir}[[:space:]] ]]; then - (cd "$dir" && cargo build-sbf) + (cd "$dir" && RUSTFLAGS="-Dwarnings" cargo build-sbf) fi -done \ No newline at end of file +done diff --git a/scripts/check-detached-minimal-versions.sh b/scripts/check-detached-minimal-versions.sh new file mode 100755 index 000000000..2aa25152b --- /dev/null +++ b/scripts/check-detached-minimal-versions.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +set -eo pipefail +base="$(dirname "${BASH_SOURCE[0]}")" +# pacify shellcheck: cannot follow dynamic path +# shellcheck disable=SC1090,SC1091 +source "$base/read-cargo-variable.sh" + +here="$(dirname "$0")" +src_root="$(readlink -f "${here}/..")" +cd "${src_root}" + +dir=$1 + +# backup toml file before messing with it +cargo_toml="./Cargo.toml" +cp ${cargo_toml} ${cargo_toml}.bak + +# Remove all other members +toml set ${cargo_toml}.bak workspace.members '' > ${cargo_toml} +sed -i'' "s/members.*/members = [\"$dir\"]/" ${cargo_toml} + +# Remove paths from deps +sed -i'' "s/ path = .*, v/ v/" ${cargo_toml} + +# Remove patches +sed -i'' "s/solana-.* path.*}//" ${cargo_toml} + +# Add it back for the one to test +sed -i'' "s/solana-$dir = {/solana-$dir = { path = \"$dir\",/" ${cargo_toml} + +# Run test +set +e +bash ./scripts/check-minimal-versions.sh +status=$? + +# Restore toml file +mv ${cargo_toml}.bak ${cargo_toml} + +exit $status diff --git a/scripts/patch-crates-functions.sh b/scripts/patch-crates-functions.sh index 58bc95d0b..15f439619 100644 --- a/scripts/patch-crates-functions.sh +++ b/scripts/patch-crates-functions.sh @@ -13,6 +13,7 @@ crate_dirs=( big-mod-exp bincode blake3-hasher + bls-signatures bn254 borsh client-traits @@ -77,7 +78,6 @@ crate_dirs=( reserved-account-keys reward-info sanitize - scripts sdk sdk-ids sdk-macro @@ -100,7 +100,6 @@ crate_dirs=( system-transaction sysvar sysvar-id - target time-utils transaction transaction-error diff --git a/scripts/test-bench.sh b/scripts/test-bench.sh index eccbccd2c..84af67809 100755 --- a/scripts/test-bench.sh +++ b/scripts/test-bench.sh @@ -5,4 +5,4 @@ here="$(dirname "$0")" src_root="$(readlink -f "${here}/..")" cd "${src_root}" -./cargo nightly bench -p solana-sdk --features openssl-vendored +./cargo nightly bench -p solana-sdk diff --git a/sdk-ids/Cargo.toml b/sdk-ids/Cargo.toml index 249ce27f0..c43d77647 100644 --- a/sdk-ids/Cargo.toml +++ b/sdk-ids/Cargo.toml @@ -9,11 +9,11 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } -[dependencies] -solana-pubkey = { workspace = true, default-features = false } - [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] +[dependencies] +solana-pubkey = { workspace = true, default-features = false } + [lints] workspace = true diff --git a/sdk-macro/Cargo.toml b/sdk-macro/Cargo.toml index 7dc46aa04..5b2b807d5 100644 --- a/sdk-macro/Cargo.toml +++ b/sdk-macro/Cargo.toml @@ -9,6 +9,9 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [lib] proc-macro = true @@ -17,6 +20,3 @@ bs58 = { workspace = true, features = ["alloc"] } proc-macro2 = { workspace = true } quote = { workspace = true } syn = { workspace = true, features = ["full"] } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index c28c11458..c21bc99dd 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -3,7 +3,7 @@ name = "solana-sdk" description = "Solana SDK" documentation = "https://docs.rs/solana-sdk" readme = "README.md" -version = "2.2.2" +version = "2.3.0" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } @@ -11,6 +11,14 @@ license = { workspace = true } edition = { workspace = true } include = ["src/**/*", "README.md"] +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[lib] +crate-type = ["cdylib", "rlib"] + [features] # "program" feature is a legacy feature retained to support v1.3 and older # programs. New development should not use this feature. Instead use the @@ -22,96 +30,44 @@ default = [ "full", # functionality that is not compatible or needed for on-chain programs ] full = [ - "serde_json", "solana-signature", - "solana-transaction-context/debug-signature", "solana-pubkey/rand", - "dep:solana-client-traits", - "dep:solana-cluster-type", - "dep:solana-ed25519-program", - "dep:solana-commitment-config", - "dep:solana-compute-budget-interface", - "dep:solana-genesis-config", - "dep:solana-hard-forks", "dep:solana-keypair", "dep:solana-offchain-message", "dep:solana-precompile-error", - "dep:solana-precompiles", "dep:solana-presigner", - "dep:solana-quic-definitions", - "dep:solana-rent-collector", - "dep:solana-secp256k1-program", "dep:solana-seed-derivable", "dep:solana-seed-phrase", "dep:solana-shred-version", "dep:solana-signer", - "dep:solana-system-transaction", "dep:solana-transaction", "dep:solana-transaction-error", ] -borsh = [ - "solana-compute-budget-interface/borsh", - "solana-program/borsh", - "solana-secp256k1-recover/borsh", -] +borsh = ["solana-program/borsh"] dev-context-only-utils = [ "solana-account/dev-context-only-utils", - "solana-compute-budget-interface/dev-context-only-utils", - "solana-rent-debits/dev-context-only-utils", "solana-transaction/dev-context-only-utils", - "solana-transaction-context/dev-context-only-utils", ] frozen-abi = [ - "solana-feature-set/frozen-abi", "solana-fee-structure/frozen-abi", "solana-account/frozen-abi", - "solana-cluster-type/frozen-abi", - "solana-genesis-config/frozen-abi", - "solana-hard-forks/frozen-abi", "solana-inflation/frozen-abi", - "solana-packet/frozen-abi", - "solana-poh-config/frozen-abi", "solana-program/frozen-abi", - "solana-rent-collector/frozen-abi", - "solana-reward-info/frozen-abi", "solana-short-vec/frozen-abi", "solana-signature/frozen-abi", "solana-transaction/frozen-abi", - "solana-transaction-error/frozen-abi" + "solana-transaction-error/frozen-abi", ] -# Enables the "vendored" feature of openssl inside of secp256r1-program -openssl-vendored = ["solana-precompiles/openssl-vendored"] [dependencies] bincode = { workspace = true } bs58 = { workspace = true } serde = { workspace = true } -serde_json = { workspace = true, optional = true } solana-account = { workspace = true, features = ["bincode"] } -solana-bn254 = { workspace = true } -solana-client-traits = { workspace = true, optional = true } -solana-cluster-type = { workspace = true, features = [ - "serde", -], optional = true } -solana-commitment-config = { workspace = true, optional = true, features = [ - "serde", -] } -solana-compute-budget-interface = { workspace = true, optional = true, features = [ - "serde", -] } -solana-decode-error = { workspace = true } solana-derivation-path = { workspace = true } -solana-ed25519-program = { workspace = true, optional = true } solana-epoch-info = { workspace = true, features = ["serde"] } solana-epoch-rewards-hasher = { workspace = true } -solana-feature-set = { workspace = true } solana-fee-structure = { workspace = true, features = ["serde"] } -solana-genesis-config = { workspace = true, features = [ - "serde" -], optional = true } -solana-hard-forks = { workspace = true, features = [ - "serde", -], optional = true } solana-inflation = { workspace = true, features = ["serde"] } solana-instruction = { workspace = true } solana-keypair = { workspace = true, optional = true, features = [ @@ -119,33 +75,17 @@ solana-keypair = { workspace = true, optional = true, features = [ ] } solana-message = { workspace = true, features = ["serde"] } solana-native-token = { workspace = true } -solana-nonce-account = { workspace = true } solana-offchain-message = { workspace = true, optional = true, features = ["verify"] } -solana-packet = { workspace = true, features = ["bincode", "serde"] } -solana-poh-config = { workspace = true, features = ["serde"] } solana-precompile-error = { workspace = true, optional = true } -solana-precompiles = { workspace = true, optional = true } solana-presigner = { workspace = true, optional = true } solana-program = { workspace = true } solana-program-memory = { workspace = true } solana-pubkey = { workspace = true, default-features = false, features = [ "std", ] } -solana-quic-definitions = { workspace = true, optional = true } -solana-rent-collector = { workspace = true, features = [ - "serde" -], optional = true } -solana-rent-debits = { workspace = true } -solana-reserved-account-keys = { workspace = true } -solana-reward-info = { workspace = true, features = ["serde"] } solana-sanitize = { workspace = true } solana-sdk-ids = { workspace = true } solana-sdk-macro = { workspace = true } -solana-secp256k1-program = { workspace = true, optional = true, features = [ - "bincode", -] } -solana-secp256k1-recover = { workspace = true } -solana-secp256r1-program = { workspace = true, default-features = false } solana-seed-derivable = { workspace = true, optional = true } solana-seed-phrase = { workspace = true, optional = true } solana-serde = { workspace = true } @@ -159,7 +99,6 @@ solana-signature = { workspace = true, features = [ "verify", ], optional = true } solana-signer = { workspace = true, optional = true } -solana-system-transaction = { workspace = true, optional = true } solana-time-utils = { workspace = true } solana-transaction = { workspace = true, features = [ "blake3", @@ -167,11 +106,9 @@ solana-transaction = { workspace = true, features = [ "serde", "verify" ], optional = true } -solana-transaction-context = { workspace = true, features = ["bincode"] } solana-transaction-error = { workspace = true, features = [ "serde", ], optional = true } -solana-validator-exit = { workspace = true } thiserror = { workspace = true } [target.'cfg(target_arch = "wasm32")'.dependencies] @@ -180,24 +117,9 @@ js-sys = { workspace = true } wasm-bindgen = { workspace = true } [dev-dependencies] -curve25519-dalek = { workspace = true } -ed25519-dalek = { workspace = true } -libsecp256k1 = { workspace = true, features = ["hmac"] } -openssl = { workspace = true } -rand0-7 = { workspace = true } -serde_derive = { workspace = true } -serde_with = { workspace = true, features = ["macros"] } solana-instructions-sysvar = { workspace = true, features = ["dev-context-only-utils"] } solana-program = { workspace = true, features = ["dev-context-only-utils"] } solana-sdk = { path = ".", features = ["dev-context-only-utils"] } -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - -[lib] -crate-type = ["cdylib", "rlib"] - [lints] workspace = true diff --git a/sdk/src/feature.rs b/sdk/src/feature.rs deleted file mode 100644 index b07da2ce9..000000000 --- a/sdk/src/feature.rs +++ /dev/null @@ -1 +0,0 @@ -pub use solana_program::feature::*; diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 65bc41fd4..a4c77b479 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -34,26 +34,19 @@ // Allows macro expansion of `use ::solana_sdk::*` to work within this crate extern crate self as solana_sdk; -#[cfg(feature = "full")] -pub use solana_commitment_config as commitment_config; +#[deprecated(since = "2.2.0", note = "Use `solana-message` crate instead")] +pub use solana_message as message; #[cfg(not(target_os = "solana"))] pub use solana_program::program_stubs; -// These solana_program imports could be *-imported, but that causes a bunch of -// confusing duplication in the docs due to a rustdoc bug. #26211 -#[allow(deprecated)] -pub use solana_program::sdk_ids; #[cfg(target_arch = "wasm32")] pub use solana_program::wasm_bindgen; pub use solana_program::{ - account_info, address_lookup_table, big_mod_exp, blake3, bpf_loader, bpf_loader_deprecated, - bpf_loader_upgradeable, clock, config, custom_heap_default, custom_panic_default, - debug_account_data, declare_deprecated_sysvar_id, declare_sysvar_id, ed25519_program, - epoch_rewards, epoch_schedule, fee_calculator, impl_sysvar_get, incinerator, instruction, - keccak, lamports, loader_instruction, loader_upgradeable_instruction, loader_v4, - loader_v4_instruction, message, msg, native_token, nonce, program, program_error, - program_option, program_pack, rent, secp256k1_program, serialize_utils, slot_hashes, - slot_history, stable_layout, stake, stake_history, syscalls, system_instruction, - system_program, sysvar, unchecked_div_by_const, vote, + account_info, big_mod_exp, blake3, bpf_loader, bpf_loader_deprecated, clock, config, + custom_heap_default, custom_panic_default, debug_account_data, declare_deprecated_sysvar_id, + declare_sysvar_id, ed25519_program, epoch_rewards, epoch_schedule, fee_calculator, + impl_sysvar_get, incinerator, instruction, keccak, lamports, msg, native_token, program, + program_error, program_option, program_pack, rent, secp256k1_program, serialize_utils, + slot_hashes, slot_history, stable_layout, syscalls, sysvar, unchecked_div_by_const, }; #[cfg(feature = "borsh")] pub use solana_program::{borsh, borsh0_10, borsh1}; @@ -63,34 +56,11 @@ pub use solana_signer::signers; pub mod entrypoint; pub mod entrypoint_deprecated; pub mod example_mocks; -pub mod feature; -#[cfg(feature = "full")] -#[deprecated(since = "2.2.0", note = "Use `solana-genesis-config` crate instead")] -pub use solana_genesis_config as genesis_config; -#[cfg(feature = "full")] -#[deprecated(since = "2.2.0", note = "Use `solana-hard-forks` crate instead")] -pub use solana_hard_forks as hard_forks; pub mod hash; pub mod log; pub mod native_loader; -pub mod net; -#[deprecated(since = "2.2.2", note = "Use `agave-precompiles` crate instead")] -pub mod precompiles; -pub mod program_utils; pub mod pubkey; #[cfg(feature = "full")] -#[deprecated(since = "2.2.0", note = "Use `solana_rent_collector` crate instead")] -pub use solana_rent_collector as rent_collector; -#[deprecated(since = "2.2.0", note = "Use `solana-reward-info` crate instead")] -pub mod reward_info { - pub use solana_reward_info::RewardInfo; -} -#[deprecated(since = "2.2.0", note = "Use `solana-reward-info` crate instead")] -pub mod reward_type { - pub use solana_reward_info::RewardType; -} -pub mod rpc_port; -#[cfg(feature = "full")] #[deprecated(since = "2.2.0", note = "Use `solana-shred-version` crate instead")] pub use solana_shred_version as shred_version; pub mod signature; @@ -106,24 +76,6 @@ pub use solana_account as account; note = "Use `solana_account::state_traits` crate instead" )] pub use solana_account::state_traits as account_utils; -#[deprecated(since = "2.1.0", note = "Use `solana-bn254` crate instead")] -pub use solana_bn254 as alt_bn128; -#[cfg(feature = "full")] -#[deprecated(since = "2.2.0", note = "Use `solana-client-traits` crate instead")] -pub use solana_client_traits as client; -#[deprecated( - since = "2.2.0", - note = "Use `solana-compute-budget-interface` crate instead" -)] -#[cfg(feature = "full")] -pub use solana_compute_budget_interface as compute_budget; -#[deprecated(since = "2.1.0", note = "Use `solana-decode-error` crate instead")] -pub use solana_decode_error as decode_error; -#[deprecated(since = "2.1.0", note = "Use `solana-derivation-path` crate instead")] -pub use solana_derivation_path as derivation_path; -#[cfg(feature = "full")] -#[deprecated(since = "2.2.0", note = "Use `solana-ed25519-program` crate instead")] -pub use solana_ed25519_program as ed25519_instruction; #[deprecated(since = "2.2.0", note = "Use `solana-epoch-info` crate instead")] pub use solana_epoch_info as epoch_info; #[deprecated( @@ -131,11 +83,6 @@ pub use solana_epoch_info as epoch_info; note = "Use `solana-epoch-rewards-hasher` crate instead" )] pub use solana_epoch_rewards_hasher as epoch_rewards_hasher; -#[deprecated(since = "2.2.2", note = "Use `agave-feature-set` crate instead")] -pub mod feature_set { - #[allow(deprecated)] - pub use solana_feature_set::*; -} #[deprecated(since = "2.2.0", note = "Use `solana-fee-structure` crate instead")] pub use solana_fee_structure as fee; #[deprecated(since = "2.1.0", note = "Use `solana-inflation` crate instead")] @@ -145,15 +92,9 @@ pub use solana_inflation as inflation; note = "Use `solana_message::inner_instruction` instead" )] pub use solana_message::inner_instruction; -#[deprecated(since = "2.2.0", note = "Use `solana-nonce-account` crate instead")] -pub use solana_nonce_account as nonce_account; #[cfg(feature = "full")] #[deprecated(since = "2.2.0", note = "Use `solana-offchain-message` crate instead")] pub use solana_offchain_message as offchain_message; -#[deprecated(since = "2.1.0", note = "Use `solana-packet` crate instead")] -pub use solana_packet as packet; -#[deprecated(since = "2.2.0", note = "Use `solana-poh-config` crate instead")] -pub use solana_poh_config as poh_config; #[deprecated(since = "2.1.0", note = "Use `solana-program-memory` crate instead")] pub use solana_program_memory as program_memory; #[deprecated(since = "2.1.0", note = "Use `solana_pubkey::pubkey` instead")] @@ -173,20 +114,6 @@ pub use solana_program_memory as program_memory; /// assert_eq!(ID, my_id); /// ``` pub use solana_pubkey::pubkey; -#[cfg(feature = "full")] -#[deprecated(since = "2.2.0", note = "Use `solana-quic-definitions` crate instead")] -pub use solana_quic_definitions as quic; -#[deprecated(since = "2.2.0", note = "Use `solana-rent-debits` crate instead")] -pub use solana_rent_debits as rent_debits; -#[cfg(feature = "full")] -#[deprecated( - since = "2.2.2", - note = "Use `agave-reserved-account-keys` crate instead" -)] -pub mod reserved_account_keys { - #[allow(deprecated)] - pub use solana_reserved_account_keys::*; -} #[deprecated(since = "2.1.0", note = "Use `solana-sanitize` crate instead")] pub use solana_sanitize as sanitize; /// Same as `declare_id` except report that this id has been deprecated. @@ -215,23 +142,12 @@ pub use solana_sdk_macro::declare_deprecated_id; pub use solana_sdk_macro::declare_id; /// Convenience macro to define multiple static public keys. pub use solana_sdk_macro::pubkeys; -#[deprecated(since = "2.2.0", note = "Use `solana-secp256k1-program` crate instead")] -#[cfg(feature = "full")] -pub use solana_secp256k1_program as secp256k1_instruction; -#[deprecated(since = "2.1.0", note = "Use `solana-secp256k1-recover` crate instead")] -pub use solana_secp256k1_recover as secp256k1_recover; #[deprecated(since = "2.2.0", note = "Use `solana-serde` crate instead")] pub use solana_serde as deserialize_utils; #[deprecated(since = "2.1.0", note = "Use `solana-serde-varint` crate instead")] pub use solana_serde_varint as serde_varint; #[deprecated(since = "2.1.0", note = "Use `solana-short-vec` crate instead")] pub use solana_short_vec as short_vec; -#[cfg(feature = "full")] -#[deprecated( - since = "2.2.0", - note = "Use `solana-system-transaction` crate instead" -)] -pub use solana_system_transaction as system_transaction; #[deprecated(since = "2.2.0", note = "Use `solana-time-utils` crate instead")] pub use solana_time_utils as timing; #[cfg(feature = "full")] @@ -240,38 +156,5 @@ pub use solana_time_utils as timing; note = "Use `solana_transaction::simple_vote_transaction_checker` instead" )] pub use solana_transaction::simple_vote_transaction_checker; -#[deprecated( - since = "2.2.0", - note = "Use `solana-transaction-context` crate instead" -)] -pub mod transaction_context { - pub use solana_transaction_context::*; -} -#[deprecated(since = "2.2.0", note = "Use `solana-validator-exit` crate instead")] -pub use solana_validator_exit as exit; - -/// Convenience macro for `AddAssign` with saturating arithmetic. -/// Replace by `std::num::Saturating` once stable -#[macro_export] -macro_rules! saturating_add_assign { - ($i:expr, $v:expr) => {{ - $i = $i.saturating_add($v) - }}; -} pub extern crate bs58; - -#[cfg(test)] -mod tests { - #[test] - fn test_saturating_add_assign() { - let mut i = 0u64; - let v = 1; - saturating_add_assign!(i, v); - assert_eq!(i, 1); - - i = u64::MAX; - saturating_add_assign!(i, v); - assert_eq!(i, u64::MAX); - } -} diff --git a/sdk/src/net.rs b/sdk/src/net.rs deleted file mode 100644 index c901c6765..000000000 --- a/sdk/src/net.rs +++ /dev/null @@ -1,3 +0,0 @@ -use std::time::Duration; - -pub const DEFAULT_TPU_COALESCE: Duration = Duration::from_millis(5); diff --git a/sdk/src/precompiles.rs b/sdk/src/precompiles.rs deleted file mode 100644 index 303147f62..000000000 --- a/sdk/src/precompiles.rs +++ /dev/null @@ -1,10 +0,0 @@ -//! Solana precompiled programs. - -#![cfg(feature = "full")] - -#[deprecated(since = "2.1.0", note = "Use `solana-precompile-error` crate instead.")] -pub use solana_precompile_error::PrecompileError; -#[allow(deprecated)] -pub use solana_precompiles::{ - get_precompile, get_precompiles, is_precompile, verify_if_precompile, Precompile, Verify, -}; diff --git a/sdk/src/program_utils.rs b/sdk/src/program_utils.rs deleted file mode 100644 index f4444ea95..000000000 --- a/sdk/src/program_utils.rs +++ /dev/null @@ -1,38 +0,0 @@ -//! Contains a single utility function for deserializing from [bincode]. -//! -//! [bincode]: https://docs.rs/bincode - -use crate::instruction::InstructionError; - -/// Deserialize with a limit based the maximum amount of data a program can expect to get. -/// This function should be used in place of direct deserialization to help prevent OOM errors -pub fn limited_deserialize(instruction_data: &[u8]) -> Result -where - T: serde::de::DeserializeOwned, -{ - solana_program::program_utils::limited_deserialize( - instruction_data, - crate::packet::PACKET_DATA_SIZE as u64, - ) -} - -#[cfg(test)] -pub mod tests { - use super::*; - - #[test] - fn test_limited_deserialize() { - #[derive(serde_derive::Deserialize, serde_derive::Serialize)] - enum Foo { - Bar(Vec), - } - - let item = Foo::Bar([1; crate::packet::PACKET_DATA_SIZE - 12].to_vec()); // crate::packet::PACKET_DATA_SIZE - 12: size limit, minus enum variant and vec len() serialized sizes - let serialized = bincode::serialize(&item).unwrap(); - assert!(limited_deserialize::(&serialized).is_ok()); - - let item = Foo::Bar([1; crate::packet::PACKET_DATA_SIZE - 11].to_vec()); // Extra byte should bump serialized size over the size limit - let serialized = bincode::serialize(&item).unwrap(); - assert!(limited_deserialize::(&serialized).is_err()); - } -} diff --git a/sdk/src/pubkey.rs b/sdk/src/pubkey.rs index 344f06984..21bfa87b0 100644 --- a/sdk/src/pubkey.rs +++ b/sdk/src/pubkey.rs @@ -6,30 +6,3 @@ pub use solana_pubkey::{ bytes_are_curve_point, ParsePubkeyError, Pubkey, PubkeyError, MAX_SEEDS, MAX_SEED_LEN, PUBKEY_BYTES, }; - -#[deprecated(since = "2.1.0")] -#[cfg(feature = "full")] -pub fn write_pubkey_file(outfile: &str, pubkey: Pubkey) -> Result<(), Box> { - use std::io::Write; - - let printable = format!("{pubkey}"); - let serialized = serde_json::to_string(&printable)?; - - if let Some(outdir) = std::path::Path::new(&outfile).parent() { - std::fs::create_dir_all(outdir)?; - } - let mut f = std::fs::File::create(outfile)?; - f.write_all(&serialized.into_bytes())?; - - Ok(()) -} - -#[deprecated(since = "2.1.0")] -#[cfg(feature = "full")] -pub fn read_pubkey_file(infile: &str) -> Result> { - let f = std::fs::File::open(infile)?; - let printable: String = serde_json::from_reader(f)?; - - use std::str::FromStr; - Ok(Pubkey::from_str(&printable)?) -} diff --git a/sdk/src/rpc_port.rs b/sdk/src/rpc_port.rs deleted file mode 100644 index 0bbaa1d7f..000000000 --- a/sdk/src/rpc_port.rs +++ /dev/null @@ -1,8 +0,0 @@ -//! RPC default port numbers. - -/// Default port number for JSON RPC API -pub const DEFAULT_RPC_PORT: u16 = 8899; -pub const DEFAULT_RPC_PORT_STR: &str = "8899"; - -/// Default port number for JSON RPC pubsub -pub const DEFAULT_RPC_PUBSUB_PORT: u16 = 8900; diff --git a/sdk/src/transaction.rs b/sdk/src/transaction.rs index 7e4864a3d..69cb46b7a 100644 --- a/sdk/src/transaction.rs +++ b/sdk/src/transaction.rs @@ -1,21 +1,15 @@ #![cfg(feature = "full")] +#[deprecated(since = "2.2.0", note = "Use solana_transaction crate instead")] +pub use solana_transaction::{ + sanitized::{MessageHash, SanitizedTransaction, TransactionAccountLocks, MAX_TX_ACCOUNT_LOCKS}, + uses_durable_nonce, + versioned::{ + sanitized::SanitizedVersionedTransaction, Legacy, TransactionVersion, VersionedTransaction, + }, + Transaction, TransactionVerificationMode, +}; #[deprecated(since = "2.2.0", note = "Use solana_transaction_error crate instead")] pub use solana_transaction_error::{ AddressLoaderError, SanitizeMessageError, TransactionError, TransactionResult as Result, TransportError, TransportResult, }; -#[deprecated(since = "2.2.0", note = "Use solana_transaction crate instead")] -pub use { - solana_program::message::{AddressLoader, SimpleAddressLoader}, - solana_transaction::{ - sanitized::{ - MessageHash, SanitizedTransaction, TransactionAccountLocks, MAX_TX_ACCOUNT_LOCKS, - }, - uses_durable_nonce, - versioned::{ - sanitized::SanitizedVersionedTransaction, Legacy, TransactionVersion, - VersionedTransaction, - }, - Transaction, TransactionVerificationMode, - }, -}; diff --git a/secp256k1-program/Cargo.toml b/secp256k1-program/Cargo.toml index b67fc17ef..54cf71d88 100644 --- a/secp256k1-program/Cargo.toml +++ b/secp256k1-program/Cargo.toml @@ -2,13 +2,30 @@ name = "solana-secp256k1-program" description = "Instructions for the Solana Secp256k1 native program." documentation = "https://docs.rs/solana-secp256k1-program" -version = "2.2.1" +version = "2.2.3" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +bincode = [ + "dep:bincode", + "dep:solana-feature-set", + "dep:solana-instruction", + "dep:solana-precompile-error", + "dep:solana-sdk-ids", + "serde", +] +dev-context-only-utils = ["bincode"] +serde = ["dep:serde", "dep:serde_derive"] + [dependencies] bincode = { workspace = true, optional = true } digest = { workspace = true } @@ -37,20 +54,3 @@ solana-program-error = { workspace = true } solana-sdk = { path = "../sdk" } solana-secp256k1-program = { path = ".", features = ["dev-context-only-utils"] } solana-signer = { workspace = true } - -[features] -bincode = [ - "dep:bincode", - "dep:solana-feature-set", - "dep:solana-instruction", - "dep:solana-precompile-error", - "dep:solana-sdk-ids", - "serde", -] -dev-context-only-utils = ["bincode"] -serde = ["dep:serde", "dep:serde_derive"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] diff --git a/secp256k1-recover/Cargo.toml b/secp256k1-recover/Cargo.toml index 3fbe28bcd..edaea7d60 100644 --- a/secp256k1-recover/Cargo.toml +++ b/secp256k1-recover/Cargo.toml @@ -9,6 +9,13 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[features] +borsh = ["dep:borsh"] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] + [dependencies] borsh = { workspace = true, optional = true } solana-frozen-abi = { workspace = true, optional = true, features = [ @@ -19,12 +26,12 @@ solana-frozen-abi-macro = { workspace = true, optional = true, features = [ ] } thiserror = { workspace = true } -[target.'cfg(target_os = "solana")'.dependencies] -solana-define-syscall = { workspace = true } - [target.'cfg(not(target_os = "solana"))'.dependencies] libsecp256k1 = { workspace = true } +[target.'cfg(target_os = "solana")'.dependencies] +solana-define-syscall = { workspace = true } + [dev-dependencies] anyhow = { workspace = true } borsh = { workspace = true } @@ -33,12 +40,5 @@ solana-program = { path = "../program" } [target.'cfg(not(target_os = "solana"))'.dev-dependencies] libsecp256k1 = { workspace = true, features = ["hmac"] } -[features] -borsh = ["dep:borsh"] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - [lints] workspace = true diff --git a/secp256r1-program/Cargo.toml b/secp256r1-program/Cargo.toml index 4bf47902c..e4318ffcb 100644 --- a/secp256r1-program/Cargo.toml +++ b/secp256r1-program/Cargo.toml @@ -2,13 +2,22 @@ name = "solana-secp256r1-program" description = "Precompile implementation for the secp256r1 elliptic curve." documentation = "https://docs.rs/solana-secp256r1" -version = "2.2.2" +version = "2.2.4" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +default = [] +openssl-vendored = ["openssl/vendored"] + [dependencies] bytemuck = { workspace = true, features = ["derive"] } solana-feature-set = { workspace = true } @@ -16,21 +25,12 @@ solana-precompile-error = { workspace = true } solana-sdk-ids = { workspace = true } [target.'cfg(all(not(target_arch = "wasm32"), not(target_os = "solana")))'.dependencies] -solana-instruction = { workspace = true, features = ["std"] } openssl = { workspace = true } +solana-instruction = { workspace = true, features = ["std"] } [dev-dependencies] solana-logger = { workspace = true } solana-sdk = { path = "../sdk" } -[features] -default = [] -openssl-vendored = ["openssl/vendored"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/secp256r1-program/src/lib.rs b/secp256r1-program/src/lib.rs index 9060ea46d..9a3211ffd 100644 --- a/secp256r1-program/src/lib.rs +++ b/secp256r1-program/src/lib.rs @@ -831,12 +831,17 @@ mod target_arch { #[cfg(any(target_arch = "wasm32", target_os = "solana"))] mod target_arch { - use {solana_feature_set::FeatureSet, solana_precompile_error::PrecompileError}; + use solana_precompile_error::PrecompileError; + #[deprecated( + since = "2.2.4", + note = "Use agave_precompiles::secp256r1::verify instead" + )] + #[allow(deprecated)] pub fn verify( _data: &[u8], _instruction_datas: &[&[u8]], - _feature_set: &FeatureSet, + _feature_set: &solana_feature_set::FeatureSet, ) -> Result<(), PrecompileError> { Err(PrecompileError::InvalidSignature) } diff --git a/seed-derivable/Cargo.toml b/seed-derivable/Cargo.toml index fbdfe12d8..4bb678f85 100644 --- a/seed-derivable/Cargo.toml +++ b/seed-derivable/Cargo.toml @@ -9,8 +9,8 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } -[dependencies] -solana-derivation-path = { workspace = true } - [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +solana-derivation-path = { workspace = true } diff --git a/seed-phrase/Cargo.toml b/seed-phrase/Cargo.toml index 76b05cdf2..3a367dc93 100644 --- a/seed-phrase/Cargo.toml +++ b/seed-phrase/Cargo.toml @@ -9,10 +9,10 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [dependencies] hmac = { workspace = true } pbkdf2 = { workspace = true } sha2 = { workspace = true } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] diff --git a/serde-varint/Cargo.toml b/serde-varint/Cargo.toml index 7a7a6a8e6..997b14673 100644 --- a/serde-varint/Cargo.toml +++ b/serde-varint/Cargo.toml @@ -2,13 +2,16 @@ name = "solana-serde-varint" description = "Solana definitions for integers that serialize to variable size" documentation = "https://docs.rs/solana-serde-varint" -version = "2.2.1" +version = "2.2.2" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [dependencies] serde = { workspace = true } @@ -17,6 +20,3 @@ bincode = { workspace = true } rand = { workspace = true } serde_derive = { workspace = true } solana-short-vec = { workspace = true } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] diff --git a/serde/Cargo.toml b/serde/Cargo.toml index a5e34c93e..d5c0f2c9c 100644 --- a/serde/Cargo.toml +++ b/serde/Cargo.toml @@ -9,12 +9,12 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [dependencies] serde = { workspace = true } [dev-dependencies] bincode = { workspace = true } serde_derive = { workspace = true } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] diff --git a/serialize-utils/Cargo.toml b/serialize-utils/Cargo.toml index b9306f8f3..e29090c52 100644 --- a/serialize-utils/Cargo.toml +++ b/serialize-utils/Cargo.toml @@ -9,6 +9,9 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [dependencies] solana-instruction = { workspace = true, default-features = false, features = [ "std", @@ -25,6 +28,3 @@ solana-pubkey = { workspace = true, default-features = false, features = [ "borsh", "serde", ] } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] diff --git a/sha256-hasher/Cargo.toml b/sha256-hasher/Cargo.toml index 5d9077157..5951e38f5 100644 --- a/sha256-hasher/Cargo.toml +++ b/sha256-hasher/Cargo.toml @@ -12,6 +12,9 @@ edition = { workspace = true } [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] +[features] +sha2 = ["dep:sha2"] + [dependencies] solana-hash = { workspace = true } @@ -25,8 +28,5 @@ sha2 = { workspace = true } sha2 = { workspace = true, optional = true } solana-define-syscall = { workspace = true } -[features] -sha2 = ["dep:sha2"] - [lints] workspace = true diff --git a/short-vec/Cargo.toml b/short-vec/Cargo.toml index 306b5dc28..b1a880abd 100644 --- a/short-vec/Cargo.toml +++ b/short-vec/Cargo.toml @@ -9,6 +9,12 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[features] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] + [dependencies] serde = { workspace = true } solana-frozen-abi = { workspace = true, optional = true, features = [ @@ -23,11 +29,5 @@ assert_matches = { workspace = true } bincode = { workspace = true } serde_json = { workspace = true } -[features] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - [lints] workspace = true diff --git a/shred-version/Cargo.toml b/shred-version/Cargo.toml index 606183c88..a2b6896fb 100644 --- a/shred-version/Cargo.toml +++ b/shred-version/Cargo.toml @@ -9,13 +9,13 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [dependencies] solana-hard-forks = { workspace = true } solana-hash = { workspace = true } solana-sha256-hasher = { workspace = true } -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - [lints] workspace = true diff --git a/signature/Cargo.toml b/signature/Cargo.toml index 34be89365..0bb400182 100644 --- a/signature/Cargo.toml +++ b/signature/Cargo.toml @@ -2,13 +2,27 @@ name = "solana-signature" description = "Solana 64-byte signature type" documentation = "https://docs.rs/solana-signature" -version = "2.2.1" +version = "2.3.0" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +default = ["std", "alloc"] +alloc = [] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "std"] +rand = ["dep:rand"] +serde = ["dep:serde", "dep:serde_derive", "dep:serde-big-array"] +std = ["alloc"] +verify = ["dep:ed25519-dalek"] + [dependencies] ed25519-dalek = { workspace = true, optional = true } five8 = { workspace = true } @@ -35,23 +49,5 @@ solana-pubkey = { workspace = true, features = ["std"] } solana-short-vec = { workspace = true } solana-signature = { path = ".", features = ["serde"] } -[features] -default = ["std", "alloc"] -alloc = [] -frozen-abi = [ - "dep:solana-frozen-abi", - "dep:solana-frozen-abi-macro", - "std" -] -rand = ["dep:rand"] -serde = ["dep:serde", "dep:serde_derive", "dep:serde-big-array"] -std = ["alloc"] -verify = ["dep:ed25519-dalek"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/signer/Cargo.toml b/signer/Cargo.toml index 87ae77a51..12fed1753 100644 --- a/signer/Cargo.toml +++ b/signer/Cargo.toml @@ -9,12 +9,12 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } -[dependencies] -solana-pubkey = { workspace = true } -solana-signature = { workspace = true } -solana-transaction-error = { workspace = true } - [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] all-features = true rustdoc-args = ["--cfg=docsrs"] + +[dependencies] +solana-pubkey = { workspace = true } +solana-signature = { workspace = true } +solana-transaction-error = { workspace = true } diff --git a/slot-hashes/Cargo.toml b/slot-hashes/Cargo.toml index d26d6d810..2b4a90e82 100644 --- a/slot-hashes/Cargo.toml +++ b/slot-hashes/Cargo.toml @@ -9,6 +9,13 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[features] +serde = ["dep:serde", "dep:serde_derive", "solana-hash/serde"] +sysvar = ["dep:solana-sdk-ids", "dep:solana-sysvar-id"] + [dependencies] serde = { workspace = true, optional = true } serde_derive = { workspace = true, optional = true } @@ -18,10 +25,3 @@ solana-sysvar-id = { workspace = true, optional = true } [dev-dependencies] solana-sha256-hasher = { workspace = true } - -[features] -serde = ["dep:serde", "dep:serde_derive", "solana-hash/serde"] -sysvar = ["dep:solana-sdk-ids", "dep:solana-sysvar-id"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] diff --git a/slot-history/Cargo.toml b/slot-history/Cargo.toml index 8e43978dd..b9e634de2 100644 --- a/slot-history/Cargo.toml +++ b/slot-history/Cargo.toml @@ -9,18 +9,18 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +serde = ["dep:serde", "dep:serde_derive", "bv/serde"] +sysvar = ["dep:solana-sdk-ids", "dep:solana-sysvar-id"] + [dependencies] bv = { workspace = true } serde = { workspace = true, optional = true } serde_derive = { workspace = true, optional = true } solana-sdk-ids = { workspace = true, optional = true } solana-sysvar-id = { workspace = true, optional = true } - -[features] -serde = ["dep:serde", "dep:serde_derive", "bv/serde"] -sysvar = ["dep:solana-sdk-ids", "dep:solana-sysvar-id"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] diff --git a/sysvar-id/Cargo.toml b/sysvar-id/Cargo.toml index beebc2a53..a86f5a349 100644 --- a/sysvar-id/Cargo.toml +++ b/sysvar-id/Cargo.toml @@ -9,14 +9,14 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } -[dependencies] -solana-pubkey = { workspace = true, default-features = false } -solana-sdk-ids = { workspace = true } - [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] all-features = true rustdoc-args = ["--cfg=docsrs"] +[dependencies] +solana-pubkey = { workspace = true, default-features = false } +solana-sdk-ids = { workspace = true } + [lints] workspace = true diff --git a/sysvar/Cargo.toml b/sysvar/Cargo.toml index 314455eda..0a277c13c 100644 --- a/sysvar/Cargo.toml +++ b/sysvar/Cargo.toml @@ -2,13 +2,41 @@ name = "solana-sysvar" description = "Solana sysvar account types" documentation = "https://docs.rs/solana-sysvar" -version = "2.2.1" +version = "2.2.2" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +bincode = ["dep:bincode", "serde", "solana-stake-interface/bincode"] +bytemuck = ["dep:bytemuck", "dep:bytemuck_derive"] +dev-context-only-utils = ["bincode", "bytemuck", "solana-instructions-sysvar/dev-context-only-utils"] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "solana-stake-interface/frozen-abi", +] +serde = [ + "dep:serde", + "dep:serde_derive", + "solana-clock/serde", + "solana-epoch-rewards/serde", + "solana-epoch-schedule/serde", + "solana-fee-calculator/serde", + "solana-last-restart-slot/serde", + "solana-rent/serde", + "solana-slot-hashes/serde", + "solana-slot-history/serde", + "solana-stake-interface/serde", +] + [dependencies] bincode = { workspace = true, optional = true } bytemuck = { workspace = true, optional = true } @@ -56,33 +84,5 @@ solana-sha256-hasher = { workspace = true } solana-sysvar = { path = ".", features = ["dev-context-only-utils"] } test-case = { workspace = true } -[features] -bincode = ["dep:bincode", "serde", "solana-stake-interface/bincode"] -bytemuck = ["dep:bytemuck", "dep:bytemuck_derive"] -dev-context-only-utils = ["bincode", "bytemuck", "solana-instructions-sysvar/dev-context-only-utils"] -frozen-abi = [ - "dep:solana-frozen-abi", - "dep:solana-frozen-abi-macro", - "solana-stake-interface/frozen-abi" -] -serde = [ - "dep:serde", - "dep:serde_derive", - "solana-clock/serde", - "solana-epoch-rewards/serde", - "solana-epoch-schedule/serde", - "solana-fee-calculator/serde", - "solana-last-restart-slot/serde", - "solana-rent/serde", - "solana-slot-hashes/serde", - "solana-slot-history/serde", - "solana-stake-interface/serde", -] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/transaction-error/Cargo.toml b/transaction-error/Cargo.toml index 989990c83..0443a7fdd 100644 --- a/transaction-error/Cargo.toml +++ b/transaction-error/Cargo.toml @@ -9,6 +9,15 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] +serde = ["dep:serde", "dep:serde_derive", "solana-instruction/serde"] + [dependencies] serde = { workspace = true, optional = true } serde_derive = { workspace = true, optional = true } @@ -19,14 +28,5 @@ solana-instruction = { workspace = true, default-features = false, features = [ ] } solana-sanitize = { workspace = true } -[features] -frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] -serde = ["dep:serde", "dep:serde_derive", "solana-instruction/serde"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/transaction/Cargo.toml b/transaction/Cargo.toml index 1c92148e6..111545c1a 100644 --- a/transaction/Cargo.toml +++ b/transaction/Cargo.toml @@ -2,13 +2,44 @@ name = "solana-transaction" description = "Solana transaction-types" documentation = "https://docs.rs/solana-transaction" -version = "2.2.2" +version = "2.2.3" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +bincode = [ + "dep:bincode", + "dep:solana-bincode", + "dep:solana-signer", + "dep:solana-system-interface", + "serde", + "solana-message/bincode", +] +blake3 = ["bincode", "solana-message/blake3"] +dev-context-only-utils = ["blake3", "precompiles", "serde", "verify"] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "dep:solana-logger", +] +precompiles = ["dep:solana-feature-set", "dep:solana-precompiles"] +serde = [ + "dep:serde", + "dep:serde_derive", + "dep:solana-short-vec", + "solana-message/serde", + "solana-signature/serde", +] +verify = ["blake3", "solana-signature/verify"] + [dependencies] bincode = { workspace = true, optional = true } serde = { workspace = true, optional = true } @@ -45,43 +76,9 @@ solana-keypair = { workspace = true } solana-nonce = { workspace = true } solana-packet = { workspace = true } solana-presigner = { workspace = true } -solana-program = { workspace = true, default-features = false } solana-pubkey = { workspace = true, features = ["rand"] } solana-sdk = { path = "../sdk" } solana-sha256-hasher = { workspace = true } solana-transaction = { path = ".", features = ["dev-context-only-utils"] } +solana-vote-interface = { workspace = true, features = ["bincode"] } static_assertions = { workspace = true } - -[features] -bincode = [ - "dep:bincode", - "dep:solana-bincode", - "dep:solana-signer", - "dep:solana-system-interface", - "serde", - "solana-message/bincode", -] -blake3 = [ - "bincode", - "solana-message/blake3", -] -dev-context-only-utils = ["blake3", "precompiles", "serde", "verify"] -frozen-abi = [ - "dep:solana-frozen-abi", - "dep:solana-frozen-abi-macro", - "dep:solana-logger", -] -precompiles = ["dep:solana-feature-set", "dep:solana-precompiles"] -serde = [ - "dep:serde", - "dep:serde_derive", - "dep:solana-short-vec", - "solana-message/serde", - "solana-signature/serde", -] -verify = ["blake3", "solana-signature/verify"] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] diff --git a/transaction/src/sanitized.rs b/transaction/src/sanitized.rs index 4a1c630b2..aa6b0dad5 100644 --- a/transaction/src/sanitized.rs +++ b/transaction/src/sanitized.rs @@ -344,8 +344,8 @@ mod tests { super::*, solana_keypair::Keypair, solana_message::{MessageHeader, SimpleAddressLoader}, - solana_program::vote::{self, state::Vote}, solana_signer::Signer, + solana_vote_interface::{instruction, state::Vote}, }; #[test] @@ -357,8 +357,7 @@ mod tests { let node_keypair = Keypair::new(); let auth_keypair = Keypair::new(); let votes = Vote::new(vec![1, 2, 3], bank_hash); - let vote_ix = - vote::instruction::vote(&vote_keypair.pubkey(), &auth_keypair.pubkey(), votes); + let vote_ix = instruction::vote(&vote_keypair.pubkey(), &auth_keypair.pubkey(), votes); let mut vote_tx = Transaction::new_with_payer(&[vote_ix], Some(&node_keypair.pubkey())); vote_tx.partial_sign(&[&node_keypair], block_hash); vote_tx.partial_sign(&[&auth_keypair], block_hash); diff --git a/vote-interface/Cargo.toml b/vote-interface/Cargo.toml index 3bab7ab66..0b6993704 100644 --- a/vote-interface/Cargo.toml +++ b/vote-interface/Cargo.toml @@ -2,13 +2,47 @@ name = "solana-vote-interface" description = "Solana vote interface." documentation = "https://docs.rs/solana-vote-interface" -version = "2.2.4" +version = "2.2.5" authors = { workspace = true } repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[features] +bincode = [ + "dep:bincode", + "dep:solana-serialize-utils", + "dep:solana-system-interface", + "serde", +] +dev-context-only-utils = [ + "bincode", + "dep:arbitrary", + "solana-pubkey/dev-context-only-utils", +] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "serde", + "solana-hash/frozen-abi", + "solana-pubkey/frozen-abi", + "solana-short-vec/frozen-abi", +] +serde = [ + "dep:serde", + "dep:serde_derive", + "dep:solana-serde-varint", + "dep:solana-short-vec", + "solana-hash/serde", + "solana-pubkey/serde", +] + [dependencies] arbitrary = { workspace = true, features = ["derive"], optional = true } bincode = { workspace = true, optional = true } @@ -45,39 +79,5 @@ solana-logger = { workspace = true } solana-pubkey = { workspace = true, features = ["dev-context-only-utils"] } solana-vote-interface = { path = ".", features = ["dev-context-only-utils"] } -[features] -bincode = [ - "dep:bincode", - "dep:solana-serialize-utils", - "dep:solana-system-interface", - "serde" -] -dev-context-only-utils = [ - "bincode", - "dep:arbitrary", - "solana-pubkey/dev-context-only-utils", -] -frozen-abi = [ - "dep:solana-frozen-abi", - "dep:solana-frozen-abi-macro", - "serde", - "solana-hash/frozen-abi", - "solana-pubkey/frozen-abi", - "solana-short-vec/frozen-abi", -] -serde = [ - "dep:serde", - "dep:serde_derive", - "dep:solana-serde-varint", - "dep:solana-short-vec", - "solana-hash/serde", - "solana-pubkey/serde" -] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -all-features = true -rustdoc-args = ["--cfg=docsrs"] - [lints] workspace = true diff --git a/vote-interface/src/error.rs b/vote-interface/src/error.rs index 35ab73fb2..46b27747c 100644 --- a/vote-interface/src/error.rs +++ b/vote-interface/src/error.rs @@ -3,7 +3,6 @@ use { core::fmt, num_derive::{FromPrimitive, ToPrimitive}, - solana_decode_error::DecodeError, }; /// Reasons the vote might have had an error @@ -73,7 +72,8 @@ impl fmt::Display for VoteError { } } -impl DecodeError for VoteError { +#[allow(deprecated)] +impl solana_decode_error::DecodeError for VoteError { fn type_of() -> &'static str { "VoteError" } @@ -86,9 +86,10 @@ mod tests { #[test] fn test_custom_error_decode() { use num_traits::FromPrimitive; + #[allow(deprecated)] fn pretty_err(err: InstructionError) -> String where - T: 'static + std::error::Error + DecodeError + FromPrimitive, + T: 'static + std::error::Error + solana_decode_error::DecodeError + FromPrimitive, { if let InstructionError::Custom(code) = err { let specific_error: T = T::decode_custom_error_to_enum(code).unwrap();