Force program address off the curve (bp #11323) (#11397)

* Force program address off the curve (#11323)

(cherry picked from commit 03263c850a)

* nudge

* trailing whitespace

Co-authored-by: Jack May <jack@solana.com>
Co-authored-by: Trent Nelson <trent@solana.com>
This commit is contained in:
mergify[bot]
2020-08-06 09:46:35 +00:00
committed by GitHub
parent 798a6db915
commit 1a9aa78129
14 changed files with 1184 additions and 969 deletions

View File

@@ -77,6 +77,9 @@ pub fn register_syscalls<'a>(
) -> Result<MemoryRegion, EbpfError<BPFError>> {
// Syscall function common across languages
vm.register_syscall_ex("abort", syscall_abort)?;
if invoke_context.is_cross_program_supported() {
vm.register_syscall_ex("sol_create_program_address", syscall_create_program_address)?;
}
{
let invoke_context = Rc::new(RefCell::new(invoke_context));
@@ -362,6 +365,36 @@ impl SyscallObject<BPFError> for SyscallSolAllocFree {
}
}
/// Create a program address
pub fn syscall_create_program_address(
seeds_addr: u64,
seeds_len: u64,
program_id_addr: u64,
address_addr: u64,
_arg5: u64,
ro_regions: &[MemoryRegion],
rw_regions: &[MemoryRegion],
) -> Result<u64, EbpfError<BPFError>> {
let untranslated_seeds = translate_slice!(&[&str], seeds_addr, seeds_len, ro_regions)?;
let seeds = untranslated_seeds
.iter()
.map(|untranslated_seed| {
translate_slice!(
u8,
untranslated_seed.as_ptr(),
untranslated_seed.len(),
ro_regions
)
})
.collect::<Result<Vec<_>, EbpfError<BPFError>>>()?;
let program_id = translate_type!(Pubkey, program_id_addr, rw_regions)?;
let new_address =
Pubkey::create_program_address(&seeds, program_id).map_err(SyscallError::BadSeeds)?;
let address = translate_slice_mut!(u8, address_addr, 32, ro_regions)?;
address.copy_from_slice(new_address.as_ref());
Ok(0)
}
// Cross-program invocation syscalls
pub type TranslatedAccounts<'a> = (Vec<Rc<RefCell<Account>>>, Vec<(&'a mut u64, &'a mut [u8])>);