# Trace a Runtime Bug from a Solidity Stack Trace with Atlas in 2026

> Atlas helps Solidity developers pinpoint runtime bugs from stack traces, integrating with `forge test` and `soldeer` for efficient debugging.

Atlas empowers Solidity developers in 2026 to trace runtime bugs from production stack traces directly to the responsible line of code and implement a fix, all without an attached debugger, by integrating direct with the Foundry toolchain, including `forge test`, `soldeer (forge soldeer install)`, and `forge fmt`.

## Key takeaways

- Atlas directly consumes Solidity `file:line` stack traces for precise bug localization.
- Atlas validates Solidity trace offsets, preventing debugging with outdated contract code.
- The `grep` tool helps pinpoint Solidity `require` messages or custom error definitions.
- Atlas's `lsp` integration maps Solidity function call graphs to identify root causes.
- Atlas automates Solidity fixes, adds `forge test` regression tests, and shows `forge snapshot` gas deltas.
- All Solidity code changes are permission-gated and require explicit approval via unified diffs.

## How Atlas Traces Solidity Runtime Bugs from Stack Traces

Atlas traces Solidity runtime bugs by consuming raw stack traces, which are lists of `file:line` pairs, and using its `read` tool to inspect each frame. In 2026, this process allows developers to quickly understand the execution path leading to an error within a Foundry project, even without a live debugger.

When a Solidity contract encounters a runtime error in production, the resulting stack trace provides critical `file:line` information. Atlas's `read` tool is designed to consume these exact `file:line` pairs. For each frame in the trace, Atlas reads the specified Solidity file at the reported offset. This initial inspection helps to validate the trace against the current codebase. If an offset is out of range, Atlas immediately flags it, preventing misdiagnosis from an outdated trace. This capability is crucial for Solidity projects where precise line numbers are vital for understanding complex contract interactions and potential vulnerabilities.

## Validating Solidity Stack Traces Against Current Codebase

Atlas ensures the integrity of Solidity stack traces by validating reported offsets against the current file content. If Atlas reports "Offset <n> is out of range for this file," it indicates the trace originated from an older build, a common occurrence in 2026's rapid deployment cycles, requiring a re-read from the top.

A common challenge in debugging production Solidity systems is dealing with stack traces generated from older contract versions. Atlas addresses this directly: when its `read` tool attempts to access an `Offset <n>` that is no longer valid for the current version of a Solidity file, it fails loudly. This explicit error prevents developers from wasting time investigating code that has since changed. The recommended action is to re-read the file from the top, ensuring that any subsequent line number analysis is based on the current, deployed contract code. This validation step is fundamental for maintaining accuracy when debugging critical Solidity smart contracts.

## Pinpointing Solidity Error Messages with Grep

To efficiently locate the source of a Solidity runtime error, Atlas employs its `grep` tool to search for the specific error message string. This approach, effective in 2026, often reveals where the error is constructed within the contract, providing more context than just the top frame of a stack trace, especially for `require` statements or custom errors.

While a stack trace points to the location of an error, the error message itself often contains valuable clues about the underlying condition. Atlas's `grep` tool allows developers to search the entire Solidity codebase for the exact error message string. This is particularly useful in Foundry projects, where `require` statements or custom error definitions (`error MyCustomError(uint256 value);`) are prevalent. Finding where the error message is constructed can reveal the specific condition that failed, which is frequently more informative than merely examining the top frame of the stack trace. This helps to quickly narrow down the potential causes of a bug in a complex Solidity contract.

## Analyzing Solidity Callers with LSP Find References

Atlas leverages its `lsp` tool's `findReferences` operation to identify all callers of a failing Solidity function, a crucial step in 2026 for understanding how bad input reaches the problematic code. This allows developers to trace the flow of execution and pinpoint the exact path that leads to the runtime bug within a Foundry project.

Once a failing Solidity function is identified, understanding its call graph is paramount. Atlas integrates with the Language Server Protocol (LSP) to provide a `findReferences` operation. This tool allows developers to see every location in the Solidity codebase that calls the identified failing function. By examining these callers, developers can trace back the execution path and determine how the problematic input or state was passed to the function. This comprehensive view helps in understanding the full context of the bug, moving beyond the immediate point of failure to identify the true root cause within the interconnected logic of Solidity contracts.

## Implementing Solidity Fixes and Regression Tests with Atlas

Atlas facilitates the entire fix cycle for Solidity bugs, from proposing code changes with its `edit` tool to adding regression tests using `forge test`. In 2026, Atlas also integrates `forge snapshot` to show gas cost deltas and `forge fmt` for consistent code style before any changes are committed.

