Skip to content

Commit 3d1d9bd

Browse files
jbertholddkcumming
andauthored
Fix checks and their ordering in some proofs, update mir-semantics dependency (#134)
* `withdraw_excess_lamports_account` used a wrong error code for the overflow case * `withdraw_excess_lamports_mint` skipped checking overflow errors when the mint auth flag was set * `transfer_checked` had a stray `assert(result.is_ok())` placed before some error checks * `close_account` skipped checking for overflow when the account was owned by system or incinerator Also updates the `mir-semantics` dependency to the latest feature branch. --------- Co-authored-by: Daniel Cumming <[email protected]>
1 parent f9a2014 commit 3d1d9bd

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

p-token/src/entrypoint-runtime-verification.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,19 +1815,21 @@ pub fn test_process_close_account(accounts: &[AccountInfo; 3]) -> ProgramResult
18151815
} else if accounts[1].key() != &INCINERATOR_ID {
18161816
assert_eq!(result, Err(ProgramError::InvalidAccountData));
18171817
return result;
1818-
} else if dst_init_lamports.checked_add(src_init_lamports).is_none() {
1818+
}
1819+
if dst_init_lamports.checked_add(src_init_lamports).is_none() {
18191820
assert_eq!(result, Err(ProgramError::Custom(14)));
18201821
return result;
18211822
}
1823+
assert!(result.is_ok());
18221824

18231825
// Validate owner falls through to here if no error
18241826
assert_eq!(accounts[0].lamports(), 0);
18251827
assert_eq!(
18261828
accounts[1].lamports(),
18271829
dst_init_lamports + src_init_lamports
18281830
);
1829-
assert_eq!(accounts[0].data_len(), 0); // TODO: More sol_memset stuff?
1830-
assert!(result.is_ok());
1831+
#[cfg(any(target_os = "solana", target_arch = "bpf"))]
1832+
assert_eq!(accounts[0].data_len(), 0); // Solana-RT only
18311833
}
18321834
result
18331835
}
@@ -2042,8 +2044,6 @@ pub fn test_process_transfer_checked(
20422044
assert_eq!(result, Err(ProgramError::IncorrectProgramId));
20432045
return result;
20442046
}
2045-
assert!(result.is_ok());
2046-
20472047
if accounts[0] != accounts[2] && amount != 0 {
20482048
if src_new.is_native() && src_initial_lamports < amount {
20492049
// Not sure how to fund native mint
@@ -2066,6 +2066,7 @@ pub fn test_process_transfer_checked(
20662066
assert_eq!(accounts[1].lamports(), dst_initial_lamports + amount);
20672067
}
20682068
}
2069+
assert!(result.is_ok());
20692070

20702071
// Delegate updates
20712072
if old_src_delgate == Some(*accounts[3].key()) && accounts[0] != accounts[2] {
@@ -4504,7 +4505,7 @@ fn test_process_withdraw_excess_lamports_account(accounts: &[AccountInfo; 3]) ->
45044505
.checked_add(src_init_lamports - minimum_balance)
45054506
.is_none()
45064507
{
4507-
assert_eq!(result, Err(ProgramError::Custom(0)));
4508+
assert_eq!(result, Err(ProgramError::Custom(14)));
45084509
return result;
45094510
}
45104511

@@ -4651,26 +4652,29 @@ fn test_process_withdraw_excess_lamports_mint(accounts: &[AccountInfo; 3]) -> Pr
46514652
} else if !accounts[2].is_signer() {
46524653
assert_eq!(result, Err(ProgramError::MissingRequiredSignature));
46534654
return result;
4654-
} else if src_init_lamports < minimum_balance {
4655+
}
4656+
4657+
if src_init_lamports < minimum_balance {
46554658
assert_eq!(result, Err(ProgramError::Custom(0)));
46564659
return result;
46574660
} else if dst_init_lamports
46584661
.checked_add(src_init_lamports - minimum_balance)
46594662
.is_none()
46604663
{
4661-
assert_eq!(result, Err(ProgramError::Custom(0)));
4664+
assert_eq!(result, Err(ProgramError::Custom(14)));
46624665
return result;
46634666
}
46644667

4668+
assert!(result.is_ok());
46654669
assert_eq!(accounts[0].lamports(), minimum_balance);
46664670
assert_eq!(
46674671
accounts[1].lamports(),
4668-
dst_init_lamports + (src_init_lamports - minimum_balance)
4672+
dst_init_lamports
4673+
.checked_add(src_init_lamports - minimum_balance)
4674+
.unwrap()
46694675
);
4670-
assert!(result.is_ok())
46714676
}
46724677
}
4673-
46744678
result
46754679
}
46764680

p-token/test-properties/select-proofs.sh

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,32 @@ sed -n -e "/^| ${HEADING}.*/,/^\$/ {/| ${HEADING}.*/d; /^\$/q; s/^| \(test_p[a-z
2424
| Passing |
2525
|-----------------------------------------|
2626
| test_ptoken_domain_data |
27+
| test_process_approve_checked |
28+
| test_process_approve |
29+
| test_process_freeze_account |
2730
| test_process_get_account_data_size |
31+
| test_process_initialize_account2 |
32+
| test_process_initialize_account3 |
33+
| test_process_initialize_account |
2834
| test_process_initialize_immutable_owner |
2935
| test_process_initialize_mint2_freeze |
3036
| test_process_initialize_mint2_no_freeze |
3137
| test_process_initialize_mint_freeze |
3238
| test_process_initialize_mint_no_freeze |
39+
| test_process_mint_to_checked |
40+
| test_process_mint_to |
3341
| test_process_revoke |
42+
| test_process_set_authority_account |
3443
| test_process_set_authority_mint |
3544
| test_process_sync_native |
45+
| test_process_thaw_account |
46+
| test_process_transfer |
47+
| test_process_withdraw_excess_lamports_account |
48+
| test_process_withdraw_excess_lamports_mint |
3649
3750
| Failing nodes |
3851
|-----------------------------------------------|
39-
| test_process_approve_checked |
40-
| test_process_approve |
4152
| test_process_close_account |
42-
| test_process_freeze_account |
43-
| test_process_initialize_account2 |
44-
| test_process_initialize_account3 |
45-
| test_process_initialize_account |
46-
| test_process_mint_to_checked |
47-
| test_process_mint_to |
48-
| test_process_set_authority_account |
49-
| test_process_thaw_account |
50-
| test_process_withdraw_excess_lamports_account |
51-
| test_process_withdraw_excess_lamports_mint |
5253
5354
| Long-running (2h+) |
5455
|-------------------------------|

0 commit comments

Comments
 (0)