diff --git a/Cargo.lock b/Cargo.lock index 1a7213a9fd9bef..b40731b9b6cdc7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5688,6 +5688,23 @@ dependencies = [ "solana-sdk", ] +[[package]] +name = "solana-bn254" +version = "2.1.0" +dependencies = [ + "ark-bn254", + "ark-ec", + "ark-ff", + "ark-serialize", + "array-bytes", + "bytemuck", + "serde", + "serde_derive", + "serde_json", + "solana-program", + "thiserror", +] + [[package]] name = "solana-bpf-loader-program" version = "2.1.0" @@ -5700,6 +5717,7 @@ dependencies = [ "memoffset 0.9.1", "rand 0.8.5", "scopeguard", + "solana-bn254", "solana-compute-budget", "solana-curve25519", "solana-log-collector", @@ -6798,10 +6816,6 @@ version = "2.1.0" dependencies = [ "anyhow", "arbitrary", - "ark-bn254", - "ark-ec", - "ark-ff", - "ark-serialize", "array-bytes", "assert_matches", "base64 0.22.1", @@ -7311,6 +7325,7 @@ dependencies = [ "sha2 0.10.8", "sha3 0.10.8", "siphasher", + "solana-bn254", "solana-decode-error", "solana-frozen-abi", "solana-frozen-abi-macro", diff --git a/Cargo.toml b/Cargo.toml index 9efe9428a10264..b34b95f2b3cb64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -336,6 +336,7 @@ solana-banks-interface = { path = "banks-interface", version = "=2.1.0" } solana-banks-server = { path = "banks-server", version = "=2.1.0" } solana-bench-tps = { path = "bench-tps", version = "=2.1.0" } solana-bloom = { path = "bloom", version = "=2.1.0" } +solana-bn254 = { path = "curves/bn254", version = "=2.1.0" } solana-bpf-loader-program = { path = "programs/bpf_loader", version = "=2.1.0" } solana-bucket-map = { path = "bucket_map", version = "=2.1.0" } agave-cargo-registry = { path = "cargo-registry", version = "=2.1.0" } diff --git a/curves/bn254/Cargo.toml b/curves/bn254/Cargo.toml new file mode 100644 index 00000000000000..7182ff53f95b45 --- /dev/null +++ b/curves/bn254/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "solana-bn254" +description = "Solana BN254" +documentation = "https://docs.rs/solana-bn254" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[dependencies] +bytemuck = { workspace = true, features = ["derive"] } +solana-program = { workspace = true } +thiserror = { workspace = true } + +[target.'cfg(not(target_os = "solana"))'.dependencies] +ark-bn254 = { workspace = true } +ark-ec = { workspace = true } +ark-ff = { workspace = true } +ark-serialize = { workspace = true } + +[dev-dependencies] +array-bytes = { workspace = true } +serde = { workspace = true } +serde_derive = { workspace = true } +serde_json = { workspace = true } diff --git a/sdk/program/src/alt_bn128/compression.rs b/curves/bn254/src/compression.rs similarity index 98% rename from sdk/program/src/alt_bn128/compression.rs rename to curves/bn254/src/compression.rs index 5bcbe06434172e..b284772fca01b6 100644 --- a/sdk/program/src/alt_bn128/compression.rs +++ b/curves/bn254/src/compression.rs @@ -1,5 +1,5 @@ pub mod prelude { - pub use crate::alt_bn128::compression::{ + pub use crate::compression::{ alt_bn128_compression_size::*, consts::*, target_arch::*, AltBn128CompressionError, }; } @@ -70,7 +70,7 @@ mod target_arch { use { super::*, - crate::alt_bn128::compression::alt_bn128_compression_size, + crate::compression::alt_bn128_compression_size, ark_serialize::{CanonicalDeserialize, CanonicalSerialize, Compress, Validate}, }; @@ -194,6 +194,7 @@ mod target_arch { super::*, alt_bn128_compression_size::{G1, G1_COMPRESSED, G2, G2_COMPRESSED}, prelude::*, + solana_program::syscalls, }; pub fn alt_bn128_g1_compress( @@ -201,7 +202,7 @@ mod target_arch { ) -> Result<[u8; G1_COMPRESSED], AltBn128CompressionError> { let mut result_buffer = [0; G1_COMPRESSED]; let result = unsafe { - crate::syscalls::sol_alt_bn128_compression( + syscalls::sol_alt_bn128_compression( ALT_BN128_G1_COMPRESS, input as *const _ as *const u8, input.len() as u64, @@ -218,7 +219,7 @@ mod target_arch { pub fn alt_bn128_g1_decompress(input: &[u8]) -> Result<[u8; G1], AltBn128CompressionError> { let mut result_buffer = [0; G1]; let result = unsafe { - crate::syscalls::sol_alt_bn128_compression( + syscalls::sol_alt_bn128_compression( ALT_BN128_G1_DECOMPRESS, input as *const _ as *const u8, input.len() as u64, @@ -237,7 +238,7 @@ mod target_arch { ) -> Result<[u8; G2_COMPRESSED], AltBn128CompressionError> { let mut result_buffer = [0; G2_COMPRESSED]; let result = unsafe { - crate::syscalls::sol_alt_bn128_compression( + syscalls::sol_alt_bn128_compression( ALT_BN128_G2_COMPRESS, input as *const _ as *const u8, input.len() as u64, @@ -256,7 +257,7 @@ mod target_arch { ) -> Result<[u8; G2], AltBn128CompressionError> { let mut result_buffer = [0; G2]; let result = unsafe { - crate::syscalls::sol_alt_bn128_compression( + syscalls::sol_alt_bn128_compression( ALT_BN128_G2_DECOMPRESS, input as *const _ as *const u8, input.len() as u64, @@ -275,7 +276,7 @@ mod target_arch { mod tests { use { super::*, - crate::alt_bn128::compression::target_arch::convert_endianness, + crate::compression::target_arch::convert_endianness, ark_serialize::{CanonicalDeserialize, CanonicalSerialize, Compress, Validate}, std::ops::Neg, target_arch::{ diff --git a/sdk/program/src/alt_bn128/mod.rs b/curves/bn254/src/lib.rs similarity index 99% rename from sdk/program/src/alt_bn128/mod.rs rename to curves/bn254/src/lib.rs index c7e1d8e5d28250..e60417cde6b53d 100644 --- a/sdk/program/src/alt_bn128/mod.rs +++ b/curves/bn254/src/lib.rs @@ -1,10 +1,10 @@ pub mod compression; pub mod prelude { - pub use crate::alt_bn128::{consts::*, target_arch::*, AltBn128Error}; + pub use crate::{consts::*, target_arch::*, AltBn128Error}; } use { - bytemuck_derive::{Pod, Zeroable}, + bytemuck::{Pod, Zeroable}, consts::*, thiserror::Error, }; @@ -305,14 +305,15 @@ mod target_arch { #[cfg(target_os = "solana")] mod target_arch { - use super::*; + use {super::*, solana_program::syscalls}; + pub fn alt_bn128_addition(input: &[u8]) -> Result, AltBn128Error> { if input.len() > ALT_BN128_ADDITION_INPUT_LEN { return Err(AltBn128Error::InvalidInputData); } let mut result_buffer = [0; ALT_BN128_ADDITION_OUTPUT_LEN]; let result = unsafe { - crate::syscalls::sol_alt_bn128_group_op( + syscalls::sol_alt_bn128_group_op( ALT_BN128_ADD, input as *const _ as *const u8, input.len() as u64, @@ -332,7 +333,7 @@ mod target_arch { } let mut result_buffer = [0u8; ALT_BN128_POINT_SIZE]; let result = unsafe { - crate::syscalls::sol_alt_bn128_group_op( + syscalls::sol_alt_bn128_group_op( ALT_BN128_MUL, input as *const _ as *const u8, input.len() as u64, @@ -356,7 +357,7 @@ mod target_arch { } let mut result_buffer = [0u8; 32]; let result = unsafe { - crate::syscalls::sol_alt_bn128_group_op( + syscalls::sol_alt_bn128_group_op( ALT_BN128_PAIRING, input as *const _ as *const u8, input.len() as u64, @@ -374,7 +375,7 @@ mod target_arch { #[cfg(test)] mod tests { use { - crate::alt_bn128::{prelude::*, PodG1}, + crate::{prelude::*, PodG1}, ark_bn254::g1::G1Affine, ark_ec::AffineRepr, ark_serialize::{CanonicalSerialize, Compress}, diff --git a/programs/bpf_loader/Cargo.toml b/programs/bpf_loader/Cargo.toml index 82789e15d43498..219a60c87cfa5e 100644 --- a/programs/bpf_loader/Cargo.toml +++ b/programs/bpf_loader/Cargo.toml @@ -15,6 +15,7 @@ byteorder = { workspace = true } libsecp256k1 = { workspace = true } log = { workspace = true } scopeguard = { workspace = true } +solana-bn254 = { workspace = true } solana-compute-budget = { workspace = true } solana-curve25519 = { workspace = true } solana-log-collector = { workspace = true } @@ -43,4 +44,7 @@ name = "solana_bpf_loader_program" targets = ["x86_64-unknown-linux-gnu"] [features] -shuttle-test = ["solana-type-overrides/shuttle-test", "solana-program-runtime/shuttle-test"] +shuttle-test = [ + "solana-type-overrides/shuttle-test", + "solana-program-runtime/shuttle-test", +] diff --git a/programs/bpf_loader/src/syscalls/mod.rs b/programs/bpf_loader/src/syscalls/mod.rs index 84627033323b66..fbd176166cde6e 100644 --- a/programs/bpf_loader/src/syscalls/mod.rs +++ b/programs/bpf_loader/src/syscalls/mod.rs @@ -12,6 +12,11 @@ pub use self::{ }; #[allow(deprecated)] use { + solana_bn254::prelude::{ + alt_bn128_addition, alt_bn128_multiplication, alt_bn128_pairing, AltBn128Error, + ALT_BN128_ADDITION_OUTPUT_LEN, ALT_BN128_MULTIPLICATION_OUTPUT_LEN, + ALT_BN128_PAIRING_ELEMENT_LEN, ALT_BN128_PAIRING_OUTPUT_LEN, + }, solana_compute_budget::compute_budget::ComputeBudget, solana_log_collector::{ic_logger_msg, ic_msg}, solana_poseidon as poseidon, @@ -24,11 +29,6 @@ use { }, solana_sdk::{ account_info::AccountInfo, - alt_bn128::prelude::{ - alt_bn128_addition, alt_bn128_multiplication, alt_bn128_pairing, AltBn128Error, - ALT_BN128_ADDITION_OUTPUT_LEN, ALT_BN128_MULTIPLICATION_OUTPUT_LEN, - ALT_BN128_PAIRING_ELEMENT_LEN, ALT_BN128_PAIRING_OUTPUT_LEN, - }, big_mod_exp::{big_mod_exp, BigModExpParams}, blake3, bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, entrypoint::{BPF_ALIGN_OF_U128, MAX_PERMITTED_DATA_INCREASE, SUCCESS}, @@ -1572,7 +1572,7 @@ declare_builtin_function!( _arg5: u64, memory_mapping: &mut MemoryMapping, ) -> Result { - use solana_sdk::alt_bn128::prelude::{ALT_BN128_ADD, ALT_BN128_MUL, ALT_BN128_PAIRING}; + use solana_bn254::prelude::{ALT_BN128_ADD, ALT_BN128_MUL, ALT_BN128_PAIRING}; let budget = invoke_context.get_compute_budget(); let (cost, output): (u64, usize) = match group_op { ALT_BN128_ADD => ( @@ -1839,7 +1839,7 @@ declare_builtin_function!( _arg5: u64, memory_mapping: &mut MemoryMapping, ) -> Result { - use solana_sdk::alt_bn128::compression::prelude::{ + use solana_bn254::compression::prelude::{ alt_bn128_g1_compress, alt_bn128_g1_decompress, alt_bn128_g2_compress, alt_bn128_g2_decompress, ALT_BN128_G1_COMPRESS, ALT_BN128_G1_DECOMPRESS, ALT_BN128_G2_COMPRESS, ALT_BN128_G2_DECOMPRESS, G1, G1_COMPRESSED, G2, G2_COMPRESSED, diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 13e302254999ab..36b292d71c2142 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -4634,6 +4634,19 @@ dependencies = [ "solana-sdk", ] +[[package]] +name = "solana-bn254" +version = "2.1.0" +dependencies = [ + "ark-bn254", + "ark-ec", + "ark-ff", + "ark-serialize", + "bytemuck", + "solana-program", + "thiserror", +] + [[package]] name = "solana-bpf-loader-program" version = "2.1.0" @@ -4643,6 +4656,7 @@ dependencies = [ "libsecp256k1 0.6.0", "log", "scopeguard", + "solana-bn254", "solana-compute-budget", "solana-curve25519", "solana-log-collector", @@ -5285,10 +5299,6 @@ dependencies = [ name = "solana-program" version = "2.1.0" dependencies = [ - "ark-bn254", - "ark-ec", - "ark-ff", - "ark-serialize", "base64 0.22.1", "bincode", "bitflags 2.6.0", @@ -5724,6 +5734,7 @@ name = "solana-sbf-rust-alt-bn128" version = "2.1.0" dependencies = [ "array-bytes", + "solana-bn254", "solana-program", ] @@ -5732,6 +5743,7 @@ name = "solana-sbf-rust-alt-bn128-compression" version = "2.1.0" dependencies = [ "array-bytes", + "solana-bn254", "solana-program", ] @@ -6162,6 +6174,7 @@ dependencies = [ "sha2 0.10.8", "sha3 0.10.8", "siphasher", + "solana-bn254", "solana-decode-error", "solana-program", "solana-sanitize", diff --git a/programs/sbf/Cargo.toml b/programs/sbf/Cargo.toml index 111beed9b0ace2..e61318bd85f962 100644 --- a/programs/sbf/Cargo.toml +++ b/programs/sbf/Cargo.toml @@ -27,6 +27,7 @@ serde_derive = "1.0.112" # must match the serde version, see https://github.com/ serde_json = "1.0.56" solana-account-decoder = { path = "../../account-decoder", version = "=2.1.0" } solana-accounts-db = { path = "../../accounts-db", version = "=2.1.0" } +solana-bn254 = { path = "../../curves/bn254", version = "=2.1.0" } solana-bpf-loader-program = { path = "../bpf_loader", version = "=2.1.0" } solana-cli-output = { path = "../../cli-output", version = "=2.1.0" } solana-compute-budget = { path = "../../compute-budget", version = "=2.1.0" } diff --git a/programs/sbf/rust/alt_bn128/Cargo.toml b/programs/sbf/rust/alt_bn128/Cargo.toml index f80c24bf4b2f3f..03e523e58b9797 100644 --- a/programs/sbf/rust/alt_bn128/Cargo.toml +++ b/programs/sbf/rust/alt_bn128/Cargo.toml @@ -10,6 +10,7 @@ edition = { workspace = true } [dependencies] array-bytes = { workspace = true } +solana-bn254 = { workspace = true } solana-program = { workspace = true } [lib] diff --git a/programs/sbf/rust/alt_bn128/src/lib.rs b/programs/sbf/rust/alt_bn128/src/lib.rs index 54a3c1fd29a3e5..7a546dc248fba3 100644 --- a/programs/sbf/rust/alt_bn128/src/lib.rs +++ b/programs/sbf/rust/alt_bn128/src/lib.rs @@ -1,9 +1,9 @@ //! Alt_bn128 Syscalls tests extern crate solana_program; -use solana_program::{ - alt_bn128::prelude::{alt_bn128_addition, alt_bn128_multiplication, alt_bn128_pairing}, - custom_heap_default, custom_panic_default, msg, +use { + solana_bn254::prelude::{alt_bn128_addition, alt_bn128_multiplication, alt_bn128_pairing}, + solana_program::{custom_heap_default, custom_panic_default, msg}, }; fn alt_bn128_addition_test() { diff --git a/programs/sbf/rust/alt_bn128_compression/Cargo.toml b/programs/sbf/rust/alt_bn128_compression/Cargo.toml index 53fb783d9981c4..7f80554f592e31 100644 --- a/programs/sbf/rust/alt_bn128_compression/Cargo.toml +++ b/programs/sbf/rust/alt_bn128_compression/Cargo.toml @@ -10,6 +10,7 @@ edition = { workspace = true } [dependencies] array-bytes = { workspace = true } +solana-bn254 = { workspace = true } solana-program = { workspace = true } [lib] diff --git a/programs/sbf/rust/alt_bn128_compression/src/lib.rs b/programs/sbf/rust/alt_bn128_compression/src/lib.rs index 7545788fc3cf4a..a5ca6645142ec3 100644 --- a/programs/sbf/rust/alt_bn128_compression/src/lib.rs +++ b/programs/sbf/rust/alt_bn128_compression/src/lib.rs @@ -1,12 +1,12 @@ //! Alt_bn128 compression Syscalls tests extern crate solana_program; -use solana_program::{ - alt_bn128::compression::prelude::{ +use { + solana_bn254::compression::prelude::{ alt_bn128_g1_compress, alt_bn128_g1_decompress, alt_bn128_g2_compress, alt_bn128_g2_decompress, }, - custom_heap_default, custom_panic_default, msg, + solana_program::{custom_heap_default, custom_panic_default, msg}, }; fn alt_bn128_compression_g1() { diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 00f8f754ec1fd4..fcc164c0e86793 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -17,8 +17,8 @@ edition = { workspace = true } program = [] default = [ - "borsh", - "full" # functionality that is not compatible or needed for on-chain programs + "borsh", + "full", # functionality that is not compatible or needed for on-chain programs ] full = [ "byteorder", @@ -35,14 +35,12 @@ full = [ "digest", ] borsh = ["dep:borsh", "solana-program/borsh", "solana-secp256k1-recover/borsh"] -dev-context-only-utils = [ - "qualifier_attr" -] +dev-context-only-utils = ["qualifier_attr"] frozen-abi = [ - "dep:solana-frozen-abi", - "dep:solana-frozen-abi-macro", - "solana-program/frozen-abi", - "solana-short-vec/frozen-abi" + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "solana-program/frozen-abi", + "solana-short-vec/frozen-abi", ] [dependencies] @@ -59,9 +57,12 @@ derivation-path = { workspace = true } digest = { workspace = true, optional = true } ed25519-dalek = { workspace = true, optional = true } ed25519-dalek-bip32 = { workspace = true, optional = true } -generic-array = { workspace = true, features = ["serde", "more_lengths"], optional = true } +generic-array = { workspace = true, features = [ + "serde", + "more_lengths", +], optional = true } hmac = { workspace = true } -itertools = { workspace = true } +itertools = { workspace = true } lazy_static = { workspace = true } libsecp256k1 = { workspace = true, optional = true, features = ["hmac"] } log = { workspace = true } @@ -80,6 +81,7 @@ serde_with = { workspace = true, features = ["macros"] } sha2 = { workspace = true } sha3 = { workspace = true, optional = true } siphasher = { workspace = true } +solana-bn254 = { workspace = true } solana-decode-error = { workspace = true } solana-frozen-abi = { workspace = true, optional = true } solana-frozen-abi-macro = { workspace = true, optional = true } diff --git a/sdk/program/Cargo.toml b/sdk/program/Cargo.toml index 87ea38d7be0801..64aa7dff559a0c 100644 --- a/sdk/program/Cargo.toml +++ b/sdk/program/Cargo.toml @@ -9,7 +9,7 @@ repository = { workspace = true } homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } -rust-version = "1.75.0" # solana platform-tools rust version +rust-version = "1.75.0" # solana platform-tools rust version [dependencies] bincode = { workspace = true } @@ -52,10 +52,6 @@ getrandom = { workspace = true, features = ["custom"] } solana-define-syscall = { workspace = true } [target.'cfg(not(target_os = "solana"))'.dependencies] -ark-bn254 = { workspace = true } -ark-ec = { workspace = true } -ark-ff = { workspace = true } -ark-serialize = { workspace = true } base64 = { workspace = true, features = ["alloc", "std"] } bitflags = { workspace = true } curve25519-dalek = { workspace = true } diff --git a/sdk/program/src/lib.rs b/sdk/program/src/lib.rs index 8e9fdfb38c68ea..fd8da928c3e5bb 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 account_info; pub mod address_lookup_table; -pub mod alt_bn128; pub mod big_mod_exp; pub mod blake3; #[cfg(feature = "borsh")] diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 2d2a98a5c2864a..95a9b880ff14a1 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -46,11 +46,11 @@ 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, alt_bn128, 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, + 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_memory, program_option, program_pack, rent, secp256k1_program, serde_varint, serialize_utils, slot_hashes, slot_history, stable_layout, stake, stake_history, syscalls, @@ -109,6 +109,8 @@ pub mod transaction_context; pub mod transport; pub mod wasm; +#[deprecated(since = "2.1.0", note = "Use `solana-bn254` crate instead")] +pub use solana_bn254 as alt_bn128; #[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-sanitize` crate instead")]