Skip to content

Instantly share code, notes, and snippets.

@KartikTalwar
Forked from stolksdorf/Ethereum 101.md
Last active August 29, 2015 13:58
Show Gist options
  • Save KartikTalwar/10169362 to your computer and use it in GitHub Desktop.
Save KartikTalwar/10169362 to your computer and use it in GitHub Desktop.

Abstract : The goal of this article to to breifly summarized and make more accesible the main points of the Ethereum white paper. This article assumes a working knowledge of the basics of cryptocurrencies.

Ethereum 101

What is Ethereum

Ethereum is a new cryptocurrency, like Bitcoin or Litecoin, but adds a number of new features. Most notably the inclusion of Agents (or contracts in Ethereum jargon). Independant Turing-complete programs that exist on the ethereum blockchain and are distributaly. These Agents can receive Ether (Ethereums currency), transfer Ether, hold balances, even activate other Agents.

Ethereum also attempts to fix some current issues with cryptocurenncy mining, such as specialized hardware, large mining pools that aim to control the network, and the lack of reward for stale blocks, disincentivzing miners with weaker hardware.

Agents

At it's core Ethereum is just like anyother cryptocurrency. You can transfer the currency (ether) between wallets, ether can be mined, people can trade ether for goods and services. However Ethereum includes the idea of Agents (or contracts in Ethereum jargon). An Agent is a Turing-complete program that can be attached to an Ethereum wallet. Whenever that wallet recieves a transaction, the program is executed. Since the program is attached to a wallet, it can hold a balance, make transfers, and has limited and persistant storage on the blockcahin itself**. It is a completely independent entity, is executed in a completely distributed way, and is open source.

The Agent's code is also kept wihtin this storage, allowing an Agent to modify it's source code during execution. Check out Decentralized Autonomous Organizations in the Examples to see how this can be used.

How are Agents executed?

Agents are executed as part of the mining process. All of the Agent's code and persistant memory is stored within the block chain. Whenever a miner processes a transaction to an Agent, they also must process and execute the Agent's code. As a reward for doing this, the Agent must pay the miner additional (although, very small) fees. The fees are related what the Agent does during the execution; Each transaction made, writing/reading for persistant memory, even for each line of code. This encourages miners to process the transactions involving to Agents, and encourages the Agents to be efficient with their execution.

This system protects the network from two types of attacks. Firstly, malicious Agents could try to run infinitely using all the resources on the miner's computer. But since each action has a fee associated with it, the Agent would quickly run out of money. Secondly, malicious parties could try to activate the Agent many times, attempting to drain it's operating balance. However, since to actiavte an Agent, the party must actually transfer currency to the Agent, covering it's operating costs.

To farther protect against this type of attack the Ethereum protocol allows for the first 16 lines of any Agent to be executed without fees. This allows the Agent to decide if the transfer to actiavte it is capable of covering it's execution costs, if not it stops before any fees could be incurred. Example:

if amount_to_withdrawl < 100 * block.basefee:
	stop
elif:
	//rest of program here...

It's more useful to think of ether is a currency of computatonal power, rather than of money. You get rewarded ether for running Agents, and you can transfer that ether to your own agents for them to run.

Mining

Bitcoin and other cryptocurrency mining currently favours specialized hardware and collective mining pools. Both go against the core idea of distributed mining. Not everyone is incentivised to participate in mining because without specialized hardware they will never get rewarded for mining blocks (this is called mining a "Stale Block").

Ethereum combats this in two ways. Firstly, Ethereum rewards miners who end up mining stale blocks a partial amount of the total reward. It's no longer a first-come-first-serve reward system, but rewards people for trying to participate in maintaining the network through mining.

Secondly, a different mining alogorithm is being used. Some cryptocurrencies use scrypt as their mining algorithm, which is computational expensive, but uses very little memory. This allows the production of specialized hardware that can run scrypt in parallel. Ethereum's mining algorithm, called Dagger, will be both computational difficult and memory intensive. Reading and writing to memory will become the bottle-neck. Best-case scenerio, this prevents specialized hardware and maintins the democratic nature of mining. Worst-case scenerio, people figure out how to create specialized hardware, which would accelerate computing technology ahead by years. Either way, a win-win.

Examples

