Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

(This is a brief summary of Ethereum's white paper)

Ethereum 101

What is Ethereum

Ethereum is a new cryptocurrency, like Bitcoin or Litecoin, that adds a number of new features. Most notably the inclusion of Agents (also known as Contracts); Independent Turing-complete programs that exist on the Ethereum blockchain. These Agents can receive Ether (Ethereum's currency) and other inputs, perform computations, hold balances, transfer Ether, and even activate other Agents.

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

Agents

At it's core Ethereum is just like any other cryptocurrency. You can transfer ether between wallets, ether can be mined, people can trade ether for goods and services. However Ethereum includes the idea of Agents. An Agent is a Turing-complete program that part of an Ethereum wallet. Whenever a wallet that has an Agent receives a transaction, the Agent's program is executed. Since the program is attached to a wallet, it can hold a balance, make transfers, and has persistent storage on the blockchain 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 within 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 useful.

How are Agents executed?

Agents are executed as part of the mining process. All of the Agent's code and persistent 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 ether transaction made, writing/reading for persistent 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 activate 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 instructions of any Agent to be executed without fees. This allows the Agent to decide if the transfer to activate it is capable of covering it's execution costs, if not it stops before any fees could be incurred. Example:

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

It's more useful to think of ether is a currency of computational 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 incentivized to participate in mining because without specialized hardware they will never get rewarded for mining blocks since block rewards are distributed on a first-come-first-serve basis. 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. Secondly, a different mining algorithm 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 scenario, this prevents specialized hardware and maintains the democratic nature of mining. Worst-case scenario, 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 representation 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 simplified language notation. See the white paper for actual examples.

Crop Insurance You could create a financial 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. More complex examples could involve multiple information sources or payment being inversely related to 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[DROUGHT_THRESHOLD]:
	make_transfer(agent.storage[PAYOUT], FARMER)

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 withdrawal 100% of the funds. Bob can withdrawal 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 malicious, 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_withdrawal = tx.data[0]

//Check the date and reset withdrawal 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_LIMIT] = 0
	agent.storage[BOB_LIMIT]   = 0

if tx.sender == ALICE
	amount_available = agent.balance * 0.01 - agent.storage[ALICE_LIMIT]
	if amount_to_withdrawal <= amount_available:
		make_transfer(amount_to_withdrawal, ALICE)
		agent.storage[ALICE_LIMIT] = agent.storage[ALICE_LIMIT] + amount_to_withdrawal
elif tx.sender == BOB:
	recipent = BOB
	amount_available = agent.balance * 0.0005 - agent.storage[BOB_LIMIT]
	if amount_to_withdrawal <= amount_available:
		make_transfer(amount_to_withdrawal, BOB)
		agent.storage[BOB_LIMIT] = agent.storage[BOB_LIMIT] + amount_to_withdrawal
//Dual signing transactions is outside of the scope of the article, so we're simplifying here
elif tx.sender == BOB_AND_ALICE:
	amount_available = agent.balance
	if amount_to_withdrawal <= amount_available:
		make_transfer(amount_to_withdrawal, ALICE)
		stop

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 independently, but how it runs can be changed at a later date by interested parties. More interestingly, a network of Agents could be created which all communicate with eachother through the block chain, able to modify eachother's code.

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]

--- Scott Tolksdorf, github.com/stolksdorf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.