<?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 Harley Swick on Medium]]></title>
        <description><![CDATA[Stories by Harley Swick on Medium]]></description>
        <link>https://medium.com/@hdswick?source=rss-bda93e152652------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qbDj1p4yQ9Vy-7ndSIhDDA.png</url>
            <title>Stories by Harley Swick on Medium</title>
            <link>https://medium.com/@hdswick?source=rss-bda93e152652------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:25:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hdswick/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[Using the Truebit Filesystem]]></title>
            <link>https://medium.com/truebit/using-the-truebit-filesystem-f6a5d4ac9604?source=rss-bda93e152652------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6a5d4ac9604</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[decentralization]]></category>
            <category><![CDATA[data-availability]]></category>
            <category><![CDATA[truebit]]></category>
            <category><![CDATA[filesystem]]></category>
            <dc:creator><![CDATA[Harley Swick]]></dc:creator>
            <pubDate>Wed, 16 Jan 2019 23:39:06 GMT</pubDate>
            <atom:updated>2019-01-17T00:32:01.654Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yXpu1jGXZCNPHDBJG6uR6w.jpeg" /></figure><h3>Overview</h3><p>If you are following the Truebit project you have hopefully heard about truebit-os. If you haven’t, you should read this post before continuing <a href="https://medium.com/truebit/developing-with-truebit-an-overview-86a2e3565e22">https://medium.com/truebit/developing-with-truebit-an-overview-86a2e3565e22</a>. In summary, truebit-os is the client that network participants (miners) run to earn TRU tokens. The client handles the interactions between Ethereum and the off chain functionality like the WebAssembly interpreter and IPFS. The Truebit filesystem is a component of the truebit-os system. Funny enough, it was the inclusion of the filesystem that explains why it is called “truebit-os” and not “truebit-client”. Like a normal operating system, truebit-os uses the filesystem to work with data one would expect from a UNIX system. What is novel is this filesystem is built on top of Ethereum and IPFS. The complexity involved with such functionality is hidden by the abstractions inside truebit-os.</p><p>The part we can’t fully abstract away is how Task Givers make their data accessible to the rest of the Truebit network. When a task giver submits a task, they also submit a piece of data that allows the filesystem to retrieve the data for the program and the input data. Before we go into how files are represented and interacts with, we should take some time to go over what storage types Truebit offers now. Each storage type has its own trade-offs so it is important to discuss how each work and their pros and cons.</p><p>The first type of storage is simple Ethereum bytes. Note, the data is persisted in the Truebit filesystem’s contract. The filesystem is not meant to work with storage data on arbitrary contracts.This is useful for small pieces of data that later need to be used onchain. Also you don’t have to worry about data availability. This can be expensive depending on the current gas price and is limited by the gas limit. We do not support retrieving arbitrary data from any random smart contract. Access to particular smart contract methods for data sources can be added in the future. For now the only methods the client supports are the ones provided by the Truebit filesystem.</p><p>The second type of storage is encoding the data inside of a smart contract and deploying. This is not a typical functioning contract with methods coded by Solidity. It is the literal binary data stored as contract code. This is then later stored using low level calls to the EVM. Such an approach is a more exceptional use of a deployed contract, but it is functional. Be advised the trade-offs are similar to the storage type above (Filesystem bytes). Users might like this type in the case where the want to reuse the data, and be absolutely certain the data is accessible in the future.</p><p>The third type of storage, and probably most popular is IPFS. This storage type certainly scales much better then the previous types. You won’t have to worry about the gas limit. The gas limit is not very large so most useful files will probably be stored here. Beware!!! IPFS does not have the same data availability guarantees as Ethereum. There is no guarantee the data is replicated. Jason Teutsch wrote an article outlining this problem <a href="https://medium.com/truebit/a-file-system-dilemma-2bd81a2cba25">https://medium.com/truebit/a-file-system-dilemma-2bd81a2cba25</a>. Luckily, there are some tricks to get around this that should work for most applications. The easiest trick is to take advantage of the built in incentive’s a particular Dapp provides. Dapp developers (Task Givers) have a vested self interest in solving this problem, so they should be incentivized to run IPFS nodes. They get around the ephemeral data problem by running their own IPFS nodes that replicate their task data, thus providing a much stronger data availability guarantee for their tasks. Or the protocol itself can incentivize the participants to run the nodes (this would be more decentralized, but slightly more complex).</p><h3>Using Truebit Filesystem IRL</h3><p>Now that we have covered the different types of storage provided by the Truebit filesystem, we will go into detail on how to use it. Truebit tasks take in input by reading in a file, and outputs data by writing out to a file. These are normal concepts for regular programs, but might seem out of place for a blockchain application. The functionality is rather straightforward though. The Truebit filesystem smart contract makes use of two basic entities. Bundles and files. Bundles, are like directories, in that they are just a collection of files. When we submit a task, we must submit a bundleID so the filesystem knows how to retrieve the WASM code and any input data. Task Giver’s can mix and match the types of files they want to use for a particular task as they see fit. The bundle contains the list of these files. What constitutes a “file” in the Truebit filesystem depends on its file type. Earlier, I outlined the different file types supported. Bytes, contracts, or IPFS. If the data is stored in bytes then all that is needed is the fileID. If it is a contract then the contract address is used to retrieve the data. IPFS data is retrieved using the IPFS hash.</p><p>Hopefully, at this point you at least have a rough idea how the filesystem works. Now we will walk through how to do this in Solidity code. Before a task giver can call createTask they need to make sure their task’s code file and input data are accessible. The filesystem contract provides a variety of different methods, for more details you can go here to check out an example here <a href="https://github.com/TrueBitFoundation/truebit-os/blob/master/scrypt-data/contract.sol">https://github.com/TrueBitFoundation/truebit-os/blob/master/scrypt-data/contract.sol</a></p><p>The rest of the post will assume you are using an interface around the filesystem smart contract. The first method we will need to use is to create an empty bundle.</p><pre>bytes32 bundleID = filesystem.makeBundle(nonce);</pre><p>The <em>nonce </em>is a unique number used to generate filesystem identifiers. We use the nonce for bundleID’s and fileID’s. Uniqueness is the responsibility of the transaction sender. The easiest solution is to use a random number generator to make an integer with several decimal places. The unique number is hashed with the address of the transaction sender. The bundleID is simply a hash of the nonce and transaction sender’s address (msg.sender) field provided by the EVM.</p><p>Now that we have an empty bundle we will need to start creating some files. Here is how to create a file for the three different types of storage provided.</p><p>For persisting a file as bytes in the contract storage we do this:</p><pre>bytes32 fileID = filesystem.createFileWithContents(&quot;input.data&quot;, nonce, data, data.length);</pre><p>We named the file “input.data”. We need a <em>nonce</em> provided by the user for the unique ID. We need the <em>data</em>, which must be of type bytes32[] , and the last argument is the length of <em>data</em>.</p><p>If we want to add a deployed smart contract to the Truebit filesystem we do it like this:</p><pre>bytes32 fileID = filesystem.addContractFile(&quot;input.data&quot;, nonce, contractAddress, root, size);</pre><p>We named the file “input.data” like earlier. We need a <em>nonce</em>. The key piece to note is the <em>contractAddress</em>. This the 32 byte address we use for any smart contract address. We will also need the merkle <em>root</em> of the bytes in data. There are a number of ways to generate this root. truebit-os contains a node module to do this: <a href="https://github.com/TrueBitFoundation/truebit-os/blob/master/wasm-client/merkle-computer/merkleRoot.js">https://github.com/TrueBitFoundation/truebit-os/blob/master/wasm-client/merkle-computer/merkleRoot.js</a>. Finally we need to provide the length of bytes as the <em>size</em> argument. Please note putting any random smart contract in here will not work the way you are expecting it to.</p><p>At this point some of the patterns should start to be apparent, and registering IPFS data is not very different.</p><pre>bytes32 fileId = filesystem.addIPFSFile(&quot;input.data&quot;, size, ipfsHash, merkleRoot, nonce);</pre><p><em>size</em> is the byte length of the IPFS file. <em>ipfsHash </em>is the IPFS file identifier<em>. merkleRoot</em> is the hash created by merklizing the IPFS file being used as input. <em>The nonce</em> is obtained like we did earlier.</p><p>So we’ve created our file, but it isn’t inside of our bundle. So we can fill up the bundle with our files like this:</p><pre>filesystem.addToBundle(bundleID, fileID);</pre><p>After the files are associated to the bundleID we have one more step. A bundle is not complete without the code file. In terms of storage, code files are indistinguishable from input or output files. However, the Truebit system does treat them somewhat differently so it is helpful to distinguish them. Also, for the most part, a code file will be reused for many tasks. Where as the input data and output data will probably be different per task. So we include the code file into the bundle when we finalize it. The process of finalization involves generating a merkle root of the bundle and storing it for use in our Truebit tasks. This is done by calling this method:</p><pre>filesystem.finalizeBundleIPFS(bundleId, codeFileID);</pre><p>All we need is the bundleID and the fileID of the code file. And that’s it! We can now use this bundle with our Truebit task.</p><h3>Conclusion</h3><p>Storing data in a trust-less way is not exactly trivial, it is my hope that this article and the Truebit filesystem itself provides some insight on how to solve such problems. Please keep in mind that a lot of this tech is very primitive. Personally maintaining an IPFS server or Ethereum storage are not exactly ideal, but they work today. As new tech arises around this domain, we plan to extend the filesystem using the protocol outlined above. We are very excited to see what is created by the greater decentralized community.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6a5d4ac9604" width="1" height="1" alt=""><hr><p><a href="https://medium.com/truebit/using-the-truebit-filesystem-f6a5d4ac9604">Using the Truebit Filesystem</a> was originally published in <a href="https://medium.com/truebit">Truebit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing a Truebit Task in Rust]]></title>
            <link>https://medium.com/truebit/writing-a-truebit-task-in-rust-6d96f2ee0a4b?source=rss-bda93e152652------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d96f2ee0a4b</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[truebit]]></category>
            <dc:creator><![CDATA[Harley Swick]]></dc:creator>
            <pubDate>Mon, 26 Nov 2018 20:31:17 GMT</pubDate>
            <atom:updated>2018-11-27T13:19:36.579Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*5WnQ33uWkr2iobSrl9evTQ.jpeg" /></figure><p>In this post I’ll be going through step by step how to write and compile your own Truebit task with the Rust programming language.</p><p>You might be wondering, why Rust? I would rather write it in Python or JS. The reason is that Truebit tasks are written in WASM (WebAssembly). Our current off-chain interpreter is literally a fork of the reference WASM interpreter modified to produce merkle proofs. We chose WASM because it is a concise spec and it is increasingly becoming very popular. However, as of right now, WASM does not support garbage collection. You can follow progress on this issue here <a href="https://github.com/WebAssembly/proposals/issues/16">https://github.com/WebAssembly/proposals/issues/16</a>. That means languages like Python or JS are not supported, because they use garbage collectors. This leaves us with non-garbage collected languages like C, C++, or Rust.</p><p>Rust is great because it can compete with lower level languages in terms of performance, but it feels like a higher level language. This is because Rust utilizes what is called zero-cost abstraction. Here is a good blog post that goes more in depth into that <a href="https://blog.rust-lang.org/2015/05/11/traits.html">https://blog.rust-lang.org/2015/05/11/traits.html</a>. Cargo, Rust’s build tool and package manager, provides a big competitive advantage over C or C++. Later, we will see how Cargo allows us to specify different compilation targets . This makes it trivial to compile our Rust program into WASM. Without further ado, let’s get started!</p><p>I highly recommend getting your Rust program working without thinking about Truebit initially. The first step is obviously getting Rust installed on your machine <a href="https://www.rust-lang.org/en-US/install.html">https://www.rust-lang.org/en-US/install.html</a>. Once that is setup, we can start a new project. In this tutorial I’ll be going through a very simple program that reads in the alphabet, reverses it, and then writes it out. This might seem overly simple, but it does touch on the IO operations that have a bit more nuance in the context of Truebit. We can start our project like this:</p><pre>cargo new reverse_alphabet</pre><p>Now open up reverse_alphabet/src/main.rs in your favorite text editor. You should see something this:</p><pre>fn main() {                                                                     <br>    println!(&quot;Hello, world!&quot;);                                                  <br>}</pre><p>You can run this simple Hello World program with cargo run . For our Truebit task we need a text file containing the alphabet.</p><pre>echo &quot;abcdefghijklmnopqrstuvwxyz&quot; &gt; alphabet.txt</pre><p>Now we need to modify our program to read in this file, process it, and then write out a new text file. You can simply copy this file: <a href="https://github.com/TrueBitFoundation/truebit-toolchain/blob/master/workspace/reverse_alphabet/src/main.rs">https://github.com/TrueBitFoundation/truebit-toolchain/blob/master/workspace/reverse_alphabet/src/main.rs</a></p><p>When you run the program you should see a file called reverse_alphabet.txt. After we have written and successfully compiled our program, we need to compile our program into the proper WASM format. This essentially involves changing the wasm compilation target to Emscripten. Since that can take a while to install, we’ve developed the truebit-toolchain to streamline this process.</p><pre>git clone <a href="/service/mailto:git@github.com">git@github.com</a>:TrueBitFoundation/truebit-toolchain.git</pre><p>We’ll want to move our Rust project into the workspace directory.</p><pre>mv reverse_alphabet truebit-toolchain/workspace</pre><p>Now build the docker image (installation instructions: <a href="https://docs.docker.com/install/">https://docs.docker.com/install/</a>).</p><pre>docker build . -t truebit-toolchain:latest</pre><p>I’ve written a handy script that sets up a bash environment inside the Docker container.</p><pre>chmod 755 truebit-toolchain/scripts/open_bash.sh<br>./truebit-toolchain/scripts/open_bash.sh</pre><p>This image already has Rust and Emscripten installed. We’ll use them to compile our Truebit task.</p><pre>source $HOME/.cargo/env<br>cd /workspace/reverse_alphabet<br>cargo build --target wasm32-unknown-emscripten --release</pre><p>Now if you look in the target/wasm32-unknown-emscripten/release you should see reverse_alphabet.js and reverse_alphabet.wasm . The .js file is the Emscripten module that specifies different run time operations for the WASM program. Here is a great resource if you want to read more in depth about it <a href="https://kripken.github.io/emscripten-site/docs/api_reference/module.html">https://kripken.github.io/emscripten-site/docs/api_reference/module.html</a>.</p><p>We’ll be using both files for our next step. I like to move them into the root of the project, but technically you don’t have to. The only trade off is it might make the absolute paths we’ll be using a bit longer.</p><pre>mv target/wasm32-unknown-emscripten/release/{reverse_alphabet.js,reverse_alphabet.wasm} .</pre><p>You might be thinking that we are done. The Rust program has been compiled into WASM, but we actually have one more step. We need to modify our WASM file into what I like to call “Truebit flavored WASM”. This involves injecting a few precompiled WASM modules into the one we compiled. We need to do this in order for it to be compatible with the different runtime operations expected of Truebit. This may sound complicated, but don’t worry. The Docker container we installed makes this trivial.We use the preparation script in emscripten-module-wrapper to do this.</p><pre>node /truebit-toolchain/modules/emscripten-module-wrapper/prepare.js \<br>/workspace/reverse_alphabet/reverse_alphabet.js \<br>--file /workspace/reverse_alphabet/alphabet.txt \<br>--file /workspace/reverse_alphabet/reverse_alphabet.txt \<br>--asmjs \<br>--out /workspace/dist</pre><p>Make sure an empty reverse_alphabet.txt is in the root of your project, or else this script will fail( echo &gt; reverse_alphabet.txt ).</p><p>Most notably we injected a filesystem module that implements the basic IO operations we are using in our Rust program. We need this because the WASM runtime environment doesn’t know how to do calls to your operating system by default. After running the above script you should see JSON printed out like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZvXBXkhPvKe1hCKIakUWKA.png" /></figure><p>Make sure to copy the hash field, as you will need it for when you submit the task on chain. If you look in /workspace/dist you should see a globals.wasm file. This is our Truebit flavored WASM file that we can share over the network. We have finally created our Truebit task using the Rust programming language.</p><p>In a follow up article, I will go through how to submit this Task to the network , and how to use the Truebit filesystem.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d96f2ee0a4b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/truebit/writing-a-truebit-task-in-rust-6d96f2ee0a4b">Writing a Truebit Task in Rust</a> was originally published in <a href="https://medium.com/truebit">Truebit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Developing with Truebit: An Overview]]></title>
            <link>https://medium.com/truebit/developing-with-truebit-an-overview-86a2e3565e22?source=rss-bda93e152652------2</link>
            <guid isPermaLink="false">https://medium.com/p/86a2e3565e22</guid>
            <category><![CDATA[truebit]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Harley Swick]]></dc:creator>
            <pubDate>Mon, 29 Oct 2018 22:52:36 GMT</pubDate>
            <atom:updated>2018-10-31T01:40:37.833Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rS39I49DICUPwO5yD6MHbA.jpeg" /></figure><p>Alas, truebit-os has finally been released to the public to use and play around with. We still have a long journey ahead of us, but we are proud of the work that has been done up to this point. We often get the question, ‘How do I use Truebit for my project X?’, and this article is meant to be a detailed response to that question. This article describes at a high level the process of running a task on Truebit.</p><p>Since it might have been a while since you read the <a href="http://people.cs.uchicago.edu/~teutsch/papers/truebit.pdf">whitepaper</a>, I’ll give a refresher on what Truebit does and how some parts of it work. Let’s start with an example. Imagine a developer building the next big thing on top of Ethereum. But oh no, their magical cryptographic algorithm exceeds the block gas limit. What on earth are they going to do? One option they have is to run the algorithm in the form of a Truebit task. In order to do this, a few things need to happen. The first and most important is how input data is expected to be provided. In order to input and output any kind of data with Truebit you have to go through Truebit’s Filesystem.</p><p>Truebit currently supports two types of storage, on-chain storage and IPFS. The on-chain storage works by deploying the data as a smart contract. The data is then accessed by simply passing around the contract address. This is secure, but expensive, and does not scale well. IPFS, is maybe less secure, because of the data availability problem (which is too large of an issue to get into right now), but scales very well. You can use either storage type and access that data in your program (task) as if it was a local file. So before you decide if Truebit is right for you, make sure to take into account all of your needed IO operations and how secure you want those to be. Effective storage is a very big concern of ours and we are actively looking into ways to improve this process for our users.</p><p>The next thing you have to figure out is how to write your program in some form that can be compiled into WASM. Truebit uses WASM because it is quickly becoming <em>the</em> platform to target. The WASM spec is also concise and focused. This makes implementing the WASM interpreter in Solidity simpler, and something we only need to do once. WASM is still new so there are a constraints around which program languages can be used. Garbage collected languages are not very well supported (however, this seems to be changing). As of writing this article, Truebit <strong>ONLY SUPPORTS TASKS WRITTEN IN C, C++, or RUST. </strong>We do not support running smart contracts in Solidity. Which is a common misunderstanding.</p><p>New technologies can come with their own growing pains. WASM compilers are no exception. You will be happy to hear that the truebit-toolchain was specifically designed to make the compilation process easier for developers. I won’t go into the details on how to use it here, because this is well documented in this post <a href="https://medium.com/truebit/truebit-toolchain-transmute-4984928364a7">https://medium.com/truebit/truebit-toolchain-transmute-4984928364a7</a><br>Once you have a nice wasm file to execute, you’ll need an instance of truebit-os running. You can find detailed installation instructions here <a href="https://github.com/TrueBitFoundation/truebit-os">https://github.com/TrueBitFoundation/truebit-os</a>. Once you have the client running you have everything you need to run a Truebit task. I’ll go over some more concepts to highlight how the process works. If you want to see a detailed example application, check out this repo <a href="https://github.com/TrueBitFoundation/example-app">https://github.com/TrueBitFoundation/example-app</a>.</p><p>A lot of tasks require some kind of input and output. If you want a task to get input, you must read it from a file, and if you want the task to create some kind of output, you must write it to a file. How that data is accessed is dependent on the storage type chosen. In regards to the task, you simply use the standard IO operations of whatever language you are using. For the most part, everything else is automated for you by the truebit-os client.</p><p>Now that we have covered installation and compilation steps, I’m sure you are wondering how do I actually submit a task to Truebit to be solved? All task giver’s have to do is call createTask on our IncentiveLayer contract. Figuring out what arguments to put in this function is the hurdle to jump over. The basic createTask method of the Truebit contract, takes a few arguments:</p><ol><li>initHash: You’ll need the initial hash of the task, so there is a deterministic starting point of the task. We are working on making this easier to do.</li><li>codeType: 0 is WAST, 1 is WASM. You’ll know by your file extension of the task.</li><li>storageType: 0 is Blockchain, 1 is IPFS. IPFS is cheaper.</li><li>storageAddress: Contract Address or IPFS hash</li><li>maxDifficulty: Determines the difficulty of the task (1 is okay for testing)</li><li>reward: The amount of TRU tokens offered as a reward</li></ol><p>If you have these parameters figured out then you’re ready to go. If you are expecting output data there might be some extra steps in dealing with the Truebit Filesystem, but that is a case by case basis. The example-app linked above demonstrates one way to do it. As a task giver, there is nothing more to worry about after submitting the task.</p><p>Hopefully, this answered a few questions you had about developing with Truebit. Please stay tuned for any updates. Our development team is working very hard to streamline this process and make developing on Truebit as easy as possible. This product is currently in beta form so please be patient. If you have any issues post them on our Github or ask for help on our Gitter <a href="https://gitter.im/TrueBitFoundation/Lobby">https://gitter.im/TrueBitFoundation/Lobby</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86a2e3565e22" width="1" height="1" alt=""><hr><p><a href="https://medium.com/truebit/developing-with-truebit-an-overview-86a2e3565e22">Developing with Truebit: An Overview</a> was originally published in <a href="https://medium.com/truebit">Truebit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Poor Man’s Virtual FileSystem with 9p, Rust, and a Raspberry Pi]]></title>
            <link>https://medium.com/@hdswick/poor-mans-virtual-filesystem-with-9p-rust-and-a-raspberry-pi-95ea1d4703ea?source=rss-bda93e152652------2</link>
            <guid isPermaLink="false">https://medium.com/p/95ea1d4703ea</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[plan-9]]></category>
            <category><![CDATA[rust]]></category>
            <dc:creator><![CDATA[Harley Swick]]></dc:creator>
            <pubDate>Sat, 20 Oct 2018 21:00:39 GMT</pubDate>
            <atom:updated>2018-10-20T21:00:39.077Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial, I’ll be going through how to setup a basic virtual filesystem between a Raspberry Pi and a laptop.</p><p>To follow along you’ll need a Raspberry Pi, an Ethernet Cable, and a laptop.</p><p>I’m running an Ubuntu laptop, and using the standard Raspian Jessie on the Pi.</p><h3>Setup Raspberry Pi</h3><p>I actually had some difficulty in getting my Raspberry Pi setup the way I wanted. There were a number of gotcha’s that weren’t always mentioned in some of the other tutorial’s I was reading. So I’ll try to lay out all of the steps I took here.</p><p>I recommend using the Raspbian image provided by Raspberry Pi <a href="https://www.raspberrypi.org/downloads/raspbian/">https://www.raspberrypi.org/downloads/raspbian/</a>. We’ll want to ssh into the Raspberry Pi, but the latest versions of raspbian don’t enable ssh by dfeault. So in order to do that, we need to copy an empty file named ssh into the SD card you put the Raspbian image on. Then simply connect the Pi to your home router with the Ethernet cord.</p><p>In order to get the IP address of the Pi, we need to get the IP address of our router. I would just look on Google how to get the IP address for your particular router. Put the IP address in the browser. Then you should see the Pi connected. It showed up on mine with the name raspberrypi. It should have something similar to yours. You can either use the IP address or the hostname. The hostname is obviously easier to remember.</p><p>ssh from your laptop to the Pi with this command.</p><p>ssh pi@raspberrypi</p><p>I recommend changing the password, and you can always change the hostname of the Pi by changing /etc/hostname.</p><h3>9p protocol</h3><p>9p is a protocol designed by Bell Labs for the plan9 operating system. 9p specifies a way to encode/decode binary messages between a client and server in such a way to control a virtual file system. One of the novelties of plan9 was it used the 9p protocol for its entire file system. The OS plan9 isn’t widely used today, but the 9p protocol lives on in other operating systems. With linux, the mount command has a type flag (-t) which we can set to 9p and it will use the 9p protocol. So in any linux distribution there is a 9p client.</p><p>There are a number of different 9p file server implementations. But I was looking for one that I could extend for other projects I have in mind. A great project I found was, rust-9p. The instructions were simple, and the implementation is very readable. For our 9p file server in this tutorial, we’ll simply use the example application that rust-9p includes.</p><p>We will be using that file server over the router’s intranet and mounting the Raspberry Pi’s file to a directory on our laptop. The use case that inspired this for me was that I wanted to edit some code on the Raspberry Pi using my favorite editor configured on my own laptop. I’ve recently been reading a lot about the plan9 operating system and the 9p protocol. A great project I’ve found is rust-9p (<a href="https://github.com/pfpacket/rust-9p">https://github.com/pfpacket/rust-9p</a>).</p><h3>Rust Build Tools FTW!!!</h3><p>We’ll need to build a binary of the rust-9p example application that is compatible with the Raspberry Pi. A cool thing we can do with Rust is build our project for a different operating system then the one our computer is running on. I found this tutorial to be really useful to make that happen: <a href="https://hackernoon.com/compiling-rust-for-the-raspberry-pi-49fdcd7df658">https://hackernoon.com/compiling-rust-for-the-raspberry-pi-49fdcd7df658</a></p><p>Once you get the dependencies installed by the following the tutorial you can build the unpfs binary with this command:</p><pre>cd rust-9p/example/unpfs<br>cargo build --target=armv7-unknown-linux-gnueabihf</pre><p>Then in /target/armv7-unknown-linux-gnueabihf/release you should see the unpfs binary. You can then use sftp to put the binary on the Raspberry Pi.</p><p>Once you get the binary on the Pi, you can start the File Server like this:</p><pre>./unpfs &#39;tcp!0.0.0.0!564&#39; /exportdir</pre><p>Then on your own laptop you can connect to the server and mount the file.</p><pre>sudo mount -t 9p -o version=9p2000.L,trans=tcp,port=564,uname=$USER *RASPBERRY-PI-IP-ADDRESS* /mountdir</pre><p>Now anything of in /exportdir will show up in /mountdir, and any writes to /mountdir will change /exportdir.</p><h3>Conclusion</h3><p>You may be wondering if there are other possible easier ways to connect to a virtual file system, and you are probably correct. However, I think this approach is interesting in several ways. First, from an educational standpoint, I differently learned a lot, and will never think about file systems the same way. The second reason is that sometimes other solutions might be more complicated, or you have resource constraints. This is an easy replacement. The third, and final reason, is that other options don’t give you the ability to extend a file server for your own purposes. Using the rust-9p as a library, all we have to do is implement the FileSystem trait, and we can be serving up whatever you want. Imagine implementing something like Google search but using the file system instead of a browser. I’m very interested in how far we can push the boundaries for these types of applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95ea1d4703ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unix Domain Sockets (IPC) with Elixir]]></title>
            <link>https://medium.com/@hdswick/unix-domain-sockets-ipc-with-elixir-ec027f83c511?source=rss-bda93e152652------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec027f83c511</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Harley Swick]]></dc:creator>
            <pubDate>Sun, 14 Oct 2018 22:07:35 GMT</pubDate>
            <atom:updated>2018-10-14T22:07:35.182Z</atom:updated>
            <content:encoded><![CDATA[<p>Lately, I’ve been working on my Ethereum JSON RPC Client <a href="https://github.com/hswick/exw3">https://github.com/hswick/exw3</a>. One of the dependencies it uses is <a href="https://github.com/exthereum/ethereumex">https://github.com/exthereum/ethereumex</a> which is a lower level RPC Client and handles sending messages back and forth from an Ethereum node. The team behind ethereumex had an open issue <a href="https://github.com/exthereum/ethereumex">https://github.com/exthereum/ethereumex</a> to add an IPC client. Along with this issue they included a nice little bounty of 0.4 eth. The idea behind this issue is that your program can communicate with the Ethereum node using IPC instead of HTTP. The benefits of this are performance and security. The security aspect is crucial because it enables signing transactions which involves sending the password to the Ethereum node. However, doing this over the wire with HTTP exposes you to packet sniffing attacks. Having this feature was a must, and receiving a nice little bounty was an extra bonus! In the end I was able to get this to work, and wanted to share my experience with the community because I didn’t feel this feature was well documented.</p><p>The reason this feature had not been added to ethereumex before is that the dogma around IPC with Elixir is that it couldn’t be done. Erlang communicates with processes in its VM not ones of the outside world. <a href="https://stackoverflow.com/questions/34711738/unix-domain-sockets-in-elixir">https://stackoverflow.com/questions/34711738/unix-domain-sockets-in-elixi r</a> A lot of folks pointed towards the prockets library. But it didn’t look like a very elegant solution. After some digging it seemed that this feature was possible without using a library. I stumbled upon this post <a href="https://elixirforum.com/t/running-phoenix-on-a-unix-socket/9703">https://elixirforum.com/t/running-phoenix-on-a-unix-socket/9703</a>. The user Voltone mentioned looking into Erlang’s :gen_tcp. And included this link <a href="http://erlang.org/doc/man/inet.html#type-local_address">http://erlang.org/doc/man/inet.html#type-local_address</a>. I found this to be a bit cryptic, but it was a good start.</p><p>I’ve never used :gen_tcp before so I looked up some tutorials to get me started. Elixir provides a good tutorial <a href="https://elixir-lang.org/getting-started/mix-otp/task-and-gen-tcp.html">https://elixir-lang.org/getting-started/mix-otp/task-and-gen-tcp.html</a>. Basically create a GenServer that acts as the Server and you can send and receive messages over a port. Easy enough. What I wasn’t sure about was what to put for the connection information.</p><p>Turns out it was fairly trivial:</p><pre>opts = [:binary, active: false, reuseaddr: true]                           response = :gen_tcp.connect({:local, state[:path]}, 0, opts)</pre><p>Instead of a url pass a tuple: {:local, *path to unix socket*}. And instead of a port number, simply pass in 0. Wala! The feature worked. One thing to look out for is that your receive message might be getting cut off, so you’ll have to make sure to receive all of it.</p><p>If you want to see the full solution check it out here: <a href="https://github.com/exthereum/ethereumex">https://github.com/exthereum/ethereumex</a></p><p>So in the end, I go the feature working, submitted the PR and it was merged. I included the new version into my library and I was able to reduce my test’s time by 5x. So big performance and security gain, couldn’t be more happy!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec027f83c511" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reasons I dislike JavaScript]]></title>
            <link>https://medium.com/@hdswick/reasons-i-dislike-javascript-a843d9fe6830?source=rss-bda93e152652------2</link>
            <guid isPermaLink="false">https://medium.com/p/a843d9fe6830</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Harley Swick]]></dc:creator>
            <pubDate>Sat, 13 Oct 2018 21:19:17 GMT</pubDate>
            <atom:updated>2018-10-13T21:19:17.177Z</atom:updated>
            <content:encoded><![CDATA[<p>When choosing a programming language it is important to balance a number of considerations. Is your choice merely a nicer syntax or are the reasons deeper? You should be honest with yourself, because these things matter. When committing to working on a long term coding project, it is like a marriage. You’ll be using that language all day, every day. Being attracted to that language is important, it makes you enjoy your stay. However, can that language support you in times of need?</p><p>JavaScript has a lot of things going for it. For one, it is the most programming language in the world. Working on a hackathon project, and need a language everyone knows? JavaScript is probably the first choice. With popularity, brings a rich ecosystem. In a ‘winner takes all’ type way. More libraries, means more people are drawn to it, and so on. Why is JavaScript so popular though? Simple, it is the only language that works in the browser. The fact that JavaScript is standardized for the Web made it the new C. It has an approachable syntax that is inherited from the Algol family (think C, Java, etc). The dynamic typing and anonymous functions provides a great deal of flexibility not seen in other languages. However, it can be argued that these blessings are also a curse.</p><h3>Ecosystem</h3><p>JavaScript’s popularity has brought a lot of libraries for the ecosystem, but this brings the difficulty of choosing which library to use. For whatever task you are thinking of there is probably a JavaScript library, but there are also probably several libraries. Some of these differences might be technical, some of the differences might simply be tribal. One person/company is putting their weight behind a project while others are supporting another. What happens when you finally choose a library, and then 6 months later that library is no longer cool? This is what is known as JavaScript fatigue. Instead of working on an app, developers are forced to learn ever new libraries, with more than likely marginal differences from before. One could argue though that this phenomena is a symptom of the relative youth of JavaScript in its new glory. Node.js is less than 10 years old, combine that with its fame, and you are going to get chaos. However, over time, the dust might settle and the community might converge on certain ideas. I think this is possible, but looking at the current state of affairs, I’m guessing improbable. Even npm isn’t safe from this social phenomena. Now I won’t go into this more, because this problem is well documented. Usually the people complaining the most are in the JS ecosystem!</p><h3>Language Itself</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*18Z_GybOdi9iBVv3.jpg" /></figure><p>So that’s just the ecosystem, what about the language itself? Well, like I said earlier it is an approachable language, and the flexibility it provides is useful. Like all languages, JavaScript is a product of its history. The latest changes have been with ES6 which provide async/await and some other functional features. Also, now that ES6 is supported by all browsers and Node.js you no longer need a transpiler to transpile JS into… JS. This has been a huge improvement. However, these new changes are not without warts. The async/await macro does not play nice with some of the enumeration operations like reduce and forEach. Which cause a lot of lost time debugging problems that were introduced because the language can’t support intuitive design due to backwards compatibility reasons.</p><h3>Low Skill Cap</h3><p>My biggest complaint with JS is that it is simply boring. There is a very low skill cap. Once you learn modules, promises, and how to avoid the bad parts of JS, then that’s it. Prototypes are interesting, but they are just hacks for objects. There is a very good reason the language is boring. It is because the language spec has to be supported by all of the browsers, and they can’t spend all their time constantly adding new features. This results, in one, using a lot of libraries, which leads to issues I stated above. I think this is an important point to make. When working on long term projects this can accelerate fatigue and burn out. Who wants to work all day every day on a project that uses uninspiring tooling? I don’t. What makes languages interesting to me is that I can constantly evolve as a developer, there are deeper and more interesting things to learn. I don’t feel like I get that with JavaScript.</p><p>The other issue with JS being a low skill cap, is that it means as a JavaScript developer you are more replaceable. This has to be balanced with a language being complicated for complexity sake (think Brainfuck). But if you spend all your time in this language, you should be concerned. You are replaceable, and you probably don’t have as much of a diverse outlook on architecture as other developers.</p><h3>Concurrency</h3><p>JavaScript has been concurrent for a long time. The asynchronous runtime allows it to handle a large amount of tasks at the same time. Node.js can scale, no doubt about it. But I would argue that the concurrency primitives that the language provides are rather simple. If all you have is a hammer, everything looks like a nail. This situation has been improved with promises so we don’t end up in callback hell. However, with this, most of the libraries I use return promises. Which is fine, except for the fact that 90% of the time I’m using async/await it is just to make asynchronous code run synchronously.</p><h3>Conclusion</h3><p>JavaScript is an unavoidable language. It pulls in all developers with its gravity like a blackhole. It is much better to embrace it and learn how to use it if you want to be successful. For small front end projects, I usually opt for vanilla JS. For more complex things, I like Elm or Vue. But if you don’t have to work on the browser, I think it important to give some thought on alternatives. Because, in my opinion, it will save you time and probably make you a happier developer.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a843d9fe6830" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Illusion of Type Safety on the EVM]]></title>
            <link>https://medium.com/@hdswick/illusion-of-type-safety-on-the-evm-1e09e9c7e46b?source=rss-bda93e152652------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e09e9c7e46b</guid>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Harley Swick]]></dc:creator>
            <pubDate>Wed, 02 May 2018 03:52:14 GMT</pubDate>
            <atom:updated>2018-05-02T06:05:35.298Z</atom:updated>
            <content:encoded><![CDATA[<p>A couple weeks ago, while working on some code for Truebit, I ran into a perplexing smart contract bug. All I had to work off of was the dreaded ‘invalid opcode’ error message. So what does any good Solidity dev do? They comment out all the require statements and see which ones work (this was pre-require w/ reason days). Even after that, still the same error message. At that point I had given up for the day. I came back to the code after not thinking about it for a while, and found the painfully obvious bug. What had happened was that I had switched some arguments around in my JS code. Instead of passing in an address to another smart contract as a parameter, I had simply passed in 9. Doh! But how could this be? Solidity is typed, so shouldn’t it stop things like that? Nope. The Solidity compiler can only find your mistakes at compile time, not at runtime. This is a very obvious statement, but I think it has a lot deeper meaning.</p><p><strong>The Deeper Meaning</strong></p><p>The deeper meaning is that Solidity types are all an illusion. They are there simply to make it easier to write predictable programs that developers are used to. It all goes back to the<a href="https://ethereum.github.io/yellowpaper/paper.pdf"> Ethereum Yellowpaper</a>, which specs out the EVM. As part of the specification, the EVM only has one data type and that is a 256 bit word (32 bytes). All of the other data types from addresses, integers, etc. are represented as 256 bit words in the EVM. This explains why the EVM was perfectly content with me passing it 9 instead of a valid address.</p><p><strong>Why Does This Matter?</strong></p><p>The reason this matters is that in programming, low level details have an effect on high level architectural decisions. Striving to make your architecture fully type correct shouldn’t be that high of a priority if it doesn’t have much effect on runtime behavior. The only time this matters is when you are trying to get your code to compile. Your user or your boss doesn’t care if the code passes the type checker, they care if it works. Once again, don’t let types dictate high level decisions when writing dapps. Another reason is that perhaps you are finding Solidity’s basic types to be too rigid for your problem. Well, simply take advantage that all types are bytes32. This is essentially what is being done with <a href="https://blog.zeppelinos.org/proxy-patterns/">OpenZeppelin’s Proxy Pattern </a>.</p><p><strong>What Can Be Done?</strong></p><p>Let’s go back to my bug story. How could this have been prevented? Well, obviously solc can’t do anything to help. This has to be done by the rpc client (think web3.js or truffle). Now some may say that TypeScript is the answer to my problem (and to all of humanity’s problems). However, I’m a big skeptic of typed programming languages. Instead, I think that any contract abstraction worth their salt should be using the contract ABI to assert whether or not you passed in the correct data. This is along the lines of<a href="https://clojure.org/guides/spec"> clojure.spec</a>. In my opinion, spec’s are much more powerful than types. A type checker (like TypeScript) can only tell you whether or not you passed in an integer. But something like clojure.spec can tell you whether or not that integer is within a certain range (for example: preventing you from doing integer underflow/overflow). I have some ideas on how such an implementation would look, and have done some experiments. Maybe, one day I’ll even put out a solution that others can use. For now, I can hope that others keep this in perspective while building their software and be better off.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e09e9c7e46b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[FalseByte goes to ETHDenver]]></title>
            <link>https://medium.com/@hdswick/falsebyte-goes-to-ethdenver-a7f0968d4ef8?source=rss-bda93e152652------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7f0968d4ef8</guid>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Harley Swick]]></dc:creator>
            <pubDate>Thu, 01 Mar 2018 20:05:45 GMT</pubDate>
            <atom:updated>2018-03-01T21:32:38.637Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*zH4-kTl4wWBV7l-5-wAirQ.png" /></figure><p>Recently I had the chance to participate in the ETHDenver Hackathon competition with a few friends. It was easily one of the coolest hackathons I’ve been to. The chill room with the bean bags and the house DJ was definitely my favorite. Also, I kind of freaked out when I got a ColoradoCoin and found out I could use it with the food trucks. The whole experience felt a lot like devcon but even more hacking focused and a little more laid back. Most people might’ve seen Truebit representing in the art room on the 6th floor, but we also had a team competing in the hackathon. I was a part of that team, and sort of the ring leader. I was accompanied by fellow Truebit Dev Sami and our friend Deon. Collectively, we called ourselves Team FalseByte, aka hacker alter-ego of Truebit. (Shout out to Matt Condon for the FalseByte name suggestion)</p><p>In the weeks leading up to the event we were trying to figure out what we wanted to do. I had been throwing around some ideas around using a Truebit Lite architecture to do scalable voting. Which is basically a stripped down Truebit system that does one function, instead of implement a Turing Machine. When all of a sudden the Aragon team notified us of their Nest proposal <a href="https://github.com/aragon/nest/issues/6">https://github.com/aragon/nest/issues/6</a>. The goal of the Nest proposal was a verifiable carbon voting mechanism. We originally thought about using a Truebit Lite architecture but ended up finding an even simpler alternative.</p><p>This proposal was made to try to solve some of the current issues with voting on Ethereum using token balances. These were all new problems to me. Yet very fun to think about. As they were different than the problems we are solving at Truebit. Voting with tokens is similar to a group of shareholders making a decision and the decision being weighted by how many shares one has. Simple implementations of these systems works for small groups, but not so much for pseudo-anonymous entities like a bunch of random Ethereum accounts. Basically, with decentralized organizations you can’t trust each other, nor should you. However, a good decentralized system will allow people to act in a trustless manner. Creating a trustless voting system without making limiting tradeoffs isn’t easy. The main attack vector for this kind of system is the Double Vote. Which I will explain with an example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*EyeWh1LIjDgR1GZ04Q6zTw.jpeg" /><figcaption><a href="https://9gag.com/gag/amzdLdy/doge-meeting">https://9gag.com/gag/amzdLdy/doge-meeting</a></figcaption></figure><p>Let’s say there is a group of hacker shiba inu’s trying to decide if they should get pizza or burritos for dinner. The weight of their vote is denominated by how much balance they have in the WOW ERC20 token contract (proposed ETH-DOGE token). ShibeZero and ShibeOne are going to be colluding together to get pizza. This is because they know that ShibeTwo has more WOW than both of them combined. And ShibeTwo loves burritos. So how they are going to try to win is with a Double Vote.</p><p>ShibeThree votes for burritos with a balance of 40000 WOW. Then ShibeZero votes for pizza with a balance of 15000 WOW. In order to beat ShibeThree, he will perform the Double Vote trick. ShibeZero will transfer all of the balance to a colluding party (a sybil version of this attack could also work). ShibeOne originally had 20000 WOW. After ShibeZero sent the tokens, ShibeOne now has 35000. ShibeOne now votes with a weight of 35000 WOW. So the current voting weight for pizza is now 50000 (15000 + 35000), while burritos is only 40000. Even though collectively ShibeZero and ShibeOne only have 35000 tokens. This seems like a pretty glaring problem for token based voting.</p><p>However, there are implementations that defend against this attack. The simplest solution is to lock up tokens upon voting. But this creates a lot of risk for the parties involved. The other option is the MiniMe token which takes snapshots of balances at each block. This is effective but could potentially be very expensive. Team FalseByte’s implementation works differently. We use an offchain monitoring agent to watch for token transfer’s and then update the balance on the voting contract.The way it works is that voting participants run these monitoring agent’s for the duration of the voting period. When they see a token transfer event they update the recorded balance on the voting contract. Anyone can update the balance because that data is retrieved trustlessly from the ERC20 contact via the balanceOf method. This is very similar to how carbon voting has been done before, but has the improvement of being done on the blockchain and using peer-to-peer enforcement.</p><p>So after 36 hours of hacking we were able to come up with the smart contracts, a test suite, and a command line interface. We demoed in front of the judges, which I unfortunately messed up a little bit at the last second… of course. But we did win some of Aragon’s bounty which was the goal anyways. (Side note: we were in group 5 which means we were beat out by BlockStreet Boys…lol). Overall it was a good time in Denver and I loved hanging with all the cool Ethereum peeps. This was a fun project that gave me a chance to push my skills as a developer. I’m looking forward to collaborating with the Aragon team on using this new voting system we developed. Hopefully, one day DAO’s all over will be using the falsebyte carbon voting mechanism.</p><p>Here is the repo: <a href="https://github.com/hswick/falsebyte-carbon-voting">https://github.com/hswick/falsebyte-carbon-voting</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7f0968d4ef8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>