Skip to content

Commit

Permalink
✨ Rename config to TridentConfig as the old name was causing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lukacan committed Jan 13, 2025
1 parent 03756e2 commit 69bd5a1
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ incremented upon a breaking change and the patch version will be incremented for

**Changed**

- renamed Config to TridentConfig ([246](https://github.com/Ackee-Blockchain/trident/pull/246))
- errors are simplified and transaction error contains only transaction error ([244](https://github.com/Ackee-Blockchain/trident/pull/244))

## [0.8.1] - 2024-11-14
Expand Down
6 changes: 3 additions & 3 deletions crates/client/src/commander/afl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{fs::File, path::Path};
use tokio::{io::AsyncWriteExt, process::Command};

use trident_config::afl::AflSeed;
use trident_config::Config;
use trident_config::TridentConfig;

use super::{Commander, Error};
use rand::RngCore;
Expand All @@ -15,7 +15,7 @@ impl Commander {
/// Runs fuzzer on the given target.
#[throws]
pub async fn run_afl(&self, target: String) {
let config = Config::new();
let config = TridentConfig::new();

// build args without cargo target dir
let build_args = config.get_afl_build_args();
Expand Down Expand Up @@ -77,7 +77,7 @@ impl Commander {
/// Runs fuzzer on the given target.
#[throws]
pub async fn run_afl_debug(&self, target: String, crash_file: String) {
let config = Config::new();
let config = TridentConfig::new();

let crash_file_path = Path::new(&crash_file);

Expand Down
8 changes: 4 additions & 4 deletions crates/client/src/commander/honggfuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::process;
use std::{os::unix::process::CommandExt, process::Stdio};
use tokio::process::Command;

use trident_config::Config;
use trident_config::TridentConfig;

use crate::constants::*;

Expand All @@ -14,7 +14,7 @@ impl Commander {
/// Runs fuzzer on the given target with exit code option.
#[throws]
pub async fn run_honggfuzz_with_exit_code(&self, target: String) {
let config = Config::new();
let config = TridentConfig::new();

// obtain hfuzz_run_args from env variable, this variable can contain multiple
// arguments so we need to parse the variable content.
Expand Down Expand Up @@ -86,7 +86,7 @@ impl Commander {
/// Runs fuzzer on the given target.
#[throws]
pub async fn run_honggfuzz(&self, target: String) {
let config = Config::new();
let config = TridentConfig::new();

let hfuzz_run_args = std::env::var("HFUZZ_RUN_ARGS").unwrap_or_default();

Expand Down Expand Up @@ -134,7 +134,7 @@ impl Commander {
/// Runs fuzzer on the given target.
#[throws]
pub async fn run_hfuzz_debug(&self, target: String, crash_file_path: String) {
let config = Config::new();
let config = TridentConfig::new();

let crash_file = Path::new(&crash_file_path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ fn main() {
None,
processor!(entry_idl_test),
);
let config = Config::new();
let config = TridentConfig::new();
let mut client =
TridentSVM::new_client(&[program_additional_program, program_idl_test], &config);
fuzz_trident ! (fuzz_ix : FuzzInstruction , | fuzz_data : InstructionsSequence , client : TridentSVM , config : Config |);
fuzz_trident ! (fuzz_ix : FuzzInstruction , | fuzz_data : InstructionsSequence , client : TridentSVM , config : TridentConfig |);
}
9 changes: 5 additions & 4 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,25 @@ pub enum Error {
}

#[derive(Debug, Deserialize, Clone)]
pub struct Config {
pub struct TridentConfig {
pub honggfuzz: Option<HonggFuzz>,
pub afl: Option<Afl>,
pub fuzz: Option<Fuzz>,
}

impl Default for Config {
impl Default for TridentConfig {
fn default() -> Self {
Self::new()
}
}

impl Config {
impl TridentConfig {
pub fn new() -> Self {
let root = discover_root().expect("failed to find the root folder");
let s = fs::read_to_string(root.join(TRIDENT_TOML).as_path())
.expect("failed to read the Trident config file");
let _config: Config = toml::from_str(&s).expect("failed to parse the Trident config file");
let _config: TridentConfig =
toml::from_str(&s).expect("failed to parse the Trident config file");
_config
}

Expand Down
2 changes: 1 addition & 1 deletion crates/fuzz/derive/fuzz_test_executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn fuzz_test_executor(input: TokenStream) -> TokenStream {
&self,
accounts: &RefCell<FuzzAccounts>,
client: &mut impl trident_fuzz::fuzzing::FuzzClient,
config: &trident_fuzz::fuzzing::Config,
config: &trident_fuzz::fuzzing::TridentConfig,
) -> core::result::Result<(), trident_fuzz::fuzzing::FuzzClientErrorWithOrigin> {
match self {
#(#display_match_arms)*
Expand Down
4 changes: 2 additions & 2 deletions crates/fuzz/src/fuzz_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use solana_sdk::signature::Keypair;
use solana_sdk::sysvar::Sysvar;
use solana_sdk::transaction::TransactionError;

use trident_config::Config;
use trident_config::TridentConfig;
use trident_svm::utils::ProgramEntrypoint;

/// A trait providing methods to read and write (manipulate) accounts
pub trait FuzzClient {
fn new_client(programs: &[ProgramEntrypoint], config: &Config) -> Self;
fn new_client(programs: &[ProgramEntrypoint], config: &TridentConfig) -> Self;
/// Get the cluster rent
fn get_sysvar<T: Sysvar>(&self) -> T;

Expand Down
4 changes: 2 additions & 2 deletions crates/fuzz/src/fuzz_client_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use solana_sdk::pubkey::Pubkey;
use solana_sdk::signer::Signer;
use solana_sdk::sysvar::Sysvar;

use trident_config::Config;
use trident_config::TridentConfig;

use trident_svm::trident_svm::TridentSVM;
use trident_svm::utils::ProgramEntrypoint;
Expand All @@ -17,7 +17,7 @@ use crate::fuzz_client::FuzzClient;
use solana_sdk::transaction::TransactionError;

impl FuzzClient for TridentSVM<'_> {
fn new_client(programs: &[ProgramEntrypoint], config: &Config) -> Self {
fn new_client(programs: &[ProgramEntrypoint], config: &TridentConfig) -> Self {
let sbf_programs =
config
.programs()
Expand Down
4 changes: 2 additions & 2 deletions crates/fuzz/src/fuzz_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::fmt::Display;

use crate::fuzz_client::FuzzClient;
use crate::fuzz_test_executor::FuzzTestExecutor;
use trident_config::Config;
use trident_config::TridentConfig;

pub struct FuzzData<T, U> {
pub pre_ixs: Vec<T>,
Expand Down Expand Up @@ -51,7 +51,7 @@ where
pub fn run_with_runtime(
&self,
client: &mut impl FuzzClient,
config: &Config,
config: &TridentConfig,
) -> core::result::Result<(), Box<dyn Error + 'static>> {
// solana_logger::setup_with_default("off");
// #[cfg(fuzzing_debug)]
Expand Down
4 changes: 2 additions & 2 deletions crates/fuzz/src/fuzz_test_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use std::cell::RefCell;

use crate::error::FuzzClientErrorWithOrigin;
use crate::fuzz_client::FuzzClient;
use trident_config::Config;
use trident_config::TridentConfig;

pub trait FuzzTestExecutor<T> {
fn run_fuzzer(
&self,
accounts: &RefCell<T>,
client: &mut impl FuzzClient,
config: &Config,
config: &TridentConfig,
) -> core::result::Result<(), FuzzClientErrorWithOrigin>;
}
2 changes: 1 addition & 1 deletion crates/fuzz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub mod fuzzing {

/// trident methods
pub use super::accounts_storage::*;
pub use trident_config::Config;
pub use trident_config::TridentConfig;

pub use super::error::*;
pub use super::fuzz_client::FuzzClient;
Expand Down
4 changes: 2 additions & 2 deletions crates/fuzz/src/transaction_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::fuzz_stats::FuzzingStatistics;
use crate::ix_ops::IxOps;
use crate::snapshot::Snapshot;

use trident_config::Config;
use trident_config::TridentConfig;

pub struct TransactionExecutor;

Expand All @@ -19,7 +19,7 @@ impl TransactionExecutor {
instruction_name: &str,
client: &mut impl FuzzClient,
ix: &I,
config: &Config,
config: &TridentConfig,
accounts: &RefCell<I::IxAccounts>,
) -> core::result::Result<(), FuzzClientErrorWithOrigin>
where
Expand Down
4 changes: 2 additions & 2 deletions crates/template/src/test_fuzz_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ pub fn generate_source_code(_idl_instructions: &[Idl], lib_names: &[String]) ->

#(#programs)*

let config = Config::new();
let config = TridentConfig::new();
let mut client = TridentSVM::new_client(&[ #(#input_array),* ], &config);
fuzz_trident!(
fuzz_ix: FuzzInstruction,
|fuzz_data: InstructionsSequence, client: TridentSVM, config: Config|
|fuzz_data: InstructionsSequence, client: TridentSVM, config: TridentConfig|
);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() {
None,
processor!(entry),
);
let config = Config::new();
let config = TridentConfig::new();
let mut client = TridentSVM::new_client(&[program], &config);
fuzz_trident ! (fuzz_ix : FuzzInstruction , | fuzz_data : InstructionsSequence , client : TridentSVM , config : Config |);
fuzz_trident ! (fuzz_ix : FuzzInstruction , | fuzz_data : InstructionsSequence , client : TridentSVM , config : TridentConfig |);
}
4 changes: 2 additions & 2 deletions examples/cpi/cpi-metaplex-7/trident-tests/fuzz_0/test_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn main() {
processor!(entry),
);

let config = Config::new();
let config = TridentConfig::new();
let mut client = TridentSVM::new_client(&[program], &config);
fuzz_trident ! (fuzz_ix : FuzzInstruction , | fuzz_data : InstructionsSequence , client : TridentSVM , config : Config |);
fuzz_trident ! (fuzz_ix : FuzzInstruction , | fuzz_data : InstructionsSequence , client : TridentSVM , config : TridentConfig |);
}
4 changes: 2 additions & 2 deletions examples/cpi/simple-cpi-6/trident-tests/fuzz_0/test_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() {
None,
processor!(entry_caller),
);
let config = Config::new();
let config = TridentConfig::new();
let mut client = TridentSVM::new_client(&[program_callee, program_caller], &config);
fuzz_trident ! (fuzz_ix : FuzzInstruction , | fuzz_data : InstructionsSequence , client : TridentSVM , config : Config |);
fuzz_trident ! (fuzz_ix : FuzzInstruction , | fuzz_data : InstructionsSequence , client : TridentSVM , config : TridentConfig |);
}
4 changes: 2 additions & 2 deletions examples/hello_world/trident-tests/fuzz_0/test_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() {
None,
processor!(entry_hello_world),
);
let config = Config::new();
let config = TridentConfig::new();
let mut client = TridentSVM::new_client(&[program_hello_world], &config);
fuzz_trident ! (fuzz_ix : FuzzInstruction , | fuzz_data : InstructionsSequence , client : TridentSVM , config : Config |);
fuzz_trident ! (fuzz_ix : FuzzInstruction , | fuzz_data : InstructionsSequence , client : TridentSVM , config : TridentConfig |);
}

0 comments on commit 69bd5a1

Please sign in to comment.