Skip to content

Commit dea99c5

Browse files
authored
fix(lint): bound reentrancy helper analysis (#15063)
* fix(lint): bound reentrancy helper analysis * address steven's comments * fix reentrancy events clippy * address steven's comments
1 parent 23a85ae commit dea99c5

14 files changed

Lines changed: 918 additions & 28 deletions

Cargo.lock

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,10 @@ tempo-alloy = { git = "https://github.com/tempoxyz/tempo", rev = "4d3f1db11a496d
604604
tempo-contracts = { git = "https://github.com/tempoxyz/tempo", rev = "4d3f1db11a496d5fc98bb33d8055de102e5f5e11" }
605605

606606
# solar
607-
solar = { package = "solar-compiler", git = "https://github.com/paradigmxyz/solar", rev = "4393d0dbb8d37df4df5c2840350a73a189441988" }
608-
solar-interface = { package = "solar-interface", git = "https://github.com/paradigmxyz/solar", rev = "4393d0dbb8d37df4df5c2840350a73a189441988" }
609-
solar-ast = { package = "solar-ast", git = "https://github.com/paradigmxyz/solar", rev = "4393d0dbb8d37df4df5c2840350a73a189441988" }
610-
solar-sema = { package = "solar-sema", git = "https://github.com/paradigmxyz/solar", rev = "4393d0dbb8d37df4df5c2840350a73a189441988" }
607+
solar = { package = "solar-compiler", git = "https://github.com/paradigmxyz/solar", rev = "da6b0c3a8c0edd23f8b1414c61418ba78d6c4670" }
608+
solar-interface = { package = "solar-interface", git = "https://github.com/paradigmxyz/solar", rev = "da6b0c3a8c0edd23f8b1414c61418ba78d6c4670" }
609+
solar-ast = { package = "solar-ast", git = "https://github.com/paradigmxyz/solar", rev = "da6b0c3a8c0edd23f8b1414c61418ba78d6c4670" }
610+
solar-sema = { package = "solar-sema", git = "https://github.com/paradigmxyz/solar", rev = "da6b0c3a8c0edd23f8b1414c61418ba78d6c4670" }
611611

612612
[workspace.metadata.cargo-shear]
613613
ignored = ["idna_adapter", "cast", "chisel", "forge", "alloy-contract"]
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use std::{
2+
collections::{HashMap, HashSet, VecDeque},
3+
hash::Hash,
4+
};
5+
6+
pub const DEFAULT_HELPER_ANALYSIS_CACHE_LIMIT: usize = 65_536;
7+
8+
/// Bounded memo table for lint analyses that inline internal helper calls.
9+
#[derive(Debug)]
10+
pub struct HelperAnalysisCache<K, V> {
11+
entries: HashMap<K, V>,
12+
in_progress: HashSet<K>,
13+
order: VecDeque<K>,
14+
max_entries: usize,
15+
}
16+
17+
impl<K, V> HelperAnalysisCache<K, V>
18+
where
19+
K: Clone + Eq + Hash,
20+
{
21+
pub fn new(max_entries: usize) -> Self {
22+
Self {
23+
entries: HashMap::new(),
24+
in_progress: HashSet::new(),
25+
order: VecDeque::new(),
26+
max_entries,
27+
}
28+
}
29+
30+
pub fn is_in_progress(&self, key: &K) -> bool {
31+
self.in_progress.contains(key)
32+
}
33+
34+
pub fn get(&self, key: &K) -> Option<&V> {
35+
self.entries.get(key)
36+
}
37+
38+
pub fn start(&mut self, key: K) {
39+
self.in_progress.insert(key);
40+
}
41+
42+
pub fn finish(&mut self, key: K, value: V) {
43+
self.in_progress.remove(&key);
44+
if self.max_entries == 0 {
45+
return;
46+
}
47+
48+
if !self.entries.contains_key(&key) {
49+
self.order.push_back(key.clone());
50+
}
51+
self.entries.insert(key, value);
52+
53+
while self.entries.len() > self.max_entries {
54+
if let Some(oldest) = self.order.pop_front() {
55+
self.entries.remove(&oldest);
56+
self.in_progress.remove(&oldest);
57+
} else {
58+
break;
59+
}
60+
}
61+
}
62+
}

crates/lint/src/sol/analysis/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
//!
88
//! All helpers borrow HIR and never mutate it.
99
10+
pub mod helper_cache;
1011
pub mod interface;
1112
pub mod primitives;

0 commit comments

Comments
 (0)