After identifying the root cause, Atlas assists in implementing the fix. Its `edit` tool allows for precise modifications to Solidity contract files. Crucially, Atlas then guides the developer to add a regression test in the `test/` directory using `forge test`. This ensures the bug cannot recur silently. Before approving the changes, Atlas can run `forge snapshot` to display the gas cost delta of the proposed Solidity modifications, a vital consideration for smart contracts. Finally, `forge fmt` is applied to the diff to maintain code style, and Atlas presents a unified diff for approval, ensuring transparency and control over every change to the Solidity codebase.

## Atlas's Safety and Review Mechanisms for Solidity Code

Atlas incorporates robust safety and review mechanisms for Solidity code changes, including permission-gated tool calls and a read-only plan agent. In 2026, every proposed edit generates a unified diff for approval, and `forge snapshot` provides gas cost deltas, ensuring developers maintain full control over their critical smart contracts.

Working with Solidity contracts demands extreme caution due to their immutable nature and financial implications. Atlas is built with multiple layers of safety. Every tool call, such as `edit` or `lsp`, is permission-gated, requiring explicit `allow`, `ask`, or `deny` rules. Atlas first drafts a plan in a read-only plan agent, asking for approval before switching to a build agent that can make changes. For every file edit, Atlas computes a unified diff and surfaces it for approval, allowing developers to review every line change. Furthermore, for Solidity projects, Atlas can run `forge snapshot` to show the gas delta of proposed changes, providing a critical metric for smart contract optimization and security before any commit is made.

## Steps

1. Paste the Solidity stack trace into Atlas and have it `read` each frame's `file:line` at the reported offset.
2. If Atlas reports "Offset <n> is out of range for this file," the trace came from a different build; re-read the Solidity file from the top before trusting any line number.
3. Use the Atlas `grep` tool to search for the error message string within your Solidity project to find where it is constructed, which is usually more informative than the top frame.
4. Employ the Atlas `lsp` tool's `findReferences` operation on the failing Solidity function to see which callers can reach it with the bad input.
5. Use the Atlas `edit` tool to apply the fix to your Solidity contract, then ask Atlas to add a regression test in `test/` and run `forge test` behind a permission prompt.
6. Have Atlas run `forge snapshot` so you can see the gas delta of your Solidity changes before approving, then ask Atlas to run `forge fmt` on the diff for consistent styling.
7. Review the unified diff presented by Atlas for your Solidity contract changes and approve the write operation.

## FAQ

### How does Atlas handle Solidity stack traces from different contract builds?

Atlas validates each `file:line` offset in a Solidity stack trace against the current file content. If an offset is out of range, Atlas will explicitly report this, indicating the trace is from an older build. You should then re-read the file from the top to ensure accuracy with the current contract version.

### Can Atlas suggest Solidity-specific fixes like reentrancy guards or custom errors?

Yes, Atlas can be asked to add Solidity-specific constructs like reentrancy guards or convert `require` strings to custom errors to cut deploy size, leveraging its understanding of AST declarations and the Foundry project structure.

### How does Atlas ensure gas efficiency for Solidity contract changes?

Before approving any Solidity code changes, Atlas can run `forge snapshot` to compute and display the gas cost delta. This allows you to review the gas impact of your modifications directly within Atlas before committing them.

### What Solidity tools does Atlas integrate with for development workflow?

Atlas integrates deeply with the Foundry toolchain, including `forge test` for running tests, `soldeer (forge soldeer install)` for package management, and `forge fmt` for code formatting. It operates within a Foundry project with `foundry.toml` and `src/` directories.

### How does Atlas protect my Solidity codebase during automated changes?

Atlas employs several safety measures: all tool calls are permission-gated, it drafts plans in a read-only agent for approval, and every proposed file edit generates a unified diff for your review and explicit approval before writing to disk. It also snapshots changes as git patches for easy rollback.

### Can Atlas write `forge test` fuzz tests for Solidity contracts?

Yes, Atlas can write fuzz tests in your `test/` directory and run `forge test` behind a permission prompt. This helps ensure robust testing for your Solidity contracts and prevents regressions.

### Does Atlas support Solidity custom errors for better debugging?

Atlas understands Solidity's custom error syntax. When using `grep` for error messages, it can help locate where these custom errors are defined or emitted, providing clearer context than generic `require` messages.

---

Canonical HTML: https://runatlas.sh/resources/stacks/trace-a-runtime-bug-from-a-stack-trace-in-solidity
Source of truth: aeo_pages row `/resources/stacks/trace-a-runtime-bug-from-a-stack-trace-in-solidity` (segment: Stacks) (this file is generated from it, never hand-edited).
Licence: Atlas is proprietary with a free core. It is not open source and there is no public source repository.
