Add SystemInstruction::CreateAccount support to CPI (#11649)
This commit is contained in:
@ -256,6 +256,11 @@ typedef struct {
|
||||
const SolPubkey *program_id; /** program_id of the currently executing program */
|
||||
} SolParameters;
|
||||
|
||||
/**
|
||||
* Maximum number of bytes a program may add to an account during a single realloc
|
||||
*/
|
||||
#define MAX_PERMITTED_DATA_INCREASE (1024 * 10)
|
||||
|
||||
/**
|
||||
* De-serializes the input parameters into usable types
|
||||
*
|
||||
@ -297,6 +302,7 @@ static bool sol_deserialize(
|
||||
uint64_t data_len = *(uint64_t *) input;
|
||||
input += sizeof(uint64_t);
|
||||
input += data_len;
|
||||
input += MAX_PERMITTED_DATA_INCREASE;
|
||||
input = (uint8_t*)(((uint64_t)input + 8 - 1) & ~(8 - 1)); // padding
|
||||
input += sizeof(uint64_t);
|
||||
}
|
||||
@ -334,6 +340,7 @@ static bool sol_deserialize(
|
||||
input += sizeof(uint64_t);
|
||||
params->ka[i].data = (uint8_t *) input;
|
||||
input += params->ka[i].data_len;
|
||||
input += MAX_PERMITTED_DATA_INCREASE;
|
||||
input = (uint8_t*)(((uint64_t)input + 8 - 1) & ~(8 - 1)); // padding
|
||||
|
||||
// rent epoch
|
||||
|
@ -48,6 +48,9 @@ macro_rules! entrypoint {
|
||||
};
|
||||
}
|
||||
|
||||
/// Maximum number of bytes a program may add to an account during a single realloc
|
||||
pub const MAX_PERMITTED_DATA_INCREASE: usize = 1_024 * 10;
|
||||
|
||||
/// Deserialize the input arguments
|
||||
///
|
||||
/// # Safety
|
||||
@ -99,7 +102,7 @@ pub unsafe fn deserialize<'a>(input: *mut u8) -> (&'a Pubkey, Vec<AccountInfo<'a
|
||||
let data = Rc::new(RefCell::new({
|
||||
from_raw_parts_mut(input.add(offset), data_len)
|
||||
}));
|
||||
offset += data_len;
|
||||
offset += data_len + MAX_PERMITTED_DATA_INCREASE;
|
||||
offset += (offset as *const u8).align_offset(align_of::<u128>()); // padding
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
|
@ -159,6 +159,10 @@ pub enum InstructionError {
|
||||
/// Provided seeds do not result in a valid address
|
||||
#[error("Provided seeds do not result in a valid address")]
|
||||
InvalidSeeds,
|
||||
|
||||
// Failed to reallocate account data of this length
|
||||
#[error("Failed to reallocate account data")]
|
||||
InvalidRealloc,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
|
Reference in New Issue
Block a user