Participatory Computing

One of my family friends congratulated me recently on the success of the ‘Ether startup,’ leaving me briefly puzzled. While the parallels between issuing common stock, stock options, and digital tokens are relatively intuitive, this was the first time I heard an open source community described as a company — by someone unfamiliar with open source software. Technically, Ethereum isn’t a startup but an organization rooted in open source communities working to develop decentralized, logic-gated information and value exchange. There are similarities, and differences, between open source communities funded by digital tokens and traditional startup equity.

Transitioning from a Clinical Informatics fellow at UCSF to starting an R&D lab has provided me an opportunity to reflect on the valuable mentorship I’ve been lucky to receive along the way.

Analog Labs is an applied research laboratory aiming to:

  1. Educate societies about blockchain technology and emerging paradigms in Participatory Computing
  2. Apply this research directly toward social good
  3. Be financially and environmentally sustainable

The excitement surrounding cryptocurrencies drew attention to a field in tech that had been niche until relatively recently. Capital allows companies to grow and subsequently create value for society. However too rapid influx of wealth into cryptocurrencies can outrun the ability of these technologies to mature and evolve. Rapidly increasing prices of cryptocurrencies can bring wealth (and ruin) to speculators and can also discourage the spending of Ether to actually run applications. The excitement surrounding the industry, despite being a source of attention and potential investment funds, needs to keep pace with the development of these technologies for the sake of the long-term health of these technologies.

Since I started purchasing health insurance last month — $902.04 per month for medical insurance and $32.52 per month for dental insurance — I’m reminded of the dizzying cost of healthcare in the United States — the glaring economic and public health problem that sparked my interest in Ethereum several years ago. Analog Labs’ flagship project is a study of grassroots primary care models on the Ethereum blockchain. This living experiment is an opportunity to tap into a body of literature in Global Health and international communities’ experience with designing creative solutions to the challenge of funding healthcare’s perpetual journey to better.

Analog Labs is also seeking to help develop 2-4 projects that further the lab’s goals of applied research for sustainable social good by providing funding, technical expertise, and collaborative work, especially in the areas of:

  • health insurance
  • environmentally-friendly shipping materials
  • public transportation

 

I’m grateful to Betty Tran, Steven Truong, Peter Mikhail, Royd Carlson, The Haham-Grossman family, Linh Tran, Darlene Nguyen, Dr. Blake Gregory, Dr. Indhu Subramanian, Dr. Taft Bhuket, Dr. David Avrin, Dr. Sidhartha Sinha, Dr. Scott Enderby, the Highland family, the UCSF community, Bella Shah, Seth Blumberg, Dana Gersten, Tanner Irwin, Youssif Abdulhamid, Shahzad Ahsan, and friends at UCSF’s Aldea community for their support, mentorship, and contributions to this work.

 

Omar Metwally, MD

 

 

Re-programming the developing world: the tobacco problem

Omar Metwally, MD
University of California, San Francisco

If I were a government or private health insurance company trying to improve public health and reduce costs associated with treating cancers, chronic obstructive pulmonary disease, cardiovascular diseases, and many other preventable tobacco-related illnesses, how would I take on this challenge? Would offering nicotine addicts cash or subsidizing their insurance premiums curtail these unhealthy behaviors? While there’s some evidence that paying smokers works in the short-term, the effect is modest and has not been shown to be a successful long-term strategy.  The 2017 recipient of the Nobel Prize in Economic Sciences, Professor Richard Thaler’s work demonstrates how humans’ bias toward short-term rewards contributes to poor long-term decision making. Especially in the case of chemical dependence, immediate positive reinforcement (e.g. a puff of a cigarette) trumps the relative abstractness of long-term planning. Who doesn’t want to live a long, healthy life free of suffering, expensive healthcare bills, and the loss of independence associated with frequent trips to the hospital? But to an addict, a drag from a cigarette is more attractive than the prospect of being rewarded with something like health, time, or disposable income in 10, 20, or 50 years time.

Breaking chemical dependence, and modifying behavior (such as a sedentary lifestyle, unhealthy eating habits, and compliance with preventive healthcare) in general, depends to a large extent on modifying one’s environment. This includes things like eliminating triggers (ashtrays, packs of cigarettes and lighters lying around), and enablers. More effective than paying someone to ditch unhealthy habits may be helping someone with an addiction change their social context. I’m skeptical about the efficacy of an incentive program that would, for example, pay smokers cash in exchange for urine tests that verify an individual’s nicotine-free status. The desire for long-term abstinence from substances, weight loss, or regular exercise must be intrinsic and reinforced by the company one keeps. A chronic smoker is more likely to smoke among a group of friends who also smoke than in an environment where they’re constantly subject to inconvenience, protest, or punishment whenever they reach for a cigarette. The corollary is the hypothesis that helping a smoker and their group of smoking friends quit together may be more effective than limiting an intervention to individuals.

Continuing the thought experiment, how does a health minister or surgeon general help people modify unhealthy behavior while changing one’s entire psychosocial situation? Instead of an intervention like a urine test, which people may find embarrassing or perhaps not worth the inconvenience of extra pocket money paid at the conclusion of a research study, what might a reward system look like which compensates individuals based on a convenient, dignified, and inexpensive  “proof-of-motivation”? If I’m a smoker interested in quitting  and make my intentions clear to my family, friends, and co-workers, could their vouching for me serve as such proof-of-motivation? If I truly muster the willpower to not smoke for a week, month, or year, could the people closest to me supplant something as sensitive/specific as a blood or urine test?

A hacker-mind will be quick to point out that a nicotine addict, if determined to do so, will find a way to game simple trust-based systems, whether it means stepping into -20C weather, walking for a mile to a secluded smoking spot, or sneaking cigarettes while driving to and from work. Moreover, a smoker could easily convince others to lie about their behavior in exchange for sharing the reward with colluders. What is necessary is a more perfect mechanism for allowing individuals to vouch for one another’s behavior. Earlier in my career, I had a tendency as a technologist in general and blockchain researcher in particular to reach for technology XYZ and ask, what can I do with this technology? I see this bias throughout Silicon Valley; we love to build things, and technology is an easy starting point for our desire to effect change.

The organizational and technological merits of my specialty’s distributed, peer-to-peer paradigms are rather clear. The other half of the blockchain equation, proof-of-work, makes sense in the context of value stores, a feature common to the two predominant cryptocurrencies (Ethereum and Bitcoin) — in addition to Ethereum’s Turing completeness and logic layer. In the excitement of embracing new technologies, one should be wary of shoehorning technologies into domains where a logical fit doesn’t exist. Bitcoin as a digital asset makes sense. Ethereum as a value store — and much of its organizational functionality  — makes sense.

But with the goals of promoting healthy behaviors, helping developing countries kick a terribly addictive habit, and improving air quality as our starting point, how does one begin to effect change without burning up the planet’s resources in the process (one Bitcoin transaction wastes enough energy to power a household in a developing country for weeks)?

I would love the feedback of people thinking about this problem from different points of view. More than a billion human lives, which will be claimed by the tobacco industry in the 21st century, depend on it.

 

 

 

The Nile and the Ethereum Blockchain

Omar Metwally, MD
University of California, San Francisco

Distributed Data Sharing Hyperledger (DDASH).
=============================================
   Github repository
   -----------------
   Project website
   -----------------

Like blood rushing through a major artery, the Nile flows north from its origins in eastern Africa, nourishing hundreds of millions of people in Ethiopia, Sudan, and Egypt. Through millenia, the world’s longest river has turned otherwise uninhabitable deserts into fertile farmland, giving birth to civilizations that depend on its water for sustenance and trade. Herodutus, the ancient Greek historian, described Egypt as “the gift of the Nile,” and in the southern Egyptian cities of Aswan and Luxor, the Nile’s critical importance into modern times is ubiquitously apparent.

I step outside Aswan airport into a warm, brilliant January morning. A sweet breeze and southern Egyptians’ lightness greet us, a stark contrast from Cairo’s frenetic bustle . A charming Nubian man drives us to our hotel, and as we pass acres of hydroelectric generators and the Aswan High Dam, the Nile’s modern day importance to a country dependent on its every last drop comes into focus.

The Ethiopian government began constructing The Grand Ethiopian Renaissance Dam in 2011, making it Africa’s largest hydroelectric power plant. Although the $6.4 billion project is well underway, the ramifications of this project remain incompletely understood. The potential threat of depriving downstream countries (the Nile flows from south to north) of water and hydroelectric energy has raised concerns about its potential impact on human life.

While hydropolitics is a step removed from my field of Clinical Informatics, this complicated situation involving numerous parties with conflicting interests (sound familiar?) piqued my interest. The U.S. healthcare system, like this sensitive hydropolitial situation, is plagued by the major problem of many conflicting interests with little incentive to cooperate. Stifled health information exchange has bred a climate of competition rather than cooperation, ultimately to the detriment of individuals. I began my career as a blockchain researcher in 2014 when I realized this paradigm’s potential to create equity and promote cooperation. The conflict surrounding the Nile and the Renaissance Dam is a vivid demonstration of how the Ethereum blockchain can help nations solve a geopolitical conflict surrounding a scarce natural resource through cooperation rather than competition. My core thesis on blockchain, a technology that bridges computing, psychology, and economics, is that opportunities for cooperation will arise naturally as individuals benefit from increasing opportunities to participate in decision-making on all scales.   

To demonstrate these principles and test the above hypothesis, I spent several jet-lagged nights deploying a Nilometer contract on the Ethereum blockchain. This Ethereum contract lets parties bid for a minimum Nile water level and send a variable amount of Ether to support their bid. If the next month’s water level meets this minimum, these funds move from digital escrow to a pre-determined recipient (for example, a government, non-profit, or corporation). 

nilometer

Hydrological Time Series data were obtained from Technical University of Munich (Deutsches Geodätisches Forschungsinstitut an der Technischen Universität München).

 

Trolling for a wealthier world

Omar Metwally, MD 
University of California, San Francisco

“No,” said the priest, “you don’t need to accept everything as true, you only have to accept it as necessary.” “Depressing view,” said K. “The lie made into the rule of the world.”  – The Trial (Franz Kafka)


Goal

To understand what motivates people to create and share knowledge.

Plot

Larry, is a cafe owner on a mission to brew the world’s best cup of coffee.
larry
Larry’s on a mission to brew the world’s best coffee

The Cast:

Roy Bender:  Australian-American physician who invented Roy’s Retractable Needle in 1990. His patents in Australia, America, and Germany brought him great success and have since expired.  

surfer.jpg
Dr. Roy Bender enjoying his patents’ success

Ernesto Bernal: Ernesto is an altruistic Mexican inventor whose outrage at the cost of American “Epi Pens” (life-saving medical devices used to treat potentially fatal allergic reactions by delivering epinephrine into the thigh muscles) inspired him to invent Ernie’s Excellent Pen. Ernie’s Excellent Pen uses the technology behind Roy’s Rectractable Needle to make this life-saving medication more affordable for patients.

ernesto.jpg
Dr. Ernesto Bernal building “Ernie’s Excellent Pen”

Dr. Xu: Chinese scientist looking for a way out of a dead-end postdoc. He spends a lot of time trolling websites like reddit in between experiments.

xu.jpg
Dr. Xu, Full-time redditor, part-time postdoc

Dr. Chang: Chinese scientist who invented China Pen in 2005, her own version of the epi pen. Dr. Chang, a brilliant scientist without business aspirations, quickly forgot about her invention and moved on to other research projects. She and Dr. Xu were postdocs together and longtime friends. 

chang.jpg
Dr. Chang mentoring her student

Part I

Looking for inspiration for his next big invention to save him from a stagnant postdoc, Dr. Xu browses the blackswan network, a database of inventions and ideas, on a quiet afternoon in his lab. He likes the website because it’s like a nerdy version of reddit, a website that has occupied a lot of his time recently. While browsing blackswan he stumbles upon Ernie’s Excellent Pen (a medical device built using Roy’s Retractable Needle), which immediately reminds him of his old friend’s China Pen. He creates an “attribution” on the blockchain, an association between two devices/components, that looks like:


To a human, this attribution looks something like:
[Appraiser's (Dr. Xu's) Ethereum address, Resource1* (Roy's Retractable Needle), Resource2* (Dr. Chang's China Pen), Timestamp, Transaction Handle]

To a machine, this same attribution might look like:
[0x6060604052341561000f576, Qmt3z9320ba, Qz429ccr082, 1508029285, 0xc6a493eb108266c548906c8b]

This attribution allows others to see that Roy’s Retractable Needle and the China Pen are related to one another. Others can “upvote” this association as a useful one and create their own associations (so that Dr. Xu can learn about related inventions which he wouldn’t have otherwise encounter). For someone on the hunt for the next big idea, this is a great way to find inspiration and learn about what others are building. All community members can vote on how useful an attribution is and can create their own attributions.

*As a side note, resources are named something like Qmt3z9320ba , and these names also function as locations (addresses) of files with detailed information about each invention, including schematic drawings and textual descriptions. If any of the files to which these addresses point are modified, the entire address changes — one way to make sure each timestamp accurately reflects the information with which it’s associated. 

Part II

Larry owns a hip cafe in Tel Aviv and has invented many gadgets on his quest to brew the perfect cup of coffee. As he sips on a cup of coffee and browses the blackswan network, inspiration strikes, and he has a new idea for a modified French press that could be built using the spring-loaded mechanism underlying Roy’s Retractable Needle. Larry draws up some sketches and a description of how his Better Coffee Press would work and confidently uploads the information to the blackswan network. He doesn’t need to worry about someone else claiming ownership of his ideas because there’s a timestamped record of this information on the blackswan network. 

Part III

The owner of Oakland Standard, a manufacturer in Oakland, California, discovers Larry’s sketches a week later and calls him in his cafe. He loves the idea, he tells Larry, and wants to bring his product (Better Coffee Press) to the U.S. market. One of Oakland Standard’s designers suggests using a slightly modified component from Ernie’s Excellent Pen (Larry’s never heard of Ernie or his epi pen, but he likes Oakland Standard’s suggestion). Larry seals the deal with Oakland Standard. 

Oakland Standard eventually takes the product to market, and it’s a hit among hipsters and coffee connoisseurs across the U.S.. After Oakland Standard (and Larry) make their millions, the design for Better Coffee Press appears on the blackswan network around the same time that the patent is published and viewable on Google Patents and the US Patent and Trademark Office website:


Type: device
Name: Better Coffee Press
Function: hand-operated coffee brewing device
Content-addressed hash: Qbb4a27e6783
Author1: Larry Bucks
Timestamp: 1601036650
Classifier1: Food and Beverage
Classifier2: Brewing System

Part IV

Dr. Xu is having another rough day in his lab. He heard about the Better Coffee Press on reddit and bought one so he can brew coffee in between experiments. As soon as his coffee press arrives in the mail, Dr. Xu brews his first cup of coffee, sets his laptop on his lab bench, and pulls up a stool. Sipping an extraordinarily delicious cup of coffee, he admires the technical genius of this new coffee press and begins dismantling the gadget. As he takes apart the coffee press, he records the following attributions (logical associations between the coffee press and its underlying components) on his quest for inspiration for his own inventions:


Human version:
[Appraiser's (Dr. Xu's) Ethereum address, Resource1 (Roy's Retractable Needle), Resource2 (Larry's Better Coffee Press), Timestamp, Transaction Handle]

Machine version:
[0x6060604052341561000f576, Qmt3z9320ba, Qbb4a27e6783, 1508029285, 0xa8e493eb108266c548906331]

[Appraiser's (Dr. Xu's) Ethereum address, Resource1 (Ernie’s Excellent Pen), Resource2 (Larry's Better Coffee Press), Timestamp, Transaction Handle]

[0x6060604052341561000f576, Qz429ccr082, Qbb4a27e6783, 1508029285, 0xd8a493eb106206a448906257]

Part V

Oakland Standard sells tens of millions of dollars worth of the Better Coffee Press, and Larry makes a fortune in licensing fees. Meanwhile, Roy, Ernie, and Dr. Chang have also made millions — in tokens.

Whenever blackswan community members like Dr. Xu appraise information by creating and voting on the quality of attributions, inventors like Roy, Ernie, and Dr. Chang receive tokens on the blackswan network. 

But why would anyone care about earning tokens when they could earn real money like Larry and Oakland Standard? Aren’t these tokens just monopoly money? Larry and Oakland Standard earned their wealth by operating within the intellectual property systems of each respective country where they manufactured and sold the Better Coffee Press. They had the financial resources to pay intellectual property attorneys tens of millions of dollars in fees to draft and review contracts, and even more to enforce their patents by taking infringers to court.

But what about all the smart people out there who don’t have the same access to intellectual property attorneys and millions of dollars in investment capital? 

Larry may be a clever capitalist, but he also sees the value of the novel economy emerging around the blackswan network. As he sips on a cup of coffee, Larry is already planning his next big venture. He announces on his cafe’s website that he’s on a quest to build an even better coffee brewing system and drafts an Ethereum contract that will award $5 million to all the tinkerers out there who make the most meaningful intellectual contributions to his future invention. Larry types up his Ethereum contract, buys $5 million worth of Ether, and sends these funds to be held in digital escrow. He then creates this entry for his future invention on the blackswan network, which he calls Best Coffee Press:



Type: device Name: Best Coffee Press 
Function: hand-operated coffee brewing device that keeps coffee warm and serves up to 6 people 
Content-addressed hash: Qzt7w201e55j 
Author1: Larry Bucks 
Timestamp: 1720015640 
Classifier1: Food and Beverage 
Classifier2: Brewing System

Part VI

One year and many blockchain transactions later, new records of device components and devices have been created on the blackswan network, new attributions have been made, and millions of makers have earned tokens for their contributions. Larry has also amassed a personal fortune as a result of his second contract with Oakland Standard to manufacture and sell his latest invention, Best Coffee Press. 

Larry’s smart contract then distributes the $5 million that have been held in escrow for the past year to 280 inventors on the blackswan network whose work has contributed to the creation and success of Best Coffee Press. Rather than dividing $5 million equally among 280 people (each receiving $17,857.14), Larry wrote his contract to reward inventors proportionally to their contributions; the more frequently a device or component appears in the blockchain in the form of attributions (as they relate to Best Coffee Press), the greater those inventors’ piece of the $5 million pie. 

While making his own personal fortune (and bringing wealth to Oakland Standard, teams of attorneys, factory workers, and international governments), Larry also brought wealth to 280 inventors who would not have otherwise contributed to or benefitted from Larry’s success he had operated solely under existing systems of information disclosure, such as the US Patent and Trademark Office. Through his foresight in adopting the blackswan network, Larry was able to create his Best Coffee Press in half the time it took to create his less innovative (and less successful) Better Coffee Press.

One of Larry’s childhood friends, now a famous Professor of Medicine, read a newspaper article about Larry and came to visit his old friend in his cafe. 

Larry greeted his old friend with a warm hug and insisted on brewing the best cup of coffee for him using his latest invention. As they enjoyed what Prof. Grossman admitted was truly the best cup of coffee he had ever tasted and watched people hurrying beyond the cafe’s windows, Prof. Grossman began, “I’ve heard of billionaires who’ve made fortunes building monopolies…but a billionaire who’s made fortunes by dismantling monopolies?”

turkish_coffee.jpg
Larry pouring coffee for his childhood friend

Larry’s face wrinkled with laughter. “Most people think that wealth can be made only at others’ expense,” he answered. “The secret is, the more you give, the more you get. And here I’ve found a way to do just that.”

“From a certain point onward there is no longer any turning back. That is the point that must be reached.” ― The Trial (Franz Kafka)

How to connect 3+ Ethereum nodes in a private Ethereum network.

Omar Metwally, MD 
University of California, San Francisco 

Distributed Data Sharing Hyperledger (DDASH).
=============================================
    Github repository
    -----------------
    Project website
    -----------------

How to create a private Ethereum Network, Part Deux

By: Omar Metwally, MD

Background and Prerequisites:  This tutorial picks up where part one (“How to create a private Ethereum network”) left off.

 

Numerous people have asked me how to connect 3+ nodes in a private network after reading my previous tutorial. There are scripts out there that will pseudo-automate the process, but I believe in understanding the fundamentals and building it yourself from the ground-up without obfuscating layers between you and your network. Many people got hung up on obtaining a machine’s enode address (basically your Ethereum client’s public key) using the bootnode application. Depending on which machine you’re running and how you installed geth (the Go Ethereum client), chances are you don’t have bootnode installed. I realized that most people out there are not running Linux machines and therefore are getting stuck here.

The good news is that creating a network with any number of peers is possible without having to install bootnode.

A crucially important difference between private Ethereum networks and the main Ethereum network

is that, unlike the main Ethereum network (where real money is used to power the Ethereum supercomputer, create contracts, and move money around the network), private Ethereum networks do not automatically let anyone join the network. In a private network, each peer must identify all other peers to which it wants to connect. In networking parlance, a node becomes a peer when it connects to a fellow node.

Nodes are identified via enode addresses, which are basically public keys.

To illustrate how to create a private network with 3+ nodes, I’ll use the private blackswan network I created to run one of our projects, called DDASH (Distributed Data Sharing Hyperledger). You’re welcome to follow along and join the blackswan network or take notes and create your own private network.

Step 1: Create a genesis block 

All peers must use the exact same genesis block specified by genesis.json:

/Users/omarmetwally/Desktop/blackswan/genesis.json

For more information about the contents of this file, see my previous tutorial.

The exactly location of the genesis.json file will probably differ on your machine, depending on your operating system and how you installed geth.

Step 2: Clear old chain data

This will allow you to start from a blank slate and is necessary whenever you change the genesis block because you can’t merge two chains with different genesis blocks.

rm -r /Users/omarmetwally/Desktop/blackswan/data/geth

Step 3: Reinitialize the genesis block 

Again, this needs to be done on each node.

geth --datadir=/Users/omarmetwally/Desktop/blackswan/data init /Users/omarmetwally/Desktop/blackswan/genesis.json

Step 4: Discover each node’s enode address

To create a private network, each machine needs to know every other machine’s address.

geth --verbosity 1 --datadir=/Users/omarmetwally/blackswan/data console

Then type in:

> admin.nodeInfo

Copy the enode address, including quotation marks. It will look something like this (without the ellipsis):

 "enode://0f2a26.....730c"

Step 5: Create the static-nodes.json file on each node

This step is critical and a common point of failure for many people creating a private Ethereum network. This file identifies other network peers using their enode addresses. Create a file called static-nodes.json in the local geth data directory of each node, and paste the enode of every peer in your private network, such that it looks something like:

[

"enode://164c8...cf3eb815a7@12.167.347.338:30303",

"enode://c49d9...7343bac665@104.236.141.200:30303"

]

Note the quotation marks, the commas, and the format:  enode@ip_address:port.

Save this file as static-nodes.json in your local geth data directory, which in my case is:

/Users/omarmetwally/Desktop/blackswan/data/static-nodes.json

Step 6: Launch your private network.

Run this command on each node

geth --verbosity 2 --datadir=/Users/omarmetwally/Desktop/blackswan/data --networkid 4828 --port 30303 --rpc -rpcport 8545 --etherbase "0xYourEthereumAddress" console

The flags in the above command are important.

networkid

The blackswan network id is 4828, but your own private network will contain its own identifying network id which you should create to be unique.

verbosity

How much information geth will spew, which can help with troubleshooting or be too much unnecessary information cluttering your screen.

datadir

This must correspond to your own local geth data directory. You will not get a helpful error message if this does not correspond to a real directory on your machine, so be careful here.

etherbase

This is your Ethereum address on the private network.

rpcport and port 

The port and rpcport flags are networking parameters which I will not get into here. Make sure that your firewall will not block the ports you’re trying to use, and be careful when opening your machine to the outside world. Be very careful when exposing the RPC API to the outside world to prevent theft of real Ether and loss of real money! Any real Ether you might own should be kept completely separate from your development environment.

Step 7: Mining on your private network

Mine Ether by running:

geth --verbosity 4 --datadir /Users/omarmetwally/Desktop/blackswan/data --networkid 4828 --port 30303 --etherbase "0xYourEthereumAddress" --mine --minerthreads=1 

Then open a new Terminal window (if you’re using a Mac) or new Terminal tab (Ctrl-tab) and check your balance:

geth attach /Users/omarmetwally/Desktop/blackswan/data/geth.ipc console

> web3.eth.getBalance(web3.eth.accounts[0])

You should see your account balance increase fairly quickly as you mine.

Acknowledgements

Royd Carlson’s (UC Berkeley) feedback was instrumental in conceiving this article. The comments and emails I receive from readers of this blog help make these articles relevant to the Ethereum community .

Knowledge is power, and my goal is to empower the readers of this blog with the information necessary to create blockchain applications with the potential to re-program institutions, level playing fields, and take a huge step toward more democratic societies. I’m humbled to welcome visitors to this blog, especially from nations where access to and dissemination of  knowledge is much more difficult than we sometimes take for granted in the Western world.

“…the poor catch up with the rich to the extent that they achieve the same level of technological know-how, skill, and education, not by becoming the property of the wealthy.”  (Thomas Piketty, Capital in the Twenty-First Century)

On the economics of knowledge creation and sharing

Omar Metwally, MD 
omar.metwally@gmail.com
University of California, San Francisco

DDASH - Ethereum Operating System 
for Knowledge Creation and Sharing
==========================================
    Github repository
    -----------------
    Project website
    -----------------
    First Draft

Abstract

This work bridges the technical concepts underlying distributed computing and blockchain technologies with their profound socioeconomic and sociopolitical implications, particularly on academic research and the healthcare industry. Several examples from academia, industry, and healthcare are explored throughout this paper. The limiting factor in contemporary life sciences research is often funding: for example, to purchase expensive laboratory equipment and materials, to hire skilled researchers and technicians, and to acquire and disseminate data through established academic channels. In the case of the U.S. healthcare system, hospitals generate massive amounts of data, only a small minority of which is utilized to inform current and future medical practice. Similarly, corporations too expend large amounts of money to collect, secure and transmit data from one centralized source to another. In all three scenarios, data moves under the traditional paradigm of centralization, in which data is hosted and curated by individuals and organizations and of benefit to only a small subset of people.

1. Introduction

In its current siloed state, data is a liability rather than an asset. The value of data depends on its quantity and quality. Organizations, including corporations, government, and academia, have few incentives to share data outside the context of selling it. For instance, advertisers use data procured  from individuals’ browsing history and social media use (via internet service providers, social media and search engines) to create detailed profiles of individuals’ online behavior and spending habits and more effective sell products to unknowing consumers. While this paradigm fits naturally into a capitalistic society, these economics of data collection and transfer do not facilitate the generation or sharing of knowledge in the academic setting.

A typical university-based research group depends upon external funding to support its research activities. These funds often originate from governmental bodies, philanthropic organizations, or corporations and are difficult to secure [1]. Only a small minority of tenure track scientists ever becomes principal investigators, and a lab that is productive today can become defunct tomorrow if its principal investigator is unable to secure funding for laboratory equipment and supplies such as microscope parts, reagents, and to compensate technicians and trainees [2]. Principal investigators spend a majority of their time writing grant applications rather than participating directly in the process of knowledge generation [3].

It is often said that publications are the currency of academia. The maxim “publish or perish” applies to most research groups, whose work culminates in peer-reviewed publications with publication fees commonly amounting to several thousand dollars [4]. Moreover, these peer-reviewed publications are heavily biased toward so-called “positive results,” in which mathematical correlations between variables are described [5]. The vast majority of data produced by scientific researchers do not refute the null hypothesis; in a best case scenario, they are deemed “negative results,” and are discarded; in a worst case scenario, they are data that can’t be replicated, verified, or are outright fraudulent [6]. The result is the modern-day academic machinery. This severely flawed system, a victim of many conflicting economic forces, results in a tremendously inefficient workflow in which most grant money is wasted in the form of negative, and therefore unpublishable, results. Principal investigators spend a majority of their time trying to secure funding. The ultimate winner is the $10 billion business of academic publishing [6]. In this reality, data with the potential to produce vast knowledge is rendered into a vastly wasted opportunity to exponentially build on communities’ resources. Individuals’ roles are minimized by the centralization of resources in the hands of a privileged few.

2. Background

While the term “blockchain” has been touted to near-hysteria in popular media in the context of initial coin offerings and get-rich-quick schemes, an understanding of this data structure’s logic reveals the tremendous and fascinating socioeconomic implications of storing data on blockchain. In its most simplified form, a blockchain is a ledger [7]. The reason for blockchain’s natural association with financial derivatives lies in its ability to mathematically prove the authenticity of data and demonstrate proof of stake and proof of work [8].

The starting port for these use cases is the typical consumer, who is separate from (and often completely unaware of) the data collected about him or her. For instance, a customer’s online behavior is collected and used to up-sell the customer as much as algorithmically possible [9]. Customers have  nothing to gain (and a few thousand dollars each year in extra spending to lose) from such data, which companies can sell to data brokers and merchants [10]. Analogously, the majority of taxpayers have no access to — and oftentimes no way to directly benefit from — publications funded through research that ends up property of academic journals [11, 12].

2.1 Case Study: Proof of Stake

Consider a research lab living from grant to grant, sifting through negative results to find crumbs of publishable positive results. If its lab notebooks were stored in the form of a blockchain, every experiment conducted, every machine learning model and dataset, and every clinical trial would generate data that lives on the blockchain as a cryptographic asset. Also referred to as “coins” and “tokens,” these cryptographic assets have inherent value because they are perfect receipts of the existence and transfer of data [13]. Never before in history has such a perfect ledger existed [14, 15]. On the blockchain, a relatively worthless set of negative results generated by a research lab becomes, when combined with negative results from thousands of other research groups, a trove of extremely valuable scientific data which can be traced to its owners whenever and however it is utilized. This large collection of negative results can become the source of unexpected positive results.

Moreover these blockchain-hosted data take on a new life as a financial derivative [16, 17]. These cryptographic assets, perfect receipts of the creation and movement of knowledge, can be traded by third-parties analogously to the way a company’s common stock is bought and sold on private and public marketplaces, albeit without the same regulations and on a different scale [13]. These tokens enable individuals, small and large groups alike to be compensated for their services in ways that are impractical or impossible in traditional economies [18]. Rather than relying on the slow and inefficient process of securing funding through grants, research labs can codify contracts on the blockchain to allow third-parties to bid for services and products rendered, on the metadata (what kind of knowledge research labs generate through their scholarly activities), and allow third-parties to become stakeholders in a research group’s success by directly benefitting from these research activities. For instance, if I believe that a particular group is contributing to science and society in a positive way, I can economically support this group by donating computing power and electrical energy to support the integrity of their lab notebook-turned-ledger, or by trading fiat for tokens representing proof of stake in their scholarly activities. What are today opportunities exclusive to accredited investors and institutions will become abundant opportunities for individuals to influence how perceived value circulates through society.

2.2 Case Study: Proof of Work

Consider the United States healthcare system, which still excludes millions of Americans from access to healthcare and financially ruins even more [19, 20]. Insurance companies are able to impose high premiums simply because they can. This is the logic of a capitalistic society, and insurance companies alone enjoy the benefits of owning valuable health data to their fullest extent — at the expense of those whose health data was collected [20, 21]. Imagine, on a smaller scale, a radiology group that puts a copy of every imaging study they do on a blockchain, along with a timestamp, a description of which type of study was done, and why it was performed. In doing so, data that would have otherwise been discarded can be engaged with by third-parties while directly benefiting the radiology group as well. For instance, grassroots-based health insurance co-ops could emerge from these sources of data which are otherwise privy to insurance companies, to the benefit of health consumers, who can undergo imaging studies and receive other healthcare services at a fraction of current costs. Information about which studies are performed — where, by whom, and why, and the result of those studies, can be used to lower healthcare costs while improving health outcomes, rather than raise healthcare costs and increasing profits.

One question that naturally arises, especially in the context of current centralized data paradigms, is: why would healthcare providers be incentivized to make public valuable data that is routinely used by corporations and insurance companies to maximize profits? One powerful force driving healthcare costs upward is the process through which health providers bill patients via insurance companies. Whether ordering relatively common drugs or expensive therapeutics or procedures, healthcare systems rely on administrators whose role is to submit authorization requests to insurance companies for approval to prescribe therapeutics on their patients’ behalf [22]. When a service is rendered in the hospital or in a clinic, a healthcare team is reimbursed a fraction of the amount they bill for, creating a cat and mouse game in which providers continuously bill as high as possible for services rendered with the expectation that they will only receive a fraction of what they bill for, and in which insurance companies place limitations on which drugs and services this will pay for and how much of the cost they will cover [23]. Blockchain would provide an end to this cat-and-mouse game and create a race to the bottom for healthcare costs, through price transparency and elimination of bloated administrative layers that handle authorization requests and billing, while creating a race to the top for healthcare outcomes as this ledger of health services and outcomes would be publicly accessible on a blockchain. Simultaneously, healthcare providers can immediately receive payment for services rendered, and although individual payments may be less, overall profits would increase because payments would arrive immediately and there would be no need for entire departments of administrators whose entire role is to maximally inflate bills sent to insurance companies (and patients, insured and uninsured) and to see these bills through collection.

2.3 Informing current and future medical practice

We may well already have all the knowledge we need to cure many illnesses currently considered incurable [24]. We may well have all the data we need to create intelligent machines that can interpret CT scans, diagnose disease, and synthesize drugs to cure any condition. The reason this knowledge hasn’t culminated in more rapid advancement in healthcare and science is that information is fragmented into pieces, siloed, and ultimately rendered worthless data. Blockchain allows transparent access to data. It would be naive to imply that a data structure will cure society of all its ailments. However blockchain allows data to culminate into extremely valuable information, once at the disposal of a powerful few, now to the benefit of all who become stakeholders by contributing to, interacting with, and propagating data.

3. The need for a ledger of scholarly assets

The need for this project, a protocol for the hosting and sharing of data on a distributed network (“Distributed Data Sharing Hyperledger,” or DDASH), arises from the observations by the above examples, as well as the observation that numerous research groups at UCSF and other academic institutions are working in parallel in their endeavors to create knowledge with little synergistic interaction [25]. How would research group A at UCSF Medical Center know that research group B at the University of Michigan is working to answer the same scientific questions, for instance? Without a transparent glimpse into which resources an organization owns and how they are being used and shared, both research groups miss opportunities for synergistic collaboration, within and among organizations.

Those acquainted with the politics of contemporary academia will be quick to raise several criticisms. Working within the current reality of Google, the most comprehensive collection of information known to humanity as of September 2017, why can’t research groups A and B simply host their digital assets — data and knowledge gleamed from this data — on websites or public databases? And if groups A and B are competing to be the first to publish in academic journals and competing to drink from the same pools of grant funding, why would any research group benefit by sharing the results of experiments that were costly to run before they can reap the benefits of publication and intellectual property [26]? The answer is in blockchain’s ability to capture proof of work and proof of stake in a network’s digital assets. There is nothing to stop a competing research group from stealing these data and benefiting at their competitors’ expense. Hosting data in the form of knowledge on a blockchain elegantly solves this problem through irrefutable mathematical proof of data ownership, transfer, and authenticity [27].

3.1 Distributed Data Sharing Hyperledger (DDASH)

DDASH (link to open source Github repository) is a ledger of scholarly data and knowledge produced by life science, informatics, and clinical researchers at UCSF and other academic institutions. The need for this project arises from the negative impact of data siloing, competition, and counterproductive financial incentives in the academic world on the creation and sharing of knowledge. Concretely, researchers can host data — datasets, experimental results, and machine learning models, among other examples of scholarly knowledge — on the distributed InterPlanetary Filesystem (IPFS) network and record the location of these assets on an Ethereum-based blockchain, along with a description of the asset, when it was created, and who has privileges to access the data.

3.2 Network Architecture

We believe that the IPFS protocol’s combination of security and speed is well suited for this application. IPFS uses content-based addressing, in which a hashing function determines a file’s network address based on the file’s contents [28]. Storing data in the form of a directed acyclic diagram (in this case, a Merkle DAG) results in trees that can be efficiently traversed and queried. IPFS is a peer-to-peer network in which data is continuously circulating through network participants’ machines which are running the client software. Data are rendered permanent by virtue of content-based addressing and persistent by virtue of its peer-to-peer architecture, and data are rapidly accessible without the bottlenecks that Internet Protocol imposes.

3.3 Blockchain as a ledger

The blockchain functions as a decentralized ledger of digital resources and the movement of these resources throughout the network. As the DDASH protocol is formalized, more robust mechanisms for associating IPFS hashes with the owner of the resource and the permissions granted by the owner are necessary. Currently the DDASH protocol accounts for the following elements:

  • IPFS content-addressed hash, which defines the location of an asset on the IPFS network
  • The owner’s public key fingerprint
  • The public key fingerprints of users authorized to access the resource, or a designation as “public”
  • Timestamp

In its current form, DDASH interfaces between the IPFS network and the Ethereum blockchain. One can conceive an alternative version of the DDASH protocol that seamlessly integrates a ledger-based indexing and permission management system, using for example IPFS’s native public and private keys and a native IPFS ledger. Keeping the networking architecture separate from the blockchain has tangible advantages, however, including the versatility of allowing users to create digital assets using any permutation of blockchains, private and public.

3.4 Security

DDASH allows users to manage access to privileged resources using public-key encryption. Public-key encryption allows users to identify themselves on the network using a verifiable public key, which can be used to encrypt resources such that they can only be unencrypted using a  corresponding private key accessible exclusively to the intended recipient. Future versions of the DDASH protocol may feature ways to host resources on private clusters and manage access to these clusters on the blockchain. In doing so, resources are secured by limiting the movement of certain data to a subset of the swarm (network peers), and through a second layer of encryption. This not only allows data to move much more quickly through a network, it also greatly enhances security compared to the antiquated paradigm of data hosted on centralized, and therefore inherently vulnerable, servers. Common sources of wasted IT budgets and wasted productivity, such as forgotten, cracked and stolen passwords, or easily-intercepted HTTP network traffic, are obviated by virtue of the DDASH protocol. What stands between the theoretical underpinnings of this protocol and its implementation in academic centers and healthcare systems is not a question of the feasibility of this technology, but rather, whether legislation governing health information and computing will keep up with emerging trends in computing. Catastrophic beaches of sensitive consumer information, such as the Equifax data breach, have become regular occurrences and urgent reminders of the shortcomings of our antiquated Internet Protocol and undeserved trust in institutions that centralize large amounts of highly sensitive data at individuals’ expense [29].

3.5. DDASH Repository

DDASH is hosted as an open source repository at https://github.com/osmode/ddash.

We intend for this nascent project to illustrate the concepts and the larger vision outlined here while serving as a starting point for a formalized protocol for hosting and interacting with distributed digital assets. We made this a public repository early in the conception of this project in order to allow the codebase to benefit from the technical expertise and creativity of the open source community, and to allow the project to benefit from the rapid and exciting evolution in computing paradigms driven by the blockchain and distributing computing communities.

4. Using DDASH

DDASH currently runs on the blackswan private Ethereum network at 104.236.141.200. It benefits from the open source work produced by the IPFSEthereumOpenPGPweb3.py, and py-ipfs communities.

The Go Ethereum clientweb3.py, and py-ipfs Python packages are all prerequisite. The instructions here are for machines running Ubuntu 16.04. A Ethereum node must be connected to the blackswan private network and possess the ability to lock/unlock accounts to send transactions.

4.1 Directory Structure

Start by creating these directories:

mkdir /home/omarmetwally/blackswan
mkdir /home/omarmetwally/blackswan/gnupg
mkdir /home/omarmetwally/blackswan/data

4.2 Genesis Block

To connect to the blackswan network, you’ll need to use the same genesis block defined in genesis.json (see the Github repository). Move this file to /home/omarmetwally/blackswan/ and set your genesis block (you only need to do this once, and you need to install the Ethereum go client geth and Ethereum developer tools first):

 

geth --datadir=/home/omarmetwally/blackswan/data init /home/omarmetwally/blackswan/genesis.json

bootnode --genkey=boot.key

bootnode --nodekey=boot.key 

4.3 Go Ethereum client and IPFS daemons

In order to use the web3.py and ipfs wrappers, you’ll need to run geth and ipfs daemons in the background, respectively:

geth --verbosity 1 --datadir /home/omarmetwally/blackswan/data --networkid 4828 --port 30303 --rpcapi="db,eth,net,web3,personal,web3" --rpc 104.236.141.200 --rpcport 8545  console 

Be very careful when enabling RPC while your accounts are unlocked. This can lead to Ethereum wallet attacks, hence the recommendation to keep your development environment completely separate from any real Ether you might own.

The above command starts the go Ethereum client on your local machine and attempts to connect to the blackswan server at 104.236.141.200. Remember to set your genesis block according to the above directions. Trying to join this network with a different genesis block (such as the default genesis block) will not work.

Then open a new terminal window or tab and start the ifps daemon:

ipfs daemon

4.4 DDASH command line interface

Once your Ethereum and IPFS nodes are running, your account is unlocked, and you can interact with both clients, start the DDASH command line interface (CLI):

python main.py

                    DDASH
    ::: Distributed Data Sharing Hyperledger :::
    https://github.com/osmode/ddash

    Welcome to the DDASH Command Line Interface.

[1]   ddash> sanity check
      IPFS and geth appear to be running.
[2]   ddash> set directory /home/omarmetwally/blackswan/gnupg
[3]   ddash> new key
[4]   ddash> show keys
[5]   ddash> use key 0
[6]   ddash> show accounts
[7]   ddash> use account 0
[8]   ddash> set recipient your_recipient's_pubkey_id 
[9]   ddash> set file /path/to/clinical/trial/data.csv
[10]  ddash> encrypt
[11]  ddash> upload
[12]  ddash> checkout QmUahy9JKE6Q5LSHArePowQ91fsXNR2yKafTYtC9xQqhwP

The above commands:
1. check if IPFS daemon and Go Ethereum client are running
2. specify working directory (need to have read/write permission)
3. generate a new PGP keypair
4. list all PGP keypairs on your machine
5. uses the first (index 0) keypair as your identity
6. list Ethereum accounts
7. specify index of Ethereum account to use for transactions
8. specify an intended recipient's public key
9. upload the file to IPFS and create transaction containing the hash, user id of the person who uploaded the file, and recipient's public key id (or "public" indicating that it's not encrypted).
10. encrypt file from step 9 using public key from step 8
11. upload file from step 9 to IPFS network
12. check blockchain using IPFS hash as handle

 

4.5 Mining on the blackswan Ethereum network

Mining difficulty is currently relatively easy (1e6) on the blackswan network. Mine Ether by running:

geth --verbosity 4 --datadir /Users/omarmetwally/Desktop/blackswan/data --networkid 4828 --port 30303 --rpc 104.236.141.200--rpcport 8545  --mine console

 

5. Acknowledgements

I’m grateful to my mentor, Dr. David Avrin (UCSF) for his belief in this vision and for his unwavering support. My colleagues, Dr. Michael Wang and Dr. Steven Chan, provided formative feedback during the conception of these ideas. Steven Truong (UC Berkeley) inspired me with his technical creativity. Visionaries such as Vitalik Buterin and Juan Benet, and many brilliant minds contributing to the open source communities they inspired, conceived the technical underpinnings which are allowing these concepts to grow into powerful tools which I believe will transform and modernized academic research. 

6. References

  1. Grover A et al. “The Economics of Academic Medical Centers.” N Engl J Med 2014; 370:2360-2362. June 19, 2014. DOI: 10.1056/NEJMp1403609.
  2. Bohannon J. “Want to be a PI?”Science. June 2 2014. http://www.sciencemag.org/careers/2014/06/want-be-pi-what-are-odds. Accessed: 11 September 2017.
  3. Kaplan K. “A roll of the dice.” Nature 479, 433-435 (2011). doi:10.1038/nj7373-433.
  4. Van Noreen R. “Open access: the true cost of science publishing.” Nature. 27 March 2013. Accessed: 11 September 2017. Available: https://www.nature.com/news/open-access-the-true-cost-of-science-publishing-1.12676.
  5. World Health Organization. “WHO Statement on public disclosure of clinical trial results.” Published: 9 April 2015. Accessed: 11 September 2017. Available: http://www.who.int/ictrp/results/reporting/en/.
  6. Ionnidis JP. “Why most published research findings are false.” PLoS Medicine Published: 30 August 2005. Accessed: 11 September 2017. Available: https://doi.org/10.1371/journal.pmed.0020124.
  7. Narayan A et al. Bitcoin and cryptocurrency technologies. Princeton University Press, 19 July 2016.
  8. Narayan A and Clark J. “Bitcoin’s academic pedigree.” ACM Vol 15:14, 29 August 2017. doi: 10.1145/3134434.3136559
  9. Keyes D. “Amazon looks to gain a machine learning advantage.” Business Insider. Published: 8 September 2017. Accessed: 11 September 2017. Available: http://www.businessinsider.com/amazon-looks-to-gain-a-machine-learning-advantage-2017-9.
  10. Federal Trade Commission. “Data Brokers: A Call for Transparency and Accountability.” Published: May 2014. Accessed: 11 September 2017. Available: https://www.ftc.gov/system/files/documents/reports/data-brokers-call-transparency-accountability-report-federal-trade-commission-may-2014/140527databrokerreport.pdf.
  11. Kimbrough, Julie L., and Laura N. Gasaway. “Publication of government-funded research, open access, and the public interest.” Vand. J. Ent. & Tech. L. 18 (2015): 267.
  12. California State Department of Public Health. “California Taxpayer access to publicly funded research act (Assembly Bill No. 609).” Published: 29 September 2014. Accessed: 11 September 2017. Available: https://leginfo.legislature.ca.gov/faces/billNavClient.xhtml?bill_id=201320140AB609.
  13. Nakamoto, S. “Bitcoin: A peer-to-peer electronic cash system.” Satoshi Nakamoti Institute. Published: 31 October 2008. Accessed: 11 September 2017. Available: http://nakamotoinstitute.org/bitcoin/#selection-2203.14-2203.21 .
  14. Aspnes J et al. “Exposing computationally-challenged Byzantine imposters.” Yale University Department of Computer Science. Published: 26 July 2005. Accessed: 11 September 2017. Available: http://cs.yale.edu/publications/techreports/tr1332.pdf.
  15. Boyle TF. “GLT and GLR: component architecture for general ledgers.”  https://linas.org/mirrors/www.gldialtone.com/2001.07.14/GLT-GLR.htm .
  16. Wood G. “Ethereum: a secure decentralized transaction ledger.” http://gavwood.com/paper.pdf.
  17. Buterin V. “Notes on scalable blockchain protocols.” Ethereum Foundation. Published: 31 May 2015. https://github.com/vbuterin/scalability_paper/blob/master/scalability.pdf.
  18. Y Combinator. June 30th 2017. “IPFS, CoinList, and the Filecoin ICO with Juan Benet .” https://blog.ycombinator.com/ipfs-coinlist-and-the-filecoin-ico-with-juan-benet-and-dalton-caldwell/.
  19. Centers for Disease Control and Prevention. “Health Insurance Coverage.” https://www.cdc.gov/nchs/fastats/health-insurance.htm.
  20. Metwally O. “Building smart contract-based health insurance.” Published: 30 June 2014. https://omarmetwally.wordpress.com/2014/06/30/building-smart-contract-based-health-insurance/.
  21. Angrisano C et al l (McKinsey Global Institute). “Accounting for the cost of health care in the United States.” Jan 2017. http://www.mckinsey.com/industries/healthcare-systems-and-services/our-insights/accounting-for-the-cost-of-health-care-in-the-united-states.
  22. California Department of Health and Human Services. “Treatment Authorization Request.” http://www.dhcs.ca.gov/provgovpart/Pages/TAR.aspx.
  23. Jiwani A et al. “Billing and insurance-related administrative costs in the United States’ health care: synthesis of micro-costing evidence.”  BMC Health Serv Res. 2014 Nov 13;14:556. doi: 10.1186/s12913-014-0556-7.
  24. Hamermesh RG and Guisti K. “One obstacle to curing cancer: patient data isn’t shared.” Harvard Business Review, 28 Nov 2016. https://hbr.org/2016/11/one-obstacle-to-curing-cancer-patient-data-isnt-shared.
  25. Distributed Data Sharing Hyperledger. https://github.com/osmode/ddash.
  26. Fecher B, Friesike S and Hebing M. “What drives academic data sharing?” PLoS One Published: February 25, 2015. Available: https://doi.org/10.1371/journal.pone.0118053.
  27. Ethereum Foundation. “A next-generation smart contract and decentralized application platform.” https://github.com/ethereum/wiki/wiki/White-Paper .
  28. Benet J. “IPFS – content addressed, versioned, p2p file system.” arXiv:1407.3561 [cs.NI].
  29. Gressen S (Federal Trade Commission). “The Equifax Data Breach: What to Do.” Published: 8 September 2017. Available: https://www.consumer.ftc.gov/blog/2017/09/equifax-data-breach-what-do

How to create a private Ethereum network

 

Omar Metwally, MD 
University of California, San Francisco

DDASH - Ethereum Operating System for Knowledge Creation and Sharing
=============================================
    Github repository
    -----------------
    Project website
    -----------------

Objectives:

  1. To create a private Ethereum network
  2. To deploy a simple contract to your private Ethereum network
  3. To interact with a contract on your private Ethereum network

Target audience:  

Ethereum developers.

Necessity: 

The need for this tutorial arises from outdated Ethereum documentation, resulting in hair-pulling, heartburn, and insomnia.

Precautions:

Isolate your development environment, and your private Ethereum network, from any real Ether you might have. It’s easy to compromise your machine and lose real money if you slip up.

Part Two

After you finish this tutorial, check out Part Deux: How to connect 3+ nodes in a private Ethereum network.

Step 1: Set up a virtual server and install Ethereum command-line tools

Many tutorials guide you through deploying contracts using the Ethereum wallet GUI. I’m using the Go Ethereum client (geth) and encourage others to learn how to use the command line interface (CLI). The better you understand the Ethereum client’s internal workings and the anatomy of a blockchain, the more power to you. It doesn’t matter which hosting service you use,  but these instructions assume you’re running an Ubuntu server. [Geth Installation instructions for Ubuntu] 

My private network is called “UCSFnet” at this (fake) IP address 101.102.103.104

Very important: make sure you set aside at least 2GB RAM on your virtual server in order for mining to work. If you skimp on RAM, mining may not work.

Now open a new terminal window, log into your Ubuntu server via SSH and create your working directory called “ucsfnet”

ssh root@101.102.103.104
mkdir ucsfnet
cd ucsfnet
mkdir data
mkdir source

Step 2: Create genesis block

The genesis block is the first block of any blockchain and its parameters are specified in “genesis.json”, which I saved under /root/ucsfnet/genesis.json. My genesis block looks something like this:

{
"config": {
        "chainId": 15,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },

  "alloc"      : {
  "0x0000000000000000000000000000000000000001": {"balance": "111111111"},
  "0x0000000000000000000000000000000000000002": {"balance": "222222222"}
    },

  "coinbase"   : "0x0000000000000000000000000000000000000000",
  "difficulty" : "0x00001",
  "extraData"  : "",
  "gasLimit"   : "0x2fefd8",
  "nonce"      : "0x0000000000000107",
  "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp"  : "0x00"
}

Note that chainId=1 refers to the main Ethereum network, so it’s important to create a unique chainId for your network so your client doesn’t confuse your private blockchain with the main network. For the sake of illustration and testing, set mining difficulty to a low value. Also make sure you specify a unique nonce to start out with. The alloc field allows you to pre-populate accounts with Ether.

Now navigate to the directory where you created your genesis.json file and initialize the bootnode, a node through which your Ethereum client can join your private network and interact with other nodes connected to your private network.

cd /root/ucsfnet/data
geth --datadir=/root/ucsfnet/data init /root/ucsfnet/genesis.json
bootnode --genkey=boot.key
bootnode --nodekey=boot.key

Pay attention to the enode address that the previous commands results. You’ll need this for the next step.

Step 3: Connect to your externally reachable bootnode

The bootnode you created in the previous step is externally reachable, and in this step we’re going to connect to that node to create a one-node network. As you go through this tutorial and expand your knowledge of Ethereum networking, you’ll be able to add infinitely many nodes to your private network. The following commands create the geth.ipc file you’ll need to interact with your network in the subsequent steps. However after completing this tutorial, you’ll be able to skip this step the next time you connect to your network if you’re developing/testing and not using any networking protocols.

Open a new terminal window:

ssh root@101.102.103.104

geth --datadir=/root/ucsfnet/data --bootnodes=enode://148f3....@101.102.103.104:3031

Replace 148f3…. above with the enode address from Step 2. Make sure to include the enode://  prefix.

Step 4: Create a new account and check your balance

Start by opening a new terminal window and connecting to your virtual server via SSH:

ssh root@101.102.103.104
geth attach /root/ucsfnet/data/geth.ipc 
> eth.accounts

You’ll notice that there are no account addresses yet. Now you’ll create your first account. Be sure to replace “mypassword” with a strong password. Remember it and keep it safe; Ethereum is unforgiving in that there is no way to unlock your account if you forget your password!

> personal.newAccount("mypassword")
> web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")

Remember your account’s address, which is prefixed by “0x”. Notice that your account has zero Ether, but don’t be discouraged. I’ll soon turn you into an Ethereum billionaire (but alas, the Ether you collect on your private network is only good on your private network).

Step 5: Mine on your private network

The purpose of mining here is two-fold. First you create Ether which you’ll need to power your transaction through gas (an Ethereum sub-unit). Second, mining incorporates your transactions into the blockchain. Open a new terminal window and connect to your private server:

ssh root@101.102.103.104
geth --datadir=/root/ucsfnet/data --mine --minerthreads=1 --etherbase=0x...

The etherbase parameter specifies the address which should receive the Ether you generate by mining. This should contain your wallet address from Step 4. If you check your account balance again (Step 4), you’ll find that you quickly became a billionaire. Congratulations! Again, the Ether you generate on your private network is only good on your private network, but that’s OK. Your newfound knowledge of how to develop for Ethereum is more valuable than all the Ether in the world.

Step 6: Compile a simple contract

Unfortunately, the official Ethereum documentation has not been updated to reflect the fact that compiling using the solC compiler is no longer possible via RPC. This means that you will end up in a rabbit hole if you try to follow the instructions on the official Ethereum documentation and many other tutorials based on official documentation. There are 2 ways to compile contracts, and I encourage you do try both so you understand what’s going on under the hood.

First install the command-line compiler, solC:

sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install solc

Now open a new terminal window, connect to your server via SSH, and navigate to the directory where your source code will live:

cd /root/ucsfnet/source

And save this demo “greeter” contract in /root/ucsfnet/greeter.sol:

contract mortal {

/* Define variable owner of the type address*/
 address owner;

/* this function is executed at initialization and sets the owner of the contract */
 function mortal() { owner = msg.sender; }

/* Function to recover the funds on the contract */
 function kill() { if (msg.sender == owner) selfdestruct(owner); }
}

