oksolc 0.2.5, a faster Solidity compiler written in Zig, now supports solc 0.8.36 to 0.8.39

2026-11-24来源 dev.toEnglish
oksolc 0.2.5, a faster Solidity compiler written in Zig, now supports solc 0.8.36 to 0.8.39

oksolc 0.2.5 now supports solc 0.8.37, 0.8.38 and 0.8.39, as well as solc 0.8.36.

Before oksolc 0.2.5, the compiler targeted only solc 0.8.36. A project pinned to a later release had no way to get the same bytecode from oksolc that its own solc produces.

What oksolc is

oksolc is a new Solidity compiler written in Zig. It accepts the same Standard JSON input as solc, and on the 12 projects we measured it built 3.3 to 6.0 times faster than solc's via-IR pipeline.

We wrote it for our own use while developing Chainwall. The goal was shorter build times during contract development.

oksolc provides a command-line tool, a C library with the same interface as libsolc, and a Zig module. The supported compilation path is optimized via-IR through Standard JSON.

What changed in oksolc 0.2.5

  • The default is now solc 0.8.39, and --solc-version selects any of the three earlier releases. The selected release controls pragma checks, code generation, diagnostics and metadata.
  • block.slotnum and Yul slotnum() compile on the Amsterdam EVM version from the solc 0.8.37 target onwards.
  • solc fixed four via-IR bugs between solc 0.8.37 and solc 0.8.39: SOL-2026-4, SOL-2026-6, SOL-2026-7 and SOL-2026-8 in the Solidity compiler bug list. oksolc applies the same fixes on every target.
  • Checked and unchecked arithmetic get separate constant helpers, and Yul returndatacopy calls that can revert keep their bounds checks.

I compiled the 14 projects bundled with the oksolc benchmark with both compilers, on each of the three new solc releases. The complete Standard JSON output was the same every time. The README reports the same result for 17 workloads.

The solc 0.8.36 target keeps the security fixes and the constant-helper fix, so its bytecode can differ from solc 0.8.36. The README documents each difference.

Build times on 12 open-source projects

For each project we sent the same Standard JSON build request to solc 0.8.39 and to oksolc 0.2.5 targeting solc 0.8.39. oksolc ran on 1 job and on 4 jobs. The benchmark records a result only when both compilers produce the same bytecode. Both compilers ran the optimized via-IR pipeline, so these times compare oksolc with solc via-IR, not with solc's default pipeline.

Project solc 0.8.39 oksolc, 1 job oksolc, 4 jobs
Sablier v2 1.2.0 523.1 s 208.4 s 145.9 s
EigenLayer 0.3.0 175.1 s 77.9 s 40.0 s
Solady 0.1.26 58.1 s 29.2 s 17.5 s
Uniswap v4 (2024-06-06) 39.3 s 18.2 s 7.4 s
Pendle v2 (2026-09-16) 26.0 s 12.1 s 6.8 s
OpenZeppelin 4.8.0 20.9 s 9.7 s 3.7 s
OpenZeppelin 4.7.0 18.9 s 8.8 s 3.2 s
Liquity (2024-10-30) 14.7 s 7.0 s 3.4 s
OpenZeppelin 4.9.0 13.6 s 6.4 s 2.7 s
OpenZeppelin 5.0.2 10.8 s 5.1 s 2.0 s
OpenZeppelin 5.6.1 10.3 s 4.9 s 1.7 s
Uniswap v4 (2022-06-16) 6.6 s 3.1 s 1.3 s

With a single job, oksolc built every project 2.0 to 2.5 times faster than solc. With 4 jobs, it was 3.3 to 6.0 times faster. Building all twelve took 15 minutes 17 seconds with solc and 3 minutes 56 seconds with oksolc on 4 jobs.

Incremental builds are faster still. In a serve or watch session, oksolc keeps the compiler in memory and reuses work between edits.

I measured on my Apple Silicon MacBook Air with 16 GB of memory. The solc times and the oksolc 4-job times are the median of 3 runs after 1 warmup run. The 1-job times are single runs. On 4 jobs, oksolc used more memory than solc on most projects, for example a peak of 5.3 GiB against 2.4 GiB on Solady. Sablier v2 peaked at about 8 GiB with either compiler in these runs, and its three runs varied more than any other project's.

Sablier v2, the largest project in the set, went from 8 minutes 43 seconds with solc to 2 minutes 26 seconds with oksolc on 4 jobs, with the same bytecode.

How to use it

Build

You need Zig 0.17.1. Build oksolc from the release tag:

git clone https://github.com/okcontract/oksolc cd oksolc git checkout v0.2.5 zig build -Doptimize=ReleaseFast ./zig-out/bin/oksolc version 

Use with Foundry

For a Foundry project, point foundry.toml at the oksolc executable and enable optimized via-IR:

[profile.default] solc = "/absolute/path/to/oksolc/zig-out/bin/oksolc" via_ir = true optimizer = true optimizer_runs = 200 

Then run forge build as usual. If the project has artifacts from another compiler, run forge clean first.

This configuration builds with via-IR. If your project does not use via-IR today, the bytecode will differ from your current build.

Parallel compilation and cache

Parallel compilation is off by default. Turn it on with an oksolc.toml next to foundry.toml:

parallel = true jobs = 4 

The incremental compiler keeps its cache between runs only if you set cache = true in ~/.config/oksolc/config.toml.

Select a solc release

Through Foundry, oksolc uses its default target, solc 0.8.39. To select another release, use the command line:

oksolc standard-json --solc-version 0.8.37 request.json 

oksolc has a web server built in

oksolc can serve a local page for browsing a compiled project. It lists the project's source files next to the file you select, with an outline of everything that file declares.

For each contract the page also shows the ABI and the creation and runtime bytecode with their sizes. You can search the project, and two side panels list diagnostics and references.

The browser is left out of a default build. Build with -Dbrowser=true, which needs Bun 1.4.5 and TypeScript 7.0.2, then run it from your project:

oksolc serve --browse 

Open http://127.0.0.1:8080. serve watches the Solidity files in src/ and recompiles when they change. To browse a single Standard JSON request instead, run oksolc browse --request input.json.

Including the browser adds about 0.3 MB to the binary.

What should it show next? Open an issue and tell us.

Try it on your project

Build one of your own projects with oksolc and compare the result with solc. If the two differ, open an issue on github.com/okcontract/oksolc and include the output of oksolc version --json.

If oksolc is useful to you, star the repository. For new releases, follow us on X at @okcontract.

原文:https://www.a8q9.cn/en/article/oksolc-0-2-5-a-faster-solidity-compiler-written-in-zig-now-supports-solc-0-8-36--cbf4fc.html

相关文章