<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: zhaog100</title>
    <description>The latest articles on DEV Community by zhaog100 (@zhaog100).</description>
    <link>https://dev.to/zhaog100</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3830273%2F09bdcd65-42a5-4914-9ebd-e48b07797bcd.jpeg</url>
      <title>DEV Community: zhaog100</title>
      <link>https://dev.to/zhaog100</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zhaog100"/>
    <language>en</language>
    <item>
      <title>Solidity to Compact: A Developer's Comparison Guide for Midnight Network</title>
      <dc:creator>zhaog100</dc:creator>
      <pubDate>Tue, 14 Apr 2026 02:52:22 +0000</pubDate>
      <link>https://dev.to/zhaog100/solidity-to-compact-a-developers-comparison-guide-for-midnight-network-l01</link>
      <guid>https://dev.to/zhaog100/solidity-to-compact-a-developers-comparison-guide-for-midnight-network-l01</guid>
      <description>&lt;h1&gt;
  
  
  Solidity to Compact: A Developer's Comparison Guide
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A practical side-by-side reference for developers transitioning from Solidity to Midnight's Compact language.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;If you're a Solidity developer looking to build on Midnight Network, you'll find that Compact shares some familiar concepts but introduces privacy-first design patterns that fundamentally change how you think about smart contracts.&lt;/p&gt;

