-
Notifications
You must be signed in to change notification settings - Fork 245
feat: (PRO-255) add adversarial tests for fee payer policy violations… #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dev-jodee
merged 2 commits into
release/feature-freeze-for-audit
from
feat/pro-252-adversary-testing
Sep 23, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| use crate::common::{assertions::RpcErrorAssertions, *}; | ||
| use jsonrpsee::rpc_params; | ||
| use solana_sdk::{signer::Signer, transaction::Transaction}; | ||
| use solana_system_interface::instruction::transfer; | ||
| use spl_associated_token_account::get_associated_token_address; | ||
| use spl_token::instruction as token_instruction; | ||
|
|
||
| #[tokio::test] | ||
| async fn test_fee_payer_as_sol_transfer_source() { | ||
| let ctx = TestContext::new().await.expect("Failed to create test context"); | ||
| let setup = TestAccountSetup::new().await; | ||
|
|
||
| let fee_payer_pubkey = FeePayerTestHelper::get_fee_payer_pubkey(); | ||
|
|
||
| let large_sol_transfer = transfer( | ||
| &fee_payer_pubkey, | ||
| &setup.sender_keypair.pubkey(), | ||
| 1_000_000, // 0.001 SOL in lamports | ||
| ); | ||
|
|
||
| let malicious_tx = ctx | ||
| .transaction_builder() | ||
| .with_fee_payer(fee_payer_pubkey) | ||
| .with_spl_payment( | ||
| &setup.usdc_mint.pubkey(), | ||
| &setup.sender_keypair.pubkey(), | ||
| &fee_payer_pubkey, | ||
| 10, // Small payment: 0.00001 USDC tokens (much less than 0.001 SOL value) | ||
| ) | ||
| .with_instruction(large_sol_transfer) | ||
| .build() | ||
| .await | ||
| .expect("Failed to create transaction with fee payer as SOL source"); | ||
|
|
||
| let result = ctx | ||
| .rpc_call::<serde_json::Value, _>("signTransactionIfPaid", rpc_params![malicious_tx]) | ||
| .await; | ||
|
|
||
| match result { | ||
| Err(error) => { | ||
| error.assert_contains_message("Insufficient token payment"); | ||
| } | ||
| Ok(_) => panic!("Expected error for fee payer as SOL transfer source"), | ||
| } | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_fee_payer_as_spl_transfer_source() { | ||
| let ctx = TestContext::new().await.expect("Failed to create test context"); | ||
| let setup = TestAccountSetup::new().await; | ||
|
|
||
| let fee_payer_pubkey = FeePayerTestHelper::get_fee_payer_pubkey(); | ||
|
|
||
| let fee_payer_token_account = | ||
| get_associated_token_address(&fee_payer_pubkey, &setup.usdc_mint.pubkey()); | ||
| let sender_token_account = | ||
| get_associated_token_address(&setup.sender_keypair.pubkey(), &setup.usdc_mint.pubkey()); | ||
|
|
||
| // Mint tokens for the fee payer | ||
| setup | ||
| .mint_tokens_to_account(&fee_payer_token_account, 100_000) | ||
| .await | ||
| .expect("Failed to mint tokens"); | ||
|
|
||
| // Run the test transaction | ||
| let large_token_transfer = token_instruction::transfer( | ||
| &spl_token::id(), | ||
| &fee_payer_token_account, | ||
| &sender_token_account, | ||
| &fee_payer_pubkey, | ||
| &[&fee_payer_pubkey], | ||
| 100_000, | ||
| ) | ||
| .expect("Failed to create token transfer instruction"); | ||
|
|
||
| let malicious_tx = ctx | ||
| .transaction_builder() | ||
| .with_fee_payer(fee_payer_pubkey) | ||
| .with_spl_payment( | ||
| &setup.usdc_mint.pubkey(), | ||
| &setup.sender_keypair.pubkey(), | ||
| &fee_payer_pubkey, | ||
| 1_000, // Smaller than the 100,000 USDC transfer | ||
| ) | ||
| .with_instruction(large_token_transfer) | ||
| .build() | ||
| .await | ||
| .expect("Failed to create transaction with fee payer as USDC source"); | ||
|
|
||
| let result = ctx | ||
| .rpc_call::<serde_json::Value, _>("signTransactionIfPaid", rpc_params![malicious_tx]) | ||
| .await; | ||
|
|
||
| match result { | ||
| Err(error) => { | ||
| error.assert_contains_message("Insufficient token payment"); | ||
| } | ||
| Ok(_) => panic!("Expected error for fee payer as USDC transfer source"), | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Adversarial Basic Tests | ||
| // | ||
| // CONFIG: Uses tests/src/common/fixtures/kora-test.toml (permissive policies) | ||
| // TESTS: Security and robustness testing with normal configuration | ||
| // - Program validation attacks (disallowed programs) | ||
| // - Invalid token states (frozen) | ||
| // - Fee payer exploitation | ||
|
|
||
| mod fee_payer_exploitation; | ||
| mod program_validation; | ||
| mod token_states; | ||
|
|
||
| // Make common utilities available | ||
| #[path = "../src/common/mod.rs"] | ||
| mod common; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| use crate::common::{assertions::RpcErrorAssertions, *}; | ||
| use jsonrpsee::rpc_params; | ||
| use solana_sdk::{instruction::Instruction, pubkey::Pubkey}; | ||
| use std::str::FromStr; | ||
|
|
||
| #[tokio::test] | ||
| async fn test_disallowed_memo_program() { | ||
| let ctx = TestContext::new().await.expect("Failed to create test context"); | ||
|
|
||
| let disallowed_program_id = Pubkey::from_str("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr") | ||
| .expect("Failed to parse SPL Memo program ID"); | ||
|
|
||
| let malicious_instruction = Instruction::new_with_bincode(disallowed_program_id, &(), vec![]); | ||
|
|
||
| let malicious_tx = ctx | ||
| .transaction_builder() | ||
| .with_fee_payer(FeePayerTestHelper::get_fee_payer_pubkey()) | ||
| .with_instruction(malicious_instruction) | ||
| .build() | ||
| .await | ||
| .expect("Failed to create transaction with disallowed program"); | ||
|
|
||
| let result = | ||
| ctx.rpc_call::<serde_json::Value, _>("signTransaction", rpc_params![malicious_tx]).await; | ||
|
|
||
| match result { | ||
| Err(error) => { | ||
| let expected_message = | ||
| format!("Program {disallowed_program_id} is not in the allowed list"); | ||
| error.assert_error_type_and_message("Invalid transaction", &expected_message); | ||
| } | ||
| Ok(_) => panic!("Expected error for transaction with disallowed program"), | ||
| } | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_disallowed_program_v0_transaction() { | ||
| let ctx = TestContext::new().await.expect("Failed to create test context"); | ||
|
|
||
| let disallowed_program_id = Pubkey::from_str("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr") | ||
| .expect("Failed to parse BPF Loader Upgradeable program ID"); | ||
|
|
||
| let malicious_instruction = Instruction::new_with_bincode(disallowed_program_id, &(), vec![]); | ||
|
|
||
| let malicious_tx = ctx | ||
| .v0_transaction_builder() | ||
| .with_fee_payer(FeePayerTestHelper::get_fee_payer_pubkey()) | ||
| .with_instruction(malicious_instruction) | ||
| .build() | ||
| .await | ||
| .expect("Failed to create V0 transaction with disallowed program"); | ||
|
|
||
| let result = | ||
| ctx.rpc_call::<serde_json::Value, _>("signTransaction", rpc_params![malicious_tx]).await; | ||
|
|
||
| match result { | ||
| Err(error) => { | ||
| let expected_message = | ||
| format!("Program {disallowed_program_id} is not in the allowed list"); | ||
| error.assert_error_type_and_message("Invalid transaction", &expected_message); | ||
| } | ||
| Ok(_) => panic!("Expected error for V0 transaction with disallowed program"), | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| use crate::common::{assertions::RpcErrorAssertions, *}; | ||
| use jsonrpsee::rpc_params; | ||
| use solana_sdk::{ | ||
| program_pack::Pack, signature::Keypair, signer::Signer, transaction::Transaction, | ||
| }; | ||
| use solana_system_interface::instruction::create_account; | ||
| use spl_associated_token_account::get_associated_token_address; | ||
| use spl_token::instruction as token_instruction; | ||
|
|
||
| #[tokio::test] | ||
| async fn test_frozen_token_account_as_fee_payment() { | ||
| let ctx = TestContext::new().await.expect("Failed to create test context"); | ||
| let setup = TestAccountSetup::new().await; | ||
|
|
||
| let frozen_token_account_keypair = Keypair::new(); | ||
|
|
||
| let rent = setup | ||
| .rpc_client | ||
| .get_minimum_balance_for_rent_exemption(spl_token::state::Account::LEN) | ||
| .await | ||
| .expect("Failed to get rent exemption"); | ||
|
|
||
| let create_account_ix = create_account( | ||
| &setup.sender_keypair.pubkey(), | ||
| &frozen_token_account_keypair.pubkey(), | ||
| rent, | ||
| spl_token::state::Account::LEN as u64, | ||
| &spl_token::id(), | ||
| ); | ||
|
|
||
| let create_frozen_token_account_ix = spl_token::instruction::initialize_account( | ||
| &spl_token::id(), | ||
| &frozen_token_account_keypair.pubkey(), | ||
| &setup.usdc_mint.pubkey(), | ||
| &setup.sender_keypair.pubkey(), | ||
| ) | ||
| .expect("Failed to create initialize account instruction"); | ||
|
|
||
| let mint_tokens_ix = token_instruction::mint_to( | ||
| &spl_token::id(), | ||
| &setup.usdc_mint.pubkey(), | ||
| &frozen_token_account_keypair.pubkey(), | ||
| &setup.sender_keypair.pubkey(), | ||
| &[&setup.sender_keypair.pubkey()], | ||
| 100_000, | ||
| ) | ||
| .expect("Failed to create mint instruction"); | ||
|
|
||
| let freeze_instruction = token_instruction::freeze_account( | ||
| &spl_token::id(), | ||
| &frozen_token_account_keypair.pubkey(), | ||
| &setup.usdc_mint.pubkey(), | ||
| &setup.sender_keypair.pubkey(), | ||
| &[&setup.sender_keypair.pubkey()], | ||
| ) | ||
| .expect("Failed to create freeze instruction"); | ||
|
|
||
| let recent_blockhash = setup.rpc_client.get_latest_blockhash().await.unwrap(); | ||
| let setup_tx = Transaction::new_signed_with_payer( | ||
| &[create_account_ix, create_frozen_token_account_ix, mint_tokens_ix, freeze_instruction], | ||
| Some(&setup.sender_keypair.pubkey()), | ||
| &[&setup.sender_keypair, &frozen_token_account_keypair], | ||
| recent_blockhash, | ||
| ); | ||
|
|
||
| setup | ||
| .rpc_client | ||
| .send_and_confirm_transaction(&setup_tx) | ||
| .await | ||
| .expect("Failed to setup and freeze token account"); | ||
|
|
||
| let malicious_tx = ctx | ||
| .transaction_builder() | ||
| .with_fee_payer(FeePayerTestHelper::get_fee_payer_pubkey()) | ||
| .with_spl_payment_with_accounts( | ||
| &frozen_token_account_keypair.pubkey(), | ||
| &get_associated_token_address( | ||
| &FeePayerTestHelper::get_fee_payer_pubkey(), | ||
| &setup.usdc_mint.pubkey(), | ||
| ), | ||
| &setup.sender_keypair.pubkey(), | ||
| 50_000, | ||
| ) | ||
| .build() | ||
| .await | ||
| .expect("Failed to create transaction with frozen fee payer token account"); | ||
|
|
||
| let result = | ||
| ctx.rpc_call::<serde_json::Value, _>("signTransaction", rpc_params![malicious_tx]).await; | ||
|
|
||
| match result { | ||
| // 0x11: Frozen token account | ||
| Err(error) => { | ||
| error.assert_contains_message("custom program error: 0x11"); | ||
| } | ||
| Ok(_) => panic!("Expected error for transaction with frozen fee payment account"), | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.