Skip to content

Commit

Permalink
clean feature: libsecp256k1_0_5_upgrade_enabled (#34080)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry authored Nov 16, 2023
1 parent 34f5c68 commit 2573b7a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 56 deletions.
17 changes: 4 additions & 13 deletions programs/bpf_loader/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ use {
disable_fees_sysvar, enable_alt_bn128_compression_syscall, enable_alt_bn128_syscall,
enable_big_mod_exp_syscall, enable_partitioned_epoch_reward, enable_poseidon_syscall,
error_on_syscall_bpf_function_hash_collisions, last_restart_slot_sysvar,
libsecp256k1_0_5_upgrade_enabled, reject_callx_r10,
remaining_compute_units_syscall_enabled, stop_sibling_instruction_search_at_parent,
stop_truncating_strings_in_syscalls, switch_to_new_elf_parser,
reject_callx_r10, remaining_compute_units_syscall_enabled,
stop_sibling_instruction_search_at_parent, stop_truncating_strings_in_syscalls,
switch_to_new_elf_parser,
},
hash::{Hash, Hasher},
instruction::{
Expand Down Expand Up @@ -849,16 +849,7 @@ declare_builtin_function!(
let Ok(recovery_id) = libsecp256k1::RecoveryId::parse(adjusted_recover_id_val) else {
return Ok(Secp256k1RecoverError::InvalidRecoveryId.into());
};
let sig_parse_result = if invoke_context
.feature_set
.is_active(&libsecp256k1_0_5_upgrade_enabled::id())
{
libsecp256k1::Signature::parse_standard_slice(signature)
} else {
libsecp256k1::Signature::parse_overflowing_slice(signature)
};

let Ok(signature) = sig_parse_result else {
let Ok(signature) = libsecp256k1::Signature::parse_standard_slice(signature) else {
return Ok(Secp256k1RecoverError::InvalidSignature.into());
};

Expand Down
52 changes: 9 additions & 43 deletions sdk/src/secp256k1_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,7 @@
use {
crate::{
feature_set::{
libsecp256k1_0_5_upgrade_enabled, libsecp256k1_fail_on_bad_count,
libsecp256k1_fail_on_bad_count2, FeatureSet,
libsecp256k1_fail_on_bad_count, libsecp256k1_fail_on_bad_count2, FeatureSet,
},
instruction::Instruction,
precompiles::PrecompileError,
Expand Down Expand Up @@ -973,17 +972,10 @@ pub fn verify(
return Err(PrecompileError::InvalidSignature);
}

let sig_parse_result = if feature_set.is_active(&libsecp256k1_0_5_upgrade_enabled::id()) {
libsecp256k1::Signature::parse_standard_slice(
&signature_instruction[sig_start..sig_end],
)
} else {
libsecp256k1::Signature::parse_overflowing_slice(
&signature_instruction[sig_start..sig_end],
)
};

let signature = sig_parse_result.map_err(|_| PrecompileError::InvalidSignature)?;
let signature = libsecp256k1::Signature::parse_standard_slice(
&signature_instruction[sig_start..sig_end],
)
.map_err(|_| PrecompileError::InvalidSignature)?;

let recovery_id = libsecp256k1::RecoveryId::parse(signature_instruction[sig_end])
.map_err(|_| PrecompileError::InvalidRecoveryId)?;
Expand Down Expand Up @@ -1068,14 +1060,7 @@ pub mod test {
instruction_data[0] = num_signatures;
let writer = std::io::Cursor::new(&mut instruction_data[1..]);
bincode::serialize_into(writer, &offsets).unwrap();
let mut feature_set = FeatureSet::all_enabled();
feature_set
.active
.remove(&libsecp256k1_0_5_upgrade_enabled::id());
feature_set
.inactive
.insert(libsecp256k1_0_5_upgrade_enabled::id());

let feature_set = FeatureSet::all_enabled();
verify(&instruction_data, &[&[0u8; 100]], &feature_set)
}

Expand All @@ -1089,13 +1074,7 @@ pub mod test {
let writer = std::io::Cursor::new(&mut instruction_data[1..]);
bincode::serialize_into(writer, &offsets).unwrap();
instruction_data.truncate(instruction_data.len() - 1);
let mut feature_set = FeatureSet::all_enabled();
feature_set
.active
.remove(&libsecp256k1_0_5_upgrade_enabled::id());
feature_set
.inactive
.insert(libsecp256k1_0_5_upgrade_enabled::id());
let feature_set = FeatureSet::all_enabled();

assert_eq!(
verify(&instruction_data, &[&[0u8; 100]], &feature_set),
Expand Down Expand Up @@ -1224,13 +1203,7 @@ pub mod test {
instruction_data[0] = 0;
let writer = std::io::Cursor::new(&mut instruction_data[1..]);
bincode::serialize_into(writer, &offsets).unwrap();
let mut feature_set = FeatureSet::all_enabled();
feature_set
.active
.remove(&libsecp256k1_0_5_upgrade_enabled::id());
feature_set
.inactive
.insert(libsecp256k1_0_5_upgrade_enabled::id());
let feature_set = FeatureSet::all_enabled();

assert_eq!(
verify(&instruction_data, &[&[0u8; 100]], &feature_set),
Expand All @@ -1251,14 +1224,7 @@ pub mod test {
let message_arr = b"hello";
let mut secp_instruction = new_secp256k1_instruction(&secp_privkey, message_arr);
let mint_keypair = Keypair::new();
let mut feature_set = feature_set::FeatureSet::all_enabled();
feature_set
.active
.remove(&feature_set::libsecp256k1_0_5_upgrade_enabled::id());
feature_set
.inactive
.insert(feature_set::libsecp256k1_0_5_upgrade_enabled::id());
let feature_set = feature_set;
let feature_set = feature_set::FeatureSet::all_enabled();

let tx = Transaction::new_signed_with_payer(
&[secp_instruction.clone()],
Expand Down

0 comments on commit 2573b7a

Please sign in to comment.