Adds missing program_id in InvokeContext::push() calls. (#20621)

This commit is contained in:
Alexander Meißner 2021-10-12 19:26:55 +02:00 committed by GitHub
parent 005d6863fd
commit 06cad19c91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 61 deletions

View File

@ -129,8 +129,7 @@ impl<'a> InvokeContext for ThisInvokeContext<'a> {
if self.invoke_stack.is_empty() {
self.pre_accounts = Vec::with_capacity(instruction.accounts.len());
let mut work = |_unique_index: usize, account_index: usize| {
if account_index < message.account_keys.len() && account_index < self.accounts.len()
{
if account_index < self.accounts.len() {
let account = self.accounts[account_index].1.borrow();
self.pre_accounts
.push(PreAccount::new(&self.accounts[account_index].0, &account));
@ -696,7 +695,13 @@ mod tests {
let mut depth_reached = 0;
for program_id in invoke_stack.iter() {
if Err(InstructionError::CallDepth)
== invoke_context.push(program_id, &message, &message.instructions[0], &[], None)
== invoke_context.push(
program_id,
&message,
&message.instructions[0],
&[MAX_DEPTH + depth_reached],
None,
)
{
break;
}
@ -1188,7 +1193,8 @@ mod tests {
let owned_account = AccountSharedData::new(42, 1, &callee_program_id);
let not_owned_account = AccountSharedData::new(84, 1, &solana_sdk::pubkey::new_rand());
let readonly_account = AccountSharedData::new(168, 1, &caller_program_id);
let readonly_account = AccountSharedData::new(168, 1, &solana_sdk::pubkey::new_rand());
let loader_account = AccountSharedData::new(0, 0, &native_loader::id());
let mut program_account = AccountSharedData::new(1, 0, &native_loader::id());
program_account.set_executable(true);
@ -1205,10 +1211,11 @@ mod tests {
solana_sdk::pubkey::new_rand(),
Rc::new(RefCell::new(readonly_account)),
),
(caller_program_id, Rc::new(RefCell::new(loader_account))),
(callee_program_id, Rc::new(RefCell::new(program_account))),
];
let account_indices = [0, 1, 2];
let program_indices = vec![3];
let program_indices = [3, 4];
let programs: Vec<(_, ProcessInstructionWithContext)> =
vec![(callee_program_id, mock_process_instruction)];
@ -1218,7 +1225,8 @@ mod tests {
AccountMeta::new_readonly(accounts[2].0, false),
];
let caller_instruction = CompiledInstruction::new(2, &(), vec![0, 1, 2, 3]);
let caller_instruction =
CompiledInstruction::new(program_indices[0] as u8, &(), vec![0, 1, 2, 3, 4]);
let callee_instruction = Instruction::new_with_bincode(
callee_program_id,
&MockInstruction::NoopSuccess,
@ -1226,9 +1234,6 @@ mod tests {
);
let message = Message::new(&[callee_instruction], None);
let feature_set = FeatureSet::all_enabled();
let demote_program_write_locks = feature_set.is_active(&demote_program_write_locks::id());
let ancestors = Ancestors::default();
let blockhash = Hash::default();
let fee_calculator = FeeCalculator::default();
@ -1241,7 +1246,7 @@ mod tests {
Rc::new(RefCell::new(MockComputeMeter::default())),
Rc::new(RefCell::new(Executors::default())),
None,
Arc::new(feature_set),
Arc::new(FeatureSet::all_enabled()),
Arc::new(Accounts::default_for_tests()),
&ancestors,
&blockhash,
@ -1252,12 +1257,14 @@ mod tests {
&caller_program_id,
&message,
&caller_instruction,
&program_indices,
&program_indices[..1],
None,
)
.unwrap();
// not owned account modified by the caller (before the invoke)
let demote_program_write_locks =
invoke_context.is_feature_active(&demote_program_write_locks::id());
let caller_write_privileges = message
.account_keys
.iter()
@ -1268,7 +1275,7 @@ mod tests {
assert_eq!(
InstructionProcessor::process_cross_program_instruction(
&message,
&program_indices,
&program_indices[1..],
&account_indices,
&caller_write_privileges,
&mut invoke_context,
@ -1282,7 +1289,7 @@ mod tests {
assert_eq!(
InstructionProcessor::process_cross_program_instruction(
&message,
&program_indices,
&program_indices[1..],
&account_indices,
&caller_write_privileges,
&mut invoke_context,
@ -1291,6 +1298,8 @@ mod tests {
);
accounts[2].1.borrow_mut().data_as_mut_slice()[0] = 0;
invoke_context.pop();
let cases = vec![
(MockInstruction::NoopSuccess, Ok(())),
(
@ -1303,40 +1312,19 @@ mod tests {
Err(InstructionError::ExternalAccountDataModified),
),
];
for case in cases {
let callee_instruction =
Instruction::new_with_bincode(callee_program_id, &case.0, metas.clone());
let message = Message::new(&[callee_instruction], None);
let ancestors = Ancestors::default();
let blockhash = Hash::default();
let fee_calculator = FeeCalculator::default();
let mut invoke_context = ThisInvokeContext::new(
Rent::default(),
&accounts,
programs.as_slice(),
None,
ComputeBudget::default(),
Rc::new(RefCell::new(MockComputeMeter::default())),
Rc::new(RefCell::new(Executors::default())),
None,
Arc::new(FeatureSet::all_enabled()),
Arc::new(Accounts::default_for_tests()),
&ancestors,
&blockhash,
&fee_calculator,
);
invoke_context
.push(
&caller_program_id,
&message,
&caller_instruction,
&program_indices,
&program_indices[..1],
None,
)
.unwrap();
let caller_write_privileges = message
.account_keys
.iter()
@ -1346,13 +1334,14 @@ mod tests {
assert_eq!(
InstructionProcessor::process_cross_program_instruction(
&message,
&program_indices,
&program_indices[1..],
&account_indices,
&caller_write_privileges,
&mut invoke_context,
),
case.1
);
invoke_context.pop();
}
}
@ -1363,7 +1352,8 @@ mod tests {
let owned_account = AccountSharedData::new(42, 1, &callee_program_id);
let not_owned_account = AccountSharedData::new(84, 1, &solana_sdk::pubkey::new_rand());
let readonly_account = AccountSharedData::new(168, 1, &caller_program_id);
let readonly_account = AccountSharedData::new(168, 1, &solana_sdk::pubkey::new_rand());
let loader_account = AccountSharedData::new(0, 0, &native_loader::id());
let mut program_account = AccountSharedData::new(1, 0, &native_loader::id());
program_account.set_executable(true);
@ -1380,9 +1370,10 @@ mod tests {
solana_sdk::pubkey::new_rand(),
Rc::new(RefCell::new(readonly_account)),
),
(caller_program_id, Rc::new(RefCell::new(loader_account))),
(callee_program_id, Rc::new(RefCell::new(program_account))),
];
let program_indices = vec![3];
let program_indices = [3];
let programs: Vec<(_, ProcessInstructionWithContext)> =
vec![(callee_program_id, mock_process_instruction)];
let metas = vec![
@ -1391,7 +1382,8 @@ mod tests {
AccountMeta::new_readonly(accounts[2].0, false),
];
let caller_instruction = CompiledInstruction::new(2, &(), vec![0, 1, 2, 3]);
let caller_instruction =
CompiledInstruction::new(program_indices[0] as u8, &(), vec![0, 1, 2, 3, 4]);
let callee_instruction = Instruction::new_with_bincode(
callee_program_id,
&MockInstruction::NoopSuccess,
@ -1399,7 +1391,6 @@ mod tests {
);
let message = Message::new(&[callee_instruction.clone()], None);
let feature_set = FeatureSet::all_enabled();
let ancestors = Ancestors::default();
let blockhash = Hash::default();
let fee_calculator = FeeCalculator::default();
@ -1412,7 +1403,7 @@ mod tests {
Rc::new(RefCell::new(MockComputeMeter::default())),
Rc::new(RefCell::new(Executors::default())),
None,
Arc::new(feature_set),
Arc::new(FeatureSet::all_enabled()),
Arc::new(Accounts::default_for_tests()),
&ancestors,
&blockhash,
@ -1454,6 +1445,8 @@ mod tests {
);
accounts[2].1.borrow_mut().data_as_mut_slice()[0] = 0;
invoke_context.pop();
// Other test cases
let cases = vec![
(MockInstruction::NoopSuccess, Ok(())),
@ -1475,25 +1468,6 @@ mod tests {
let callee_instruction =
Instruction::new_with_bincode(callee_program_id, &case.0, metas.clone());
let message = Message::new(&[callee_instruction.clone()], None);
let ancestors = Ancestors::default();
let blockhash = Hash::default();
let fee_calculator = FeeCalculator::default();
let mut invoke_context = ThisInvokeContext::new(
Rent::default(),
&accounts,
programs.as_slice(),
None,
ComputeBudget::default(),
Rc::new(RefCell::new(MockComputeMeter::default())),
Rc::new(RefCell::new(Executors::default())),
None,
Arc::new(FeatureSet::all_enabled()),
Arc::new(Accounts::default_for_tests()),
&ancestors,
&blockhash,
&fee_calculator,
);
invoke_context
.push(
&caller_program_id,
@ -1503,7 +1477,6 @@ mod tests {
None,
)
.unwrap();
assert_eq!(
InstructionProcessor::native_invoke(
&mut invoke_context,
@ -1513,6 +1486,7 @@ mod tests {
),
case.1
);
invoke_context.pop();
}
}