1use anyhow::Error;
2use clap::Parser;
3use clap::Subcommand;
4
5use fehler::throws;
6
7mod command;
8
9use crate::command::FuzzCommand;
10
11#[derive(Parser)]
12#[command(
13 name = "Trident",
14 about = "Trident is Rust based fuzzer for Solana programs written using Anchor framework.",
15 version = env!("CARGO_PKG_VERSION")
16)]
17struct Cli {
18 #[clap(subcommand)]
19 command: Command,
20}
21
22#[derive(Subcommand)]
23enum Command {
24 #[command(about = "Show the HowTo message.")]
25 How,
26 #[command(
27 about = "Initialize Trident in the current Anchor workspace.",
28 override_usage = "\nTrident will skip initialization if Trident.toml already exists."
29 )]
30 Init {
31 #[arg(
32 short,
33 long,
34 required = false,
35 help = "Force Trident initialization. Trident dependencies will be updated based on the version of Trident CLI."
36 )]
37 force: bool,
38 #[arg(
39 short,
40 long,
41 required = false,
42 help = "Skip building the program before initializing Trident."
43 )]
44 skip_build: bool,
45 #[arg(
46 short,
47 long,
48 required = false,
49 help = "Specify the name of the program for which fuzz test will be generated.",
50 value_name = "FILE"
51 )]
52 program_name: Option<String>,
53 #[arg(
54 short,
55 long,
56 required = false,
57 help = "Name of the fuzz test to initialize.",
58 value_name = "NAME"
59 )]
60 test_name: Option<String>,
61 },
62 #[command(
63 about = "Run fuzz subcommands.",
64 override_usage = "With fuzz subcommands you can add new fuzz test \
65 template or you can run fuzz test on already initialzied one.\
66 \n\n\x1b[1m\x1b[4mEXAMPLE:\x1b[0m\
67 \n trident add\
68 \n trident fuzz run fuzz_0\
69 \n trident fuzz debug \x1b[92m<FUZZ_TARGET>\x1b[0m \x1b[92m<SEED>\x1b[0m"
70 )]
71 Fuzz {
72 #[clap(subcommand)]
73 subcmd: FuzzCommand,
74 },
75 #[command(about = "Clean build target, additionally perform `anchor clean`")]
76 Clean,
77 #[command(about = "Start HTTP server to serve fuzzing dashboards")]
78 Server {
79 #[arg(
80 short,
81 long,
82 required = false,
83 help = "Directory to monitor for dashboard files",
84 value_name = "DIR",
85 default_value = ".fuzz-artifacts"
86 )]
87 directory: String,
88 #[arg(
89 short,
90 long,
91 required = false,
92 help = "Port to run the server on",
93 value_name = "PORT",
94 default_value = "8000"
95 )]
96 port: u16,
97 #[arg(
98 long,
99 required = false,
100 help = "Host to bind the server to",
101 value_name = "HOST",
102 default_value = "localhost"
103 )]
104 host: String,
105 },
106 #[command(about = "Compare two regression JSON files and identify differing iteration seeds")]
107 Compare {
108 #[arg(help = "Path to the first regression JSON file", value_name = "FILE1")]
109 file1: String,
110 #[arg(help = "Path to the second regression JSON file", value_name = "FILE2")]
111 file2: String,
112 },
113}
114
115#[throws]
116pub async fn start() {
117 let cli = Cli::parse();
118
119 match cli.command {
120 Command::How => command::howto()?,
121 Command::Fuzz { subcmd } => command::fuzz(subcmd).await?,
122 Command::Init {
123 force,
124 skip_build,
125 program_name,
126 test_name,
127 } => command::init(force, skip_build, program_name, test_name).await?,
128 Command::Clean => command::clean().await?,
129 Command::Server {
130 directory,
131 port,
132 host,
133 } => command::server(directory, port, host).await?,
134 Command::Compare { file1, file2 } => command::compare_regression(file1, file2)?,
135 }
136}