<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<title>9o</title>
	<subtitle>Blog about coding and my personal thoughts</subtitle>
	<updated>2026-05-12T00:00:00Z</updated>
	<link rel="alternate" type="text/html" href="https://9o.is" />
	<id>https://9o.is/atom_content.xml</id>
	<link rel="self" type="application/atom+xml" href="https://9o.is/atom_content.xml" />
<entry>
	<title>Why Snapshot Testing is easy but not simple</title>
	<link rel="alternate" type="text/html" href="https://9o.is/why-snapshot-testing-is-easy-but-not-simple.html" />
	<id>https://9o.is/why-snapshot-testing-is-easy-but-not-simple.html</id>
	<updated>2026-05-09T00:00:00Z</updated>
	<published>2026-05-09T00:00:00Z</published>
	<author>
		<name>Jul</name>
		<uri>https://9o.is</uri>
	</author>
	<summary>An analytical critique of Jest snapshot testing, arguing that the practice prioritizes immediate ease over architectural simplicity. By asserting against the entirety of a function&#39;s serialized output, snapshots violate the robustness principle and frequently fail due to benign structural modifications. The article explores how this brittleness degrades test suite reliability and advocates for transitioning to targeted, explicit assertions and dedicated visual regression tools.</summary>
	<content type="html"><![CDATA[<h1>Why Snapshot Testing is easy but not simple</h1>
	<p><strong>Last modification on </strong> <time>2026-05-09</time></p>
	<nav aria-labelledby="toc-heading">
    <h2 id="toc-heading">Table of Contents</h2>
    <ol>
        <li><a href="#robustness-overview">Brief Overview Of The Robustness Principle</a></li>
        <li><a href="#robustness-snapshot">Snapshot Tests Violate The Robustness Principle</a></li>
        <li><a href="#easy-vs-simple">Easy vs. Simple: The Design Trade-off</a></li>
        <li><a href="#ui-limitations">The Limitations of UI Snapshots</a></li>
    </ol>
</nav>
<p>In 2016, Christoph Pojer (at the time a Facebook developer) introduced Jest’s snapshot testing to the world. In a talk with Kent C. Dodds<sup id="fnref1"><a href="#fn1" rel="footnote">1</a></sup>, Pojer posed a question that has influenced modern front-end development: <em>&#8220;What can we do to make it low effort to write unit tests?&#8221;</em></p>
<p>The problem Christoph identified was real: developers find writing unit tests tedious. His solution was to automate test writing and make it easier for developers. But in reality, this approach made things harder because the generated tests are more brittle and less maintainable. By choosing &#8220;easy&#8221; over &#8220;simple,&#8221; snapshot testing didn&#8217;t solve the problem that developers need to understand when writing unit tests at scale—it made the problem worse.</p>
<h2 id="robustness-overview">Brief Overview Of The Robustness Principle</h2>
<p>The robustness principle, also commonly known as Postel&#8217;s Law<sup id="fnref2"><a href="#fn2" rel="footnote">2</a></sup>, states: &#8220;be conservative in what you do, be liberal in what you accept from others&#8221;. Although Postel briefly mentioned the robustness principle for designing internet protocols, programmers have adopted and extended it across many programming contexts—from function design to data processing to API contracts. Consider a Javascript function that calculates the total price of items:</p>
<pre><code class="language-javascript">function calculateTotal(items) {
    return items.reduce((sum, item) =&#62; sum + item.price, 0);
}
</code></pre>
<p>This function is fragile—it crashes if you pass it anything other than an array with a <code>reduce</code> method. It will fail with <code>Set</code> objects, array-like objects, or iterables. A more robust version accepts what it needs liberally:</p>
<pre><code class="language-javascript">function calculateTotal(items) {
    let sum = 0;
    for (const item of items) {
        sum += item?.price ?? 0;
    }
    return sum;
}
</code></pre>
<p>Now it works with arrays, Sets, or any iterable, and items can be undefined or missing their price property. This example demonstrates how the robust version is &#8220;liberal in what it accepts&#8221; while remaining &#8220;conservative in what it does&#8221; (calculating a sum). </p>
<p>In practice, you&#8217;d want to restrict this to only objects with a price property. Being too liberal in what you accept does carry security implications worth considering. RFC 9413<sup id="fnref3"><a href="#fn3" rel="footnote">3</a></sup> and research in language-theoretic security (LangSec)<sup id="fnref4"><a href="#fn4" rel="footnote">4</a></sup> by Meredith Patterson have shown that overly permissive input handling can introduce vulnerabilities. For instance, if the function recursively calculated prices in nested objects without depth limits, and the input came from an untrusted user, an attacker could construct deeply nested structures to trigger a denial-of-service attack. In this context, it&#8217;s typically safe for input objects to contain extra properties that the function simply ignores.</p>
<p>To restrict our function to only accept objects with a price property, we could use TypeScript to check for us.</p>
<pre><code class="language-typescript">function calculateTotal(items: Iterable&#60;{ price: number }&#62;) {
    let sum = 0;
    for (const item of items) {
        sum += item.price;
    }
    return sum;
}
</code></pre>
<p>Robustness in type theory extends well beyond simple input validation to encompass more sophisticated concepts like contravariance, where functions are deliberately designed to accept broader, more general types than strictly necessary for their immediate implementation (being liberal in what they accept as input). This flexibility allows functions to work with a wider range of arguments while maintaining type safety. The &#8220;L&#8221; in SOLID—the Liskov Substitution Principle—formalizes this fundamental idea of robustness at the type level through the concept of behavioral subtyping. The principle states that objects of a superclass should be replaceable with objects of a subclass without breaking the application, ensuring that derived types extend base types without altering their desirable properties and behaviors.</p>
<h2 id="robustness-snapshot">Snapshot Tests Violate The Robustness Principle</h2>
<p>In software testing, it helps to think from a meta-programming perspective: the code is your input (or data), and the test results are your output. The goal is to write conservative tests that liberally accept different implementations, so software modifications don&#8217;t unintentionally break existing tests. In other words, your unit tests should be robust to change. A test should only fail when the specific behavior it checks is actually broken.</p>
<p>Snapshot testing achieves the exact opposite. Because a snapshot asserts the <em>entire</em> output of a function or component, it&#8217;s inherently brittle. A single, irrelevant change to any property breaks every test that depends on that function.</p>
<p>Consider a function that returns user data:</p>
<pre><code class="language-javascript">function getUser(id) {
    return { id, name: "Alice", email: "alice@example.com" };
}
</code></pre>
<p>With snapshot testing, your test captures everything:</p>
<pre><code class="language-javascript">expect(getUser(1)).toMatchSnapshot();
&#47;&#47; Snapshot: { id: 1, name: "Alice", email: "alice@example.com" }
</code></pre>
<p>Now add a <code>createdAt</code> timestamp to the user object:</p>
<pre><code class="language-javascript">function getUser(id) {
    return { id, name: "Alice", email: "alice@example.com", createdAt: "2024-01-01" };
}
</code></pre>
<p><strong>Every snapshot test breaks</strong>, even though the core behavior (returning user data) hasn&#8217;t changed. If you have 10 snapshot tests using this function, you now have 10 failing tests instead of zero.</p>
<p>The robust alternative uses targeted assertions:</p>
<pre><code class="language-javascript">expect(getUser(1)).toHaveProperty("name", "Alice");
expect(getUser(1)).toHaveProperty("email", "alice@example.com");
</code></pre>
<p>These assertions remain true when <code>createdAt</code> is added—they only fail when the specific properties they care about actually break. I&#8217;ve led teams and scaled projects with hundreds of unit tests, and I&#8217;ve learned this: if developers don&#8217;t follow basic principles like robustness, adoption of unit testing will fall apart. Does that mean instead of writing 10 unit tests, you&#8217;ll need to write 20 and type more? Yes, but that&#8217;s the price of building something simple rather than easy.</p>
<h2 id="easy-vs-simple">Easy vs. Simple: The Design Trade-off</h2>
<p>In his talk, Pojer identifies the manual creation of assertions as a point of friction: &#8220;You try to write a test and you have this object and you try to match [it with] toEqual&#8230; how can we make this easier?&#8221;</p>
<p>This approach highlights a common tension in software design: prioritizing immediate ease over architectural simplicity. While generating and updating a snapshot requires very low immediate effort, it tightly couples the test to the entirety of the function&#8217;s serialized output. In contrast, a simple test relies on targeted assertions that verify specific invariants, decoupling the test suite from irrelevant structural modifications.</p>
<p>Because snapshots assert against the complete output, they frequently fail due to benign changes. When a test suite generates a high volume of false positives, developers can experience alert fatigue. This often leads to a routine of automatically updating the snapshots without strictly reviewing the code modifications, ultimately degrading the reliability of the test suite as a functional verification tool.</p>
<h2 id="ui-limitations">The Limitations of UI Snapshots</h2>
<p>A common rationale for maintaining snapshot tests is their application to UI components<sup id="fnref5"><a href="#fn5" rel="footnote">5</a></sup><sup id="fnref6"><a href="#fn6" rel="footnote">6</a></sup>. However, a user interface is a visual output derived from the complex interplay of HTML, CSS, and browser rendering pipelines. A Jest snapshot strictly captures the serialized HTML structure.</p>
<p>Because the testing tool does not evaluate the rendered output, evaluating HTML markup is an unreliable method for verifying visual correctness. An updated CSS utility class will fail a snapshot test, but inspecting the resulting HTML diff provides little assurance to developers that the visual rendering remains intact.</p>
<p>Test objectives should dictate the tooling. If the goal is to verify component semantics or accessibility attributes, explicit assertions remain the most robust approach (e.g., <code>expect(button).toHaveAttribute(&#39;aria-expanded&#39;, &#39;true&#39;)</code>). Conversely, if the objective is to guarantee visual consistency, the correct technical solution is Visual Regression Testing, which evaluates actual pixel renderings.</p>
<p>Ultimately, snapshot testing occupies an ambiguous technical space: it lacks the targeted precision of a unit test and the visual accuracy of an end-to-end rendering test. By archiving the current state of an output rather than defining its required functional constraints, snapshots record what the data is rather than what it must be. Transitioning away from snapshots requires writing explicit assertions, which demands more upfront effort but yields a more resilient and meaningful test suite.</p>
<div class="footnotes">
<hr/>
<ol>

<li id="fn1">
<p>Christoph Pojer. &#8220;Jest Snapshot Testing.&#8221; Talk with Kent C. Dodds on the Testing JavaScript podcast. <a href="https://www.youtube.com/watch?v=i31VtyJSM-I&amp;t=17m58s">https:&#47;&#47;www.youtube.com&#47;watch?v=i31VtyJSM-I&#38;t=17m58s</a>&#160;<a href="#fnref1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn2">
<p>Jon Postel. &#8220;Transmission Control Protocol.&#8221; RFC 793, September 1981. <a href="https://tools.ietf.org/html/rfc793">https:&#47;&#47;tools.ietf.org&#47;html&#47;rfc793</a>&#160;<a href="#fnref2" rev="footnote">&#8617;</a></p>
</li>

<li id="fn3">
<p>IETF. &#8220;Maintaining Robust Protocols.&#8221; RFC 9413, June 2023. <a href="https://tools.ietf.org/html/rfc9413">https:&#47;&#47;tools.ietf.org&#47;html&#47;rfc9413</a>&#160;<a href="#fnref3" rev="footnote">&#8617;</a></p>
</li>

<li id="fn4">
<p>Meredith Patterson and Sergey Bratus. &#8220;Language-Theoretic Security.&#8221; Foundational research on formal language theory and input validation as a security mechanism. <a href="https://langsec.org">https:&#47;&#47;langsec.org</a>&#160;<a href="#fnref4" rev="footnote">&#8617;</a></p>
</li>

<li id="fn5">
<p>&#8220;Snapshot Testing.&#8221; Jest 24.x Archived Documentation. <a href="https://archive.jestjs.io/docs/en/24.x/snapshot-testing">https:&#47;&#47;archive.jestjs.io&#47;docs&#47;en&#47;24.x&#47;snapshot-testing</a>&#160;<a href="#fnref5" rev="footnote">&#8617;</a></p>
</li>

<li id="fn6">
<p>Ben McCormick. &#8220;Testing with Jest Snapshots: First Impressions.&#8221; September 2016. <a href="https://benmccormick.org/2016/09/19/074100.html">https:&#47;&#47;benmccormick.org&#47;2016&#47;09&#47;19&#47;074100.html</a>  &#160;<a href="#fnref6" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content>
</entry>
<entry>
	<title>What is blockchain?</title>
	<link rel="alternate" type="text/html" href="https://9o.is/what-is-blockchain.html" />
	<id>https://9o.is/what-is-blockchain.html</id>
	<updated>2017-03-01T00:00:00Z</updated>
	<published>2017-03-01T00:00:00Z</published>
	<author>
		<name>Jul</name>
		<uri>https://9o.is</uri>
	</author>
	<summary>&quot;What is blockchain?&quot; was the one question people at the IBM Garage asked the most after several new Garage locations were announced, due to the high demand for consultancy services related to blockchain-as-a-service. With my experience working at a Bitcoin startup, I aim to answer that question by walking you through smart contracts, a bit of Bitcoin&#39;s history, and the differences between Bitcoin and private blockchains.</summary>
	<content type="html"><![CDATA[<h1>What is blockchain?</h1>
	<p><strong>Last modification on </strong> <time>2017-03-01</time></p>
	<nav aria-labelledby="toc-heading">
    <h2 id="toc-heading">Table of Contents</h2>
    <ol>
        <li><a href="#generic-use-case">Generic Use-case Scenario</a></li>
        <li><a href="#tsa">TSA: Timestamping Authority</a></li>
        <li><a href="#hashing">Hashed documents?</a></li>
        <li><a href="#timestamping">Timestamping</a></li>
        <li><a href="#security">Security of blockchain</a></li>
        <li><a href="#origin">Origin of blockchain</a></li>
        <li><a href="#blockchain-as-a-service">Blockchain as a service</a></li>
        <li><a href="#smart-contracts">Smart Contracts</a></li>
        <li><a href="#opinions">My opinions</a></li>
    </ol>
</nav>
<p>You may have tried googling this question to end up coming short or, even worse, be more confused than you initially were. That&#8217;s because people interpret the term &#8220;blockchain&#8221; in different ways. Like the word meme&#8230;</p>
<blockquote>
<p>&#8230;meme was coined by Richard Dawkins to represent a &#8220;social gene&#8221; — a meaning that only exists within social constructs. Winking in Ireland is a meme for being friendly. It&#8217;s socially passed down from one person to the next like a gene, but it was not passed down completely, which is why it means something different — promiscuous — in the US. So when you&#8217;re in the US, don&#8217;t wink at strangers (wink wink).</p>
</blockquote>
<p>Today, the social web has extended the term &#8220;meme&#8221; to mean any funny joke. The term blockchain is no different. It means something different depending on which community uses it.</p>
<p>That causes a lot of confusion and has made it the one question that people at work in IBM&#8217;s Bluemix Garage ask the most after several new Garage locations were announced because of the highly demanded consultancy for blockchain-as-a-service. The service is powered by the open source project, Fabric, <a href="https://github.com/hyperledger/hyperledger/blob/3ae1e266f3a715b129d26169d166e56aeabcb1f6/README.md#fabric-incubator">IBM&#8217;s blockchain merged with digital assets</a>, and is now the leading incubation project for <a href="https://www.hyperledger.org/">Hyperledger</a>.</p>
<p>I&#8217;m asked this question a lot because I&#8217;ve been in the Bitcoin loop for years now and have founded a Bitcoin startup before joining the Garage. Luckily, Hyperledger is very different from Bitcoin and much simpler to understand because of its centralized security model.</p>
<p>To put the question to rest, my observation — from being part of the Bitcoin community, interested in what Ethereum has been up to, and listening to some leaders of the Hyperledger project explain blockchain to large crowds of people — is that all definitions of blockchain cross at one point. That point most closely resembles <a href="https://www.anf.es/pdf/Haber_Stornetta.pdf">Haber and Stornetta&#8217;s</a> <a href="http://danielsuo.com/projects/bitcoin/literature/improving-time-stamping.pdf">timestamping solution</a> (circa 1990) as referenced in <a href="https://bitcoin.org/bitcoin.pdf">Bitcoin&#8217;s whitepaper</a>.</p>
<h2 id="generic-use-case">Generic Use-case Scenario</h2>
<p>To understand the timestamping problem, here&#8217;s an example scenario:</p>
<ul>
<li>Alice owns property X and wants to transfer ownership to Bob.</li>
<li>Alice digitally signs a contract — stamped with the date and time — that transfers ownership of X to Bob.</li>
<li>Bob can prove ownership of X since the date and time on the contract.</li>
</ul>
<p>The problem is that nothing stops Alice from digitally signing a second contract with an earlier timestamp to transfer ownership of X to Charlie. Charlie can get the authorities involved and claim Bob stole X from him. Bob shows his contract, and now the spotlight is on Alice. Why did she sign two contracts? Alice can invent a story that she didn&#8217;t sign Bob&#8217;s contract: he stole her private key and signed the contract himself.</p>
<p>So to whom does X belong? Alice, Bob, or Charlie? No one outside the negotiation knows, not even the authorities, so it can&#8217;t be settled in court. That makes Alice&#8217;s timestamp useless.</p>
<p>That&#8217;s the problem. The timestamp must come from a trustworthy legal entity. This is the same problem that cryptocurrencies, like Bitcoin, have faced for decades and is commonly known as the double-spending attack.</p>
<h2 id="tsa">TSA: Timestamping Authority</h2>
<p>The easy solution is to use a third-party service, known as the Timestamping Authority [TSA], that everyone can trust, like a bank, to sign and timestamp contracts. Now, Alice can digitally sign a contract that transfers ownership of X to Bob and go to the TSA to have the contract signed and timestamped with the current date and time.</p>
<p>Bob can then accept the contract since it was signed by the TSA. Alice can sign a second contract to transfer the ownership of X to Charlie, but the TSA will not timestamp the contract because property X belongs to Bob, not Alice. That solves the problem&#8230;sort of.</p>
<p>The problem with that solution is that everyone trusts the TSA. This leaves the TSA with too much authority to sign and timestamp contracts. If the TSA somehow benefits from screwing over Bob and taking sides with Charlie and Alice for capital-gain reasons, Bob will get screwed just like in the initial scenario. Trusting the TSA doesn&#8217;t guarantee a trustworthy system.</p>
<p>Haber and Stornetta&#8217;s timestamping proposal helps reduce — not fix — the problem, by minimizing the TSA&#8217;s authoritative power. Instead of the TSA signing and timestamping contracts, that authority is left to the parties of the contract, greatly reducing the TSA&#8217;s privilege. The TSA only acts as a ticking machine that sends out a signal at an interval to aggregate a bunch of contracts and transparently broadcast that information to an <em>open network of witnesses</em>.</p>
<p>You can&#8217;t simply trust a random person, so to join this network of witnesses, or let&#8217;s call it &#8220;the gang,&#8221; you have to be invited. That means having a registration system and identifying each member of your gang. It can just be your friends or your business colleagues. The larger the gang, the better, since it makes the gang more distributed. So, let&#8217;s say the interval is 10 minutes. During those 10 minutes, the gang will spend time collecting all hashed documents that have to be timestamped.</p>
<h2 id="hashing">Hashed documents?</h2>
<p>Hashed documents. Say it with me. Hashed documents. If you want a blockchain, you don&#8217;t want a weak chain. You want a strong chain! Yeah! Think of it as a physical chain. What kind of chain do you use to tie your bike? A plastic one? I don&#8217;t think so. You want a steel chain that is hard to break. The same goes for blockchain. Hashing is the steel. You don&#8217;t need to know how it works, but what it does.</p>
<p>A crypto hash function takes a text of any length and randomly creates a fixed-sized text called a hash. That&#8217;s it. If you take a legal document text and hash it, it will produce a short random text. Hashing is magical for several reasons you should know:</p>
<ol>
<li>It&#8217;s impossible to get any information from the legal document with only the hash, so you can safely share the hash with anyone in the world and know that the chances of Earth getting struck by an asteroid are significantly more probable than someone recovering your document from the hash.</li>
<li>It&#8217;s impossible to generate the same hash with different documents, so the hash is the identifier of the legal document.</li>
<li>It is random. Changing a single character in the legal document text will generate a completely different hash.</li>
</ol>
<h2 id="timestamping">Timestamping</h2>
<p>Okay, now that you know hashing, you&#8217;re halfway to knowing how blockchain works! Yay! Stay with me! Back to how timestamping works. When a client wants to timestamp a legal document, the client hashes the document and gives the hash to the gang. The gang continues to collect all hashed documents until the interval is up.</p>
<figure class="light-bg">
    <img src="/images/what-is-blockchain/what-is-blockchain-1.webp" alt="Diagram showing a sequence of documents before it reaches the 10-minute interval">
    <figcaption>Fig 1. Collect all hashed documents until the interval is up.</figcaption>
</figure>
<p>When the interval is up, all hashed documents are hashed together one by one to represent all documents collected as one &#8220;block&#8221;.</p>
<figure class="light-bg">
    <img src="/images/what-is-blockchain/what-is-blockchain-2.webp" alt="Diagram showing a sequence of documents once it reached the 10-minute interval">
    <figcaption>Fig 2. Collect all hashed documents once the interval is up.</figcaption>
</figure>
<figure class="light-bg">
    <img src="/images/what-is-blockchain/what-is-blockchain-3.webp" alt="Diagram showing a sequence of documents hashed together as a binary tree">
    <figcaption>Fig 3. All hashed documents are hashed together one by one creating a block.</figcaption>
</figure>
<p>The same happens at each interval.</p>
<figure class="light-bg">
    <img src="/images/what-is-blockchain/what-is-blockchain-4.webp" alt="Diagram showing a sequence of documents hashed together as a binary tree with an additional interval collecting more documents for the second, upcoming block">
    <figcaption>Fig 4. Repeat the process for every interval.</figcaption>
</figure>
<p>But the blocks don&#8217;t stand alone. The block hash is hashed with the previous block&#8217;s hash. So the hash of one block depends on the one before it, and the one before it depends on the one before that one, and so on. Because of the hashing properties I mentioned, this literally ties all blocks together, creating a chain.</p>
<figure class="light-bg">
    <img src="/images/what-is-blockchain/what-is-blockchain-5.webp" alt="Diagram showing a couple of blocks hashed together">
    <figcaption>Fig 5. The block hash is hashed with the previous block's hash.</figcaption>
</figure>
<p>That builds up a chain of blocks aka. blockchain.</p>
<figure class="light-bg">
    <img src="/images/what-is-blockchain/what-is-blockchain-6.webp" alt="Diagram showing a multiple blocks hashed together">
    <figcaption>Fig 6. Multiple blocks hashed together creates a blockchain.</figcaption>
</figure>
<p>Changing a single character in any hashed document or adding a block in the middle of the chain will require changing everything in the current block and every block ahead of it. That is a very important tamper-proof property that blockchain provides and is one of the biggest selling points anyone would make to you. Think of blockchain like a timeline — the past should not be changed.</p>
<p>In that sense, the timestamping solution is misleading because it never specifies a time but the relative time<sup id="fnref1"><a href="#fn1" rel="footnote">1</a></sup>. That&#8217;s the most important matter — order preservation. That is sufficient to help poor Bob not get screwed like last time.</p>
<h2 id="security">Security of blockchain</h2>
<p>This is my favorite topic of all, and I can spend hours talking about it, but I&#8217;ll just get to the point. I lied earlier. Blockchain is not 100% tamper-proof. In other words, it can be tampered with. It&#8217;s technically tamper-evident. If something changes, the hashes will change. As I mentioned earlier, changing a single character in any hashed document or adding a block in the middle of the chain will have to change everything in the current block and every block ahead of it.</p>
<p>One question I skipped was: how does the gang agree on who adds the next block to the blockchain? Another way to phrase it: What is the consensus?</p>
<p>A simple consensus could be a roll of the die. Whoever in the gang gets the highest roll gets to add the next block. That&#8217;s just an example. You can get creative and come up with any algorithm you think works best. What matters is that the consensus is fair and doesn&#8217;t benefit anyone.</p>
<p>But when there is consensus, there needs to be cooperation. Gang members need to be honest. If one member is not honest, then it&#8217;ll be okay; the majority will overpower the dishonest member. Still, this particular scenario goes back to the initial problem. There are two blockchains. There are two stories. There&#8217;s the honest story and the dishonest story. There&#8217;s Alice&#8217;s story and Bob&#8217;s story. If it happens to be that the majority of the gang are dishonest because they want to screw, you know who, poor ol&#8217; Bob, the gang can do it, so the blockchain model can break. It&#8217;s much harder to break, but it can break.</p>
<p>We went from trusting Alice which was a disaster, to trusting the TSA, to trusting the gang, which is better but can still fail in the worst-case scenario.</p>
<p>Bitcoin further improves the solution in a very clever way that excitingly works well in practice using a method, known as Proof of Work, where gang members are not registered or identified, allowing Bitcoin to be decentralized and censorship-resistant. The member you trust to add the next block to the chain is the member that&#8217;s most financially invested in the gang. Bitcoin has presented new challenges with its drastic innovative changes, but it is still vulnerable to some hypothetical attacks. There has been lots of research on alternatives like variations of proof of virtual work. Only time will tell, but the future looks bright!</p>
<p>Lesson learned: <em>trust is the essence of security, and you cannot escape it.</em></p>
<h2 id="origin">Origin of blockchain</h2>
<p>Satoshi Nakamoto never mentioned &#8220;block chain&#8221; or &#8220;blockchain&#8221; when he announced his invention of Bitcoin — he mentioned &#8220;block&#8221; and &#8220;chaining&#8221; but never block chain.</p>
<p>The first time <em>block chain</em> was mentioned in a related Bitcoin discussion was between Satoshi and Hal Finney<sup id="fnref2"><a href="#fn2" rel="footnote">2</a></sup> in the <a href="https://satoshi.nakamotoinstitute.org/emails/cryptography/6/">cryptography mailing list, cypherpunk</a>. The term <em>block chain</em> made sense during the time of the discussion because it wasn&#8217;t the first time that naming has been used in cryptography. <em>Blockchaining</em> is an encryption method that has existed since 1976 and is still used today, and it works similarly to the blockchaining in blockchain. To further support my definition of blockchain, Hal Finney used <em>block chain</em> in the context of timestamping.</p>
<h2 id="blockchain-as-a-service">Blockchain as a service</h2>
<p>&#8230; has existed for +20 years. That&#8217;s right. Tell that to your friend and leave them baffled. In 1994, Haber and Stornetta saw the potential in their discovery and started a company called <a href="http://surety.com/">Surety</a>.</p>
<p>However, that doesn&#8217;t mean that Surety competes against IBM and other companies invested in blockchain because everyone&#8217;s definition of blockchain is different. Like I mentioned in the security section, blockchain includes proof of work when you speak of blockchain in Bitcoinland. Blockchain includes smart contracts when you speak in the Hyperledger world.</p>
<h2 id="smart-contracts">Smart Contracts</h2>
<p>The goal of the Hyperledger is to build a platform for smart contracts or <em>chaincode</em>, as it&#8217;s known in the Hyperledger project. Smart contract was coined by Nick Szabo, the creator of BitGold, a proposal that is awfully similar to Bitcoin, and the arguably leading contender of Satoshi Nakamoto&#8217;s true identity.</p>
<blockquote>
<p>[Smart contracts] embed contracts in all sorts of property that is valuable and controlled by digital means. Smart contracts reference that property in a dynamic, often proactively enforced form, and provide much better observation and verification where proactive measures must fall short.
— Nick Szabo, <a href="https://web.archive.org/web/20160312140021/http://szabo.best.vwh.net/idea.html">https:&#47;&#47;web.archive.org&#47;web&#47;20160312140021&#47;http:&#47;&#47;szabo.best.vwh.net&#47;idea.html</a></p>
</blockquote>
<p>Whenever there are two or more legal personalities, like a person or corporation, there are usually contracts involved. If a party breaks the contract, the counter-party will take them to court and settle the issue, justly or unjustly — it will be settled with human intervention. This is a reactive solution. Smart contracts are proactive.</p>
<p>The (application&#8217;s) code is the contract, and there is no way around it; there shouldn&#8217;t be any human intervention at its optimal use case. Of course, there is the possibility of a bug being present in the smart contract code, but it&#8217;s argued that a bug is part of the contract; it&#8217;s a feature, not a vulnerability. Taking advantage of the feature is not a criminal activity.</p>
<p>A perfect example of this demonstration is <em>the DAO</em>, a smart contract application that allows investors to crowdsource funding in a decentralized environment, so there are no identities and not a single registration system. <a href="http://www.nytimes.com/2016/05/22/business/dealbook/crypto-ether-bitcoin-currency.html">The DAO received over $152 million in funding, making it the largest crowdsourced project in history</a>.</p>
<p>Later, it was discovered that the numbers in the DAO contract weren&#8217;t matching because someone was leaking money from the DAO to their account using a bug no one was aware of. Over $60 million was drained from the DAO using <em>this feature</em>. Call it stealing, but the code is the contract, and the attacker used it as their <a href="http://pastebin.com/CcGUBgDG">get-out-of-jail card</a>.</p>
<p>What does this mean for the Hyperledger project? Hyperledger doesn&#8217;t focus on decentralized blockchains. In a centralized environment, anyone with the slightest privilege has an identity, so if they try to pull off something clever like the DAO attack, they&#8217;ll most likely go to court. This arguably defeats the whole purpose of smart contracts, but the economics of a private blockchain are still unknown. We&#8217;ll just have to wait and see how it goes and how IBM handles its end.</p>
<h2 id="opinions">My opinions</h2>
<p>Haber and Stornetta&#8217;s timestamping proposal, as we may know it as blockchain, is not new (relative to internet technology). The innovative part of Bitcoin is the economics and game-theory involved in the security of decentralized blockchains, not blockchain itself. Many companies can benefit from private (centralized) blockchains, but they may be in for disappointment if they end up in a worst-case scenario regarding security. Because of that, IBM should start looking into best practices when deploying blockchains for customers.</p>
<div class="footnotes">
<hr/>
<ol>

<li id="fn1">
<p>Even though blockchain only provides relative timestamping, a time period can be guaranteed by <em>anchoring</em> blocks. To anchor the blocks in a fixed time period, a <em>widely-witnessed</em> piece of information, like a New York Times article title with the published date, is copied to a block. That guarantees the anchored block was never created before the published date. <a href="https://blockchain.info/tx/4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b">Satoshi Nakamoto did this in the very first block of the Bitcoin blockchain to guarantee that it was never created before January 3rd of 2009</a>.&#160;<a href="#fnref1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn2">
<p>Who is Hal Finney? <a href="https://bitcointalk.org/index.php?topic=155054.0">https:&#47;&#47;bitcointalk.org&#47;index.php?topic=155054.0</a>&#160;<a href="#fnref2" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content>
</entry>
</feed>
