Add get_processed_sibling_instruction syscall (#22859)
This commit is contained in:
14
programs/bpf/Cargo.lock
generated
14
programs/bpf/Cargo.lock
generated
@ -3017,6 +3017,20 @@ dependencies = [
|
||||
"solana-program 1.10.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-sibling-instructions"
|
||||
version = "1.10.0"
|
||||
dependencies = [
|
||||
"solana-program 1.10.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-sibling_inner-instructions"
|
||||
version = "1.10.0"
|
||||
dependencies = [
|
||||
"solana-program 1.10.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-spoof1"
|
||||
version = "1.10.0"
|
||||
|
@ -81,6 +81,8 @@ members = [
|
||||
"rust/sanity",
|
||||
"rust/secp256k1_recover",
|
||||
"rust/sha",
|
||||
"rust/sibling_inner_instruction",
|
||||
"rust/sibling_instruction",
|
||||
"rust/spoof1",
|
||||
"rust/spoof1_system",
|
||||
"rust/sysvar",
|
||||
|
@ -91,6 +91,8 @@ fn main() {
|
||||
"sanity",
|
||||
"secp256k1_recover",
|
||||
"sha",
|
||||
"sibling_inner_instruction",
|
||||
"sibling_instruction",
|
||||
"spoof1",
|
||||
"spoof1_system",
|
||||
"upgradeable",
|
||||
|
23
programs/bpf/rust/sibling_inner_instruction/Cargo.toml
Normal file
23
programs/bpf/rust/sibling_inner_instruction/Cargo.toml
Normal file
@ -0,0 +1,23 @@
|
||||
[package]
|
||||
name = "solana-bpf-rust-sibling_inner-instructions"
|
||||
version = "1.10.0"
|
||||
description = "Solana BPF test program written in Rust"
|
||||
authors = ["Solana Maintainers <maintainers@solana.foundation>"]
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
license = "Apache-2.0"
|
||||
homepage = "https://solana.com/"
|
||||
documentation = "https://docs.rs/solana-bpf-rust-log-data"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
solana-program = { path = "../../../../sdk/program", version = "=1.10.0" }
|
||||
|
||||
[features]
|
||||
default = ["program"]
|
||||
program = []
|
||||
|
||||
[lib]
|
||||
crate-type = ["lib", "cdylib"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
69
programs/bpf/rust/sibling_inner_instruction/src/lib.rs
Normal file
69
programs/bpf/rust/sibling_inner_instruction/src/lib.rs
Normal file
@ -0,0 +1,69 @@
|
||||
//! Example Rust-based BPF program that queries sibling instructions
|
||||
|
||||
#![cfg(feature = "program")]
|
||||
|
||||
use solana_program::{
|
||||
account_info::AccountInfo,
|
||||
entrypoint,
|
||||
entrypoint::ProgramResult,
|
||||
instruction::{
|
||||
get_processed_sibling_instruction, get_stack_height, AccountMeta, Instruction,
|
||||
TRANSACTION_LEVEL_STACK_HEIGHT,
|
||||
},
|
||||
msg,
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
accounts: &[AccountInfo],
|
||||
_instruction_data: &[u8],
|
||||
) -> ProgramResult {
|
||||
msg!("sibling inner");
|
||||
|
||||
// account 0 is mint
|
||||
// account 1 is noop
|
||||
// account 2 is invoke_and_return
|
||||
|
||||
// Check sibling instructions
|
||||
|
||||
let sibling_instruction2 = Instruction::new_with_bytes(
|
||||
*accounts[2].key,
|
||||
&[3],
|
||||
vec![AccountMeta::new_readonly(*accounts[1].key, false)],
|
||||
);
|
||||
let sibling_instruction1 = Instruction::new_with_bytes(
|
||||
*accounts[1].key,
|
||||
&[2],
|
||||
vec![
|
||||
AccountMeta::new_readonly(*accounts[0].key, true),
|
||||
AccountMeta::new_readonly(*accounts[1].key, false),
|
||||
],
|
||||
);
|
||||
let sibling_instruction0 = Instruction::new_with_bytes(
|
||||
*accounts[1].key,
|
||||
&[1],
|
||||
vec![
|
||||
AccountMeta::new_readonly(*accounts[1].key, false),
|
||||
AccountMeta::new_readonly(*accounts[0].key, true),
|
||||
],
|
||||
);
|
||||
|
||||
assert_eq!(TRANSACTION_LEVEL_STACK_HEIGHT + 1, get_stack_height());
|
||||
assert_eq!(
|
||||
get_processed_sibling_instruction(0),
|
||||
Some(sibling_instruction0)
|
||||
);
|
||||
assert_eq!(
|
||||
get_processed_sibling_instruction(1),
|
||||
Some(sibling_instruction1)
|
||||
);
|
||||
assert_eq!(
|
||||
get_processed_sibling_instruction(2),
|
||||
Some(sibling_instruction2)
|
||||
);
|
||||
assert_eq!(get_processed_sibling_instruction(3), None);
|
||||
|
||||
Ok(())
|
||||
}
|
23
programs/bpf/rust/sibling_instruction/Cargo.toml
Normal file
23
programs/bpf/rust/sibling_instruction/Cargo.toml
Normal file
@ -0,0 +1,23 @@
|
||||
[package]
|
||||
name = "solana-bpf-rust-sibling-instructions"
|
||||
version = "1.10.0"
|
||||
description = "Solana BPF test program written in Rust"
|
||||
authors = ["Solana Maintainers <maintainers@solana.foundation>"]
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
license = "Apache-2.0"
|
||||
homepage = "https://solana.com/"
|
||||
documentation = "https://docs.rs/solana-bpf-rust-log-data"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
solana-program = { path = "../../../../sdk/program", version = "=1.10.0" }
|
||||
|
||||
[features]
|
||||
default = ["program"]
|
||||
program = []
|
||||
|
||||
[lib]
|
||||
crate-type = ["lib", "cdylib"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
100
programs/bpf/rust/sibling_instruction/src/lib.rs
Normal file
100
programs/bpf/rust/sibling_instruction/src/lib.rs
Normal file
@ -0,0 +1,100 @@
|
||||
//! Example Rust-based BPF program that queries sibling instructions
|
||||
|
||||
#![cfg(feature = "program")]
|
||||
|
||||
use solana_program::{
|
||||
account_info::AccountInfo,
|
||||
entrypoint,
|
||||
entrypoint::ProgramResult,
|
||||
instruction::{
|
||||
get_processed_sibling_instruction, get_stack_height, AccountMeta, Instruction,
|
||||
TRANSACTION_LEVEL_STACK_HEIGHT,
|
||||
},
|
||||
msg,
|
||||
program::invoke,
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
accounts: &[AccountInfo],
|
||||
_instruction_data: &[u8],
|
||||
) -> ProgramResult {
|
||||
msg!("sibling");
|
||||
|
||||
// account 0 is mint
|
||||
// account 1 is noop
|
||||
// account 2 is invoke_and_return
|
||||
// account 3 is sibling_inner
|
||||
|
||||
// Invoke child instructions
|
||||
|
||||
let instruction3 = Instruction::new_with_bytes(
|
||||
*accounts[2].key,
|
||||
&[3],
|
||||
vec![AccountMeta::new_readonly(*accounts[1].key, false)],
|
||||
);
|
||||
let instruction2 = Instruction::new_with_bytes(
|
||||
*accounts[1].key,
|
||||
&[2],
|
||||
vec![
|
||||
AccountMeta::new_readonly(*accounts[0].key, true),
|
||||
AccountMeta::new_readonly(*accounts[1].key, false),
|
||||
],
|
||||
);
|
||||
let instruction1 = Instruction::new_with_bytes(
|
||||
*accounts[1].key,
|
||||
&[1],
|
||||
vec![
|
||||
AccountMeta::new_readonly(*accounts[1].key, false),
|
||||
AccountMeta::new_readonly(*accounts[0].key, true),
|
||||
],
|
||||
);
|
||||
let instruction0 = Instruction::new_with_bytes(
|
||||
*accounts[3].key,
|
||||
&[0],
|
||||
vec![
|
||||
AccountMeta::new_readonly(*accounts[0].key, false),
|
||||
AccountMeta::new_readonly(*accounts[1].key, false),
|
||||
AccountMeta::new_readonly(*accounts[2].key, false),
|
||||
AccountMeta::new_readonly(*accounts[3].key, false),
|
||||
],
|
||||
);
|
||||
invoke(&instruction3, accounts)?;
|
||||
invoke(&instruction2, accounts)?;
|
||||
invoke(&instruction1, accounts)?;
|
||||
invoke(&instruction0, accounts)?;
|
||||
|
||||
// Check sibling instructions
|
||||
|
||||
let sibling_instruction1 = Instruction::new_with_bytes(
|
||||
*accounts[1].key,
|
||||
&[43],
|
||||
vec![
|
||||
AccountMeta::new_readonly(*accounts[1].key, false),
|
||||
AccountMeta::new(*accounts[0].key, true),
|
||||
],
|
||||
);
|
||||
let sibling_instruction0 = Instruction::new_with_bytes(
|
||||
*accounts[1].key,
|
||||
&[42],
|
||||
vec![
|
||||
AccountMeta::new(*accounts[0].key, true),
|
||||
AccountMeta::new_readonly(*accounts[1].key, false),
|
||||
],
|
||||
);
|
||||
|
||||
assert_eq!(TRANSACTION_LEVEL_STACK_HEIGHT, get_stack_height());
|
||||
assert_eq!(
|
||||
get_processed_sibling_instruction(0),
|
||||
Some(sibling_instruction0)
|
||||
);
|
||||
assert_eq!(
|
||||
get_processed_sibling_instruction(1),
|
||||
Some(sibling_instruction1)
|
||||
);
|
||||
assert_eq!(get_processed_sibling_instruction(2), None);
|
||||
|
||||
Ok(())
|
||||
}
|
@ -3343,3 +3343,79 @@ fn test_program_bpf_realloc_invoke() {
|
||||
TransactionError::InstructionError(0, InstructionError::InvalidRealloc)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "bpf_rust"))]
|
||||
fn test_program_bpf_processed_inner_instruction() {
|
||||
solana_logger::setup();
|
||||
|
||||
let GenesisConfigInfo {
|
||||
genesis_config,
|
||||
mint_keypair,
|
||||
..
|
||||
} = create_genesis_config(50);
|
||||
let mut bank = Bank::new_for_tests(&genesis_config);
|
||||
let (name, id, entrypoint) = solana_bpf_loader_program!();
|
||||
bank.add_builtin(&name, &id, entrypoint);
|
||||
let bank = Arc::new(bank);
|
||||
let bank_client = BankClient::new_shared(&bank);
|
||||
|
||||
let sibling_program_id = load_bpf_program(
|
||||
&bank_client,
|
||||
&bpf_loader::id(),
|
||||
&mint_keypair,
|
||||
"solana_bpf_rust_sibling_instructions",
|
||||
);
|
||||
let sibling_inner_program_id = load_bpf_program(
|
||||
&bank_client,
|
||||
&bpf_loader::id(),
|
||||
&mint_keypair,
|
||||
"solana_bpf_rust_sibling_inner_instructions",
|
||||
);
|
||||
let noop_program_id = load_bpf_program(
|
||||
&bank_client,
|
||||
&bpf_loader::id(),
|
||||
&mint_keypair,
|
||||
"solana_bpf_rust_noop",
|
||||
);
|
||||
let invoke_and_return_program_id = load_bpf_program(
|
||||
&bank_client,
|
||||
&bpf_loader::id(),
|
||||
&mint_keypair,
|
||||
"solana_bpf_rust_invoke_and_return",
|
||||
);
|
||||
|
||||
let instruction2 = Instruction::new_with_bytes(
|
||||
noop_program_id,
|
||||
&[43],
|
||||
vec![
|
||||
AccountMeta::new_readonly(noop_program_id, false),
|
||||
AccountMeta::new(mint_keypair.pubkey(), true),
|
||||
],
|
||||
);
|
||||
let instruction1 = Instruction::new_with_bytes(
|
||||
noop_program_id,
|
||||
&[42],
|
||||
vec![
|
||||
AccountMeta::new(mint_keypair.pubkey(), true),
|
||||
AccountMeta::new_readonly(noop_program_id, false),
|
||||
],
|
||||
);
|
||||
let instruction0 = Instruction::new_with_bytes(
|
||||
sibling_program_id,
|
||||
&[1, 2, 3, 0, 4, 5, 6],
|
||||
vec![
|
||||
AccountMeta::new(mint_keypair.pubkey(), true),
|
||||
AccountMeta::new_readonly(noop_program_id, false),
|
||||
AccountMeta::new_readonly(invoke_and_return_program_id, false),
|
||||
AccountMeta::new_readonly(sibling_inner_program_id, false),
|
||||
],
|
||||
);
|
||||
let message = Message::new(
|
||||
&[instruction2, instruction1, instruction0],
|
||||
Some(&mint_keypair.pubkey()),
|
||||
);
|
||||
assert!(bank_client
|
||||
.send_and_confirm_message(&[&mint_keypair], message)
|
||||
.is_ok());
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ fn process_instruction_common(
|
||||
if program.executable()? {
|
||||
debug_assert_eq!(
|
||||
first_instruction_account,
|
||||
1 - (invoke_context.get_invoke_depth() > 1) as usize,
|
||||
1 - (invoke_context.get_stack_height() > 1) as usize,
|
||||
);
|
||||
|
||||
if !check_loader_id(&program.owner()?) {
|
||||
@ -1045,7 +1045,7 @@ impl Executor for BpfExecutor {
|
||||
) -> Result<(), InstructionError> {
|
||||
let log_collector = invoke_context.get_log_collector();
|
||||
let compute_meter = invoke_context.get_compute_meter();
|
||||
let invoke_depth = invoke_context.get_invoke_depth();
|
||||
let stack_height = invoke_context.get_stack_height();
|
||||
|
||||
let mut serialize_time = Measure::start("serialize");
|
||||
let program_id = *invoke_context.transaction_context.get_program_key()?;
|
||||
@ -1074,7 +1074,7 @@ impl Executor for BpfExecutor {
|
||||
create_vm_time.stop();
|
||||
|
||||
execute_time = Measure::start("execute");
|
||||
stable_log::program_invoke(&log_collector, &program_id, invoke_depth);
|
||||
stable_log::program_invoke(&log_collector, &program_id, stack_height);
|
||||
let mut instruction_meter = ThisInstructionMeter::new(compute_meter.clone());
|
||||
let before = compute_meter.borrow().get_remaining();
|
||||
let result = if use_jit {
|
||||
|
@ -22,14 +22,17 @@ use {
|
||||
blake3, bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable,
|
||||
entrypoint::{BPF_ALIGN_OF_U128, MAX_PERMITTED_DATA_INCREASE, SUCCESS},
|
||||
feature_set::{
|
||||
self, blake3_syscall_enabled, disable_fees_sysvar, do_support_realloc,
|
||||
fixed_memcpy_nonoverlapping_check, libsecp256k1_0_5_upgrade_enabled,
|
||||
prevent_calling_precompiles_as_programs, return_data_syscall_enabled,
|
||||
secp256k1_recover_syscall_enabled, sol_log_data_syscall_enabled,
|
||||
update_syscall_base_costs,
|
||||
self, add_get_processed_sibling_instruction_syscall, blake3_syscall_enabled,
|
||||
disable_fees_sysvar, do_support_realloc, fixed_memcpy_nonoverlapping_check,
|
||||
libsecp256k1_0_5_upgrade_enabled, prevent_calling_precompiles_as_programs,
|
||||
return_data_syscall_enabled, secp256k1_recover_syscall_enabled,
|
||||
sol_log_data_syscall_enabled, update_syscall_base_costs,
|
||||
},
|
||||
hash::{Hasher, HASH_BYTES},
|
||||
instruction::{AccountMeta, Instruction, InstructionError},
|
||||
instruction::{
|
||||
AccountMeta, Instruction, InstructionError, ProcessedSiblingInstruction,
|
||||
TRANSACTION_LEVEL_STACK_HEIGHT,
|
||||
},
|
||||
keccak, native_loader,
|
||||
precompiles::is_precompile,
|
||||
program::MAX_RETURN_DATA,
|
||||
@ -222,6 +225,24 @@ pub fn register_syscalls(
|
||||
syscall_registry.register_syscall_by_name(b"sol_log_data", SyscallLogData::call)?;
|
||||
}
|
||||
|
||||
if invoke_context
|
||||
.feature_set
|
||||
.is_active(&add_get_processed_sibling_instruction_syscall::id())
|
||||
{
|
||||
syscall_registry.register_syscall_by_name(
|
||||
b"sol_get_processed_sibling_instruction",
|
||||
SyscallGetProcessedSiblingInstruction::call,
|
||||
)?;
|
||||
}
|
||||
|
||||
if invoke_context
|
||||
.feature_set
|
||||
.is_active(&add_get_processed_sibling_instruction_syscall::id())
|
||||
{
|
||||
syscall_registry
|
||||
.register_syscall_by_name(b"sol_get_stack_height", SyscallGetStackHeight::call)?;
|
||||
}
|
||||
|
||||
Ok(syscall_registry)
|
||||
}
|
||||
|
||||
@ -262,6 +283,9 @@ pub fn bind_syscall_context_objects<'a, 'b>(
|
||||
let is_zk_token_sdk_enabled = invoke_context
|
||||
.feature_set
|
||||
.is_active(&feature_set::zk_token_sdk_enabled::id());
|
||||
let add_get_processed_sibling_instruction_syscall = invoke_context
|
||||
.feature_set
|
||||
.is_active(&add_get_processed_sibling_instruction_syscall::id());
|
||||
|
||||
let loader_id = invoke_context
|
||||
.transaction_context
|
||||
@ -444,6 +468,24 @@ pub fn bind_syscall_context_objects<'a, 'b>(
|
||||
}),
|
||||
);
|
||||
|
||||
// processed inner instructions
|
||||
bind_feature_gated_syscall_context_object!(
|
||||
vm,
|
||||
add_get_processed_sibling_instruction_syscall,
|
||||
Box::new(SyscallGetProcessedSiblingInstruction {
|
||||
invoke_context: invoke_context.clone(),
|
||||
}),
|
||||
);
|
||||
|
||||
// Get stack height
|
||||
bind_feature_gated_syscall_context_object!(
|
||||
vm,
|
||||
add_get_processed_sibling_instruction_syscall,
|
||||
Box::new(SyscallGetStackHeight {
|
||||
invoke_context: invoke_context.clone(),
|
||||
}),
|
||||
);
|
||||
|
||||
// Cross-program invocation syscalls
|
||||
vm.bind_syscall_context_object(
|
||||
Box::new(SyscallInvokeSignedC {
|
||||
@ -2955,6 +2997,166 @@ impl<'a, 'b> SyscallObject<BpfError> for SyscallLogData<'a, 'b> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SyscallGetProcessedSiblingInstruction<'a, 'b> {
|
||||
invoke_context: Rc<RefCell<&'a mut InvokeContext<'b>>>,
|
||||
}
|
||||
impl<'a, 'b> SyscallObject<BpfError> for SyscallGetProcessedSiblingInstruction<'a, 'b> {
|
||||
fn call(
|
||||
&mut self,
|
||||
index: u64,
|
||||
meta_addr: u64,
|
||||
program_id_addr: u64,
|
||||
data_addr: u64,
|
||||
accounts_addr: u64,
|
||||
memory_mapping: &MemoryMapping,
|
||||
result: &mut Result<u64, EbpfError<BpfError>>,
|
||||
) {
|
||||
let invoke_context = question_mark!(
|
||||
self.invoke_context
|
||||
.try_borrow()
|
||||
.map_err(|_| SyscallError::InvokeContextBorrowFailed),
|
||||
result
|
||||
);
|
||||
let loader_id = question_mark!(
|
||||
invoke_context
|
||||
.transaction_context
|
||||
.get_loader_key()
|
||||
.map_err(SyscallError::InstructionError),
|
||||
result
|
||||
);
|
||||
|
||||
let budget = invoke_context.get_compute_budget();
|
||||
question_mark!(
|
||||
invoke_context
|
||||
.get_compute_meter()
|
||||
.consume(budget.syscall_base_cost),
|
||||
result
|
||||
);
|
||||
|
||||
let stack_height = invoke_context.get_stack_height();
|
||||
let instruction_trace = invoke_context.get_instruction_trace();
|
||||
let instruction_context = if stack_height == TRANSACTION_LEVEL_STACK_HEIGHT {
|
||||
// pick one of the top-level instructions
|
||||
instruction_trace
|
||||
.len()
|
||||
.checked_sub(2)
|
||||
.and_then(|result| result.checked_sub(index as usize))
|
||||
.and_then(|index| instruction_trace.get(index))
|
||||
.and_then(|instruction_list| instruction_list.get(0))
|
||||
} else {
|
||||
// Walk the last list of inner instructions
|
||||
instruction_trace.last().and_then(|inners| {
|
||||
let mut current_index = 0;
|
||||
inners.iter().rev().skip(1).find(|(this_stack_height, _)| {
|
||||
if stack_height == *this_stack_height {
|
||||
if index == current_index {
|
||||
return true;
|
||||
} else {
|
||||
current_index += 1;
|
||||
}
|
||||
}
|
||||
false
|
||||
})
|
||||
})
|
||||
}
|
||||
.map(|(_, instruction_context)| instruction_context);
|
||||
|
||||
if let Some(instruction_context) = instruction_context {
|
||||
let ProcessedSiblingInstruction {
|
||||
data_len,
|
||||
accounts_len,
|
||||
} = question_mark!(
|
||||
translate_type_mut::<ProcessedSiblingInstruction>(
|
||||
memory_mapping,
|
||||
meta_addr,
|
||||
&loader_id
|
||||
),
|
||||
result
|
||||
);
|
||||
|
||||
if *data_len >= instruction_context.get_instruction_data().len()
|
||||
&& *accounts_len == instruction_context.get_number_of_instruction_accounts()
|
||||
{
|
||||
let program_id = question_mark!(
|
||||
translate_type_mut::<Pubkey>(memory_mapping, program_id_addr, &loader_id),
|
||||
result
|
||||
);
|
||||
let data = question_mark!(
|
||||
translate_slice_mut::<u8>(
|
||||
memory_mapping,
|
||||
data_addr,
|
||||
*data_len as u64,
|
||||
&loader_id,
|
||||
),
|
||||
result
|
||||
);
|
||||
let accounts = question_mark!(
|
||||
translate_slice_mut::<AccountMeta>(
|
||||
memory_mapping,
|
||||
accounts_addr,
|
||||
*accounts_len as u64,
|
||||
&loader_id,
|
||||
),
|
||||
result
|
||||
);
|
||||
|
||||
*program_id =
|
||||
instruction_context.get_program_id(invoke_context.transaction_context);
|
||||
data.clone_from_slice(instruction_context.get_instruction_data());
|
||||
let account_metas = instruction_context
|
||||
.get_instruction_accounts_metas()
|
||||
.iter()
|
||||
.map(|meta| AccountMeta {
|
||||
pubkey: *invoke_context
|
||||
.get_key_of_account_at_index(meta.index_in_transaction),
|
||||
is_signer: meta.is_signer,
|
||||
is_writable: meta.is_writable,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
accounts.clone_from_slice(account_metas.as_slice());
|
||||
}
|
||||
*data_len = instruction_context.get_instruction_data().len();
|
||||
*accounts_len = instruction_context.get_number_of_instruction_accounts();
|
||||
*result = Ok(true as u64);
|
||||
return;
|
||||
}
|
||||
*result = Ok(false as u64);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SyscallGetStackHeight<'a, 'b> {
|
||||
invoke_context: Rc<RefCell<&'a mut InvokeContext<'b>>>,
|
||||
}
|
||||
impl<'a, 'b> SyscallObject<BpfError> for SyscallGetStackHeight<'a, 'b> {
|
||||
fn call(
|
||||
&mut self,
|
||||
_arg1: u64,
|
||||
_arg2: u64,
|
||||
_arg3: u64,
|
||||
_arg4: u64,
|
||||
_arg5: u64,
|
||||
_memory_mapping: &MemoryMapping,
|
||||
result: &mut Result<u64, EbpfError<BpfError>>,
|
||||
) {
|
||||
let invoke_context = question_mark!(
|
||||
self.invoke_context
|
||||
.try_borrow()
|
||||
.map_err(|_| SyscallError::InvokeContextBorrowFailed),
|
||||
result
|
||||
);
|
||||
|
||||
let budget = invoke_context.get_compute_budget();
|
||||
question_mark!(
|
||||
invoke_context
|
||||
.get_compute_meter()
|
||||
.consume(budget.syscall_base_cost),
|
||||
result
|
||||
);
|
||||
|
||||
*result = Ok(invoke_context.get_stack_height() as u64);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[allow(deprecated)]
|
||||
|
@ -3,7 +3,7 @@
|
||||
use {
|
||||
bytemuck::Pod,
|
||||
solana_program_runtime::{ic_msg, invoke_context::InvokeContext},
|
||||
solana_sdk::instruction::InstructionError,
|
||||
solana_sdk::instruction::{InstructionError, TRANSACTION_LEVEL_STACK_HEIGHT},
|
||||
solana_zk_token_sdk::zk_token_proof_instruction::*,
|
||||
std::result::Result,
|
||||
};
|
||||
@ -28,7 +28,7 @@ pub fn process_instruction(
|
||||
input: &[u8],
|
||||
invoke_context: &mut InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
if invoke_context.get_invoke_depth() != 1 {
|
||||
if invoke_context.get_stack_height() != TRANSACTION_LEVEL_STACK_HEIGHT {
|
||||
// Not supported as an inner instruction
|
||||
return Err(InstructionError::UnsupportedProgramId);
|
||||
}
|
||||
|
Reference in New Issue
Block a user