* Removes SyscallSetAccountProperties. * Removes TransactionContextAttribute.
This commit is contained in:
parent
b2ece6368f
commit
66d06b3f99
|
@ -99,8 +99,6 @@ pub struct ComputeBudget {
|
|||
pub heap_cost: u64,
|
||||
/// Memory operation syscall base cost
|
||||
pub mem_op_base_cost: u64,
|
||||
/// Number of compute units consumed per AccountPropertyUpdate
|
||||
pub account_property_update_cost: u64,
|
||||
}
|
||||
|
||||
impl Default for ComputeBudget {
|
||||
|
@ -144,7 +142,6 @@ impl ComputeBudget {
|
|||
heap_size: None,
|
||||
heap_cost: 8,
|
||||
mem_op_base_cost: 10,
|
||||
account_property_update_cost: 10,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,8 +39,8 @@ use {
|
|||
},
|
||||
hash::{Hasher, HASH_BYTES},
|
||||
instruction::{
|
||||
AccountMeta, AccountPropertyUpdate, Instruction, InstructionError,
|
||||
ProcessedSiblingInstruction, TRANSACTION_LEVEL_STACK_HEIGHT,
|
||||
AccountMeta, Instruction, InstructionError, ProcessedSiblingInstruction,
|
||||
TRANSACTION_LEVEL_STACK_HEIGHT,
|
||||
},
|
||||
keccak, native_loader,
|
||||
precompiles::is_precompile,
|
||||
|
@ -51,7 +51,7 @@ use {
|
|||
Secp256k1RecoverError, SECP256K1_PUBLIC_KEY_LENGTH, SECP256K1_SIGNATURE_LENGTH,
|
||||
},
|
||||
sysvar::{Sysvar, SysvarId},
|
||||
transaction_context::{IndexOfAccount, InstructionAccount, TransactionContextAttribute},
|
||||
transaction_context::{IndexOfAccount, InstructionAccount},
|
||||
},
|
||||
std::{
|
||||
alloc::Layout,
|
||||
|
@ -246,13 +246,7 @@ pub fn register_syscalls(
|
|||
syscall_registry.register_syscall_by_name(b"sol_memcmp_", SyscallMemcmp::call)?;
|
||||
syscall_registry.register_syscall_by_name(b"sol_memset_", SyscallMemset::call)?;
|
||||
|
||||
if is_abi_v2 {
|
||||
// Set account attributes
|
||||
syscall_registry.register_syscall_by_name(
|
||||
b"sol_set_account_attributes",
|
||||
SyscallSetAccountProperties::call,
|
||||
)?;
|
||||
} else {
|
||||
if !is_abi_v2 {
|
||||
// Processed sibling instructions
|
||||
syscall_registry.register_syscall_by_name(
|
||||
b"sol_get_processed_sibling_instruction",
|
||||
|
@ -1640,77 +1634,6 @@ declare_syscall!(
|
|||
}
|
||||
);
|
||||
|
||||
declare_syscall!(
|
||||
/// Update the properties of accounts
|
||||
SyscallSetAccountProperties,
|
||||
fn inner_call(
|
||||
invoke_context: &mut InvokeContext,
|
||||
updates_addr: u64,
|
||||
updates_count: u64,
|
||||
_arg3: u64,
|
||||
_arg4: u64,
|
||||
_arg5: u64,
|
||||
memory_mapping: &mut MemoryMapping,
|
||||
) -> Result<u64, EbpfError> {
|
||||
let budget = invoke_context.get_compute_budget();
|
||||
|
||||
invoke_context.get_compute_meter().consume(
|
||||
budget.syscall_base_cost.saturating_add(
|
||||
budget
|
||||
.account_property_update_cost
|
||||
.saturating_mul(updates_count),
|
||||
),
|
||||
)?;
|
||||
let transaction_context = &invoke_context.transaction_context;
|
||||
let instruction_context = transaction_context
|
||||
.get_current_instruction_context()
|
||||
.map_err(SyscallError::InstructionError)?;
|
||||
let updates = translate_slice::<AccountPropertyUpdate>(
|
||||
memory_mapping,
|
||||
updates_addr,
|
||||
updates_count,
|
||||
invoke_context.get_check_aligned(),
|
||||
invoke_context.get_check_size(),
|
||||
)?;
|
||||
for update in updates.iter() {
|
||||
let mut borrowed_account = instruction_context
|
||||
.try_borrow_instruction_account(
|
||||
transaction_context,
|
||||
update.instruction_account_index,
|
||||
)
|
||||
.map_err(SyscallError::InstructionError)?;
|
||||
let attribute =
|
||||
unsafe { std::mem::transmute::<_, TransactionContextAttribute>(update.attribute) };
|
||||
match attribute {
|
||||
TransactionContextAttribute::TransactionAccountOwner => {
|
||||
let owner_pubkey = translate_type::<Pubkey>(
|
||||
memory_mapping,
|
||||
update.value,
|
||||
invoke_context.get_check_aligned(),
|
||||
)?;
|
||||
|
||||
borrowed_account
|
||||
.set_owner(&owner_pubkey.to_bytes())
|
||||
.map_err(SyscallError::InstructionError)?;
|
||||
}
|
||||
TransactionContextAttribute::TransactionAccountLamports => borrowed_account
|
||||
.set_lamports(update.value)
|
||||
.map_err(SyscallError::InstructionError)?,
|
||||
TransactionContextAttribute::TransactionAccountData => borrowed_account
|
||||
.set_data_length(update.value as usize)
|
||||
.map_err(SyscallError::InstructionError)?,
|
||||
TransactionContextAttribute::TransactionAccountIsExecutable => borrowed_account
|
||||
.set_executable(update.value != 0)
|
||||
.map_err(SyscallError::InstructionError)?,
|
||||
_ => {
|
||||
return Err(SyscallError::InvalidAttribute.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(0)
|
||||
}
|
||||
);
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[allow(deprecated)]
|
||||
|
@ -4026,148 +3949,6 @@ mod tests {
|
|||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_syscall_sol_set_account_properties() {
|
||||
let program_key = Pubkey::new_unique();
|
||||
let loader_key = bpf_loader::id();
|
||||
let transaction_accounts = vec![
|
||||
(
|
||||
loader_key,
|
||||
AccountSharedData::new(0, 0, &native_loader::id()),
|
||||
),
|
||||
(program_key, AccountSharedData::new(0, 0, &loader_key)),
|
||||
(
|
||||
Pubkey::new_unique(),
|
||||
AccountSharedData::new(0, 0, &program_key),
|
||||
),
|
||||
(
|
||||
Pubkey::new_unique(),
|
||||
AccountSharedData::new(0, 0, &program_key),
|
||||
),
|
||||
];
|
||||
let mut transaction_context =
|
||||
TransactionContext::new(transaction_accounts, Some(Rent::default()), 1, 1);
|
||||
transaction_context
|
||||
.get_next_instruction_context()
|
||||
.unwrap()
|
||||
.configure(
|
||||
&[0, 1],
|
||||
&[
|
||||
InstructionAccount {
|
||||
index_in_transaction: 2,
|
||||
index_in_caller: 2,
|
||||
index_in_callee: 0,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
},
|
||||
InstructionAccount {
|
||||
index_in_transaction: 3,
|
||||
index_in_caller: 3,
|
||||
index_in_callee: 0,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
},
|
||||
],
|
||||
&[],
|
||||
);
|
||||
let mut invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
|
||||
invoke_context.push().unwrap();
|
||||
|
||||
let keys = [loader_key];
|
||||
let updates_list = [
|
||||
AccountPropertyUpdate {
|
||||
instruction_account_index: 0,
|
||||
attribute: TransactionContextAttribute::TransactionAccountLamports as u16,
|
||||
value: 10000000,
|
||||
_marker: std::marker::PhantomData::default(),
|
||||
},
|
||||
AccountPropertyUpdate {
|
||||
instruction_account_index: 0,
|
||||
attribute: TransactionContextAttribute::TransactionAccountData as u16,
|
||||
value: 512,
|
||||
_marker: std::marker::PhantomData::default(),
|
||||
},
|
||||
AccountPropertyUpdate {
|
||||
instruction_account_index: 0,
|
||||
attribute: TransactionContextAttribute::TransactionAccountIsExecutable as u16,
|
||||
value: true as u64,
|
||||
_marker: std::marker::PhantomData::default(),
|
||||
},
|
||||
AccountPropertyUpdate {
|
||||
instruction_account_index: 1,
|
||||
attribute: TransactionContextAttribute::TransactionAccountOwner as u16,
|
||||
value: VM_ADDRESS_KEYS,
|
||||
_marker: std::marker::PhantomData::default(),
|
||||
},
|
||||
];
|
||||
|
||||
let cost = invoke_context
|
||||
.get_compute_budget()
|
||||
.syscall_base_cost
|
||||
.saturating_add(
|
||||
invoke_context
|
||||
.get_compute_budget()
|
||||
.account_property_update_cost
|
||||
.saturating_mul(updates_list.len() as u64),
|
||||
);
|
||||
|
||||
const VM_ADDRESS_KEYS: u64 = 0x100000000;
|
||||
const VM_ADDRESS_UPDATES_LIST: u64 = 0x200000000;
|
||||
let config = Config::default();
|
||||
let mut memory_mapping = MemoryMapping::new(
|
||||
vec![
|
||||
MemoryRegion {
|
||||
host_addr: keys.as_ptr() as u64,
|
||||
vm_addr: VM_ADDRESS_KEYS,
|
||||
len: (keys.len() * std::mem::size_of::<Pubkey>()) as u64,
|
||||
vm_gap_shift: 63,
|
||||
is_writable: true,
|
||||
},
|
||||
MemoryRegion {
|
||||
host_addr: updates_list.as_ptr() as u64,
|
||||
vm_addr: VM_ADDRESS_UPDATES_LIST,
|
||||
len: (updates_list.len() * std::mem::size_of::<AccountPropertyUpdate>()) as u64,
|
||||
vm_gap_shift: 63,
|
||||
is_writable: true,
|
||||
},
|
||||
],
|
||||
&config,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
invoke_context
|
||||
.get_compute_meter()
|
||||
.borrow_mut()
|
||||
.mock_set_remaining(cost);
|
||||
let mut result = ProgramResult::Ok(0);
|
||||
SyscallSetAccountProperties::call(
|
||||
&mut invoke_context,
|
||||
VM_ADDRESS_UPDATES_LIST,
|
||||
updates_list.len() as u64,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
&mut memory_mapping,
|
||||
&mut result,
|
||||
);
|
||||
assert_eq!(result.unwrap(), 0);
|
||||
{
|
||||
let transaction_context = &invoke_context.transaction_context;
|
||||
let account = transaction_context
|
||||
.get_account_at_index(2)
|
||||
.unwrap()
|
||||
.borrow();
|
||||
assert_eq!(account.lamports(), 10000000);
|
||||
assert_eq!(account.data().len(), 512);
|
||||
assert!(account.executable());
|
||||
let account = transaction_context
|
||||
.get_account_at_index(3)
|
||||
.unwrap()
|
||||
.borrow();
|
||||
assert_eq!(account.owner(), &loader_key);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_program_address() {
|
||||
// These tests duplicate the direct tests in solana_program::pubkey
|
||||
|
|
|
@ -743,34 +743,6 @@ pub fn get_stack_height() -> usize {
|
|||
}
|
||||
}
|
||||
|
||||
/// Used to specify which properties of which accounts to update
|
||||
/// when calling the `sol_set_account_properties` syscall.
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct AccountPropertyUpdate<'a> {
|
||||
/// Index of the account to update
|
||||
pub instruction_account_index: u16,
|
||||
/// Index of the property to update
|
||||
pub attribute: u16,
|
||||
/// Value to set, encoding depends on the attribute
|
||||
pub value: u64,
|
||||
/// Holds the lifetime parameter in case that the value is a pointer
|
||||
pub _marker: std::marker::PhantomData<&'a ()>,
|
||||
}
|
||||
|
||||
/// Sets properties of accounts according to the given list of updates
|
||||
pub fn set_account_properties(updates: &[AccountPropertyUpdate]) {
|
||||
#[cfg(target_os = "solana")]
|
||||
unsafe {
|
||||
crate::syscalls::sol_set_account_properties(updates.as_ptr(), updates.len() as u64);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "solana"))]
|
||||
{
|
||||
crate::program_stubs::sol_set_account_properties(updates);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_account_meta_layout() {
|
||||
#[derive(Debug, Default, PartialEq, Eq, Clone, Serialize, Deserialize)]
|
||||
|
|
|
@ -4,11 +4,8 @@
|
|||
|
||||
use {
|
||||
crate::{
|
||||
account_info::AccountInfo,
|
||||
entrypoint::ProgramResult,
|
||||
instruction::{AccountPropertyUpdate, Instruction},
|
||||
program_error::UNSUPPORTED_SYSVAR,
|
||||
pubkey::Pubkey,
|
||||
account_info::AccountInfo, entrypoint::ProgramResult, instruction::Instruction,
|
||||
program_error::UNSUPPORTED_SYSVAR, pubkey::Pubkey,
|
||||
},
|
||||
itertools::Itertools,
|
||||
std::sync::{Arc, RwLock},
|
||||
|
@ -100,7 +97,6 @@ pub trait SyscallStubs: Sync + Send {
|
|||
fn sol_get_stack_height(&self) -> u64 {
|
||||
0
|
||||
}
|
||||
fn sol_set_account_properties(&self, _updates: &[AccountPropertyUpdate]) {}
|
||||
}
|
||||
|
||||
struct DefaultSyscallStubs {}
|
||||
|
@ -198,13 +194,6 @@ pub(crate) fn sol_get_stack_height() -> u64 {
|
|||
SYSCALL_STUBS.read().unwrap().sol_get_stack_height()
|
||||
}
|
||||
|
||||
pub(crate) fn sol_set_account_properties(updates: &[AccountPropertyUpdate]) {
|
||||
SYSCALL_STUBS
|
||||
.read()
|
||||
.unwrap()
|
||||
.sol_set_account_properties(updates)
|
||||
}
|
||||
|
||||
/// Check that two regions do not overlap.
|
||||
///
|
||||
/// Hidden to share with bpf_loader without being part of the API surface.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
instruction::{AccountMeta, AccountPropertyUpdate, ProcessedSiblingInstruction},
|
||||
instruction::{AccountMeta, ProcessedSiblingInstruction},
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
|
||||
|
@ -61,7 +61,6 @@ define_syscall!(fn sol_get_return_data(data: *mut u8, length: u64, program_id: *
|
|||
define_syscall!(fn sol_log_data(data: *const u8, data_len: u64));
|
||||
define_syscall!(fn sol_get_processed_sibling_instruction(index: u64, meta: *mut ProcessedSiblingInstruction, program_id: *mut Pubkey, data: *mut u8, accounts: *mut AccountMeta) -> u64);
|
||||
define_syscall!(fn sol_get_stack_height() -> u64);
|
||||
define_syscall!(fn sol_set_account_properties(updates_addr: *const AccountPropertyUpdate, updates_count: u64));
|
||||
define_syscall!(fn sol_curve_validate_point(curve_id: u64, point_addr: *const u8, result: *mut u8) -> u64);
|
||||
define_syscall!(fn sol_curve_group_op(curve_id: u64, group_op: u64, left_input_addr: *const u8, right_input_addr: *const u8, result_point_addr: *mut u8) -> u64);
|
||||
define_syscall!(fn sol_curve_multiscalar_mul(curve_id: u64, scalars_addr: *const u8, points_addr: *const u8, points_len: u64, result_point_addr: *mut u8) -> u64);
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
//! Data shared between program runtime and built-in programs as well as SBF programs
|
||||
#![deny(clippy::indexing_slicing)]
|
||||
|
||||
#[cfg(target_os = "solana")]
|
||||
use crate::instruction::AccountPropertyUpdate;
|
||||
#[cfg(not(target_os = "solana"))]
|
||||
use crate::{
|
||||
account::WritableAccount,
|
||||
|
@ -24,59 +22,6 @@ use {
|
|||
},
|
||||
};
|
||||
|
||||
/// For addressing (nested) properties of the TransactionContext
|
||||
#[repr(u16)]
|
||||
pub enum TransactionContextAttribute {
|
||||
/// TransactionContext -> &[u8]
|
||||
ReturnData,
|
||||
/// TransactionContext -> u128
|
||||
AccountsResizeDelta,
|
||||
/// TransactionContext -> u16
|
||||
TransactionAccountCount,
|
||||
/// TransactionContext -> &[TransactionAccount] -> Pubkey
|
||||
TransactionAccountKey,
|
||||
/// TransactionContext -> &[TransactionAccount] -> Pubkey
|
||||
TransactionAccountOwner,
|
||||
/// TransactionContext -> &[TransactionAccount] -> u64
|
||||
TransactionAccountLamports,
|
||||
/// TransactionContext -> &[TransactionAccount] -> &[u8]
|
||||
TransactionAccountData,
|
||||
/// TransactionContext -> &[TransactionAccount] -> bool
|
||||
TransactionAccountIsExecutable,
|
||||
/// TransactionContext -> &[TransactionAccount] -> u64
|
||||
TransactionAccountRentEpoch,
|
||||
/// TransactionContext -> &[TransactionAccount] -> bool
|
||||
TransactionAccountTouchedFlag,
|
||||
/// TransactionContext -> u8
|
||||
InstructionStackHeight,
|
||||
/// TransactionContext -> u8
|
||||
InstructionStackCapacity,
|
||||
/// TransactionContext -> &[u8]
|
||||
InstructionStackEntry,
|
||||
/// TransactionContext -> u16
|
||||
InstructionTraceLength,
|
||||
/// TransactionContext -> u16
|
||||
InstructionTraceCapacity,
|
||||
/// TransactionContext -> &[InstructionContext] -> u8
|
||||
InstructionTraceNestingLevel,
|
||||
/// TransactionContext -> &[InstructionContext] -> u128
|
||||
InstructionTraceLamportSum,
|
||||
/// TransactionContext -> &[InstructionContext] -> &[u8]
|
||||
InstructionTraceInstructionData,
|
||||
/// TransactionContext -> &[InstructionContext] -> &[u16]
|
||||
InstructionTraceProgramAccount,
|
||||
/// TransactionContext -> &[InstructionContext] -> &[InstructionAccount] -> u16
|
||||
InstructionAccountIndexInTransaction,
|
||||
/// TransactionContext -> &[InstructionContext] -> &[InstructionAccount] -> u16
|
||||
InstructionAccountIndexInCaller,
|
||||
/// TransactionContext -> &[InstructionContext] -> &[InstructionAccount] -> u16
|
||||
InstructionAccountIndexInCallee,
|
||||
/// TransactionContext -> &[InstructionContext] -> &[InstructionAccount] -> bool
|
||||
InstructionAccountIsSigner,
|
||||
/// TransactionContext -> &[InstructionContext] -> &[InstructionAccount] -> bool
|
||||
InstructionAccountIsWritable,
|
||||
}
|
||||
|
||||
/// Index of an account inside of the TransactionContext or an InstructionContext.
|
||||
pub type IndexOfAccount = u16;
|
||||
|
||||
|
@ -752,16 +697,6 @@ impl<'a> BorrowedAccount<'a> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "solana")]
|
||||
pub fn set_owner<'b>(&mut self, pubkey: &'b [u8]) -> AccountPropertyUpdate<'b> {
|
||||
AccountPropertyUpdate {
|
||||
instruction_account_index: self.index_in_instruction as u16,
|
||||
attribute: TransactionContextAttribute::TransactionAccountOwner as u16,
|
||||
value: pubkey.as_ptr() as u64,
|
||||
_marker: std::marker::PhantomData::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the number of lamports of this account (transaction wide)
|
||||
#[inline]
|
||||
pub fn get_lamports(&self) -> u64 {
|
||||
|
@ -797,16 +732,6 @@ impl<'a> BorrowedAccount<'a> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "solana")]
|
||||
pub fn set_lamports(&mut self, lamports: u64) -> AccountPropertyUpdate<'static> {
|
||||
AccountPropertyUpdate {
|
||||
instruction_account_index: self.index_in_instruction as u16,
|
||||
attribute: TransactionContextAttribute::TransactionAccountLamports as u16,
|
||||
value: lamports,
|
||||
_marker: std::marker::PhantomData::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds lamports to this account (transaction wide)
|
||||
#[cfg(not(target_os = "solana"))]
|
||||
pub fn checked_add_lamports(&mut self, lamports: u64) -> Result<(), InstructionError> {
|
||||
|
@ -892,16 +817,6 @@ impl<'a> BorrowedAccount<'a> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "solana")]
|
||||
pub fn set_data_length(&mut self, new_length: usize) -> AccountPropertyUpdate<'static> {
|
||||
AccountPropertyUpdate {
|
||||
instruction_account_index: self.index_in_instruction as u16,
|
||||
attribute: TransactionContextAttribute::TransactionAccountData as u16,
|
||||
value: new_length as u64,
|
||||
_marker: std::marker::PhantomData::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Appends all elements in a slice to the account
|
||||
#[cfg(not(target_os = "solana"))]
|
||||
pub fn extend_from_slice(&mut self, data: &[u8]) -> Result<(), InstructionError> {
|
||||
|
@ -976,16 +891,6 @@ impl<'a> BorrowedAccount<'a> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "solana")]
|
||||
pub fn set_executable(&mut self, is_executable: bool) -> AccountPropertyUpdate<'static> {
|
||||
AccountPropertyUpdate {
|
||||
instruction_account_index: self.index_in_instruction as u16,
|
||||
attribute: TransactionContextAttribute::TransactionAccountIsExecutable as u16,
|
||||
value: is_executable as u64,
|
||||
_marker: std::marker::PhantomData::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the rent epoch of this account (transaction wide)
|
||||
#[cfg(not(target_os = "solana"))]
|
||||
#[inline]
|
||||
|
|
Loading…
Reference in New Issue