<?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: Toshiya Matsumoto</title>
    <description>The latest articles on DEV Community by Toshiya Matsumoto (@toshiya_matsumoto_ac94abe).</description>
    <link>https://dev.to/toshiya_matsumoto_ac94abe</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%2F2142214%2F2a679b0a-f620-48f3-95fc-41fdc6e40158.jpeg</url>
      <title>DEV Community: Toshiya Matsumoto</title>
      <link>https://dev.to/toshiya_matsumoto_ac94abe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/toshiya_matsumoto_ac94abe"/>
    <language>en</language>
    <item>
      <title>Connecting Conversation and UI with Hermes: The Architecture of an AI Dialogue Plugin</title>
      <dc:creator>Toshiya Matsumoto</dc:creator>
      <pubDate>Mon, 23 Nov 2026 06:01:40 +0000</pubDate>
      <link>https://dev.to/toshiya_matsumoto_ac94abe/connecting-conversation-and-ui-with-hermes-the-architecture-of-an-ai-dialogue-plugin-3kg6</link>
      <guid>https://dev.to/toshiya_matsumoto_ac94abe/connecting-conversation-and-ui-with-hermes-the-architecture-of-an-ai-dialogue-plugin-3kg6</guid>
      <description>&lt;p&gt;I built a Hermes plugin that opens a form in the chat when you talk to it, helps you fill in the values through a GUI, and then runs the request through an SDK behind the scenes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fk9g4if3gcp4lbdt4tfi5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fk9g4if3gcp4lbdt4tfi5.png" alt=" " width="800" height="542"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Purpose 🎯
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;An overview of the architecture I landed on&lt;/li&gt;
&lt;li&gt;Problems I ran into along the way, and how I fixed them&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I will not go into the SDK itself (the mechanics of sending funds).&lt;/p&gt;

&lt;h2&gt;
  
  
  1. How the model, the user, and the UI work together 🧩
&lt;/h2&gt;

&lt;p&gt;There are three players:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Player&lt;/th&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;User&lt;/td&gt;
&lt;td&gt;Tells the chat what they want. Fills in the form and decides when to run it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Model&lt;/td&gt;
&lt;td&gt;Reads the conversation and decides what to do&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;UI&lt;/td&gt;
&lt;td&gt;Renders a form in the chat. Calls the SDK from the submit button&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The model can only produce text and tool calls. Hermes therefore provides three mechanisms that connect the model to the outside world.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart LR
    U([User]) -- chat --&amp;gt; M[Model]
    M -- 1.1 call a tool --&amp;gt; P[Plugin logic&amp;lt;br/&amp;gt;Python]
    P -- return value + afterCall --&amp;gt; M
    S[1.2 SKILL.md&amp;lt;br/&amp;gt;playbook] -. only when loaded .-&amp;gt; M
    M -- 1.3 write a directive in the reply --&amp;gt; H[Hermes]
    H -- replace with a component --&amp;gt; UI[Form&amp;lt;br/&amp;gt;React]
    U -- input / submit --&amp;gt; UI
    UI -- run --&amp;gt; SDK[(SDK)]&lt;/code&gt;&lt;/pre&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mechanism&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;th&gt;Direction&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;tool&lt;/td&gt;
&lt;td&gt;Lets the model invoke processing&lt;/td&gt;
&lt;td&gt;Model ⇄ plugin logic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SKILL.md&lt;/td&gt;
&lt;td&gt;Teaches the model the procedure&lt;/td&gt;
&lt;td&gt;→ Model&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;directive&lt;/td&gt;
&lt;td&gt;Hermes replaces it with a UI component&lt;/td&gt;
&lt;td&gt;Model → Hermes → UI&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  1.1 tool: a function the model can call
&lt;/h3&gt;

&lt;p&gt;A tool is a function the model can call. The developer registers the name, the shape of the arguments, and the handler. The handler is written in Python.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;register_tool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'create_draft'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;schema&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'create_draft'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'description'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Create a draft for a transfer'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'parameters'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="s1"&gt;'type'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'object'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s1"&gt;'properties'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s1"&gt;'kind'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;'type'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'string'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'enum'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'send'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'deposit'&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;span class="p"&gt;.&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;span class="s1"&gt;'fields'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="s1"&gt;'type'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'object'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="s1"&gt;'properties'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s1"&gt;'network'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;'type'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'string'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'null'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'enum'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'polygon'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'base'&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;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;None&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;span class="s1"&gt;'token'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;   &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;'type'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'string'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'null'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'enum'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'USDC'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'JPYC'&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;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;None&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;span class="s1"&gt;'amount'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;'type'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'string'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'null'&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;span class="s1"&gt;'to'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;'type'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'string'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'null'&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;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="s1"&gt;'additionalProperties'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;False&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;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s1"&gt;'required'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'kind'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'fields'&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;span class="p"&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;handler&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;create_handler&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;p&gt;The only thing visible to the model is the &lt;code&gt;schema&lt;/code&gt;. Every field allows &lt;code&gt;null&lt;/code&gt;, and the allowed values are listed in an &lt;code&gt;enum&lt;/code&gt;. If the user says "I want to send 0.01 USDC," the model calls the tool with arguments in this shape. Fields the user did not mention are left as &lt;code&gt;null&lt;/code&gt; rather than guessed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"kind"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"send"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"fields"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"network"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"token"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"USDC"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"amount"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"0.01"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"to"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&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;p&gt;Hermes runs the &lt;code&gt;handler&lt;/code&gt; and returns the result to the model. The model reads that result and writes its next reply.&lt;/p&gt;

&lt;p&gt;This is where &lt;strong&gt;&lt;code&gt;afterCall&lt;/code&gt;&lt;/strong&gt; comes in. You put "rules to follow after the call" in the return value. Because the return value always reaches the model immediately after the tool is called, it is a good place for instructions that must not be skipped.&lt;/p&gt;

&lt;p&gt;In practice, with a local model (qwen3.6), I saw it invent directive names, pass along unverified information, or skip the form I had prepared. I now put those same reminders in &lt;code&gt;afterCall&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here is a typical example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"directive"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"::draft-card{id=\"…\"}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"afterCall"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"In your next reply, write the directive above on its own line, exactly as is. Do not ask for missing values in the chat. Collect input through the card."&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  1.2 SKILL.md: a playbook you give the model
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;SKILL.md&lt;/code&gt; is a playbook you have the model read. You write "when asked to send funds, proceed like this" in Markdown.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;---
name: send
description: "Start a transfer and report the result."
---

Do not ask for the network, token, amount, or destination in the chat.
The form already has input fields. Write a short sentence, then put the directive on the next line.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The only thing that always goes into the system prompt is the one-line &lt;code&gt;description&lt;/code&gt;. The body enters the conversation only when the model decides "I need this skill" and loads it. The upside is that you can write a long procedure and still keep the everyday prompt short. The downside is that &lt;strong&gt;if the model never reads it, the procedure never arrives&lt;/strong&gt;. In other words, whether it gets read is up to the model. This comes up again in the wrap-up.&lt;/p&gt;

&lt;h3&gt;
  
  
  1.3 directive: one line in the reply becomes UI
&lt;/h3&gt;

&lt;p&gt;A directive is a mechanism that replaces one line in the model's reply with a React component. On the UI side, you register a name and a component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;area&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;TRANSCRIPT_DIRECTIVE_AREA&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// a constant from the Hermes Plugin SDK&lt;/span&gt;
  &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'draft-card'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;render&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;DraftCard&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;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;props&lt;/span&gt;&lt;span class="p"&gt;}&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="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;p&gt;When the model replies like this, Hermes replaces the &lt;code&gt;::draft-card{...}&lt;/code&gt; line with a card. The contents of the curly braces are passed to the component as &lt;code&gt;attrs&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I've opened a transfer form. Please fill in the rest.

::draft-card{token="USDC" amount="0.01"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The model does not draw the screen. It just writes one line that means "put this component here."&lt;/p&gt;

&lt;h3&gt;
  
  
  The flow that connects tools and directives
&lt;/h3&gt;



&lt;pre data-lang="mermaid"&gt;&lt;code&gt;sequenceDiagram
    actor U as User
    participant M as Model
    participant T as tool (Python)
    participant H as Hermes
    participant UI as Form (React)
    participant SDK as SDK

    U-&amp;gt;&amp;gt;M: I want to send 0.01 USDC
    M-&amp;gt;&amp;gt;T: call create_draft
    T--&amp;gt;&amp;gt;M: directive and afterCall
    M-&amp;gt;&amp;gt;H: write the directive in the reply
    H-&amp;gt;&amp;gt;UI: replace the directive line with a form
    U-&amp;gt;&amp;gt;UI: fill in the rest and submit
    UI-&amp;gt;&amp;gt;SDK: send funds&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;That was enough to get "talk to it and a form opens" working. But once the values had been passed from the directive attributes into the form, &lt;strong&gt;they existed only in React state (inside the screen)&lt;/strong&gt;. That is where the trouble started 😅&lt;/p&gt;

&lt;h3&gt;
  
  
  The problems
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;You cannot change the values in conversation while the form is open.&lt;/strong&gt;
Even if the user says "actually, make it 0.02," the model cannot read the form values, and it cannot edit them either. If it emits a new directive and opens a different form, the destination the user already typed in disappears.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;After submit, the result never reaches the model.&lt;/strong&gt;
It is the UI that runs the operation. Only the UI knows the operation ID and the result. If the user asks "what happened to that transfer?", the model has nothing to answer with.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;There is a risk of double submission.&lt;/strong&gt;
A flag in the UI can stop a button from being mashed, but it cannot stop the same form being opened twice, or a retry after the app is restarted.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All three have the same root cause: &lt;strong&gt;where the values live&lt;/strong&gt;. If you put them in the reply, the UI cannot edit them. If you put them in UI state, the model cannot read them.&lt;/p&gt;

&lt;p&gt;So I decided to put them somewhere that is neither of those places. That somewhere is SQLite.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Introducing SQLite 🗄️
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2.1 Architecture with SQLite
&lt;/h3&gt;



&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart LR
    U([User]) -- chat --&amp;gt; M[Model]
    M -- create / read / update / cancel --&amp;gt; T[tool&amp;lt;br/&amp;gt;Python]
    T -- return value + afterCall + directive --&amp;gt; M
    T &amp;lt;--&amp;gt; DB[(Draft&amp;lt;br/&amp;gt;SQLite)]
    M -- "::draft-card{id=…}" --&amp;gt; H[Hermes]
    H -- replace with a component --&amp;gt; UI[Card&amp;lt;br/&amp;gt;React]
    UI &amp;lt;-- plugin REST API --&amp;gt; DB
    U -- input / submit --&amp;gt; UI
    UI -- send funds --&amp;gt; SDK[(SDK)]&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Each chat session holds one draft row. The model reads and writes that same row through tools; the UI does it through the plugin's REST API. The table actually looks like this (only the columns needed for this explanation):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;drafts&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="kt"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;session_id&lt;/span&gt; &lt;span class="kt"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;kind&lt;/span&gt; &lt;span class="kt"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;fields&lt;/span&gt; &lt;span class="kt"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;        &lt;span class="c1"&gt;-- input values (JSON)&lt;/span&gt;
  &lt;span class="n"&gt;revision&lt;/span&gt; &lt;span class="kt"&gt;INTEGER&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;-- incremented by 1 whenever a value changes&lt;/span&gt;
  &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="kt"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;         &lt;span class="c1"&gt;-- editing / sending / consumed / cancelled&lt;/span&gt;
  &lt;span class="n"&gt;claim_token&lt;/span&gt; &lt;span class="kt"&gt;TEXT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;operation_id&lt;/span&gt; &lt;span class="kt"&gt;TEXT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;outcome&lt;/span&gt; &lt;span class="kt"&gt;TEXT&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;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;p&gt;To summarize, I chose SQLite for these two reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The data has to survive across conversation turns.&lt;/strong&gt; A tool runs and exits every time it is called, so the data cannot live in memory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Both the Python side and the UI side need to reach it.&lt;/strong&gt; The file lives on the Python side, and the UI goes through an API.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is only one table, so I skipped an ORM and manage the schema version with &lt;code&gt;PRAGMA user_version&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The only thing the directive now passes is the &lt;strong&gt;ID&lt;/strong&gt;. Every time the card opens, it reads the latest saved values.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Summary 🧭
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;tool&lt;/strong&gt; is the path the model uses to invoke processing and receive a result. With &lt;code&gt;afterCall&lt;/code&gt; in the return value, you can reliably deliver reminders immediately after the call.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;SKILL.md&lt;/code&gt;&lt;/strong&gt; is a playbook. It only arrives when the model actually loads it.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;directive&lt;/strong&gt; is a mechanism that turns one line of a reply into UI.&lt;/li&gt;
&lt;li&gt;If you keep values inside the screen, you cannot edit them in conversation, report results after submit, or prevent double submission. I solved this by putting them in a &lt;strong&gt;SQLite draft&lt;/strong&gt;, which the model reads and writes through tools and the UI reads and writes through an API.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That said, I ran into one more wall. When the text a plugin adds to the system prompt (the prompt section) &lt;strong&gt;exceeds 4,000 characters&lt;/strong&gt;, a local model (qwen3.6) did not load it at all. The plugin cannot raise this limit. As I added more transfer types, it grew to 4,482 characters, and the model stopped calling tools entirely and started answering everything in the chat 😅&lt;/p&gt;

&lt;p&gt;I also tried moving the procedure out into &lt;code&gt;SKILL.md&lt;/code&gt;. But that model (qwen3.6) did not read the skill, and started asking for the destination in the chat. It was exactly the "if it does not read it, it never arrives" problem I described in 1.2.&lt;/p&gt;

&lt;p&gt;For now, I write only a short one-line "when to use this" for each type, and push the detailed rules into the tool schema, &lt;code&gt;afterCall&lt;/code&gt;, and validation on the card, so everything stays under the limit. If the number of types keeps growing, though, we will run out of room eventually. I am still thinking about how to handle that.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Source code of the Hermes plugin SDK (tool registration, directives, prompt sections)&lt;/li&gt;
&lt;li&gt;SQLite: &lt;a href="https://www.sqlite.org/lang_update.html" rel="noopener noreferrer"&gt;UPDATE&lt;/a&gt;, &lt;a href="https://www.sqlite.org/partialindex.html" rel="noopener noreferrer"&gt;Partial Indexes&lt;/a&gt;, &lt;a href="https://www.sqlite.org/pragma.html#pragma_user_version" rel="noopener noreferrer"&gt;PRAGMA user_version&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>python</category>
      <category>architecture</category>
    </item>
    <item>
      <title>🔑 Reusing passkeys across environments — browser edition</title>
      <dc:creator>Toshiya Matsumoto</dc:creator>
      <pubDate>Sun, 08 Nov 2026 08:12:49 +0000</pubDate>
      <link>https://dev.to/toshiya_matsumoto_ac94abe/reusing-passkeys-across-environments-browser-edition-1jdj</link>
      <guid>https://dev.to/toshiya_matsumoto_ac94abe/reusing-passkeys-across-environments-browser-edition-1jdj</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published in Japanese on Zenn: &lt;a href="https://zenn.dev/toshibowie/articles/48cbbc9a8a88f4" rel="noopener noreferrer"&gt;passkeyを環境を超えて使い回したい ブラウザ編&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Goal
&lt;/h2&gt;

&lt;p&gt;A passkey is a key that is bound to a specific site. A passkey created on &lt;code&gt;wallet.example.com&lt;/code&gt; cannot be seen by pages on other domains or browser extensions.&lt;/p&gt;

&lt;p&gt;However, when building apps, you often want to do things like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Derive the same secret using the same passkey in a web application on a different domain.&lt;/li&gt;
&lt;li&gt;Use an arbitrary site's passkey from a browser extension.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This article covers &lt;strong&gt;two approaches that use only browser standards&lt;/strong&gt;, backed by code that actually ran. Native apps and OS mechanisms are a topic for another post.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a passkey? A quick mental model 🧩
&lt;/h2&gt;

&lt;p&gt;A passkey is a WebAuthn (FIDO2) key pair.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;private key&lt;/strong&gt; stays securely stored within a provider (such as iCloud Keychain, Google Password Manager or 1Password) and never leaves.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;public key&lt;/strong&gt; is sent to the site.&lt;/li&gt;
&lt;li&gt;When the site asks you to 'sign this challenge', the provider will return a signature after user verification (UV), such as Touch ID.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The important constraint is the &lt;strong&gt;RP ID&lt;/strong&gt; (Relying Party ID). A passkey is bound to an RP ID (usually the site's hostname) at the time of creation, and the browser strictly checks whether the calling page is permitted to claim that RP ID. This is why passkeys are resistant to phishing, but also why they cannot be used freely in another environment.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;PRF extension&lt;/strong&gt; is also available (a pseudo-random function extension). Rather than providing a signature, it enables you to extract a &lt;strong&gt;32-byte secret&lt;/strong&gt; from the passkey.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PRF = HMAC(the passkey's internal random secret, salt)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the same passkey and salt produces the same value every time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bottleneck: three things that must match 🎯
&lt;/h2&gt;

&lt;p&gt;In order to obtain the same secret in a different environment, all three of these must match.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What must match&lt;/th&gt;
&lt;th&gt;If it doesn't&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;RP ID&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The browser throws &lt;code&gt;SecurityError&lt;/code&gt;. You never reach the passkey&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;The passkey (credential) itself&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Calling &lt;code&gt;create&lt;/code&gt; makes a &lt;strong&gt;new&lt;/strong&gt; passkey. PRF differs per passkey, so values won't match&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;salt&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Same passkey, different salt → different value&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The main topic of this article is how to get past the RP ID constraint.&lt;/p&gt;

&lt;h2&gt;
  
  
  Approach 1: Websites 🌐
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1-a. Allow another origin with &lt;code&gt;/.well-known/webauthn&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This uses &lt;strong&gt;Related Origin Requests&lt;/strong&gt; from WebAuthn Level 3. The domain that owns the RP ID can publish a list of origins permitted to claim its RP ID.&lt;/p&gt;

&lt;p&gt;For example, place this file on the RP ID side (&lt;code&gt;wallet.example.com&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;https://wallet.example.com/.well-known/webauthn&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"origins"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"https://app.example.net"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Serve it with &lt;code&gt;Content-Type: application/json&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This allows a page on &lt;code&gt;https://app.example.net&lt;/code&gt; to call WebAuthn with an explicit &lt;code&gt;rpId&lt;/code&gt;. No changes are needed to the calling site's server.&lt;/p&gt;

&lt;p&gt;This is what creating the passkey on &lt;code&gt;wallet.example.com&lt;/code&gt; looks like. If you omit &lt;code&gt;rp.id&lt;/code&gt;, the browser will use the page hostname as the RP ID.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;SALT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TextEncoder&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;example/seed/v1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cred&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;rp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Example Wallet&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;            &lt;span class="c1"&gt;// omit rp.id → RP ID is wallet.example.com&lt;/span&gt;
    &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getRandomValues&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;me&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;displayName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;me&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;challenge&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getRandomValues&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
    &lt;span class="na"&gt;pubKeyCredParams&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public-key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;alg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public-key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;alg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;257&lt;/span&gt; &lt;span class="p"&gt;}],&lt;/span&gt;
    &lt;span class="na"&gt;authenticatorSelection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;residentKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;required&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;userVerification&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;required&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;extensions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;prf&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;first&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;SALT&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;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;prfOnCreate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cred&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getClientExtensionResults&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;prf&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;first&lt;/span&gt;  &lt;span class="c1"&gt;// some providers return this on create&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is an example of getting PRF from the same passkey on a different domain (&lt;code&gt;app.example.net&lt;/code&gt;). The only difference is an &lt;strong&gt;explicit &lt;code&gt;rpId&lt;/code&gt;&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cred&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;rpId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;wallet.example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                &lt;span class="c1"&gt;// ← the key point&lt;/span&gt;
    &lt;span class="na"&gt;challenge&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getRandomValues&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
    &lt;span class="na"&gt;allowCredentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;                      &lt;span class="c1"&gt;// empty → passkeys for this RP ID show in the picker&lt;/span&gt;
    &lt;span class="na"&gt;userVerification&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;required&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;extensions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;prf&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;first&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;SALT&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;span class="c1"&gt;// same salt as create&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;prf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cred&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getClientExtensionResults&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;prf&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;first&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the browser detects that &lt;code&gt;rpId&lt;/code&gt; does not match the page origin, it fetches &lt;code&gt;https://wallet.example.com/.well-known/webauthn&lt;/code&gt; and allows the call if &lt;code&gt;origins&lt;/code&gt; contains the page origin. Otherwise, it throws &lt;code&gt;SecurityError&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This worked in experiments across two &lt;code&gt;*.vercel.app&lt;/code&gt; projects on the Public Suffix List (i.e. separate registrable domains).&lt;/p&gt;

&lt;p&gt;The following constraints should be kept in mind:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can list a maximum of &lt;strong&gt;5 eTLD+1s&lt;/strong&gt; (&lt;code&gt;a.example.net&lt;/code&gt; and &lt;code&gt;b.example.net&lt;/code&gt; count as one).&lt;/li&gt;
&lt;li&gt;Supported in Chrome/Edge 128+ and Safari 18+. Not verified in Firefox.&lt;/li&gt;
&lt;li&gt;The RP side must use HTTPS. It is not possible to validate with &lt;code&gt;localhost&lt;/code&gt; as the RP.&lt;/li&gt;
&lt;li&gt;Negative confirmation (i.e. removing the allowlist entry and checking for &lt;code&gt;SecurityError&lt;/code&gt;) was not performed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  1-b. Parent/child subdomains need no well-known file
&lt;/h3&gt;

&lt;p&gt;An RP ID may already be the page's hostname, or any of its parent domains up to the registrable domain.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Page: https://app.wallet.example.com
Allowed rpId: app.wallet.example.com / wallet.example.com / example.com
Not allowed:  other.example.com / example.net
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Therefore, if you create the passkey with &lt;code&gt;rp.id: 'example.com'&lt;/code&gt; from the outset, both &lt;code&gt;wallet.example.com&lt;/code&gt; and &lt;code&gt;app.example.com&lt;/code&gt; can &lt;code&gt;get&lt;/code&gt; the same passkey. If you expect more subdomains later, using the parent as the RP ID at creation time is the easiest option. 🌱&lt;/p&gt;

&lt;p&gt;However, a passkey &lt;strong&gt;already created with RP ID &lt;code&gt;wallet.example.com&lt;/code&gt;&lt;/strong&gt; cannot later be changed to use the parent RP ID. Existing users need approach 1-a.&lt;/p&gt;

&lt;h2&gt;
  
  
  Approach 2: Browser extensions 🧩
&lt;/h2&gt;

&lt;p&gt;Here's how to use a site's passkey from a Chrome extension page (origin: &lt;code&gt;chrome-extension://&amp;lt;id&amp;gt;&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;The important point: Chrome &lt;strong&gt;skips&lt;/strong&gt; the “RP ID must match the page origin” check for extensions that hold a host permission for the target site. Chromium even comments, “Allow claiming an RP ID if an extension can access this page.” So, declare the RP ID host in &lt;code&gt;manifest.json&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"manifest_version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Example passkey bridge"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"host_permissions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"https://wallet.example.com/*"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Declare the &lt;strong&gt;same host as the RP ID&lt;/strong&gt;. For RP ID &lt;code&gt;example.com&lt;/code&gt;, use &lt;code&gt;https://example.com/*&lt;/code&gt;; for &lt;code&gt;wallet.example.com&lt;/code&gt;, use &lt;code&gt;https://wallet.example.com/*&lt;/code&gt;. Content-script &lt;code&gt;matches&lt;/code&gt; do not count.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The extension-page code is the same as the 1-a caller: call &lt;code&gt;get&lt;/code&gt; with an explicit &lt;code&gt;rpId&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cred&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;rpId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;wallet.example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;challenge&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getRandomValues&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
    &lt;span class="na"&gt;allowCredentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
    &lt;span class="na"&gt;userVerification&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;required&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;extensions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;prf&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;first&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;SALT&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;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;p&gt;Extension-specific notes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The call fails if the user turns off site access in the extension settings.&lt;/li&gt;
&lt;li&gt;The Chrome Web Store review will ask you to justify that host permission.&lt;/li&gt;
&lt;li&gt;This also means &lt;strong&gt;any extension with broad permissions like &lt;code&gt;https://*/*&lt;/code&gt; can do the same&lt;/strong&gt;. The Touch ID prompt shows RP &lt;code&gt;wallet.example.com&lt;/code&gt;, so users may not notice the difference. Services that derive seeds from passkeys should include this path in their threat model. ⚠️&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Bonus: choosing &lt;code&gt;allowCredentials&lt;/code&gt; 🪄
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;allowCredentials&lt;/code&gt; on &lt;code&gt;get&lt;/code&gt; changes the UX:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Empty&lt;/strong&gt;: passkeys for that RP ID appear in the picker—use this the first time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Credential id set&lt;/strong&gt;: Skip the picker and go straight to Touch ID. Use this from the second time onwards.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A credential ID is a public identifier, not a secret. You can store it and carry it across environments. It works on other devices synced by the same provider (for example, another Mac on iCloud or another Chrome on GPM). A different provider returns &lt;code&gt;NotAllowedError&lt;/code&gt;, so fall back to an empty-array picker on failure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways 📝
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Approach&lt;/th&gt;
&lt;th&gt;What you place where&lt;/th&gt;
&lt;th&gt;Who controls allow&lt;/th&gt;
&lt;th&gt;Best for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1-a &lt;code&gt;/.well-known/webauthn&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;One JSON file on the RP ID server&lt;/td&gt;
&lt;td&gt;RP lists origins explicitly&lt;/td&gt;
&lt;td&gt;Cross-domain web apps; keep existing passkeys&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1-b Parent domain as RP ID&lt;/td&gt;
&lt;td&gt;Set &lt;code&gt;rp.id&lt;/code&gt; to the parent at create time&lt;/td&gt;
&lt;td&gt;Stays inside one registrable domain&lt;/td&gt;
&lt;td&gt;New passkeys; designs with growing subdomains&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2 Extension host permission&lt;/td&gt;
&lt;td&gt;One line in &lt;code&gt;manifest.json&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;User extension settings + Store review&lt;/td&gt;
&lt;td&gt;Calling from a browser extension&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In every case, &lt;strong&gt;same RP ID + same passkey + same salt → same PRF&lt;/strong&gt;. Confirming that was the biggest takeaway.&lt;/p&gt;

&lt;h2&gt;
  
  
  Not verified yet
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Differences between providers (iCloud Keychain, Google Password Manager and 1Password) have not yet been verified.&lt;/li&gt;
&lt;li&gt;Negative confirmation after removing the allowlist entry (removing the origin from origins in 1-a; using an undeclared host as &lt;code&gt;rpId&lt;/code&gt; in 2) was not performed.&lt;/li&gt;
&lt;li&gt;Does the PRF remain the same when using a hybrid (QR) with an iPhone?&lt;/li&gt;
&lt;li&gt;Firefox support for Related Origin Requests has not yet been verified.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.w3.org/TR/webauthn-3/" rel="noopener noreferrer"&gt;WebAuthn Level 3&lt;/a&gt; — RP ID rules (§5.1.3), PRF extension, Related Origin Requests&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/webauthn/chrome_web_authentication_delegate.cc" rel="noopener noreferrer"&gt;Chromium &lt;code&gt;chrome_web_authentication_delegate.cc&lt;/code&gt;&lt;/a&gt; — RP ID check exemption for extensions&lt;/li&gt;
&lt;li&gt;&lt;a href="https://publicsuffix.org/" rel="noopener noreferrer"&gt;Public Suffix List&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>passkeys</category>
      <category>webauthn</category>
      <category>security</category>
      <category>javascript</category>
    </item>
    <item>
      <title>🚦 Auto-routing Claude models with Jev prompt classification</title>
      <dc:creator>Toshiya Matsumoto</dc:creator>
      <pubDate>Fri, 06 Nov 2026 05:00:43 +0000</pubDate>
      <link>https://dev.to/toshiya_matsumoto_ac94abe/auto-routing-claude-models-with-jev-prompt-classification-m5a</link>
      <guid>https://dev.to/toshiya_matsumoto_ac94abe/auto-routing-claude-models-with-jev-prompt-classification-m5a</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published in Japanese on Zenn: &lt;a href="https://zenn.dev/toshibowie/articles/9244c8f317a7a9" rel="noopener noreferrer"&gt;Jevでプロンプトを仕分けして、Claudeのモデルを自動で切り替える&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Goal 🎯
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Stop burning Opus on "hello" and Haiku on design decisions&lt;/li&gt;
&lt;li&gt;Let &lt;strong&gt;Jev&lt;/strong&gt; (TypeSafe AI's classification model) classify each prompt, then automatically switch Claude Code's model and effort every turn&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I built a Claude Code plugin that sends every prompt to Jev, picks a suitable model and effort, and applies them for that turn.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Jev? 🧩
&lt;/h2&gt;

&lt;p&gt;You pass it text plus "descriptions of the choices," and it returns &lt;strong&gt;which choice fits&lt;/strong&gt;, with probabilities.&lt;br&gt;
You supply both the label names and the description text on every request. Those descriptions are all Jev uses to decide.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input : state (text to classify) + criteria (label → description of that label)
Output: choice (selected label) + confidence + probabilities (for every label)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are three players:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Player&lt;/th&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Jev&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Picks one label from the descriptions you passed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Custom plugin&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Builds the request, calls Jev, reads the response, sets the model&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Claude Code&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Sends the model request with the model and effort the plugin chose&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;⚠️ &lt;strong&gt;Note:&lt;/strong&gt; Jev only provides a classification API. Callers have to hit the raw API themselves.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Unlike &lt;code&gt;/model&lt;/code&gt;, this plugin does not touch conversation history or memory files. The only thing that changes is the model name and effort on each request.&lt;/p&gt;

&lt;h2&gt;
  
  
  How 🛠️
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. What we send to Jev
&lt;/h3&gt;

&lt;p&gt;Here is the request the plugin builds , shown as &lt;code&gt;curl&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-s&lt;/span&gt; https://api.typesafe.ai/v1/systemone &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Authorization: Bearer &lt;/span&gt;&lt;span class="nv"&gt;$TYPESAFE_API_KEY&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{
    "state": "Fix the typo in the README",
    "model": "jev-latest",
    "questions": {
      "tier": {
        "type": "choice",
        "instructions": "How much model capability does answering this coding-assistant prompt need",
        "criteria": {
          "micro":    "A greeting, a yes/no, a one-line factual question, or a short follow-up that needs no code reading",
          "low":      "A small well-defined edit or lookup in one or two files, a rename, a simple command to run, formatting",
          "medium":   "A feature or bug fix across several files, writing tests, explaining how part of a system works",
          "high":     "Debugging that needs investigation across modules, a refactor touching many files, planning a multi-step change, a normal code review",
          "critical": "Architecture or design decisions, migrations, state-machine changes, ambiguous multi-step tasks with trade-offs",
          "max":      "Fund-safety or security code, adversarial review, cryptography or key handling, anything where a subtle mistake loses money or leaks secrets"
        }
      }
    }
  }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. What comes back
&lt;/h3&gt;

&lt;p&gt;This is the real response for the request above (&lt;code&gt;state&lt;/code&gt; = "Fix the typo in the README"). HTTP 200, 0.17s, called once.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"model"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"jev-1.14.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"answers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"tier"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"choice"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"choice"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"low"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"confidence"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"probabilities"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"micro"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.08&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"low"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.92&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"medium"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"high"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"critical"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"max"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"usage"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"input_tokens"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;504&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"output_tokens"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;59&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;choice&lt;/code&gt;: the label Jev picked. The plugin reads &lt;strong&gt;only&lt;/strong&gt; &lt;code&gt;answers.tier.choice&lt;/code&gt;; if the JSON is broken, it treats it as &lt;code&gt;undefined&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;probabilities&lt;/code&gt;: probabilities for every label. Here &lt;code&gt;low&lt;/code&gt; is 0.92, &lt;code&gt;micro&lt;/code&gt; is 0.08, and the rest are 0.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;confidence&lt;/code&gt; and &lt;code&gt;usage&lt;/code&gt;: the plugin ignores these.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because Jev returned &lt;code&gt;low&lt;/code&gt;, the plugin looks up &lt;code&gt;ROUTES.low&lt;/code&gt; and sets &lt;code&gt;haiku&lt;/code&gt; with effort &lt;code&gt;high&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Deciding after the response
&lt;/h3&gt;

&lt;p&gt;The label Jev returns is &lt;code&gt;tier&lt;/code&gt;. The plugin maps &lt;code&gt;tier&lt;/code&gt; through &lt;code&gt;ROUTES&lt;/code&gt; to get the model and effort. Jev does not choose the model — the plugin does.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ROUTES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;micro&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;haiku&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;            &lt;span class="na"&gt;effort&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;medium&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;low&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;haiku&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;            &lt;span class="na"&gt;effort&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;high&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;   &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;medium&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;   &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sonnet&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;           &lt;span class="na"&gt;effort&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;high&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;   &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;high&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;     &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;opus&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;             &lt;span class="na"&gt;effort&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;medium&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;critical&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;opus&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;             &lt;span class="na"&gt;effort&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;high&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;   &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;max&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;claude-fable-5-1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;effort&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;high&lt;/span&gt;&lt;span class="dl"&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;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;tier (label from Jev)&lt;/th&gt;
&lt;th&gt;When Jev picks it (summary of &lt;code&gt;criteria&lt;/code&gt;)&lt;/th&gt;
&lt;th&gt;Model the plugin uses (&lt;code&gt;ROUTES[tier]&lt;/code&gt;)&lt;/th&gt;
&lt;th&gt;effort&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;micro&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Greeting, yes/no, one-line answer&lt;/td&gt;
&lt;td&gt;&lt;code&gt;haiku&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;medium&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;low&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Small edit in 1–2 files, rename, formatting&lt;/td&gt;
&lt;td&gt;&lt;code&gt;haiku&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;high&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;medium&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Multi-file feature or bugfix, writing tests&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sonnet&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;high&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;high&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Cross-module investigation, large refactor, normal review&lt;/td&gt;
&lt;td&gt;&lt;code&gt;opus&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;medium&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;critical&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Design decisions, migrations, state-machine changes&lt;/td&gt;
&lt;td&gt;&lt;code&gt;opus&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;high&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;max&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Fund/security, adversarial review, crypto and keys&lt;/td&gt;
&lt;td&gt;&lt;code&gt;claude-fable-5-1&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;high&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;route&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ROUTES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;tier&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;    &lt;span class="c1"&gt;// e.g. "high" → { model: 'opus', effort: 'medium' }&lt;/span&gt;

&lt;span class="c1"&gt;// One exception: if we would stay on Haiku past 150k context tokens, bump to Sonnet&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;haiku&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;contextTokens&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="nx"&gt;_000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;ROUTES&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;medium&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;route&lt;/span&gt;                   &lt;span class="c1"&gt;// rewrite this turn's request to route.model / route.effort&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the label is missing from the table, or the Jev call fails, the plugin changes nothing — same behaviour as with no plugin at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Result ✅
&lt;/h2&gt;

&lt;p&gt;The routing result shows up under the prompt almost instantly, and it feels great. It doesn't interrupt the UX at all.&lt;br&gt;
The accuracy seems solid.&lt;br&gt;
Simple tasks now land on Haiku or Sonnet, so the stress of picking a model yourself goes away and the workflow feels more efficient.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgl7z3nwqurgf23uezlgo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgl7z3nwqurgf23uezlgo.png" alt="model-router routing micro → haiku" width="379" height="87"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Going forward, I also think this kind of classification could help with things like prompt-injection defense and other security use cases.&lt;/p&gt;

&lt;p&gt;As a side note, I also drew on the conversation in &lt;a href="https://mozaic.fm/episodes/218/monthly-ecosystem-202610.html" rel="noopener noreferrer"&gt;mozaic.fm ep.218&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>claude</category>
      <category>ai</category>
      <category>typescript</category>
      <category>llm</category>
    </item>
    <item>
      <title>🧵 Run Multi Threads With Rust On Browser — Rayon And 2 Layers Web Worker Mechanism</title>
      <dc:creator>Toshiya Matsumoto</dc:creator>
      <pubDate>Mon, 13 Apr 2026 13:43:00 +0000</pubDate>
      <link>https://dev.to/toshiya_matsumoto_ac94abe/run-multi-threads-with-rust-on-browser-rayon-and-2-layers-web-worker-mechanism-10ne</link>
      <guid>https://dev.to/toshiya_matsumoto_ac94abe/run-multi-threads-with-rust-on-browser-rayon-and-2-layers-web-worker-mechanism-10ne</guid>
      <description>&lt;p&gt;&lt;em&gt;There are no OS threads in the browser — so how does Rust's parallel processing library Rayon actually work?&lt;/em&gt;&lt;br&gt;
Here's a summary.&lt;/p&gt;
&lt;h2&gt;
  
  
  🤔 Why Do We Need This?
&lt;/h2&gt;

&lt;p&gt;When you run heavy computation (taking seconds to tens of seconds) on the browser's main thread, &lt;strong&gt;the UI completely freezes&lt;/strong&gt;. Buttons become unclickable, scrolling stops, and you get the dreaded "This page is not responding" warning.&lt;/p&gt;

&lt;p&gt;The solution is &lt;strong&gt;multithreading&lt;/strong&gt; — offload heavy computation to the background, and split the work across multiple threads.&lt;/p&gt;


&lt;h2&gt;
  
  
  🏗️ Two-Layer Web Worker Architecture
&lt;/h2&gt;

&lt;p&gt;Parallel computation in the browser requires Web Workers serving &lt;strong&gt;two distinct roles&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌─────────────────────────────────────┐
│  🖥️ Main Thread (UI Thread)          │
│                                      │
│  User interactions, screen rendering │
│  → Always responsive                 │
└──────────┬───────────────────────────┘
           │ 📨 postMessage
           ↓
┌─────────────────────────────────────┐
│  👷 Layer 1: Worker Thread (1)       │
│                                      │
│  Takes on heavy computation          │
│  → Zero impact on the main thread    │
│                                      │
│  ┌─────────┬─────────┬─────────┐     │
│  │ 🏃 #1   │ 🏃 #2   │ 🏃 #3   │     │
│  │ rayon   │ rayon   │ rayon   │     │  ← Layer 2
│  │ Worker  │ Worker  │ Worker  │     │    N Web Workers
│  │         │         │         │     │
│  │ Part of │ Part of │ Part of │     │
│  │ the work│ the work│ the work│     │
│  └─────────┴─────────┴─────────┘     │
└─────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🛡️ Layer 1 — Protecting the UI
&lt;/h3&gt;

&lt;p&gt;The role of the Layer 1 Web Worker is to &lt;strong&gt;move heavy computation out of the main thread&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Rayon doesn't come into play here yet — the purpose of this worker thread is simply to decouple from the main thread and keep it free.&lt;/p&gt;

&lt;p&gt;An important note: even if you call a Rust &lt;code&gt;async&lt;/code&gt; function from WASM, the internal CPU work &lt;strong&gt;synchronously blocks the thread&lt;/strong&gt;. Being &lt;code&gt;async&lt;/code&gt; doesn't prevent UI freezing. It's the Web Worker that sets the UI thread free.&lt;/p&gt;

&lt;h3&gt;
  
  
  ⚡ Layer 2 — Splitting the Work
&lt;/h3&gt;

&lt;p&gt;With Layer 1 alone, computation still runs &lt;strong&gt;sequentially on a single thread&lt;/strong&gt;. Layer 2 &lt;strong&gt;splits the computation itself across multiple threads&lt;/strong&gt; for actual speedup.&lt;/p&gt;




&lt;h2&gt;
  
  
  🦀 Rayon — Parallelise with &lt;code&gt;.par_iter()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Rayon&lt;/strong&gt; is Rust's parallel computation library. Usage is simple:&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="c1"&gt;// 😴 Normal (single-threaded, sequential)&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="nf"&gt;.iter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;.map&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="nf"&gt;heavy_computation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="nf"&gt;.collect&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// ⚡ Rayon (multi-threaded, parallel)&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="nf"&gt;.par_iter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;    &lt;span class="c1"&gt;// ← just add par_&lt;/span&gt;
    &lt;span class="nf"&gt;.map&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="nf"&gt;heavy_computation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="nf"&gt;.collect&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change &lt;code&gt;.iter()&lt;/code&gt; to &lt;code&gt;.par_iter()&lt;/code&gt; — that's it. Splitting, dispatching, and collecting results is all handled automatically by Rayon.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;😴 1 thread:
  Thread 1: [Task 1, Task 2, ..., Task 524,288]
  → One thread does everything sequentially

⚡ 8 threads (Rayon):
  Thread 1: [Task      1 –  65,536]  🏃
  Thread 2: [Task 65,537 – 131,072]  🏃
  ...
  Thread 8: [Task 458,753 – 524,288]  🏃
  → 8 threads working simultaneously → ~8x faster
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🌍 Same Rust Code, Different Backend
&lt;/h2&gt;

&lt;p&gt;The beauty of Rayon is that &lt;strong&gt;the same Rust code&lt;/strong&gt; runs on both native and browser. Only the underlying thread implementation differs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         Same Rust code
         data.par_iter()
              │
     ┌────────┴────────┐
     ↓                 ↓
 🖥️ Native         🌐 Browser
     │                 │
  OS threads      wasm-bindgen-rayon
  (pthread)            │
     │            Web Worker × N
     ↓                 ↓
  Parallel ✅      Parallel ✅
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Native&lt;/strong&gt;: Rayon → OS threads (pthread). No configuration needed — it just works.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Browser&lt;/strong&gt;: OS threads don't exist → &lt;code&gt;wasm-bindgen-rayon&lt;/code&gt; translates Rayon's thread requests into Web Workers. &lt;code&gt;initThreadPool(N)&lt;/code&gt; spawns N Web Workers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;initThreadPool()&lt;/code&gt; is only needed in the browser. On native, Rayon automatically uses OS threads.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔒 Requirements for Browser Multithreading
&lt;/h2&gt;

&lt;p&gt;Browser multithreading requires several conditions to be met for security reasons.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Requirement&lt;/th&gt;
&lt;th&gt;Why?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;🔐 &lt;strong&gt;HTTPS&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;SharedArrayBuffer&lt;/code&gt; (shared memory between threads) is only available over HTTPS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;📦 &lt;strong&gt;COEP/COOP headers&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;Cross-origin isolation required as a Spectre vulnerability mitigation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;⚛️ &lt;strong&gt;atomics flag&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;Enables inter-thread memory synchronisation at WASM compile time&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;📚 &lt;strong&gt;build-std&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;Rebuilds Rust's standard library from source with atomics support&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  ⚛️ Why is build-std needed?
&lt;/h3&gt;

&lt;p&gt;The pre-built version of Rust's standard library (&lt;code&gt;std&lt;/code&gt;) does not include atomics (shared memory operations). To share memory between threads, &lt;code&gt;std&lt;/code&gt; must be rebuilt from source.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# ❌ Pre-built std → no atomics → no multithreading&lt;/span&gt;
wasm-pack build &lt;span class="nt"&gt;--release&lt;/span&gt; &lt;span class="nt"&gt;--target&lt;/span&gt; web

&lt;span class="c"&gt;# ✅ build-std rebuilds std → atomics enabled → multithreading works&lt;/span&gt;
&lt;span class="nv"&gt;CARGO_UNSTABLE_BUILD_STD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;std,panic_abort wasm-pack build &lt;span class="nt"&gt;--release&lt;/span&gt; &lt;span class="nt"&gt;--target&lt;/span&gt; web
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;💡 We pass this as an environment variable because Cargo's &lt;code&gt;[unstable]&lt;/code&gt; section is global and cannot be scoped to WASM targets only. Putting it in the config file would break native builds.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🎯 Summary
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User triggers an action 🖱️
  │
  ↓ postMessage
  │
👷 Layer 1: Worker Thread (1)
  │  → Does not block the UI
  │
  ├→ Rayon par_iter()
  │   │
  │   ├→ 🏃 Worker #1: part of the work
  │   ├→ 🏃 Worker #2: part of the work
  │   ...
  │   └→ 🏃 Worker #N: part of the work
  │
  │   → All workers complete → results collected
  │
  ↓ postMessage({ status: 'done' })
  │
🖥️ Main Thread: display result ✅
   → UI stayed responsive throughout 🎉
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🔑 Three Key Takeaways
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Layer 1&lt;/strong&gt; = Protects the UI. Just one worker. Moves heavy computation off the main thread.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Layer 2&lt;/strong&gt; = Makes computation faster. N workers. &lt;code&gt;par_iter()&lt;/code&gt; automatically splits the work.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The same Rust code&lt;/strong&gt; runs on both native and browser. Only the underlying thread implementation differs.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;How was that?&lt;/p&gt;

&lt;p&gt;Speed up your browser computation with Rust's parallel processing library Rayon ⚡⚡⚡&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>performance</category>
      <category>rust</category>
      <category>webdev</category>
    </item>
    <item>
      <title>🔐 Practical Guide to ZKP: Learn Real Usecase of ZKP with Plonky2</title>
      <dc:creator>Toshiya Matsumoto</dc:creator>
      <pubDate>Tue, 31 Mar 2026 02:48:05 +0000</pubDate>
      <link>https://dev.to/toshiya_matsumoto_ac94abe/practical-guide-to-zkp-learn-real-usecase-of-zkp-with-plonky2-408l</link>
      <guid>https://dev.to/toshiya_matsumoto_ac94abe/practical-guide-to-zkp-learn-real-usecase-of-zkp-with-plonky2-408l</guid>
      <description>&lt;p&gt;&lt;em&gt;It's for those who have heard of ZKP but never known the real usecase.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Before We Start
&lt;/h2&gt;

&lt;p&gt;Zero-Knowledge Proof (ZKP) is a technology that proves the truth of a statement without revealing the underlying information. A common example is proving you know a password without showing it.&lt;/p&gt;

&lt;p&gt;This article will use the Rust's fast recursive SNARK framework &lt;a href="https://github.com/0xPolygonZero/plonky2" rel="noopener noreferrer"&gt;Plonky2&lt;/a&gt; to build 3 ZKP circuits step by step. By the end of this article, you will understand the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;How ZKP Circuits Work&lt;/strong&gt; — Constraints, Witness, Public Inputs&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hash Chain Proof&lt;/strong&gt; — Proving the order of data processing&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;State Transition Proof&lt;/strong&gt; — Proving the update of Merkle tree&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🧩 Core Model: Circuit, Prover, Verifier
&lt;/h2&gt;

&lt;p&gt;Let's understand the core 3 models of ZKP:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Entity&lt;/th&gt;
&lt;th&gt;What&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Circuit&lt;/strong&gt; 📐&lt;/td&gt;
&lt;td&gt;Define mathematical constraints&lt;/td&gt;
&lt;td&gt;Template of Exam Questions — Define how the answer looks like&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Prover&lt;/strong&gt; 🧑‍💻&lt;/td&gt;
&lt;td&gt;Generate proof with secret inputs&lt;/td&gt;
&lt;td&gt;Student who solves the exam&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Verifier&lt;/strong&gt; ✅&lt;/td&gt;
&lt;td&gt;Verify validity of proof with public inputs&lt;/td&gt;
&lt;td&gt;Grader who checks the answer without seeing the solution&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Core Concept: &lt;strong&gt;The circuit only defines the rules — it doesn't solve them.&lt;/strong&gt; The prover supplies the secret answer. The verifier checks that the rules were followed without ever seeing that answer.&lt;/p&gt;




&lt;h2&gt;
  
  
  🌍 Real World Flow of ZKP: Who Proves, Who Verifies
&lt;/h2&gt;

&lt;p&gt;Let's see how ZKP is used in the real world:&lt;/p&gt;

&lt;h3&gt;
  
  
  Flow Chart: Outline of Proof and Verification
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌──────────────────────────────────────────────────────────────────────┐
│ 1. Build Circuit (Developer does it once)                            │
│                                                                      │
│ Define constraints with CircuitBuilder → build() → CircuitData       │
│                                                                      │
│ Output:                                                              │
│   ・CircuitData (circuit definition)                                 │
│   ・VerifierCircuitData (verifier key) → made public                 │
└────────────────────────────────┬─────────────────────────────────────┘
                                 │
                  ┌──────────────┴──────────────┐
                  ▼                             ▼
┌───────────────────────────┐   ┌───────────────────────────┐
│ 2. Prove                  │   │ 4. Verify                 │
│                           │   │                           │
│ = The party who holds     │   │ Verifier = Only sees      │
│   the data                │   │ the result                │
│                           │   │                           │
│ ・Has secret inputs       │   │ ・Receives only the proof │
│ ・Sets secrets in         │   │ ・Sees only public inputs │
│   PartialWitness          │   │ ・Knows nothing about     │
│ ・data.prove(pw)          │   │   secret inputs           │
│   generates proof         │   │ ・data.verify(proof)      │
│                           │   │   → Ok / Error            │
└─────────────┬─────────────┘   └─────────────┬─────────────┘
              │                               │
              │  3. Send proof                │
              │  proof + public_inputs        │
              └──────────────►────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Concrete Example: Private Database Update
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌───────────────────┐                    ┌───────────────────┐
│ Prover            │                    │ Verifier          │
│ (Data owner)      │                    │ (Auditor/Contract)│
└────────┬──────────┘                    └────────┬──────────┘
         │                                        │
         │ 1. Update the data                     │
         │    (e.g. change a balance)              │
         │    * This is secret                     │
         │                                        │
         │ 2. Generate ZK proof                   │
         │    prove(secret inputs)                │
         │    → obtain proof                      │
         │                                        │
         │ 3. Send proof ───────────────────────► │
         │    (contains no secret information)     │
         │                                        │
         │                                        │ 4. verify(proof)
         │                                        │    Public inputs only:
         │                                        │    ・old_root → new_root
         │                                        │    ・No idea what changed
         │                                        │    → Ok ✓
         │                                        │
         │                                        │ 5. Update state
         │                                        │    (record new_root)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  👀 Point: What Is Public Or Not
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Information&lt;/th&gt;
&lt;th&gt;Prover knows&lt;/th&gt;
&lt;th&gt;Verifier sees&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;What changed (value, position)&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Merkle path (sibling nodes)&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Old state root (old_root)&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;New state root (new_root)&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Proof&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The verifier only confirms that the state root transition is correct. &lt;strong&gt;It never learns what was updated.&lt;/strong&gt; 🤫&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚙️ Setup: Plonky2 Basic Structure
&lt;/h2&gt;

&lt;p&gt;All Plonky2 circuits starts from same 3 type definitions.&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="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;plonky2&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;field&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;goldilocks_field&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;GoldilocksField&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;plonky2&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;plonk&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;config&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;PoseidonGoldilocksConfig&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;D&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;usize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                    &lt;span class="c1"&gt;// Extension degree (always 2 in Plonky2)&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;F&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;GoldilocksField&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;              &lt;span class="c1"&gt;// Finite field for arithmetic&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;C&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;PoseidonGoldilocksConfig&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;     &lt;span class="c1"&gt;// Hash config (Poseidon over Goldilocks)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And all circuits follows the pattern of the same 3 steps&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Build:   CircuitBuilder → Define constraints → builder.build() → CircuitData
2. Prove:   PartialWitness → Set secret inputs → data.prove(pw) → Proof
3. Verify:  data.verify(proof) → Ok(()) or Error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's make it run! 🚀&lt;/p&gt;




&lt;h2&gt;
  
  
  👋 Example 1: "Hello World" Circuit
&lt;/h2&gt;

&lt;p&gt;This first circuit proves &lt;strong&gt;"I know two numbers that add up to a specific sum"&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Sum is public (Verifier can see it). Two numbers are secret (Verifier can't see them).&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="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;plonky2&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;
    &lt;span class="nn"&gt;field&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="nn"&gt;goldilocks_field&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;GoldilocksField&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nn"&gt;types&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nn"&gt;iop&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="nn"&gt;target&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nn"&gt;witness&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="n"&gt;PartialWitness&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;WitnessWrite&lt;/span&gt;&lt;span class="p"&gt;}},&lt;/span&gt;
    &lt;span class="nn"&gt;plonk&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;
        &lt;span class="nn"&gt;circuit_builder&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;CircuitBuilder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nn"&gt;circuit_data&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="n"&gt;CircuitConfig&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;CircuitData&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="nn"&gt;config&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;PoseidonGoldilocksConfig&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nn"&gt;proof&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;ProofWithPublicInputs&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;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;D&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;usize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;F&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;GoldilocksField&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;C&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;PoseidonGoldilocksConfig&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;SimpleCircuit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CircuitData&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;D&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;      &lt;span class="c1"&gt;// Secret input slot&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;      &lt;span class="c1"&gt;// Secret input slot&lt;/span&gt;
    &lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;    &lt;span class="c1"&gt;// Made public&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;SimpleCircuit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;Self&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;CircuitConfig&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;standard_recursion_config&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;CircuitBuilder&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;D&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Create slots for secret inputs (called "Targets" in Plonky2)&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="nf"&gt;.add_virtual_target&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="nf"&gt;.add_virtual_target&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Define constraint: sum = a + b&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="nf"&gt;.add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Make sum visible to the verifier&lt;/span&gt;
        &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="nf"&gt;.register_public_input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Compile the circuit&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="py"&gt;.build&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;Self&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;prove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ProofWithPublicInputs&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;D&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;pw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;PartialWitness&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;pw&lt;/span&gt;&lt;span class="nf"&gt;.set_target&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nn"&gt;F&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from_canonical_u64&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="n"&gt;pw&lt;/span&gt;&lt;span class="nf"&gt;.set_target&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nn"&gt;F&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from_canonical_u64&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.data&lt;/span&gt;&lt;span class="nf"&gt;.prove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;proof&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ProofWithPublicInputs&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;D&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nn"&gt;anyhow&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.data&lt;/span&gt;&lt;span class="nf"&gt;.verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;proof&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&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;p&gt;&lt;strong&gt;Usage：&lt;/strong&gt;&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="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;circuit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;SimpleCircuit&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Prover: "I know two numbers that add up to 8"&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;proof&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;circuit&lt;/span&gt;&lt;span class="nf"&gt;.prove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Verifier: "Is this proof valid?" (can't see 3 and 5 — only sees 8)&lt;/span&gt;
&lt;span class="nd"&gt;assert_eq!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;proof&lt;/span&gt;&lt;span class="py"&gt;.public_inputs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nn"&gt;F&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from_canonical_u64&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nd"&gt;assert!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;circuit&lt;/span&gt;&lt;span class="nf"&gt;.verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;proof&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.is_ok&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🔍 What Happened?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Build Phase                    Prove Phase                   Verify Phase
┌────────────────┐           ┌────────────────┐          ┌──────────────┐
│ builder.add    │           │ pw.set_target  │          │ data.verify  │
│ (a, b)         │           │ (a=3, b=5)     │          │ (proof)      │
│                │           │                │          │              │
│ Define         │    →      │ Set secret     │    →     │ Verify proof │
│ constraint:    │           │ inputs         │          │              │
│ "sum = a + b"  │           │ → generate     │          │ Visible:     │
│                │           │   proof        │          │  sum=8 only  │
│ * No compute   │           │                │          │              │
│  Rules only    │           │ a=3, b=5 are   │          │ Hidden:      │
│                │           │ NOT in proof   │          │  a=3, b=5    │
└────────────────┘           └────────────────┘          └──────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Build Phase&lt;/strong&gt;: &lt;code&gt;builder.add(a, b)&lt;/code&gt; does &lt;strong&gt;not&lt;/strong&gt; compute &lt;code&gt;a + b&lt;/code&gt;. It creates a &lt;em&gt;constraint&lt;/em&gt; that says "sum must equal a + b". The circuit is a template of rules.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prove Phase&lt;/strong&gt;: When the prover sets &lt;code&gt;a=3, b=5&lt;/code&gt;, Plonky2 generates a cryptographic proof that these values satisfy the constraints.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Verify Phase&lt;/strong&gt;: The verifier checks the proof. It sees &lt;code&gt;sum=8&lt;/code&gt; in the public inputs, but has no way of knowing &lt;code&gt;a=3&lt;/code&gt; or &lt;code&gt;b=5&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Key point&lt;/strong&gt;: A &lt;code&gt;Target&lt;/code&gt; in Plonky2 is not a variable — it's a "wire" in the circuit. &lt;code&gt;builder.add(a, b)&lt;/code&gt; computes nothing. It just connects two inputs to an addition gate.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🔗 Example 2: Hashchain — Proving Ordered Processing
&lt;/h2&gt;

&lt;p&gt;Alright let's create something more practical now. &lt;br&gt;
It proves that the final hash is calculated from the underlying items in the right processing order.&lt;/p&gt;
&lt;h3&gt;
  
  
  Concept
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;state_0 = hash(0)
state_1 = hash(state_0 || item_0)
state_2 = hash(state_1 || item_1)
state_3 = hash(state_2 || item_2)    ← Final hash (public)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Each step feeds the previous hash into the next.&lt;br&gt;
If any item in the chain is modified, the final hash changes.&lt;br&gt;
The prover proves the chain was computed correctly; the verifier only checks the final hash.&lt;/p&gt;
&lt;h3&gt;
  
  
  Proof and Verification Flow
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Prover                                   Verifier
  ──────                                   ────────

  Holds secret items:
  items = [item_0, item_1, item_2]
         ↓
  Set secret inputs in circuit:
  pw.set_target(items[0], item_0)
  pw.set_target(items[1], item_1)
  pw.set_target(items[2], item_2)
         ↓
  Generate proof:
  proof = data.prove(pw)
         ↓
  Send proof ──────────────────────────►  Receive proof
  (items are NOT included in proof)        ↓
                                       Extract final hash from
                                       proof.public_inputs
                                         ↓
                                       data.verify(proof) → Ok ✓
                                         ↓
                                       "Does the final hash match
                                        the expected value?"
                                       ← This is business logic (outside the circuit)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Code
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="k"&gt;crate&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;utils&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;poseidon_hash_out&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;PoseidonHashOutTarget&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;HashChainCircuit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CircuitData&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;D&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Target&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="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;HashChainCircuit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chain_length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;usize&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;Self&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;CircuitConfig&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;standard_recursion_config&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;CircuitBuilder&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;D&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Create a target (slot) for each item in the chain&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Target&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="n"&gt;chain_length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nf"&gt;.map&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="nf"&gt;.add_virtual_target&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
            &lt;span class="nf"&gt;.collect&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Start from hash(0)&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;zero&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="nf"&gt;.zero&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;PoseidonHashOutTarget&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;hash_inputs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;zero&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

        &lt;span class="c1"&gt;// Chain: for each item, state = hash(state || item)&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;inputs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="nf"&gt;.to_vec&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nd"&gt;vec!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;&lt;span class="nf"&gt;.concat&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;PoseidonHashOutTarget&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;hash_inputs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;inputs&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// Only expose the final hash — items stay secret&lt;/span&gt;
        &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="nf"&gt;.register_public_inputs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="nf"&gt;.to_vec&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="py"&gt;.build&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;Self&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;prove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ProofWithPublicInputs&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;D&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;pw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;PartialWitness&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.items&lt;/span&gt;&lt;span class="nf"&gt;.iter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.zip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="nf"&gt;.iter&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;pw&lt;/span&gt;&lt;span class="nf"&gt;.set_target&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nn"&gt;F&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from_canonical_u32&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.data&lt;/span&gt;&lt;span class="nf"&gt;.prove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&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;p&gt;&lt;strong&gt;Usage：&lt;/strong&gt;&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="c1"&gt;// Build a circuit for a chain of length 3&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;circuit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;HashChainCircuit&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Prove: "I processed items [1, 2, 3] in this exact order"&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;proof&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;circuit&lt;/span&gt;&lt;span class="nf"&gt;.prove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="c1"&gt;// Verify: proof is valid and the final hash is in proof.public_inputs&lt;/span&gt;
&lt;span class="nd"&gt;assert!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;circuit&lt;/span&gt;&lt;span class="py"&gt;.data&lt;/span&gt;&lt;span class="nf"&gt;.verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;proof&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.is_ok&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  💡 Why is this useful?
&lt;/h3&gt;

&lt;p&gt;Imagine a database with 10,000 records. &lt;br&gt;
The prover generates a single proof for the entire hash chain. The verifier can confirm that all records were processed correctly by checking just that one proof — no need to recalculate anything.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Usecase Example：&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;📋 &lt;strong&gt;Watch Log&lt;/strong&gt;: Proof that logs are not manipulated&lt;/li&gt;
&lt;li&gt;📦 &lt;strong&gt;Batch Process&lt;/strong&gt;: Proof that bulk transactions are processed in the right order&lt;/li&gt;
&lt;li&gt;🔄 &lt;strong&gt;Data Pipeline&lt;/strong&gt;: Proof that the ETL process is processed correctly. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Circuit is nothing but a calculator — &lt;code&gt;hash(hash(hash(0, item0), item1), item2) = final_hash&lt;/code&gt;.&lt;br&gt;
The &lt;em&gt;verifier&lt;/em&gt; judges whether the final hash matches the expected value.&lt;br&gt;
This separation of concerns — mathematical rules inside the circuit, business logic outside — is the fundamental pattern of ZKP design.&lt;/p&gt;


&lt;h2&gt;
  
  
  🌳 Example 3: State Transition — Proves Merkle Tree Update
&lt;/h2&gt;

&lt;p&gt;Many systems store data in a Merkle tree.&lt;br&gt;
&lt;strong&gt;State Transition Proof&lt;/strong&gt; proves "I updated a leaf of the tree and the value of the root has changed from &lt;code&gt;old_root&lt;/code&gt; to &lt;code&gt;new_root&lt;/code&gt;"&lt;/p&gt;

&lt;p&gt;The verifier only sees the two root values.&lt;br&gt;
Which leaf was changed, and what the old or new value was, is never revealed.&lt;/p&gt;
&lt;h3&gt;
  
  
  Merkle Tree Update Root
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                    Merkle Tree (height=2, 4 leaves)

            Before Update                       After Update
          old_root                            new_root
           /    \                              /    \
         h01     h23                         h01     h23
        /   \   /   \                       /   \   /   \
      [10] [20] [30] [40]               [10] [99] [30] [40]
             ↑                                  ↑
          index=1                            index=1
          old_value=20                       new_value=99


  What the Prover knows          What the Verifier sees
  ────────────────────          ──────────────────────
  ・index = 1                   ・old_root
  ・old_value = 20              ・new_root
  ・new_value = 99              ・proof (cryptographic)
  ・Merkle path (sibling nodes)
  ・old_root, new_root
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Code
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;StateTransitionCircuit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CircuitData&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;D&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;old_leaf&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;new_leaf&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;merkle_proof&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;MerkleProofTarget&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Target&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;old_root&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;PoseidonHashOutTarget&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;new_root&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;PoseidonHashOutTarget&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;StateTransitionCircuit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;usize&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;Self&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;CircuitConfig&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;standard_recursion_config&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;CircuitBuilder&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;D&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;old_leaf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="nf"&gt;.add_virtual_target&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;new_leaf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="nf"&gt;.add_virtual_target&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="nf"&gt;.add_virtual_target&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;merkle_proof&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;MerkleProofTarget&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Target&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;old_root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;PoseidonHashOutTarget&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;new_root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;PoseidonHashOutTarget&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Constraint 1: old_leaf at this index produces old_root&lt;/span&gt;
        &lt;span class="n"&gt;merkle_proof&lt;/span&gt;&lt;span class="py"&gt;.verify&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;D&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;old_leaf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;old_root&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Constraint 2: compute root from new_leaf with same index and siblings → computed_new_root&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;computed_new_root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
            &lt;span class="n"&gt;merkle_proof&lt;/span&gt;&lt;span class="py"&gt;.get_root&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;D&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;new_leaf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Constraint 3: computed root must match the provided new_root&lt;/span&gt;
        &lt;span class="n"&gt;computed_new_root&lt;/span&gt;&lt;span class="nf"&gt;.connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new_root&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Public inputs: only the two roots&lt;/span&gt;
        &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="nf"&gt;.register_public_inputs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;old_root&lt;/span&gt;&lt;span class="nf"&gt;.to_vec&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
        &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="nf"&gt;.register_public_inputs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;new_root&lt;/span&gt;&lt;span class="nf"&gt;.to_vec&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="py"&gt;.build&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;Self&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;old_leaf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new_leaf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;merkle_proof&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;old_root&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new_root&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;p&gt;&lt;strong&gt;The prover sets the witness (secret inputs):&lt;/strong&gt;&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="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;prove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;MerkleTree&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;leaf_index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;old_value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;new_value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ProofWithPublicInputs&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;D&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Get old state&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;proof&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="nf"&gt;.prove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;leaf_index&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;old_root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="nf"&gt;.get_root&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// Update the tree&lt;/span&gt;
    &lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="nf"&gt;.update_leaf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;leaf_index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new_value&lt;/span&gt;&lt;span class="nf"&gt;.hash&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;new_root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="nf"&gt;.get_root&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// Set all secret witnesses&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;pw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;PartialWitness&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;pw&lt;/span&gt;&lt;span class="nf"&gt;.set_target&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.old_leaf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nn"&gt;F&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from_canonical_u32&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;old_value&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="n"&gt;pw&lt;/span&gt;&lt;span class="nf"&gt;.set_target&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.new_leaf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nn"&gt;F&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from_canonical_u32&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;new_value&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="n"&gt;pw&lt;/span&gt;&lt;span class="nf"&gt;.set_target&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nn"&gt;F&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from_canonical_u64&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;leaf_index&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.merkle_proof&lt;/span&gt;&lt;span class="nf"&gt;.set_witness&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;pw&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;proof&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.old_root&lt;/span&gt;&lt;span class="nf"&gt;.set_witness&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;pw&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;old_root&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.new_root&lt;/span&gt;&lt;span class="nf"&gt;.set_witness&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;pw&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new_root&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.data&lt;/span&gt;&lt;span class="nf"&gt;.prove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&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;p&gt;&lt;strong&gt;Usage:&lt;/strong&gt;&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="c1"&gt;// Create a Merkle tree with 4 leaves&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;tree&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;MerkleTree&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// height=2 → 4 leaves&lt;/span&gt;
&lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="nf"&gt;.update_leaf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10u32&lt;/span&gt;&lt;span class="nf"&gt;.hash&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="nf"&gt;.update_leaf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20u32&lt;/span&gt;&lt;span class="nf"&gt;.hash&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="nf"&gt;.update_leaf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30u32&lt;/span&gt;&lt;span class="nf"&gt;.hash&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="nf"&gt;.update_leaf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40u32&lt;/span&gt;&lt;span class="nf"&gt;.hash&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;circuit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;StateTransitionCircuit&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Prove: "I changed leaf 1 from 20 to 99"&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;proof&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;circuit&lt;/span&gt;&lt;span class="nf"&gt;.prove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;99&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Verify: the root transition is correct&lt;/span&gt;
&lt;span class="n"&gt;circuit&lt;/span&gt;&lt;span class="py"&gt;.data&lt;/span&gt;&lt;span class="nf"&gt;.verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;proof&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"should verify"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🤥 Can you deceive?
&lt;/h3&gt;

&lt;p&gt;When a prover tries to cheat — e.g. claiming the old value was 999 when it was actually 20 — the Merkle path won't match the old_root, and proof generation itself fails.&lt;br&gt;
It's impossible to generate a valid proof for a false statement. 🛡️&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="c1"&gt;// Panics — you can't prove a lie&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;panic&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;catch_unwind&lt;/span&gt;&lt;span class="p"&gt;(||&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;circuit&lt;/span&gt;&lt;span class="nf"&gt;.prove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;999&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// 999 ≠ actual value&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nd"&gt;assert!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="nf"&gt;.is_err&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🧱 Overall Picture: How To Combine the Patterns
&lt;/h2&gt;

&lt;p&gt;The three patterns above are useful on their own, but they become truly powerful when combined.&lt;/p&gt;

&lt;h3&gt;
  
  
  Combining the Patterns
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌────────────────────────────────────────────────────────────────┐
│                                                                │
│  Prover (the party who holds the data)                         │
│  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━                         │
│                                                                │
│  Step 1: Prove individual operations                           │
│  ┌──────────────────────────────────────────────────────┐      │
│  │                                                      │      │
│  │  ┌────────────────┐  ┌────────────────┐              │      │
│  │  │ Operation A    │  │ Operation B    │  ...         │      │
│  │  │                │  │                │              │      │
│  │  │ State          │  │ State          │              │      │
│  │  │ Transition     │  │ Transition     │              │      │
│  │  │ (Merkle tree)  │  │ (Merkle tree)  │              │      │
│  │  └───────┬────────┘  └───────┬────────┘              │      │
│  │          │ proof_a           │ proof_b                │      │
│  └──────────┼───────────────────┼───────────────────────┘      │
│             │                   │                               │
│             ▼                   ▼                               │
│  Step 2: Chain the proofs together (hash chain)                │
│  ┌──────────────────────────────────────────────────────┐      │
│  │                                                      │      │
│  │  hash(hash(hash(0, proof_a), proof_b), ...)          │      │
│  │    = final_hash                                      │      │
│  │                                                      │      │
│  └─────────────────────────┬────────────────────────────┘      │
│                             │                                  │
│                     Final proof                                │
│                                                                │
└─────────────────────────────┬──────────────────────────────────┘
                              │
                              │  Send proof
                              ▼
┌────────────────────────────────────────────────────────────────┐
│                                                                │
│  Verifier (auditor / smart contract / server)                  │
│  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━                   │
│                                                                │
│  verify(proof) → Ok ✓                                         │
│                                                                │
│  Visible:  old_root, new_root                                  │
│  Hidden:   individual operations, data values, account details │
│                                                                │
│  * Verifying just one proof cryptographically guarantees       │
│    the correctness of ALL operations                           │
│                                                                │
└────────────────────────────────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Role of Each Pattern
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pattern&lt;/th&gt;
&lt;th&gt;What it proves&lt;/th&gt;
&lt;th&gt;Example use cases&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Hash Chain&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A sequence of data was processed in the correct order&lt;/td&gt;
&lt;td&gt;Audit logs, batch processing, data pipelines&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;State Transition&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A Merkle tree update was performed correctly&lt;/td&gt;
&lt;td&gt;Database updates, balance changes, config changes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;By combining them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prove each individual update with a state transition proof&lt;/li&gt;
&lt;li&gt;Chain those proofs together with a hash chain&lt;/li&gt;
&lt;li&gt;The verifier checks just one final proof to confirm the correctness of everything&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🛠️ Practical Tips
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. 🏎️ Always Build in Release Mode
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cargo &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;--release&lt;/span&gt; test_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Debug mode is orders of magnitude slower. A proof that takes 2 seconds in release can take minutes in debug. 🐢→🐇&lt;/p&gt;

&lt;h3&gt;
  
  
  2. 🔁 The Circuit Pattern Is Always the Same
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;MyCircuit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CircuitData&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;D&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;// Compiled circuit&lt;/span&gt;
    &lt;span class="c1"&gt;// ... targets (wire slots)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;MyCircuit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;Self&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;            &lt;span class="c1"&gt;// Build phase: define constraints&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;CircuitBuilder&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;D&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="c1"&gt;// ... add constraints ...&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="py"&gt;.build&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;C&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="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;prove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;        &lt;span class="c1"&gt;// Prove phase: set witness&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;pw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;PartialWitness&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="c1"&gt;// ... set values on targets ...&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.data&lt;/span&gt;&lt;span class="nf"&gt;.prove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pw&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;h3&gt;
  
  
  3. 🔓🔒 Public vs. Secret Is Decided at Build Time
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// This value stays secret (only the prover knows it)&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;secret&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="nf"&gt;.add_virtual_target&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// This value becomes public (verifier can see it)&lt;/span&gt;
&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="nf"&gt;.register_public_input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// Now it's public&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. ⚠️ Constraints Are Assertions, Not Computations
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// This does NOT compute a + b at build time&lt;/span&gt;
&lt;span class="c1"&gt;// It creates a gate with the constraint: sum = a + b&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="nf"&gt;.add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// At prove time, if the witness values don't satisfy&lt;/span&gt;
&lt;span class="c1"&gt;// the constraint, proof generation fails&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🎬 Wrapping Up
&lt;/h2&gt;

&lt;p&gt;Zero-knowledge proofs aren't magic. They're constraint systems wrapped in clever cryptography. The circuit defines the rules, the prover fills in the secret inputs, and the verifier checks the proof without ever seeing those inputs.&lt;/p&gt;

&lt;p&gt;With Plonky2:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🔗 &lt;strong&gt;Hash Chain&lt;/strong&gt; — prove that data was processed in the correct order&lt;/li&gt;
&lt;li&gt;🌳 &lt;strong&gt;State Transition&lt;/strong&gt; — prove a database update without revealing what changed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The code patterns are consistent and composable. Once you understand &lt;code&gt;CircuitBuilder → PartialWitness → prove → verify&lt;/code&gt;, you can stack simple circuits to build arbitrarily complex proof systems. 🧱✨&lt;/p&gt;




&lt;p&gt;&lt;em&gt;The code in this article uses the &lt;a href="https://github.com/0xPolygonZero/plonky2" rel="noopener noreferrer"&gt;Plonky2&lt;/a&gt; framework — a fast recursive SNARK system built on Poseidon hashing over the Goldilocks field.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>rust</category>
      <category>zkp</category>
      <category>cryptocurrency</category>
      <category>webdev</category>
    </item>
    <item>
      <title>React Best Practices in Cursor</title>
      <dc:creator>Toshiya Matsumoto</dc:creator>
      <pubDate>Sun, 01 Feb 2026 08:29:48 +0000</pubDate>
      <link>https://dev.to/toshiya_matsumoto_ac94abe/react-best-practices-in-cursor-79e</link>
      <guid>https://dev.to/toshiya_matsumoto_ac94abe/react-best-practices-in-cursor-79e</guid>
      <description>&lt;h1&gt;
  
  
  Goal
&lt;/h1&gt;

&lt;p&gt;Use React Best Practices quickly out of the box in Cursor.&lt;br&gt;
While it's been written in many blogs for Claude Code but not for Cursor. &lt;br&gt;
Let's make it work!&lt;/p&gt;
&lt;h1&gt;
  
  
  What is React Best Practices?
&lt;/h1&gt;

&lt;p&gt;10+ years of React and Next.js optimization knowledge collection provided by Vercel. &lt;br&gt;
&lt;a href="https://vercel.com/blog/introducing-react-best-practices" rel="noopener noreferrer"&gt;https://vercel.com/blog/introducing-react-best-practices&lt;/a&gt;&lt;br&gt;
Setting them in the skills or rules in the AI agents, it allows the agents to work by referencing to the documents during processing. &lt;/p&gt;
&lt;h1&gt;
  
  
  Procedure
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Run the following command to install agent-skills under a specific project.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx add-skill vercel-labs/agent-skills
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Select Cursor and follow the instructions. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvpbnyukgag67ljekiavd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvpbnyukgag67ljekiavd.png" alt=" " width="800" height="680"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It installs the files automatically under&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.cursor/skills/react-best-practices/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;however, &lt;strong&gt;Cursor is not able to detect them just out of the box&lt;/strong&gt; because the format in md files is different from what Cursor expects.&lt;/p&gt;

&lt;p&gt;If you go to &lt;br&gt;
&lt;code&gt;Cursor -&amp;gt; Settings... -&amp;gt; Cursor Settings -&amp;gt; Rules,Skills,Subagents&lt;/code&gt;&lt;br&gt;
you should be seeing No Skills are set over there. &lt;/p&gt;

&lt;p&gt;In order for Cursor to read it, you need to convert it with &lt;code&gt;/migrate-to-skills&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;Here is a prompt I used. &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8j0gc63otfvpdv46e5gf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8j0gc63otfvpdv46e5gf.png" alt=" " width="800" height="127"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Conversion command is officially provided by Cursor. &lt;br&gt;
See: &lt;a href="https://cursor.com/docs/context/skills#migrating-rules-and-commands-to-skills" rel="noopener noreferrer"&gt;https://cursor.com/docs/context/skills#migrating-rules-and-commands-to-skills&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Type /migrate-to-skills in Agent chat&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Takeaway
&lt;/h1&gt;

&lt;p&gt;You need to run &lt;code&gt;/migrate-to-skills&lt;/code&gt; for Cursor to read React Best Practices in Cursor.&lt;/p&gt;

</description>
      <category>cursor</category>
      <category>ai</category>
      <category>react</category>
      <category>vercel</category>
    </item>
    <item>
      <title>🚀 Type Safety Across Layers: From Messy DBs to Clean Apps</title>
      <dc:creator>Toshiya Matsumoto</dc:creator>
      <pubDate>Mon, 01 Sep 2025 12:54:28 +0000</pubDate>
      <link>https://dev.to/toshiya_matsumoto_ac94abe/type-safety-across-layers-from-messy-dbs-to-clean-apps-4o23</link>
      <guid>https://dev.to/toshiya_matsumoto_ac94abe/type-safety-across-layers-from-messy-dbs-to-clean-apps-4o23</guid>
      <description>&lt;p&gt;Every developer knows this pain: your database says “nullable is fine,” but your app screams “absolutely not.”&lt;/p&gt;

&lt;p&gt;👉 Example: An event table with a date column. The DB allows &lt;code&gt;null&lt;/code&gt; (because some events don’t have confirmed dates yet).&lt;br&gt;
But in your React UI? Showing an event with date: &lt;code&gt;null&lt;/code&gt; is not only useless — it’s a bug waiting to happen.&lt;/p&gt;

&lt;p&gt;This mismatch creates an annoying gap between your DB schema and your application layer. Ignore it, and you’ll end up patching with type casts that look fine… until runtime crashes say otherwise.&lt;/p&gt;
&lt;h2&gt;
  
  
  ⚠️ The Wrong Way: Casting Your Troubles Away
&lt;/h2&gt;

&lt;p&gt;We’ve all done this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x: unknown = 'hello';
console.log((x as string).length);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sure, TypeScript stops complaining. But you’ve effectively turned off its seatbelt.&lt;br&gt;
Type assertions bypass safety checks, leaving you with runtime landmines — the exact opposite of why you chose TypeScript in the first place.&lt;/p&gt;
&lt;h2&gt;
  
  
  ✅ The Right Way: Type Guards
&lt;/h2&gt;

&lt;p&gt;Enter &lt;strong&gt;Type Guards&lt;/strong&gt; — TypeScript’s built-in way to narrow types safely.&lt;/p&gt;

&lt;p&gt;Your DB or API DTO might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// event.dto.ts
type EventDto = {
  name: string;
  date: Date | null;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But your app layer needs stricter guarantees:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// event.ts
type Event = {
  name: string;
  date: Date;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s how you bridge that gap:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function hasDate(event: EventDto): event is Event {
  return event.date !== null;
}

export function filterValidEvents(events: EventDto[]): Event[] {
  return events.filter(hasDate); &amp;lt;== here you go.
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, your UI only ever sees events with valid dates. TypeScript enforces the rule, no assertions required.&lt;/p&gt;

&lt;h2&gt;
  
  
  🎁 Why This Pattern Wins
&lt;/h2&gt;

&lt;p&gt;Type Safety: no unsafe casts, no silent failures.&lt;/p&gt;

&lt;p&gt;Separation of Concerns: DBs stay flexible; apps stay strict.&lt;/p&gt;

&lt;p&gt;Scalable: extendable to any nullable fields or DTOs.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧩 Takeaway
&lt;/h2&gt;

&lt;p&gt;Nullable data is inevitable when dealing with databases or APIs.&lt;br&gt;
But instead of brute-forcing types, let Type Guards do the heavy lifting.&lt;/p&gt;

&lt;p&gt;They let you:&lt;/p&gt;

&lt;p&gt;Accept messy, real-world data from your DB.&lt;/p&gt;

&lt;p&gt;Hand your app layer clean, reliable objects.&lt;/p&gt;

&lt;p&gt;Keep TypeScript as your safety net, not your afterthought.&lt;/p&gt;

&lt;p&gt;👉 Next time you hit the null wall, don’t cast — guard.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>🎙️ Building Your Own Live Audio Waveform in React Native</title>
      <dc:creator>Toshiya Matsumoto</dc:creator>
      <pubDate>Sun, 31 Aug 2025 09:46:11 +0000</pubDate>
      <link>https://dev.to/toshiya_matsumoto_ac94abe/building-your-own-live-audio-waveform-in-react-native-4e49</link>
      <guid>https://dev.to/toshiya_matsumoto_ac94abe/building-your-own-live-audio-waveform-in-react-native-4e49</guid>
      <description>&lt;h2&gt;
  
  
  🚀 Motivation
&lt;/h2&gt;

&lt;p&gt;There aren’t many (if any!) well-known libraries out there for live audio recording data visualization with a waveform in React Native. So… why not just build one yourself? 😉&lt;/p&gt;

&lt;h2&gt;
  
  
  🎬 Demo
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F938yepunba048103nlr8.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F938yepunba048103nlr8.gif" alt="Animated GIF showing a loading spinner with bouncing dots" width="720" height="1536"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pretty neat, right? Let’s dive in.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚙️ Assumptions
&lt;/h2&gt;

&lt;p&gt;Here’s the setup I used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`react-native`: 0.79.5
`expo`: 53.0.17
`expo-av`: 15.1.7
`react-native-svg`: 15.12.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Run it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx expo run:ios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🎤 1. Recording Process
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1-1: Enable Metering
&lt;/h3&gt;

&lt;p&gt;The magic trick 🪄 is setting &lt;code&gt;isMeteringEnabled: true&lt;/code&gt; in &lt;code&gt;recording.prepareToRecordAsync()&lt;/code&gt; from &lt;code&gt;expo-av&lt;/code&gt;. This unlocks audio-level metering data (like dB values).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Audio, InterruptionModeIOS } from 'expo-av';

const { granted, status } = await Audio.requestPermissionsAsync();
await Audio.setAudioModeAsync({
  allowsRecordingIOS: true,
  playsInSilentModeIOS: true,
  staysActiveInBackground: true,
  interruptionModeIOS: InterruptionModeIOS.DuckOthers,
});

// Adjust as you like 🎛️
const recordingOptions = {
  android: {
    extension: '.m4a',
    outputFormat: Audio.AndroidOutputFormat.MPEG_4,
    audioEncoder: Audio.AndroidAudioEncoder.AAC,
    sampleRate: 44100,
    numberOfChannels: 2,
    bitRate: 128000,
  },
  ios: {
    extension: '.m4a',
    outputFormat: Audio.IOSOutputFormat.MPEG4AAC,
    audioQuality: Audio.IOSAudioQuality.HIGH,
    sampleRate: 44100,
    numberOfChannels: 2,
    bitRate: 128000,
    linearPCMBitDepth: 16,
    linearPCMIsBigEndian: false,
    linearPCMIsFloat: false,
  },
  web: {
    mimeType: 'audio/webm;codecs=opus',
    bitsPerSecond: 128000,
  },
};

const recording = new Audio.Recording();
await recording.prepareToRecordAsync({
  ...recordingOptions,
  isMeteringEnabled: true, // 🎯 enables audio-level metering
});
await recording.startAsync();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  1-2: Poll the Recording State
&lt;/h3&gt;

&lt;p&gt;Now let’s grab that juicy data 📊. Use the recording object and poll its status every 100ms.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// poll metering data every 100ms
const interval = setInterval(async () =&amp;gt; {
  if (recording) {
    const status = await recording.getStatusAsync();
    if (status.isRecording &amp;amp;&amp;amp; typeof status.metering === 'number') {
      setLevels((prev) =&amp;gt; {
        const newLevels = [...prev, status.metering];
        // keep last 100 samples 🪣
        return newLevels.slice(-100);
      });
    }
  }
}, 100);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example of &lt;code&gt;status&lt;/code&gt;:&lt;br&gt;
&lt;code&gt;{"canRecord": true, "durationMillis": 602, "isRecording": true, "mediaServicesDidReset": false, "metering": -48.3475341796875}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The metering value is what you care about 🎧.&lt;/p&gt;

&lt;p&gt;👉 Decibel scale basics:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0 dB   → loudest possible (max recording level) 🔊  
-160 dB → silence 🤫
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I only keep the latest 100 values (slice(-100)) because… who wants a million bars on screen? 🙃&lt;/p&gt;

&lt;p&gt;Time to visualize! 🎨&lt;/p&gt;

&lt;p&gt;Okay let's visualise it.&lt;/p&gt;

&lt;h2&gt;
  
  
  📊 2. Waveform Visualization with SVG
&lt;/h2&gt;

&lt;p&gt;You don’t need to be a math wizard 🧙 to draw waveforms. Just rectangles on a grid!&lt;/p&gt;

&lt;h3&gt;
  
  
  How it works:
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;1&lt;/code&gt;. Draw a rectangle for each audio sample 📦.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Height = based on audio volume.&lt;/li&gt;
&lt;li&gt;Width = fixed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;2&lt;/code&gt;. Place it at the correct (x, y) coordinate.&lt;/p&gt;

&lt;p&gt;Visual guide (yes, it’s really this simple 👇):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1qcstpvuxeq1u4q8skwt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1qcstpvuxeq1u4q8skwt.png" alt="Waveform formula illustration on SVG" width="711" height="711"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Converting dB → amplitude&lt;/strong&gt;&lt;br&gt;
Formula:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Math.pow(10, db / 20); // standard dB → amplitude
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For easier handling, add +40 before conversion:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Original level: -60dB（almost silence）
Math.pow(10, (-60 + 40) / 20) = Math.pow(10, -1) = 0.1

// Original level: -20dB（small sound volume）
Math.pow(10, (-20 + 40) / 20) = Math.pow(10, 1) = 10

// Original level: 0dB（maximum sound volume）
Math.pow(10, (0 + 40) / 20) = Math.pow(10, 2) = 100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then scale it with &lt;code&gt;normalizedLevel * height * 0.05&lt;/code&gt;.&lt;br&gt;
(That &lt;code&gt;0.05&lt;/code&gt; is just a tweak factor — adjust to taste! 🎚️)&lt;/p&gt;

&lt;p&gt;And yes, we’ll use &lt;code&gt;Rect&lt;/code&gt; from &lt;code&gt;react-native-svg&lt;/code&gt; to draw the bars.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Codes&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Convert levels to SVG bars
  const width = 358;
  const height = 280;
  const barWidth = 3;
  const barSpacing = 1;
  const maxBarsCount = Math.floor(width / (barWidth + barSpacing));
  const halfHeight = height / 2;

  // Create vertical bars for each level
  const bars = levels.slice(-maxBarsCount).map((level, index) =&amp;gt; {
    const normalizedLevel = Math.max(0, Math.pow(10, (level + 40) / 20));
    const barHeight = Math.max(1, normalizedLevel * height * 0.05);

    // Calculate position so bar extends equally above and below center
    const halfBarHeight = barHeight / 2;

    const startX = 0;
    const x = startX + index * (barWidth + barSpacing);
    const y = halfHeight - halfBarHeight;

    return (
      &amp;lt;Rect
        key={index}
        x={x}
        y={y}
        width={barWidth}
        height={barHeight}
        fill="#8E8E93"
        rx={1}
      /&amp;gt;
    );
  });

  return (
    &amp;lt;View className="bg-white p-2 flex-1"&amp;gt;
      &amp;lt;Svg height={height} width={width}&amp;gt;
        {bars}
      &amp;lt;/Svg&amp;gt;
    &amp;lt;/View&amp;gt;
  );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;(&lt;code&gt;levels.slice(-maxBarsCount)&lt;/code&gt;, &lt;code&gt;maxBarsCount&lt;/code&gt; removes the stale bars that overflows in the screen)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  ✅ Summary
&lt;/h2&gt;

&lt;p&gt;With just &lt;code&gt;expo-av&lt;/code&gt; + a little SVG magic 🪄, you can visualize live audio waveforms in React Native — no external libraries needed, no hassle.&lt;/p&gt;

&lt;p&gt;Next time you record 🎤, make it look cool too.&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>mobile</category>
      <category>ios</category>
      <category>webdev</category>
    </item>
    <item>
      <title>🧼 Type-Safe Filtering in TypeScript: Handling Nullable Fields from Your Database</title>
      <dc:creator>Toshiya Matsumoto</dc:creator>
      <pubDate>Fri, 30 May 2025 14:09:34 +0000</pubDate>
      <link>https://dev.to/toshiya_matsumoto_ac94abe/type-safe-filtering-in-typescript-handling-nullable-fields-from-your-database-22lo</link>
      <guid>https://dev.to/toshiya_matsumoto_ac94abe/type-safe-filtering-in-typescript-handling-nullable-fields-from-your-database-22lo</guid>
      <description>&lt;h2&gt;
  
  
  🌟 The Challenge: Bridging Type Safety Between DB and App Layers
&lt;/h2&gt;

&lt;p&gt;In many real-world applications, the database schema often permits &lt;code&gt;null&lt;/code&gt; values — for good reason. For instance, a &lt;code&gt;date&lt;/code&gt; field in an event table might be intentionally left blank if the event date hasn’t been finalized yet.&lt;/p&gt;

&lt;p&gt;However, your application layer — especially the part that renders UI — usually prefers clean, reliable data. If a date is &lt;code&gt;null&lt;/code&gt;, you probably don’t want to show that event in the UI at all.&lt;/p&gt;

&lt;p&gt;This creates a gap between what your &lt;strong&gt;database allows&lt;/strong&gt; and what your &lt;strong&gt;application expects&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You might be tempted to solve this quickly with a forced type cast like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;unknown&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="kd"&gt;as &lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;But&lt;/span&gt; &lt;span class="nx"&gt;relying&lt;/span&gt; &lt;span class="nx"&gt;on&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;assertions&lt;/span&gt; &lt;span class="nx"&gt;skips&lt;/span&gt; &lt;span class="nx"&gt;safety&lt;/span&gt; &lt;span class="nx"&gt;checks&lt;/span&gt; &lt;span class="nx"&gt;and&lt;/span&gt; &lt;span class="nx"&gt;can&lt;/span&gt; &lt;span class="nx"&gt;lead&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;runtime&lt;/span&gt; &lt;span class="nx"&gt;bugs&lt;/span&gt; &lt;span class="err"&gt;—&lt;/span&gt; &lt;span class="nx"&gt;exactly&lt;/span&gt; &lt;span class="nx"&gt;what&lt;/span&gt; &lt;span class="nx"&gt;TypeScript&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;meant&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;help&lt;/span&gt; &lt;span class="nx"&gt;you&lt;/span&gt; &lt;span class="nx"&gt;avoid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🎯 The Solution: Using Type Guards
&lt;/h2&gt;

&lt;p&gt;Instead of casting, a safer and cleaner solution is to use &lt;strong&gt;Type Guards&lt;/strong&gt; — a TypeScript feature that allows you to narrow types in a type-safe way.&lt;/p&gt;

&lt;p&gt;Let’s say your application pulls in event data like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// event.dto.ts - from database or external API&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;EventDto&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&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;p&gt;But your UI layer expects all events to have a valid &lt;code&gt;date&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// event.ts - for use within the app&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Event&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Date&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;p&gt;To filter out incomplete events, define a custom type guard:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;hasDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;EventDto&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;Event&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&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;p&gt;Then you can filter safely and TypeScript will infer the correct type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;filterValidEvents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;events&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;EventDto&lt;/span&gt;&lt;span class="p"&gt;[]):&lt;/span&gt; &lt;span class="nx"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;hasDate&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;p&gt;Now your UI layer will only receive events that have confirmed dates — and TypeScript will enforce this guarantee for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  ✅ Benefits
&lt;/h2&gt;

&lt;p&gt;Type safety without unnecessary assertions.&lt;/p&gt;

&lt;p&gt;Separation of concerns: the DB layer can remain flexible, while the app layer stays strict.&lt;/p&gt;

&lt;p&gt;Scalability: you can extend this pattern to other nullable fields and DTOs.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧠 Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Dealing with partial or nullable data from external sources is inevitable. But with TypeScript’s type guards, you don’t have to compromise safety or clarity. &lt;br&gt;
Embrace the gap between layers — and bridge it elegantly.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>backend</category>
    </item>
    <item>
      <title>🚀 Seamless Data Magic: From Notion to Database with MCP Server &amp; AI Agents</title>
      <dc:creator>Toshiya Matsumoto</dc:creator>
      <pubDate>Sat, 17 May 2025 02:04:14 +0000</pubDate>
      <link>https://dev.to/toshiya_matsumoto_ac94abe/seamless-data-magic-from-notion-to-database-with-mcp-server-ai-agents-3kp7</link>
      <guid>https://dev.to/toshiya_matsumoto_ac94abe/seamless-data-magic-from-notion-to-database-with-mcp-server-ai-agents-3kp7</guid>
      <description>&lt;h2&gt;
  
  
  🎯 The Goal
&lt;/h2&gt;

&lt;p&gt;Build a seamless bridge between non-engineering contributors managing data in Notion and engineers who need that data formatted for database insertion. &lt;/p&gt;

&lt;h2&gt;
  
  
  🌟 The Challenge
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Values like "Japan" or "Tokyo" don't match the foreign keys in different tables.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🛠 Tech Stack Overview
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Notion&lt;/strong&gt;: Used as the collaborative data entry platform for non-engineers.&lt;br&gt;
&lt;strong&gt;MCP Server&lt;/strong&gt;: Bridges Notion and external tools, enabling structured data retrieval via API.&lt;br&gt;
&lt;strong&gt;Cursor Agent&lt;/strong&gt;: An AI-powered agent that automates data transformation, semantic inference, and prompt execution.&lt;br&gt;
&lt;strong&gt;TypeScript&lt;/strong&gt;: Ensures type safety and robust data handling throughout the automation scripts.&lt;/p&gt;
&lt;h2&gt;
  
  
  🌟 The Solution
&lt;/h2&gt;

&lt;p&gt;🚀 &lt;strong&gt;Let's ask Cursor Agent to infer the semantic data to be the foreign keys in one prompt!&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  🔗 Step 1: Integrate Notion MCP Server to Retrieve Structured Event Data
&lt;/h3&gt;

&lt;p&gt;Non-engineers created and updated event entries directly in Notion—no devs required.&lt;/p&gt;

&lt;p&gt;To extract and structure that data:&lt;br&gt;
✅ I used the Notion MCP Server via Cursor Agent.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// .cursor/mcp.json
{
  "mcpServers": {
    "notionApi": {
      "command": "npx",
      "args": [
        "-y",
        "@notionhq/notion-mcp-server"
      ],
      "env": {
        "OPENAPI_MCP_HEADERS": "{\"Authorization\": \"Bearer {YOUR_NOTION_API_KEY}\", \"Notion-Version\": \"2022-06-28\" }"
      }
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allows you to retrieve structured data from Notion in AI Agent's context.&lt;/p&gt;

&lt;h3&gt;
  
  
  🧠 Step 2: Let Cursor Agent to Infer Semantic Foreign Keys
&lt;/h3&gt;

&lt;p&gt;Ask AI Agent to fetch the master data from the API with curl command in prior, and to infer the semantic foreign keys in each row.&lt;/p&gt;

&lt;p&gt;The data in Notion&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// countries table
-----------------
| id | name     |
-----------------
| 1  | Japan    |
| 2  | USA      |
| 3  | Germany  |
-----------------
// events table
-----------------------------------------------
| id | name         | location   | country_id |
-----------------------------------------------
| 1  | Tech Expo    | Tokyo, JPN | null       |
| 2  | Art Summit   | LA, USA    | null       |
| 3  | Music Fest   | Berlin, DE | null       |
-----------------------------------------------

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

&lt;/div&gt;



&lt;p&gt;Asking the Agent to infer the &lt;code&gt;country_id&lt;/code&gt; in each row from the semantic &lt;code&gt;location&lt;/code&gt; names to match the foreign keys from data you already fetched via API.&lt;/p&gt;

&lt;p&gt;Ultimately the data should look like this in the Agent's context 👏&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-----------------------------------------------
| id | name         | location   | country_id |
-----------------------------------------------
| 1  | Tech Expo    | Tokyo, JPN | 1          |
| 2  | Art Summit   | LA, USA    | 2          |
| 3  | Music Fest   | Berlin, DE | 3          |
-----------------------------------------------
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🧠 Step 3: Ask Agent to convert the data to the payload for the events table
&lt;/h3&gt;

&lt;p&gt;Finally Ask the Agent to convert the data to the payload for the events table following the schema defined in the &lt;code&gt;schema.json&lt;/code&gt; file you put.&lt;/p&gt;

&lt;p&gt;Voila, you can now get the payload ready to be inserted into the events table!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// ./output/events.json
{
  "name": "Tech Expo",
  "location": "Tokyo, JPN",
  "country_id": 1
},
{
  "name": "Art Summit",
  "location": "LA, USA",
  "country_id": 2
},
{
  "name": "Music Fest", 
  "location": "Berlin, DE",
  "country_id": 3
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Prompt I used
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// /prompt/create-events.md
### Prompt Instructions

## For Events

- Retrieve the rows in the Events DB, sorted by ascending startDateTime in Notion via notionGeodeworkApi in MCP settings.
- Generate the payload for the events table according to the schema defined in @schema.ts.
- Use the following API to fetch country data:

  API Endpoint: {NEXT_PUBLIC_SUPABASE_URL}/rest/v1/countries
  API Key: {NEXT_PUBLIC_SUPABASE_ANON_KEY}

  Sample curl:
  curl -H "apikey: &amp;lt;API_KEY&amp;gt;" "&amp;lt;API_ENDPOINT&amp;gt;"

- Replace the `country_id` in each row with the foreign key from the country table.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I stored the prompt in the &lt;code&gt;prompt/create-events.md&lt;/code&gt; file so that everybody can use and reproduce the process easily.&lt;/p&gt;

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

&lt;p&gt;Successfully extracted the structured data from Notion and converted it to the payload for the events table with the help of AI Agent.&lt;/p&gt;

&lt;p&gt;I actually integragted the process to insert the data with &lt;code&gt;drizzle-kit&lt;/code&gt; and &lt;code&gt;supabase&lt;/code&gt; all in one go, but I'll write about it in another blog post!&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>cursor</category>
      <category>notion</category>
      <category>sql</category>
    </item>
    <item>
      <title>Github Actions with Vercel in 2024</title>
      <dc:creator>Toshiya Matsumoto</dc:creator>
      <pubDate>Mon, 13 Jan 2025 14:07:05 +0000</pubDate>
      <link>https://dev.to/toshiya_matsumoto_ac94abe/github-actions-with-vercel-in-2024-3222</link>
      <guid>https://dev.to/toshiya_matsumoto_ac94abe/github-actions-with-vercel-in-2024-3222</guid>
      <description>&lt;p&gt;When you already have the app working on Vercel but you want to integrate Github Actions on top of it. Here's the right place to check.&lt;/p&gt;

&lt;h3&gt;
  
  
  Vercel
&lt;/h3&gt;

&lt;p&gt;You need the following data from Vercel dashboard. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ORG_ID&lt;/code&gt;
Go to the &lt;strong&gt;top page&lt;/strong&gt; &amp;gt; Settings &amp;gt; Team ID.
Note that it's not under individual project page. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The URL you visit is like this&lt;code&gt;https://vercel.com/{your_account_name}s-projects/~/settings&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;PROJECT_ID&lt;/code&gt;&lt;br&gt;
Go to &lt;strong&gt;project page&lt;/strong&gt; &amp;gt; Settings &amp;gt; Team ID &amp;gt; Project ID&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;VERCEL_TOKEN&lt;/code&gt;&lt;br&gt;
Go to &lt;strong&gt;project page&lt;/strong&gt; &amp;gt; Settings &amp;gt; Environment Variables&lt;br&gt;
Enter VERCEL_TOKEN as a key and the arbitrary value.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Github
&lt;/h3&gt;

&lt;p&gt;Go to the Github project page &amp;gt; Settings &amp;gt; Secrets and variables &amp;gt; Actions &amp;gt; Repository secrets &amp;gt; New repository secret&lt;/p&gt;

&lt;p&gt;and set the ones you copied from the Vercel above and others that are needed respectively such as dotenv values depending on your implementation. &lt;/p&gt;

&lt;h3&gt;
  
  
  Code
&lt;/h3&gt;

&lt;p&gt;Create .github/workflows/workflow.yml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: Github Auto Deploy

on:
  push:
    branches:
      - main

env:
  VERCEL_ORG_ID: ${{ secrets.ORG_ID }}
  VERCEL_PROJECT_ID: ${{ secrets.PROJECT_ID }}

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup Bun Runtime
        uses: oven-sh/setup-bun@v1
        with:
          bun-version: latest

      - name: Install Dependencies
        run: bun install

      - name: Run Unit Tests
        run: bun unit:test

      - name: Install Playwright Browsers
        run: bunx playwright install --with-deps

      - name: Run E2E Tests
        run: bunx playwright test
        env:
          CI: true
          NODE_ENV: test
          CTF_MGMT_API_ACCESS_TOKEN: ${{ secrets.CTF_MGMT_API_ACCESS_TOKEN }}
          CTF_SPACE_ID: ${{ secrets.CTF_SPACE_ID }}
          CTF_CDA_ACCESS_TOKEN: ${{ secrets.CTF_CDA_ACCESS_TOKEN }}

      - name: Install Vercel CLI
        run: bun install -g vercel@latest

      - name: Pull Vercel Environment Information
        run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}

      - name: Build Project Artifacts
        run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}

      - name: Deploy Project Artifacts to Vercel
        run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}

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

&lt;/div&gt;



</description>
      <category>githubactions</category>
      <category>vercel</category>
      <category>bunjs</category>
      <category>nextjs</category>
    </item>
    <item>
      <title>Page can't be indexed in Google Search Console</title>
      <dc:creator>Toshiya Matsumoto</dc:creator>
      <pubDate>Thu, 09 Jan 2025 14:59:03 +0000</pubDate>
      <link>https://dev.to/toshiya_matsumoto_ac94abe/page-cant-be-indexed-in-google-search-console-ghm</link>
      <guid>https://dev.to/toshiya_matsumoto_ac94abe/page-cant-be-indexed-in-google-search-console-ghm</guid>
      <description>&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;My personal website pages built with NextJs v14.x.x hosted by Vercel were not indexed at all for ages somewhere down the line ... very shocking...&lt;/p&gt;

&lt;h2&gt;
  
  
  Details in Google Search Console
&lt;/h2&gt;

&lt;p&gt;When you visit Sitemap page, it says &lt;code&gt;Couldn't fetch&lt;/code&gt;.&lt;br&gt;
When I visited URL Inspection page, it says &lt;code&gt;Site-wide availability issues&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Investigating Process
&lt;/h2&gt;

&lt;p&gt;However I could see the content &lt;code&gt;https:mypage/sitemap.xml&lt;/code&gt; on browser.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;curl -I https:mypage/sitemap.xml&lt;/code&gt; shows 200 response status properly.&lt;/p&gt;

&lt;p&gt;Then I checked more details in &lt;code&gt;Site-wide availability issues&lt;/code&gt; on    &lt;a href="https://support.google.com/webmasters/answer/9012289#will_i_be_indexed&amp;amp;zippy=%2Csite-wide-availability-issues" rel="noopener noreferrer"&gt;https://support.google.com/webmasters/answer/9012289#will_i_be_indexed&amp;amp;zippy=%2Csite-wide-availability-issues&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and then found this one:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Robots.txt unreachable: Google won't crawl a website if the robots.txt file is present but not reachable. You can check your robots.txt availability in the Crawl Stats report.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then I realised that&lt;code&gt;https:mypage/robots.txt&lt;/code&gt; returns 500 status despite the fact that I didn't prepare the robots.txt in my NextJS directory. &lt;/p&gt;

&lt;p&gt;Running production mode in NextJS hides the error details while dev mode shows you the details. &lt;/p&gt;

&lt;p&gt;Voila, my poor error handling returns &lt;code&gt;500&lt;/code&gt; status even though /robots.txt does not exist which in turn confused Google Indexer  and put it the label of &lt;code&gt;Not Indexable Page&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;The case is closed. &lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>vercel</category>
      <category>seo</category>
      <category>google</category>
    </item>
  </channel>
</rss>