contract greeter is mortal {
 /* define variable greeting of the type string */
 string greeting;

/* this runs when the contract is executed */
 function greeter(string _greeting) public {
 greeting = "UCSFnet lives!";
 }

/* main function */
 function greet() constant returns (string) {
 return greeting;
 }
}

Now compile this contract using solC:

solc --bin --abi  -o /root/ucsfnet/source /root/ucsfnet/source/greeter.sol 

In the above command, the bin and abi flags tell the solC compiler to generate Ethereum Virtual Machine (EVM) bytecode and an Application Binary Inferface (ABI) file, respectively. The o flag defines an output directory where these files will be created, and the last argument is the location of the contract (*.sol file) you want to compile.

Compiling a contract this way generates two files:

EVM file, indicated by the *.bin extension. This corresponds to the contract bytecode generated by the web-based compiler, which is easier to use and will be described below.

ABI file, indicated by an *.abi extension. An application binary interface is like an outline or template of your contract and helps you and others interact with the contract when it’s live on the blockchain.

Open both files using vim or your text editor of choice to see what they contain. Understanding what these files contain will make deploying and interacting with your contracts much clearer.

Alternatively, you can use the online compiler. This is easier because you can just copy-paste your Solidity code. However both methods are equivalent, and I’ll elaborate on this below. Copy and paste the code in greeter.sol (above) into the online compiler. Give it a second, and then click on the “Contract details…” link. Notice that the contents of the Bytecode field are equivalent to the greeter.bin file that you created using solC. Also notice that the Interface field is equivalent to the contents of the greeter.abi file you created when you compiled using the command-line solC compiler.

Step 7: Deploy a “Greeter” contract to your private network

Copy the contents of the Web3 deploy field in the online compiler. Paste them into a text editor on your computer and note the bolded changes I made:

var _greeting = 'UCSFnet lives!';

