<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by MoZi on Medium]]></title>
        <description><![CDATA[Stories by MoZi on Medium]]></description>
        <link>https://medium.com/@0xmozi.v3?source=rss-9666a9383250------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Ds1WeVsQg-Uh_JFd</url>
            <title>Stories by MoZi on Medium</title>
            <link>https://medium.com/@0xmozi.v3?source=rss-9666a9383250------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:17:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@0xmozi.v3/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Learning STARK From Zero #1: What Is a Trace, and Why Fibonacci?]]></title>
            <link>https://medium.com/@0xmozi.v3/learning-stark-from-zero-1-what-is-a-trace-and-why-fibonacci-4b2554abb5c0?source=rss-9666a9383250------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b2554abb5c0</guid>
            <category><![CDATA[stark]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[cryptography]]></category>
            <dc:creator><![CDATA[MoZi]]></dc:creator>
            <pubDate>Tue, 04 Aug 2026 08:35:14 GMT</pubDate>
            <atom:updated>2026-08-04T08:35:14.453Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Personal study blog</em> <em>— a deep dive into the </em><a href="https://github.com/microbecode/stark-from-zero"><em>stark-from-zero</em></a><em> repo by </em><a href="https://github.com/microbecode">Lauri Peltonen</a><em>, an educational STARK implementation in Rust.</em></p><p><strong>The Problems STARK Aims to Solve</strong></p><p>Imagine someone performing a heavy computational task — millions of steps — and then telling me, “The result is X”. How can I trust what they said was true, without verifying it by repeating the entire computation by myself?</p><p>STARK (<strong>S</strong>calable <strong>T</strong>ransparent <strong>AR</strong>gument of <strong>K</strong>nowledge) is a cryptographic technique designed to address this problem: the prover generates a brief proof that the computation was performed correctly, and the verifier can check it much faster than it would take to repeat the computation.</p><blockquote>Note: You might often hear the term “zk-STARK.” However, in this blog series, I will only use “STARK.” The stark-from-zero repo focuses purely on computational integrity (Scalable &amp; Transparent) and intentionally leaves out the Zero-Knowledge (privacy) component to keep the code’s logic simple and easy to learn from scratch.</blockquote><p>To prove this, the computation must be recorded step by step — not just the final result. That record is called a trace, and the verifier only needs to select a few random samples from the record. The more samples that are verified, the smaller the chance that the prover will lie.</p><p>This repo uses Fibonacci as an example, not because Fibonacci is particularly important, but because it’s the simplest example of a <em>“transition rule between steps”</em> F(n) = F(n-1) + F(n-2) — enough to illustrate the core concept of STARK without the complexity of other domains.</p><p><strong>How a trace is built: </strong><a href="https://github.com/microbecode/stark-from-zero/blob/d4f211fe2d94e4854647a5918de05ca34fee23ec/src/trace.rs#L81-#L107">Trace::from_computation</a></p><p>Core structure:</p><pre>    pub fn from_computation&lt;F&gt;(num_steps: usize, num_vars: usize, mut compute: F) -&gt; Self<br>    where<br>        F: FnMut(usize, &amp;[i128]) -&gt; Vec&lt;i128&gt;,<br>    {<br>        let mut trace: Vec&lt;Vec&lt;i128&gt;&gt; = Vec::with_capacity(num_steps);<br><br>        for step in 0..num_steps {<br>            let prev_state = if step == 0 {<br>                vec![0; num_vars] // Initial state<br>            } else {<br>                trace[step - 1].clone()<br>            };<br><br>            let new_state = compute(step, &amp;prev_state);<br>            if new_state.len() != num_vars {<br>                panic!(<br>                    &quot;Computation function returned {} values, expected {}&quot;,<br>                    new_state.len(),<br>                    num_vars<br>                );<br>            }<br><br>            trace.push(new_state);<br>        }<br><br>        Trace::new(trace)<br>    }</pre><p>This is a generic function: it knows nothing about Fibonacci. The specific logic is passed through the `compute` closure. The basic pattern is:</p><pre>state(0) = initial<br>state(n) = compute(n, state(n-1))</pre><p><strong>Why 3 columns, not 1?</strong></p><p>The Fibonacci trace in this repo consists of 3 columns per row — [F(n-2), F(n-1), F(n)] — rather than 1 column like STARK101 Tutorial.</p><p>The reason has to do with Merkle proofs. This system hashes an entire row into a single Merkle tree leaf. If the trace were 1 column, to verify the rule F(n) = F(n-1) + F(n-2), the verifier would have to request a <strong>Batched Merkle proof to open multiple neighboring leaves</strong> (across three different rows) and check their consistency. If the trace is 3 columns (sliding window), a single row already contains all three required values — the verifier only needs to open one Merkle proof per verification.</p><p>The trade-off: the trace becomes more expensive (the same values are stored repeatedly across multiple rows) in order to simplify verification. This is good for educational repositories — the code is relatively easier to understand.</p><p><strong>Dry run</strong></p><p>for <a href="https://github.com/microbecode/stark-from-zero/blob/d4f211fe2d94e4854647a5918de05ca34fee23ec/src/trace.rs#L116-#L132">fibonacci::generate_fibonacci_trace(5, 1, 1)</a>:</p><pre>| step | prev_state        | new_state |<br>|------|-------------------|-----------|<br>|  0   | [0,0,0] (default) | [0,1,1]   |<br>|------|-------------------|-----------|<br>|  1   | [0,1,1]           | [1,1,1]   |<br>|------|-------------------|-----------|<br>|  2   | [1,1,1]           | [1,1,2]   |<br>|------|-------------------|-----------|<br>|  3   | [1,1,2]           | [1,2,3]   |<br>|------|-------------------|-----------|<br>|  4   | [1,2,3]           | [2,3,5]   |</pre><p>The general pattern is: take all elements from <strong><em>prev_state </em></strong>except the one at index 0, then append the new value to the end. For Fibonacci, you only need the last 2 terms (num_vars=3), but if the equation requires more history (e.g., Tribonacci, which sums the last 3 terms), the indexing pattern remains the same — only <strong><em>num_vars </em></strong>and the number of terms being summed change.</p><p><strong>Limitations I found: parameter b is not used</strong></p><pre>pub fn generate_fibonacci_trace(num_steps: usize, a: i128, _b: i128) -&gt; Trace {<br>    ...<br>    } else if step == 1 {<br>        vec![a, a, a]   // &lt;- b Never been used!<br>    }<br>    ...<br>}</pre><p>I verified this with a test: <strong>generate_fibonacci_trace(5, 1, 1)</strong> and <strong>generate_fibonacci_trace(5, 1, 99999)</strong> produce identical traces. As a result, this function is limited to generating sequences where F(0) = F(1) = a — it cannot generate other Fibonacci-like sequences such as the Lucas sequence (2, 1, 3, 4, 7, …), which requires two different seeds.</p><p>I think this is intentional, though i haven’t explored the <strong>prover.rs </strong>section yet, so I can’t say for sure why the `b` parameter in the `generate_fibonacci_trace` function isn’t being used.</p><p><strong>A fix I implemented and tested myself:</strong></p><pre>    pub fn generate_fibonacci_trace(num_steps: usize, a: i128, b: i128) -&gt; Trace {<br>        Trace::from_computation(num_steps, 3, move |step, prev_state| {<br>            if step == 0 {<br>                vec![0, 0, a]<br>            } else if step == 1 {<br>                vec![0, a, b]<br>            } else {<br>                let f_n_minus_2 = prev_state[1];<br>                let f_n_minus_1 = prev_state[2];<br>                let f_n = f_n_minus_1 + f_n_minus_2;<br>                vec![f_n_minus_2, f_n_minus_1, f_n]<br>            }<br>        })<br>    }</pre><pre>    #[test]<br>    fn test_generate_fibonacci_trace() {<br>        let trace = fibonacci::generate_fibonacci_trace(5, 2, 1);<br><br>        // trace = []<br>        //<br>        // iter 1: i = 0<br>        //<br>        //  step = 0<br>        //  prev_state = [0,0,0]<br>        //  compute(0, [0,0,0])<br>        //<br>        //  new_state = [0,0,2]<br>        //<br>        //  trace = [ [0,0,2] ]<br>        //<br>        // iter 2: i = 1<br>        //<br>        //  step = 1<br>        //  prev_state = [0,0,2]<br>        //  compute(1, [0,0,2])<br>        //<br>        //  new_state = [0, 2, 1]<br>        //<br>        //  trace = [ [0,0,2], [0,2,1] ]<br>        //<br>        // iter 3 = i = 2<br>        //<br>        //  step = 2<br>        //  prev_state = [0,2,1]<br>        //  compute(2, [0,2,1]):<br>        //      f_n_minus_2 = prev_state[1] = 2<br>        //      f_n_minus_1 = prev_state[2] = 1<br>        //      f_n = f_n_minus_2 + f_n_minus_1 = 2 + 1 = 3<br>        //<br>        //  new_state = [2,1,3]<br>        //<br>        //  trace = [ [0,0,2], [0,2,1], [2,1,3] ]<br>        //<br>        // iter 4: i = 3<br>        //<br>        //  step = 3<br>        //  prev_state = [2,1,3]<br>        //  compute(3, [2,1,3]):<br>        //      f_n_minus_2 = prev_state[1] = 1<br>        //      f_n_minus_1 = prev_state[2] = 3<br>        //      f_n = f_n_minus_2 + f_n_minus_1 = 1 + 3 = 4<br>        //<br>        //  new_state = [1,3,4]<br>        //<br>        //  trace = [ [0,0,2], [0,2,1], [2,1,3], [1,3,4] ]<br>        //<br>        // iter 5: i = 4<br>        //<br>        //  step = 4<br>        //  prev_state = [1,3,4]<br>        //  compute(4, [1,3,4]):<br>        //      f_n_minus_2 = prev_state[1] = 3<br>        //      f_n_minus_1 = prev_state[2] = 4<br>        //      f_n = f_n_minus_2 + f_n_minus_1 = 3 + 4 = 7<br>        //<br>        //  new_state = [3,4, 7]<br>        //<br>        //  trace = [<br>        //              [0,0,2],<br>        //              [0,2,1],<br>        //              [2,1,3],<br>        //              [1,3,4],<br>        //              [3,4,7]<br>        //          ]<br>        assert_eq!(trace.get(0, 2), Some(2));<br>        assert_eq!(trace.get(1, 2), Some(1));<br>        assert_eq!(trace.get(2, 2), Some(3));<br>        assert_eq!(trace.get(3, 2), Some(4));<br>        assert_eq!(trace.get(4, 2), Some(7));<br>    }</pre><pre>running 1 test<br>test trace::tests::test_generate_fibonacci_trace ... ok<br><br>test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 48 filtered out; finished in 0.00s</pre><p>These have been tested for a=1, b=1 (standard Fibonacci), a=2, b=1 (Lucas), and other seed combinations — all of which produce the correct sequence, in line with the addition rule.</p><p><strong>Next</strong></p><p>This trace is just the first step in the STARK pipeline — the next steps involve how it’s committed and turned into a proof. I haven’t dug into that part yet, so #2 will be me figuring it out as I go.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b2554abb5c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>