Skip to content

svm::process_instructions crashes with "to_pubkey" error when including token_program or associated_token_program #376

@lappi

Description

@lappi

When using svm::process_instructions with IDL-based instruction format (program_idl + instruction_name), including token_program and associated_token_program accounts causes a panic in to_pubkey() with "range end index 32 out of range for slice of length 16".

Steps to Reproduce

  1. Create an Anchor program with an instruction that uses token_program and associated_token_program accounts
  2. Create a runbook using IDL-based instruction format:
action "initialize" "svm::process_instructions" {
    instruction {
        program_idl = variable.program.idl
        instruction_name = "initialize"
        instruction_args = []

        payer { public_key = "..." }
        pool { public_key = "..." }
        token_a_mint { public_key = "..." }
        token_b_mint { public_key = "..." }
        pool_token_a_account { public_key = "..." }
        pool_token_b_account { public_key = "..." }
        system_program { public_key = "11111111111111111111111111111111" }                       // causes crash
        token_program { public_key = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" }             // causes crash
        associated_token_program { public_key = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" } // causes crash
    }
    signers = [signer.payer]
}
  1. Run RUST_BACKTRACE=full surfpool run initialize --env localnet
  2. Get the error:
thread 'Runbook Runloop' panicked at /Users/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/txtx-addon-network-svm-types-0.3.13/src/lib.rs:425:46:
range end index 32 out of range for slice of length 16
stack backtrace:
   0:        0x104c9fce0 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h217270392019d164
   1:        0x104cc2af4 - core::fmt::write::he22fcab56bd3ec61
   2:        0x104c9b55c - std::io::Write::write_fmt::hb32eaafcfd249a19
   3:        0x104c9fb94 - std::sys::backtrace::BacktraceLock::print::h115149c0b879e5c3
   4:        0x104ca0d24 - std::panicking::default_hook::{{closure}}::h5c3a234feebd11a5
   5:        0x104ca0b60 - std::panicking::default_hook::ha0b223ccc4379930
   6:        0x104ca1854 - std::panicking::rust_panic_with_hook::h203f96c93e7ac62d
   7:        0x104ca1420 - std::panicking::begin_panic_handler::{{closure}}::hcc8f653f753c0254
   8:        0x104ca0194 - std::sys::backtrace::__rust_end_short_backtrace::h911de07218b69a6c
   9:        0x104ca10d8 - _rust_begin_unwind
  10:        0x104d520b4 - core::panicking::panic_fmt::h6a4014bec58fba4f
  11:        0x104cca880 - core::slice::index::slice_end_index_len_fail::do_panic::runtime::h385f2d9d99153a75
  12:        0x104d52460 - core::slice::index::slice_end_index_len_fail::ha150b75f771021fb
  13:        0x1047c4f38 - txtx_addon_network_svm_types::SvmValue::to_pubkey::ha8573c9dd01fca59
  14:        0x103be6fc0 - txtx_addon_network_svm::codec::instruction::parse_instructions_map::hc742ab6f09a17e6a
  15:        0x103b7fd70 - <txtx_addon_network_svm::commands::process_instructions::ProcessInstructions as txtx_addon_kit::types::commands::CommandImplementation>::check_signed_executability::h839bb4c7e2e15c01
  16:        0x1030e2ef8 - txtx_core::eval::evaluate_command_instance::{{closure}}::h230b56da04e6bec8
  17:        0x1030e7290 - txtx_core::eval::run_constructs_evaluation::{{closure}}::h378af2182e7c9cdb
  18:        0x1030dbbbc - txtx_core::start_supervised_runbook_runloop::{{closure}}::h7da4025d3c172c62
  19:        0x1030c6ccc - tokio::runtime::park::CachedParkThread::block_on::hfe937bcdb04bf2a5
  20:        0x103303bf4 - hiro_system_kit::tokio_helpers::nestable_block_on::h1297c59df700715b
  21:        0x102fd0b98 - std::sys::backtrace::__rust_begin_short_backtrace::hed8aeb1dfaadd841
  22:        0x10330fca8 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h6185af37ff15529a
  23:        0x104ca60cc - std::sys::pal::unix::thread::Thread::new::thread_start::h6d53b1b0c047a3b9
  24:        0x183361c08 - __pthread_cond_wait

Expected Behavior

The instruction should parse successfully with all standard Solana program accounts.
OR
Provide a human-friendly error message when we're attaching program accounts and also the clear block in the documentation about the accounts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions