From 8705df5543df71ea405eeeec6570a2bf694d6efe Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Thu, 16 Jan 2025 04:42:20 +0400 Subject: [PATCH] extract big-mod-exp crate --- Cargo.lock | 17 ++++++++++ Cargo.toml | 1 + programs/sbf/Cargo.lock | 15 +++++++- sdk/big-mod-exp/Cargo.toml | 34 +++++++++++++++++++ .../big_mod_exp.rs => big-mod-exp/src/lib.rs} | 2 +- sdk/program/Cargo.toml | 1 + sdk/program/src/lib.rs | 3 +- svm/examples/Cargo.lock | 15 +++++++- 8 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 sdk/big-mod-exp/Cargo.toml rename sdk/{program/src/big_mod_exp.rs => big-mod-exp/src/lib.rs} (98%) diff --git a/Cargo.lock b/Cargo.lock index 76a375728a5342..400e15ae65b2b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6220,6 +6220,22 @@ dependencies = [ "solana-vote-program", ] +[[package]] +name = "solana-big-mod-exp" +version = "2.2.0" +dependencies = [ + "array-bytes", + "getrandom 0.2.10", + "js-sys", + "num-bigint 0.4.6", + "num-traits", + "serde", + "serde_derive", + "serde_json", + "solana-define-syscall", + "wasm-bindgen", +] + [[package]] name = "solana-bincode" version = "2.2.0" @@ -8226,6 +8242,7 @@ dependencies = [ "serde_json", "solana-account-info", "solana-atomic-u64", + "solana-big-mod-exp", "solana-bincode", "solana-borsh", "solana-clock", diff --git a/Cargo.toml b/Cargo.toml index 7e1fa38779f382..fcb61de74bc89f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -448,6 +448,7 @@ solana-banks-client = { path = "banks-client", version = "=2.2.0" } solana-banks-interface = { path = "banks-interface", version = "=2.2.0" } solana-banks-server = { path = "banks-server", version = "=2.2.0" } solana-bench-tps = { path = "bench-tps", version = "=2.2.0" } +solana-big-mod-exp = { path = "sdk/big-mod-exp", version = "=2.2.0" } solana-bincode = { path = "sdk/bincode", version = "=2.2.0" } solana-bloom = { path = "bloom", version = "=2.2.0" } solana-bn254 = { path = "curves/bn254", version = "=2.2.0" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 316adbe52bce1c..1da106ea8c5ee9 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "Inflector" @@ -5153,6 +5153,18 @@ dependencies = [ "tokio-serde", ] +[[package]] +name = "solana-big-mod-exp" +version = "2.2.0" +dependencies = [ + "getrandom 0.2.10", + "js-sys", + "num-bigint 0.4.6", + "num-traits", + "solana-define-syscall", + "wasm-bindgen", +] + [[package]] name = "solana-bincode" version = "2.2.0" @@ -6483,6 +6495,7 @@ dependencies = [ "serde_derive", "solana-account-info", "solana-atomic-u64", + "solana-big-mod-exp", "solana-bincode", "solana-borsh", "solana-clock", diff --git a/sdk/big-mod-exp/Cargo.toml b/sdk/big-mod-exp/Cargo.toml new file mode 100644 index 00000000000000..caf8d1792e291e --- /dev/null +++ b/sdk/big-mod-exp/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "solana-big-mod-exp" +description = "Solana big integer modular exponentiation" +documentation = "https://docs.rs/solana-big-mod-exp" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[target.'cfg(target_os = "solana")'.dependencies] +solana-define-syscall = { workspace = true } + +[target.'cfg(not(target_os = "solana"))'.dependencies] +num-bigint = { workspace = true } +num-traits = { workspace = true } + +[target.'cfg(target_arch = "wasm32")'.dependencies] +getrandom = { workspace = true, features = ["js", "wasm-bindgen"] } +js-sys = { workspace = true } +wasm-bindgen = { 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", "wasm32-unknown-unknown"] + +[lints] +workspace = true diff --git a/sdk/program/src/big_mod_exp.rs b/sdk/big-mod-exp/src/lib.rs similarity index 98% rename from sdk/program/src/big_mod_exp.rs rename to sdk/big-mod-exp/src/lib.rs index d3447436288206..69468545d55d7a 100644 --- a/sdk/program/src/big_mod_exp.rs +++ b/sdk/big-mod-exp/src/lib.rs @@ -46,7 +46,7 @@ pub fn big_mod_exp(base: &[u8], exponent: &[u8], modulus: &[u8]) -> Vec { modulus_len: modulus.len() as u64, }; unsafe { - crate::syscalls::sol_big_mod_exp( + solana_define_syscall::definitions::sol_big_mod_exp( ¶m as *const _ as *const u8, return_value.as_mut_slice() as *mut _ as *mut u8, ) diff --git a/sdk/program/Cargo.toml b/sdk/program/Cargo.toml index 7ac275aa4a70b9..745fb34a44ba58 100644 --- a/sdk/program/Cargo.toml +++ b/sdk/program/Cargo.toml @@ -28,6 +28,7 @@ serde_bytes = { workspace = true } serde_derive = { workspace = true } solana-account-info = { workspace = true, features = ["bincode"] } solana-atomic-u64 = { workspace = true } +solana-big-mod-exp = { workspace = true } solana-bincode = { workspace = true } solana-borsh = { workspace = true, optional = true } solana-clock = { workspace = true, features = ["serde", "sysvar"] } diff --git a/sdk/program/src/lib.rs b/sdk/program/src/lib.rs index 6ba5230302fd7b..6a454b8922ebda 100644 --- a/sdk/program/src/lib.rs +++ b/sdk/program/src/lib.rs @@ -471,7 +471,6 @@ extern crate self as solana_program; pub mod address_lookup_table; -pub mod big_mod_exp; pub mod blake3; pub mod bpf_loader; pub mod bpf_loader_deprecated; @@ -506,6 +505,8 @@ pub mod sysvar; pub mod vote; pub mod wasm; +#[deprecated(since = "2.2.0", note = "Use `solana-big-mod-exp` crate instead")] +pub use solana_big_mod_exp as big_mod_exp; #[cfg(feature = "borsh")] #[deprecated(since = "2.1.0", note = "Use `solana-borsh` crate instead")] pub use solana_borsh::deprecated as borsh; diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index ec51f4a2312caa..2a3f36192290af 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "Inflector" @@ -5014,6 +5014,18 @@ dependencies = [ "tokio-serde", ] +[[package]] +name = "solana-big-mod-exp" +version = "2.2.0" +dependencies = [ + "getrandom 0.2.15", + "js-sys", + "num-bigint 0.4.6", + "num-traits", + "solana-define-syscall", + "wasm-bindgen", +] + [[package]] name = "solana-bincode" version = "2.2.0" @@ -6313,6 +6325,7 @@ dependencies = [ "serde_derive", "solana-account-info", "solana-atomic-u64", + "solana-big-mod-exp", "solana-bincode", "solana-borsh", "solana-clock",