From 910ff8a3eaaf643730464169c32ef62c1d9d567a Mon Sep 17 00:00:00 2001 From: Sergey Timoshin Date: Tue, 21 Jan 2025 20:02:41 +0000 Subject: [PATCH] chore: cleanup Cargo.toml deps (#1503) --- Cargo.lock | 187 ++------- Cargo.toml | 16 +- .../programs/token-escrow/Cargo.toml | 2 +- forester-utils/Cargo.toml | 20 +- forester/Cargo.toml | 16 +- program-libs/batched-merkle-tree/Cargo.toml | 2 +- program-libs/bloom-filter/Cargo.toml | 7 +- .../concurrent-merkle-tree/Cargo.toml | 16 +- program-libs/hash-set/Cargo.toml | 12 +- program-libs/hasher/Cargo.toml | 4 +- program-libs/indexed-merkle-tree/Cargo.toml | 16 +- program-libs/macros/Cargo.toml | 5 - program-libs/merkle-tree-metadata/Cargo.toml | 4 +- program-libs/utils/Cargo.toml | 14 +- program-libs/utils/src/lib.rs | 1 + program-libs/utils/src/offset/copy.rs | 381 ++++++++++++++++++ program-libs/utils/src/offset/mod.rs | 2 + program-libs/utils/src/offset/zero_copy.rs | 336 +++++++++++++++ program-libs/verifier/Cargo.toml | 6 +- program-libs/zero-copy/Cargo.toml | 2 +- .../account-compression-test/Cargo.toml | 10 +- .../compressed-token-test/Cargo.toml | 2 +- program-tests/e2e-test/Cargo.toml | 18 - program-tests/merkle-tree/Cargo.toml | 8 +- program-tests/system-cpi-test/Cargo.toml | 5 - program-tests/system-test/Cargo.toml | 2 +- program-tests/utils/Cargo.toml | 26 +- programs/account-compression/Cargo.toml | 8 +- programs/compressed-token/Cargo.toml | 3 +- programs/system/Cargo.toml | 3 +- prover/client/Cargo.toml | 18 +- sdk-libs/client/Cargo.toml | 2 +- sdk-libs/macros/Cargo.toml | 1 - sdk-libs/photon-api/Cargo.toml | 1 - sdk-libs/sdk/Cargo.toml | 4 +- xtask/Cargo.toml | 8 +- 36 files changed, 843 insertions(+), 325 deletions(-) create mode 100644 program-libs/utils/src/offset/copy.rs create mode 100644 program-libs/utils/src/offset/mod.rs create mode 100644 program-libs/utils/src/offset/zero_copy.rs diff --git a/Cargo.lock b/Cargo.lock index af1d51c6a8..ddfffb4602 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,7 +20,6 @@ dependencies = [ "anchor-lang", "bytemuck", "light-batched-merkle-tree", - "light-bloom-filter", "light-bounded-vec", "light-concurrent-merkle-tree", "light-hash-set", @@ -29,16 +28,11 @@ dependencies = [ "light-indexed-merkle-tree", "light-merkle-tree-metadata", "light-merkle-tree-reference", - "light-prover-client", - "light-utils 1.1.0", - "light-verifier", + "light-utils", "num-bigint 0.4.6", - "num-traits", "rand 0.8.5", - "serial_test", "solana-sdk", "solana-security-txt", - "tokio", ] [[package]] @@ -63,7 +57,7 @@ dependencies = [ "light-program-test", "light-prover-client", "light-test-utils", - "light-utils 1.1.0", + "light-utils", "light-verifier", "num-bigint 0.4.6", "rand 0.8.5", @@ -1340,7 +1334,7 @@ dependencies = [ "anchor-lang", "light-hasher", "light-system-program", - "light-utils 1.1.0", + "light-utils", ] [[package]] @@ -1684,31 +1678,13 @@ checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" name = "e2e-test" version = "1.1.0" dependencies = [ - "account-compression", - "anchor-lang", - "anchor-spl", "light-batched-merkle-tree", - "light-compressed-token", - "light-concurrent-merkle-tree", - "light-hasher", - "light-indexed-merkle-tree", - "light-merkle-tree-reference", "light-program-test", "light-prover-client", "light-registry", - "light-system-program", "light-test-utils", - "light-utils 1.1.0", - "light-verifier", - "num-bigint 0.4.6", - "num-traits", - "rand 0.8.5", - "reqwest", "solana-client", - "solana-program-test", "solana-sdk", - "spl-concurrent-merkle-tree", - "spl-token", "tokio", ] @@ -1956,7 +1932,6 @@ dependencies = [ "anyhow", "async-trait", "bb8", - "bincode", "borsh 0.10.3", "bs58 0.5.1", "clap 4.5.23", @@ -1993,7 +1968,6 @@ dependencies = [ "solana-transaction-status", "thiserror 1.0.64", "tokio", - "tokio-tungstenite 0.16.1", "tracing", "tracing-appender", "tracing-subscriber", @@ -2007,33 +1981,22 @@ version = "1.2.0" dependencies = [ "account-compression", "anchor-lang", - "anchor-spl", - "async-trait", "light-batched-merkle-tree", "light-client", - "light-compressed-token", "light-concurrent-merkle-tree", "light-hash-set", "light-hasher", "light-indexed-merkle-tree", - "light-merkle-tree-reference", "light-prover-client", "light-registry", "light-system-program", - "light-utils 1.1.0", + "light-utils", "light-verifier", "log", - "num-bigint 0.4.6", "num-traits", - "photon-api", "reqwest", - "solana-client", - "solana-program-test", "solana-sdk", - "solana-transaction-status", - "spl-token", "thiserror 1.0.64", - "tokio", ] [[package]] @@ -2904,7 +2867,7 @@ dependencies = [ "light-merkle-tree-metadata", "light-merkle-tree-reference", "light-prover-client", - "light-utils 1.1.0", + "light-utils", "light-verifier", "light-zero-copy", "rand 0.8.5", @@ -2921,9 +2884,8 @@ version = "0.1.0" dependencies = [ "bitvec", "fastmurmur3", - "light-utils 1.1.0", + "light-utils", "num-bigint 0.4.6", - "num-traits", "rand 0.8.5", "solana-program", "thiserror 1.0.64", @@ -2958,7 +2920,7 @@ dependencies = [ "light-sdk", "light-system-program", "light-test-utils", - "light-utils 1.1.0", + "light-utils", "log", "num-bigint 0.4.6", "num-traits", @@ -2980,13 +2942,12 @@ name = "light-compressed-token" version = "1.2.0" dependencies = [ "account-compression", - "aligned-sized", "anchor-lang", "anchor-spl", "light-hasher", "light-heap", "light-system-program", - "light-utils 1.1.0", + "light-utils", "rand 0.8.5", "solana-sdk", "solana-security-txt", @@ -3005,7 +2966,7 @@ dependencies = [ "light-hash-set", "light-hasher", "light-merkle-tree-reference", - "light-utils 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "light-utils", "memoffset 0.9.1", "num-bigint 0.4.6", "num-traits", @@ -3023,7 +2984,7 @@ dependencies = [ "ark-bn254", "ark-ff", "light-heap", - "light-utils 1.1.0", + "light-utils", "num-bigint 0.4.6", "num-traits", "rand 0.8.5", @@ -3054,20 +3015,15 @@ dependencies = [ name = "light-indexed-merkle-tree" version = "1.1.0" dependencies = [ - "borsh 0.10.3", - "hex", "light-bounded-vec", "light-concurrent-merkle-tree", "light-hash-set", "light-hasher", "light-merkle-tree-reference", - "light-utils 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "memoffset 0.9.1", + "light-utils", "num-bigint 0.4.6", "num-traits", "rand 0.8.5", - "serde", - "serde_json", "solana-program", "thiserror 1.0.64", ] @@ -3077,8 +3033,6 @@ name = "light-macros" version = "1.1.0" dependencies = [ "bs58 0.5.1", - "light-hasher", - "light-utils 1.1.0", "proc-macro2", "quote", "syn 2.0.96", @@ -3091,7 +3045,7 @@ dependencies = [ "anchor-lang", "borsh 0.10.3", "bytemuck", - "light-utils 1.1.0", + "light-utils", "solana-program", "thiserror 1.0.64", "zerocopy 0.8.14", @@ -3101,10 +3055,8 @@ dependencies = [ name = "light-merkle-tree-reference" version = "1.1.0" dependencies = [ - "hex", "light-bounded-vec", "light-hasher", - "log", "num-bigint 0.4.6", "thiserror 1.0.64", ] @@ -3141,7 +3093,7 @@ dependencies = [ "light-registry", "light-sdk", "light-system-program", - "light-utils 1.1.0", + "light-utils", "light-verifier", "log", "num-bigint 0.4.6", @@ -3170,7 +3122,7 @@ dependencies = [ "light-hasher", "light-indexed-merkle-tree", "light-merkle-tree-reference", - "light-utils 1.1.0", + "light-utils", "log", "num-bigint 0.4.6", "num-traits", @@ -3213,7 +3165,7 @@ dependencies = [ "light-macros", "light-sdk-macros", "light-system-program", - "light-utils 1.1.0", + "light-utils", "num-bigint 0.4.6", "solana-program", "solana-sdk", @@ -3223,9 +3175,8 @@ dependencies = [ name = "light-sdk-macros" version = "0.4.0" dependencies = [ - "bs58 0.5.1", "light-hasher", - "light-utils 1.1.0", + "light-utils", "prettyplease", "proc-macro2", "quote", @@ -3239,14 +3190,13 @@ dependencies = [ "account-compression", "aligned-sized", "anchor-lang", - "groth16-solana", "light-batched-merkle-tree", "light-concurrent-merkle-tree", "light-hasher", "light-heap", "light-indexed-merkle-tree", "light-macros", - "light-utils 1.1.0", + "light-utils", "light-verifier", "rand 0.8.5", "solana-sdk", @@ -3260,19 +3210,14 @@ dependencies = [ "account-compression", "anchor-lang", "anchor-spl", - "anyhow", - "ark-ff", - "async-trait", "create-address-test-program", "forester-utils", "light-batched-merkle-tree", "light-client", "light-compressed-token", "light-concurrent-merkle-tree", - "light-hash-set", "light-hasher", "light-indexed-merkle-tree", - "light-macros", "light-merkle-tree-metadata", "light-merkle-tree-reference", "light-program-test", @@ -3280,24 +3225,16 @@ dependencies = [ "light-registry", "light-sdk", "light-system-program", - "light-utils 1.1.0", - "light-verifier", + "light-utils", "log", - "memoffset 0.9.1", "num-bigint 0.4.6", "num-traits", - "photon-api", "rand 0.8.5", - "reqwest", - "serde", - "solana-client", "solana-program-test", "solana-sdk", - "solana-transaction-status", "spl-token", "spl-token-2022 3.0.5", "thiserror 1.0.64", - "tokio", ] [[package]] @@ -3310,8 +3247,10 @@ dependencies = [ "ark-ff", "borsh 0.10.3", "bytemuck", + "light-bounded-vec", "light-hasher", "light-poseidon", + "memoffset 0.9.1", "num-bigint 0.4.6", "rand 0.8.5", "solana-program", @@ -3319,22 +3258,6 @@ dependencies = [ "zerocopy 0.8.14", ] -[[package]] -name = "light-utils" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e2b5a4959cb0456b483a20b4f3930920949137c00e76b5d0f9bf8d701a3c6a" -dependencies = [ - "anyhow", - "ark-bn254", - "ark-ff", - "light-bounded-vec", - "num-bigint 0.4.6", - "rand 0.8.5", - "solana-program", - "thiserror 1.0.64", -] - [[package]] name = "light-verifier" version = "1.1.0" @@ -3342,7 +3265,7 @@ dependencies = [ "borsh 0.10.3", "groth16-solana", "light-prover-client", - "light-utils 1.1.0", + "light-utils", "reqwest", "serial_test", "solana-program", @@ -4055,7 +3978,6 @@ dependencies = [ "serde_json", "serde_with 3.9.0", "url", - "uuid", ] [[package]] @@ -4580,7 +4502,7 @@ dependencies = [ "light-prover-client", "light-registry", "light-test-utils", - "light-utils 1.1.0", + "light-utils", "serial_test", "solana-sdk", "tokio", @@ -5053,19 +4975,6 @@ dependencies = [ "syn 2.0.96", ] -[[package]] -name = "sha-1" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if", - "cpufeatures", - "digest 0.9.0", - "opaque-debug", -] - [[package]] name = "sha1" version = "0.10.6" @@ -6969,15 +6878,10 @@ dependencies = [ "light-sdk", "light-system-program", "light-test-utils", - "light-utils 1.1.0", + "light-utils", "light-verifier", - "num-bigint 0.4.6", - "num-traits", - "reqwest", "serial_test", - "solana-program-test", "solana-sdk", - "spl-token", "tokio", ] @@ -6997,7 +6901,7 @@ dependencies = [ "light-sdk", "light-system-program", "light-test-utils", - "light-utils 1.1.0", + "light-utils", "light-verifier", "quote", "serde_json", @@ -7379,18 +7283,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-tungstenite" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e80b39df6afcc12cdf752398ade96a6b9e99c903dfdc36e53ad10b9c366bca72" -dependencies = [ - "futures-util", - "log", - "tokio", - "tungstenite 0.16.0", -] - [[package]] name = "tokio-tungstenite" version = "0.20.1" @@ -7595,25 +7487,6 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" -[[package]] -name = "tungstenite" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ad3713a14ae247f22a728a0456a545df14acf3867f905adff84be99e23b3ad1" -dependencies = [ - "base64 0.13.1", - "byteorder", - "bytes", - "http 0.2.12", - "httparse", - "log", - "rand 0.8.5", - "sha-1", - "thiserror 1.0.64", - "url", - "utf-8", -] - [[package]] name = "tungstenite" version = "0.20.1" @@ -7790,16 +7663,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" -[[package]] -name = "uuid" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" -dependencies = [ - "getrandom 0.2.15", - "serde", -] - [[package]] name = "valuable" version = "0.1.0" @@ -8319,7 +8182,7 @@ dependencies = [ "light-indexed-merkle-tree", "light-program-test", "light-test-utils", - "light-utils 1.1.0", + "light-utils", "num-bigint 0.4.6", "quote", "rand 0.8.5", diff --git a/Cargo.toml b/Cargo.toml index 8bd22e17ca..83f4fe930b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -78,9 +78,18 @@ bb8 = "0.8.6" # Logging log = "0.4" +env_logger = "0.11" # Error handling thiserror = "1.0" +anyhow = "1.0" + +# Arkworks +ark-ff = "0.4" +ark-bn254 = "0.4" +ark-serialize = "0.4" +ark-std = "0.4" + # Light Protocol light-hash-set = { version = "1.2.0", path = "program-libs/hash-set" } @@ -120,10 +129,13 @@ num-traits = "0.2.19" zerocopy = { version = "0.8.14"} # HTTP client -reqwest = "0.11.26" +reqwest = "0.11" # Testing -serial_test = "3.1.1" +serial_test = "3.2.0" + +# Random +rand = "0.8.5" [patch.crates-io] "solana-account-decoder" = { git = "https://github.com/lightprotocol/agave", branch = "v1.18.22-enforce-cpi-tracking" } diff --git a/examples/token-escrow/programs/token-escrow/Cargo.toml b/examples/token-escrow/programs/token-escrow/Cargo.toml index 812b0e538e..0f4fd6c7d1 100644 --- a/examples/token-escrow/programs/token-escrow/Cargo.toml +++ b/examples/token-escrow/programs/token-escrow/Cargo.toml @@ -36,7 +36,7 @@ light-client = { workspace = true } light-test-utils = { workspace = true, features = ["devenv"] } light-program-test = { workspace = true, features = ["devenv"] } tokio = { workspace = true } -light-prover-client = { workspace = true, version = "1.2.0" } +light-prover-client = { workspace = true } anchor-spl = { workspace = true } [lints.rust.unexpected_cfgs] diff --git a/forester-utils/Cargo.toml b/forester-utils/Cargo.toml index 9186a6c078..9921b61ab4 100644 --- a/forester-utils/Cargo.toml +++ b/forester-utils/Cargo.toml @@ -7,12 +7,11 @@ repository = "https://github.com/lightprotocol/light-protocol" description = "Utility library for Light's Forester node implementation" [dependencies] + # Light Protocol account-compression = { workspace = true } -light-compressed-token = { workspace = true } light-hash-set = { workspace=true } light-hasher = { workspace = true } -light-merkle-tree-reference = { workspace = true } light-concurrent-merkle-tree = { workspace = true } light-indexed-merkle-tree = { workspace = true } light-prover-client = { workspace = true } @@ -21,34 +20,23 @@ light-system-program = { workspace = true, features = ["cpi"] } light-utils = { workspace = true } light-batched-merkle-tree = { workspace = true } light-verifier = { workspace = true } -photon-api = { workspace = true } light-client = { workspace = true } # Anchor anchor-lang = { workspace = true } -anchor-spl = { workspace = true } # Solana -spl-token = { workspace = true, features = ["no-entrypoint"] } -solana-program-test = { workspace = true } solana-sdk = { workspace = true } -solana-client = { workspace = true } -solana-transaction-status = { workspace = true } - -# Async ecosystem -tokio = { workspace = true } -async-trait = { workspace = true } # Error handling -thiserror = "1.0" +thiserror = { workspace = true } # Logging -log = "0.4" +log = { workspace = true } # Big numbers -num-bigint = { workspace = true } num-traits = { workspace = true } # HTTP client -reqwest = "0.11.26" +reqwest = { workspace = true } diff --git a/forester/Cargo.toml b/forester/Cargo.toml index 9a24ea9322..3857b85ba1 100644 --- a/forester/Cargo.toml +++ b/forester/Cargo.toml @@ -24,21 +24,19 @@ light-merkle-tree-metadata = { workspace = true } light-sdk = { workspace = true } light-program-test = { workspace = true} solana-transaction-status = { workspace = true } -bincode = "1.3" url = "2.2" -tokio-tungstenite = "0.16" bb8 = { workspace = true } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } tokio = { version = "1", features = ["full"] } -reqwest = { version = "0.11", features = ["json", "rustls-tls", "blocking"] } +reqwest = { workspace = true, features = ["json", "rustls-tls", "blocking"] } futures = "0.3.31" -thiserror = "1" -borsh = "0.10.3" +thiserror = { workspace = true } +borsh = { workspace = true } bs58 = "0.5.1" -env_logger = "0.11" -async-trait = "0.1.81" +env_logger = { workspace = true } +async-trait = { workspace = true} tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json"] } tracing-appender = "0.2.3" @@ -47,11 +45,11 @@ lazy_static = "1.4" warp = "0.3" dashmap = "6.1.0" scopeguard = "1.2.0" -anyhow = "1.0.94" +anyhow = { workspace = true } itertools = "0.14.0" [dev-dependencies] -serial_test = "3.2.0" +serial_test = { workspace = true } light-prover-client = { workspace = true } light-test-utils = { workspace = true } light-program-test = { workspace = true, features = ["devenv"] } diff --git a/program-libs/batched-merkle-tree/Cargo.toml b/program-libs/batched-merkle-tree/Cargo.toml index 9d3749db23..8a2a70a43e 100644 --- a/program-libs/batched-merkle-tree/Cargo.toml +++ b/program-libs/batched-merkle-tree/Cargo.toml @@ -27,7 +27,7 @@ anchor-lang = { workspace = true , optional = true } zerocopy = { workspace = true } [dev-dependencies] -rand = "0.8.5" +rand = { workspace = true } light-prover-client = { workspace = true } light-merkle-tree-reference = { workspace = true } tokio = {workspace = true} diff --git a/program-libs/bloom-filter/Cargo.toml b/program-libs/bloom-filter/Cargo.toml index aef65171b1..d84f9c11c7 100644 --- a/program-libs/bloom-filter/Cargo.toml +++ b/program-libs/bloom-filter/Cargo.toml @@ -12,11 +12,10 @@ solana = ["solana-program"] [dependencies] bitvec = "1.0.1" fastmurmur3 = "0.2.0" -num-bigint = "0.4" -num-traits = "0.2" +num-bigint = { workspace = true } solana-program = { workspace = true, optional = true } -thiserror = "1.0" +thiserror = { workspace = true } [dev-dependencies] -rand = "0.8" +rand = { workspace = true } light-utils = { workspace = true } diff --git a/program-libs/concurrent-merkle-tree/Cargo.toml b/program-libs/concurrent-merkle-tree/Cargo.toml index 6e0e756cf9..75892f670a 100644 --- a/program-libs/concurrent-merkle-tree/Cargo.toml +++ b/program-libs/concurrent-merkle-tree/Cargo.toml @@ -15,22 +15,22 @@ solana = [ ] [dependencies] -borsh = "0.10" +borsh = { workspace = true } light-bounded-vec = { workspace = true } light-hasher = { workspace = true } -light-utils = { version = "1.1.0"} +light-utils = { workspace = true } memoffset = "0.9" solana-program = { workspace = true, optional = true } -thiserror = "1.0" +thiserror = { workspace = true} [dev-dependencies] -ark-bn254 = "0.4" -ark-ff = "0.4" +ark-bn254 = { workspace = true } +ark-ff = { workspace = true } light-merkle-tree-reference = { workspace = true} light-hash-set = { workspace = true, features = ["solana"] } -rand = "0.8" +rand = { workspace = true } solana-program = { workspace = true } spl-concurrent-merkle-tree = { version = "0.2.0", default-features = false} tokio = { workspace = true } -num-bigint = "0.4" -num-traits = "0.2" +num-bigint = { workspace = true } +num-traits = { workspace = true} diff --git a/program-libs/hash-set/Cargo.toml b/program-libs/hash-set/Cargo.toml index 658be35ef6..6fdd71f264 100644 --- a/program-libs/hash-set/Cargo.toml +++ b/program-libs/hash-set/Cargo.toml @@ -11,14 +11,14 @@ solana = ["solana-program"] [dependencies] light-utils = { workspace = true } -num-bigint = "0.4" -num-traits = "0.2" +num-bigint = { workspace = true } +num-traits = { workspace = true } solana-program = { workspace = true, optional = true } -thiserror = "1.0" +thiserror = { workspace = true} [target.'cfg(target_os = "solana")'.dependencies] light-heap = { workspace = true } [dev-dependencies] -ark-bn254 = "0.4" -ark-ff = "0.4" -rand = "0.8" +ark-bn254 = { workspace = true } +ark-ff = { workspace = true } +rand = { workspace = true } diff --git a/program-libs/hasher/Cargo.toml b/program-libs/hasher/Cargo.toml index 8d132ca94c..d03ad3254c 100644 --- a/program-libs/hasher/Cargo.toml +++ b/program-libs/hasher/Cargo.toml @@ -12,10 +12,10 @@ solana = [] [dependencies] light-poseidon = "0.2.0" solana-program = { workspace = true } -thiserror = "1.0" +thiserror = { workspace = true } [target.'cfg(not(target_os = "solana"))'.dependencies] -ark-bn254 = "0.4.0" +ark-bn254 = { workspace = true } sha2 = "0.10" sha3 = "0.10" diff --git a/program-libs/indexed-merkle-tree/Cargo.toml b/program-libs/indexed-merkle-tree/Cargo.toml index c9d011d22f..4d300f80a6 100644 --- a/program-libs/indexed-merkle-tree/Cargo.toml +++ b/program-libs/indexed-merkle-tree/Cargo.toml @@ -13,23 +13,17 @@ solana = [ ] [dependencies] -borsh = { version = "0.10" } light-bounded-vec = { workspace = true } light-hasher = { workspace = true } light-concurrent-merkle-tree = { workspace = true } light-merkle-tree-reference = { workspace = true } -light-utils = { version = "1.1.0"} -memoffset = "0.9" -num-bigint = "0.4" -num-traits = "0.2" +light-utils = { workspace = true } +num-bigint = { workspace = true } +num-traits = { workspace = true } solana-program = { workspace = true, optional = true } -thiserror = "1.0" +thiserror = { workspace = true } [dev-dependencies] light-hash-set = { workspace = true } -thiserror = "1.0" -rand = "0.8" -hex = "0.4" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" +rand = { workspace = true} diff --git a/program-libs/macros/Cargo.toml b/program-libs/macros/Cargo.toml index e0e152fd34..5775015eba 100644 --- a/program-libs/macros/Cargo.toml +++ b/program-libs/macros/Cargo.toml @@ -12,10 +12,5 @@ proc-macro2 = { workspace = true } quote = { workspace = true } syn = { workspace = true } -light-hasher = { workspace = true } - -[dev-dependencies] -light-utils = { workspace = true } - [lib] proc-macro = true diff --git a/program-libs/merkle-tree-metadata/Cargo.toml b/program-libs/merkle-tree-metadata/Cargo.toml index 544a7b7eda..02b5b3c989 100644 --- a/program-libs/merkle-tree-metadata/Cargo.toml +++ b/program-libs/merkle-tree-metadata/Cargo.toml @@ -12,8 +12,8 @@ anchor = ["anchor-lang", "solana"] solana = [] [dependencies] -thiserror = "1.0" -borsh = "0.10.0" +thiserror = { workspace = true} +borsh = { workspace = true } bytemuck = "1.17" solana-program = { workspace = true } anchor-lang = { workspace = true , optional = true } diff --git a/program-libs/utils/Cargo.toml b/program-libs/utils/Cargo.toml index 3caf66def5..40cfe46d9c 100644 --- a/program-libs/utils/Cargo.toml +++ b/program-libs/utils/Cargo.toml @@ -11,19 +11,21 @@ default = [] anchor = ["anchor-lang"] [dependencies] -anyhow = "1.0" -ark-ff = "0.4" +anyhow = { workspace = true } +ark-ff = { workspace = true } +ark-bn254 = { workspace = true } light-hasher = { workspace = true } -num-bigint = { version = "0.4", features = ["rand"] } -thiserror = "1.0" +num-bigint = { workspace = true, features = ["rand"] } +thiserror = { workspace = true } solana-program = { workspace = true } -ark-bn254 = "0.4.0" -rand = "0.8" +rand = { workspace = true } zerocopy = { workspace = true, features = ["derive"] } borsh = { workspace = true } bytemuck = { workspace = true } anchor-lang = { workspace = true, optional = true } +light-bounded-vec = { workspace = true } [dev-dependencies] light-poseidon = { workspace = true } borsh = { workspace = true } +memoffset = "0.9" \ No newline at end of file diff --git a/program-libs/utils/src/lib.rs b/program-libs/utils/src/lib.rs index 55eef53788..7661c1e7d7 100644 --- a/program-libs/utils/src/lib.rs +++ b/program-libs/utils/src/lib.rs @@ -16,6 +16,7 @@ pub mod account; pub mod bigint; pub mod fee; pub mod hashchain; +pub mod offset; pub mod prime; pub mod pubkey; pub mod rand; diff --git a/program-libs/utils/src/offset/copy.rs b/program-libs/utils/src/offset/copy.rs new file mode 100644 index 0000000000..bb1039c0e9 --- /dev/null +++ b/program-libs/utils/src/offset/copy.rs @@ -0,0 +1,381 @@ +use std::{mem, ptr}; + +use light_bounded_vec::{ + BoundedVec, BoundedVecMetadata, CyclicBoundedVec, CyclicBoundedVecMetadata, +}; + +/// Creates a copy of value of type `T` based on the provided `bytes` buffer. +/// +/// # Safety +/// +/// This is higly unsafe. This function doesn't ensure alignment and +/// correctness of provided buffer. The responsibility of such checks is on +/// the caller. +pub unsafe fn read_value_at(bytes: &[u8], offset: &mut usize) -> T +where + T: Clone, +{ + let size = mem::size_of::(); + let ptr = bytes[*offset..*offset + size].as_ptr() as *const T; + *offset += size; + ptr::read(ptr) +} + +/// Creates a `BoundedVec` from the sequence of values provided in `bytes` buffer. +/// +/// # Safety +/// +/// This is higly unsafe. This function doesn't ensure alignment and +/// correctness of provided buffer. The responsibility of such checks is on +/// the caller. +/// +/// The `T` type needs to be either a primitive or struct consisting of +/// primitives. It cannot contain any nested heap-backed stucture (like vectors, +/// slices etc.). +pub unsafe fn read_bounded_vec_at( + bytes: &[u8], + offset: &mut usize, + metadata: &BoundedVecMetadata, +) -> BoundedVec +where + T: Clone, +{ + let size = mem::size_of::() * metadata.capacity(); + let ptr = bytes[*offset..*offset + size].as_ptr() as *const T; + + let mut vec = BoundedVec::with_metadata(metadata); + let dst_ptr: *mut T = vec.as_mut_ptr(); + + for i in 0..metadata.length() { + let val = ptr::read(ptr.add(i)); + // SAFETY: We ensured the bounds. + unsafe { ptr::write(dst_ptr.add(i), val) }; + } + + *offset += size; + + vec +} + +/// Creates a `CyclicBoundedVec` from the sequence of values provided in +/// `bytes` buffer. +/// +/// # Safety +/// +/// This is higly unsafe. This function doesn't ensure alignment and +/// correctness of provided buffer. The responsibility of such checks is on +/// the caller. +pub unsafe fn read_cyclic_bounded_vec_at( + bytes: &[u8], + offset: &mut usize, + metadata: &CyclicBoundedVecMetadata, +) -> CyclicBoundedVec +where + T: Clone, +{ + let size = mem::size_of::() * metadata.capacity(); + let src_ptr = bytes[*offset..*offset + size].as_ptr() as *const T; + + let mut vec = CyclicBoundedVec::with_metadata(metadata); + let dst_ptr: *mut T = vec.as_mut_ptr(); + + for i in 0..metadata.length() { + let val = ptr::read(src_ptr.add(i)); + // SAFETY: We ensured the bounds. + unsafe { ptr::write(dst_ptr.add(i), val) }; + } + + *offset += size; + + vec +} + +#[cfg(test)] +mod test { + use std::slice; + + use bytemuck::{Pod, Zeroable}; + use memoffset::offset_of; + + use super::*; + + #[test] + fn test_value_at() { + #[derive(Clone, Copy, Pod, Zeroable)] + #[repr(C)] + struct TestStruct { + a: isize, + b: usize, + c: i64, + d: u64, + e: i32, + f: u32, + g: i16, + _padding_1: [u8; 2], + h: u16, + _padding_2: [u8; 2], + i: i8, + _padding_3: [i8; 3], + j: u8, + _padding_4: [i8; 3], + } + + let mut buf = vec![0_u8; mem::size_of::()]; + let s = buf.as_mut_ptr() as *mut TestStruct; + + unsafe { + (*s).a = isize::MIN; + (*s).b = usize::MAX; + (*s).c = i64::MIN; + (*s).d = u64::MAX; + (*s).e = i32::MIN; + (*s).f = u32::MAX; + (*s).g = i16::MIN; + (*s).h = u16::MAX; + (*s).i = i8::MIN; + (*s).j = u8::MAX; + + let mut offset = offset_of!(TestStruct, a); + assert_eq!(offset, 0); + assert_eq!(read_value_at::(&buf, &mut offset), isize::MIN); + assert_eq!(offset, 8); + + let mut offset = offset_of!(TestStruct, b); + assert_eq!(offset, 8); + assert_eq!(read_value_at::(&buf, &mut offset), usize::MAX); + assert_eq!(offset, 16); + + let mut offset = offset_of!(TestStruct, c); + assert_eq!(offset, 16); + assert_eq!(read_value_at::(&buf, &mut offset), i64::MIN); + assert_eq!(offset, 24); + + let mut offset = offset_of!(TestStruct, d); + assert_eq!(offset, 24); + assert_eq!(read_value_at::(&buf, &mut offset), u64::MAX); + assert_eq!(offset, 32); + + let mut offset = offset_of!(TestStruct, e); + assert_eq!(offset, 32); + assert_eq!(read_value_at::(&buf, &mut offset), i32::MIN); + assert_eq!(offset, 36); + + let mut offset = offset_of!(TestStruct, f); + assert_eq!(offset, 36); + assert_eq!(read_value_at::(&buf, &mut offset), u32::MAX); + assert_eq!(offset, 40); + + let mut offset = offset_of!(TestStruct, g); + assert_eq!(offset, 40); + assert_eq!(read_value_at::(&buf, &mut offset), i16::MIN); + assert_eq!(offset, 42); + + let mut offset = offset_of!(TestStruct, h); + assert_eq!(offset, 44); + assert_eq!(read_value_at::(&buf, &mut offset), u16::MAX); + assert_eq!(offset, 46); + + let mut offset = offset_of!(TestStruct, i); + assert_eq!(offset, 48); + assert_eq!(read_value_at::(&buf, &mut offset), i8::MIN); + assert_eq!(offset, 49); + + let mut offset = offset_of!(TestStruct, j); + assert_eq!(offset, 52); + assert_eq!(read_value_at::(&buf, &mut offset), u8::MAX); + assert_eq!(offset, 53); + } + } + + #[test] + fn test_read_bounded_vec_at() { + #[derive(Clone, Copy, Pod, Zeroable)] + #[repr(C)] + struct TestStruct { + a: [i64; 32], + b: [u64; 32], + c: [[u8; 32]; 32], + } + + let mut buf = vec![0_u8; mem::size_of::()]; + let s = buf.as_mut_ptr() as *mut TestStruct; + + unsafe { + for (i, element) in (*s).a.iter_mut().enumerate() { + *element = -(i as i64); + } + for (i, element) in (*s).b.iter_mut().enumerate() { + *element = i as u64; + } + for (i, element) in (*s).c.iter_mut().enumerate() { + *element = [i as u8; 32]; + } + + let metadata = BoundedVecMetadata::new_with_length(32, 32); + let mut offset = offset_of!(TestStruct, a); + assert_eq!(offset, 0); + let vec: BoundedVec = read_bounded_vec_at(&buf, &mut offset, &metadata); + for (i, element) in vec.iter().enumerate() { + assert_eq!(i as i64, -*element); + } + assert_eq!(offset, 256); + + let metadata = BoundedVecMetadata::new_with_length(32, 32); + let mut offset = offset_of!(TestStruct, b); + assert_eq!(offset, 256); + let vec: BoundedVec = read_bounded_vec_at(&buf, &mut offset, &metadata); + for (i, element) in vec.iter().enumerate() { + assert_eq!(i as u64, *element); + } + assert_eq!(offset, 512); + + let metadata = BoundedVecMetadata::new_with_length(32, 32); + let mut offset = offset_of!(TestStruct, c); + assert_eq!(offset, 512); + let vec: BoundedVec<[u8; 32]> = read_bounded_vec_at(&buf, &mut offset, &metadata); + for (i, element) in vec.iter().enumerate() { + assert_eq!(&[i as u8; 32], element); + } + assert_eq!(offset, 1536); + } + } + + #[test] + fn test_read_cyclic_bounded_vec_at() { + #[derive(Clone, Copy, Pod, Zeroable)] + #[repr(C)] + struct TestStruct { + a: [i64; 32], + b: [u64; 32], + c: [[u8; 32]; 32], + } + + let mut buf = vec![0_u8; mem::size_of::()]; + let s = buf.as_mut_ptr() as *mut TestStruct; + + unsafe { + for (i, element) in (*s).a.iter_mut().enumerate() { + *element = -(i as i64); + } + for (i, element) in (*s).b.iter_mut().enumerate() { + *element = i as u64; + } + for (i, element) in (*s).c.iter_mut().enumerate() { + *element = [i as u8; 32]; + } + + // Start the cyclic vecs from the middle. + + let metadata = CyclicBoundedVecMetadata::new_with_indices(32, 32, 14, 13); + let mut offset = offset_of!(TestStruct, a); + assert_eq!(offset, 0); + let vec: CyclicBoundedVec = + read_cyclic_bounded_vec_at(&buf, &mut offset, &metadata); + assert_eq!(vec.capacity(), 32); + assert_eq!(vec.len(), 32); + assert_eq!(vec.first_index(), 14); + assert_eq!(vec.last_index(), 13); + assert_eq!( + vec.iter().collect::>().as_slice(), + &[ + &-14, &-15, &-16, &-17, &-18, &-19, &-20, &-21, &-22, &-23, &-24, &-25, &-26, + &-27, &-28, &-29, &-30, &-31, &-0, &-1, &-2, &-3, &-4, &-5, &-6, &-7, &-8, &-9, + &-10, &-11, &-12, &-13 + ] + ); + assert_eq!(offset, 256); + + let metadata = CyclicBoundedVecMetadata::new_with_indices(32, 32, 14, 13); + let mut offset = offset_of!(TestStruct, b); + assert_eq!(offset, 256); + let vec: CyclicBoundedVec = + read_cyclic_bounded_vec_at(&buf, &mut offset, &metadata); + assert_eq!(vec.capacity(), 32); + assert_eq!(vec.len(), 32); + assert_eq!(vec.first_index(), 14); + assert_eq!(vec.last_index(), 13); + assert_eq!( + vec.iter().collect::>().as_slice(), + &[ + &14, &15, &16, &17, &18, &19, &20, &21, &22, &23, &24, &25, &26, &27, &28, &29, + &30, &31, &0, &1, &2, &3, &4, &5, &6, &7, &8, &9, &10, &11, &12, &13 + ] + ); + assert_eq!(offset, 512); + + let metadata = CyclicBoundedVecMetadata::new_with_indices(32, 32, 14, 13); + let mut offset = offset_of!(TestStruct, c); + assert_eq!(offset, 512); + let vec: CyclicBoundedVec<[u8; 32]> = + read_cyclic_bounded_vec_at(&buf, &mut offset, &metadata); + assert_eq!(vec.capacity(), 32); + assert_eq!(vec.len(), 32); + assert_eq!(vec.first_index(), 14); + assert_eq!(vec.last_index(), 13); + assert_eq!( + vec.iter().collect::>().as_slice(), + &[ + &[14_u8; 32], + &[15_u8; 32], + &[16_u8; 32], + &[17_u8; 32], + &[18_u8; 32], + &[19_u8; 32], + &[20_u8; 32], + &[21_u8; 32], + &[22_u8; 32], + &[23_u8; 32], + &[24_u8; 32], + &[25_u8; 32], + &[26_u8; 32], + &[27_u8; 32], + &[28_u8; 32], + &[29_u8; 32], + &[30_u8; 32], + &[31_u8; 32], + &[0_u8; 32], + &[1_u8; 32], + &[2_u8; 32], + &[3_u8; 32], + &[4_u8; 32], + &[5_u8; 32], + &[6_u8; 32], + &[7_u8; 32], + &[8_u8; 32], + &[9_u8; 32], + &[10_u8; 32], + &[11_u8; 32], + &[12_u8; 32], + &[13_u8; 32], + ] + ); + assert_eq!(offset, 1536); + } + } + + #[test] + fn test_read_cyclic_bounded_vec_first_last() { + let mut vec = CyclicBoundedVec::::with_capacity(2); + vec.push(0); + vec.push(37); + vec.push(49); + + let metadata_bytes = vec.metadata().to_le_bytes(); + let metadata = CyclicBoundedVecMetadata::from_le_bytes(metadata_bytes); + let bytes = unsafe { + slice::from_raw_parts( + vec.as_mut_ptr() as *mut u8, + mem::size_of::() * vec.capacity(), + ) + }; + + let mut offset = 0; + let vec_copy: CyclicBoundedVec = + unsafe { read_cyclic_bounded_vec_at(bytes, &mut offset, &metadata) }; + + assert_eq!(*vec.first().unwrap(), 37); + assert_eq!(vec.first(), vec_copy.first()); // Fails. Both should be 37 + assert_eq!(*vec.last().unwrap(), 49); + assert_eq!(vec.last(), vec_copy.last()); // Fails. Both should be 49 + } +} diff --git a/program-libs/utils/src/offset/mod.rs b/program-libs/utils/src/offset/mod.rs new file mode 100644 index 0000000000..03452ca062 --- /dev/null +++ b/program-libs/utils/src/offset/mod.rs @@ -0,0 +1,2 @@ +pub mod copy; +pub mod zero_copy; diff --git a/program-libs/utils/src/offset/zero_copy.rs b/program-libs/utils/src/offset/zero_copy.rs new file mode 100644 index 0000000000..513ce8cd96 --- /dev/null +++ b/program-libs/utils/src/offset/zero_copy.rs @@ -0,0 +1,336 @@ +use std::mem; + +/// Casts a part of provided `bytes` buffer with the given `offset` to a +/// mutable pointer to `T`. +/// +/// Should be used for single values. +/// +/// # Safety +/// +/// This is higly unsafe. This function doesn't ensure alignment and +/// correctness of provided buffer. The responsibility of such checks is on +/// the caller. +pub unsafe fn read_ptr_at(bytes: &[u8], offset: &mut usize) -> *mut T { + let size = mem::size_of::(); + let ptr = bytes[*offset..*offset + size].as_ptr() as *mut T; + *offset += size; + ptr +} + +/// Casts a part of provided `bytes` buffer with the given `offset` to a +/// mutable pointer to `T`. +/// +/// Should be used for array-type sequences. +/// +/// # Safety +/// +/// This is higly unsafe. This function doesn't ensure alignment and +/// correctness of provided buffer. The responsibility of such checks is on +/// the caller. +pub unsafe fn read_array_like_ptr_at(bytes: &[u8], offset: &mut usize, len: usize) -> *mut T { + let size = mem::size_of::() * len; + let ptr = bytes[*offset..*offset + size].as_ptr() as *mut T; + *offset += size; + ptr +} + +/// Casts a part of provided `bytes` buffer with the given `offset` to a +/// mutable pointer to `T`. +/// +/// Should be used for array-type sequences. +/// +/// # Safety +/// +/// This is higly unsafe. This function doesn't ensure alignment and +/// correctness of provided buffer. The responsibility of such checks is on +/// the caller. +pub unsafe fn read_array_like_ptr_at_mut( + bytes: &mut [u8], + offset: &mut usize, + len: usize, +) -> *mut T { + let size = mem::size_of::() * len; + let ptr = bytes[*offset..*offset + size].as_ptr() as *mut T; + *offset += size; + ptr +} + +/// Writes provided `data` into provided `bytes` buffer with the given +/// `offset`. +pub fn write_at(bytes: &mut [u8], data: &[u8], offset: &mut usize) { + let size = mem::size_of::(); + bytes[*offset..*offset + size].copy_from_slice(data); + *offset += size; +} + +#[cfg(test)] +mod test { + use bytemuck::{Pod, Zeroable}; + use memoffset::offset_of; + + use super::*; + + #[test] + fn test_read_ptr_at() { + #[derive(Clone, Copy, Pod, Zeroable)] + #[repr(C)] + struct TestStruct { + a: isize, + b: usize, + c: i64, + d: u64, + e: i32, + f: u32, + g: i16, + _padding_1: [u8; 2], + h: u16, + _padding_2: [u8; 2], + i: i8, + _padding_3: [i8; 3], + j: u8, + _padding_4: [i8; 3], + } + + let mut buf = vec![0_u8; mem::size_of::()]; + let s = buf.as_mut_ptr() as *mut TestStruct; + + unsafe { + (*s).a = isize::MIN; + (*s).b = usize::MAX; + (*s).c = i64::MIN; + (*s).d = u64::MAX; + (*s).e = i32::MIN; + (*s).f = u32::MAX; + (*s).g = i16::MIN; + (*s).h = u16::MAX; + (*s).i = i8::MIN; + (*s).j = u8::MAX; + + let mut offset = offset_of!(TestStruct, a); + assert_eq!(offset, 0); + assert_eq!(*read_ptr_at::(&buf, &mut offset), isize::MIN); + assert_eq!(offset, 8); + + let mut offset = offset_of!(TestStruct, b); + assert_eq!(offset, 8); + assert_eq!(*read_ptr_at::(&buf, &mut offset), usize::MAX); + assert_eq!(offset, 16); + + let mut offset = offset_of!(TestStruct, c); + assert_eq!(offset, 16); + assert_eq!(*read_ptr_at::(&buf, &mut offset), i64::MIN); + assert_eq!(offset, 24); + + let mut offset = offset_of!(TestStruct, d); + assert_eq!(offset, 24); + assert_eq!(*read_ptr_at::(&buf, &mut offset), u64::MAX); + assert_eq!(offset, 32); + + let mut offset = offset_of!(TestStruct, e); + assert_eq!(offset, 32); + assert_eq!(*read_ptr_at::(&buf, &mut offset), i32::MIN); + assert_eq!(offset, 36); + + let mut offset = offset_of!(TestStruct, f); + assert_eq!(offset, 36); + assert_eq!(*read_ptr_at::(&buf, &mut offset), u32::MAX); + assert_eq!(offset, 40); + + let mut offset = offset_of!(TestStruct, g); + assert_eq!(offset, 40); + assert_eq!(*read_ptr_at::(&buf, &mut offset), i16::MIN); + assert_eq!(offset, 42); + + let mut offset = offset_of!(TestStruct, h); + assert_eq!(offset, 44); + assert_eq!(*read_ptr_at::(&buf, &mut offset), u16::MAX); + assert_eq!(offset, 46); + + let mut offset = offset_of!(TestStruct, i); + assert_eq!(offset, 48); + assert_eq!(*read_ptr_at::(&buf, &mut offset), i8::MIN); + assert_eq!(offset, 49); + + let mut offset = offset_of!(TestStruct, j); + assert_eq!(offset, 52); + assert_eq!(*read_ptr_at::(&buf, &mut offset), u8::MAX); + assert_eq!(offset, 53); + } + } + + #[test] + fn test_read_array_like_ptr_at() { + #[derive(Clone, Copy, Pod, Zeroable)] + #[repr(C)] + struct TestStruct { + a: [i64; 32], + b: [u64; 32], + } + + let mut buf = vec![0_u8; mem::size_of::()]; + let s = buf.as_mut_ptr() as *mut TestStruct; + + unsafe { + for (i, element) in (*s).a.iter_mut().enumerate() { + *element = -(i as i64); + } + for (i, element) in (*s).b.iter_mut().enumerate() { + *element = i as u64; + } + + let mut offset = offset_of!(TestStruct, a); + assert_eq!(offset, 0); + let ptr: *mut i64 = read_array_like_ptr_at(&buf, &mut offset, 32); + for i in 0..32 { + assert_eq!(*(ptr.add(i)), -(i as i64)); + } + assert_eq!(offset, 256); + + let mut offset = offset_of!(TestStruct, b); + assert_eq!(offset, 256); + let ptr: *mut u64 = read_array_like_ptr_at(&buf, &mut offset, 32); + for i in 0..32 { + assert_eq!(*(ptr.add(i)), i as u64); + } + assert_eq!(offset, 512); + } + } + + #[test] + fn test_read_array_like_ptr_at_mut() { + #[derive(Clone, Copy, Pod, Zeroable)] + #[repr(C)] + struct TestStruct { + a: [i64; 32], + b: [u64; 32], + } + + let mut buf = vec![0_u8; mem::size_of::()]; + let s = buf.as_mut_ptr() as *mut TestStruct; + + unsafe { + for (i, element) in (*s).a.iter_mut().enumerate() { + *element = -(i as i64); + } + for (i, element) in (*s).b.iter_mut().enumerate() { + *element = i as u64; + } + + let mut offset = offset_of!(TestStruct, a); + assert_eq!(offset, 0); + let ptr: *mut i64 = read_array_like_ptr_at_mut(&mut buf, &mut offset, 32); + for i in 0..32 { + assert_eq!(*(ptr.add(i)), -(i as i64)); + } + assert_eq!(offset, 256); + + let mut offset = offset_of!(TestStruct, b); + assert_eq!(offset, 256); + let ptr: *mut u64 = read_array_like_ptr_at_mut(&mut buf, &mut offset, 32); + for i in 0..32 { + assert_eq!(*(ptr.add(i)), i as u64); + } + assert_eq!(offset, 512); + } + } + + #[test] + fn test_write_at() { + #[derive(Clone, Copy, Pod, Zeroable)] + #[repr(C)] + struct TestStruct { + a: isize, + b: usize, + c: i64, + d: u64, + e: i32, + f: u32, + g: i16, + _padding_1: [u8; 2], + h: u16, + _padding_2: [u8; 2], + i: i8, + _padding_3: [i8; 3], + j: u8, + _padding_4: [i8; 3], + } + + let mut buf = vec![0_u8; mem::size_of::()]; + + let a: isize = isize::MIN; + let b: usize = usize::MAX; + let c: i64 = i64::MIN; + let d: u64 = u64::MAX; + let e: i32 = i32::MIN; + let f: u32 = u32::MAX; + let g: i16 = i16::MIN; + let h: u16 = u16::MAX; + let i: i8 = i8::MIN; + let j: u8 = u8::MAX; + + let mut offset = offset_of!(TestStruct, a); + assert_eq!(offset, 0); + write_at::(&mut buf, &a.to_le_bytes(), &mut offset); + assert_eq!(offset, 8); + + let mut offset = offset_of!(TestStruct, b); + assert_eq!(offset, 8); + write_at::(&mut buf, &b.to_le_bytes(), &mut offset); + assert_eq!(offset, 16); + + let mut offset = offset_of!(TestStruct, c); + assert_eq!(offset, 16); + write_at::(&mut buf, &c.to_le_bytes(), &mut offset); + assert_eq!(offset, 24); + + let mut offset = offset_of!(TestStruct, d); + assert_eq!(offset, 24); + write_at::(&mut buf, &d.to_le_bytes(), &mut offset); + assert_eq!(offset, 32); + + let mut offset = offset_of!(TestStruct, e); + assert_eq!(offset, 32); + write_at::(&mut buf, &e.to_le_bytes(), &mut offset); + assert_eq!(offset, 36); + + let mut offset = offset_of!(TestStruct, f); + assert_eq!(offset, 36); + write_at::(&mut buf, &f.to_le_bytes(), &mut offset); + assert_eq!(offset, 40); + + let mut offset = offset_of!(TestStruct, g); + assert_eq!(offset, 40); + write_at::(&mut buf, &g.to_le_bytes(), &mut offset); + assert_eq!(offset, 42); + + let mut offset = offset_of!(TestStruct, h); + assert_eq!(offset, 44); + write_at::(&mut buf, &h.to_le_bytes(), &mut offset); + assert_eq!(offset, 46); + + let mut offset = offset_of!(TestStruct, i); + assert_eq!(offset, 48); + write_at::(&mut buf, &i.to_le_bytes(), &mut offset); + assert_eq!(offset, 49); + + let mut offset = offset_of!(TestStruct, j); + assert_eq!(offset, 52); + write_at::(&mut buf, &j.to_le_bytes(), &mut offset); + assert_eq!(offset, 53); + + let s = buf.as_mut_ptr() as *mut TestStruct; + + unsafe { + assert_eq!((*s).a, a); + assert_eq!((*s).b, b); + assert_eq!((*s).c, c); + assert_eq!((*s).d, d); + assert_eq!((*s).e, e); + assert_eq!((*s).f, f); + assert_eq!((*s).g, g); + assert_eq!((*s).h, h); + assert_eq!((*s).i, i); + assert_eq!((*s).j, j); + } + } +} diff --git a/program-libs/verifier/Cargo.toml b/program-libs/verifier/Cargo.toml index 809ba950ce..1b0b1f2003 100644 --- a/program-libs/verifier/Cargo.toml +++ b/program-libs/verifier/Cargo.toml @@ -11,8 +11,8 @@ solana = ["solana-program"] [dependencies] groth16-solana = "0.0.3" -thiserror = "1.0" -borsh = "0.10" +thiserror = { workspace = true } +borsh = { workspace = true } solana-program = { workspace = true, optional = true } light-utils = { workspace = true } @@ -20,7 +20,7 @@ light-utils = { workspace = true } tokio = { workspace = true } reqwest = { version = "0.11.24", features = ["json", "rustls-tls"] } light-prover-client = { workspace = true } -serial_test = "3.2.0" +serial_test = { workspace = true } [lints.rust.unexpected_cfgs] level = "allow" diff --git a/program-libs/zero-copy/Cargo.toml b/program-libs/zero-copy/Cargo.toml index 78d66d140f..1014692265 100644 --- a/program-libs/zero-copy/Cargo.toml +++ b/program-libs/zero-copy/Cargo.toml @@ -20,4 +20,4 @@ zerocopy = {version="0.8.14"} [dev-dependencies] rand = "0.8" num-traits.workspace = true -zerocopy = {version="0.8.14", features=["derive"]} +zerocopy = {version="0.8.14", features=["derive"]} \ No newline at end of file diff --git a/program-tests/account-compression-test/Cargo.toml b/program-tests/account-compression-test/Cargo.toml index 7092284608..b5965a7dd1 100644 --- a/program-tests/account-compression-test/Cargo.toml +++ b/program-tests/account-compression-test/Cargo.toml @@ -20,15 +20,15 @@ default = ["custom-heap"] [dependencies] [dev-dependencies] -ark-bn254 = "0.4.0" -ark-ff = "0.4.0" +ark-bn254 = { workspace = true } +ark-ff = { workspace = true } solana-program-test = { workspace = true} light-test-utils = { workspace = true, features=["devenv"] } light-program-test = { workspace = true, features = ["devenv"] } light-client = { workspace = true } tokio = { workspace = true } light-prover-client = {workspace = true } -num-bigint = "0.4.6" +num-bigint = { workspace = true } anchor-spl = { workspace = true } anchor-lang = { workspace = true } account-compression = { workspace = true } @@ -40,9 +40,9 @@ light-merkle-tree-reference = {workspace = true} light-bounded-vec = {workspace = true} light-utils = {workspace = true} light-verifier = {workspace = true} -rand = "0.8" +rand = { workspace = true } solana-sdk = { workspace = true } -serial_test = "3.1.1" +serial_test = { workspace = true } light-bloom-filter = { workspace = true } light-batched-merkle-tree = { workspace = true } light-merkle-tree-metadata = { workspace = true } \ No newline at end of file diff --git a/program-tests/compressed-token-test/Cargo.toml b/program-tests/compressed-token-test/Cargo.toml index cd05bd8122..77f203d912 100644 --- a/program-tests/compressed-token-test/Cargo.toml +++ b/program-tests/compressed-token-test/Cargo.toml @@ -36,5 +36,5 @@ tokio = { workspace = true } light-prover-client = {workspace = true } spl-token = { workspace = true } anchor-spl = { workspace = true } -rand = "0.8" +rand = { workspace = true } serial_test = { workspace = true } \ No newline at end of file diff --git a/program-tests/e2e-test/Cargo.toml b/program-tests/e2e-test/Cargo.toml index 421c1bcd75..6c80131ab8 100644 --- a/program-tests/e2e-test/Cargo.toml +++ b/program-tests/e2e-test/Cargo.toml @@ -18,33 +18,15 @@ custom-heap = [] default = ["custom-heap"] [dependencies] -anchor-lang = { workspace = true } -light-compressed-token = { workspace = true } light-registry = { workspace = true } -light-system-program = { workspace = true } -account-compression = { workspace = true } -light-hasher = {workspace = true} -light-concurrent-merkle-tree = {workspace = true} -light-indexed-merkle-tree = {workspace = true} -light-merkle-tree-reference = {workspace = true} -light-utils = {workspace = true} -light-verifier = {workspace = true} [target.'cfg(not(target_os = "solana"))'.dependencies] solana-sdk = { workspace = true } solana-client = { workspace = true } [dev-dependencies] -solana-program-test = { workspace = true } light-test-utils = { workspace = true, features=["devenv"] } light-program-test = { workspace = true, features = ["devenv"] } -reqwest = "0.11.26" tokio = { workspace = true } light-prover-client = {workspace = true } -num-bigint = "0.4.6" -num-traits = "0.2.19" -spl-token = { workspace = true } -anchor-spl = { workspace = true } -rand = "0.8" -spl-concurrent-merkle-tree = { version = "0.2.0", default-features = false} light-batched-merkle-tree = { workspace = true } diff --git a/program-tests/merkle-tree/Cargo.toml b/program-tests/merkle-tree/Cargo.toml index f548b34aff..46e9e483f4 100644 --- a/program-tests/merkle-tree/Cargo.toml +++ b/program-tests/merkle-tree/Cargo.toml @@ -9,9 +9,5 @@ edition = "2021" [dependencies] light-bounded-vec = { workspace = true } light-hasher = { workspace = true } -thiserror = "1.0" -log = "0.4.20" -num-bigint = "0.4" - -[dev-dependencies] -hex = "0.4" \ No newline at end of file +thiserror = { workspace = true } +num-bigint = { workspace = true } diff --git a/program-tests/system-cpi-test/Cargo.toml b/program-tests/system-cpi-test/Cargo.toml index 526d00244d..d3d31929c9 100644 --- a/program-tests/system-cpi-test/Cargo.toml +++ b/program-tests/system-cpi-test/Cargo.toml @@ -35,18 +35,13 @@ light-merkle-tree-metadata = { workspace = true } solana-sdk = { workspace = true } [dev-dependencies] -solana-program-test = { workspace = true } light-client = { workspace = true } light-sdk = { workspace = true } light-program-test = { workspace = true, features=["devenv"]} light-test-utils = { workspace = true, features=["devenv"] } -reqwest = "0.11.26" tokio = { workspace = true } light-prover-client = { workspace = true } light-verifier = { workspace = true } -num-bigint = "0.4.6" -num-traits = "0.2.19" -spl-token = { workspace = true } anchor-spl = { workspace = true } serial_test = { workspace = true } diff --git a/program-tests/system-test/Cargo.toml b/program-tests/system-test/Cargo.toml index 8107f1a8b4..36c06dcb8b 100644 --- a/program-tests/system-test/Cargo.toml +++ b/program-tests/system-test/Cargo.toml @@ -38,6 +38,6 @@ solana-cli-output = { workspace = true } serde_json = "1.0.133" solana-sdk = { workspace = true } quote.workspace = true -serial_test = "3.1.1" +serial_test = { workspace = true } light-batched-merkle-tree = { workspace = true } light-merkle-tree-metadata = { workspace = true } \ No newline at end of file diff --git a/program-tests/utils/Cargo.toml b/program-tests/utils/Cargo.toml index 27c871923f..b654d5b093 100644 --- a/program-tests/utils/Cargo.toml +++ b/program-tests/utils/Cargo.toml @@ -13,45 +13,29 @@ devenv = [] [dependencies] anchor-lang = { workspace = true } anchor-spl = { workspace = true } -anyhow = "1.0" -ark-ff = "0.4" -light-hash-set = { workspace=true } -num-bigint = "0.4" -num-traits = "0.2" +num-bigint = { workspace = true } +num-traits = { workspace = true } solana-program-test = { workspace = true } solana-sdk = { workspace = true } -solana-client = { workspace = true } -thiserror = "1.0" -light-macros = { workspace = true } +thiserror = { workspace = true } account-compression = { workspace = true } light-compressed-token = { workspace = true } light-system-program = { workspace = true } light-registry = { workspace = true } spl-token = { workspace = true, features = ["no-entrypoint"] } -solana-transaction-status = { workspace = true } -tokio = { workspace = true } light-prover-client = { workspace = true } -reqwest = "0.11.26" light-hasher = { workspace = true } light-merkle-tree-reference = { workspace = true } light-concurrent-merkle-tree = { workspace = true } light-indexed-merkle-tree = { workspace = true } -light-verifier = { workspace = true } light-utils = { workspace = true } light-program-test = { workspace = true } forester-utils = { workspace = true } light-sdk = { workspace = true } -memoffset = "0.9.1" -rand = "0.8" -photon-api = { workspace = true } -log = "0.4" -serde = { version = "1.0.197", features = ["derive"] } -async-trait = "0.1.82" +rand = { workspace = true } +log = { workspace = true } light-client = { workspace = true } create-address-test-program = { workspace = true } spl-token-2022 = { workspace = true } light-batched-merkle-tree = { workspace = true } light-merkle-tree-metadata = { workspace = true } - -[dev-dependencies] -rand = "0.8" diff --git a/programs/account-compression/Cargo.toml b/programs/account-compression/Cargo.toml index c544077601..e143ed13f6 100644 --- a/programs/account-compression/Cargo.toml +++ b/programs/account-compression/Cargo.toml @@ -34,11 +34,8 @@ light-heap = { workspace = true, optional = true } light-concurrent-merkle-tree = { workspace = true, features = ["solana"] } light-indexed-merkle-tree = { workspace = true, features = ["solana"] } light-utils = { workspace = true, features = ["anchor"] } -light-bloom-filter = { workspace = true, features = ["solana"] } num-bigint = "0.4" -num-traits = "0.2.19" solana-security-txt = "1.1.0" -light-verifier = { workspace = true, features = ["solana"] } light-batched-merkle-tree = {workspace = true, features = ["solana"] } light-merkle-tree-metadata = {workspace = true, features = ["anchor"] } @@ -46,8 +43,5 @@ light-merkle-tree-metadata = {workspace = true, features = ["anchor"] } solana-sdk = { workspace = true } [dev-dependencies] -rand = "0.8.5" -light-prover-client = { workspace = true, features = ["gnark"] } +rand = { workspace = true } light-merkle-tree-reference = { workspace = true } -tokio = { version = "1.16.1" } -serial_test = "3.1.1" \ No newline at end of file diff --git a/programs/compressed-token/Cargo.toml b/programs/compressed-token/Cargo.toml index e7d4cbf94a..9674bbd741 100644 --- a/programs/compressed-token/Cargo.toml +++ b/programs/compressed-token/Cargo.toml @@ -26,7 +26,6 @@ idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"] anchor-lang = { workspace = true } anchor-spl = { workspace = true } spl-token = { workspace = true, features = ["no-entrypoint"]} -aligned-sized = { workspace = true } account-compression = { workspace = true, features = ["cpi", "no-idl"] } light-system-program = { workspace = true, features = ["cpi"] } solana-security-txt = "1.1.0" @@ -38,7 +37,7 @@ spl-token-2022 = { workspace = true } solana-sdk = { workspace = true } [dev-dependencies] -rand = "0.8.5" +rand = { workspace = true } [lints.rust.unexpected_cfgs] level = "allow" diff --git a/programs/system/Cargo.toml b/programs/system/Cargo.toml index 705d70ebbc..2b84d7cb22 100644 --- a/programs/system/Cargo.toml +++ b/programs/system/Cargo.toml @@ -31,7 +31,6 @@ light-concurrent-merkle-tree = { workspace = true } light-indexed-merkle-tree = { workspace = true } account-compression = { workspace = true } light-utils = { workspace = true , features = ["anchor"]} -groth16-solana = "0.0.3" light-verifier = { workspace = true, features = ["solana"] } solana-security-txt = "1.1.0" light-batched-merkle-tree = {workspace = true, features = ["solana"] } @@ -40,7 +39,7 @@ light-batched-merkle-tree = {workspace = true, features = ["solana"] } solana-sdk = { workspace = true } [dev-dependencies] -rand = "0.8.5" +rand = { workspace = true } [lints.rust.unexpected_cfgs] diff --git a/prover/client/Cargo.toml b/prover/client/Cargo.toml index 4050fabd40..eb86a339c2 100644 --- a/prover/client/Cargo.toml +++ b/prover/client/Cargo.toml @@ -21,29 +21,29 @@ light-concurrent-merkle-tree = { workspace = true } light-bounded-vec = { workspace = true } light-utils = { workspace = true } # ark dependencies -ark-serialize = "0.4.2" -ark-bn254 = { version = "0.4" } -ark-std = { version = "0.4", default-features = false, features = ["parallel"] } +ark-serialize = { workspace = true } +ark-bn254 = { workspace = true } +ark-std = { workspace = true, default-features = false, features = ["parallel"] } light-batched-merkle-tree = { workspace = true } # solana groth16-solana = "0.0.3" solana-program = { workspace = true } -num-bigint = { version = "0.4.6", features = ["serde"] } +num-bigint = { workspace = true, features = ["serde"] } once_cell = "1.20" -thiserror = "1.0" -log = "0.4" -env_logger = "0.11.2" +thiserror = { workspace = true } +log = { workspace = true } +env_logger = { workspace = true } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.133" -num-traits = "0.2.19" +num-traits = { workspace = true } tokio = { workspace = true, optional = true } reqwest = { version = "0.11.24", features = ["json", "rustls-tls"], optional = true } sysinfo = "0.33" [dev-dependencies] -serial_test = "3.2.0" +serial_test = { workspace = true } [lints.rust.unexpected_cfgs] level = "allow" diff --git a/sdk-libs/client/Cargo.toml b/sdk-libs/client/Cargo.toml index 63849ee002..66dd9df838 100644 --- a/sdk-libs/client/Cargo.toml +++ b/sdk-libs/client/Cargo.toml @@ -40,5 +40,5 @@ light-program-test = { workspace = true } light-system-program = { workspace = true } light-compressed-token = { workspace = true } spl-token = { workspace = true } -rand = "0.8.5" +rand = { workspace = true } light-utils = { workspace = true } \ No newline at end of file diff --git a/sdk-libs/macros/Cargo.toml b/sdk-libs/macros/Cargo.toml index f7ce43426b..c23b6104dd 100644 --- a/sdk-libs/macros/Cargo.toml +++ b/sdk-libs/macros/Cargo.toml @@ -7,7 +7,6 @@ license = "Apache-2.0" edition = "2021" [dependencies] -bs58 = "0.5" proc-macro2 = { workspace = true } quote = { workspace = true } syn = { workspace = true } diff --git a/sdk-libs/photon-api/Cargo.toml b/sdk-libs/photon-api/Cargo.toml index 33d38c0db2..a9f39c1767 100644 --- a/sdk-libs/photon-api/Cargo.toml +++ b/sdk-libs/photon-api/Cargo.toml @@ -12,7 +12,6 @@ serde_derive = "^1.0" serde_with = "^3.9" serde_json = "^1.0" url = "^2.5" -uuid = { version = "^1.11", features = ["serde", "v4"] } [dependencies.reqwest] version = "^0.11" features = ["json", "multipart"] diff --git a/sdk-libs/sdk/Cargo.toml b/sdk-libs/sdk/Cargo.toml index 70ae8d8301..a829631313 100644 --- a/sdk-libs/sdk/Cargo.toml +++ b/sdk-libs/sdk/Cargo.toml @@ -28,7 +28,7 @@ legacy = ["account-compression", "light-system-program"] solana-program = { workspace = true } anchor-lang = { workspace = true } num-bigint = { workspace = true } -borsh = "0.10.0" +borsh = { workspace = true } light-macros = { workspace = true } light-sdk-macros = { workspace = true } @@ -44,4 +44,4 @@ solana-sdk = { workspace = true } [dev-dependencies] light-indexed-merkle-tree = { workspace = true } -num-bigint = "0.4.6" +num-bigint = { workspace = true } diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index ea7490c7f4..3dfb92b06d 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" [dependencies] account-compression = { workspace = true } anyhow = "1.0" -ark-bn254 = "0.4" -ark-ff = "0.4" +ark-bn254 = { workspace = true } +ark-ff = { workspace = true } clap = { version = "4", features = ["derive"] } groth16-solana = "0.0.3" light-concurrent-merkle-tree = { workspace = true } @@ -15,8 +15,8 @@ light-hash-set = { workspace = true } light-hasher = { workspace = true } light-indexed-merkle-tree = { workspace = true } light-utils = { workspace = true } -num-bigint = "0.4" -rand = "0.8" +num-bigint = { workspace = true } +rand = { workspace = true } quote = "1.0" sha2 = "0.10" solana-program = { workspace = true }