Skip to content

Commit b059889

Browse files
committed
apply #134: Fix checks and their ordering in some proofs
1 parent 6e1ef2d commit b059889

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

program/src/entrypoint-runtime-verification.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3240,16 +3240,21 @@ fn test_process_close_account(
32403240
} else if accounts[1].key != &INCINERATOR_ID {
32413241
assert_eq!(result, Err(ProgramError::InvalidAccountData));
32423242
return result;
3243-
} else if dst_init_lamports.checked_add(src_init_lamports).is_none() {
3243+
}
3244+
if dst_init_lamports.checked_add(src_init_lamports).is_none() {
32443245
assert_eq!(result, Err(ProgramError::Custom(14)));
32453246
return result;
32463247
}
3248+
assert!(result.is_ok());
32473249

32483250
// Validate owner falls through to here if no error
3249-
assert_eq!(accounts[1].lamports(), dst_init_lamports + src_init_lamports);
32503251
assert_eq!(accounts[0].lamports(), 0);
3251-
assert_eq!(accounts[0].data_len(), 0); // TODO: More sol_memset stuff?
3252-
assert!(result.is_ok());
3252+
assert_eq!(
3253+
accounts[1].lamports(),
3254+
dst_init_lamports + src_init_lamports
3255+
);
3256+
#[cfg(any(target_os = "solana", target_arch = "bpf"))]
3257+
assert_eq!(accounts[0].data_len(), 0); // Solana-RT only
32533258
}
32543259

32553260
// Ensure instruction_data was not mutated
@@ -3810,9 +3815,6 @@ fn test_process_transfer_checked(
38103815
assert_eq!(result, Err(ProgramError::IncorrectProgramId));
38113816
return result;
38123817
}
3813-
3814-
assert!(result.is_ok());
3815-
38163818
if accounts[0].key != accounts[2].key && amount != 0 {
38173819
if get_account(&accounts[0]).is_native() && src_initial_lamports < amount {
38183820
// Not sure how to fund native mint
@@ -3834,6 +3836,7 @@ fn test_process_transfer_checked(
38343836
assert_eq!(accounts[1].lamports(), dst_initial_lamports + amount);
38353837
}
38363838
}
3839+
assert!(result.is_ok());
38373840

38383841
// Delegate updates
38393842
if old_src_delgate == Some(*accounts[3].key) && accounts[0].key != accounts[2].key {
@@ -4995,16 +4998,18 @@ fn test_process_withdraw_excess_lamports_account(
49954998
.checked_add(src_init_lamports - minimum_balance)
49964999
.is_none()
49975000
{
4998-
assert_eq!(result, Err(ProgramError::Custom(0)));
5001+
assert_eq!(result, Err(ProgramError::Custom(14)));
49995002
return result;
50005003
}
50015004

5005+
assert!(result.is_ok());
50025006
assert_eq!(accounts[0].lamports(), minimum_balance);
50035007
assert_eq!(
50045008
accounts[1].lamports(),
5005-
dst_init_lamports + (src_init_lamports - minimum_balance)
5009+
dst_init_lamports
5010+
.checked_add(src_init_lamports - minimum_balance)
5011+
.unwrap()
50065012
);
5007-
assert!(result.is_ok())
50085013
}
50095014
}
50105015

@@ -5173,26 +5178,27 @@ fn test_process_withdraw_excess_lamports_mint(
51735178
return result;
51745179
}
51755180

5176-
else if src_init_lamports < minimum_balance {
5181+
if src_init_lamports < minimum_balance {
51775182
assert_eq!(result, Err(ProgramError::Custom(0)));
51785183
return result;
51795184
} else if dst_init_lamports
51805185
.checked_add(src_init_lamports - minimum_balance)
51815186
.is_none()
51825187
{
5183-
assert_eq!(result, Err(ProgramError::Custom(0)));
5188+
assert_eq!(result, Err(ProgramError::Custom(14)));
51845189
return result;
51855190
}
51865191

5192+
assert!(result.is_ok());
51875193
assert_eq!(accounts[0].lamports(), minimum_balance);
51885194
assert_eq!(
51895195
accounts[1].lamports(),
5190-
dst_init_lamports + (src_init_lamports - minimum_balance)
5196+
dst_init_lamports
5197+
.checked_add(src_init_lamports - minimum_balance)
5198+
.unwrap()
51915199
);
5192-
assert!(result.is_ok())
51935200
}
51945201
}
5195-
51965202
// Ensure instruction_data was not mutated
51975203
assert_eq!(*instruction_data, instruction_data_with_discriminator[1..]);
51985204

0 commit comments

Comments
 (0)