From d3a1d866b3ff8b9753f9ed6ac93dee7d5162f9c0 Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Sat, 16 Sep 2023 08:41:21 -0700 Subject: [PATCH] Fix lamport calculation and transfer for loader-v4 program upgrade --- programs/loader-v4/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/loader-v4/src/lib.rs b/programs/loader-v4/src/lib.rs index 312c14f7acf888..817ee5e5f3224c 100644 --- a/programs/loader-v4/src/lib.rs +++ b/programs/loader-v4/src/lib.rs @@ -429,8 +429,8 @@ pub fn process_instruction_deploy( load_program_metrics.submit_datapoint(&mut invoke_context.timings); if let Some(mut source_program) = source_program { let rent = invoke_context.get_sysvar_cache().get_rent()?; - let required_lamports = rent.minimum_balance(program.get_data().len()); - let transfer_lamports = program.get_lamports().saturating_sub(required_lamports); + let required_lamports = rent.minimum_balance(source_program.get_data().len()); + let transfer_lamports = required_lamports.saturating_sub(program.get_lamports()); program.set_data_from_slice(source_program.get_data())?; source_program.set_data_length(0)?; source_program.checked_sub_lamports(transfer_lamports)?;