Pass the correct program_id to programs (#8630)
This commit is contained in:
@ -9,6 +9,7 @@ use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use solana_rbpf::{memory_region::MemoryRegion, EbpfVm};
|
||||
use solana_sdk::{
|
||||
account::KeyedAccount,
|
||||
bpf_loader,
|
||||
entrypoint::SUCCESS,
|
||||
instruction::InstructionError,
|
||||
loader_instruction::LoaderInstruction,
|
||||
@ -147,6 +148,8 @@ pub fn process_instruction(
|
||||
) -> Result<(), InstructionError> {
|
||||
solana_logger::setup_with_default("solana=info");
|
||||
|
||||
debug_assert!(bpf_loader::check_id(program_id));
|
||||
|
||||
if keyed_accounts.is_empty() {
|
||||
warn!("No account keys");
|
||||
return Err(InstructionError::NotEnoughAccountKeys);
|
||||
@ -164,8 +167,11 @@ pub fn process_instruction(
|
||||
}
|
||||
};
|
||||
let parameter_accounts = keyed_accounts_iter.as_slice();
|
||||
let parameter_bytes =
|
||||
serialize_parameters(program_id, parameter_accounts, &instruction_data)?;
|
||||
let parameter_bytes = serialize_parameters(
|
||||
program.unsigned_key(),
|
||||
parameter_accounts,
|
||||
&instruction_data,
|
||||
)?;
|
||||
|
||||
info!("Call BPF program");
|
||||
match vm.execute_program(parameter_bytes.as_slice(), &[], &[heap_region]) {
|
||||
@ -265,13 +271,13 @@ mod tests {
|
||||
// Case: Empty keyed accounts
|
||||
assert_eq!(
|
||||
Err(InstructionError::NotEnoughAccountKeys),
|
||||
process_instruction(&program_id, &vec![], &instruction_data)
|
||||
process_instruction(&bpf_loader::id(), &vec![], &instruction_data)
|
||||
);
|
||||
|
||||
// Case: Not signed
|
||||
assert_eq!(
|
||||
Err(InstructionError::MissingRequiredSignature),
|
||||
process_instruction(&program_id, &keyed_accounts, &instruction_data)
|
||||
process_instruction(&bpf_loader::id(), &keyed_accounts, &instruction_data)
|
||||
);
|
||||
|
||||
// Case: Write bytes to an offset
|
||||
@ -279,7 +285,7 @@ mod tests {
|
||||
keyed_accounts[0].account.borrow_mut().data = vec![0; 6];
|
||||
assert_eq!(
|
||||
Ok(()),
|
||||
process_instruction(&program_id, &keyed_accounts, &instruction_data)
|
||||
process_instruction(&bpf_loader::id(), &keyed_accounts, &instruction_data)
|
||||
);
|
||||
assert_eq!(
|
||||
vec![0, 0, 0, 1, 2, 3],
|
||||
@ -291,7 +297,7 @@ mod tests {
|
||||
keyed_accounts[0].account.borrow_mut().data = vec![0; 5];
|
||||
assert_eq!(
|
||||
Err(InstructionError::AccountDataTooSmall),
|
||||
process_instruction(&program_id, &keyed_accounts, &instruction_data)
|
||||
process_instruction(&bpf_loader::id(), &keyed_accounts, &instruction_data)
|
||||
);
|
||||
}
|
||||
|
||||
@ -312,7 +318,7 @@ mod tests {
|
||||
// Case: Empty keyed accounts
|
||||
assert_eq!(
|
||||
Err(InstructionError::NotEnoughAccountKeys),
|
||||
process_instruction(&program_id, &vec![], &instruction_data)
|
||||
process_instruction(&bpf_loader::id(), &vec![], &instruction_data)
|
||||
);
|
||||
|
||||
let rent_account = RefCell::new(rent::create_account(1, &rent));
|
||||
@ -321,7 +327,7 @@ mod tests {
|
||||
// Case: Not signed
|
||||
assert_eq!(
|
||||
Err(InstructionError::MissingRequiredSignature),
|
||||
process_instruction(&program_id, &keyed_accounts, &instruction_data)
|
||||
process_instruction(&bpf_loader::id(), &keyed_accounts, &instruction_data)
|
||||
);
|
||||
|
||||
// Case: Finalize
|
||||
@ -331,7 +337,7 @@ mod tests {
|
||||
];
|
||||
assert_eq!(
|
||||
Ok(()),
|
||||
process_instruction(&program_id, &keyed_accounts, &instruction_data)
|
||||
process_instruction(&bpf_loader::id(), &keyed_accounts, &instruction_data)
|
||||
);
|
||||
assert!(keyed_accounts[0].account.borrow().executable);
|
||||
|
||||
@ -345,7 +351,7 @@ mod tests {
|
||||
];
|
||||
assert_eq!(
|
||||
Err(InstructionError::InvalidAccountData),
|
||||
process_instruction(&program_id, &keyed_accounts, &instruction_data)
|
||||
process_instruction(&bpf_loader::id(), &keyed_accounts, &instruction_data)
|
||||
);
|
||||
}
|
||||
|
||||
@ -369,20 +375,20 @@ mod tests {
|
||||
// Case: Empty keyed accounts
|
||||
assert_eq!(
|
||||
Err(InstructionError::NotEnoughAccountKeys),
|
||||
process_instruction(&program_id, &vec![], &vec![])
|
||||
process_instruction(&bpf_loader::id(), &vec![], &vec![])
|
||||
);
|
||||
|
||||
// Case: Only a program account
|
||||
assert_eq!(
|
||||
Ok(()),
|
||||
process_instruction(&program_id, &keyed_accounts, &vec![])
|
||||
process_instruction(&bpf_loader::id(), &keyed_accounts, &vec![])
|
||||
);
|
||||
|
||||
// Case: Account not executable
|
||||
keyed_accounts[0].account.borrow_mut().executable = false;
|
||||
assert_eq!(
|
||||
Err(InstructionError::InvalidInstructionData),
|
||||
process_instruction(&program_id, &keyed_accounts, &vec![])
|
||||
process_instruction(&bpf_loader::id(), &keyed_accounts, &vec![])
|
||||
);
|
||||
keyed_accounts[0].account.borrow_mut().executable = true;
|
||||
|
||||
@ -391,7 +397,7 @@ mod tests {
|
||||
keyed_accounts.push(KeyedAccount::new(&program_key, false, ¶meter_account));
|
||||
assert_eq!(
|
||||
Ok(()),
|
||||
process_instruction(&program_id, &keyed_accounts, &vec![])
|
||||
process_instruction(&bpf_loader::id(), &keyed_accounts, &vec![])
|
||||
);
|
||||
|
||||
// Case: With duplicate accounts
|
||||
@ -402,7 +408,7 @@ mod tests {
|
||||
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, ¶meter_account));
|
||||
assert_eq!(
|
||||
Ok(()),
|
||||
process_instruction(&program_id, &keyed_accounts, &vec![])
|
||||
process_instruction(&bpf_loader::id(), &keyed_accounts, &vec![])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user