← Latest papers
💻 computer science

SolAgent: A Specialized Multi-Agent Framework for Solidity Code Generation

SolAgent is a specialized multi-agent framework that leverages a dual-loop refinement mechanism combining the Forge compiler and Slither static analyzer to significantly outperform existing LLMs and AI tools in generating secure, functional Solidity smart contracts, while also enabling the distillation of high-quality trajectories into smaller open-source models.

Original authors: Wei Chen, Zhiyuan Peng, Xin Yin, Chao Ni, Chenhao Ying, Bang Xie, Yuan Luo

Published 2026-02-02
📖 5 min read🧠 Deep dive

Original authors: Wei Chen, Zhiyuan Peng, Xin Yin, Chao Ni, Chenhao Ying, Bang Xie, Yuan Luo

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

The Big Problem: Building Digital Fortresses with a "Magic Pen"

Imagine you are building a digital fortress (a Smart Contract) that holds millions of dollars. Once you build it and lock the door, you can never change a single brick. If you make a tiny mistake, thieves can break in and steal everything.

Recently, we got a "Magic Pen" (Large Language Models or LLMs) that can write code for us instantly. But this pen is like a very confident but inexperienced apprentice. It writes beautiful-looking code that looks right, but often:

  1. It doesn't work: The code has hidden errors that cause it to crash immediately (Compilation Failure).
  2. It's insecure: It leaves secret backdoors open that hackers can exploit.
  3. It gets stuck: It tries to write the whole fortress in one go, gets overwhelmed, and gives up.

The paper argues that simply asking the Magic Pen to "write a secure contract" isn't enough. We need a better system.


The Solution: SolAgent (The Master Builder Team)

The authors created SolAgent, which isn't just one AI, but a team of specialized AI agents working together. Instead of writing the code once and hoping for the best, SolAgent mimics how human experts build software: Write, Check, Fix, Repeat.

Think of SolAgent as a construction site with two main workers and a set of high-tech tools:

1. The Two Workers

  • The Coding Agent (The Builder): This AI takes your request (e.g., "Build a vault that only opens if you have a key") and writes the initial draft of the code.
  • The Refining Agent (The Inspector): This AI doesn't just read the code; it actively tests it. It looks at the Builder's work, finds mistakes, and tells the Builder exactly how to fix them.

2. The High-Tech Tools (The "Dual-Loop" System)

The genius of SolAgent is how it uses two specific tools to check the work, creating a "dual-loop" of quality control:

  • The Inner Loop (The "Forge" Test):

    • Analogy: Imagine a stress-test machine that tries to break the door of your vault.
    • What it does: It runs the code through a compiler (Forge) to see if it actually works. If the code crashes or fails a math test, the Refining Agent gets a report saying, "This line is broken," and sends it back to the Builder to fix.
    • Result: This ensures the code is functional.
  • The Outer Loop (The "Slither" Security Scan):

    • Analogy: Imagine a security expert with a metal detector walking around the vault looking for hidden traps or loose bricks.
    • What it does: It uses a static analyzer (Slither) to scan for known security holes (like a "reentrancy" bug where a thief can trick the vault into paying out twice). If it finds a hole, it tells the Refining Agent to patch it immediately.
    • Result: This ensures the code is secure.

3. The File System (The "Library Card")

General AI often gets confused because it doesn't know what other files exist in the project. SolAgent is equipped with a File System Tool.

  • Analogy: Instead of guessing what tools are in the shed, the AI can actually walk over, open the shed door, read the labels on the boxes, and grab the right tools it needs to finish the job. This helps it understand complex projects with many different parts.

How It Works: The "Stop" Button

You might think, "Won't they just keep fixing the code forever?"
The paper introduces a Dynamic Stopping Mechanism. It's like a smart timer that knows when to quit:

  • Success: If the code passes all tests and has no security holes, stop.
  • Stuck: If the AI keeps making the exact same mistake over and over (looping), stop to save time.
  • Stagnation: If the code isn't getting any better after a few tries, stop.

The Results: Why It Matters

The researchers tested SolAgent on a tough benchmark called SolEval+ (a collection of real-world smart contract challenges).

  1. It Works Much Better:

    • Standard AI (the "Magic Pen" alone) only got about 25% of the contracts right on the first try.
    • SolAgent got 64.39% right on the first try. That's more than double the success rate.
    • Analogy: If you asked 100 random people to build a safe, 25 might build one that works. SolAgent is like hiring a master architect who builds 64 working safes out of 100.
  2. It's Safer:

    • Compared to code written by humans, SolAgent reduced security vulnerabilities by nearly 40%.
    • Analogy: It found and fixed the hidden traps that even experienced human builders sometimes miss.
  3. It's Cheaper (The "Distillation" Trick):

    • Running a team of AI agents is expensive. So, the authors took the "high-quality conversations" (the trajectory) between the Builder and the Inspector and used them to teach a smaller, cheaper AI model (Qwen3-8B).
    • Analogy: They took the notes from a master chef's kitchen and taught a junior cook how to make the same perfect dish. The junior cook (the small model) learned to cook almost as well as the big team, but much faster and cheaper.

Summary

SolAgent is a new way to use AI to write blockchain code. Instead of trusting a single AI to get it right the first time, it sets up a team that writes code, tests it with a compiler, scans it for security holes, and fixes mistakes until it's perfect. The result is code that is significantly more reliable and secure than what current AI or even human experts typically produce.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →