solana-labs / solana

Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.
https://solanalabs.com
Apache License 2.0
13.02k stars 4.19k forks source link

Cross program invocation panics when allocating account #11341

Closed hendrikhofstadt closed 4 years ago

hendrikhofstadt commented 4 years ago

Problem

When allocating an account using a cross-program-invocation of SystemInstruction::CreateAccount the handler panics when trying to copy the newly created account's data to the original VM-owned account. This fails because then lengths of both do not match since at the start the program has a data of 0 len and the newly allocated size afterwards.

thread '<unnamed>' panicked at 'destination and source slices have different lengths', nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/macros/mod.rs:10:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1117
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1508
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:217
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:526
  11: rust_begin_unwind
             at src/libstd/panicking.rs:437
  12: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  13: core::panicking::panic
             at src/libcore/panicking.rs:50
  14: core::slice::<impl [T]>::clone_from_slice
             at nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/macros/mod.rs:10
  15: solana_bpf_loader_program::syscalls::call
             at programs/bpf_loader/src/syscalls.rs:862
  16: <solana_bpf_loader_program::syscalls::SyscallProcessInstructionRust as solana_rbpf::ebpf::SyscallObject<solana_bpf_loader_program::BPFError>>::call
             at programs/bpf_loader/src/syscalls.rs:544
  17: solana_rbpf::EbpfVm<E>::execute_program
             at registry/src/github.com-1ecc6299db9ec823/solana_rbpf-0.1.28/src/lib.rs:764
  18: solana_bpf_loader_program::process_instruction
             at programs/bpf_loader/src/lib.rs:214
  19: solana_bpf_loader_program
             at ./sdk/src/entrypoint_native.rs:191
  20: solana_runtime::native_loader::NativeLoader::process_instruction
             at runtime/src/native_loader.rs:144
  21: solana_runtime::message_processor::MessageProcessor::process_instruction
             at runtime/src/message_processor.rs:363
  22: solana_runtime::message_processor::MessageProcessor::execute_instruction
             at runtime/src/message_processor.rs:557
  23: solana_runtime::message_processor::MessageProcessor::process_message
             at runtime/src/message_processor.rs:581
  24: solana_runtime::bank::Bank::load_and_execute_transactions::{{closure}}
             at runtime/src/bank.rs:1767
aeyakovenko commented 4 years ago

Tag @jackcmay

jackcmay commented 4 years ago

@hendrikhofstadt Can you tell me what commit you are at, I'd like to confirm that exact point of failure

hendrikhofstadt commented 4 years ago

@jackcmay 0bc9bcc8

jackcmay commented 4 years ago

@hendrikhofstadt The lines numbers in the stack trace don't match correctly at the commit. I expect that the panic is happening here: https://github.com/solana-labs/solana/blob/f3e83c080a8f58f6aa7417234798bac4a046345b/programs/bpf_loader/src/syscalls.rs#L818

hendrikhofstadt commented 4 years ago

@jackcmay yes, i had some minor changes that changed line numbers

jackcmay commented 4 years ago

Fixed in #11649