<?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: Efe Kırbaş</title>
    <description>The latest articles on DEV Community by Efe Kırbaş (@efek).</description>
    <link>https://dev.to/efek</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4063515%2Fc6475038-e94d-4e95-aa93-7a4951830ed0.png</url>
      <title>DEV Community: Efe Kırbaş</title>
      <link>https://dev.to/efek</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/efek"/>
    <language>en</language>
    <item>
      <title>Zero-Knowledge Age Verification on Midnight: How Compact Enables Private On-Chain Data</title>
      <dc:creator>Efe Kırbaş</dc:creator>
      <pubDate>Mon, 10 Aug 2026 08:30:56 +0000</pubDate>
      <link>https://dev.to/midnight-aliit/zero-knowledge-age-verification-on-midnight-how-compact-enables-private-on-chain-data-139g</link>
      <guid>https://dev.to/midnight-aliit/zero-knowledge-age-verification-on-midnight-how-compact-enables-private-on-chain-data-139g</guid>
      <description>&lt;h2&gt;
  
  
  How do you verify user eligibility on-chain without revealing sensitive personal identity data?
&lt;/h2&gt;

&lt;p&gt;Traditional KYC processes force an unwanted trade-off: transparency versus privacy. Exposing dates of birth or identity credentials directly on a public ledger introduces severe privacy and security risks.&lt;/p&gt;

&lt;p&gt;Midnight Network solves this dilemma through a clean separation of Public vs. Private State:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Private State: The user's sensitive data (e.g., birthdate) stays on-device in their local environment/wallet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Public State: Only the verification status (e.g., a boolean true/false) is posted to the ledger.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How Compact Structures ZK Predicate Logic
&lt;/h2&gt;

&lt;p&gt;Midnight’s domain-specific language, Compact, allows developers to write zero-knowledge logic without drowning in complex cryptographic circuits.&lt;/p&gt;

&lt;p&gt;Here is how a simple ZK predicate for age verification looks in Compact:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="n"&gt;contract&lt;/span&gt; &lt;span class="n"&gt;AgeVerification&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;is_verified&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;transition&lt;/span&gt; &lt;span class="nf"&gt;verify_age&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;birth_year&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Uint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;current_year&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Uint&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Executed inside the ZK circuit&lt;/span&gt;
        &lt;span class="nf"&gt;assert&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;current_year&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;birth_year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Public ledger only learns the boolean output&lt;/span&gt;
        &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;is_verified&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;caller&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How It Works Under the Hood
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Local Input: The user inputs their birth_year locally inside their wallet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ZK Proof Generation: The wallet executes the circuit locally and generates a Zero-Knowledge Proof confirming (current_year - birth_year) &amp;gt;= 18.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Off-Chain Privacy: The actual birth_year raw data never leaves the off-chain environment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On-Chain Verification: Validators only verify the validity of the mathematical proof—never the raw user inputs.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;This architecture replaces raw data exposure with verifiable cryptographic proofs. From selective KYC to private DeFi credit scoring, Midnight abstracts complex ZK mathematics into simple, readable logic.&lt;/p&gt;

&lt;p&gt;Building privacy-first dApps on Midnight changes how we handle data ownership on-chain.&lt;/p&gt;

</description>
      <category>web3</category>
      <category>blockchain</category>
      <category>midnightfordevs</category>
      <category>privacy</category>
    </item>
    <item>
      <title>Mastering Zero-Knowledge Identity Patterns in Midnight with Compact</title>
      <dc:creator>Efe Kırbaş</dc:creator>
      <pubDate>Sun, 09 Aug 2026 08:10:34 +0000</pubDate>
      <link>https://dev.to/efek/mastering-zero-knowledge-identity-patterns-in-midnight-with-compact-2313</link>
      <guid>https://dev.to/efek/mastering-zero-knowledge-identity-patterns-in-midnight-with-compact-2313</guid>
      <description>&lt;p&gt;If you're coming from the world of EVM and Solidity, you know the golden rule: &lt;strong&gt;everything on the blockchain is public&lt;/strong&gt;. If you need to verify a user's identity, you typically have to store their public address or identity hash directly on-chain, creating a permanent, public trail of their activities.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://midnight.network/" rel="noopener noreferrer"&gt;Midnight Network&lt;/a&gt; flips this paradigm on its head. As a data-protection blockchain, it allows developers to build applications that protect sensitive data while still guaranteeing execution correctness through Zero-Knowledge (ZK) proofs.&lt;/p&gt;

&lt;p&gt;In this guide, we're going to dive into &lt;strong&gt;Compact&lt;/strong&gt; (Midnight’s TypeScript-inspired smart contract language) and explore a fundamental privacy pattern: &lt;strong&gt;Zero-Knowledge Identity Verification&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Concept: Commit-Reveal Identity
&lt;/h2&gt;

