Skip to content

Commit

Permalink
fix: require up to date delegator record when slashing (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos authored Sep 10, 2024
1 parent 381604a commit c797b1a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
38 changes: 27 additions & 11 deletions staking/integration-tests/tests/integrity_pool_slash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,6 @@ fn test_slash() {
post_dummy_publisher_caps(&mut svm, &payer, publisher_keypair.pubkey(), 50);
advance(&mut svm, &payer, publisher_caps).unwrap();

advance_delegation_record(
&mut svm,
&payer,
publisher_keypair.pubkey(),
stake_account_positions,
pyth_token_mint.pubkey(),
pool_data_pubkey,
None,
)
.unwrap();

// undelegate 2 PYTH at epoch N + 2
undelegate(
&mut svm,
Expand Down Expand Up @@ -373,6 +362,32 @@ fn test_slash() {
}
);

assert_anchor_program_error!(
slash(
&mut svm,
&payer,
stake_account_positions,
0,
slash_custody,
publisher_keypair.pubkey(),
pool_data_pubkey,
),
IntegrityPoolError::OutdatedDelegatorAccounting,
0
);
svm.expire_blockhash();

advance_delegation_record(
&mut svm,
&payer,
publisher_keypair.pubkey(),
stake_account_positions,
pyth_token_mint.pubkey(),
pool_data_pubkey,
None,
)
.unwrap();

assert_anchor_program_error!(
slash(
&mut svm,
Expand All @@ -387,6 +402,7 @@ fn test_slash() {
0
);


slash(
&mut svm,
&payer,
Expand Down
3 changes: 3 additions & 0 deletions staking/programs/integrity-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ pub mod integrity_pool {

let current_epoch = get_current_epoch()?;

// assert delegator record is up to date
delegation_record.assert_up_to_date(current_epoch)?;

require_gte!(
current_epoch,
slash_event.epoch,
Expand Down

0 comments on commit c797b1a

Please sign in to comment.