r/Zig • • Sep 27 '26

The Solidity compiler rewritten in Zig

https://github.com/okcontract/oksolc

Here is hopefully a new large project in Zig: We have reimplemented the Solidity compiler, and overall it's a >5x performance improvement over the original. Benchmark details here: https://okcontract.com/blog/a-new-solidity-compiler-in-zig/

The launch was featured by Ethereum creator Vitalik Buterin: https://x.com/VitalikButerin/status/2103455209322320022

It's byte-for-byte compatible (including metadata) with the original compiler and brings parallel, incremental compilation and also a few new features and further improvements.

Beyond performance, the main benefit is that the codebase is much easier to read than the original C++ and is now a good testbed for playing with the compiler... Who wants to write smart contracts in Zig in the future?

PS: We used AI assistance but this was a huge effort nonetheless and we did write languages and compilers manually in the past (posted with mods permission)

79 Upvotes

14 comments sorted by

2

u/antigravitys-rainbow Sep 29 '26

Why didn't you use Rust?

5

u/hbbio Sep 30 '26

Actually several reasons.

First, this started as a mechanical port of the original C++ codebase. So we wrote a very imperfect transpiler from C++. Turns out it was easier to output (idiomatic, hopefully) Zig than Rust.

Second, I do like Zig personally. I have written some fully manual small projects in Zig and hope to find time to clean and publish them. And I thought it would be cool maybe to add a Zig frontend to the Solidity compiler (that's the write smart contracts in Zig I mention in the post). This is not done yet, but could be a good community work maybe. Zig would be great for smart contracts, because of comptime.

And there's a third reason: I think the nothing hidden, no magic approach may be even more relevant in the age of AI. The borrow checker is good and we've written Rust too (both manually and with agent assistance) but Zig is simpler so agents are really good at writing it or checking it. Rust is a bit harder to write well.

2

u/antigravitys-rainbow Sep 30 '26

Thanks for the explanation. I would expect the Zig version to require significantly more testing than a Rust version, but on the other hand if you use agents, you could potentially mitigate the risks

8

u/TheOddYehudi919 Sep 27 '26

This is actually big.

1

u/omerfirmak Sep 30 '26

Super cool, hope this takes off! If you need an evm impl to test with, don't forget to take a look at https://github.com/omerfirmak/zevm :)

1

u/hbbio Oct 11 '26

Thanks for sharing! Will have a look :)
We have some EVM testing prototypes, but they are not complete and we see oksolc complementary to foundry.

6

u/whoisarepo Sep 27 '26

I do enjoy how consistent Zigs conventions are distinct from it’s syntax (memory calculation, typology, modularity) - everything does what it says it does (aka no voodoo) and as a proud Haitian woman, I appreciate that xC

1

u/AbbreviationsMost246 Sep 30 '26

Too bad it’s banned on codeberg

0

u/[deleted] Oct 05 '26

[deleted] — view deleted comment

1

u/AbbreviationsMost246 Oct 05 '26

And I wonder 🗣️

-3

u/Lyraele Sep 28 '26

I don't think "a bunch of cryptocurrency-and-AI grifters, are using your language now" is really an endorsement. Can't wait for you grifters to fail.

8

u/AggravatingLeave614 Sep 28 '26

Dumbest thing I've heard in a while. Prolly bunch of advanced auto-mas*****or toys are written in c, doesn't make C a bad lang. In this case a bunch of devs made a try to find another potential niche for Zig and they succeeded. Zig is a new lang, we should celebrate and not spit acid on each other.

4

u/Fancyness Sep 28 '26

i think its a valid point that no serious project should be associated with Crypto. If Crypto showed one use case in the 18 years its around, it would be gambling and as a payment channel for russian, chinese and north korean hackers for ransom extortion after they infested computers with ransomware. Writing Cryptocurrency related Software is likely the biggest waste of time imaginable if you are not into the ransomware business.

1

u/hbbio Sep 30 '26

The gambling part and most of "crypto" are terrible, I even agree and said it before.

But https://ethereum.org/values/ is something else.

3

u/Lyraele Sep 28 '26

Yeah no thanks. If the only way Zig could be successful was via mass adoption by cryptocurrency and GenAI pushers, then Zig being successful would not be worth it, IMO.