&lt;p&gt;This guide maps 10 common Solidity patterns to their Compact equivalents, highlighting key differences along the way.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Contract Structure &amp;amp; Module Definition
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Solidity
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract MyToken {
    // state variables, functions, events
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Compact
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: MIT
pragma language_version &amp;gt;= 0.21.0;

module MyToken {
    import CompactStandardLibrary;
    // ledger entries, circuits, types
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key differences:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compact uses &lt;code&gt;module&lt;/code&gt; instead of &lt;code&gt;contract&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;pragma language_version&lt;/code&gt; instead of &lt;code&gt;pragma solidity&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;No inheritance — use &lt;code&gt;import&lt;/code&gt; with optional &lt;code&gt;prefix&lt;/code&gt; for namespacing&lt;/li&gt;
&lt;li&gt;Functions are called &lt;code&gt;circuit&lt;/code&gt;s (they become ZK circuits)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  2. State Variables (Ledger Entries)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Solidity
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;contract Storage {
    uint256 public count;
    address public owner;
    mapping(address =&amp;gt; uint256) public balances;
    bool public initialized;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Compact
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module Storage {
    import CompactStandardLibrary;

    // Public (unshielded) state — visible on-chain
    export ledger count: Uint&amp;lt;128&amp;gt;;
    export ledger owner: Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;;
    export ledger balances: Map&amp;lt;Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;, Uint&amp;lt;128&amp;gt;&amp;gt;;
    export sealed ledger initialized: Bool;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key differences:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;State variables are called &lt;code&gt;ledger&lt;/code&gt; entries&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;export&lt;/code&gt; makes them readable; &lt;code&gt;sealed&lt;/code&gt; restricts writes to the module&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;uint256&lt;/code&gt; — max is &lt;code&gt;Uint&amp;lt;128&amp;gt;&lt;/code&gt; (circuit backend limitation)&lt;/li&gt;
&lt;li&gt;Addresses use &lt;code&gt;Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;&lt;/code&gt; instead of a simple &lt;code&gt;address&lt;/code&gt; type&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Map&amp;lt;K, V&amp;gt;&lt;/code&gt; replaces &lt;code&gt;mapping&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. Constructor &amp;amp; Initialization
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Solidity
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;contract Ownable {
    address public owner;

    constructor(address _owner) {
        owner = _owner;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Compact
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module Ownable {
    import CompactStandardLibrary;

    export ledger _owner: Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;;

    // Called during contract deployment
    export circuit constructor(owner: Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;): [] {
        assert(!isKeyOrAddressZero(owner), "Invalid owner");
        _owner = owner;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key differences:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compact uses a &lt;code&gt;constructor&lt;/code&gt; circuit (special naming convention)&lt;/li&gt;
&lt;li&gt;Must return &lt;code&gt;[]&lt;/code&gt; (empty tuple)&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;assert()&lt;/code&gt; for validation — no &lt;code&gt;require()&lt;/code&gt; equivalent&lt;/li&gt;
&lt;li&gt;No constructor overloading&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4. Functions → Circuits
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Solidity
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function transfer(address to, uint256 amount) public returns (bool) {
    require(balances[msg.sender] &amp;gt;= amount, "Insufficient balance");
    balances[msg.sender] -= amount;
    balances[to] += amount;
    return true;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Compact
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export circuit transfer(
    sender: Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;,
    recipient: Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;,
    amount: Uint&amp;lt;128&amp;gt;
): [] {
    assert(_balances[sender] &amp;gt;= amount, "Insufficient balance");
    _balances[sender] = _balances[sender] - amount;
    _balances[recipient] = _balances[recipient] + amount;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key differences:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;function&lt;/code&gt; → &lt;code&gt;circuit&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;msg.sender&lt;/code&gt; — caller identity passed as parameter or derived from context&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;public&lt;/code&gt;/&lt;code&gt;private&lt;/code&gt;/&lt;code&gt;internal&lt;/code&gt; visibility — use &lt;code&gt;export&lt;/code&gt; for public&lt;/li&gt;
&lt;li&gt;All circuits are ZK circuits under the hood&lt;/li&gt;
&lt;li&gt;State mutations use direct assignment (&lt;code&gt;=&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  5. Mappings &amp;amp; Storage
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Solidity
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mapping(address =&amp;gt; uint256) public balances;
mapping(address =&amp;gt; mapping(address =&amp;gt; uint256)) public allowances;

function getBalance(address account) public view returns (uint256) {
    return balances[account];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Compact
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export ledger balances: Map&amp;lt;Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;, Uint&amp;lt;128&amp;gt;&amp;gt;;
export ledger allowances: Map&amp;lt;Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;,
                              Map&amp;lt;Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;, Uint&amp;lt;128&amp;gt;&amp;gt;&amp;gt;;

export circuit getBalance(
    account: Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;
): Uint&amp;lt;128&amp;gt; {
    return balances[account];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key differences:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Nested maps use nested &lt;code&gt;Map&amp;lt;K, Map&amp;lt;K, V&amp;gt;&amp;gt;&lt;/code&gt; syntax&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;.at()&lt;/code&gt; or overflow checks — &lt;code&gt;Uint&amp;lt;128&amp;gt;&lt;/code&gt; is inherently bounded&lt;/li&gt;
&lt;li&gt;Access with &lt;code&gt;[]&lt;/code&gt; notation (same as Solidity)&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;delete&lt;/code&gt; keyword — assign zero manually&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  6. Access Control
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Solidity
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;modifier onlyOwner() {
    require(msg.sender == owner, "Not the owner");
    _;
}

function setPrice(uint256 _price) public onlyOwner {
    price = _price;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Compact
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Access control is inline — no modifier syntax
export circuit setPrice(
    caller: Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;,
    newPrice: Uint&amp;lt;128&amp;gt;
): [] {
    assert(caller == _owner, "Not the owner");
    _price = newPrice;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key differences:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No modifiers&lt;/strong&gt; — use inline &lt;code&gt;assert()&lt;/code&gt; checks&lt;/li&gt;
&lt;li&gt;OpenZeppelin provides &lt;code&gt;Ownable&lt;/code&gt; and &lt;code&gt;AccessControl&lt;/code&gt; modules for reuse&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ShieldedAccessControl&lt;/code&gt; provides privacy-preserving role management&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;msg.sender&lt;/code&gt; — identity comes from circuit context or parameters&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  7. Events &amp;amp; Logging
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Solidity
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;event Transfer(address indexed from, address indexed to, uint256 value);

function transfer(address to, uint256 amount) public {
    // ... transfer logic ...
    emit Transfer(msg.sender, to, amount);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Compact
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// ⚠️ Compact does NOT currently support events!
// This is a known limitation.
//
// Workaround: Use ledger entries to store an action log
export ledger _lastAction: Opaque&amp;lt;"string"&amp;gt;;

export circuit transfer(/* ... */): [] {
    // ... transfer logic ...
    _lastAction = "transfer executed";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key differences:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No event emission&lt;/strong&gt; — this is a major current limitation&lt;/li&gt;
&lt;li&gt;Workaround: store action logs in ledger entries or use off-chain indexing&lt;/li&gt;
&lt;li&gt;Future versions plan to add event support&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  8. Error Handling
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Solidity
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function withdraw(uint256 amount) public {
    require(balances[msg.sender] &amp;gt;= amount, "Insufficient funds");
    require(amount &amp;gt; 0, "Zero amount");

    balances[msg.sender] -= amount;
    payable(msg.sender).transfer(amount);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Compact
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export circuit withdraw(
    account: Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;,
    amount: Uint&amp;lt;128&amp;gt;
): [] {
    assert(balances[account] &amp;gt;= amount, "Insufficient funds");
    assert(amount &amp;gt; 0u128, "Zero amount");

    balances[account] = balances[account] - amount;
    // No payable/transfer — use token operations instead
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key differences:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;require()&lt;/code&gt; → &lt;code&gt;assert()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;revert()&lt;/code&gt; or custom error types&lt;/li&gt;
&lt;li&gt;Error messages are strings (same concept)&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;try/catch&lt;/code&gt; — circuits either succeed or fail entirely&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;payable&lt;/code&gt; — value transfers handled through ledger operations&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  9. Data Types
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Solidity
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;uint256 public totalSupply;
address public tokenHolder;
bool public active;
string public name;
struct UserInfo {
    address wallet;
    uint256 balance;
    bool registered;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Compact
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export ledger totalSupply: Uint&amp;lt;128&amp;gt;;
export ledger tokenHolder: Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;;
export ledger active: Bool;
export ledger name: Opaque&amp;lt;"string"&amp;gt;;

// Structs as record types
type UserInfo = {
    wallet: Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;,
    balance: Uint&amp;lt;128&amp;gt;,
    registered: Bool
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Solidity&lt;/th&gt;
&lt;th&gt;Compact&lt;/th&gt;
&lt;th&gt;Notes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;uint256&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Uint&amp;lt;128&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Max 128 bits in Compact&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;uint8&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Uint&amp;lt;8&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Arbitrary bit widths supported&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;address&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Two address types&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;bool&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Bool&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Capitalized&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Opaque&amp;lt;"string"&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Wrapped in Opaque&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;bytes32&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Bytes&amp;lt;32&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Fixed-size byte arrays&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;struct&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ field: Type }&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Record type syntax&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;enum&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Not supported&lt;/td&gt;
&lt;td&gt;Use constants or integers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;array[]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Limited support&lt;/td&gt;
&lt;td&gt;No dynamic arrays on ledger&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  10. Loops &amp;amp; Iteration
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Solidity
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function batchTransfer(address[] memory recipients, uint256 amount) public {
    for (uint i = 0; i &amp;lt; recipients.length; i++) {
        balances[msg.sender] -= amount;
        balances[recipients[i]] += amount;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Compact
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// ⚠️ Loops are generally avoided in Compact circuits
// Each iteration adds to the ZK circuit size (fixed at compile time)
//
// Preferred pattern: Process a fixed number of items
export circuit batchTransfer2(
    sender: Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;,
    recipient1: Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;,
    recipient2: Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;,
    amount: Uint&amp;lt;128&amp;gt;
): [] {
    assert(_balances[sender] &amp;gt;= amount * 2u128, "Insufficient balance");
    _balances[sender] = _balances[sender] - amount * 2u128;
    _balances[recipient1] = _balances[recipient1] + amount;
    _balances[recipient2] = _balances[recipient2] + amount;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key differences:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dynamic loops are problematic — each iteration increases circuit size&lt;/li&gt;
&lt;li&gt;Prefer fixed-size operations or unrolled patterns&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;while&lt;/code&gt; loops in practice&lt;/li&gt;
&lt;li&gt;Circuit size must be determinable at compile time&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Bonus: Privacy Features (Compact-Specific)
&lt;/h2&gt;

&lt;p&gt;Compact introduces concepts that have &lt;strong&gt;no direct Solidity equivalent&lt;/strong&gt;:&lt;/p&gt;

&lt;h3&gt;
  
  
  Shielded State
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Data that's private by default
// Only the owner can see the actual value
// Others can verify correctness without seeing the data

// Witness circuits — provide private inputs
export circuit proveOwnership(
    token_id: Uint&amp;lt;128&amp;gt;,
    witness: OwnershipWitness  // Private input, not visible on-chain
): Bool {
    // Returns true/false without revealing who owns what
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Selective Disclosure
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Solidity: Everything is public
uint256 public salary;  // Anyone can read

// Compact: Prove properties without revealing values
// e.g., "My salary is &amp;gt; $50,000" without revealing the actual amount
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Quick Reference Table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Concept&lt;/th&gt;
&lt;th&gt;Solidity&lt;/th&gt;
&lt;th&gt;Compact&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Contract/Module&lt;/td&gt;
&lt;td&gt;&lt;code&gt;contract Foo {}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;module Foo {}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Function&lt;/td&gt;
&lt;td&gt;&lt;code&gt;function foo() public&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;export circuit foo(): []&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;State variable&lt;/td&gt;
&lt;td&gt;&lt;code&gt;uint256 public x&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;export ledger x: Uint&amp;lt;128&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mapping&lt;/td&gt;
&lt;td&gt;&lt;code&gt;mapping(K =&amp;gt; V)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Map&amp;lt;K, V&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Address&lt;/td&gt;
&lt;td&gt;&lt;code&gt;address&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Either&amp;lt;ZswapCoinPublicKey, ContractAddress&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Error check&lt;/td&gt;
&lt;td&gt;&lt;code&gt;require(cond, msg)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;assert(cond, msg)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Events&lt;/td&gt;
&lt;td&gt;&lt;code&gt;event Transfer(...)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;❌ Not supported yet&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Modifiers&lt;/td&gt;
&lt;td&gt;&lt;code&gt;modifier onlyOwner()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Inline &lt;code&gt;assert()&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Loops&lt;/td&gt;
&lt;td&gt;&lt;code&gt;for (uint i...)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Avoid; use fixed-size ops&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Max integer&lt;/td&gt;
&lt;td&gt;&lt;code&gt;uint256&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Uint&amp;lt;128&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Constructor&lt;/td&gt;
&lt;td&gt;&lt;code&gt;constructor()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;export circuit constructor()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Import&lt;/td&gt;
&lt;td&gt;&lt;code&gt;import "./Foo.sol"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;import "./Foo" prefix Foo_&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Try it yourself&lt;/strong&gt;: Pick a simple Solidity contract and try converting it to Compact&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explore OpenZeppelin Compact Contracts&lt;/strong&gt;: &lt;a href="https://github.com/OpenZeppelin/compact-contracts" rel="noopener noreferrer"&gt;github.com/OpenZeppelin/compact-contracts&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read the Midnight docs&lt;/strong&gt;: &lt;a href="https://docs.midnight.network" rel="noopener noreferrer"&gt;docs.midnight.network&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Join the community&lt;/strong&gt;: &lt;a href="https://discord.com/invite/midnightnetwork" rel="noopener noreferrer"&gt;Discord&lt;/a&gt; | &lt;a href="https://forum.midnight.network" rel="noopener noreferrer"&gt;Forum&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;em&gt;Written by &lt;a href="https://github.com/zhaog100" rel="noopener noreferrer"&gt;@zhaog100&lt;/a&gt; for the Midnight Network bounty program.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>solidity</category>
      <category>blockchain</category>
      <category>web3</category>
      <category>midnight</category>
    </item>
    <item>
      <title>RustChain: Revolutionizing Crypto Mining with Vintage Hardware</title>
      <dc:creator>zhaog100</dc:creator>
      <pubDate>Thu, 19 Mar 2026 01:34:20 +0000</pubDate>
      <link>https://dev.to/zhaog100/rustchain-revolutionizing-crypto-mining-with-vintage-hardware-epo</link>
      <guid>https://dev.to/zhaog100/rustchain-revolutionizing-crypto-mining-with-vintage-hardware-epo</guid>
      <description>&lt;h1&gt;
  
  
  RustChain: Revolutionizing Crypto Mining with Vintage Hardware
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In a world where cryptocurrency mining has become synonymous with energy consumption and environmental concerns, &lt;strong&gt;RustChain&lt;/strong&gt; emerges as a groundbreaking solution that turns the narrative upside down. By leveraging vintage hardware from the 1990s and 2000s, RustChain is not just mining crypto—it's preserving computing history while earning rewards.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is RustChain?
&lt;/h2&gt;

&lt;p&gt;RustChain is a Proof-of-Antiquity blockchain that rewards users for running miners on old hardware. The older and more "obsolete" the hardware, the better. This innovative approach addresses two critical problems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;E-Waste Reduction&lt;/strong&gt;: Millions of tons of electronic waste are generated annually. RustChain gives old computers a new purpose.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Energy Efficiency&lt;/strong&gt;: Vintage hardware consumes a fraction of the power compared to modern GPU mining rigs.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The Proof-of-Antiquity Concept
&lt;/h2&gt;

&lt;p&gt;Traditional Proof-of-Work blockchains require massive computational power and energy. RustChain's Proof-of-Antiquity flips this model:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Vintage Hardware Bonus&lt;/strong&gt;: Older machines earn 2.5x rewards&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hardware Fingerprinting&lt;/strong&gt;: Each device is uniquely identified to prevent spoofing&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fair Distribution&lt;/strong&gt;: No ASIC arms race—everyone with old hardware can participate&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Real-World Impact
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Environmental Benefits
&lt;/h3&gt;

&lt;p&gt;According to Elyan Labs, the entire RustChain fleet (16 machines) draws roughly the same power as &lt;strong&gt;ONE modern GPU mining rig&lt;/strong&gt; (~2,000W). Meanwhile, it prevents:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;1,300+ kg&lt;/strong&gt; of manufacturing CO₂&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;250 kg&lt;/strong&gt; of e-waste&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Preserving Computing History
&lt;/h3&gt;

&lt;p&gt;The RustChain fleet includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PowerPC G4s from 2003&lt;/li&gt;
&lt;li&gt;386 laptops from 1990&lt;/li&gt;
&lt;li&gt;IBM POWER8 mainframes&lt;/li&gt;
&lt;li&gt;Mac Pro trashcans&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All still computing. All earning their keep.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Get Started
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Requirements
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Vintage Hardware&lt;/strong&gt;: Any computer from before 2010 (the older, the better)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Network Connection&lt;/strong&gt;: Basic internet connectivity&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RTC Wallet&lt;/strong&gt;: To receive your mining rewards&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Setup Process
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Download the RustChain miner&lt;/li&gt;
&lt;li&gt;Configure your hardware fingerprint&lt;/li&gt;
&lt;li&gt;Join the network and start earning&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The AI Agent Economy
&lt;/h2&gt;

&lt;p&gt;RustChain isn't just about mining—it's building an entire AI agent economy. With projects like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;BoTTube&lt;/strong&gt;: AI video platform with 1,000+ videos&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Beacon&lt;/strong&gt;: Agent-to-agent communication protocol&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TrashClaw&lt;/strong&gt;: Local tool-use agent&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The ecosystem is designed for AI agents to earn, spend, and interact using RTC tokens.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why This Matters
&lt;/h2&gt;

&lt;h3&gt;
  
  
  For Crypto Enthusiasts
&lt;/h3&gt;

&lt;p&gt;RustChain offers a sustainable alternative to traditional mining. No expensive GPUs, no massive electricity bills—just old hardware doing new things.&lt;/p&gt;

&lt;h3&gt;
  
  
  For Environmental Advocates
&lt;/h3&gt;

&lt;p&gt;Every RustChain miner is one less piece of e-waste in a landfill. It's crypto mining with a conscience.&lt;/p&gt;

&lt;h3&gt;
  
  
  For Vintage Computing Fans
&lt;/h3&gt;

&lt;p&gt;Your old computers aren't just collectibles—they're earning potential. Dust off that PowerMac and put it to work!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;RustChain represents a paradigm shift in cryptocurrency mining. By combining environmental responsibility with technological innovation, it's proving that old hardware can teach new tricks.&lt;/p&gt;

&lt;p&gt;Whether you're a crypto miner, environmental advocate, or vintage computing enthusiast, RustChain offers something unique: &lt;strong&gt;the chance to earn while preserving history&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Get Involved
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub&lt;/strong&gt;: &lt;a href="https://github.com/Scottcjn/Rustchain" rel="noopener noreferrer"&gt;https://github.com/Scottcjn/Rustchain&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Discord&lt;/strong&gt;: &lt;a href="https://discord.gg/cafc4nDV" rel="noopener noreferrer"&gt;https://discord.gg/cafc4nDV&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Start Mining&lt;/strong&gt;: &lt;a href="https://rustchain.org" rel="noopener noreferrer"&gt;https://rustchain.org&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Ready to turn your old hardware into new rewards? Join RustChain today!&lt;/em&gt; 🚀&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Word Count&lt;/strong&gt;: ~500 words&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Topics Covered&lt;/strong&gt;: RustChain, Proof-of-Antiquity, E-Waste, Vintage Hardware, AI Agent Economy&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Target Platform&lt;/strong&gt;: Dev.to&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Bounty&lt;/strong&gt;: 5 RTC (~$0.50-1.00)&lt;/p&gt;

</description>
      <category>rustchain</category>
      <category>crypto</category>
      <category>blockchain</category>
      <category>ai</category>
    </item>
    <item>
      <title>RustChain: Revolutionizing Crypto Mining with Vintage Hardware</title>
      <dc:creator>zhaog100</dc:creator>
      <pubDate>Thu, 19 Mar 2026 01:27:39 +0000</pubDate>
      <link>https://dev.to/zhaog100/rustchain-revolutionizing-crypto-mining-with-vintage-hardware-3km3</link>
      <guid>https://dev.to/zhaog100/rustchain-revolutionizing-crypto-mining-with-vintage-hardware-3km3</guid>
      <description></description>
    </item>
    <item>
      <title>Proof-of-Antiquity: Mining Crypto on Vintage Hardware with RustChain</title>
      <dc:creator>zhaog100</dc:creator>
      <pubDate>Wed, 18 Mar 2026 02:22:29 +0000</pubDate>
      <link>https://dev.to/zhaog100/proof-of-antiquity-mining-crypto-on-vintage-hardware-with-rustchain-m5e</link>
      <guid>https://dev.to/zhaog100/proof-of-antiquity-mining-crypto-on-vintage-hardware-with-rustchain-m5e</guid>
      <description>&lt;h1&gt;
  
  
  Proof-of-Antiquity: Mining Crypto on Vintage Hardware with RustChain
&lt;/h1&gt;

&lt;p&gt;A revolutionary blockchain that turns your old computers into mining powerhouses.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In a world where cryptocurrency mining has become dominated by expensive ASICs and energy-hungry GPU farms, &lt;strong&gt;RustChain&lt;/strong&gt; emerges as a breath of fresh air.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is RustChain?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;RustChain&lt;/strong&gt; is a blockchain platform built with Rust, designed to enable decentralized mining on vintage hardware.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Features
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Proof-of-Antiquity Consensus&lt;/li&gt;
&lt;li&gt;Rust-Based Implementation
&lt;/li&gt;
&lt;li&gt;Cross-Platform Support&lt;/li&gt;
&lt;li&gt;Low Energy Consumption&lt;/li&gt;
&lt;li&gt;Community-Driven&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/Scottcjn/rustchain-miner.git
cargo build &lt;span class="nt"&gt;--release&lt;/span&gt;
./target/release/rustchain-miner
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Supported Hardware
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;PowerPC G4/G5 ✅&lt;/li&gt;
&lt;li&gt;Intel x86/x64 ✅&lt;/li&gt;
&lt;li&gt;ARM (Raspberry Pi) ✅&lt;/li&gt;
&lt;li&gt;68K Macintosh 🚧&lt;/li&gt;
&lt;li&gt;Amiga (68K/PPC) 🚧&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Join the Community
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;GitHub: &lt;a href="https://github.com/Scottcjn/rustchain" rel="noopener noreferrer"&gt;https://github.com/Scottcjn/rustchain&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Bounty Program: &lt;a href="https://github.com/Scottcjn/rustchain-bounties" rel="noopener noreferrer"&gt;https://github.com/Scottcjn/rustchain-bounties&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;RustChain represents a refreshing take on blockchain technology. Dust off that old Mac and join the Proof-of-Antiquity revolution! 🦀⛏️&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wallet&lt;/strong&gt;: TGu4W5T6q4KvLAbmXmZSRpUBNRCxr2aFTP&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Word Count: 650+&lt;/em&gt;&lt;/p&gt;

</description>
      <category>rustchain</category>
      <category>blockchain</category>
      <category>cryptocurrency</category>
      <category>vintage</category>
    </item>
  </channel>
</rss>
