From d1c76bf9f358bf1cc79cbc39a8aeed2c2e3f9c3c Mon Sep 17 00:00:00 2001 From: lukacan Date: Tue, 12 Nov 2024 15:22:37 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Tidy=20up=20accountsstorages=20+?= =?UTF-8?q?=20remove=20unnecessary=20methids=20for=20FuzzClient?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + Cargo.lock | 87 ++--- Cargo.toml | 2 + crates/client/src/lib.rs | 8 + crates/fuzz/Cargo.toml | 4 +- crates/fuzz/src/accounts_storage.rs | 326 ------------------ .../src/accounts_storage/keypair_store.rs | 43 +++ .../fuzz/src/accounts_storage/mint_store.rs | 69 ++++ crates/fuzz/src/accounts_storage/mod.rs | 56 +++ crates/fuzz/src/accounts_storage/pda_store.rs | 61 ++++ .../src/accounts_storage/program_store.rs | 35 ++ .../fuzz/src/accounts_storage/stake_store.rs | 126 +++++++ .../fuzz/src/accounts_storage/token_store.rs | 87 +++++ .../fuzz/src/accounts_storage/vote_store.rs | 78 +++++ crates/fuzz/src/fuzz_client.rs | 70 +--- .../fuzz/src/program_test_client_blocking.rs | 268 +------------- crates/fuzz/src/snapshot.rs | 7 +- .../docs/features/account-storages.md | 15 +- .../docs/features/fuzz-instructions.md | 1 + .../arbitrary-custom-types-4/Cargo.lock | 14 +- .../fuzz_tests/fuzz_0/fuzz_instructions.rs | 4 +- .../arbitrary-limit-inputs-5/Cargo.lock | 14 +- .../fuzz_tests/fuzz_0/fuzz_instructions.rs | 7 +- examples/fuzz-tests/cpi-metaplex-7/Cargo.lock | 14 +- .../fuzz_tests/fuzz_0/fuzz_instructions.rs | 4 +- examples/fuzz-tests/hello_world/Cargo.lock | 2 + .../fuzz_tests/fuzz_0/fuzz_instructions.rs | 3 +- .../fuzz_tests/fuzz_1/fuzz_instructions.rs | 107 ------ .../incorrect-integer-arithmetic-3/Cargo.lock | 14 +- .../fuzz_tests/fuzz_0/fuzz_instructions.rs | 7 +- .../incorrect-ix-sequence-1/Cargo.lock | 14 +- .../fuzz_tests/fuzz_0/fuzz_instructions.rs | 12 +- examples/fuzz-tests/simple-cpi-6/Cargo.lock | 14 +- .../fuzz_tests/fuzz_0/fuzz_instructions.rs | 2 +- .../unauthorized-access-2/Cargo.lock | 283 ++------------- .../fuzz_tests/fuzz_0/fuzz_instructions.rs | 6 +- .../unchecked-arithmetic-0/Cargo.lock | 14 +- .../fuzz_tests/fuzz_0/fuzz_instructions.rs | 4 +- 38 files changed, 721 insertions(+), 1162 deletions(-) delete mode 100644 crates/fuzz/src/accounts_storage.rs create mode 100644 crates/fuzz/src/accounts_storage/keypair_store.rs create mode 100644 crates/fuzz/src/accounts_storage/mint_store.rs create mode 100644 crates/fuzz/src/accounts_storage/mod.rs create mode 100644 crates/fuzz/src/accounts_storage/pda_store.rs create mode 100644 crates/fuzz/src/accounts_storage/program_store.rs create mode 100644 crates/fuzz/src/accounts_storage/stake_store.rs create mode 100644 crates/fuzz/src/accounts_storage/token_store.rs create mode 100644 crates/fuzz/src/accounts_storage/vote_store.rs delete mode 100644 examples/fuzz-tests/hello_world/trident-tests/fuzz_tests/fuzz_1/fuzz_instructions.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index b616bedf2..f20a49fdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ incremented upon a breaking change and the patch version will be incremented for **Changed** +- improve AccountsStorage module structure and remove unnecessary methods in FuzzClient ([223](https://github.com/Ackee-Blockchain/trident/pull/223)) - improve manipulations with AccountsStorages in get_accounts() function ([219](https://github.com/Ackee-Blockchain/trident/pull/219)) **Added** diff --git a/Cargo.lock b/Cargo.lock index 1d53bb107..60813ae1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -784,11 +784,11 @@ dependencies = [ [[package]] name = "borsh" -version = "1.5.1" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6362ed55def622cddc70a4746a68554d7b687713770de539e59a739b249f8ed" +checksum = "f5327f6c99920069d1fe374aa743be1af0031dea9f250852cdf1ae6a0861ee24" dependencies = [ - "borsh-derive 1.5.1", + "borsh-derive 1.5.2", "cfg_aliases", ] @@ -820,16 +820,15 @@ dependencies = [ [[package]] name = "borsh-derive" -version = "1.5.1" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3ef8005764f53cd4dca619f5bf64cafd4664dada50ece25e4d81de54c80cc0b" +checksum = "10aedd8f1a81a8aafbfde924b0e3061cd6fedd6f6bbcfc6a76e6fd426d7bfe26" dependencies = [ "once_cell", "proc-macro-crate 3.2.0", "proc-macro2", "quote", "syn 2.0.87", - "syn_derive", ] [[package]] @@ -1025,9 +1024,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.36" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baee610e9452a8f6f0a1b6194ec09ff9e2d85dea54432acdae41aa0761c95d70" +checksum = "1aeb932158bd710538c73702db6945cb68a8fb08c519e6e12706b94263b36db8" dependencies = [ "jobserver", "libc", @@ -1268,9 +1267,9 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +checksum = "0ca741a962e1b0bff6d724a1a0958b686406e853bb14061f218562e1896f95e6" dependencies = [ "libc", ] @@ -1419,9 +1418,9 @@ dependencies = [ [[package]] name = "csv" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe" +checksum = "acdc4883a9c96732e4733212c01447ebd805833b7275a73ca3ee080fd77afdaf" dependencies = [ "csv-core", "itoa", @@ -1840,9 +1839,9 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "fastrand" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" +checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" [[package]] name = "feature-probe" @@ -2681,9 +2680,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.161" +version = "0.2.162" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" +checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" [[package]] name = "libredox" @@ -3746,9 +3745,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -3887,9 +3886,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.39" +version = "0.38.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "375116bee2be9ed569afe2154ea6a99dfdffd257f533f187498c2a8f5feaf4ee" +checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0" dependencies = [ "bitflags 2.6.0", "errno", @@ -4022,9 +4021,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.12.0" +version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" dependencies = [ "core-foundation-sys", "libc", @@ -4050,9 +4049,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.214" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] @@ -4068,9 +4067,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.214" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", @@ -4400,7 +4399,7 @@ version = "1.18.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e58fa66e1e240097665e7f87b267aa8e976ea3fcbd86918c8fd218c875395ada" dependencies = [ - "borsh 1.5.1", + "borsh 1.5.2", "futures", "solana-banks-interface", "solana-program", @@ -4758,7 +4757,7 @@ dependencies = [ "blake3", "borsh 0.10.4", "borsh 0.9.3", - "borsh 1.5.1", + "borsh 1.5.2", "bs58 0.4.0", "bv", "bytemuck", @@ -5084,7 +5083,7 @@ dependencies = [ "base64 0.21.7", "bincode", "bitflags 2.6.0", - "borsh 1.5.1", + "borsh 1.5.2", "bs58 0.4.0", "bytemuck", "byteorder", @@ -5745,18 +5744,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "syn_derive" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1329189c02ff984e9736652b1631330da25eaa6bc639089ed4915d25446cbe7b" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "syn 2.0.87", -] - [[package]] name = "sync_wrapper" version = "0.1.2" @@ -5855,9 +5842,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" +checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" dependencies = [ "cfg-if", "fastrand", @@ -5958,18 +5945,18 @@ checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" [[package]] name = "thiserror" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7c61ec9a6f64d2793d8a45faba21efbe3ced62a886d44c36a009b2b519b4c7e" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", @@ -6063,9 +6050,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.41.0" +version = "1.41.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "145f3413504347a2be84393cc8a7d2fb4d863b375909ea59f2158261aa258bbb" +checksum = "22cfb5bee7a6a52939ca9224d6ac897bb669134078daa8735560897f69de4d33" dependencies = [ "backtrace", "bytes", @@ -6367,6 +6354,8 @@ dependencies = [ "solana-program-runtime", "solana-program-test", "solana-sdk", + "solana-stake-program", + "solana-vote-program", "spl-token", "thiserror", "tokio", diff --git a/Cargo.toml b/Cargo.toml index 238e829de..d2e0d9f6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,5 +19,7 @@ solana-program = "1.17.4" solana-banks-client = "1.17.4" solana-program-runtime = "1.17.4" solana-program-test = "1.17.4" +solana-vote-program = "1.17.4" +solana-stake-program = "1.17.4" spl-associated-token-account = { version = "2", features = ["no-entrypoint"] } spl-token = { version = "4", features = ["no-entrypoint"] } diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index c4e7a0c67..31b4b5e11 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -68,6 +68,14 @@ pub mod fuzzing { pub use std::cell::RefCell; pub use std::collections::HashMap; + + pub use trident_fuzz::accounts_storage::KeypairStore; + pub use trident_fuzz::accounts_storage::MintStore; + pub use trident_fuzz::accounts_storage::PdaStore; + pub use trident_fuzz::accounts_storage::ProgramStore; + pub use trident_fuzz::accounts_storage::StakeStore; + pub use trident_fuzz::accounts_storage::TokenStore; + pub use trident_fuzz::accounts_storage::VoteStore; } mod anchor_idl; diff --git a/crates/fuzz/Cargo.toml b/crates/fuzz/Cargo.toml index 4c5a7007c..f8d0a1fdd 100644 --- a/crates/fuzz/Cargo.toml +++ b/crates/fuzz/Cargo.toml @@ -11,9 +11,11 @@ description = "The trident_fuzz crate helps you to write Rust Fuzz Tests for you # SOLANA solana-sdk = { workspace = true } solana-banks-client = { workspace = true } -spl-token = { workspace = true } +solana-stake-program = { workspace = true } +solana-vote-program = { workspace = true } solana-program-runtime = { workspace = true } solana-program-test = { workspace = true } +spl-token = { workspace = true } # ANCHOR anchor-lang = { workspace = true, features = ["init-if-needed"] } diff --git a/crates/fuzz/src/accounts_storage.rs b/crates/fuzz/src/accounts_storage.rs deleted file mode 100644 index 65d33dbb2..000000000 --- a/crates/fuzz/src/accounts_storage.rs +++ /dev/null @@ -1,326 +0,0 @@ -#![allow(dead_code)] -use std::collections::HashMap; - -use solana_sdk::{ - account::AccountSharedData, - clock::{Clock, Epoch}, - pubkey::Pubkey, - signature::Keypair, - stake::state::Lockup, -}; - -use crate::{fuzz_client::FuzzClient, AccountId}; - -pub struct PdaStore { - pub pubkey: Pubkey, - pub seeds: Vec>, -} -impl PdaStore { - pub fn pubkey(&self) -> Pubkey { - self.pubkey - } -} - -pub struct TokenStore { - pub pubkey: Pubkey, -} - -pub struct MintStore { - pub pubkey: Pubkey, -} - -pub struct ProgramStore { - pub pubkey: Pubkey, -} -pub struct VoteAccountStore { - pub pubkey: Pubkey, -} - -pub struct StakeAccountStore { - pub pubkey: Pubkey, -} - -pub struct AccountsStorage { - accounts: HashMap, - _max_accounts: u8, -} - -impl AccountsStorage { - pub fn new(max_accounts: u8) -> Self { - let accounts: HashMap = HashMap::new(); - Self { - accounts, - _max_accounts: max_accounts, - } - } - - pub fn set_custom( - &mut self, - account_id: AccountId, - client: &mut impl FuzzClient, - address: Pubkey, - account: AccountSharedData, - ) where - T: From, - { - client.set_account_custom(&address, &account); - self.accounts.insert(account_id, T::from(address)); - } -} - -impl Default for AccountsStorage { - fn default() -> Self { - Self::new(2) - } -} -// TODO Add an easy way to limit the number of created accounts -impl AccountsStorage { - pub fn get_or_create_account( - &mut self, - account_id: AccountId, - client: &mut impl FuzzClient, - lamports: u64, - ) -> Keypair { - let key = self - .accounts - .entry(account_id) - .or_insert_with(|| client.set_account(lamports)); - key.insecure_clone() - } - pub fn get(&self, account_id: AccountId) -> Keypair { - match self.accounts.get(&account_id) { - Some(v) => v.insecure_clone(), - None => Keypair::new(), - } - } -} - -impl AccountsStorage { - pub fn get_or_create_account( - &mut self, - account_id: AccountId, - _client: &mut impl FuzzClient, - program_id: Pubkey, - ) -> Pubkey { - let program_id = self - .accounts - .entry(account_id) - .or_insert_with(|| ProgramStore { pubkey: program_id }); - program_id.pubkey - } - pub fn get(&self, account_id: AccountId) -> Pubkey { - match self.accounts.get(&account_id) { - Some(v) => v.pubkey, - None => Pubkey::new_unique(), - } - } -} -impl From for TokenStore { - fn from(pubkey: Pubkey) -> Self { - TokenStore { pubkey } - } -} -impl From for MintStore { - fn from(pubkey: Pubkey) -> Self { - MintStore { pubkey } - } -} - -impl From for ProgramStore { - fn from(pubkey: Pubkey) -> Self { - ProgramStore { pubkey } - } -} - -impl From for VoteAccountStore { - fn from(pubkey: Pubkey) -> Self { - VoteAccountStore { pubkey } - } -} - -impl From for StakeAccountStore { - fn from(pubkey: Pubkey) -> Self { - StakeAccountStore { pubkey } - } -} -impl From for PdaStore { - fn from(pubkey: Pubkey) -> Self { - PdaStore { - pubkey, - seeds: Vec::new(), // Note: This creates empty seeds - } - } -} - -impl AccountsStorage { - #[allow(clippy::too_many_arguments)] - pub fn get_or_create_account( - &mut self, - account_id: AccountId, - client: &mut impl FuzzClient, - mint: Pubkey, - owner: Pubkey, - amount: u64, - delegate: Option, - is_native: Option, - delegated_amount: u64, - close_authority: Option, - ) -> Pubkey { - let key = self.accounts.entry(account_id).or_insert_with(|| { - let key = client.set_token_account( - mint, - owner, - amount, - delegate, - is_native, - delegated_amount, - close_authority, - ); - TokenStore { pubkey: key } - }); - key.pubkey - } - pub fn get(&self, account_id: AccountId) -> Pubkey { - match self.accounts.get(&account_id) { - Some(v) => v.pubkey, - None => Pubkey::default(), - } - } -} - -impl AccountsStorage { - pub fn get_or_create_account( - &mut self, - account_id: AccountId, - client: &mut impl FuzzClient, - decimals: u8, - owner: &Pubkey, - freeze_authority: Option, - ) -> Pubkey { - let key = self.accounts.entry(account_id).or_insert_with(|| { - let key = client.set_mint_account(decimals, owner, freeze_authority); - MintStore { pubkey: key } - }); - key.pubkey - } - pub fn get(&self, account_id: AccountId) -> Pubkey { - match self.accounts.get(&account_id) { - Some(v) => v.pubkey, - None => Pubkey::new_unique(), - } - } -} - -impl AccountsStorage { - pub fn get_or_create_account( - &mut self, - account_id: AccountId, - seeds: &[&[u8]], - program_id: &Pubkey, - ) -> Pubkey { - match self.accounts.get(&account_id) { - Some(v) => v.pubkey, - None => { - if let Some((key, _)) = Pubkey::try_find_program_address(seeds, program_id) { - let seeds_vec: Vec<_> = seeds.iter().map(|&s| s.to_vec()).collect(); - let pda_store = PdaStore { - pubkey: key, - seeds: seeds_vec, - }; - self.accounts.insert(account_id, pda_store); - key - } else { - Pubkey::new_unique() - } - } - } - } - pub fn get(&self, account_id: AccountId) -> Pubkey { - match self.accounts.get(&account_id) { - Some(v) => v.pubkey, - None => Pubkey::new_unique(), - } - } -} - -impl AccountsStorage { - #[allow(clippy::too_many_arguments)] - pub fn get_or_create_account( - &mut self, - account_id: AccountId, - client: &mut impl FuzzClient, - node_pubkey: &Pubkey, - authorized_voter: &Pubkey, - authorized_withdrawer: &Pubkey, - commission: u8, - clock: &Clock, - ) -> Pubkey { - let key = self.accounts.entry(account_id).or_insert_with(|| { - let key = client.set_vote_account( - node_pubkey, - authorized_voter, - authorized_withdrawer, - commission, - clock, - ); - VoteAccountStore { pubkey: key } - }); - key.pubkey - } - pub fn get(&self, account_id: AccountId) -> Pubkey { - match self.accounts.get(&account_id) { - Some(v) => v.pubkey, - None => Pubkey::new_unique(), - } - } -} - -impl AccountsStorage { - #[allow(clippy::too_many_arguments)] - pub fn get_or_create_delegated_account( - &mut self, - account_id: AccountId, - client: &mut impl FuzzClient, - voter_pubkey: Pubkey, - staker: Pubkey, - withdrawer: Pubkey, - stake: u64, - activation_epoch: Epoch, - deactivation_epoch: Option, - lockup: Option, - ) -> Pubkey { - let key = self.accounts.entry(account_id).or_insert_with(|| { - let key = client.set_delegated_stake_account( - voter_pubkey, - staker, - withdrawer, - stake, - activation_epoch, - deactivation_epoch, - lockup, - ); - StakeAccountStore { pubkey: key } - }); - key.pubkey - } - pub fn get_or_create_initialized_account( - &mut self, - account_id: AccountId, - client: &mut impl FuzzClient, - staker: Pubkey, - withdrawer: Pubkey, - lockup: Option, - ) -> Pubkey { - let key = self.accounts.entry(account_id).or_insert_with(|| { - let key = client.set_initialized_stake_account(staker, withdrawer, lockup); - StakeAccountStore { pubkey: key } - }); - key.pubkey - } - pub fn get(&self, account_id: AccountId) -> Pubkey { - match self.accounts.get(&account_id) { - Some(v) => v.pubkey, - None => Pubkey::new_unique(), - } - } -} diff --git a/crates/fuzz/src/accounts_storage/keypair_store.rs b/crates/fuzz/src/accounts_storage/keypair_store.rs new file mode 100644 index 000000000..e01a56e31 --- /dev/null +++ b/crates/fuzz/src/accounts_storage/keypair_store.rs @@ -0,0 +1,43 @@ +use solana_sdk::{account::AccountSharedData, pubkey::Pubkey, signature::Keypair, signer::Signer}; + +use crate::{fuzz_client::FuzzClient, AccountId}; + +use super::AccountsStorage; + +pub struct KeypairStore { + pub keypair: Keypair, +} + +impl KeypairStore { + pub fn pubkey(&self) -> Pubkey { + self.keypair.pubkey() + } +} + +// TODO Add an easy way to limit the number of created accounts +impl AccountsStorage { + pub fn get_or_create_account( + &mut self, + account_id: AccountId, + client: &mut impl FuzzClient, + lamports: u64, + ) -> Keypair { + let key = self.accounts.entry(account_id).or_insert_with(|| { + let keypair = Keypair::new(); + + let empty_account = + AccountSharedData::new(lamports, 0, &solana_sdk::system_program::ID); + client.set_account_custom(&keypair.pubkey(), &empty_account); + KeypairStore { + keypair: keypair.insecure_clone(), + } + }); + key.keypair.insecure_clone() + } + pub fn get(&self, account_id: AccountId) -> Keypair { + match self.accounts.get(&account_id) { + Some(v) => v.keypair.insecure_clone(), + None => Keypair::new(), + } + } +} diff --git a/crates/fuzz/src/accounts_storage/mint_store.rs b/crates/fuzz/src/accounts_storage/mint_store.rs new file mode 100644 index 000000000..b2dc7b535 --- /dev/null +++ b/crates/fuzz/src/accounts_storage/mint_store.rs @@ -0,0 +1,69 @@ +use solana_sdk::{ + account::AccountSharedData, program_option::COption, program_pack::Pack, pubkey::Pubkey, + rent::Rent, signature::Keypair, signer::Signer, +}; +use spl_token::state::Mint; + +use crate::{fuzz_client::FuzzClient, AccountId}; + +use super::AccountsStorage; + +pub struct MintStore { + pub pubkey: Pubkey, +} + +impl From for MintStore { + fn from(pubkey: Pubkey) -> Self { + MintStore { pubkey } + } +} + +impl AccountsStorage { + pub fn get_or_create_account( + &mut self, + account_id: AccountId, + client: &mut impl FuzzClient, + decimals: u8, + owner: &Pubkey, + freeze_authority: Option, + ) -> Pubkey { + let key = self.accounts.entry(account_id).or_insert_with(|| { + let mint_account = Keypair::new(); + + let authority = match freeze_authority { + Some(a) => COption::Some(a), + _ => COption::None, + }; + + let r = Rent::default(); + let lamports = r.minimum_balance(Mint::LEN); + + let mut account = AccountSharedData::new(lamports, Mint::LEN, &spl_token::id()); + + let mint = Mint { + is_initialized: true, + mint_authority: COption::Some(*owner), + freeze_authority: authority, + decimals, + ..Default::default() + }; + + let mut data = vec![0u8; Mint::LEN]; + Mint::pack(mint, &mut data[..]).unwrap(); + account.set_data_from_slice(&data); + + client.set_account_custom(&mint_account.pubkey(), &account); + + MintStore { + pubkey: mint_account.pubkey(), + } + }); + key.pubkey + } + pub fn get(&self, account_id: AccountId) -> Pubkey { + match self.accounts.get(&account_id) { + Some(v) => v.pubkey, + None => Pubkey::new_unique(), + } + } +} diff --git a/crates/fuzz/src/accounts_storage/mod.rs b/crates/fuzz/src/accounts_storage/mod.rs new file mode 100644 index 000000000..053d14712 --- /dev/null +++ b/crates/fuzz/src/accounts_storage/mod.rs @@ -0,0 +1,56 @@ +#![allow(dead_code)] +use std::collections::HashMap; + +use crate::AccountId; + +pub mod keypair_store; +pub mod mint_store; +pub mod pda_store; +pub mod program_store; +pub mod stake_store; +pub mod token_store; +pub mod vote_store; + +use crate::fuzz_client::FuzzClient; +pub use keypair_store::KeypairStore; +pub use mint_store::MintStore; +pub use pda_store::PdaStore; +pub use program_store::ProgramStore; +use solana_sdk::account::AccountSharedData; +use solana_sdk::pubkey::Pubkey; +pub use stake_store::StakeStore; +pub use token_store::TokenStore; +pub use vote_store::VoteStore; + +pub struct AccountsStorage { + accounts: HashMap, + _max_accounts: u8, +} + +impl AccountsStorage { + pub fn new(max_accounts: u8) -> Self { + let accounts: HashMap = HashMap::new(); + Self { + accounts, + _max_accounts: max_accounts, + } + } + + pub fn set_custom( + &mut self, + account_id: AccountId, + client: &mut impl FuzzClient, + address: Pubkey, + account: AccountSharedData, + ) where + T: From, + { + client.set_account_custom(&address, &account); + self.accounts.insert(account_id, T::from(address)); + } +} +impl Default for AccountsStorage { + fn default() -> Self { + Self::new(2) + } +} diff --git a/crates/fuzz/src/accounts_storage/pda_store.rs b/crates/fuzz/src/accounts_storage/pda_store.rs new file mode 100644 index 000000000..73283297e --- /dev/null +++ b/crates/fuzz/src/accounts_storage/pda_store.rs @@ -0,0 +1,61 @@ +use solana_sdk::{account::AccountSharedData, pubkey::Pubkey}; + +use crate::{fuzz_client::FuzzClient, AccountId}; + +use super::AccountsStorage; + +pub struct PdaStore { + pub pubkey: Pubkey, + pub seeds: Vec>, +} +impl PdaStore { + pub fn pubkey(&self) -> Pubkey { + self.pubkey + } +} + +impl From for PdaStore { + fn from(pubkey: Pubkey) -> Self { + PdaStore { + pubkey, + seeds: Vec::new(), // Note: This creates empty seeds + } + } +} + +impl AccountsStorage { + pub fn get_or_create_account( + &mut self, + account_id: AccountId, + client: &mut impl FuzzClient, + seeds: &[&[u8]], + program_id: &Pubkey, + ) -> Pubkey { + match self.accounts.get(&account_id) { + Some(v) => v.pubkey, + None => { + if let Some((key, _)) = Pubkey::try_find_program_address(seeds, program_id) { + let seeds_vec: Vec<_> = seeds.iter().map(|&s| s.to_vec()).collect(); + let pda_store = PdaStore { + pubkey: key, + seeds: seeds_vec, + }; + self.accounts.insert(account_id, pda_store); + client.set_account_custom( + &key, + &AccountSharedData::new(0, 0, &solana_sdk::system_program::ID), + ); + key + } else { + Pubkey::new_unique() + } + } + } + } + pub fn get(&self, account_id: AccountId) -> Pubkey { + match self.accounts.get(&account_id) { + Some(v) => v.pubkey, + None => Pubkey::new_unique(), + } + } +} diff --git a/crates/fuzz/src/accounts_storage/program_store.rs b/crates/fuzz/src/accounts_storage/program_store.rs new file mode 100644 index 000000000..82dcab15c --- /dev/null +++ b/crates/fuzz/src/accounts_storage/program_store.rs @@ -0,0 +1,35 @@ +use solana_sdk::pubkey::Pubkey; + +use crate::{fuzz_client::FuzzClient, AccountId}; + +use super::AccountsStorage; + +pub struct ProgramStore { + pub pubkey: Pubkey, +} +impl From for ProgramStore { + fn from(pubkey: Pubkey) -> Self { + ProgramStore { pubkey } + } +} + +impl AccountsStorage { + pub fn get_or_create_account( + &mut self, + account_id: AccountId, + _client: &mut impl FuzzClient, + program_id: Pubkey, + ) -> Pubkey { + let program_id = self + .accounts + .entry(account_id) + .or_insert_with(|| ProgramStore { pubkey: program_id }); + program_id.pubkey + } + pub fn get(&self, account_id: AccountId) -> Pubkey { + match self.accounts.get(&account_id) { + Some(v) => v.pubkey, + None => Pubkey::new_unique(), + } + } +} diff --git a/crates/fuzz/src/accounts_storage/stake_store.rs b/crates/fuzz/src/accounts_storage/stake_store.rs new file mode 100644 index 000000000..064ecd047 --- /dev/null +++ b/crates/fuzz/src/accounts_storage/stake_store.rs @@ -0,0 +1,126 @@ +use solana_sdk::{ + account::AccountSharedData, clock::Epoch, native_token::LAMPORTS_PER_SOL, pubkey::Pubkey, + rent::Rent, signature::Keypair, signer::Signer, stake::stake_flags::StakeFlags, +}; +use solana_stake_program::stake_state::{ + Authorized, Delegation, Lockup, Meta, Stake, StakeStateV2, +}; + +use crate::{fuzz_client::FuzzClient, AccountId}; + +use super::AccountsStorage; + +pub struct StakeStore { + pub pubkey: Pubkey, +} +impl From for StakeStore { + fn from(pubkey: Pubkey) -> Self { + StakeStore { pubkey } + } +} + +impl AccountsStorage { + #[allow(clippy::too_many_arguments)] + pub fn get_or_create_delegated_account( + &mut self, + account_id: AccountId, + client: &mut impl FuzzClient, + voter_pubkey: Pubkey, + staker: Pubkey, + withdrawer: Pubkey, + stake: u64, + activation_epoch: Epoch, + deactivation_epoch: Option, + lockup: Option, + ) -> Pubkey { + let key = self.accounts.entry(account_id).or_insert_with(|| { + let stake_account = Keypair::new(); + + let rent = Rent::default(); + let rent_exempt_lamports = rent.minimum_balance(StakeStateV2::size_of()); + let minimum_delegation = LAMPORTS_PER_SOL; // TODO: a way to get minimum delegation with feature set? + let minimum_lamports = rent_exempt_lamports.saturating_add(minimum_delegation); + + let stake_state = StakeStateV2::Stake( + Meta { + authorized: Authorized { staker, withdrawer }, + lockup: lockup.unwrap_or_default(), + rent_exempt_reserve: rent_exempt_lamports, + }, + Stake { + delegation: Delegation { + stake, + activation_epoch, + voter_pubkey, + deactivation_epoch: if let Some(epoch) = deactivation_epoch { + epoch + } else { + u64::MAX + }, + ..Delegation::default() + }, + ..Stake::default() + }, + StakeFlags::default(), + ); + let account = AccountSharedData::new_data_with_space( + if stake > minimum_lamports { + stake + } else { + minimum_lamports + }, + &stake_state, + StakeStateV2::size_of(), + &solana_sdk::stake::program::ID, + ) + .unwrap(); + + client.set_account_custom(&stake_account.pubkey(), &account); + + StakeStore { + pubkey: stake_account.pubkey(), + } + }); + key.pubkey + } + pub fn get_or_create_initialized_account( + &mut self, + account_id: AccountId, + client: &mut impl FuzzClient, + staker: Pubkey, + withdrawer: Pubkey, + lockup: Option, + ) -> Pubkey { + let key = self.accounts.entry(account_id).or_insert_with(|| { + let stake_account = Keypair::new(); + + let rent = Rent::default(); + let rent_exempt_lamports = rent.minimum_balance(StakeStateV2::size_of()); + + let stake_state = StakeStateV2::Initialized(Meta { + authorized: Authorized { staker, withdrawer }, + lockup: lockup.unwrap_or_default(), + rent_exempt_reserve: rent_exempt_lamports, + }); + let account = AccountSharedData::new_data_with_space( + rent_exempt_lamports, + &stake_state, + StakeStateV2::size_of(), + &solana_sdk::stake::program::ID, + ) + .unwrap(); + client.set_account_custom(&stake_account.pubkey(), &account); + + StakeStore { + pubkey: stake_account.pubkey(), + } + }); + key.pubkey + } + pub fn get(&self, account_id: AccountId) -> Pubkey { + match self.accounts.get(&account_id) { + Some(v) => v.pubkey, + None => Pubkey::new_unique(), + } + } +} diff --git a/crates/fuzz/src/accounts_storage/token_store.rs b/crates/fuzz/src/accounts_storage/token_store.rs new file mode 100644 index 000000000..67cb83c7f --- /dev/null +++ b/crates/fuzz/src/accounts_storage/token_store.rs @@ -0,0 +1,87 @@ +use solana_sdk::{ + account::AccountSharedData, program_option::COption, program_pack::Pack, pubkey::Pubkey, + rent::Rent, signature::Keypair, signer::Signer, +}; + +use crate::{fuzz_client::FuzzClient, AccountId}; + +use super::AccountsStorage; + +pub struct TokenStore { + pub pubkey: Pubkey, +} + +impl From for TokenStore { + fn from(pubkey: Pubkey) -> Self { + TokenStore { pubkey } + } +} + +impl AccountsStorage { + #[allow(clippy::too_many_arguments)] + pub fn get_or_create_account( + &mut self, + account_id: AccountId, + client: &mut impl FuzzClient, + mint: Pubkey, + owner: Pubkey, + amount: u64, + delegate: Option, + is_native: Option, + delegated_amount: u64, + close_authority: Option, + ) -> Pubkey { + let key = self.accounts.entry(account_id).or_insert_with(|| { + let token_account = Keypair::new(); + + let delegate = match delegate { + Some(a) => COption::Some(a), + _ => COption::None, + }; + + let is_native = match is_native { + Some(a) => COption::Some(a), + _ => COption::None, + }; + + let close_authority = match close_authority { + Some(a) => COption::Some(a), + _ => COption::None, + }; + + let r = Rent::default(); + let lamports = r.minimum_balance(spl_token::state::Account::LEN); + + let mut account = + AccountSharedData::new(lamports, spl_token::state::Account::LEN, &spl_token::id()); + + let token_account_ = spl_token::state::Account { + mint, + owner, + amount, + delegate, + state: spl_token::state::AccountState::Initialized, + is_native, + delegated_amount, + close_authority, + }; + + let mut data = vec![0u8; spl_token::state::Account::LEN]; + spl_token::state::Account::pack(token_account_, &mut data[..]).unwrap(); + account.set_data_from_slice(&data); + + client.set_account_custom(&token_account.pubkey(), &account); + + TokenStore { + pubkey: token_account.pubkey(), + } + }); + key.pubkey + } + pub fn get(&self, account_id: AccountId) -> Pubkey { + match self.accounts.get(&account_id) { + Some(v) => v.pubkey, + None => Pubkey::default(), + } + } +} diff --git a/crates/fuzz/src/accounts_storage/vote_store.rs b/crates/fuzz/src/accounts_storage/vote_store.rs new file mode 100644 index 000000000..eb86b6a10 --- /dev/null +++ b/crates/fuzz/src/accounts_storage/vote_store.rs @@ -0,0 +1,78 @@ +use solana_sdk::{ + account::{AccountSharedData, WritableAccount}, + clock::Clock, + pubkey::Pubkey, + rent::Rent, + signature::Keypair, + signer::Signer, +}; +use solana_vote_program::vote_state::{VoteInit, VoteState, VoteStateVersions}; + +use crate::{fuzz_client::FuzzClient, AccountId}; + +use super::AccountsStorage; + +pub struct VoteStore { + pub pubkey: Pubkey, +} + +impl From for VoteStore { + fn from(pubkey: Pubkey) -> Self { + VoteStore { pubkey } + } +} + +impl AccountsStorage { + #[allow(clippy::too_many_arguments)] + pub fn get_or_create_account( + &mut self, + account_id: AccountId, + client: &mut impl FuzzClient, + node_pubkey: &Pubkey, + authorized_voter: &Pubkey, + authorized_withdrawer: &Pubkey, + commission: u8, + clock: &Clock, + ) -> Pubkey { + let key = self.accounts.entry(account_id).or_insert_with(|| { + let vote_account = Keypair::new(); + + let rent = Rent::default(); + let lamports = rent.minimum_balance(VoteState::size_of()); + let mut account = AccountSharedData::new( + lamports, + VoteState::size_of(), + &solana_sdk::vote::program::ID, + ); + + let vote_state = VoteState::new( + &VoteInit { + node_pubkey: *node_pubkey, + authorized_voter: *authorized_voter, + authorized_withdrawer: *authorized_withdrawer, + commission, + }, + clock, + ); + + VoteState::serialize( + &VoteStateVersions::Current(Box::new(vote_state)), + account.data_as_mut_slice(), + ) + .unwrap(); + + client.set_account_custom(&vote_account.pubkey(), &account); + + VoteStore { + pubkey: vote_account.pubkey(), + } + }); + key.pubkey + } + pub fn get(&self, account_id: AccountId) -> Pubkey { + match self.accounts.get(&account_id) { + Some(v) => v.pubkey, + None => Pubkey::new_unique(), + } + } +} diff --git a/crates/fuzz/src/fuzz_client.rs b/crates/fuzz/src/fuzz_client.rs index 57e209c1d..6a5c06f53 100644 --- a/crates/fuzz/src/fuzz_client.rs +++ b/crates/fuzz/src/fuzz_client.rs @@ -1,14 +1,10 @@ #![allow(dead_code)] -use anchor_lang::prelude::Rent; use anchor_lang::solana_program::hash::Hash; use solana_sdk::account::AccountSharedData; -use solana_sdk::clock::{Clock, Epoch}; -use solana_sdk::instruction::AccountMeta; use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::Keypair; -use solana_sdk::stake::state::Lockup; use solana_sdk::sysvar::Sysvar; use solana_sdk::transaction::VersionedTransaction; @@ -16,40 +12,9 @@ use crate::error::*; /// A trait providing methods to read and write (manipulate) accounts pub trait FuzzClient { - /// Create a initialzied stake account - fn set_initialized_stake_account( - &mut self, - staker: Pubkey, - withdrawer: Pubkey, - lockup: Option, - ) -> Pubkey; - - /// Create a delegated stake account - #[allow(clippy::too_many_arguments)] - fn set_delegated_stake_account( - &mut self, - voter_pubkey: Pubkey, // vote account delegated to - staker: Pubkey, - withdrawer: Pubkey, - stake: u64, - activation_epoch: Epoch, - deactivation_epoch: Option, - lockup: Option, - ) -> Pubkey; - /// Get the cluster rent fn get_sysvar(&mut self) -> T; - /// Create a vote account - fn set_vote_account( - &mut self, - node_pubkey: &Pubkey, // validator identity - authorized_voter: &Pubkey, - authorized_withdrawer: &Pubkey, - commission: u8, - clock: &Clock, - ) -> Pubkey; - /// Warp to specific epoch fn warp_to_epoch(&mut self, warp_epoch: u64); @@ -59,51 +24,18 @@ pub trait FuzzClient { /// Forward in time by the desired number of seconds fn forward_in_time(&mut self, seconds: i64) -> Result<(), FuzzClientError>; - /// Create an empty account and add lamports to it - fn set_account(&mut self, lamports: u64) -> Keypair; - /// Create or overwrite a custom account, subverting normal runtime checks. fn set_account_custom(&mut self, address: &Pubkey, account: &AccountSharedData); - /// Create an SPL token account - #[allow(clippy::too_many_arguments)] - fn set_token_account( - &mut self, - mint: Pubkey, - owner: Pubkey, - amount: u64, - delegate: Option, - is_native: Option, - delegated_amount: u64, - close_authority: Option, - ) -> Pubkey; - - /// Create an SPL mint account - fn set_mint_account( - &mut self, - decimals: u8, - owner: &Pubkey, - freeze_authority: Option, - ) -> Pubkey; - /// Get the Keypair of the client's payer account fn payer(&self) -> Keypair; /// Get the account at the given address - fn get_account(&mut self, key: &Pubkey) -> Result; - - /// Get accounts based on the supplied meta information - fn get_accounts( - &mut self, - metas: &[AccountMeta], - ) -> Result, FuzzClientErrorWithOrigin>; + fn get_account(&mut self, key: &Pubkey) -> AccountSharedData; /// Get last blockhash fn get_last_blockhash(&self) -> Hash; - /// Get the cluster rent - fn get_rent(&mut self) -> Result; - /// Send a transaction and return until the transaction has been finalized or rejected. fn process_transaction( &mut self, diff --git a/crates/fuzz/src/program_test_client_blocking.rs b/crates/fuzz/src/program_test_client_blocking.rs index ea1d56a12..ccc5bee32 100644 --- a/crates/fuzz/src/program_test_client_blocking.rs +++ b/crates/fuzz/src/program_test_client_blocking.rs @@ -2,30 +2,14 @@ use solana_program_runtime::invoke_context::BuiltinFunctionWithContext; use solana_program_test::ProgramTest; use solana_program_test::ProgramTestContext; use solana_sdk::account::Account; -use solana_sdk::account::WritableAccount; use solana_sdk::account_info::AccountInfo; use solana_sdk::clock::Clock; -use solana_sdk::clock::Epoch; use solana_sdk::entrypoint::ProgramResult; -use solana_sdk::native_token::LAMPORTS_PER_SOL; -use solana_sdk::stake::stake_flags::StakeFlags; -use solana_sdk::stake::state::Authorized; -use solana_sdk::stake::state::Delegation; -use solana_sdk::stake::state::Lockup; -use solana_sdk::stake::state::Meta; -use solana_sdk::stake::state::Stake; -use solana_sdk::stake::state::StakeStateV2; -use solana_sdk::system_program::ID as SYSTEM_PROGRAM_ID; use solana_sdk::sysvar::Sysvar; -use solana_sdk::vote::state::VoteInit; -use solana_sdk::vote::state::VoteState; -use solana_sdk::vote::state::VoteStateVersions; use solana_sdk::{ - account::AccountSharedData, hash::Hash, instruction::AccountMeta, program_option::COption, - program_pack::Pack, pubkey::Pubkey, rent::Rent, signature::Keypair, signature::Signer, + account::AccountSharedData, hash::Hash, pubkey::Pubkey, rent::Rent, signature::Keypair, transaction::VersionedTransaction, }; -use spl_token::state::Mint; use tokio::runtime::Builder; use crate::config::Config; @@ -120,166 +104,27 @@ macro_rules! convert_entry { } impl FuzzClient for ProgramTestClientBlocking { - fn set_vote_account( - &mut self, - node_pubkey: &Pubkey, - authorized_voter: &Pubkey, - authorized_withdrawer: &Pubkey, - commission: u8, - clock: &Clock, - ) -> Pubkey { - let vote_account = Keypair::new(); - - let rent = Rent::default(); - let lamports = rent.minimum_balance(VoteState::size_of()); - let mut account = AccountSharedData::new( - lamports, - VoteState::size_of(), - &solana_sdk::vote::program::ID, - ); - - let vote_state = VoteState::new( - &VoteInit { - node_pubkey: *node_pubkey, - authorized_voter: *authorized_voter, - authorized_withdrawer: *authorized_withdrawer, - commission, - }, - clock, - ); - - VoteState::serialize( - &VoteStateVersions::Current(Box::new(vote_state)), - account.data_as_mut_slice(), - ) - .unwrap(); - - self.ctx.set_account(&vote_account.pubkey(), &account); - - vote_account.pubkey() - } - - fn set_account(&mut self, lamports: u64) -> Keypair { - let owner = Keypair::new(); - let account = AccountSharedData::new(lamports, 0, &SYSTEM_PROGRAM_ID); - self.ctx.set_account(&owner.pubkey(), &account); - owner - } - - fn set_token_account( - &mut self, - mint: Pubkey, - owner: Pubkey, - amount: u64, - delegate: Option, - is_native: Option, - delegated_amount: u64, - close_authority: Option, - ) -> Pubkey { - let mint_account_key = Keypair::new().pubkey(); - - let delegate = match delegate { - Some(a) => COption::Some(a), - _ => COption::None, - }; - - let is_native = match is_native { - Some(a) => COption::Some(a), - _ => COption::None, - }; - - let close_authority = match close_authority { - Some(a) => COption::Some(a), - _ => COption::None, - }; - - let r = Rent::default(); - let lamports = r.minimum_balance(spl_token::state::Account::LEN); - - let mut account = - AccountSharedData::new(lamports, spl_token::state::Account::LEN, &spl_token::id()); - - let token_account = spl_token::state::Account { - mint, - owner, - amount, - delegate, - state: spl_token::state::AccountState::Initialized, - is_native, - delegated_amount, - close_authority, - }; - - let mut data = vec![0u8; spl_token::state::Account::LEN]; - spl_token::state::Account::pack(token_account, &mut data[..]).unwrap(); - account.set_data_from_slice(&data); - self.ctx.set_account(&mint_account_key, &account); - - mint_account_key - } - - fn set_mint_account( - &mut self, - decimals: u8, - owner: &Pubkey, - freeze_authority: Option, - ) -> Pubkey { - let mint_account = Keypair::new(); - - let authority = match freeze_authority { - Some(a) => COption::Some(a), - _ => COption::None, - }; - - let r = Rent::default(); - let lamports = r.minimum_balance(Mint::LEN); - - let mut account = AccountSharedData::new(lamports, Mint::LEN, &spl_token::id()); - - let mint = Mint { - is_initialized: true, - mint_authority: COption::Some(*owner), - freeze_authority: authority, - decimals, - ..Default::default() - }; - - let mut data = vec![0u8; Mint::LEN]; - Mint::pack(mint, &mut data[..]).unwrap(); - account.set_data_from_slice(&data); - self.ctx.set_account(&mint_account.pubkey(), &account); - - mint_account.pubkey() - } - fn payer(&self) -> Keypair { self.ctx.payer.insecure_clone() } - fn get_account(&mut self, key: &Pubkey) -> Result { - Ok(self + fn get_account(&mut self, key: &Pubkey) -> AccountSharedData { + let account = self .rt .block_on(self.ctx.banks_client.get_account_with_commitment( *key, solana_sdk::commitment_config::CommitmentLevel::Confirmed, - ))? - .unwrap_or_default() - .into()) - } - fn get_accounts( - &mut self, - metas: &[AccountMeta], - ) -> Result, FuzzClientErrorWithOrigin> { - let result: Vec<_> = metas - .iter() - .map(|m| { - self.get_account(&m.pubkey) - .map_err(|e| e.with_origin(Origin::Account(m.pubkey))) - }) - .collect(); - result.into_iter().collect() + )) + .unwrap_or_default(); + match account { + Some(account) => account.into(), + None => { + let account = AccountSharedData::new(0, 0, &solana_sdk::system_program::ID); + self.ctx.set_account(key, &account); + account + } + } } - fn get_last_blockhash(&self) -> Hash { self.ctx.last_blockhash } @@ -296,9 +141,6 @@ impl FuzzClient for ProgramTestClientBlocking { self.ctx.set_account(address, account); } - fn get_rent(&mut self) -> Result { - Ok(self.rt.block_on(self.ctx.banks_client.get_rent())?) - } fn forward_in_time(&mut self, seconds: i64) -> Result<(), FuzzClientError> { // Get the current clock state from the program test context. let mut clock = self @@ -326,88 +168,4 @@ impl FuzzClient for ProgramTestClientBlocking { .block_on(self.ctx.banks_client.get_sysvar::()) .unwrap_or_default() } - fn set_delegated_stake_account( - &mut self, - voter_pubkey: Pubkey, // vote account delegated to - staker: Pubkey, - withdrawer: Pubkey, - stake: u64, - activation_epoch: Epoch, - deactivation_epoch: Option, - lockup: Option, - ) -> Pubkey { - let stake_account = Keypair::new(); - - let rent = Rent::default(); - let rent_exempt_lamports = rent.minimum_balance(StakeStateV2::size_of()); - let minimum_delegation = LAMPORTS_PER_SOL; // TODO: a way to get minimum delegation with feature set? - let minimum_lamports = rent_exempt_lamports.saturating_add(minimum_delegation); - - let stake_state = StakeStateV2::Stake( - Meta { - authorized: Authorized { staker, withdrawer }, - lockup: lockup.unwrap_or_default(), - rent_exempt_reserve: rent_exempt_lamports, - }, - Stake { - delegation: Delegation { - stake, - activation_epoch, - voter_pubkey, - deactivation_epoch: if let Some(epoch) = deactivation_epoch { - epoch - } else { - u64::MAX - }, - ..Delegation::default() - }, - ..Stake::default() - }, - StakeFlags::default(), - ); - let account = AccountSharedData::new_data_with_space( - if stake > minimum_lamports { - stake - } else { - minimum_lamports - }, - &stake_state, - StakeStateV2::size_of(), - &solana_sdk::stake::program::ID, - ) - .unwrap(); - - self.ctx.set_account(&stake_account.pubkey(), &account); - - stake_account.pubkey() - } - - fn set_initialized_stake_account( - &mut self, - staker: Pubkey, - withdrawer: Pubkey, - lockup: Option, - ) -> Pubkey { - let stake_account = Keypair::new(); - - let rent = Rent::default(); - let rent_exempt_lamports = rent.minimum_balance(StakeStateV2::size_of()); - - let stake_state = StakeStateV2::Initialized(Meta { - authorized: Authorized { staker, withdrawer }, - lockup: lockup.unwrap_or_default(), - rent_exempt_reserve: rent_exempt_lamports, - }); - let account = AccountSharedData::new_data_with_space( - rent_exempt_lamports, - &stake_state, - StakeStateV2::size_of(), - &solana_sdk::stake::program::ID, - ) - .unwrap(); - - self.ctx.set_account(&stake_account.pubkey(), &account); - - stake_account.pubkey() - } } diff --git a/crates/fuzz/src/snapshot.rs b/crates/fuzz/src/snapshot.rs index a951a13e3..604dbb352 100644 --- a/crates/fuzz/src/snapshot.rs +++ b/crates/fuzz/src/snapshot.rs @@ -75,7 +75,12 @@ impl Snapshot { &mut self, client: &mut impl FuzzClient, ) -> Result, FuzzClientErrorWithOrigin> { - let accounts = client.get_accounts(&self.metas)?; + let accounts: Vec<_> = self + .metas + .iter() + .map(|m| client.get_account(&m.pubkey)) + .collect(); + let snapshot_accounts = accounts .into_iter() .zip(self.metas.iter()) diff --git a/documentation/docs/features/account-storages.md b/documentation/docs/features/account-storages.md index 94ec797a1..145fd2fde 100644 --- a/documentation/docs/features/account-storages.md +++ b/documentation/docs/features/account-storages.md @@ -18,19 +18,20 @@ Instead, Trident generates random **AccountIDs** which are indexes to **Account Currently, supported types of Account Storages: - - Signer - - PDA - - Token Account - - Program account - - Stake account - - Vote account + - Signer (KeypairStore) + - Program Derived Address (PdaStore) + - Token Account (TokenStore) + - Mint Account (MintStore) + - Program Account (ProgramStore) + - Stake Account (StakeStore) + - Vote Account (VoteStore) Then use the corresponding AccountsStorage. ```rust pub struct FuzzAccounts { - signer: AccountsStorage, + signer: AccountsStorage, some_pda: AccountsStorage, token_vault: AccountsStorage, mint: AccountsStorage, diff --git a/documentation/docs/features/fuzz-instructions.md b/documentation/docs/features/fuzz-instructions.md index ee1ca0bce..7db685014 100644 --- a/documentation/docs/features/fuzz-instructions.md +++ b/documentation/docs/features/fuzz-instructions.md @@ -128,6 +128,7 @@ Insert a new record into AccountsStorage based on the `account_id`. If a record ```rust let hello_world_account = fuzz_accounts.hello_world_account.get_or_create_account( self.accounts.hello_world_account, + client, &[b"hello_world_seed"], &hello_world::ID, ); diff --git a/examples/fuzz-tests/arbitrary-custom-types-4/Cargo.lock b/examples/fuzz-tests/arbitrary-custom-types-4/Cargo.lock index 98f1e3a59..1a1a9e32e 100644 --- a/examples/fuzz-tests/arbitrary-custom-types-4/Cargo.lock +++ b/examples/fuzz-tests/arbitrary-custom-types-4/Cargo.lock @@ -6064,23 +6064,11 @@ dependencies = [ "thiserror", "tokio", "toml 0.8.19", - "trident-derive-accounts-snapshots", "trident-derive-displayix", "trident-derive-fuzz-test-executor", "trident-fuzz", ] -[[package]] -name = "trident-derive-accounts-snapshots" -version = "0.0.2" -dependencies = [ - "anchor-syn", - "convert_case", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "trident-derive-displayix" version = "0.0.3" @@ -6115,6 +6103,8 @@ dependencies = [ "solana-program-runtime", "solana-program-test", "solana-sdk", + "solana-stake-program", + "solana-vote-program", "spl-token", "thiserror", "tokio", diff --git a/examples/fuzz-tests/arbitrary-custom-types-4/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs b/examples/fuzz-tests/arbitrary-custom-types-4/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs index 9cf2192d4..acb425069 100644 --- a/examples/fuzz-tests/arbitrary-custom-types-4/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs +++ b/examples/fuzz-tests/arbitrary-custom-types-4/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs @@ -153,8 +153,8 @@ impl IxOps for Update { /// Keypair, PdaStore, TokenStore, MintStore, ProgramStore #[derive(Default)] pub struct FuzzAccounts { - user: AccountsStorage, - counter: AccountsStorage, + user: AccountsStorage, + counter: AccountsStorage, // _authority: AccountsStorage, // _system_program: AccountsStorage, } diff --git a/examples/fuzz-tests/arbitrary-limit-inputs-5/Cargo.lock b/examples/fuzz-tests/arbitrary-limit-inputs-5/Cargo.lock index d5edb83fd..07c1c58f0 100644 --- a/examples/fuzz-tests/arbitrary-limit-inputs-5/Cargo.lock +++ b/examples/fuzz-tests/arbitrary-limit-inputs-5/Cargo.lock @@ -6264,23 +6264,11 @@ dependencies = [ "thiserror", "tokio", "toml 0.8.19", - "trident-derive-accounts-snapshots", "trident-derive-displayix", "trident-derive-fuzz-test-executor", "trident-fuzz", ] -[[package]] -name = "trident-derive-accounts-snapshots" -version = "0.0.2" -dependencies = [ - "anchor-syn", - "convert_case", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "trident-derive-displayix" version = "0.0.3" @@ -6315,6 +6303,8 @@ dependencies = [ "solana-program-runtime", "solana-program-test", "solana-sdk", + "solana-stake-program", + "solana-vote-program", "spl-token", "thiserror", "tokio", diff --git a/examples/fuzz-tests/arbitrary-limit-inputs-5/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs b/examples/fuzz-tests/arbitrary-limit-inputs-5/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs index 59923d5c0..b9a7ddfc8 100644 --- a/examples/fuzz-tests/arbitrary-limit-inputs-5/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs +++ b/examples/fuzz-tests/arbitrary-limit-inputs-5/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs @@ -186,6 +186,7 @@ impl IxOps for InitVesting { ); let escrow = fuzz_accounts.escrow.get_or_create_account( self.accounts.escrow, + client, &[recipient.pubkey().as_ref(), b"ESCROW_SEED"], &arbitrary_limit_inputs_5::ID, ); @@ -274,12 +275,14 @@ impl IxOps for WithdrawUnlocked { let escrow = fuzz_accounts.escrow.get_or_create_account( self.accounts.escrow, + client, &[recipient.pubkey().as_ref(), b"ESCROW_SEED"], &arbitrary_limit_inputs_5::ID, ); let escrow_pda_authority = fuzz_accounts.escrow_pda_authority.get_or_create_account( self.accounts.escrow_pda_authority, + client, &[b"ESCROW_PDA_AUTHORITY"], &arbitrary_limit_inputs_5::ID, ); @@ -363,11 +366,11 @@ pub struct FuzzAccounts { sender_token_account: AccountsStorage, escrow_token_account: AccountsStorage, escrow_pda_authority: AccountsStorage, - sender: AccountsStorage, + sender: AccountsStorage, // No need to fuzz System Program // _system_program: AccountsStorage, recipient_token_account: AccountsStorage, - recipient: AccountsStorage, + recipient: AccountsStorage, mint: AccountsStorage, escrow: AccountsStorage, } diff --git a/examples/fuzz-tests/cpi-metaplex-7/Cargo.lock b/examples/fuzz-tests/cpi-metaplex-7/Cargo.lock index 0000074f6..aaabdc440 100644 --- a/examples/fuzz-tests/cpi-metaplex-7/Cargo.lock +++ b/examples/fuzz-tests/cpi-metaplex-7/Cargo.lock @@ -6279,23 +6279,11 @@ dependencies = [ "thiserror", "tokio", "toml 0.8.19", - "trident-derive-accounts-snapshots", "trident-derive-displayix", "trident-derive-fuzz-test-executor", "trident-fuzz", ] -[[package]] -name = "trident-derive-accounts-snapshots" -version = "0.0.2" -dependencies = [ - "anchor-syn", - "convert_case", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "trident-derive-displayix" version = "0.0.3" @@ -6330,6 +6318,8 @@ dependencies = [ "solana-program-runtime", "solana-program-test", "solana-sdk", + "solana-stake-program", + "solana-vote-program", "spl-token", "thiserror", "tokio", diff --git a/examples/fuzz-tests/cpi-metaplex-7/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs b/examples/fuzz-tests/cpi-metaplex-7/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs index bc0dfb82b..6b07a8d75 100644 --- a/examples/fuzz-tests/cpi-metaplex-7/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs +++ b/examples/fuzz-tests/cpi-metaplex-7/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs @@ -100,9 +100,9 @@ impl IxOps for Initialize { #[derive(Default)] pub struct FuzzAccounts { _metadata_account: AccountsStorage, - mint: AccountsStorage, + mint: AccountsStorage, _mpl_token_metadata: AccountsStorage, - signer: AccountsStorage, + signer: AccountsStorage, _system_program: AccountsStorage, _token_program: AccountsStorage, } diff --git a/examples/fuzz-tests/hello_world/Cargo.lock b/examples/fuzz-tests/hello_world/Cargo.lock index 101410613..a2ad485e9 100644 --- a/examples/fuzz-tests/hello_world/Cargo.lock +++ b/examples/fuzz-tests/hello_world/Cargo.lock @@ -6103,6 +6103,8 @@ dependencies = [ "solana-program-runtime", "solana-program-test", "solana-sdk", + "solana-stake-program", + "solana-vote-program", "spl-token", "thiserror", "tokio", diff --git a/examples/fuzz-tests/hello_world/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs b/examples/fuzz-tests/hello_world/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs index c44024f72..f0a4d38ff 100644 --- a/examples/fuzz-tests/hello_world/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs +++ b/examples/fuzz-tests/hello_world/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs @@ -67,6 +67,7 @@ impl IxOps for InitializeFn { let hello_world_account = fuzz_accounts.hello_world_account.get_or_create_account( self.accounts.hello_world_account, + client, &[b"hello_world_seed"], &hello_world::ID, ); @@ -99,7 +100,7 @@ impl IxOps for InitializeFn { /// Keypair, PdaStore, TokenStore, MintStore, ProgramStore #[derive(Default)] pub struct FuzzAccounts { - author: AccountsStorage, + author: AccountsStorage, hello_world_account: AccountsStorage, // No need to fuzz system_program // system_program: AccountsStorage, diff --git a/examples/fuzz-tests/hello_world/trident-tests/fuzz_tests/fuzz_1/fuzz_instructions.rs b/examples/fuzz-tests/hello_world/trident-tests/fuzz_tests/fuzz_1/fuzz_instructions.rs deleted file mode 100644 index 5df7ab329..000000000 --- a/examples/fuzz-tests/hello_world/trident-tests/fuzz_tests/fuzz_1/fuzz_instructions.rs +++ /dev/null @@ -1,107 +0,0 @@ -use solana_sdk::native_token::LAMPORTS_PER_SOL; -use trident_client::fuzzing::*; -/// FuzzInstruction contains all available Instructions. -/// Below, the instruction arguments (accounts and data) are defined. -#[derive(Arbitrary, DisplayIx, FuzzTestExecutor)] -pub enum FuzzInstruction { - InitializeFn(InitializeFn), -} -#[derive(Arbitrary, Debug)] -pub struct InitializeFn { - pub accounts: InitializeFnAccounts, - pub data: InitializeFnData, -} -#[derive(Arbitrary, Debug)] -pub struct InitializeFnAccounts { - pub author: AccountId, - pub hello_world_account: AccountId, - pub _system_program: AccountId, -} -/// Custom data types must derive `Debug` and `Arbitrary`. -/// To do this, redefine the type in the fuzz test and implement the `From` -/// trait -/// to convert it into the type defined in the program. -/// For more details, see: https://ackee.xyz/trident/docs/dev/features/arbitrary-data/#custom-data-types -#[derive(Arbitrary, Debug)] -pub struct InitializeFnData { - pub input: u8, -} -///IxOps implementation for `InitializeFn` with all required functions. -impl IxOps for InitializeFn { - type IxData = hello_world::instruction::InitializeFn; - type IxAccounts = FuzzAccounts; - /// Definition of the program ID that the Instruction is associated with. - fn get_program_id(&self) -> solana_sdk::pubkey::Pubkey { - hello_world::ID - } - /// Definition of the Instruction data. - /// Use randomly generated data from the fuzzer using `self.data.arg_name` - /// or customize the data as needed. - /// For more details, visit: https://ackee.xyz/trident/docs/dev/features/fuzz-instructions/#get-data - fn get_data( - &self, - _client: &mut impl FuzzClient, - _fuzz_accounts: &mut FuzzAccounts, - ) -> Result { - let data = hello_world::instruction::InitializeFn { - input: self.data.input, - }; - Ok(data) - } - /// Definition of of the accounts required by the Instruction. - /// To utilize accounts stored in `FuzzAccounts`, use - /// `fuzz_accounts.account_name.get_or_create_account()`. - /// If no signers are required, leave the vector empty. - /// For AccountMetas use ::accounts:: - /// For more details, see: https://ackee.xyz/trident/docs/dev/features/fuzz-instructions/#get-accounts - fn get_accounts( - &self, - client: &mut impl FuzzClient, - fuzz_accounts: &mut FuzzAccounts, - ) -> Result<(Vec, Vec), FuzzingError> { - let author = fuzz_accounts.author.get_or_create_account( - self.accounts.author, - client, - 5 * LAMPORTS_PER_SOL, - ); - - let hello_world_account = fuzz_accounts.hello_world_account.get_or_create_account( - self.accounts.hello_world_account, - client, - &[b"hello_world_seed"], - &hello_world::ID, - ); - let signers = vec![author.clone()]; - let acc_meta = hello_world::accounts::InitializeContext { - author: author.pubkey(), - hello_world_account, - system_program: solana_sdk::system_program::ID, - } - .to_account_metas(None); - Ok((signers, acc_meta)) - } - fn check( - &self, - _pre_ix: &[SnapshotAccount], - post_ix: &[SnapshotAccount], - _ix_data: Self::IxData, - ) -> Result<(), FuzzingError> { - if let Ok(hello_world_account) = - hello_world::StoreHelloWorld::try_deserialize(&mut post_ix[1].data()) - { - if hello_world_account.input == 253 { - return Err(FuzzingError::Custom(1)); - } - } - Ok(()) - } -} -/// Use AccountsStorage where T can be one of: -/// Keypair, PdaStore, TokenStore, MintStore, ProgramStore -#[derive(Default)] -pub struct FuzzAccounts { - author: AccountsStorage, - hello_world_account: AccountsStorage, - // No need to fuzz system_program - // system_program: AccountsStorage, -} diff --git a/examples/fuzz-tests/incorrect-integer-arithmetic-3/Cargo.lock b/examples/fuzz-tests/incorrect-integer-arithmetic-3/Cargo.lock index 02e1c4366..ccfb95fe5 100644 --- a/examples/fuzz-tests/incorrect-integer-arithmetic-3/Cargo.lock +++ b/examples/fuzz-tests/incorrect-integer-arithmetic-3/Cargo.lock @@ -6264,23 +6264,11 @@ dependencies = [ "thiserror", "tokio", "toml 0.8.19", - "trident-derive-accounts-snapshots", "trident-derive-displayix", "trident-derive-fuzz-test-executor", "trident-fuzz", ] -[[package]] -name = "trident-derive-accounts-snapshots" -version = "0.0.2" -dependencies = [ - "anchor-syn", - "convert_case", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "trident-derive-displayix" version = "0.0.3" @@ -6315,6 +6303,8 @@ dependencies = [ "solana-program-runtime", "solana-program-test", "solana-sdk", + "solana-stake-program", + "solana-vote-program", "spl-token", "thiserror", "tokio", diff --git a/examples/fuzz-tests/incorrect-integer-arithmetic-3/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs b/examples/fuzz-tests/incorrect-integer-arithmetic-3/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs index 019f44b0f..2bc579bbc 100644 --- a/examples/fuzz-tests/incorrect-integer-arithmetic-3/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs +++ b/examples/fuzz-tests/incorrect-integer-arithmetic-3/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs @@ -136,6 +136,7 @@ impl IxOps for InitVesting { ); let escrow = fuzz_accounts.escrow.get_or_create_account( self.accounts.escrow, + client, &[recipient.pubkey().as_ref(), b"ESCROW_SEED"], &incorrect_integer_arithmetic_3::ID, ); @@ -224,12 +225,14 @@ impl IxOps for WithdrawUnlocked { let escrow = fuzz_accounts.escrow.get_or_create_account( self.accounts.escrow, + client, &[recipient.pubkey().as_ref(), b"ESCROW_SEED"], &incorrect_integer_arithmetic_3::ID, ); let escrow_pda_authority = fuzz_accounts.escrow_pda_authority.get_or_create_account( self.accounts.escrow_pda_authority, + client, &[b"ESCROW_PDA_AUTHORITY"], &incorrect_integer_arithmetic_3::ID, ); @@ -313,11 +316,11 @@ pub struct FuzzAccounts { sender_token_account: AccountsStorage, escrow_token_account: AccountsStorage, escrow_pda_authority: AccountsStorage, - sender: AccountsStorage, + sender: AccountsStorage, // No need to fuzz System Program // _system_program: AccountsStorage, recipient_token_account: AccountsStorage, - recipient: AccountsStorage, + recipient: AccountsStorage, mint: AccountsStorage, escrow: AccountsStorage, } diff --git a/examples/fuzz-tests/incorrect-ix-sequence-1/Cargo.lock b/examples/fuzz-tests/incorrect-ix-sequence-1/Cargo.lock index d3cb776a3..e2cffbdc6 100644 --- a/examples/fuzz-tests/incorrect-ix-sequence-1/Cargo.lock +++ b/examples/fuzz-tests/incorrect-ix-sequence-1/Cargo.lock @@ -6064,23 +6064,11 @@ dependencies = [ "thiserror", "tokio", "toml 0.8.19", - "trident-derive-accounts-snapshots", "trident-derive-displayix", "trident-derive-fuzz-test-executor", "trident-fuzz", ] -[[package]] -name = "trident-derive-accounts-snapshots" -version = "0.0.2" -dependencies = [ - "anchor-syn", - "convert_case", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "trident-derive-displayix" version = "0.0.3" @@ -6115,6 +6103,8 @@ dependencies = [ "solana-program-runtime", "solana-program-test", "solana-sdk", + "solana-stake-program", + "solana-vote-program", "spl-token", "thiserror", "tokio", diff --git a/examples/fuzz-tests/incorrect-ix-sequence-1/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs b/examples/fuzz-tests/incorrect-ix-sequence-1/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs index 7ffe41268..a75316d8b 100644 --- a/examples/fuzz-tests/incorrect-ix-sequence-1/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs +++ b/examples/fuzz-tests/incorrect-ix-sequence-1/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs @@ -124,6 +124,7 @@ impl IxOps for EndRegistrations { let signers = vec![author.clone()]; let state = fuzz_accounts.state.get_or_create_account( self.accounts.state, + client, &[author.pubkey().as_ref(), STATE_SEED.as_ref()], &incorrect_ix_sequence_1::ID, ); @@ -174,6 +175,7 @@ impl IxOps for Initialize { let signers = vec![author.clone()]; let state = fuzz_accounts.state.get_or_create_account( self.accounts.state, + client, &[author.pubkey().as_ref(), STATE_SEED.as_ref()], &incorrect_ix_sequence_1::ID, ); @@ -233,12 +235,14 @@ impl IxOps for Invest { ); let state = fuzz_accounts.state.get_or_create_account( self.accounts.state, + client, &[project_author.pubkey().as_ref(), STATE_SEED.as_ref()], &incorrect_ix_sequence_1::ID, ); let project = fuzz_accounts.project.get_or_create_account( self.accounts.project, + client, &[ project_author.pubkey().as_ref(), state.as_ref(), @@ -295,12 +299,14 @@ impl IxOps for Register { let signers = vec![project_author.clone()]; let state = fuzz_accounts.state.get_or_create_account( self.accounts.state, + client, &[project_author.pubkey().as_ref(), STATE_SEED.as_ref()], &incorrect_ix_sequence_1::ID, ); let project = fuzz_accounts.project.get_or_create_account( self.accounts.project, + client, &[ project_author.pubkey().as_ref(), state.as_ref(), @@ -349,11 +355,11 @@ impl IxOps for Register { /// Keypair, PdaStore, TokenStore, MintStore, ProgramStore #[derive(Default)] pub struct FuzzAccounts { - project_author: AccountsStorage, - author: AccountsStorage, + project_author: AccountsStorage, + author: AccountsStorage, project: AccountsStorage, // There is no need to fuzz the 'system_program' account. // system_program: AccountsStorage, - investor: AccountsStorage, + investor: AccountsStorage, state: AccountsStorage, } diff --git a/examples/fuzz-tests/simple-cpi-6/Cargo.lock b/examples/fuzz-tests/simple-cpi-6/Cargo.lock index 9b5ca5734..93e589a6f 100644 --- a/examples/fuzz-tests/simple-cpi-6/Cargo.lock +++ b/examples/fuzz-tests/simple-cpi-6/Cargo.lock @@ -6073,23 +6073,11 @@ dependencies = [ "thiserror", "tokio", "toml 0.8.19", - "trident-derive-accounts-snapshots", "trident-derive-displayix", "trident-derive-fuzz-test-executor", "trident-fuzz", ] -[[package]] -name = "trident-derive-accounts-snapshots" -version = "0.0.2" -dependencies = [ - "anchor-syn", - "convert_case", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "trident-derive-displayix" version = "0.0.3" @@ -6124,6 +6112,8 @@ dependencies = [ "solana-program-runtime", "solana-program-test", "solana-sdk", + "solana-stake-program", + "solana-vote-program", "spl-token", "thiserror", "tokio", diff --git a/examples/fuzz-tests/simple-cpi-6/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs b/examples/fuzz-tests/simple-cpi-6/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs index 85810fbeb..fe4ed6d56 100644 --- a/examples/fuzz-tests/simple-cpi-6/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs +++ b/examples/fuzz-tests/simple-cpi-6/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs @@ -134,5 +134,5 @@ impl IxOps for InitializeCaller { #[derive(Default)] pub struct FuzzAccounts { _program: AccountsStorage, - signer_caller: AccountsStorage, + signer_caller: AccountsStorage, } diff --git a/examples/fuzz-tests/unauthorized-access-2/Cargo.lock b/examples/fuzz-tests/unauthorized-access-2/Cargo.lock index 3d4cd6992..416c47ca4 100644 --- a/examples/fuzz-tests/unauthorized-access-2/Cargo.lock +++ b/examples/fuzz-tests/unauthorized-access-2/Cargo.lock @@ -291,21 +291,6 @@ dependencies = [ "serde", ] -[[package]] -name = "anchor-spl" -version = "0.30.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04bd077c34449319a1e4e0bc21cea572960c9ae0d0fefda0dd7c52fcc3c647a3" -dependencies = [ - "anchor-lang", - "spl-associated-token-account 3.0.4", - "spl-pod 0.2.5", - "spl-token", - "spl-token-2022 3.0.4", - "spl-token-group-interface 0.2.5", - "spl-token-metadata-interface 0.3.5", -] - [[package]] name = "anchor-syn" version = "0.30.1" @@ -1860,7 +1845,6 @@ dependencies = [ name = "fuzz_tests" version = "0.1.0" dependencies = [ - "anchor-spl", "arbitrary", "assert_matches", "trident-client", @@ -4085,9 +4069,9 @@ dependencies = [ "solana-config-program", "solana-sdk", "spl-token", - "spl-token-2022 1.0.0", - "spl-token-group-interface 0.1.0", - "spl-token-metadata-interface 0.2.0", + "spl-token-2022", + "spl-token-group-interface", + "spl-token-metadata-interface", "thiserror", "zstd", ] @@ -4760,7 +4744,7 @@ dependencies = [ "solana-sdk", "solana-transaction-status", "solana-version", - "spl-token-2022 1.0.0", + "spl-token-2022", "thiserror", ] @@ -5063,10 +5047,10 @@ dependencies = [ "serde_json", "solana-account-decoder", "solana-sdk", - "spl-associated-token-account 2.3.0", + "spl-associated-token-account", "spl-memo", "spl-token", - "spl-token-2022 1.0.0", + "spl-token-2022", "thiserror", ] @@ -5238,23 +5222,7 @@ dependencies = [ "num-traits", "solana-program", "spl-token", - "spl-token-2022 1.0.0", - "thiserror", -] - -[[package]] -name = "spl-associated-token-account" -version = "3.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143109d789171379e6143ef23191786dfaac54289ad6e7917cfb26b36c432b10" -dependencies = [ - "assert_matches", - "borsh 1.5.1", - "num-derive 0.4.2", - "num-traits", - "solana-program", - "spl-token", - "spl-token-2022 3.0.4", + "spl-token-2022", "thiserror", ] @@ -5266,18 +5234,7 @@ checksum = "cce5d563b58ef1bb2cdbbfe0dfb9ffdc24903b10ae6a4df2d8f425ece375033f" dependencies = [ "bytemuck", "solana-program", - "spl-discriminator-derive 0.1.2", -] - -[[package]] -name = "spl-discriminator" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "210101376962bb22bb13be6daea34656ea1cbc248fce2164b146e39203b55e03" -dependencies = [ - "bytemuck", - "solana-program", - "spl-discriminator-derive 0.2.0", + "spl-discriminator-derive", ] [[package]] @@ -5287,18 +5244,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07fd7858fc4ff8fb0e34090e41d7eb06a823e1057945c26d480bfc21d2338a93" dependencies = [ "quote", - "spl-discriminator-syn 0.1.2", - "syn 2.0.87", -] - -[[package]] -name = "spl-discriminator-derive" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9e8418ea6269dcfb01c712f0444d2c75542c04448b480e87de59d2865edc750" -dependencies = [ - "quote", - "spl-discriminator-syn 0.2.0", + "spl-discriminator-syn", "syn 2.0.87", ] @@ -5315,19 +5261,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "spl-discriminator-syn" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c1f05593b7ca9eac7caca309720f2eafb96355e037e6d373b909a80fe7b69b9" -dependencies = [ - "proc-macro2", - "quote", - "sha2 0.10.8", - "syn 2.0.87", - "thiserror", -] - [[package]] name = "spl-memo" version = "4.0.0" @@ -5347,20 +5280,7 @@ dependencies = [ "bytemuck", "solana-program", "solana-zk-token-sdk", - "spl-program-error 0.3.0", -] - -[[package]] -name = "spl-pod" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c52d84c55efeef8edcc226743dc089d7e3888b8e3474569aa3eff152b37b9996" -dependencies = [ - "borsh 1.5.1", - "bytemuck", - "solana-program", - "solana-zk-token-sdk", - "spl-program-error 0.4.4", + "spl-program-error", ] [[package]] @@ -5372,20 +5292,7 @@ dependencies = [ "num-derive 0.4.2", "num-traits", "solana-program", - "spl-program-error-derive 0.3.2", - "thiserror", -] - -[[package]] -name = "spl-program-error" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e45a49acb925db68aa501b926096b2164adbdcade7a0c24152af9f0742d0a602" -dependencies = [ - "num-derive 0.4.2", - "num-traits", - "solana-program", - "spl-program-error-derive 0.4.1", + "spl-program-error-derive", "thiserror", ] @@ -5401,18 +5308,6 @@ dependencies = [ "syn 2.0.87", ] -[[package]] -name = "spl-program-error-derive" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d375dd76c517836353e093c2dbb490938ff72821ab568b545fd30ab3256b3e" -dependencies = [ - "proc-macro2", - "quote", - "sha2 0.10.8", - "syn 2.0.87", -] - [[package]] name = "spl-tlv-account-resolution" version = "0.5.1" @@ -5421,24 +5316,10 @@ checksum = "615d381f48ddd2bb3c57c7f7fb207591a2a05054639b18a62e785117dd7a8683" dependencies = [ "bytemuck", "solana-program", - "spl-discriminator 0.1.0", - "spl-pod 0.1.0", - "spl-program-error 0.3.0", - "spl-type-length-value 0.3.0", -] - -[[package]] -name = "spl-tlv-account-resolution" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fab8edfd37be5fa17c9e42c1bff86abbbaf0494b031b37957f2728ad2ff842ba" -dependencies = [ - "bytemuck", - "solana-program", - "spl-discriminator 0.2.5", - "spl-pod 0.2.5", - "spl-program-error 0.4.4", - "spl-type-length-value 0.4.6", + "spl-discriminator", + "spl-pod", + "spl-program-error", + "spl-type-length-value", ] [[package]] @@ -5471,36 +5352,12 @@ dependencies = [ "solana-security-txt", "solana-zk-token-sdk", "spl-memo", - "spl-pod 0.1.0", - "spl-token", - "spl-token-group-interface 0.1.0", - "spl-token-metadata-interface 0.2.0", - "spl-transfer-hook-interface 0.4.1", - "spl-type-length-value 0.3.0", - "thiserror", -] - -[[package]] -name = "spl-token-2022" -version = "3.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b01d1b2851964e257187c0bca43a0de38d0af59192479ca01ac3e2b58b1bd95a" -dependencies = [ - "arrayref", - "bytemuck", - "num-derive 0.4.2", - "num-traits", - "num_enum 0.7.3", - "solana-program", - "solana-security-txt", - "solana-zk-token-sdk", - "spl-memo", - "spl-pod 0.2.5", + "spl-pod", "spl-token", - "spl-token-group-interface 0.2.5", - "spl-token-metadata-interface 0.3.5", - "spl-transfer-hook-interface 0.6.5", - "spl-type-length-value 0.4.6", + "spl-token-group-interface", + "spl-token-metadata-interface", + "spl-transfer-hook-interface", + "spl-type-length-value", "thiserror", ] @@ -5512,22 +5369,9 @@ checksum = "b889509d49fa74a4a033ca5dae6c2307e9e918122d97e58562f5c4ffa795c75d" dependencies = [ "bytemuck", "solana-program", - "spl-discriminator 0.1.0", - "spl-pod 0.1.0", - "spl-program-error 0.3.0", -] - -[[package]] -name = "spl-token-group-interface" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "014817d6324b1e20c4bbc883e8ee30a5faa13e59d91d1b2b95df98b920150c17" -dependencies = [ - "bytemuck", - "solana-program", - "spl-discriminator 0.2.5", - "spl-pod 0.2.5", - "spl-program-error 0.4.4", + "spl-discriminator", + "spl-pod", + "spl-program-error", ] [[package]] @@ -5538,24 +5382,10 @@ checksum = "4c16ce3ba6979645fb7627aa1e435576172dd63088dc7848cb09aa331fa1fe4f" dependencies = [ "borsh 0.10.4", "solana-program", - "spl-discriminator 0.1.0", - "spl-pod 0.1.0", - "spl-program-error 0.3.0", - "spl-type-length-value 0.3.0", -] - -[[package]] -name = "spl-token-metadata-interface" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3da00495b602ebcf5d8ba8b3ecff1ee454ce4c125c9077747be49c2d62335ba" -dependencies = [ - "borsh 1.5.1", - "solana-program", - "spl-discriminator 0.2.5", - "spl-pod 0.2.5", - "spl-program-error 0.4.4", - "spl-type-length-value 0.4.6", + "spl-discriminator", + "spl-pod", + "spl-program-error", + "spl-type-length-value", ] [[package]] @@ -5567,27 +5397,11 @@ dependencies = [ "arrayref", "bytemuck", "solana-program", - "spl-discriminator 0.1.0", - "spl-pod 0.1.0", - "spl-program-error 0.3.0", - "spl-tlv-account-resolution 0.5.1", - "spl-type-length-value 0.3.0", -] - -[[package]] -name = "spl-transfer-hook-interface" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9b5c08a89838e5a2931f79b17f611857f281a14a2100968a3ccef352cb7414b" -dependencies = [ - "arrayref", - "bytemuck", - "solana-program", - "spl-discriminator 0.2.5", - "spl-pod 0.2.5", - "spl-program-error 0.4.4", - "spl-tlv-account-resolution 0.6.5", - "spl-type-length-value 0.4.6", + "spl-discriminator", + "spl-pod", + "spl-program-error", + "spl-tlv-account-resolution", + "spl-type-length-value", ] [[package]] @@ -5598,22 +5412,9 @@ checksum = "a468e6f6371f9c69aae760186ea9f1a01c2908351b06a5e0026d21cfc4d7ecac" dependencies = [ "bytemuck", "solana-program", - "spl-discriminator 0.1.0", - "spl-pod 0.1.0", - "spl-program-error 0.3.0", -] - -[[package]] -name = "spl-type-length-value" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c872f93d0600e743116501eba2d53460e73a12c9a496875a42a7d70e034fe06d" -dependencies = [ - "bytemuck", - "solana-program", - "spl-discriminator 0.2.5", - "spl-pod 0.2.5", - "spl-program-error 0.4.4", + "spl-discriminator", + "spl-pod", + "spl-program-error", ] [[package]] @@ -6256,23 +6057,11 @@ dependencies = [ "thiserror", "tokio", "toml 0.8.19", - "trident-derive-accounts-snapshots", "trident-derive-displayix", "trident-derive-fuzz-test-executor", "trident-fuzz", ] -[[package]] -name = "trident-derive-accounts-snapshots" -version = "0.0.2" -dependencies = [ - "anchor-syn", - "convert_case", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "trident-derive-displayix" version = "0.0.3" @@ -6307,6 +6096,8 @@ dependencies = [ "solana-program-runtime", "solana-program-test", "solana-sdk", + "solana-stake-program", + "solana-vote-program", "spl-token", "thiserror", "tokio", diff --git a/examples/fuzz-tests/unauthorized-access-2/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs b/examples/fuzz-tests/unauthorized-access-2/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs index be444fb35..b47d22b93 100644 --- a/examples/fuzz-tests/unauthorized-access-2/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs +++ b/examples/fuzz-tests/unauthorized-access-2/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs @@ -100,6 +100,7 @@ impl IxOps for Initialize { let escrow = fuzz_accounts.escrow.get_or_create_account( self.accounts.escrow, + client, &[ author.pubkey().as_ref(), receiver.pubkey().as_ref(), @@ -155,6 +156,7 @@ impl IxOps for Withdraw { let escrow = fuzz_accounts.escrow.get_or_create_account( self.accounts.escrow, + client, &[ receiver.pubkey().as_ref(), receiver.pubkey().as_ref(), @@ -200,9 +202,9 @@ impl IxOps for Withdraw { /// Keypair, PdaStore, TokenStore, MintStore, ProgramStore #[derive(Default)] pub struct FuzzAccounts { - receiver: AccountsStorage, + receiver: AccountsStorage, // No need to fuzz system_program // system_program: AccountsStorage, - author: AccountsStorage, + author: AccountsStorage, escrow: AccountsStorage, } diff --git a/examples/fuzz-tests/unchecked-arithmetic-0/Cargo.lock b/examples/fuzz-tests/unchecked-arithmetic-0/Cargo.lock index cd4ba961c..a22ff3ffe 100644 --- a/examples/fuzz-tests/unchecked-arithmetic-0/Cargo.lock +++ b/examples/fuzz-tests/unchecked-arithmetic-0/Cargo.lock @@ -6057,23 +6057,11 @@ dependencies = [ "thiserror", "tokio", "toml 0.8.19", - "trident-derive-accounts-snapshots", "trident-derive-displayix", "trident-derive-fuzz-test-executor", "trident-fuzz", ] -[[package]] -name = "trident-derive-accounts-snapshots" -version = "0.0.2" -dependencies = [ - "anchor-syn", - "convert_case", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "trident-derive-displayix" version = "0.0.3" @@ -6108,6 +6096,8 @@ dependencies = [ "solana-program-runtime", "solana-program-test", "solana-sdk", + "solana-stake-program", + "solana-vote-program", "spl-token", "thiserror", "tokio", diff --git a/examples/fuzz-tests/unchecked-arithmetic-0/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs b/examples/fuzz-tests/unchecked-arithmetic-0/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs index 34ff5979d..a4865cd5c 100644 --- a/examples/fuzz-tests/unchecked-arithmetic-0/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs +++ b/examples/fuzz-tests/unchecked-arithmetic-0/trident-tests/fuzz_tests/fuzz_0/fuzz_instructions.rs @@ -124,8 +124,8 @@ pub struct FuzzAccounts { // the user account, just named differently. Therefore, we will use only // the generated user accounts for both 'user' and 'authority account' fields // in this fuzz test. Additionally, there is no need to fuzz the 'system_program' account. - user: AccountsStorage, - counter: AccountsStorage, + user: AccountsStorage, + counter: AccountsStorage, // authority: AccountsStorage, // system_program: AccountsStorage, }