Foundry/alert autofix 19 - #95
Conversation
…in permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: AU_gdev_19 <64915515+Dargon789@users.noreply.github.com>
Updating git repository `https://github.com/rust-cli/rexpect` Locking 44 packages to latest compatible versions Unchanged alloy-evm v0.20.1 (available: v0.21.0) Updating alloy-hardforks v0.3.0 -> v0.3.1 Unchanged alloy-op-evm v0.20.1 (available: v0.21.0) Updating alloy-op-hardforks v0.3.0 -> v0.3.1 Removing android-tzdata v0.1.1 Updating annotate-snippets v0.12.3 -> v0.12.4 Updating aws-lc-rs v1.13.3 -> v1.14.0 Updating aws-lc-sys v0.30.0 -> v0.31.0 Updating aws-sdk-kms v1.86.0 -> v1.87.0 Updating aws-sdk-sso v1.83.0 -> v1.84.0 Updating aws-sdk-ssooidc v1.84.0 -> v1.85.0 Updating aws-sdk-sts v1.85.0 -> v1.86.0 Updating aws-smithy-runtime v1.9.1 -> v1.9.2 Updating bindgen v0.69.5 -> v0.72.1 Updating cc v1.2.36 -> v1.2.37 Updating chrono v0.4.41 -> v0.4.42 Updating comfy-table v7.2.0 -> v7.2.1 Updating console v0.16.0 -> v0.16.1 Unchanged dialoguer v0.11.0 (available: v0.12.0) Updating errno v0.3.13 -> v0.3.14 Updating iana-time-zone v0.1.63 -> v0.1.64 Unchanged idna_adapter v1.1.0 (available: v1.2.1) Updating indexmap v2.11.0 -> v2.11.1 Removing itertools v0.12.1 Removing lazycell v1.3.0 Updating linux-raw-sys v0.9.4 -> v0.11.0 Unchanged matchit v0.8.4 (available: v0.8.6) Updating normpath v1.3.0 -> v1.4.0 Updating nybbles v0.4.3 -> v0.4.4 Unchanged op-alloy-consensus v0.19.1 (available: v0.20.0) Unchanged op-alloy-rpc-types v0.19.1 (available: v0.20.0) Updating pest v2.8.1 -> v2.8.2 Updating pest_derive v2.8.1 -> v2.8.2 Updating pest_generator v2.8.1 -> v2.8.2 Updating pest_meta v2.8.1 -> v2.8.2 Unchanged protobuf v3.3.0 (available: v3.7.2) Unchanged protobuf-support v3.3.0 (available: v3.7.2) Unchanged rand v0.8.5 (available: v0.9.2) Updating revm-inspectors v0.29.1 -> v0.29.2 Removing rustc-hash v1.1.0 Updating rustix v1.0.8 -> v1.1.2 Updating rustls-webpki v0.103.4 -> v0.103.5 Updating schannel v0.1.27 -> v0.1.28 Updating security-framework v3.3.0 -> v3.4.0 Updating security-framework-sys v2.14.0 -> v2.15.0 Updating serde v1.0.219 -> v1.0.221 Adding serde_core v1.0.221 Updating serde_derive v1.0.219 -> v1.0.221 Updating serde_json v1.0.143 -> v1.0.144 Updating tempfile v3.21.0 -> v3.22.0 Updating term v1.1.0 -> v1.2.0 Updating unicode-ident v1.0.18 -> v1.0.19 Unchanged unicode-width v0.2.0 (available: v0.2.1) Unchanged vergen v8.3.2 (available: v9.0.6) Updating wasi v0.14.4+wasi-0.2.4 -> v0.14.5+wasi-0.2.4 Adding wasip2 v1.0.0+wasi-0.2.4 Removing which v4.4.2 Updating winapi-util v0.1.10 -> v0.1.11 Adding windows-core v0.62.0 Adding windows-result v0.4.0 Adding windows-strings v0.5.0 note: to see how you depend on a package, run `cargo tree --invert --package <dep>@<ver>` Co-authored-by: mattsse <19890894+mattsse@users.noreply.github.com>
…11635) fix(forge): color bug in `Display` impl for `TestResult` - Applied `wrap()` to `Painted` string to handle correctly the "nested paints"
* feat(coverage): analyze with solar * chore: walk stmts normally, sort items * wip * chore: display all items with relevant source in debug format * wip * upd * chore: clippy * test: update do_while_lcov The `++i` line was reported first, so with the old check all previous lines were ignored. Now we track all lines regardless, so this change is more correct. * fix: legacy: do not recurse into emit, revert Fixes branch_with_calldata_reads test. * correct span * fix: inline config path * fix: resolve function kinds, ignore type conversions / struct ctors * fix: walk only functions * fix: push stmt for yul stmt expr early * test: add a test case for if (..) return If statements like `if (x) return y;` were missed by the previous `has_statements` function. * test: hoist contract instantiations out of test fns * test: add test case for single if with continue/break Same as previous test with `return`.
…oundry-rs#11644) * Update cmd.rs * Update crates/anvil/src/cmd.rs Co-authored-by: onbjerg <onbjerg@users.noreply.github.com> * Update cmd.rs * Update cmd.rs --------- Co-authored-by: onbjerg <onbjerg@users.noreply.github.com>
…et docs (foundry-rs#11636) * chore(common): deprecate ProjectCompiler::verify and fix compile_target docs * fmt * Update compile.rs * fmt * Update compile.rs
Update CODEOWNERS
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Reviewer's GuideThis PR overhauls the EVM coverage pipeline by migrating the AST visitor to Solar’s AST and HIR, adds full ordering and richer formatting for coverage items, and adapts Forge’s coverage command and reporter to the new analysis. It also includes focused utility tweaks and CI improvements. Class diagram for updated coverage analysis visitorclassDiagram
class SourceVisitor {
+source_id: u32
+gcx: Gcx
+contract_name: Arc<str>
+branch_id: u32
+items: Vec<CoverageItem>
+all_lines: Vec<u32>
+function_calls: Vec<Span>
+function_calls_set: FxHashSet<Span>
+new(source_id: u32, gcx: Gcx)
+checkpoint(): SourceVisitorCheckpoint
+restore_checkpoint(checkpoint: SourceVisitorCheckpoint)
+visit_contract(contract: ast::ItemContract)
+has_tests(checkpoint: SourceVisitorCheckpoint): bool
+disambiguate_functions()
+resolve_function_calls(hir_source_id: hir::SourceId)
+sort()
+push_lines()
+push_stmt(span: Span)
+push_item_kind(kind: CoverageItemKind, span: Span)
+source_location_for(span: Span): SourceLocation
+byte_range(span: Span): Range<u32>
+line_range(span: Span): Range<u32>
+next_branch_id(): u32
}
class SourceVisitorCheckpoint {
+items: usize
+all_lines: usize
+function_calls: usize
}
class CoverageItem {
+kind: CoverageItemKind
+loc: SourceLocation
+hits: u32
+fmt_with_source(src: Option<&str>): Display
+ord_key(): Ord
}
class CoverageItemKind {
<<enum>>
Line
Statement
Branch
Function
+ord_key(): Ord
}
class SourceLocation {
+source_id: usize
+contract_name: Arc<str>
+bytes: Range<u32>
+lines: Range<u32>
+bytes(): Range<usize>
+len(): u32
}
SourceVisitor --> SourceVisitorCheckpoint
SourceVisitor --> CoverageItem
CoverageItem --> CoverageItemKind
CoverageItem --> SourceLocation
Class diagram for updated SourceFiles and SourceAnalysisclassDiagram
class SourceFiles {
+sources: HashMap<u32, PathBuf>
}
class SourceAnalysis {
+new(data: &SourceFiles, output: &ProjectCompileOutput): Result<Self>
}
SourceAnalysis --> SourceFiles
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Summary of ChangesHello @Dargon789, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request primarily focuses on updating a wide array of Rust dependencies across the project, ensuring the use of the latest stable versions and their associated security and performance improvements. A significant refactor of the Solidity coverage analysis mechanism has been implemented, transitioning from Highlights
Ignored Files
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes and found some issues that need to be addressed.
- The extensive visitor implementations in
SourceVisitorcontain duplicated branch-handling patterns—consider extracting shared logic into helper functions to improve readability and maintainability. - There are several unchecked
unwrap()andexpect()calls when fetching AST/HIR and source snippets that could panic at runtime—please add proper error handling or context-aware errors to avoid unexpected CLI crashes. - The signature
fn ord_key(&self) -> impl Ord + use<>appears to contain a strayuse<>constraint—please clean up the return type signature to remove this placeholder and ensure correct compilation.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The extensive visitor implementations in `SourceVisitor` contain duplicated branch-handling patterns—consider extracting shared logic into helper functions to improve readability and maintainability.
- There are several unchecked `unwrap()` and `expect()` calls when fetching AST/HIR and source snippets that could panic at runtime—please add proper error handling or context-aware errors to avoid unexpected CLI crashes.
- The signature `fn ord_key(&self) -> impl Ord + use<>` appears to contain a stray `use<>` constraint—please clean up the return type signature to remove this placeholder and ensure correct compilation.
## Individual Comments
### Comment 1
<location> `crates/evm/coverage/src/lib.rs:358` </location>
<code_context>
+}
+
+impl CoverageItemKind {
+ fn ord_key(&self) -> impl Ord + use<> {
+ match *self {
+ Self::Line => 0,
</code_context>
<issue_to_address>
**issue (bug_risk):** The use of `impl Ord + use<>` is invalid syntax and will not compile.
Replace `impl Ord + use<>` with a valid return type, such as a tuple or a concrete type implementing `Ord`. Remove `+ use<>` from the signature.
</issue_to_address>
### Comment 2
<location> `crates/evm/coverage/src/analysis.rs:144` </location>
<code_context>
- node.attribute("kind").ok_or_else(|| eyre::eyre!("Function has no kind"))?;
+ /// Creates a coverage item for a given kind and source location. Pushes item to the internal
+ /// collection (plus additional coverage line if item is a statement).
+ fn push_item_kind(&mut self, kind: CoverageItemKind, span: Span) {
+ let item = CoverageItem { kind, loc: self.source_location_for(span), hits: 0 };
</code_context>
<issue_to_address>
**issue (complexity):** Consider extracting helper methods for branch and require handling to reduce repeated code in coverage item creation.
Here are a few small refactorings you can do to collapse a lot of the repeated `push_item_kind` and `push_stmt` logic without touching any of the existing behavior:
1) Extract a `push_branch` helper so all of your branch pushes look like:
```rust
impl<'gcx> SourceVisitor<'gcx> {
#[inline]
fn push_branch(&mut self, span: Span, branch_id: u32, path_id: u32, is_first: bool) {
self.push_item_kind(
CoverageItemKind::Branch {
branch_id,
path_id,
is_first_opcode: is_first,
},
span,
);
}
}
```
Then in your `visit_stmt` / `visit_yul_stmt` you can replace:
```rust
let branch_id = self.next_branch_id();
self.push_item_kind(
CoverageItemKind::Branch { branch_id, path_id: 0, is_first_opcode: true },
then_stmt.span,
);
if let Some(_) = else_stmt {
self.push_item_kind(
CoverageItemKind::Branch { branch_id, path_id: 1, is_first_opcode: false },
stmt.span,
);
}
```
with
```rust
let branch_id = self.next_branch_id();
self.push_branch(then_stmt.span, branch_id, 0, true);
if else_stmt.is_some() {
self.push_branch(stmt.span, branch_id, 1, false);
}
```
2) Extract a `handle_require` since the “require → 2-branch” pattern is identical in two places:
```rust
impl<'gcx> SourceVisitor<'gcx> {
#[inline]
fn handle_require(&mut self, span: Span) {
let id = self.next_branch_id();
// false‐path
self.push_branch(span, id, 0, false);
// true‐path
self.push_branch(span, id, 1, false);
}
}
```
and then replace in your Expr visitor:
```rust
if ident.as_str() == "require" {
self.handle_require(expr.span);
}
```
These two helpers alone will collapse dozens of lines of boilerplate, make your visitor arms much shorter, and keep the exact same coverage behavior.
</issue_to_address>
### Comment 3
<location> `crates/evm/coverage/src/lib.rs:337` </location>
<code_context>
},
}
+impl PartialEq for CoverageItemKind {
+ fn eq(&self, other: &Self) -> bool {
+ self.ord_key() == other.ord_key()
</code_context>
<issue_to_address>
**issue (complexity):** Consider using #[repr(u8)] and deriving comparison traits for CoverageItemKind, and simplifying CoverageItem's comparison logic to reduce manual boilerplate.
```rust
// 1. Use `#[repr(u8)]` + `derive` on `CoverageItemKind` – drops ALL of your manual
// `PartialEq/Eq/PartialOrd/Ord` + `ord_key()` boilerplate.
#[repr(u8)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum CoverageItemKind {
Line = 0,
Statement = 1,
Branch {
branch_id: u32,
path_id: u32,
is_first_opcode: bool,
},
Function { name: Box<str> },
}
// — remove your `impl PartialEq/Eq/PartialOrd/Ord for CoverageItemKind` and the
// `fn ord_key(&self) -> impl Ord + use<> { … }` entirely.
// 2. Simplify `CoverageItem::ord_key()` to return a concrete tuple
// (no `impl Trait`), then derive `PartialEq/Eq`, and only hand‐write `Ord`:
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CoverageItem {
pub kind: CoverageItemKind,
pub loc: SourceLocation,
pub hits: u32,
}
impl CoverageItem {
fn ord_key(&self) -> (std::cmp::Reverse<usize>, u32, u32, CoverageItemKind, u32, u32) {
(
std::cmp::Reverse(self.loc.source_id),
self.loc.lines.start,
self.loc.lines.end,
self.kind.clone(),
self.loc.bytes.start,
self.loc.bytes.end,
)
}
}
impl PartialOrd for CoverageItem {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for CoverageItem {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.ord_key().cmp(&other.ord_key())
}
}
// 3. Now you can drop all the manual trait‐impls that merely forwarded to `ord_key()`.
//
// These changes preserve your sort–order logic exactly, but
// eliminate dozens of lines of boilerplate.
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request is a significant and impressive overhaul of the EVM coverage analysis, migrating to the solar AST/HIR for improved accuracy and maintainability. The changes are extensive but well-contained, touching upon dependency updates, bug fixes in Anvil and Cheatcodes, and streamlining the forge coverage CLI and its tests. The code quality is high, and the refactoring appears to be a solid improvement. I've identified one high-severity issue in the Anvil logging initialization that could regress user experience, and I've provided a suggestion to address it. The rest of the changes, including bug fixes and test improvements, look excellent.
Pull request was closed
Motivation
Solution
PR Checklist
Summary by Sourcery
Overhaul EVM coverage analysis by migrating to solar AST/HIR, enhance coverage item ordering and rendering, streamline forge coverage CLI and tests, apply bug fixes in Cheatcodes and Anvil, clean up compiler flags, bump dependencies, and improve CI workflows
New Features:
Bug Fixes:
Enhancements:
verifyflag from ProjectCompiler interfaceBuild:
CI:
Tests:
Chores: