Technology Behind Smart Contracts 15minTechnology Behind Smart Contracts 15min Samer Mahfouz CFA...
Transcript of Technology Behind Smart Contracts 15minTechnology Behind Smart Contracts 15min Samer Mahfouz CFA...
Technology Behind Smart Contracts
15min
Samer Mahfouz CFA
Financial Innovation Specialist
Email: [email protected]
Smart Contracts
30 July 2015 3 Jan 2009
Smart Contracts
~7y
3 Oct 2017 12 July 2017
Public, Permissionless Private, Permissioned
2y
2 July 2001
~7y
File sharing
Send as many copies Money
Double Spending problem
Anything
1999
MP3 music
sharing
~2y
Ethereum, Fabric & Corda are Turing Complete
Alan Turing was highly influential in the development of theoretical computer
science, providing a formalisation of the concepts of algorithm and computation
with the Turing machine, which can be considered a model of a general
purpose computer. Turing is also known for his work on breaking of German
Enigma machine in WW2.
The bomb was an electro-mechanical device used by British
cryptologists to help decipher German Enigma-machine-
encrypted secret messages during WW2
What it means to be Turing Complete ?
4
1. You can write 0’s and 1’s on a tape/memory.
2. You have conditional branching: If “condition 1 is true” do Action1
otherwise do Action2
(if (myAccount >= $10) then send $10 to Viktorija otherwise exit)
3. Have “infinite” amount of memory
– Practically it means enough memory to run a program.
– Normally, achieved using loops instead of infinite memory.
Essentially, it means, ability to
write programs (contracts) that
can solve any reasonable
computational problem.
5
Charateristic Ethereum Hyperledger Fabric R3 Corda
Description Generic blockchain platform Modular blockchain platform -Specialized distributed ledger platform
for financial industry.
-Designed to account for the highly
regulated environment of the financial
services industry.
Governance -Public: Ethereum developers, major
mining pools, major exchanges.
- Private: miners.
Linux Foundation R3
Mode of operation (participation to
consensus)
-Permissioinless public or private
- Nodes are identical,
-Permissioned, private
-Nodes have different roles
(nodes are clients, peers or orderers)
-Permissioned, private
-Nodes have different roles
(notary nodes)
Consensus - Mining based on Proof-of-Work (PoW)
- Consensus at Ledger level
- Broad understanding of consensus that
allows multiple approaches.
-Transaction level
- Specific understanding of consensus
(i.e. notary nodes)
- Transaction level
Smart contracts languages Solidity Go, Java Kotlin, Java
Currency - Ether
- Tokens via smart contract
used to pay rewards to miners and
transaction fees.
- None
- Currency and tokens via chaincode (=smart
contract)
- None
Anonymity Pseudoanonymous (can be linked to an
address but not a name)
No No
Privacy No Based on owner and access he grants to
other
Based on owner and access he
grants to other
Cost of operation (Consensys) High (~$10m/day) Only parties taking part in a transaction
have to reach consensus.
Only parties taking part in a
transaction have to reach
consensus.
Business Logic (1st step in writing a smart contract)
A contract is a set of rules between 2 parties (or more) which govern the exchange of good and services between the two parties.
Labor, Knowledge, …
Salary, bonus, perks
1. Define the KPIs
2. Measure the KPIs
3. If KPIs are met, pay salary to employee at month end.
Amazon Purchase
7
You order a
phone from
Amazon
1
Phone company list
phones for sale
Transaction Account
2
3
Oder is sent to
the warehouse
Order is sent to
the shipping
company
Shipping may include multiple
shipping companies and custom
crossing
4
5 6
Package delivered
If no complaint by Buyer before a set date,
forward money to merchant
Otherwise Raise a Dispute case
7
Linked Smart Contract
8
Master Smart Contract
Customer & Merchant
Smart Contract
Shipping
Smart Contract
Disputer Resolution
Smart Contract
The Vision: A well written smart contract
should be able to replicate the business logic of a company.
Dapps and DAO
Dapps – Decentralized Applications
DAO – Decentralized Autonomous Organizations
9
DAO is a set of Smart Contracts that are interconnecting to run an organization automatically.
Amazon as a DAO - Business Workflow
10
IF (warehouse confirm item shipment ) AND (shipping company confirm item shipment)
THEN
(Pay x% of the transaction to the merchant)
End
IF (item is received by customer based on last mile delivery company) AND (Y number of
days passed)
THEN IF ( No dispute raised by the buyer)
THEN
(Pay the merchant transaction value - x% - platform commission)
ELSE
(raise an ODR tracking ticket and send it to ODR smart contract)
END
END
-Tracking #
-Time stamp
-Geo position
-Digital Signature
Writing a Token
Smart Contract
1. Ethereum Blockchain Browser and Wallet
Install Mist or Ethereum Wallet
https://github.com/ethereum/mist/releases
Mist is an Ethererum Browser provided by the
Ethereum foundation. It has a wallet too,
called the Ethereum Wallet.
Mist includes the Ethereum Wallet.
Current we are at version 0.10,
so not even version 1! Which tells you that it is still work in progress.
12
2. Run the Remix IDE development run in a Browser
How to create and publish a smart contract
2. Run Remix
http://remix.ethereum.org
Remix a browser based IDE developed by the Ethereum developers.
Source editor, file manager, compiler and debugger.
13
3. Pick the ERC20 Token Standard template (Smart contract template used for creating tokens)
ERC20 (Ethereum Request for Comments) Token Standard Interface defines standard functions a token contract can implement.
Motivation: These functions will allow dapps and wallets to handle tokens across multiple interfaces/dapps.
Most important “ERC20 interface” functions are:
1. BalanceOf --------(Get the account balance of another account with address _owner)
2. Transfer -----------(Send _value amount of tokens to address _to)
3. Transfer event --- (Triggered when tokens are transferred)
(if (myAccount >= 10) then send 10 to Viktorija otherwise exit)
If BalanceOf (myAccount) >= 10 then Transfer(10, Viktorija_Account) otherwise exit) Transfer event (ex: send SMS message to my phone) ----triggered in case of Transfer
14
4. Write your token Program in Solidity
Create a Token
15
5. Start the Ethereum Wallet
16
You need to deploy the contract from tour main account.
6. Enter the needed parameters before deploying the contract
Enter the required parameters for your ERC20 token
17
CFAT
7. Deploy the contract
Enter the fee and authorize the transaction by entering your wallet password
18
8. View Created tokens in your wallet
19
CFAT
CFAT
9. Transfer Tokens from one account to another
20
I will transfer the new token from main account to Account1 and check the transaction on etherscan
CFAT CFAT
10. Define the token in your metamask wallet
Check the transaction on etherscan then define the token in the wallet metamask account.
21
11. Check your token on Etherscan: The contract has an address
22
CFAT
Smart Contracts Recognized under Tennessee Law! --23 Mar 2018
23