Return an error from create_program_address syscall (#11658)
This commit is contained in:
@ -12,7 +12,7 @@ use solana_sdk::{
|
|||||||
info,
|
info,
|
||||||
program::{invoke, invoke_signed},
|
program::{invoke, invoke_signed},
|
||||||
program_error::ProgramError,
|
program_error::ProgramError,
|
||||||
pubkey::Pubkey,
|
pubkey::{Pubkey, PubkeyError},
|
||||||
system_instruction,
|
system_instruction,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -97,9 +97,15 @@ fn process_instruction(
|
|||||||
|
|
||||||
info!("Test create_program_address");
|
info!("Test create_program_address");
|
||||||
{
|
{
|
||||||
let address =
|
assert_eq!(
|
||||||
Pubkey::create_program_address(&[b"You pass butter", &[nonce1]], program_id)?;
|
&Pubkey::create_program_address(&[b"You pass butter", &[nonce1]], program_id)?,
|
||||||
assert_eq!(&address, accounts[DERIVED_KEY1_INDEX].key);
|
accounts[DERIVED_KEY1_INDEX].key
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
Pubkey::create_program_address(&[b"You pass butter"], &Pubkey::default())
|
||||||
|
.unwrap_err(),
|
||||||
|
PubkeyError::InvalidSeeds
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Test derived signers");
|
info!("Test derived signers");
|
||||||
|
@ -355,7 +355,8 @@ pub fn syscall_create_program_address(
|
|||||||
ro_regions: &[MemoryRegion],
|
ro_regions: &[MemoryRegion],
|
||||||
rw_regions: &[MemoryRegion],
|
rw_regions: &[MemoryRegion],
|
||||||
) -> Result<u64, EbpfError<BPFError>> {
|
) -> Result<u64, EbpfError<BPFError>> {
|
||||||
let untranslated_seeds = translate_slice!(&[&str], seeds_addr, seeds_len, ro_regions)?;
|
let untranslated_seeds = translate_slice!(&[&u8], seeds_addr, seeds_len, ro_regions)?;
|
||||||
|
|
||||||
let seeds = untranslated_seeds
|
let seeds = untranslated_seeds
|
||||||
.iter()
|
.iter()
|
||||||
.map(|untranslated_seed| {
|
.map(|untranslated_seed| {
|
||||||
@ -368,8 +369,12 @@ pub fn syscall_create_program_address(
|
|||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, EbpfError<BPFError>>>()?;
|
.collect::<Result<Vec<_>, EbpfError<BPFError>>>()?;
|
||||||
let program_id = translate_type!(Pubkey, program_id_addr, ro_regions)?;
|
let program_id = translate_type!(Pubkey, program_id_addr, ro_regions)?;
|
||||||
|
|
||||||
let new_address =
|
let new_address =
|
||||||
Pubkey::create_program_address(&seeds, program_id).map_err(SyscallError::BadSeeds)?;
|
match Pubkey::create_program_address(&seeds, program_id).map_err(SyscallError::BadSeeds) {
|
||||||
|
Ok(address) => address,
|
||||||
|
Err(_) => return Ok(1),
|
||||||
|
};
|
||||||
let address = translate_slice_mut!(u8, address_addr, 32, rw_regions)?;
|
let address = translate_slice_mut!(u8, address_addr, 32, rw_regions)?;
|
||||||
address.copy_from_slice(new_address.as_ref());
|
address.copy_from_slice(new_address.as_ref());
|
||||||
Ok(0)
|
Ok(0)
|
||||||
|
Reference in New Issue
Block a user