Skip to content

Commit

Permalink
Merge branch 'dev' into refactor/literals-instead-of-constants
Browse files Browse the repository at this point in the history
  • Loading branch information
TilakMaddy authored Oct 4, 2024
2 parents 38493e6 + 69a4d5a commit e63862b
Show file tree
Hide file tree
Showing 41 changed files with 1,098 additions and 788 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[attr]generated linguist-generated=true diff=generated

Cargo.lock generated
reports/*.* generated

5 changes: 0 additions & 5 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ jobs:
run: |
git submodule update --init --recursive
- uses: Swatinem/rust-cache@v2
- name: Run cargo test
run: |
cargo test _by_loading_contract_directly
- uses: Swatinem/rust-cache@v2
- name: Run cargo test
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
echo "COMPRESSED_BINARY=compressed/${{ env.BIN_RELEASE_VERSIONED }}.tar.gz" >> $GITHUB_ENV
- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: ${{ env.BIN_RELEASE_VERSIONED }}.tar.gz
path: ${{ env.COMPRESSED_BINARY }}
Expand All @@ -93,7 +93,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Download All Artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
path: artifacts/

Expand Down
19 changes: 15 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 33 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
# - cargo-clippy
##################

# Run if setting up for first time
.PHONY: help
help:
@cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: setup
setup:
setup: ## Run if setting up for first time
git submodule update --init --recursive
cd tests/ccip-contracts/contracts/;\
pnpm install
Expand All @@ -19,14 +22,34 @@ setup:
cd tests/2024-07-templegold/;\
yarn

# Check for tests to pass

.PHONY: pr
pr: ## Run before sending PRs
cargo +nightly fmt --all
cargo test --quiet
cargo clippy --quiet --workspace --all-targets --all-features
cli/reportgen.sh


.PHONY: build
build: ## Build the compiler
cargo build --release


.PHONY: test
test:
test: ## Run the compiler unit tests
cargo test
cargo clippy --quiet --workspace --all-targets --all-features

.PHONY: fmt
fmt: ## Run the rust formatter
cargo +nightly fmt --all

.PHONY: test-watch
test-watch: ## Run compiler tests when files change
watchexec -e rs,toml "cargo test --quiet"


# Debug print vars with `make print-VAR_NAME`
print-%: ; @echo $*=$($*)

# Run before sending PRs
.PHONY: reportgen
reportgen:
cargo fmt
cargo clippy -- -D warnings
cli/reportgen.sh
7 changes: 4 additions & 3 deletions aderyn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aderyn"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
authors = ["Cyfrin <[email protected]>"]
description = "Rust based Solidity AST analyzer"
Expand All @@ -10,15 +10,16 @@ default-run = "aderyn"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aderyn_driver = { path = "../aderyn_driver", version = "0.2.0" }
aderyn_driver = { path = "../aderyn_driver", version = "0.3.0" }
clap = { version = "4.4.6", features = ["derive"] }
reqwest = { version = "0.12.2", default-features = false, features = ["blocking", "json", "rustls-tls"] }
semver = "1.0.22"
serde = { version = "1.0.160", features = ["derive"] }
serde_json = { version = "1.0.96", features = ["preserve_order"] }
strum = { version = "0.26", features = ["derive"] }
notify-debouncer-full = { version = "0.3.1", default-features = false }
notify-debouncer-full = "0.3.1"
cyfrin-foundry-compilers = { version = "0.3.20-aderyn", features = ["svm-solc"] }
termcolor = "1.4.1"
tokio = { version = "1.40.0", features = ["full"] }
tower-lsp = "0.20.0"
log = "0.4.22"
Expand Down
36 changes: 27 additions & 9 deletions aderyn/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
use aderyn_driver::detector::{get_all_detectors_names, get_issue_detector_by_name, IssueSeverity};
use semver::Version;
use serde_json::Value;
use std::{fs::File, io::Write, path::PathBuf, str::FromStr};
use strum::IntoEnumIterator;

pub fn create_aderyn_toml_file_at(directory: String) {
let aderyn_toml_path = PathBuf::from_str(&directory).unwrap().join("aderyn.toml");
let mut file = File::create_new(aderyn_toml_path.clone()).expect("File already exists!");
file.write_all(include_bytes!("../templates/aderyn.toml"))
.expect("To write contents into aderyn.toml");
println!("Created aderyn.toml at {}", aderyn_toml_path.display());
}

mod panic;

pub fn initialize_niceties() {
// Crash with a nice message on panic
panic::add_handler()
}

pub mod lsp;

pub fn print_detail_view(detector_name: &str) {
Expand Down Expand Up @@ -72,21 +88,23 @@ fn right_pad(s: &str, by: usize) -> String {

pub static APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));

pub fn aderyn_is_currently_running_newest_version() -> Result<bool, reqwest::Error> {
pub fn aderyn_is_currently_running_newest_version() -> Option<bool> {
let client = reqwest::blocking::Client::builder()
.user_agent(APP_USER_AGENT)
.build()?;
.build()
.expect("client is unable to initialize");

let latest_version_checker = client
.get("https://api.github.com/repos/Cyfrin/aderyn/releases/latest")
.send()?;
.send()
.ok()?;

let data = latest_version_checker.json::<Value>()?;
let newest =
Version::parse(data["tag_name"].as_str().unwrap().replace('v', "").as_str()).unwrap();
let current = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
let data = latest_version_checker.json::<Value>().ok()?;
let version_string = data["tag_name"].as_str()?;
let newest = Version::parse(version_string.replace('v', "").as_str()).ok()?;
let current = Version::parse(env!("CARGO_PKG_VERSION")).expect("Pkg version not available");

Ok(current >= newest)
Some(current >= newest)
}

#[cfg(test)]
Expand All @@ -95,6 +113,6 @@ mod latest_version_checker_tests {

#[test]
fn can_get_latest_version_from_crate_registry() {
assert!(aderyn_is_currently_running_newest_version().is_ok())
assert!(aderyn_is_currently_running_newest_version().is_some())
}
}
21 changes: 18 additions & 3 deletions aderyn/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use aderyn::{
aderyn_is_currently_running_newest_version, lsp::spin_up_language_server,
print_all_detectors_view, print_detail_view,
aderyn_is_currently_running_newest_version, create_aderyn_toml_file_at, initialize_niceties,
lsp::spin_up_language_server, print_all_detectors_view, print_detail_view,
};
use aderyn_driver::driver::{self, Args};

Expand All @@ -17,6 +17,10 @@ pub struct CommandLineArgs {
#[arg(default_value = ".")]
root: String,

/// Initialize aderyn.toml in [ROOT] which hosts all the configuration to override defaults
#[arg(long)]
init: bool,

/// Path to the source contracts. If not provided, the ROOT directory will be used.
///
/// For example, in a foundry repo:
Expand Down Expand Up @@ -85,6 +89,7 @@ enum RegistryCommand {
}

fn main() {
initialize_niceties();
let cmd_args = CommandLineArgs::parse();

if let Some(reg) = cmd_args.registry {
Expand All @@ -100,6 +105,16 @@ fn main() {
return;
}

if cmd_args.root == "init" {
create_aderyn_toml_file_at(".".to_string());
return;
}

if cmd_args.init {
create_aderyn_toml_file_at(cmd_args.root);
return;
}

let mut args: Args = Args {
root: cmd_args.root,
output: cmd_args.output,
Expand All @@ -126,7 +141,7 @@ fn main() {

// Check for updates
if !cmd_args.skip_update_check {
if let Ok(yes) = aderyn_is_currently_running_newest_version() {
if let Some(yes) = aderyn_is_currently_running_newest_version() {
if !yes {
println!();
println!("NEW VERSION OF ADERYN AVAILABLE! Please run `cyfrinup` to upgrade.");
Expand Down
79 changes: 79 additions & 0 deletions aderyn/src/panic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#![allow(clippy::unwrap_used)]
use std::{io::Write, panic::PanicInfo};
use termcolor::{Color, ColorSpec, WriteColor};

use std::io::IsTerminal;

use termcolor::{BufferWriter, ColorChoice};

pub fn stderr_buffer_writer() -> BufferWriter {
// Prefer to add colors to the output only if it is forced via an environment variable or
// because it's a terminal

let color_choice = {
if std::env::var("FORCE_COLOR").is_ok_and(|e| !e.is_empty()) {
ColorChoice::Always
} else if std::io::stderr().is_terminal() {
ColorChoice::Auto
} else {
ColorChoice::Never
}
};

BufferWriter::stderr(color_choice)
}

pub fn add_handler() {
std::panic::set_hook(Box::new(move |info: &PanicInfo<'_>| {
print_compiler_bug_message(info)
}));
}

fn print_compiler_bug_message(info: &PanicInfo<'_>) {
let message = match (
info.payload().downcast_ref::<&str>(),
info.payload().downcast_ref::<String>(),
) {
(Some(s), _) => (*s).to_string(),
(_, Some(s)) => s.to_string(),
(None, None) => "unknown error".into(),
};

let location = match info.location() {
None => "".into(),
Some(location) => format!("{}:{}\n\t", location.file(), location.line()),
};

let buffer_writer = stderr_buffer_writer();
let mut buffer = buffer_writer.buffer();
buffer
.set_color(ColorSpec::new().set_bold(true).set_fg(Some(Color::Red)))
.unwrap();
write!(buffer, "error").unwrap();
buffer.set_color(ColorSpec::new().set_bold(true)).unwrap();
write!(buffer, ": Fatal compiler bug!\n\n").unwrap();
buffer.set_color(&ColorSpec::new()).unwrap();
writeln!(
buffer,
"This is a fatal bug in the Aderyn, sorry!
Please report this crash to https://github.com/cyfrin/aderyn/issues/new and include this error message with your report.
Panic: {location}{message}
Aderyn version: {version}
Operating system: {os}
If you can also share your code and say what file you were editing or any
steps to reproduce the crash that would be a great help.
You may also want to try again with the `ADERYN_LOG=trace` environment
variable set.
",
location = location,
message = message,
version = env!("CARGO_PKG_VERSION"),
os = std::env::consts::OS,
)
.unwrap();
buffer_writer.print(&buffer).unwrap();
}
Loading

0 comments on commit e63862b

Please sign in to comment.