Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moves from recursion parsing to stack parsing #88

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
5a32ab3
basic stack-based impl
brockelmore Jul 15, 2024
8439b9f
some more working exprs
brockelmore Jul 15, 2024
b9e83d1
ifs
brockelmore Jul 15, 2024
c36c1e4
ifs working
brockelmore Jul 15, 2024
16b7fd5
ifs working for real
brockelmore Jul 16, 2024
d6ee1a6
fix some function call things
brockelmore Jul 16, 2024
6dc905b
fixing func calls
brockelmore Jul 16, 2024
7d1048d
cleaned up subctx creation
brockelmore Jul 16, 2024
5a64089
cleanup
brockelmore Jul 16, 2024
76d4bb1
cleanup and super working
brockelmore Jul 17, 2024
53e4c21
fix ifs, add more support
brockelmore Jul 17, 2024
e02fc09
tmp
brockelmore Jul 17, 2024
5a647e7
some assembly
brockelmore Jul 17, 2024
09a0de4
yul func support
brockelmore Jul 18, 2024
bf4cf20
push fix
brockelmore Jul 18, 2024
c269692
array fixes
brockelmore Jul 18, 2024
46c6813
cond op
brockelmore Jul 18, 2024
bcfcb6b
clean up
brockelmore Jul 18, 2024
2daf5c3
remove dead code
brockelmore Jul 18, 2024
615ad5e
lint
brockelmore Jul 18, 2024
164d47e
exprflag in ctx
brockelmore Jul 19, 2024
1128db4
improved function resolution
brockelmore Jul 19, 2024
ad9c1f8
feat: add coverage tests
plotchy Jul 20, 2024
765f27a
adding comments for match arm examples
plotchy Jul 20, 2024
46a5594
more fixes
brockelmore Jul 20, 2024
d200403
more require branch matches
plotchy Jul 20, 2024
4dcf69f
two failing tests remain
brockelmore Jul 20, 2024
84ae430
fixed intrinsics
brockelmore Jul 20, 2024
66da799
print cleanup
brockelmore Jul 20, 2024
802f524
lint
brockelmore Jul 20, 2024
76fa00d
happy clippy
brockelmore Jul 20, 2024
5b84232
happy fix
brockelmore Jul 20, 2024
9f8e862
all tests pass :)
brockelmore Jul 21, 2024
3f3e21e
remove panic
brockelmore Jul 21, 2024
83d11cc
lint
brockelmore Jul 21, 2024
5035e5d
reenable tests and modifiers working
brockelmore Jul 21, 2024
bf7591b
specialized builtins
brockelmore Jul 22, 2024
88d6a95
variable coverage
plotchy Jul 22, 2024
801de39
tests for delete
plotchy Jul 22, 2024
84c861b
prep delete for "pyro" test cases
plotchy Jul 22, 2024
197b5b0
Merge remote-tracking branch 'origin/plotchy/coverage' into brock/no_…
brockelmore Jul 22, 2024
044f313
small fixes
brockelmore Jul 22, 2024
a88c7df
lint
brockelmore Jul 22, 2024
1232c95
refactor tests to use todo.sol and broken.sol (#90)
plotchy Jul 22, 2024
38c69f7
fixes
brockelmore Jul 22, 2024
35e0232
restructure broken tests
brockelmore Jul 22, 2024
2c8e918
remove prints
brockelmore Jul 22, 2024
26ae57a
fix ands
brockelmore Jul 22, 2024
2c0a834
lint
brockelmore Jul 22, 2024
81c290c
feat: add support for array literals and slices (#91)
brockelmore Aug 2, 2024
95bd97d
add require in array slice, remove parsing of emits
brockelmore Aug 2, 2024
53b2b17
add pop after require (#93)
brockelmore Aug 2, 2024
85f5284
feat: support selfdestruct (#94)
brockelmore Aug 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ members = [
resolver = "2"

[workspace.package]
version = "0.2.0"
version = "0.3.0"
edition = "2021"
authors = ["Brock Elmore"]
license = "MIT OR Apache-2.0"
Expand Down
45 changes: 26 additions & 19 deletions crates/analyzers/src/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@ use crate::{FunctionVarsBoundAnalysis, LocSpan, LocStrSpan, ReportConfig, VarBou

use graph::{
elem::Elem,
nodes::{Concrete, ContextNode},
nodes::{Concrete, ContextNode, KilledKind},
range_string::ToRangeString,
GraphBackend, Range, RangeEval, SolcRange,
};
use shared::{RangeArena, StorageLocation};

use ariadne::{Color, Fmt, Label, Span};
use std::collections::{BTreeMap, BTreeSet};
use std::{
collections::{BTreeMap, BTreeSet},
fmt,
};

pub static MIN_COLOR: Color = Color::Fixed(111);
pub static MAX_COLOR: Color = Color::Fixed(106);

pub fn killed_kind_color(kind: &KilledKind) -> Color {
match kind {
KilledKind::Ended => Color::Green,
KilledKind::Unreachable => Color::Rgb(255, 121, 0),
_ => Color::Red,
}
}

#[derive(PartialEq, Eq, Clone)]
pub struct AnalysisItem {
pub init: bool,
Expand Down Expand Up @@ -159,9 +170,9 @@ impl RangePart {

pub fn to_normal_string(&self) -> String {
match self {
e @ RangePart::Equal(_) => format!(" == {}", e.to_string()),
e @ RangePart::Inclusion(..) => format!(" ∈ {}", e.to_string()),
e @ RangePart::Exclusion(_) => format!("&& ∉ {{{}}}", e.to_string()),
e @ RangePart::Equal(_) => format!(" == {}", e),
e @ RangePart::Inclusion(..) => format!(" ∈ {}", e),
e @ RangePart::Exclusion(_) => format!("&& ∉ {{{}}}", e),
}
}
}
Expand Down Expand Up @@ -214,16 +225,11 @@ impl From<AnalysisItem> for Label<LocStrSpan> {
}
}

impl ToString for StrippedAnalysisItem {
fn to_string(&self) -> String {
format!(
impl fmt::Display for StrippedAnalysisItem {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}{}{}",
// match self.storage {
// Some(StorageLocation::Memory(..)) => "Memory var ",
// Some(StorageLocation::Storage(..)) => "Storage var ",
// Some(StorageLocation::Calldata(..)) => "Calldata var ",
// None => "",
// },
self.name,
self.parts
.iter()
Expand All @@ -239,12 +245,13 @@ impl ToString for StrippedAnalysisItem {
}
}

impl ToString for RangePart {
fn to_string(&self) -> String {
impl fmt::Display for RangePart {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
RangePart::Equal(inner) => inner.to_string(),
RangePart::Inclusion(min, max) => format!("[ {}, {} ]", min, max),
RangePart::Exclusion(inner) => format!(
RangePart::Equal(inner) => write!(f, "{}", inner),
RangePart::Inclusion(min, max) => write!(f, "[ {}, {} ]", min, max),
RangePart::Exclusion(inner) => write!(
f,
"{{{}}}",
inner
.iter()
Expand Down
36 changes: 12 additions & 24 deletions crates/analyzers/src/func_analyzer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::bounds::killed_kind_color;
use crate::{
bounds::range_parts, LocStrSpan, ReportConfig, ReportDisplay, ReportKind, VarBoundAnalysis,
VarBoundAnalyzer,
Expand Down Expand Up @@ -60,19 +61,6 @@ impl<'a> FunctionVarsBoundAnalysis {
.iter()
.map(|var| (var.as_controllable_name(analyzer, arena).unwrap(), var))
.collect::<BTreeMap<_, _>>();
// create the bound strings
// let atoms = ctx.dep_atoms(analyzer).unwrap();
// println!("had {} atoms", atoms.len());
// let mut handled_atom = vec![];
// let mut bounds_string: Vec<String> = vec![];
// atoms.iter().enumerate().for_each(|(i, atom)| {
// let atom_str = atom.to_range_string(true, analyzer, arena).s;
// if !handled_atom.contains(&atom_str) {
// handled_atom.push(atom_str.clone());
// bounds_string.push(format!("{}. {}", i + 1, atom_str))
// }
// });
// let bounds_string = bounds_string.into_iter().collect::<Vec<_>>().join("\n");

let bounds_string = deps
.iter()
Expand Down Expand Up @@ -231,7 +219,7 @@ impl<'a> FunctionVarsBoundAnalysis {
labels.push(
Label::new(killed_loc.clone())
.with_message(kind.analysis_str())
.with_color(Color::Red)
.with_color(killed_kind_color(kind))
.with_priority(10),
);
}
Expand All @@ -247,8 +235,8 @@ impl<'a> FunctionVarsBoundAnalysis {
if !self_handled {
labels.push(
Label::new(killed_span.clone())
.with_message(kind.analysis_str().fg(Color::Red))
.with_color(Color::Red),
.with_message(kind.analysis_str().fg(killed_kind_color(kind)))
.with_color(killed_kind_color(kind)),
);
}
}
Expand Down Expand Up @@ -332,14 +320,14 @@ pub trait FunctionVarsBoundAnalyzer: VarBoundAnalyzer + Search + AnalyzerBackend
{
return None;
}
if !report_config.show_reverts
&& matches!(
fork.underlying(self).unwrap().killed,
Some((_, KilledKind::Revert))
)
{
return None;
}
// if !report_config.show_reverts
// && matches!(
// fork.underlying(self).unwrap().killed,
// Some((_, KilledKind::Revert))
// )
// {
// return None;
// }
let mut parents = fork.parent_list(self).unwrap();
parents.reverse();
parents.push(*fork);
Expand Down
5 changes: 3 additions & 2 deletions crates/analyzers/src/func_analyzer/report_display.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::bounds::killed_kind_color;
use crate::{FunctionVarsBoundAnalysis, LocStrSpan, ReportDisplay, ReportKind};

use graph::{elem::Elem, nodes::Concrete, GraphBackend};
Expand Down Expand Up @@ -74,8 +75,8 @@ impl<'a> ReportDisplay for CLIFunctionVarsBoundAnalysis<'a> {
if let Some((killed_span, kind)) = &self.func_var_bound_analysis.ctx_killed {
report = report.with_label(
Label::new(killed_span.clone())
.with_message(kind.analysis_str().fg(Color::Red))
.with_color(Color::Red),
.with_message(kind.analysis_str().fg(killed_kind_color(kind)))
.with_color(killed_kind_color(kind)),
);
}

Expand Down
30 changes: 16 additions & 14 deletions crates/analyzers/src/var_analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ pub trait VarBoundAnalyzer: Search + AnalyzerBackend + Sized {
let mut curr = cvar.first_version(self);

let ctx = cvar.ctx(self);
let (func_span, func_body_span) =
if let Some(fn_call) = ctx.underlying(self).unwrap().fn_call {
let underlying = ctx.underlying(self).unwrap();
let (func_span, func_body_span) = if let Some(fn_call) = underlying.fn_call() {
if underlying.is_ext_fn_call() {
(
LocStrSpan::new(file_mapping, fn_call.underlying(self).unwrap().loc),
fn_call
Expand All @@ -172,18 +173,7 @@ pub trait VarBoundAnalyzer: Search + AnalyzerBackend + Sized {
.as_ref()
.map(|body| LocStrSpan::new(file_mapping, body.loc())),
)
} else if let Some(ext_fn_call) = ctx.underlying(self).unwrap().ext_fn_call {
(
LocStrSpan::new(file_mapping, ext_fn_call.underlying(self).unwrap().loc),
ext_fn_call
.underlying(self)
.unwrap()
.body
.as_ref()
.map(|body| LocStrSpan::new(file_mapping, body.loc())),
)
} else {
let fn_call = ctx.associated_fn(self).unwrap();
(
LocStrSpan::new(file_mapping, fn_call.underlying(self).unwrap().loc),
fn_call
Expand All @@ -193,7 +183,19 @@ pub trait VarBoundAnalyzer: Search + AnalyzerBackend + Sized {
.as_ref()
.map(|body| LocStrSpan::new(file_mapping, body.loc())),
)
};
}
} else {
let fn_call = ctx.associated_fn(self).unwrap();
(
LocStrSpan::new(file_mapping, fn_call.underlying(self).unwrap().loc),
fn_call
.underlying(self)
.unwrap()
.body
.as_ref()
.map(|body| LocStrSpan::new(file_mapping, body.loc())),
)
};

let mut ba: VarBoundAnalysis = if let Some(inherited) = inherited {
let mut new_ba = inherited.clone();
Expand Down
5 changes: 3 additions & 2 deletions crates/analyzers/src/var_analyzer/report_display.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::bounds::killed_kind_color;
use crate::{
bounds::{range_parts, AnalysisItem},
LocStrSpan, ReportDisplay, ReportKind, VarBoundAnalysis,
Expand Down Expand Up @@ -84,8 +85,8 @@ impl ReportDisplay for VarBoundAnalysis {
if let Some((killed_span, kind)) = &self.ctx_killed {
report = report.with_label(
Label::new(killed_span.clone())
.with_message(kind.analysis_str().fg(Color::Red))
.with_color(Color::Red),
.with_message(kind.analysis_str().fg(killed_kind_color(kind)))
.with_color(killed_kind_color(kind)),
);
}

Expand Down
21 changes: 8 additions & 13 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ struct Args {

#[clap(long)]
pub minimize_debug: Option<String>,

#[clap(long, default_value = "false")]
pub debug_stack: bool,
}

pub fn subscriber() {
Expand Down Expand Up @@ -243,6 +246,7 @@ fn main() {
root: Root::RemappingsDirectory(env::current_dir().unwrap()),
debug_panic: args.debug_panic || args.minimize_debug.is_some(),
minimize_debug: args.minimize_debug,
debug_stack: args.debug_stack,
..Default::default()
};

Expand Down Expand Up @@ -300,7 +304,6 @@ fn main() {

println!("DONE ANALYZING IN: {parse_time}ms. Writing to cli...");

// println!("Arena: {:#?}", analyzer.range_arena);
if unsafe { USE_DEBUG_SITE } {
use pyrometer::graph_backend::mermaid_str;
use pyrometer::graph_backend::post_to_site_arena;
Expand All @@ -324,7 +327,6 @@ fn main() {
if args.stats {
println!("{}", analyzer.stats(t_end, arena));
}
// println!("Arena: {:#?}", analyzer.range_arena);

// use self.sources to fill a BTreeMap with the file_no and SourcePath.path_to_solidity_file
let mut file_mapping: BTreeMap<usize, String> = BTreeMap::new();
Expand Down Expand Up @@ -366,20 +368,10 @@ fn main() {
analyzer.open_mermaid(arena);
}

// println!("{}", analyzer.range_arena.ranges.iter().map(|i| {
// let j = i.borrow();
// let (min_cached, max_cached) = j.is_min_max_cached(&analyzer);
// format!("\t{j}, is cached: {min_cached}, {max_cached}\n")
// }).collect::<Vec<_>>().join(""));
// println!("{}", analyzer.range_arena.map.iter().map(|(k, v)| {
// format!("\t{}: {}\n", k, v)
// }).collect::<Vec<_>>().join(""));

if args.debug {
return;
}

// println!("getting contracts");
let all_contracts = analyzer
.search_children(entry, &Edge::Contract)
.into_iter()
Expand Down Expand Up @@ -431,7 +423,10 @@ fn main() {
// } else {
let _t1 = std::time::Instant::now();
if args.contracts.is_empty() {
let funcs = analyzer.search_children(entry, &Edge::Func);
let mut funcs = analyzer.search_children(entry, &Edge::Func);
funcs.extend(analyzer.search_children(entry, &Edge::FallbackFunc));
funcs.extend(analyzer.search_children(entry, &Edge::Constructor));
funcs.extend(analyzer.search_children(entry, &Edge::ReceiveFunc));
for func in funcs.into_iter() {
if !args.funcs.is_empty() {
if args.funcs.iter().any(|analyze_for| {
Expand Down
Loading
Loading