var browser_ballot_sol_greeterContract = web3.eth.contract([{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"greet","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"payable":false,"type":"constructor"}]);

var browser_ballot_sol_greeter = browser_ballot_sol_greeterContract.new(

  _greeting,

  {

    from: web3.eth.accounts[0],

    data: '0x6060604052341561000f57600080fd5b6040516103dd3803806103dd833981016040528080518201919050505b5b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b6040805190810160405280600d81526020017f48656c6c6f2c20576f726c642100000000000000000000000000000000000000815250600190805190602001906100b99291906100c1565b505b50610166565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061010257805160ff1916838001178555610130565b82800160010185558215610130579182015b8281111561012f578251825591602001919060010190610114565b5b50905061013d9190610141565b5090565b61016391905b8082111561015f576000816000905550600101610147565b5090565b90565b610268806101756000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806341c0e1b514610049578063cfae32171461005e575b600080fd5b341561005457600080fd5b61005c6100ed565b005b341561006957600080fd5b61007161017f565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100b25780820151818401525b602081019050610096565b50505050905090810190601f1680156100df5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561017c576000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b5b565b610187610228565b60018054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561021d5780601f106101f25761010080835404028352916020019161021d565b820191906000526020600020905b81548152906001019060200180831161020057829003601f168201915b505050505090505b90565b6020604051908101604052806000815250905600a165627a7a7230582069d50e4318daa30d3f74bb817c3b0cb732c4ec6a493eb108266c548906c8b6d70029',

    gas: '1000000'

  }, function (e, contract){

   console.log(e, contract);

   if (typeof contract.address !== 'undefined') {

        console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);

   }

})

Save the above as myContract.js.

Before we proceed, make sure your account balance is non-zero and that your account is unlocked. If your balance is too low, or if your account is locked, you won’t be able to deploy your contract. Follow the above steps to make sure you generate Ether by mining, and unlock your account as follows (replacing mypassword with the password you invented while creating your account):

Open new terminal window:

ssh root@101.102.103.104 
geth attach /root/ucsfnet/data/geth.ipc 
> web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")
> personal.unlockAccount(eth.accounts[0], "mypassword")

If I’ve lost you, pay attention here because this is important. This is where the Ethereum documentation hasn’t been updated yet, creating confusion regarding how contracts are compiled. Note that the web3.eth.contract() function takes as an argument an ABI. This is the same as the greeter.abi file you created using the solC compiler! Also note that the data field is equivalent to the greeter.bin EVM bytecode, with the exception that it’s prefixed by “0x”. 

Time to deploy your contract:

loadScript(myContract.js)

You should see something like:

Contract mined! address: 0x4000737c8bd7bbe3dee190b6342ba1245f5452d1 transactionHash: 0x0a4c798467f9b40f2c4ec766657d0ec07c324659ea76fcc9c8ad28fc0a192319

Congratulations! Your contract lives at the following address on your private blockchain:

0x4000737c8bd7bbe3dee190b6342ba1245f5452d1

Make a note of this. You’ll need your contract’s address to interact with it (and allow others to do the same).

If this didn’t work, make sure you’re actively mining in another window so that your transaction is incorporated into the blockchain.

Step 8: Interacting with a contract

Again, this is another place where the Ethereum documentation hasn’t yet been updated and refers to deprecated functions. With your geth client fired up, try the following:

> var abi = '[{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"greet","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"payable":false,"type":"constructor"}]'
> var abi = JSON.parse(abi)
> var contract = web3.eth.contract(abi)
> var c = contract.at("0x4000737c8bd7bbe3dee190b6342ba1245f5452d1")
> c.greet()

The first 3 inputs above define what the contract looks like via its ABI. The contract.at() method takes as an argument the address where your contract lives.

You should see the following output:

UCSFnet lives! 

Big caveat: geth chokes if any of your inputs contain illegal characters. Id est:

“ (illegal) is not equal to  " (legal) 

        and

‘ (illegal) is not equal to ' (legal) 

Conclusion

We covered a lot of ground here, from setting up your own Ethereum network to compiling your contract (and avoiding rabbit holes created by outdated documentation) to deploying the contract and interacting with it. Whew! If you ever get stuck and need to start over, just reboot your server and delete your blockchain (understanding the implications of what this means…):

rm -R /root/ucsfnet/data/geth/chaindata

 “Wir werden von so manchen Despoten – etwa Institutionen, Überzeugungen oder auch Neurosen – beherrscht, die wir aus dem Weg räumen können, wenn wir sie analysieren und verstehen.”

We are ruled by so many despots — institutions, convictions, and neuroses — which we can clear away, if we analyze and understand them

— Isaiah Berlin

Portland smoke

Support my research!

If you find this information helpful, please consider supporting my research by donating Ether or Bitcoin. Equitable, transparent, high-quality healthcare for all!

ETH donations:  0x1b4Ba9c1811233805dC4f12Ca32F22cfD85DB212

BTC donations:  1Ef7oYi1zVpA4bw7hUcD8841wbdtCw4Xen

Suggested reading:

  • Nice low-level description of networking in Ethereum (uses the Python-based client):

https://ocalog.com/post/10/ 

  • Setting up private network or local cluster

https://github.com/ethereum/go-ethereum/wiki/Setting-up-private-network-or-local-cluster

  • Connecting to the network

https://github.com/ethereum/go-ethereum/wiki/Connecting-to-the-network

  • The Go Ethereum client

https://github.com/ethereum/go-ethereum

  • Official Ethereum command line tool documentation

https://ethereum.org/cli

Learn Ethereum the hard way

Clear Paper

 

Note: In the spirit of open collaboration, I’m  keeping a public lab notebook of my work as a Clinical Informatics Fella at UCSF. Whether you cite or steal this, remember to build cool things that help people live healthier lives.

 

Educational objectives

There are a number of excellent technically focused blog posts on Ethereum out there. If you are interested in building Ethereum applications, I recommend making your way through these technical references (see end of article). This article is intended for non-technical readers interested in understanding, on a high level, the real-world implications of Ethereum’s application paradigm. More specifically, you should be able to answer these questions after reading this article:

  • What is Ethereum and how does it work?
  • Should I use Ethereum for my project?
  • What are the pros & cons of Ethereum?

 

Welcome to Hell

Let’s pretend you have a crazy boss (let’s call her Mary) who’s set on making your life difficult. You and Mary meet every month to check in and make sure you’re both on track. Mary takes out her notebook and takes notes while you share with her what’s going well and what’s not going as well. Because you’re an honest (and somewhat naive) person who hasn’t yet encountered someone like Mary, you start using these meetings as opportunities to speak openly, give and receive feedback, finding comfort in the fact that Mary’s faithfully keeping a record — a ledger — of your conversations. A month passes, and then two months, and Mary’s insanity pervades the workplace. With each subsequent meeting with Mary, she seems to glare at you with wider crazy-eyes, clench her teeth until they sound like they’re about to crack, and stabs her pen ever harder into her notebook while she keeps records of your discussions.

Three months into your job, you’re fed up with her madness and decide to resign (fortunately, you’re not a medical resident or other indentured servant and have the freedom to do so). Mary leads you to a quiet corner, throws a death stare at you, and growls: “If you resign, I will personally make sure you never find a job ever again.” By this point, the stench of bodies in Mary’s closet is overwhelming, and you email Mary to give 30-day notice. Then all hell breaks loose.

In following month, Mary copies you on several emails to her bosses. One of the emails accuses you of harassing her assistant (whom you’ve never interacted with). Another email warns you of several missed deadlines (for projects which never existed). Some emails state that no one has been able to reach you by email or phone (you’ve answered every call and email in the most timely fashion). You’re neither the first nor last of Mary’s victims, and you quickly learn that she’s more than a psychopath, she’s also written the book on psychological manipulation, deception, and torture. She’s creating a fictitious paper trail by sending contrived emails and writing a book of alternative facts, which her complicit assistant is co-authoring.

How can you shed light on Mary’s evil tactics and show others that her ledger is as legitimate as an acid trip? Because you’re a clever hacker, you decide to use Ethereum to shed light on a rancid situation.

Magic-Mushrooms-768x443.jpeg

 

A Distributed Ledger 

Pretend the Ethereum “blockchain” is a magic notebook that serves as a ledger. This notebook can appear in anyone’s hands, and every copy of this notebook is identical. This magic notebook is so smart it can understand your commands and write on its own pages. When one of its pages is written on, the other notebooks vote whether to accept the new page. If they do accept the new page, this change is reflected in every magic notebook. These magic notebooks follow you into meetings with Mary and record their own version of “the truth.” Each page in this notebook is analogous to a “block” in a “blockchain.”

So you buy yourself a magic notebook and bring it to your next meeting with Mary. As usual, she’s preparing her own notebook of alternative facts.  Her assistant, Karen, also shows up to the meeting with her own notebook of alternatively alternative facts. So there you are, in Mary’s office with Mary and Karen, everyone clutching their notebooks.

You:  "I quit."  (magic notebook hears this and writes it on page 1)

Mary:  "Good riddance." (magic notebook hears this and writes it on page 2)

You:  "Before I leave, you still owe me a paycheck." (magic notebook hears this and writes it on page 3)

Karen:  "You picked up the paycheck last week. We owe you nothing." (magic notebook hears this and writes it on page 4)

You:  "No you didn't. I've been asking you for that paycheck for weeks."(magic notebook hears this and writes it on page 5)

Realizing this is going no where, you walk out of Mary’s office carrying your magic notebook.

You next see Mary and Karen in court: you’re suing them for unpaid wages, and you bring along your magic notebook to set the facts right. When the judge asks you when you announced that you’re quitting, your magic notebook recites what’s written on page one: your statement (“I quit”) along with a timestamp. Mary and Karen jump to their feet and hold up copies of their own notebooks. However, the judge did her research on this new magic notebook, which is reputed to be the best ledger in the history of mankind because it doesn’t rest in any one person’s or organization’s hands. The truth doesn’t rest in Mary or Karen’s notebooks or email inboxes (or in either of their minds); the truth — the Ethereum ledger — is the account provided by the magic notebook, which is in everyone’s hands and is guaranteed to contain the same text on every page .

It’s worth repeating emphatically here that the Ethereum blockchain is a distributed ledger. 

Realizing the signifiance of this jargon-laden statement, you decide to go further than just shedding light on Mary’s career of lies and deception. You’re going to make Mary pay for all of the people she’s abused and manipulated over the years, and you’re going to do it with Ethereum. As you study this article and read more about how Ethereum works, you realize that the magic notebook is more than just a record of events. The notebook can execute logic (in the form of “contracts”) and store/modify/delete data. This is one big difference between Bitcoin and Ethereum. A Turing-complete system, such as Ethereum, can execute logic; unlike Bitcoin, the Ethereum Virtual Machine (EVM) is a stack machine. You can write contracts that transfer money and include basic logic to allow others to interact with your contract in a transparent manner. Anyone interested in examining a contract can do so.

If you had heard of Ethereum before you started working for Mary, you could have written a contract that states something like:

 

MARY SENDS MAGIC NOTEBOOK $100,000 EVERY MONTH

EVERY 2 WEEKS, MAGIC NOTEBOOK SENDS ALL EMPLOYEES $5,000

IF AN EMPLOYEE RESIGNS:

    MAGIC NOTEBOOK SENDS THEM A FINAL PAYCHECK

    MAGIC NOTEBOOK REMOVES THEM FROM LIST OF EMPLOYEES

 

Unlike a traditional contract, Ethereum contracts:

  • are transparent and can be examined by anyone
  • are trustless, meaning they execute faithfully and automatically
  • do not need lawyers or courts for interpretation

As your knowledge of Ethereum grows, you realize that you would have been better off writing your employment contract on the Ethereum blockchain rather than relying on Mary and her team of corporate attorneys. Had your contract been written on the Ethereum blockchain, you wouldn’t have had to rely on Mary’s sanity or lack thereof to get paid. The codified contract would execute autonomously, can be reviewed by you or anyone else, and does not need middlewomen/middlemen to interpret or execute (Auf Wiedersehen lawyers, HR staff, administrators, etc). In case Mary was still delusional enough to argue with the Ethereum ledger, the magic notebook would quickly provide proof of payment (or lack thereof) and the conditions under which the logic was executed. The logic on the Ethereum blockchain is transparent.

The current paradigm of hosting applications on a private server is analogous to doing business with Mary and Karen. The logic is centralized and opaque. I trust most applications about as much as I trust Mary and Karen. The average application is hosted on one or a cluster of privately owned and operated servers, and most applications are not open source (and even if they are open source, the average user doesn’t have the means to perform checksums and make sure they’re running the code they think they are). If the server crashes or the application behaves in unexpected ways, well, hard luck fella. Why would anyone trust the software equivalent of Mary & Karen when they could trust a decentralized ledger running autonomously executing logic?

Without getting too bogged down in details, I include this simple example of an Ethereum contract that creates a simple voting mechanism.

pragma solidity ^0.4.0;
contract Ballot {

struct Voter {
 uint weight;
 bool voted;
 uint8 vote;
 address delegate;
 }
 struct Proposal {
 uint voteCount;
 }

address chairperson;
 mapping(address => Voter) voters;
 Proposal[] proposals;

/// Create a new ballot with $(_numProposals) different proposals.
 function Ballot(uint8 _numProposals) {
 chairperson = msg.sender;
 voters[chairperson].weight = 1;
 proposals.length = _numProposals;
 }

/// Give $(voter) the right to vote on this ballot.
 /// May only be called by $(chairperson).
 function giveRightToVote(address voter) {
 if (msg.sender != chairperson || voters[voter].voted) return;
 voters[voter].weight = 1;
 }

/// Delegate your vote to the voter $(to).
 function delegate(address to) {
 Voter sender = voters[msg.sender]; // assigns reference
 if (sender.voted) return;
 while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender)
 to = voters[to].delegate;
 if (to == msg.sender) return;
 sender.voted = true;
 sender.delegate = to;
 Voter delegate = voters[to];
 if (delegate.voted)
 proposals[delegate.vote].voteCount += sender.weight;
 else
 delegate.weight += sender.weight;
 }

/// Give a single vote to proposal $(proposal).
 function vote(uint8 proposal) {
 Voter sender = voters[msg.sender];
 if (sender.voted || proposal >= proposals.length) return;
 sender.voted = true;
 sender.vote = proposal;
 proposals[proposal].voteCount += sender.weight;
 }

function winningProposal() constant returns (uint8 winningProposal) {
 uint256 winningVoteCount = 0;
 for (uint8 proposal = 0; proposal < proposals.length; proposal++)
 if (proposals[proposal].voteCount > winningVoteCount) {
 winningVoteCount = proposals[proposal].voteCount;
 winningProposal = proposal;
 }
 }
}
[Source:  https://solidity.readthedocs.io/en/develop/solidity-by-example.html%5D

 

Why develop on Ethereum?

Now that you know how Ethereum works, you have the luxury of living to witness one of the most interesting, exciting, and important developments in computing, and you too can design and develop applications on the Ethereum blockchain. Why not write an employment contract on the Ethereum blockchain that gives you and your peers a democratic way of removing problematic elements in the workplace? Or an employment contract that distributes an organizations profits more equitably and transparently? But before you can decide whether it makes sense to ditch a virtual server running your standard Python/Ruby/NodeJS/PHP/[fill in the blank] stack in favor of Ethereum, you should note a few more pros and cons of Ethereum:

Unlike the Bitcoin protocol, which is a distributed ledger of transactions based on monetary (Bitcoin) inputs and unspent transactional outputs, Ethereum is account-based. This is getting into technical details that may not interest the intended audience of this post, but it should be noted that in Ethereum there are account addresses identify users as well as individual contracts written to the Ethereum blockchain. Like Bitcoin, the Ethereum protocol is based on a cryptocurrency called Ether, which is used to fund all transactions on the Ethereum blockchain (more on this below). And just like an address that you can use to send and receive Bitcoin and Ether payments, your Ethereum contracts also have addresses which function as handles to allow users to interact with your code and identify it on the Ethereum blockchain.

 

Basic anatomy of an Ethereum contract

An Ethereum contract consists of the code you write and the state of the contract (i.e. the data associated with the contract). As described in the Solidity documentation, the magic happens in between the curly brackets, the body of a contract:

contract requestFile {

    // stuff happens here ...

}

The “stuff” consists of state variables, functions, function modifiers, and events, which will look familiar to you if you’re fluent in one of many programming languages that use these paradigms.

State variables are permanently stored in contract storage and include types such as integers (int and uint), booleans (bool), addresses (address, address.balance, address.transfer), fixed and dynamically-sized byte arrays (bytes, string), string literals, enums, structs, and mappings (similar, but not identical to, hash tables). The EVM uses standard logical operators, including comparison operators, bit operators, and index access. See the reference above for more details.

How large is a contract storage area? Vitalik Buterin answers this here. Bottom line: 2^261 bytes. That means that you’ll never really be limited by size, but rather, by the cost of conducting transactions on the Ethereum blockchain (see “Economics of Ethereum contracts” below).

Functions work similarly to other programming languages and take the form of:

function audit() returns (address addr) {
    // stuff happens here...
}

As described in the Solidity documentation, functions can be called internally or externally and have different levels of visibility, like in programming languages such as C++, Java and Python.

Function modifiers “amend the semantics of functions in a declarative way.” I’ll skip the technical details here.

Events are basically functions that use the EVM’s logging mechanism. If you’ve developed Android apps, you’ve probably used something similar.

If you’re itching to deploy a real contract to the Ethereum blockchain, check out my earlier tutorial.

 

Economics of Ethereum contracts

On a macro scale, Ethereum is a giant computer powered by every machine running the full Ethereum client. Just like every step and breath we take costs energy, so too does every computation performed by your computer require a finite amount of electrical energy. The Ethereum network is no different. The energy required to keep adding blocks to the blockchain, transfer Ether, and execute contracts is provided in the form of “gas” (an Ethereum subunit). Unlike a local machine such as your laptop, and unlike a virtual server (which runs on a real machine too), Ethereum contracts are interpreted by the Ethereum Virtual Machine, the stack machine that converts Solidity code into instructions to interact with the Ethereum blockchain.  Unlike the Bitcoin protocol, in which each transaction has a predictable cost to the network, the cost of transactions on the Ethereum blockchain depends on bandwidth consumed, computational power, and the size of data that’s being manipulated. Each transaction specifies how much gas it is willing to consume and a gas price. In the event of unused gas, the sender receives gas_rem * gas_price, and the miner of the block receives a reward of (startgas-gas_rem) * gas_price. Id est, there is a cost of conduction transactions, and miners, are rewarded financially for using their own computational power to create new blocks on the blockchain and keep the ledger going.

The economics of current application development profoundly shape how software is developed and used. Many consumer-facing applications are available for a cost on app stores or can be downloaded for a fee; many other consumer-facing applications are supported by adverts, in-app purchases, and subscription fees. Ethereum’s transactional economics were designed to safeguard against malicious agents, and understanding the Ethereum blockchain economy is important to understanding how applications on the Ethereum blockchain will function. This is illustrated in the “Security considerations” section below.

There are some good websites with details on Ethereum economics, including Ethereum’s Design Rationale and Ethereum Gas Economics.

 

Security considerations

What better way to learn good security practices on the Ethereum blockchain than to confront the most malicious of actors, your former wicked boss? While you’ve been writing Ethereum applications, Mary learned a thing or two about this Ether thingy and wrote their own contract to hinder the Ethereum network and suck your account dry of Ether. Let’s say that Mary tricks her next hapless victim into executing an Ethereum contract that does the following:

contract youGotPunked {

    function newEmployee(address dest, uint employeeId) {
        while(true) { };
    }
}

Mary is tricking her next batch of employees who aren’t savvy enough to study the contract into calling an infinite loop. If you’ve ever written an infinite loop on your machine, you know you can hang your machine by wasting all of your machine’s computing resources on executing a loop that does nothing forever. Mary’s new employees call the contract, which then runs forever, wasting computing resources across the Ethereum network. Because each transaction (such as calling the above contract) costs gas, Mary can’t use this old trick to lock up the Ethereum network.

Mary goes back to the drawing board and comes up with another contract (this example is also provided in the Solidity documentation):

contract TxAttackWallet {
    address owner;

    function TxAttackWallet() {
        owner = msg.sender;
    }

    function() {
        TxUserWallet(msg.sender).transferTo(owner, msg.sender.balance);
    }
}

When Mary’s hapless new employees call this contract, it empties all of their funds (msg.sender.balance) into Mary’s account (address owner). People have used their understanding of Ethereum’s blockchain and simple tactics such as this account emptying trick to transfer hundreds of millions of dollars worth of Ether in unexpected ways. Bottom line: there is no such thing as a perfectly secure system. The amount of energy expended in securing a system should be proportional to what’s at stake. Ethereum is no more or less inherently secure than Google or Microsoft’s applications.

 

Ethereum in healthcare 

I’m drawn to an Ethereum-based electronic health record for the same reasons I wouldn’t want anything to do with Mary and Karen. The next generation of EHRs on a blockchain should:

  • be secure, with fail-proof access control
  • be infallible, with mechanisms to deter malicious attacks on the network
  • be distributed, so that patients, providers, and researchers can benefit from responsible use data
  • be distributed, so that inter-operability is a given
  • be distributed, so that data is never lost (while preserving consensus)
  • be transparent, so that there’s an audit trail of who is accessing what
  • be transparent, so that there’s an audit trail of all transactions on the blockchain
  • be transparent, allowing health services to be rendered in the most cost-effective way possible
  • be autonomous, allowing health services to be rendered without costly third-parties who currently monopolize health data

 

Now enough White, Yellow, Mauve and Clear Papers. Let’s see some code!

 

Acknowledgements

“It’s only work if you’d rather be doing something else” (JM Barrie). I couldn’t think of a better way to spend my time, thanks to this opportunity to be a Clinical Informatics Fella at UCSF Medical Center. I’m grateful to UCSF’s Department of Hospital Medicine, my mentor, Dr. David Avrin, and my colleagues Dr. Michael Wang and Dr. Steven Chen, for their support and feedback.

 

References

  1. https://solidity.readthedocs.io/en/develop/solidity-by-example.html
  2. https://remix.ethereum.org
  3. http://ethdocs.org/en/latest/
  4. https://github.com/ethereum/wiki/wiki/Design-Rationale
  5. https://en.wikipedia.org/wiki/Bloom_filter
  6. https://ethereum.github.io/yellowpaper/paper.pdf
  7. http://whatthefuckisethereum.com/#nerd

 

 

 

 

 

 

Comments on the California Department of Public Health’s proposed regulations on medical cannabis

Note: The opinions I express here should not be construed as medical or legal advice. Marijuana is classified by the federal government as a Schedule I drug. Protect your freedom and your health by consulting a lawyer and your doctor for legal and medical advice.

In response to the California Department of Public Health’s invitation to comment on proposed regulations on medical cannabis:

I welcome the State of California’s proposed regulations for the manufacturing of medical cannabis, which I believe will help protect the safety of individual consumers and communities. I offer here my opinions on these proposals.

Despite its federal status as a Schedule I drug, cannabis is used medicinally by millions of Americans. Although only a small handful of compounds produced by plants in the Cannabis genus have been characterized, this number continues to grow as evolving legislation opens doors to medical and scientific research. Many of these compounds are known to possess therapeutic potential, individually or in synergy with other compounds. In the absence of a comprehensive body of scientific literature on C. sativa and C. indica, patients and recommending providers have few tools to help them tailor cannabis-based therapeutics, largely relying on empiric observations and trial-and-error. Each strain has a unique portfolio of psychoactive and non-psychoactive compounds which affect individuals uniquely.

Safeguarding health consumers’ safety should be the primary goal of these proposed regulations. Protecting communities and preserving the environment are also of paramount importance. The proposed regulations offer many theoretical benefits. My critique stems from a concern that these regulations, whether intentionally or unintentionally, place the interests of larger growers over smaller growers. I fear the rise of the cannabis industry’s equivalent of “Big Tobacco.” The proposed regulations disproportionately burden smaller growers with financial and bureaucratic hurdles which I worry will render so-called “Cottage” operations non-viable. The proposed regulations would impose a higher fee-to-revenue ratio for “Cultivation Licenses” for Tier 1 operations, defined as those yielding less than $100,000 in annual revenues, compared to higher tier operations.

For instance, Section 8305 and Section 8313 (“Cannabis waste management”) do not discriminate between small and very small growers, and large operations which pose much greater threats to the environment and water supply.

Favoring larger growers over smaller growers poses a threat to medical cannabis’ genetic diversity by incentivizing growers to produce the most profitable strains, rather than supplying the market with a variety of strains to meet the diverse needs of patients. This is the case with conventional as well as organic produce.

I urge the State of California to consider creating a separate category for “micro-entities,” which I define here for the sake of argument as growers possessing no more than 6 plants. Regulations should also discriminate between micro-entities who manufacture medical cannabis for their personal consumption, and micro-entities who sell what they produce. The current definition of “commercial cannabis activity” as activities that include “cultivation, possession, manufacture, processing, storing, laboratory testing, labeling, transporting, distribution, or sale of medical cannabis or a medical cannabis product” is problematic because it does not make the aforementioned distinction. The rationale for imposing regulations on large growers to protect consumers, communities, and the environment does not apply equally to large and small growers. Micro-entities should be subject to regulations that do not disproportionately burden them and should be exempt from much of the administratively burdensome language of these proposals. Because micro-entities do not share the same financial incentives as large growers, I hope that making it easier for micro-entities to manufacture medical cannabis would promote the genetic diversity of medical cannabis.

I would also like to briefly comment on the language of a few other statements which caught my attention. Section 8401 describes a “Track-and-Trace” system that would allow the State of California to account for the production and dissemination of medical cannabis products. We should apply our experience with other industries to prevent State and private monopolies from hindering innovation. I use the example of Electronic Health Records because of my familiarity with the healthcare industry: stringent regulation on electronic medical record vendors has promoted the formation of monopolies to the detriment of innovators who would have otherwise worked to develop more functional and less expensive software. It is crucial that a State-sponsored Track-and-Trace system feature an open API which would facilitate the growth of an ecosystem of tools to help growers and manufacturers comply with these regulations.

I also advocate against a separate “Nursery License”, particularly for smaller growers, because it would impose further licensing hurdles for these growers.

Article 1, Section 8000, Subsection (f) states: “Commingling is prohibited in Section 8207 of these proposed regulations to retain the integrity and clear accountability of the product.” I strongly agree with this statement for the aforementioned reasons.

Subsection (t) defines “outdoor cultivation” as “a method of cultivation techniques that does not use light deprivation techniques. Outdoor growers who rely entirely on natural sunlight can utilize light deprivation to harvest up to 4 times annually. I find the definition of outdoor cultivation inaccurate and misleading. Outdoor cultivation could instead be defined by whether or not electrical energy is the primary light source for marijuana plants.

My final comments pertain to county regulations rather than state regulations, but I would like to express them here since state regulations supersede county regulations. Mendocino County imposes regulations on marijuana farms which also apply to vineyards, such as having restrooms in greenhouses, limits to the maximum incline grade leading to a greenhouse, and the construction of greenhouses. Again, safety of patients, cannabis industry workers, communities, and the environment is paramount. At the same time, It’s worth bearing in mind that the nature of a medical marijuana farm is much different than a vineyard. To consumers of medical cannabis, marijuana is medication. A vineyard is a recreational area and its product has no therapeutic indication accepted by the medical community. I again urge the writers of these regulations and California voters to consider a more nuanced definition of “commercial cannabis activity” than the current one.

Thank you for the opportunity to comment on these proposed medical cannabis manufacturing regulations.

Respectfully,

Omar Metwally, MD

 

Healthcare on the Ethereum Blockchain

Since Ethereum’s conception, I’ve dreamed of a blockchain-based healthcare services economy and presented the idea at BitTorrent’s headquarters 3 years ago. It’s also taken me that long to conceive of a concrete study of this protocol’s readiness for the limelight. With Ethereum’s adoption by a number of blue chip companies, including JP Morgan and Microsoft, its inevitability is clear. While still unreachably abstract to many people, I believe that healthcare’s state of disarray is a perfect environment to test the waters. As I get ready to start a Clinical Informatics fellowship at UCSF Medical Center, I’m prototyping such a blockchain-based health services marketplace and would like to humbly present the proposal to the Ethereum community for its feedback.

Pricing for healthcare services is currently based on prices determined by insurance companies’ ability to negotiate price points with groups of healthcare providers, individual providers, and healthcare systems. The lack of a true free market, and insurance companies’ administrative overhead, contribute to inflated prices for healthcare services across the board. [Figure 1: Health services marketplace in the blockchain era]

Slide1

Figure 1: Health services marketplace in the blockchain era. Red text indicates how things work presently. Green indicates how things might work in a health services economy founded on the Ethereum blockchain. Notice the absence of insurance companies in the latter, hypothetical scenario. Their role has yet to be determined. I use laboratory testing as an example, but this would apply to imaging studies, office visits, surgical procedures, and consultations.

 

Enter Ethereum, a next-generation blockchain protocol for automatically executing “smart contracts.” Autonomously executed contracts obviate the need for escrow, attorneys, and administrators. Like Bitcoin’s protocol, Ethereum is a distributed blockchain that is open source, not owned by anyone, and runs off any and all computers running the client software. Ethereum’s novelty – and power – lies in the fact that it’s a Turing-complete system. Ethereum, unlike Bitcoin has mechanisms for executing logic, so smart contracts can be written by anyone, hosted on the Ethereum blockchain, and anyone in the world can interact with these contracts with the endpoint of manipulating data and moving money in the form of Ether (also a cryptocurrency).

So why not harness the Ethereum protocol to create a distributed, open source healthcare marketplace? Without administrative overhead (which accounts for the majority of an insurance company’s expenses, which are then passed on to patients and healthcare systems) and with the freedom for any provider of healthcare services to bid for a service (imaging, lab testing, consultations, procedures…), I hypothesize that the cost of healthcare services will be reduced to approximately 10% of its current artificially inflated price. Further contributing to cost and redundancy of healthcare expenditures is data siloing, the isolation of data on servers without APIs to set them free. Many healthcare providers will agree that it’s often much easier to repeat an expensive study than obtain records of that same procedure performed at an outside hospital (even if the study was just performed hours or days ago, and oftentimes, even if the study was performed at an affiliated hospital!). Ethereum’s distributed blockchain is a global ledger of everyone’s health information. I predict that sound security protocols, which need to be developed with healthcare’s unique needs in mind, will necessitate the use of biometric data to associate data on the blockchain with individuals.

So, how can we test the former hypothesis, that Ethereum can reduce the cost of healthcare services to 10% of their current prices?

I propose simulating such a bidding system to start collecting data on the free market prices Ethereum will foster by surveying physicians based in the community, as well as groups contracting with academic medical centers. If I survey Dr. Roentgen, Dr. Tomo, and Dr. Houndsfield (and a few hundred other radiologists) asking them if they would accept $X cash payment for imaging study A, B, or C (e.g. chest x-ray, mammogram, brain MRI…) performed STAT, tomorrow, or next month, we will start to approach theoretical market price for these studies.

If you are a fellow Ethereum developer or are otherwise interested in collaborating in the spirit of establishing healthcare as a human right on the Ethereum blockchain, please send me a line! I’m dreaming up experiments and am seeking partners in code.

Portland smoke

[Daydreaming in Portland]

Omar Metwally, MD

Sunday April 30th, 2017

Portland, Oregon