Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ALT_BN128_MULTIPLICATION_INPUT_LEN constant #3686

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions curves/bn254/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod consts {

/// Input length for the multiplication operation.
pub const ALT_BN128_MULTIPLICATION_INPUT_LEN: usize = 128;
pub const ALT_BN128_MULTIPLICATION_INPUT_LEN_FIX: usize = 96;
LStan marked this conversation as resolved.
Show resolved Hide resolved

/// Pair element length.
pub const ALT_BN128_PAIRING_ELEMENT_LEN: usize = 192;
Expand Down Expand Up @@ -198,12 +199,23 @@ mod target_arch {
}

pub fn alt_bn128_multiplication(input: &[u8]) -> Result<Vec<u8>, AltBn128Error> {
if input.len() > ALT_BN128_MULTIPLICATION_INPUT_LEN {
alt_bn128_apply_multiplication(input, ALT_BN128_MULTIPLICATION_INPUT_LEN_FIX)
}

pub fn alt_bn128_multiplication_128(input: &[u8]) -> Result<Vec<u8>, AltBn128Error> {
alt_bn128_apply_multiplication(input, ALT_BN128_MULTIPLICATION_INPUT_LEN)
}
LStan marked this conversation as resolved.
Show resolved Hide resolved

fn alt_bn128_apply_multiplication(
input: &[u8],
expected_length: usize,
) -> Result<Vec<u8>, AltBn128Error> {
if input.len() > expected_length {
return Err(AltBn128Error::InvalidInputData);
}

let mut input = input.to_vec();
input.resize(ALT_BN128_MULTIPLICATION_INPUT_LEN, 0);
input.resize(expected_length, 0);

let p: G1 = PodG1(
convert_endianness_64(&input[..64])
Expand Down
18 changes: 14 additions & 4 deletions programs/bpf_loader/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ 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,
alt_bn128_addition, alt_bn128_multiplication, alt_bn128_multiplication_128,
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_feature_set::{
Expand Down Expand Up @@ -1646,7 +1647,16 @@ declare_builtin_function!(

let calculation = match group_op {
ALT_BN128_ADD => alt_bn128_addition,
ALT_BN128_MUL => alt_bn128_multiplication,
ALT_BN128_MUL => {
let fix_alt_bn128_multiplication_input_length = invoke_context
.get_feature_set()
.is_active(&feature_set::fix_alt_bn128_multiplication_input_length::id());
if fix_alt_bn128_multiplication_input_length {
alt_bn128_multiplication
} else {
alt_bn128_multiplication_128
}
}
ALT_BN128_PAIRING => alt_bn128_pairing,
_ => {
return Err(SyscallError::InvalidAttribute.into());
Expand Down
5 changes: 5 additions & 0 deletions sdk/feature-set/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,10 @@ pub mod enable_alt_bn128_compression_syscall {
solana_pubkey::declare_id!("EJJewYSddEEtSZHiqugnvhQHiWyZKjkFDQASd7oKSagn");
}

pub mod fix_alt_bn128_multiplication_input_length {
solana_pubkey::declare_id!("bn2puAyxUx6JUabAxYdKdJ5QHbNNmKw8dCGuGCyRrFN");
}

pub mod enable_program_redeployment_cooldown {
solana_pubkey::declare_id!("J4HFT8usBxpcF63y46t1upYobJgChmKyZPm5uTBRg25Z");
}
Expand Down Expand Up @@ -1110,6 +1114,7 @@ lazy_static! {
(accounts_lt_hash::id(), "enables lattice-based accounts hash #3333"),
(enable_secp256r1_precompile::id(), "Enable secp256r1 precompile SIMD-0075"),
(migrate_stake_program_to_core_bpf::id(), "Migrate Stake program to Core BPF SIMD-0196 #3655"),
(fix_alt_bn128_multiplication_input_length::id(), "fix alt_bn128 multiplication input length #3686"),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me work on the SIMD. Once the SIMD is merged, let's plug the SIMD number in here.

/*************** ADD NEW FEATURES HERE ***************/
]
.iter()
Expand Down
Loading