Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
brockelmore committed Dec 8, 2023
1 parent 49a7cae commit 357d1c9
Show file tree
Hide file tree
Showing 100 changed files with 701 additions and 558 deletions.
11 changes: 6 additions & 5 deletions crates/analyzers/src/bounds.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::{LocSpan, LocStrSpan, ReportConfig, VarBoundAnalysis, FunctionVarsBoundAnalysis};
use crate::{FunctionVarsBoundAnalysis, LocSpan, LocStrSpan, ReportConfig, VarBoundAnalysis};

use graph::{
GraphBackend, Range, RangeEval, SolcRange,
range_string::ToRangeString,
nodes::ContextNode,
nodes::ContextNode, range_string::ToRangeString, GraphBackend, Range, RangeEval, SolcRange,
};

use ariadne::{Color, Fmt, Label, Span};
Expand Down Expand Up @@ -106,7 +104,10 @@ impl OrderedAnalysis {
Self { analyses }
}

pub fn from_func_analysis(fvba: FunctionVarsBoundAnalysis, analyzer: &impl GraphBackend) -> Self {
pub fn from_func_analysis(
fvba: FunctionVarsBoundAnalysis,
analyzer: &impl GraphBackend,
) -> Self {
let mut analyses = Self::default();
fvba.vars_by_ctx.iter().for_each(|(_ctx, bas)| {
bas.iter().for_each(|ba| {
Expand Down
11 changes: 5 additions & 6 deletions crates/analyzers/src/func_analyzer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
use crate::{
bounds::range_parts,
VarBoundAnalysis, VarBoundAnalyzer, LocStrSpan, ReportConfig,
ReportKind, ReportDisplay,
bounds::range_parts, LocStrSpan, ReportConfig, ReportDisplay, ReportKind, VarBoundAnalysis,
VarBoundAnalyzer,
};

use graph::{
GraphBackend, AnalyzerBackend,
nodes::{ContextNode, KilledKind},
range_string::ToRangeString,
solvers::{SolverAtom, Atomize}
solvers::{Atomize, SolverAtom},
AnalyzerBackend, GraphBackend,
};
use shared::Search;

use ariadne::{Color, Config, Fmt, Label, Report, Span};
use solang_parser::pt::{CodeLocation};
use solang_parser::pt::CodeLocation;
use std::collections::{BTreeMap, BTreeSet};

mod report_display;
Expand Down
13 changes: 3 additions & 10 deletions crates/analyzers/src/func_analyzer/report_display.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
use crate::{
LocStrSpan,
ReportKind,
FunctionVarsBoundAnalysis,
ReportDisplay
};
use crate::{FunctionVarsBoundAnalysis, LocStrSpan, ReportDisplay, ReportKind};

use graph::{
GraphBackend,
};
use graph::GraphBackend;

use ariadne::{Color, Config, Fmt, Label, Report, Span, Cache};
use ariadne::{Cache, Color, Config, Fmt, Label, Report, Span};

use std::collections::BTreeMap;

Expand Down
2 changes: 1 addition & 1 deletion crates/analyzers/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod bounds;

use graph::{GraphBackend, AnalyzerBackend};
use ariadne::{Cache, Label, Report, ReportKind, Span};
use graph::{AnalyzerBackend, GraphBackend};
use shared::Search;
use solang_parser::pt::Loc;
use std::collections::BTreeMap;
Expand Down
7 changes: 3 additions & 4 deletions crates/analyzers/src/var_analyzer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::{
bounds::{range_parts, AnalysisItem, RangePart},
LocStrSpan, ReportConfig
LocStrSpan, ReportConfig,
};

use graph::{
GraphBackend, AnalyzerBackend, Range, SolcRange,
nodes::{ContextVarNode, ContextNode, KilledKind},
nodes::{ContextNode, ContextVarNode, KilledKind},
AnalyzerBackend, GraphBackend, Range, SolcRange,
};
use shared::Search;

Expand All @@ -15,7 +15,6 @@ use solang_parser::pt::{CodeLocation, StorageLocation};
use std::collections::BTreeMap;

mod report_display;
pub use report_display::*;

#[derive(PartialOrd, Eq, PartialEq, Ord, Clone, Debug)]
pub struct CtxSwitch {
Expand Down
13 changes: 4 additions & 9 deletions crates/analyzers/src/var_analyzer/report_display.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
use crate::{
LocStrSpan,
ReportKind,
ReportDisplay,
VarBoundAnalysis,
bounds::{range_parts, AnalysisItem}
bounds::{range_parts, AnalysisItem},
LocStrSpan, ReportDisplay, ReportKind, VarBoundAnalysis,
};

use graph::{
GraphBackend,
};
use graph::GraphBackend;

use ariadne::{Color, Config, Fmt, Label, Report, Span, Cache};
use ariadne::{Cache, Color, Config, Fmt, Label, Report, Span};

impl ReportDisplay for VarBoundAnalysis {
fn report_kind(&self) -> ReportKind {
Expand Down
97 changes: 47 additions & 50 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@

use shared::GraphDot;
use analyzers::{
ReportDisplay, FunctionVarsBoundAnalyzer, ReportConfig
};
use analyzers::{FunctionVarsBoundAnalyzer, ReportConfig, ReportDisplay};
use graph::{
Edge, Range,
nodes::{ContractNode, FunctionNode, Concrete},
elem::{Elem, RangeElem},
solvers::{SolcSolver, AtomicSolveStatus, BruteBinSearchSolver},
nodes::{Concrete, ContractNode, FunctionNode},
solvers::{AtomicSolveStatus, BruteBinSearchSolver, SolcSolver},
Edge, Range,
};
use pyrometer::{Root, SourcePath, Analyzer};
use shared::{Search};
use pyrometer::{Analyzer, Root, SourcePath};
use shared::GraphDot;
use shared::Search;

use ariadne::sources;
use clap::{ArgAction, Parser, ValueHint};
use tracing_subscriber::prelude::*;
use ethers_core::types::I256;
use tracing_subscriber::prelude::*;

use std::{
collections::{BTreeMap, HashMap},
path::PathBuf,
env::{self},
fs
fs,
path::PathBuf,
};

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -279,46 +276,46 @@ fn main() {

// TODO: clean this up to actually run on all contracts
// if args.swq {
// println!("Creating SWQ graph for {} contracts", all_contracts.len());
// let mut cond_graph: Option<ConditionGraph> = None;
// for i in 0..all_contracts.len() {
// match (&mut cond_graph, analyzer.func_query(all_contracts[i])) {
// (Some(ref mut existing), Some(new)) => {
// existing.append_graph(new);
// }
// (None, Some(new)) => {
// cond_graph = Some(new);
// }
// _ => {}
// }
// }
// println!("Creating SWQ graph for {} contracts", all_contracts.len());
// let mut cond_graph: Option<ConditionGraph> = None;
// for i in 0..all_contracts.len() {
// match (&mut cond_graph, analyzer.func_query(all_contracts[i])) {
// (Some(ref mut existing), Some(new)) => {
// existing.append_graph(new);
// }
// (None, Some(new)) => {
// cond_graph = Some(new);
// }
// _ => {}
// }
// }

// if let Some(graph) = cond_graph {
// println!("{}", graph.dot_str());
// graph.open_dot();
// } else {
// println!("no graph");
// }
// if let Some(graph) = cond_graph {
// println!("{}", graph.dot_str());
// graph.open_dot();
// } else {
// println!("no graph");
// }
// } else if args.swq_mermaid {
// println!("Creating SWQ graph for {} contracts", all_contracts.len());
// let mut cond_graph: Option<ConditionGraph> = None;
// for i in 0..all_contracts.len() {
// match (&mut cond_graph, analyzer.func_query(all_contracts[i])) {
// (Some(ref mut existing), Some(new)) => {
// existing.append_graph(new);
// }
// (None, Some(new)) => {
// cond_graph = Some(new);
// }
// _ => {}
// }
// }
// println!("Creating SWQ graph for {} contracts", all_contracts.len());
// let mut cond_graph: Option<ConditionGraph> = None;
// for i in 0..all_contracts.len() {
// match (&mut cond_graph, analyzer.func_query(all_contracts[i])) {
// (Some(ref mut existing), Some(new)) => {
// existing.append_graph(new);
// }
// (None, Some(new)) => {
// cond_graph = Some(new);
// }
// _ => {}
// }
// }

// if let Some(graph) = cond_graph {
// println!("{}", graph.mermaid_str());
// } else {
// println!("no graph");
// }
// if let Some(graph) = cond_graph {
// println!("{}", graph.mermaid_str());
// } else {
// println!("no graph");
// }
// } else {
let _t1 = std::time::Instant::now();
if args.contracts.is_empty() {
Expand Down
30 changes: 14 additions & 16 deletions crates/graph/src/graph_elements.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
use crate::{VarType, nodes::*};
use crate::{nodes::*, VarType};

use shared::{ NodeIdx, AnalyzerLike, GraphLike, Heirarchical};
use shared::{AnalyzerLike, GraphLike, Heirarchical, NodeIdx};

use lazy_static::lazy_static;
use solang_parser::pt::Identifier;

use std::collections::HashMap;

pub trait GraphBackend: GraphLike<
Edge = Edge,
Node = Node,

> {}
pub trait AnalyzerBackend: AnalyzerLike<
Builtin = Builtin,
MsgNode = MsgNode,
BlockNode = BlockNode,
FunctionParam = FunctionParam,
FunctionReturn = FunctionReturn,
Function = Function
> + GraphBackend {}
pub trait GraphBackend: GraphLike<Edge = Edge, Node = Node> {}
pub trait AnalyzerBackend:
AnalyzerLike<
Builtin = Builtin,
MsgNode = MsgNode,
BlockNode = BlockNode,
FunctionParam = FunctionParam,
FunctionReturn = FunctionReturn,
Function = Function,
> + GraphBackend
{
}

pub trait AsDotStr {
fn as_dot_str(&self, analyzer: &impl GraphBackend) -> String;
Expand Down Expand Up @@ -373,4 +372,3 @@ pub enum ContextEdge {
/// Unused
Range,
}

5 changes: 2 additions & 3 deletions crates/graph/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
mod graph_elements;
mod var_type;
mod range;
mod var_type;

pub mod nodes;
pub mod solvers;


pub use var_type::*;
pub use graph_elements::*;
pub use range::*;
pub use var_type::*;
2 changes: 1 addition & 1 deletion crates/graph/src/nodes/block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{GraphBackend, AsDotStr, Node, GraphError};
use crate::{AsDotStr, GraphBackend, GraphError, Node};
use shared::NodeIdx;

use ethers_core::types::{Address, H256, U256};
Expand Down
27 changes: 18 additions & 9 deletions crates/graph/src/nodes/builtin.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
use crate::{AnalyzerBackend, GraphBackend, SolcRange, VarType, Node, GraphError, nodes::Concrete};
use crate::{nodes::Concrete, AnalyzerBackend, GraphBackend, GraphError, Node, SolcRange, VarType};

use shared::NodeIdx;
use crate::range::elem::*;
use shared::NodeIdx;

use solang_parser::pt::{Type, Expression, Loc};
use ethers_core::types::{Address, H256, U256, I256};
use ethers_core::types::{Address, H256, I256, U256};
use solang_parser::pt::{Expression, Loc, Type};

/// A builtin node
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
pub struct BuiltInNode(pub usize);

impl BuiltInNode {
/// Gets the underlying builtin from the graph
pub fn underlying<'a>(&self, analyzer: &'a impl GraphBackend) -> Result<&'a Builtin, GraphError> {
pub fn underlying<'a>(
&self,
analyzer: &'a impl GraphBackend,
) -> Result<&'a Builtin, GraphError> {
match analyzer.node(*self) {
Node::Builtin(b) => Ok(b),
e => Err(GraphError::NodeConfusion(format!(
Expand Down Expand Up @@ -85,7 +88,10 @@ impl BuiltInNode {
}

/// Returns whether the builtin is a sized array or bytes
pub fn maybe_array_size(&self, analyzer: &impl GraphBackend) -> Result<Option<U256>, GraphError> {
pub fn maybe_array_size(
&self,
analyzer: &impl GraphBackend,
) -> Result<Option<U256>, GraphError> {
match self.underlying(analyzer)? {
Builtin::SizedArray(s, _) => Ok(Some(*s)),
Builtin::Bytes(s) => Ok(Some(U256::from(*s))),
Expand All @@ -104,7 +110,10 @@ impl BuiltInNode {
}

/// Returns the zero range for this builtin type, i.e. uint256 -> [0, 0]
pub fn zero_range(&self, analyzer: &impl GraphBackend) -> Result<Option<SolcRange>, GraphError> {
pub fn zero_range(
&self,
analyzer: &impl GraphBackend,
) -> Result<Option<SolcRange>, GraphError> {
Ok(self.underlying(analyzer)?.zero_range())
}
}
Expand Down Expand Up @@ -174,7 +183,7 @@ impl Builtin {
}
}

/// Possible types that this type could have been had a literal been parsed differently - i.e. a `1`
/// Possible types that this type could have been had a literal been parsed differently - i.e. a `1`
/// could be uint8 to uint256.
pub fn possible_builtins_from_ty_inf(&self) -> Vec<Builtin> {
let mut builtins = vec![];
Expand Down Expand Up @@ -459,4 +468,4 @@ impl Builtin {
),
}
}
}
}
Loading

0 comments on commit 357d1c9

Please sign in to comment.