&lt;p&gt;To verify a user without exposing who they are, we use a pattern where:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The user holds a &lt;strong&gt;Private Secret&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The contract stores a &lt;strong&gt;Public Commitment&lt;/strong&gt; (a hash of the secret).&lt;/li&gt;
&lt;li&gt;The user generates a &lt;strong&gt;ZK Proof&lt;/strong&gt; locally to prove they know the secret behind the commitment, without ever revealing the secret itself to the network.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In Compact, this is achieved through three core pillars:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Ledger:&lt;/strong&gt; Public state visible to everyone.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Witness:&lt;/strong&gt; Private data that never leaves the user's local machine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Circuit:&lt;/strong&gt; The logic that generates a ZK proof locally before submitting a transaction.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Code Implementation
&lt;/h2&gt;

&lt;p&gt;Here is a fully functional Compact contract implementing this pattern.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pragma language_version &amp;gt;= 0.23;
import CompactStandardLibrary;

// 1. PUBLIC LEDGER STATE
// Directly export a single updatable ledger storage slot.
export ledger last_user: Bytes&amp;lt;32&amp;gt;;

// 2. PRIVATE WITNESS DATA
// Witnesses are strictly local. This value is never sent over the network.
witness secret_key(): Bytes&amp;lt;32&amp;gt;;

// 3. ZK CIRCUITS
export circuit update(): [] {
    // Read the private secret key locally from the user's device
    const sk = secret_key();

    // Derive a cryptographic commitment (identifier) from the private key
    const myself = persistentHash&amp;lt;Bytes&amp;lt;32&amp;gt;&amp;gt;(sk);

    // Write the commitment to the public ledger. 
    // disclose() is used to intentionally make the hashed value public.
    last_user.write(disclose(myself));
}

export circuit verify_user(): [] {
    // Read the private secret key locally again
    const sk = secret_key();

    // Re-calculate the identifier
    const myself = persistentHash&amp;lt;Bytes&amp;lt;32&amp;gt;&amp;gt;(sk);

    // ZK Assertion: Ensure the calculated hash matches the public ledger state.
    // If this fails, the proof generation fails.
    assert(myself == last_user.read(), "Oops: you're not the current user");

    // If successful, the blockchain only receives a mathematical proof 
    // that this assertion passed. The `secret_key` remains hidden!
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Breaking Down the Magic
&lt;/h2&gt;

&lt;p&gt;Let's look at why this works securely and doesn't leak data:&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: The Witness Function
&lt;/h3&gt;

&lt;p&gt;Unlike Solidity where msg.sender is implicitly public, Compact forces you to define private data explicitly using the witness keyword. When a user interacts with this contract, the secret_key value is supplied locally by the DApp's witness implementation (backed by the private-state provider running in the user's wallet). The Proof Server later generates the ZK proof from data already supplied locally; it never sources or handles your raw secrets.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: The Hash Commitment
&lt;/h3&gt;

&lt;p&gt;We cannot store the secret_key directly on the ledger. Instead, we use persistentHash, a built-in Compact function designed specifically for deriving state identifiers from private data. It creates a one-way deterministic hash.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Zero-Knowledge Assertion
&lt;/h3&gt;

&lt;p&gt;This is where the Zero-Knowledge magic happens. When &lt;code&gt;verify_user()&lt;/code&gt; is called, the user's machine executes the code, hashes their local secret, and compares it against &lt;code&gt;last_user.read()&lt;/code&gt;. &lt;br&gt;
If they match, the machine generates a &lt;strong&gt;ZK Proof&lt;/strong&gt; saying: &lt;em&gt;"I executed this code, and the assertion was true."&lt;/em&gt; &lt;br&gt;
The Midnight network validates the proof, not the data. The network knows the user is authorized, but has absolutely no idea what the &lt;code&gt;secret_key&lt;/code&gt; actually is.&lt;/p&gt;

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

&lt;p&gt;By separating data into &lt;strong&gt;Ledger&lt;/strong&gt; (public) and &lt;strong&gt;Witness&lt;/strong&gt; (private), and combining them inside a &lt;strong&gt;Circuit&lt;/strong&gt;, Compact makes building Zero-Knowledge applications incredibly intuitive. &lt;/p&gt;

&lt;p&gt;You no longer have to be a cryptographer writing complex polynomial equations to utilize ZK-rollups. With a syntax that feels right at home for Web2 and Web3 developers alike, Midnight allows you to build dApps where privacy is the default, not an afterthought.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Have you experimented with Compact yet? Let me know what you're building in the comments!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>midnightfordevs</category>
      <category>web3</category>
      <category>blockchain</category>
      <category>zeroknowledge</category>
    </item>
  </channel>
</rss>
