<?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 Luciap Technology on Medium]]></title>
        <description><![CDATA[Stories by Luciap Technology on Medium]]></description>
        <link>https://medium.com/@luciap_tech?source=rss-7c04d54ad4c3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yijvsM1KhQkiFooDkr1-6w.jpeg</url>
            <title>Stories by Luciap Technology on Medium</title>
            <link>https://medium.com/@luciap_tech?source=rss-7c04d54ad4c3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 11:44:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@luciap_tech/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[Orax pool is closing down]]></title>
            <link>https://medium.com/@luciap_tech/orax-pool-is-closing-down-fc4774ca4dd3?source=rss-7c04d54ad4c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc4774ca4dd3</guid>
            <dc:creator><![CDATA[Luciap Technology]]></dc:creator>
            <pubDate>Tue, 16 Jun 2020 15:28:09 GMT</pubDate>
            <atom:updated>2023-01-03T04:15:54.526Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/128/0*POXRYc-pZfMpc7-c.png" /></figure><p>It is with sadness that we are announcing that Orax pool will be<strong> closing down on June 27 2020</strong>.</p><p>We have been very proud to be the first PegNet mining pool running since day 1, and we want to give a huge thank you to the thousands of miners who have been mining with us along the way!</p><p>Our company is refocusing its time and resources. Unfortunately running Orax Pool has not been a profitable business in its 10 months of existence (even including the generous donations we received) and would likely not be in the foreseeable future.</p><h4>Important dates</h4><p><strong>June 27 2020, 9:00am (PST):</strong> mining coordinator will be turned off, effectively disconnecting all miner clients.</p><p><strong>June 27 2020, 11:00am (PST):</strong> after a thorough audit of all accounts balances, any pending amounts will be paid out to miners (regardless of the payout threshold set).</p><p>The oraxpool website will remain online until at least <strong>August 1 2020</strong> to allow users to connect and download their payout history. We highly recommend you download the sheet of your payouts for accounting/tax purpose. To do so go to the <a href="https://www.oraxpool.com/user/payouts">Payouts page</a> and click the “Download Payouts History” button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HholHEPq90MNQvxdRTyWkA.png" /></figure><p>If you have more question you can head to the <a href="https://discord.gg/ZxF9ydP">Orax Pool Discord server</a> to chat. We also recommend you join the <a href="https://discord.gg/Xz2ZN6p">official PegNet Discord</a> to continue getting involved in the PegNet ecosystem.</p><p>One last big thank you to all the users who entrusted us for mining on PegNet and we wish you the best of luck!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc4774ca4dd3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Orax mining pool system architecture]]></title>
            <link>https://medium.com/@luciap_tech/the-orax-mining-pool-system-architecture-65d3b282c7aa?source=rss-7c04d54ad4c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/65d3b282c7aa</guid>
            <category><![CDATA[pegnet]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[decentralized-finance]]></category>
            <category><![CDATA[mining-pool]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Luciap Technology]]></dc:creator>
            <pubDate>Mon, 16 Dec 2019 19:48:24 GMT</pubDate>
            <atom:updated>2019-12-16T19:48:24.263Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.oraxpool.com/">Orax</a> was the first mining pool created for <a href="https://pegnet.org/">PegNet</a>. The software was built from scratch and tailored for the specific features of that network. This article presents the overall architecture of our system and some improvements plans for the future.</p><p>This article assumes a basic understanding of how PegNet mining works, if you are not up to date you can <a href="https://github.com/pegnet/pegnet/wiki/Mining">read the official wiki</a>.</p><p>Note this article doesn’t cover any security aspects of our architecture.</p><h3>Architecture overview</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*lJ_uQJWxgbMhpls1NzhHlA.png" /><figcaption>The complete Orax system architecture</figcaption></figure><p>Here is an overview of the different components of the system:</p><ul><li><strong>orax-orchestrator</strong>: this is the central piece of the system, it builds Oracle Price Records (OPR), broadcast mining jobs to all the miners, collect their mining work and submit entries for a chance to earn PEG tokens. It was written in Golang for performance and concurrency handling reasons. We dedicate a section to the orchestrator further down this article.</li><li><a href="https://gitlab.com/oraxpool/orax-cli"><strong>orax-cli</strong></a><strong>: </strong>this is the application ran by miners. It connects to the orchestrator to receive mining jobs and send back its work. The bi-directional communication relies on a simple protocol we developed based on FlatBuffers messages over WebSocket. The client is written in Golang (easier to integrate with the orchestrator and yields good performance). The client is also the entry point to register new accounts and miners and allows running performance benchmarks.</li><li><strong>REST API: </strong>we have a classic Node.js REST API backend that handles requests from our website and some non-critical commands of the miner client. This is the gateway to our data stored in our database.</li><li><a href="https://www.oraxpool.com/"><strong>Website</strong></a><strong>:</strong> our website that serves public information and tools as well as our users area where they can track their rewards, miners and payments. It’s built on Vue.js + Vuetify 2.</li><li><strong>Database:</strong> we opted for a MongoDB replica set.</li><li><strong>Factom nodes: </strong>we maintain a fleet of Factom nodes connected to the decentralized <a href="https://www.factomprotocol.org/">Factom Protocol</a> network (the underlying blockchain of PegNet). It is critical for the pool to be able to read and write data into the blockchain. Because distributed systems can be capricious it’s important for us to have access to multiple nodes for redundancy.</li><li><strong>Monitoring and alerting</strong>: we use <a href="https://prometheus.io/">Prometheus</a> to instrument the orchestrator and <a href="https://grafana.com/grafana/">Grafana</a> for visualization and alerting. We are very satisfied by this great open-source combo.</li></ul><p>The orax-orchestrator, the backend API and the website are all fronted by Nginx proxies.</p><h3>Zoom in on the Orax orchestrator</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*v50ZhBJ9CEO3euXacQ7eFA.png" /><figcaption>Orax orchestrator internals</figcaption></figure><p>Contrary to most PoW coins, PegNet miners don’t compete to be the first to find a new block. They use their hashing power to “vote” for the oracle price of different assets. The mining time is fixed by the block time of the underlying blockchain Factom. As a consequence the state of the Orax orchestrator changes based on blockchain events (new block, end of block…) and follows a sequence of predetermined steps (build OPR, send mining job, collect shares…). So it’s naturally that we modeled the core of the application around a workflow component.</p><p>The second critical component of the orchestrator is what we called the “share collector” which is constantly connected to all the pool miners over WebSockets. It is responsible to continually receive and validate all work sent back by every single miner. The verification involves computing the <a href="https://github.com/pegnet/LXRHash">LXR Hash</a> of the data which is a very slow operation and prompted us to spend extra time to optimize this code path. Golang goroutines were invaluable here to easily process shares concurrently.</p><h4>Scaling the orchestrator horizontally and geographically</h4><p>At our present scale the current design is working very well, and we could scale vertically (migrate to a server with more CPUs) to accommodate quite some growth. Yet we are already planning the next iteration of our design: we want to extract the logical “share collector” component to make it an independent micro-service that can be deployed in multiple regions of the world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*scPr3QxBZeAZUFiYKGYnsA.png" /><figcaption>Multi share collector architecture</figcaption></figure><p>That refactoring would kill two birds with one stone:</p><p><strong>Geographical proximity</strong>: Orax pool has miners literally all around the world, and many of them are individuals mining from home. That means their home connection to our server located in East Canada can be slow and unreliable. By having share collectors located in strategic regions of the world we can get closer to our miners and guarantee a better service. The share collectors will then leverage better quality networking to communicate with the central orchestrator.</p><p><strong>Horizontal scaling and redundancy: </strong>that micro-service architecture enables horizontal scaling as we can spin up as many share collectors as we wish. Share collectors communicate with our miners and are the bottleneck to take on more load. By also adding a fail-over mechanism (not described here) we would also be able to increase the overall resiliency of our system by being able to redirect miners to another share collector in case of failure of one of them.</p><p>The main drawback of this new design is increase of the overall complexity of the system and increase of the infrastructure cost.</p><h3>Conclusion</h3><p>Designing and implementing the whole Orax stack has been an extremely rich and exciting experience. We have laid out a strong foundation and have anticipated future growth in our current design. To date we have gained the trust of hundreds of miners around the world who regularly praise how user friendly the whole mining experience with Orax is. We will continue to strive to provide the best mining service to all PegNet miners.</p><p>Start mining with Orax Pool: <a href="https://www.oraxpool.com/">https://www.oraxpool.com</a></p><p>Orax Twitter: <a href="https://twitter.com/OraxPool">https://twitter.com/OraxPool</a></p><p>Orax Discord: <a href="https://discord.gg/ZxF9ydP">https://discord.gg/ZxF9ydP</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65d3b282c7aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Launching Orax: a PegNet mining pool]]></title>
            <link>https://medium.com/@luciap_tech/launching-orax-a-pegnet-mining-pool-bcc6aacc8520?source=rss-7c04d54ad4c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/bcc6aacc8520</guid>
            <category><![CDATA[pegnet]]></category>
            <category><![CDATA[mining-pool]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[oracle]]></category>
            <category><![CDATA[factory]]></category>
            <dc:creator><![CDATA[Luciap Technology]]></dc:creator>
            <pubDate>Mon, 04 Nov 2019 15:43:28 GMT</pubDate>
            <atom:updated>2019-11-04T15:43:28.558Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/128/1*RKT5LVnICqbkQFPMdSiECw.png" /></figure><p><strong>Luciap Technology Inc. is glad to announce the public launch of Orax, a </strong><a href="https://pegnet.org/"><strong>PegNet</strong></a><strong> mining pool: </strong><a href="https://www.oraxpool.com/"><strong>https://www.oraxpool.com</strong></a><strong>.</strong></p><p>We have worked for the last few months on this project and have been running a private beta for more than 2 months and redistributed over 10 millions PEG to our fellow miners. We are now ready to open up to the public.</p><p>We have focused our attention in making the mining experience very simple: using the Orax software you can be mining on the PegNet and start earning PEG within just a few minutes. To do so, just follow our <a href="https://docs.oraxpool.com/getting-started/quickstart-guide">quickstart mining guide</a>. If you are wondering why you should mine with us, <a href="https://docs.oraxpool.com/getting-started/faq">check out our FAQ</a>.</p><p>Whether you want to mine or you are just curious you are invited to <a href="https://discord.gg/ZxF9ydP">join our happy little community on Discord</a>.</p><p>Happy mining everyone!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*V0tmaHbhDy2bW7PFqqbG7g.png" /></figure><p>Haven’t heard about PegNet yet? PegNet is a stablecoin network creating the foundation for Decentralized Finance. Checkout the project website: <a href="https://pegnet.org/">https://pegnet.org/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bcc6aacc8520" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design patterns on Factom]]></title>
            <link>https://medium.com/@luciap_tech/design-patterns-on-factom-160ece591e85?source=rss-7c04d54ad4c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/160ece591e85</guid>
            <category><![CDATA[factom]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Luciap Technology]]></dc:creator>
            <pubDate>Tue, 18 Dec 2018 19:56:00 GMT</pubDate>
            <atom:updated>2018-12-18T20:03:51.292Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2cZZvLsFmmpuxLsMaQUdGw.png" /></figure><p><strong>Factom is the data layer of the blockchain space: any arbitrary data can be published to Factom at a low and fixed cost ($0.001/kb). That opens up a lot of possibilities. Over time several design patterns have emerged for applications to efficiently and safely leverage that powerful capability. This article is directed towards developers who are already familiar with the Factom concepts of chains and entries and who are looking for a list of good practices for building a production ready application on Factom.</strong></p><p>In this article we’ll illustrate a Factom entry using a table of this form:</p><pre>+--------+--------------+<br>| Ext[0] | &lt;0xab45baab&gt; |<br>| Ext[1] | &lt;0x676c67a4&gt; |<br>+--------+--------------+<br>| This is the content.  |<br>+-----------------------+</pre><h3>Data on Factom</h3><p>Factom entries can store any data. You may have heard that Factom was meant to store hashes of documents, but that is really only one use case. Whilst there are many good reasons to exclusively publish hashes of off-chain data, there are also occasions where applications may want to publish more expressive data.</p><h4>Public immutable data for ever</h4><p>Just because you have the ability to store anything on Factom, it does not mean that you should. When you are designing your application and you are thinking of storing a piece of data you should ask yourself:</p><ul><li>Is it ok for this data to be public? Absolutely anybody can see it; the public protocol has no privacy features.</li><li>Is it ok for this data to be immutable? You cannot edit a mistake.</li><li>Is it ok to be possibly accessible <em>forever</em>? Eternity is a long time, project yourself into future situations.<br> <br>The consequences of not seriously evaluating those properties can be dramatic:</li><li>Legal issues. Think “GDPR” here. Putting personal data on a blockchain is most likely a terrible idea.</li><li>Exposing any sensitive/private data could jeopardize your competitive advantage.</li></ul><p>A natural response might be to think that you can simply encrypt the data before putting it on the blockchain. I must give you a word of caution, and repeat that e<em>ternity is a long time</em>. Encryption algorithms have a limited lifespan, they do get broken after a certain time (due to technological advancement), which means that at some point in the future your data may be deciphered. If you data has an “expiration date” (i.e. it becomes <em>completely </em>worthless after that date) that is prior the expected lifetime end of your encryption algorithm, then you may be fine. To sum up: be aware that encryption of data on a blockchain only gives you temporary privacy and you must evaluate the impact of your data getting revealed at some point in the future.</p><p>I’d extend the above by stating that it is especially important on blockchain that you don’t rely on any <a href="https://en.wikipedia.org/wiki/Security_through_obscurity">security through obscurity</a>. Do not assume you’re safe because people don’t know which chain you are using or that they won’t comprehend the data in your entries; all the data is public and they have a lot of time to figure it out (eternity is a long… ok ok enough).</p><p>But what happens if someone stores something illegal on Factom (e.g. child pornography), wouldn’t all the people running nodes of the Factom network now be operating illegally as they are effectively maintaining a database with illegal content? That would be an existential threat waiting to happen. The Factom network has a mechanism to protect itself against that: local erasure. While it is impossible to censor the content of the Factom network in its entirety, individual nodes of the network have the choice to remove an entry from their database without altering the integrity of the blockchain. If an entry has been locally erased from a node that means that particular entry cannot be queried on that particular node, but it’s possible that the content is still available on another node.</p><h4>Hashes</h4><p>A cryptographic hash function is a mathematical algorithm that maps data of arbitrary size to a bit string of a fixed size (a hash). It is designed to be a one-way function, that is, a function which is infeasible to invert. You provide a hash function (you may have heard of SHA or BLAKE functions) with a data input (a file for instance) and you get a hash as an output that will look something like <em>e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855</em>. That string can be used as a finger print of the the input file: it is impractical to find/create another file that would yield the same hash, and it also means that if the original file is modified, even by a single byte or character, the hash would be completely different. It is impossible to reconstruct the file just from its hash.</p><p>Hash functions have been around for decades and have found numerous applications. Using them in the context of blockchain brings a new dimension to it: storing hashes in Factom allows to “secure” any file against modifications (or removal) and show the proof to the world, making it accessible for any third party to audit the integrity (non alteration) of said files. The typical configuration would be to store some files in any storage service (it can be private or public, centralized or not, it is up to you) and store the hashes of those files in a chain in Factom. The idea is that you can share one of those files with another party and prove undeniably that the file hasn’t been altered since its fingerprint was recorded on Factom. Or the other party can look at the hashes recorded on chain and ask you to provide the corresponding files, so it can verify that you’re not hiding any files and that they are unmodified.</p><p>You’ll notice that hash function properties conveniently remove the biggest concerns expressed in the previous section: hashes just by themselves don’t convey sensitive information. Exposing them publicly, without possibility to edit them and for ever shouldn’t have you too worried if your application was properly designed (hash functions don’t hide the input if the input can be easily guessed though! You’d need to add a secret to the recipe in this case, see <a href="https://en.wikipedia.org/wiki/HMAC">HMAC</a>).</p><p><em>It’s worth noting that hashes are a pseudonymisation technique under EU law, not an anonymisation technique. That means hashes are still considered personal data for the purposes of GDPR.</em></p><h3>Data authentication</h3><p>Factom can store any data, and anyone owning Entry Credits can insert data into the blockchain. It is important to keep in mind that chains are not permissioned, anyone can write entries in “your chain”, whether it’s intentional or not. Two direct consequences of this situation:</p><p>1. A malicious actor can try to alter the state of your application by inserting unwanted data in chains used by the app.</p><p>2. Your chain can be spammed with garbage data, potentially slowing down your application depending how it was designed. There is no real way to prevent that so your application should be designed to be able to efficiently filter out that spam.</p><h4>Example of a counter app</h4><p>We’ll use the example of a simple counter application in the rest of this section to illustrate the patterns we are presenting. That application will keep track of a single value (number) and be able to update it over time. Even for such a trivial application you should still evaluate whether it is acceptable to store that piece of information on a public blockchain. If the counter keeps track of the number of guards escorting a valuable asset at all time, that may be not be a good idea!</p><p>The initial and naive implementation of this counter would be to create a chain for the counter, and every time the counter is updated insert an entry with the new value in that chain. An entry to update the value of the counter to 42 would look like:</p><pre>+---------------------+<br>| (no external IDs)   |<br>+---------------------+<br>| 42                  |<br>+---------------------+</pre><p>Immediately you realize that in this simple form the counter can be set to any value by anyone, making it completely unreliable.</p><h4>Cryptographic signature</h4><p>One solution is to authenticate the source of the data in the entry using <a href="https://en.wikipedia.org/wiki/Public-key_cryptography">public-key cryptography</a>: the trusted source of the information should sign the data and put the signature along the data so anyone can verify it.</p><p>A common pattern with Factom is to use the first entry of a chain as a “registration” or “header” entry that contains information to help with the interpretation and validation of subsequent entries. Using that idea the first entry of our counter chain will contain the public key(s) of the source(s) that will sign the counter updates. Then the application reading the values of the counter can verify that each update is properly signed, and if not, ignore the entry, effectively preventing anyone not in possession of the private key(s) to alter the counter value.</p><p>The first entry of the counter chain would look like:</p><pre>+--------+---------------------------------------------------------+<br>| Ext[0] | factom-counter                                          |             <br>| Ext[1] | ed25519                                                 |             <br>| Ext[2] | &lt;0x591b76f87bbea9eab70603c0a728999a25b2afac936fbeb3...&gt; |<br>+--------+---------------------------------------------------------+</pre><ul><li>Ext[0] is a human readable marker. Not strictly necessary, but you’ll often find it useful to use such marker in your parser code to quickly identify the nature of the chain.</li><li>Ext[1] indicates the type of asymmetric key used, here <a href="http://ed25519.cr.yp.to/">ed25519</a>.</li><li>Ext[2] the 32 bytes ed25519 public key to be used to verify the signatures of the following entries.</li></ul><p>The following entries update the value of the counter and take the form of:</p><pre>+--------+---------------------------------------------------------+<br>| Ext[0] | counter-update                                          |<br>| Ext[1] | &lt;0x8dbcf489023412b59d84d2675991c82d27b7e40541c34f6f...&gt; |<br>+--------+---------------------------------------------------------+<br>| 1989                                                             |<br>+------------------------------------------------------------------+</pre><ul><li>Ext[0] contains a human readable marker indicating the nature of the entry. Again, not strictly necessary but can be very handy if you have multiple type of entries in the same chain (we could imagine a ‘reset-counter’ type of entry for instance).</li><li>Ext[1] contains a 64 bytes signature of the content of the entry (“1989”). The signature must have been generated by the secret key corresponding to the public key present in the first entry of the chain.</li><li>Content contains the new value of the counter.</li></ul><h4>Anti pattern: using Entry Credit address for authentication</h4><p>You may be tempted to use the paying Entry Credit address for the purposes of authentication. It is indeed possible to retrieve that information from the Entry Credit block that contains the commit of the entry. While it does allow to match entries with an entity (controlling the EC private address) we would generally recommend against using this approach.</p><p>The reasons are:</p><ul><li>This violates an important principle in Computer Science called the <a href="https://en.wikipedia.org/wiki/Separation_of_concerns">separation of concerns</a>. Entry Credit addresses are part of the Factom protocol layer while the data authentication is part of your application layer, it is strongly recommended to not mix different layers.</li><li><a href="https://en.wikipedia.org/wiki/Loose_coupling">Tight coupling</a> of the payment component with the data authentication component brings some inflexibility/usability issues: <br>1. A user cannot delegate the payment of the insertion to another party while still authenticating the data as his.<br>2. If that address is also used for other applications, it increases the possible attack surface of your application. Your application’s authentication keys should be exposed as infrequently as possible, which is difficult when you also have to use those keys to pay for entries.</li><li>An Entry Credit address is nothing more than a cryptographic key pair that can be lost or compromised. If you lost your key you would permanently lose the ability to authenticate content against those keys. This is the same problem as directly using a key pair, which brings us to the next section about identities.</li></ul><h4>Identity</h4><p>Using an asymmetric key pair to sign and verify the data on our chain is a major improvement in the reliability of our counter application. But it is also relatively risky and inflexible to directly bind our chain data to a single key pair. One should be fearful of the future and having a key lost or compromised is fairly common:</p><ul><li>If you lose your private key you become unable to sign new data, effectively preventing new update as nobody will trust you if it is not properly signed.</li><li>If you private key is stolen, the thief can now pretend to be the source of truth and any data they insert will be trusted and considered valid.</li></ul><p>That’s why we strongly recommend integration with a digital identity system instead. The digital identity system should be able to bind multiple keys to an identity and allow management of a key’s life cycle. You should be able to rotate the keys in case of loss or hack.</p><p>Factom Inc. developed one such on-chain <a href="https://docs.google.com/document/d/1NooBhYdRARwmfqMS0lrbFoXxgbB8cFrsWIl0d0kdhF8/edit?usp=sharing">digital identity system</a> for this purpose.</p><p>Using this identity system the first entry of our chain would become:</p><pre>+--------+---------------------------------------------------------+<br>| Ext[0] | factom-counter                                          |<br>| Ext[1] | &lt;0xe0beb5b6c6632abcc812e0d05626292095ed0eb602a04095...&gt; |<br>+--------+---------------------------------------------------------+</pre><p>Ext[1] is now simply a reference to the chain of a digital identity. The counter update entries are now signed by a valid key that is attached to that digital identity. Your application would need to integrate with this identity system to be able to validate the entries but you benefit from a greater flexibility and safety.</p><h3>Replay attacks</h3><p>Replay attacks are a family of attacks that consists in reusing data for an existing valid entry to forge and insert a new entry in a chain so that it would appear valid to the application reading the data and would alter the internal state of the application. These attacks are fairly easy to overlook when you’re new to development on Factom.</p><h4>Inter-chain</h4><p>Inter-chain replay attacks consist of replaying an entry from one chain to another.</p><p>Let’s imagine we have 2 counters C1 and C2. Each has its own chain, and in both cases the data is authenticated by the same identity (i.e. same cryptographic keys). If a new value is published on counter C1, it is extremely easy for an attacker to copy that entry and insert it in the chain of counter C2. The update to counter C2 will be accepted because the signature of the data is valid. The attacker didn’t have to come up with a signature, it was given to him by the counter C1 entry. It is true though that the attacker couldn’t use any arbitrary value for the counter (otherwise the signature wouldn’t be valid anymore) but it still allows him to pick any value that was published for counter C1.</p><p>Luckily inter-chain replay attacks are easily defeated by “binding” the signature of the content to a specific chain: instead of signing only the content of the entry (which allow the signature to be“portable”), you should sign [chain ID + content] (+ being a concatenation operator). Such a signature cannot be valid if inserted in any other chain.</p><h4>Intra-chain</h4><p>While reading about the inter-chain replay attack you may have realized that it was also possible to just replay an entry within the same chain and have the same devastating effect. It’s worth noting that Factom will not allow you to commit two identical entries to the same chain. But don’t be fooled (like I was), this is only true for about an hour, after which it is indeed possible to re insert the same exact entry. This is a mechanism to prevent applications inadvertently recording duplicate data (because no regular applications should have to publish duplicate entries within such a short amount of time).</p><p>There are two potential solutions to that problem.</p><p><strong>Global uniqueness</strong></p><p>One possible solution is for your application to disallow an entry to ever appear twice. Your application should only consider valid the first insertion of a given entry by verifying the uniqueness of its entry hash. If somebody tries to replay the entry as is then your application will discard the duplicate and it won’t affect the state of your application. With this approach your application will have to keep track of all the entry hashes of valid entries processed by your application.</p><p><strong>Entry malleability</strong></p><p>You may have heard of <a href="https://en.bitcoin.it/wiki/Transaction_malleability">transaction malleability issues</a> that have happened in the past with Bitcoin. Similarly, depending on what parts of your entries are covered by the signature, you can have entry malleability: a malicious actor could modify an entry without invalidating the signature. This can be leveraged in replay attacks.</p><p>Let’s take an example:</p><pre>+--------+---------------------------------------------------------+<br>| Ext[0] | Signer_A                                                |<br>| Ext[1] | &lt;0x8dbcf489023412b59d84d2d9625ed26f57b7e40541c34f6f...&gt; |<br>| Ext[2] | Signer_B                                                |<br>| Ext[3] | &lt;0xd218bc38f70d347f291700a25d2c2fe1f433a87c693551a5...&gt; |<br>+--------+---------------------------------------------------------+<br>| A and B agreed to give C $1,000,000                              |<br>+------------------------------------------------------------------+</pre><p>Your application record the agreement in a entry that A and B would give C one million dollars. The statement is written in the content of the entry. <br>A and B, using keys associated with their digital identities (Signer_A, Signer_B) would sign that statement concatenated with the chain id (to prevent inter-chain replay) and the signatures are put in the external ids together with a reference to their respective identities. Without additional constraints the entry is malleable and an attacker can work around the global uniqueness of the entry:</p><pre>+--------+---------------------------------------------------------+<br>| Ext[0] | Signer_B                                                |<br>| Ext[1] | &lt;0xd218bc38f70d347f291700a25d2c2fe1f433a87c693551a5...&gt; |<br>| Ext[2] | Signer_A                                                |<br>| Ext[3] | &lt;0x8dbcf489023412b59d84d2d9625ed26f57b7e40541c34f6f...&gt; |<br>+--------+---------------------------------------------------------+<br>| A and B agreed to give C $1,000,000                              |<br>+------------------------------------------------------------------+</pre><p>Identities and signatures are still valid, the content is valid, but the hash of this entry is different from the previous one effectively bypassing<br>the global uniqueness check supposed to protect you against intra-chain replay attacks. As a result this entry would be read as perfectly valid and A and B may have to give away another million to C…</p><p>There are several ways to fix this malleability issue:</p><ul><li>Constrain the ordering of the external ids in the design of your application (e.g. signatures should follow the lexicographic order of the identities’ name)</li><li>Bind the signature to its external id index. That would mean adding the external id index as part of the data signed.</li></ul><p>Now you may wonder what if A and B legitimately want to give another million to C, they would have to re-emit the same entry that would not be considered valid by the application. The solution is to add a <a href="https://en.wikipedia.org/wiki/Cryptographic_nonce">nonce</a>, some random bytes that would allow the entry hash to be different. For instance we can now put a random number in the first external id, which is followed like before by the identities and signatures.</p><pre>+--------+---------------------------------------------------------+<br>| Ext[0] | &lt;0x625ed26f57b7&gt;                                        |<br>| Ext[1] | Signer_A                                                |<br>| Ext[2] | &lt;0x8dbcf489023412b59d84d2d9625ed26f57b7e40541c34f6f...&gt; |<br>| Ext[3] | Signer_B                                                |<br>| Ext[4] | &lt;0xd218bc38f70d347f291700a25d2c2fe1f433a87c693551a5...&gt; |<br>+--------+---------------------------------------------------------+<br>| A and B agreed to give C $1,000,000                              |<br>+------------------------------------------------------------------+</pre><p>What did we just do? We just re-opened a malleability issue: an attacker can now put any random number in the first external id to change the entry hash and submit his forged entry… Now you may already know how to fix that: the signatures should also cover the nonce which would prevent an attacker to freely change it. The signature of A and B now covers: (chainId + nonce + entry content)</p><pre>+--------+---------------------------------------------------------+<br>| Ext[0] | &lt;0x625ed26f57b7&gt;                                        |<br>| Ext[1] | Signer_A                                                |<br>| Ext[2] | &lt;0x7a2e4ee6dda05a7c473afa08bb8a38809b1a202485277909...&gt; |<br>| Ext[3] | Signer_B                                                |<br>| Ext[4] | &lt;0x39ddd603568428688c0ab1cdae72eb038fbcbcbc371df1e4...&gt; |<br>+--------+---------------------------------------------------------+<br>| A and B agreed to give C $1,000,000                              |<br>+------------------------------------------------------------------+</pre><p>With this solution we are protected against inter-chain and intra-chain replay attacks while still allowing legitimate duplicate agreements, bingo!</p><p><strong>Local uniqueness</strong></p><p>An alternative to global uniqueness is local uniqueness. With global uniqueness your application needs to retain all the valid entry hashes that have ever been processed. With the local uniqueness design the application entries are valid only for a given time window which allows the application to only have to check for replay attacks for that limited time frame.</p><p>The idea is to add a a block height (or timestamp) as part of the entry and require that it is close enough to the block height (or timestamp) of the block the entry will be part of. That block height or timestamp in the entry needs to be covered by a signature so that it cannot be maliciously later modified, otherwise malleability once again would allow a replay attack. With this constraint the application only has to verify the uniqueness within an acceptable time window defined by the application, typically few blocks (or few hours if using a timestamp). The acceptable time range accounts for potential technical difficulties that would delay the entry insertion into the blockchain.</p><p>Let’s take an example of local uniqueness using block height with an acceptable range of height difference of [-3, +3]. Put another way the constraint we impose to an entry to be valid is:</p><pre>|&lt;block height written in the entry&gt; - &lt;block height the entry is part of&gt;| &lt;= 3</pre><p>If an entry contains a reference to block height 9 and is actually part of the block of height 10, it passes the test. Because the blockchain is currently at height 10, the application only has to check duplicates in the entries of blocks in the range [10–6, 10] (6 being the size of the interval [-3, +3]) because we know that the entry we are are currently processing cannot possibly be a replay of a valid entry from a block with an height strictly inferior to 4.<br> <br>Few notes:</p><ul><li>It is a more complicated scheme than the global uniqueness one.</li><li>Because the entries are now timestamped with a limited lifespan it is slightly more inconvenient to create those entries in advance (offline for instance) which may be an hindrance for certain applications.</li><li>That approach is less “stateless” in the sense that the user creating the entry needs to either know the current block height or the current time.</li><li>Using block height vs timestamp: there is a small and subtle difference. In the rare case of a global Factom network stall (Factom prevents accidental forks by stalling the blockchain), the block height won’t continue to increase but the time will. It means that, when using a timestamp, the entries could expire if the network stall is too long and the entries only make it to the next block, which wouldn’t be the case when using a block height.</li></ul><h3>Conclusion</h3><p>Here’s a recap list we recommend you go through every time you are designing an application on Factom to avoid all the pitfalls described in this article:</p><ul><li>Evaluate if the “data integrity pattern” (using hash of data) could be suitable for your use case. It is a powerful, secure and well proven approach.</li><li>Always ask yourself if it is ok for the data your are storing on Factom to be public, immutable and available forever (and be cautious with symmetric encryption obfuscation).</li><li>In most cases you should use cryptographic signature to authenticate the origin of the data in a chain.</li><li>Use a digital identity (with multiple keys that can be rotated) to sign data instead of directly using a key pair.</li><li>Check that your design doesn’t allow for harmful entry malleability. Consider what could happen if data not covered by a signature is modified.</li><li>Check that your design doesn’t allow inter-chain and intra-chain replay attacks.</li></ul><h3>Examples</h3><p>Here are some real world applications specifications that put in practice the patterns described in this article:</p><ul><li><a href="https://docs.google.com/document/d/137gw8JTqKZdfe-AF0e02pFgyLsPCTjYbX0mguC_N3GE/edit?usp=sharing">On-chain voting</a></li><li><a href="https://docs.google.com/document/d/1NooBhYdRARwmfqMS0lrbFoXxgbB8cFrsWIl0d0kdhF8/edit?usp=sharing">Factom digital identity</a></li><li><a href="https://github.com/Factom-Asset-Tokens/FAT/blob/master/fatips/0.md">Factom Asset Tokens (FAT)</a></li></ul><p>If you are looking for advice on how to design your application on Factom or have any technical questions related to Factom, please reach out to us <a href="https://twitter.com/LuciapTech">@LuciapTech</a>. Luciap Technology has been involved in the design of the Factom Asset Tokens (FAT) protocol and the design of the on-chain voting protocol.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=160ece591e85" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>