Skip to content

Commit

Permalink
✨ Review updates + minor versions updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lukacan committed Oct 20, 2024
1 parent d683ff5 commit b7a26ea
Show file tree
Hide file tree
Showing 21 changed files with 529 additions and 533 deletions.
407 changes: 219 additions & 188 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ anchor-syn = "0.30.1"
anchor-lang = "0.30.1"
anchor-lang-idl-spec = "0.1.0"

# ARBITRARY
arbitrary = { version = "1.3.0", features = ["derive"] }

# SOLANA
solana-sdk = "1.17.4"
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ description = "Trident is Rust based testing framework providing several conveni
trident-client = { path = "../client", version = "0.7.0" }

# MISC
clap = { version = "=4.3.19", features = ["derive"] }
clap = { version = "4", features = ["derive"] }
tokio = { version = "1" }
anyhow = { version = "1.0.45" }
fehler = { version = "1.0.0" }
anyhow = { version = "1" }
fehler = { version = "1" }
termimad = "0.30.0"
4 changes: 2 additions & 2 deletions crates/cli/src/command/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub enum FuzzCommand {
\n \x1b[1m\x1b[4m<PATH_TO_CRASHFILE>:\x1b[0m Path to the crash found during fuzzing.\
\n\n\x1b[1m\x1b[4mHINT:\x1b[0m By default crashfiles will be stored in the following folders:\
\n \x1b[1m\x1b[4mHonggfuzz:\x1b[0m trident-tests/fuzz_tests/fuzzing/honggfuzz/hfuzz_workspace/<TARGET>\
\n \x1b[1m\x1b[4mAFL:\x1b[0m trident-tests/fuzz_tests/fuzzing/afl/afl_workspace/default/crashes\
\n \x1b[1m\x1b[4mAFL:\x1b[0m trident-tests/fuzz_tests/fuzzing/afl/afl_workspace/out/default/crashes\
\n\n\x1b[1m\x1b[4mEXAMPLE:\x1b[0m\
\n trident fuzz debug-afl fuzz_0 trident-tests/fuzz_tests/fuzzing/afl/afl_workspace/out/default/crashes/id...\
\n\n\x1b[1m\x1b[33mWarning\x1b[0m:\
Expand All @@ -81,7 +81,7 @@ pub enum FuzzCommand {
\n \x1b[1m\x1b[4m<PATH_TO_CRASHFILE>:\x1b[0m Path to the crash found during fuzzing.\
\n\n\x1b[1m\x1b[4mHINT:\x1b[0m By default crashfiles will be stored in the following folders:\
\n \x1b[1m\x1b[4mHonggfuzz:\x1b[0m trident-tests/fuzz_tests/fuzzing/honggfuzz/hfuzz_workspace/<TARGET>\
\n \x1b[1m\x1b[4mAFL:\x1b[0m trident-tests/fuzz_tests/fuzzing/afl/afl_workspace/default/crashes\
\n \x1b[1m\x1b[4mAFL:\x1b[0m trident-tests/fuzz_tests/fuzzing/afl/afl_workspace/out/default/crashes\
\n\n\x1b[1m\x1b[4mEXAMPLE:\x1b[0m\
\n trident fuzz debug-hfuzz fuzz_0 trident-tests/fuzz_tests/fuzzing/honggfuzz/hfuzz_workspace/fuzz_0/SIGAR...\
\n\n\x1b[1m\x1b[33mWarning\x1b[0m:\
Expand Down
11 changes: 8 additions & 3 deletions crates/cli/src/command/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ pub async fn init(force: bool) {

if force {
generator.initialize().await?;
show_howto();
} else {
let root_path = Path::new(&root).join(TRIDENT_TOML);
if root_path.exists() {
println!("{SKIP} It looks like Trident is already initialized as the Trident.toml was found in {} directory.",root);
println!(
"{SKIP}: It looks like Trident is already initialized.\n\
Trident.toml was found in {} directory.\n\
In case you want to reinitialize the workspace use --force/-f flag.",
root
);
} else {
generator.initialize().await?;
show_howto();
}
}

show_howto();
}
13 changes: 11 additions & 2 deletions crates/cli/src/howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

## To start fuzzing, follow these steps:

- Install ***Honggfuzz***

```bash
cargo install honggfuzz
```

For supported versions check https://ackee.xyz/trident/docs/latest/getting-started/getting-started/#supported-versions


- Initialize ***Trident*** using

```bash
Expand Down Expand Up @@ -34,11 +43,11 @@ type InitializeFnSnapshot<'info> = InitializeContextAlias<'info>;
- Run fuzzing with ***Honggfuzz*** or ***AFL***

```bash
trident fuzz run-hfuzz
trident fuzz run-hfuzz <FUZZ_TARGET>
```

```bash
trident fuzz run-afl
trident fuzz run-afl <FUZZ_TARGET>
```

### For more details, refer to the Trident documentation: https://ackee.xyz/trident/docs/dev/
16 changes: 8 additions & 8 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ macro_rules! load_template {
#[derive(Parser)]
#[command(
name = "Trident",
version = "0.7.0",
about = "Trident is Rust based fuzzer for Solana programs written using Anchor framework."
)]
struct Cli {
Expand All @@ -33,16 +32,14 @@ enum Command {
How,
#[command(
about = "Initialize Trident in the current Anchor workspace.",
override_usage = "\nTrident will skip initialization if Trident.toml already exists.\
\nIf you are sure that you want to proceed with initialization even though the Trident.toml already exists,\
\ncall trident init -f / --force."
override_usage = "\nTrident will skip initialization if Trident.toml already exists."
)]
Init {
#[arg(
short,
long,
required = false,
help = "Force Trident Initialization. Trident dependencies will be updated based on the version of Trident."
help = "Force Trident initialization. Trident dependencies will be updated based on the version of Trident CLI."
)]
force: bool,
},
Expand All @@ -51,15 +48,18 @@ enum Command {
override_usage = "With fuzz subcommands you can add new fuzz test \
template or you can run fuzz test on already initialzied one.\
\n\n\x1b[1m\x1b[4mEXAMPLE:\x1b[0m\
\n trident add\n trident fuzz run-afl fuzz_0\
\n trident fuzz debug-hfuzz \x1b[92m<TARGET>\x1b[0m \x1b[92m<PATH_TO_CRASHFILE>\x1b[0m"
\n trident add\
\n trident fuzz run-afl fuzz_0\
\n trident fuzz run-hfuzz fuzz_0\
\n trident fuzz debug-hfuzz fuzz_0 \x1b[92m<PATH_TO_CRASHFILE>\x1b[0m\
\n trident fuzz debug-afl fuzz_0 \x1b[92m<PATH_TO_CRASHFILE>\x1b[0m"
)]
Fuzz {
#[clap(subcommand)]
subcmd: FuzzCommand,
},
#[command(
about = "Clean build targets of AFL and Honggfuzz, additionally perform `anchor build`"
about = "Clean build targets of AFL and Honggfuzz, additionally perform `anchor clean`"
)]
Clean,
}
Expand Down
42 changes: 18 additions & 24 deletions crates/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ license-file = "../../LICENSE"
readme = "../../README.md"
description = "The trident_client crate helps you build and deploy an Anchor program to a local cluster and run a test suite against it."

[build-dependencies]
anyhow = { version = "1.0.45", features = ["std"], default-features = false }

[dev-dependencies]
pretty_assertions = "1.1.0"

[dependencies]
# TRIDENT
Expand All @@ -38,27 +33,26 @@ honggfuzz = { version = "0.5.55" }
afl = { version = "0.15.10" }

# ARBITRARY
arbitrary = { version = "1.3.0", features = ["derive"] }
arbitrary = { workspace = true }


# MISC
tokio = "1"
serde_json = "1.0.72"
serde = { version = "1.0.136", default-features = false }
bincode = "1.3.3"
borsh = "0.10.3"
futures = "0.3.18"
fehler = "1.0.0"
thiserror = "1.0.30"
anyhow = { version = "1.0.45" }
cargo_metadata = "0.17.0"
syn = { version = "1.0.109", features = ["visit"] }
quote = "1.0.14"
toml = { version = "0.5.8", features = ["preserve_order"] }
log = "0.4"
proc-macro2 = { version = "1.0.66", default-features = false }
serde_json = "1"
serde = { version = "1", default-features = false }
bincode = "1"
futures = "0.3"
fehler = "1"
thiserror = "1"
anyhow = "1"
cargo_metadata = "0.18"
quinn-proto = { version = "0.10.6", features = ["arbitrary"] }
pathdiff = "0.2.1"
indicatif = "0.17.8"
regex = "1.10.3"
convert_case = "0.6.0"
syn = { version = "2", features = ["visit", "full"] }
quote = "1"
toml = { version = "0.8", features = ["preserve_order"] }
pathdiff = "0.2"
convert_case = "0.6"


[dev-dependencies]
pretty_assertions = "1.1.0"
15 changes: 0 additions & 15 deletions crates/client/build.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/client/src/commander/honggfuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ impl Commander {
}
}

println!("{}", cargo_target_dir);
match config.get_fuzzing_with_stats() {
true => {
// enforce keep output to be true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ pub fn generate_source_code(idls: &[Idl]) -> String {
use trident_client::fuzzing::*;

/// Link the relevant Account Context Alias from the program.
/// Aliases are generated by the `AccountsSnapshots` macro and stored in
/// a module named `trident_fuzz_<context_name>_snapshot::<Context_Alias_Name>`.
/// Example: `use hello_world::trident_fuzz_initialize_context_snapshot::InitializeContextAlias;`
/// For more complex programs, you may need to find the appropriate module.
/// Aliases are generated by the `AccountsSnapshots` macro.
#(#all_snapshot_types)*


Expand Down Expand Up @@ -304,13 +301,13 @@ fn get_instruction_ixops(
type IxAccounts = FuzzAccounts;
type IxSnapshot = #ix_snapshot<'info>;

/// The `get_program_id()` function specifies the program ID that the Instruction is associated with.
/// Definition of the program ID that the Instruction is associated with.
fn get_program_id(&self) -> solana_sdk::pubkey::Pubkey {
#module_name::ID
}

/// The `get_data()` function specifies the structure of the Instruction data.
/// You can utilize randomly generated data from the fuzzer using `self.data.arg_name`
/// 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(
Expand All @@ -324,9 +321,10 @@ fn get_instruction_ixops(
Ok(data)
}

/// The `get_accounts()` function specifies the structure of the accounts required by the Instruction.
/// Definition of of the accounts required by the Instruction.
/// To utilize accounts stored in `FuzzAccounts`, use `fuzz_accounts.account_name.get_or_create_account()`.
/// This method will either create a new account or return an existing one.
/// If no signers are required, leave the vector empty.
/// For AccountMetas use <program>::accounts::<corresponding_metas>
/// For more details, see: https://ackee.xyz/trident/docs/dev/features/fuzz-instructions/#get-accounts
fn get_accounts(
&self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ version = "0.1.0"
description = "Created with Trident"
edition = "2021"

# Dependencies specific to Fuzz test
[dependencies]
# ... your dependencies here
arbitrary = "1.3.0"
assert_matches = "1.4.0"
Loading

0 comments on commit b7a26ea

Please sign in to comment.