Having access to a cryptographically secure reresentation of value and a Turning-complete language allows you to build nearly anything in Ethereum. We'll cover a few use cases here to give the reader an idea of how flexible and powerful this system is. Note: These examples use a simplifed language notation for the reader and is not actual Ethereum script. See the white paper for actual examples.

  1. Crop Insurance You could create a finicial derivative using EthereumScript, like crop insurance for farmers. The owner of the derivative sends new rainfall data to the Agent and the Agent can pay out the farmers accordingly in case of a drought.

This is a very basic example, but I hope the reader can image the complexity of the derivatives that could be created using this system, such as being paid out based inversely on the rainfall.

//Make sure the activation fee will cover our execution cost
if tx.value < 200 * block.basefee:
	stop
//If it's the owner, update the Agent's knowledge of the rainfall
if tx.sender == OWNER:
	agent.storage[CURRENT_RAINFALL] = tx.data[0]
	stop
if agent.storage[CURRENT_RAINFALL] < agent.storage[THRESHOLD]:
	make_transfer(agent.storage[PAYOUT], FARMER)
  1. Savings Account Alice wants to keep her funds safe, but worried about the lose/theft of her private key. She contacts Bob, a bank, with whom they create an Agent that will hold Alice's funds. Alice can ask the Agent for up to 1% of her funds per day (which is fine for her). If she needs more, both her and Bob together can withdrawl 100% of the funds. Bob can withdrawl 0.05% of the funds per day, incase Alice's private key gets stolen they can still recover some funds. If Bob turns out to be malious, Alice can still withdraw her funds 20x faster than Bob.
//Make sure the activation fee will cover our execution cost
if tx.value < 200 * block.basefee:
	stop

amount_to_withdrawl = tx.data[0]

//Check the date and reset withdrawl limits
if block.timestamp > agent.storage[NEXT_DAY]
	agent.storage[NEXT_DAY]       = block.timestamp + 86400 //set the limit check to the next day
	agent.storage[ALICE_WTIHDRAW] = 0
	agent.storage[BOB_WTIHDRAW]   = 0

if tx.sender == ALICE
	amount_available = agent.balance * 0.01 - agent.storage[ALICE_WTIHDRAW]
	if amount_to_withdrawl <= amount_available:
		make_transfer(amount_to_withdrawl, ALICE)
		agent.storage[ALICE_WTIHDRAW] = agent.storage[ALICE_WTIHDRAW] + amount_to_withdrawl
elif tx.sender == BOB:
	recipent = BOB
	amount_available = agent.balance * 0.0005 - agent.storage[BOB_WTIHDRAW]
	if amount_to_withdrawl <= amount_available:
		make_transfer(amount_to_withdrawl, BOB)
		agent.storage[BOB_WTIHDRAW] = agent.storage[BOB_WTIHDRAW] + amount_to_withdrawl
//Dual signing transactions is outside of the scope of the article, so I'm simplifying here
elif tx.sender == BOB_AND_ALICE:
	amount_available = agent.balance
	if amount_to_withdrawl <= amount_available:
		make_transfer(amount_to_withdrawl, ALICE)
		stop
  1. Decentralized Autonomous Organizations A DAO is essentially an Agent that can change it's own code given a voting majority of selected individuals. This allows the Agent to operate independantly, but how it runs can be changed at a later date by a majority party.

A real world example of this is setting up an Agent that will payout a list of shareholders each quarter. If over 50% of the shareholders agree they can kick out an existing member from that list. Let's look at how we would implement that kind of voting system within a DAO.

//Our three actions we could do are:
// 1) Submit a shareholder change for a vote
// 2) Vote in favour of shareholder change
// 3) Finalize vote

//Make sure the activation fee will cover our execution cost
if tx.value < 200 * block.basefee:
	stop

//The new sharehodler lsit will be sent in tx.data[1]
if tx.data[0] == SHAREHOLDER_CHANGE:
	agent.storage[NEW_LIST] = tx.data[1];
	agent.storage[NUM_VOTES] = 1;
	agent.storage[tx.sender + VOTED] = 1;

elif tx.data[0] == VOTE_IN_FAVOR:
	//Make sure the shareholder hasn't voted already
	if agent.storage[tx.sender + VOTED] == 0:
		agent.storage[tx.sender + VOTED] = 1
		agent.storage[NUM_VOTES] += 1;

elif tx.data[0] == FINALIZE:
	if agent.storage[NUM_VOTES] > agent.storage[NUM_SHAREHOLDERS] * 0.5:
		agent.storage[SHAREHOLDER_LIST] = agent.storage[NEW_LIST]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment