SlideShare a Scribd company logo
1 of 53
Download to read offline
PYTHON IN CHAINS
RUNNING PYTHON CODE FOR IOT PROJECTS
ON A CUSTOM-BUILT BLOCKCHAIN NETWORK
Daniel Hong (홍석현) | @unifiedh
“I KNOW THERE HAS BEEN A LOT OF HYPE
SURROUNDING BLOCKCHAIN TECH, BUT…
PYTHON ON THE BLOCKCHAIN?
ISN’T THAT LIKE…”
Photo courtesy of: Hyunse Lee
“지역주민과 함께 읽는 한국학:
파이썬으로 읽는 디지털 인문학”
“Korean Studies with local residents:
Learning Digital Humanities using Python”
…NOPE.
1. Python is a universal language that can run on almost every computer.
SOME BASIC FACTS:
2. Blockchain platforms can also act as a computer, and be programmed like any other computer.
3. Python and some blockchain platforms share a similarly structured runtime architecture.
BLOCKCHAIN PLATFORMS AS A COMPUTER
Ethereum Virtual Machine (EVM)
BLOCKCHAIN PLATFORMS AS A COMPUTER
Ethereum Virtual Machine (EVM)
Provides a Turing-complete execution environment
Provides a high level programming language
& easier code deployment support
Adjustable code execution fees (Gas)
Better blockchain extensibility for
application usage
CODE EXECUTION ON THE EVM
pragma solidity ^0.4.11;
contract hello
{
string world;
constructor() public
{
world = "Hello, World!";
}
function sayHello() public view returns (string)
{
return world;
}
}
Solidity Code (Smart Contract)
CODE EXECUTION ON THE EVM
pragma solidity ^0.4.11;
contract hello
{
string world;
constructor() public
{
world = "Hello, World!";
}
function sayHello() public view returns (string)
{
return world;
}
}
Solidity Code (Smart Contract)
Ethereum Blockchain
Compile & Deploy
CODE EXECUTION ON THE EVM
pragma solidity ^0 .4 .1 1 ;
contract hello
{
string world;
constructor() public
{
world = "Hello, World!";
}
function sayHello() public view returns (string)
{
return world;
}
}
Solidity Code (Smart Contract)
Ethereum Blockchain
Compile & Deploy
Application Code
Smart Contract
Interaction Library
Access Smart Contract
via Contract ABI
BLOCKCHAIN PLATFORMS AS A COMPUTER
Ethereum Virtual Machine (EVM)
Poor development environment support
Confusing language syntax
Inefficient Gas system
(The Extensibility Issue)
Language compatibility
Resource-intensive;
not suitable for embedded systems
BLOCKCHAIN PLATFORMS AS A COMPUTER
Ethereum Virtual Machine (EVM)
Poor development environment support
Confusing language syntax
Inefficient Gas system
(The Extensibility Issue)
Language compatibility
Resource-intensive;
not suitable for embedded systems
PYTHON TO THE RESCUE
PYTHON TO THE RESCUE
Integrating Smart Contracts with existing
Python code and applications
Writing & Compiling Ethereum Smart Contracts
with Python
Modifying & Running the EVM
on embedded devices for IoT system development
PYTHON TO THE RESCUE
Integrating Smart Contracts with existing
Python code and applications
Writing & Compiling Ethereum Smart Contracts
with Python
Modifying & Running the EVM
on embedded devices for IoT system development
SMART CONTRACT INTEGRATION
‣ web3.py: A Python implementation of the web3.js library (originally written in JavaScript);
used to call Smart Contract code within local Python code
‣ Populus: A Python-based Smart Contract development environment
for Ethereum blockchain developers using Python
‣ Py-EVM: A Python implementation of the Ethereum Virtual Machine (EVM) itself;
will modify this to build a custom implementation of the EVM optimized for embedded systems
SOME PREREQUISITES:
‣ Trinity: An Ethereum blockchain client based on the Py-EVM project
& completely written in Python
SMART CONTRACT INTEGRATION
INSTALLING REQUIRED SOFTWARE & LIBRARIES
# Install solc & py-solc
$ brew update; brew upgrade; brew tap ethereum/ethereum; brew install solidity
$ python3 -m solc.install v0.4.11
# Install Populus
$ brew install pkg-config libffi autoconf automake libtool openssl
$ pip3 install populus
# Install Trinity
$ pip3 install -U trinity
SMART CONTRACT INTEGRATION
WRITING A “HELLO WORLD” SMART CONTRACT
& INTEGRATING SOLIDITY CODE WITH PYTHON
pragma solidity ^0.4.11;
contract hello
{
string world;
constructor() public
{
world = "Hello, World!";
}
function sayHello() public view returns (string)
{
return world;
}
}
Solidity Code (Smart Contract)
./contracts/hello.sol
SMART CONTRACT INTEGRATION
WRITING A “HELLO WORLD” SMART CONTRACT
& INTEGRATING SOLIDITY CODE WITH PYTHON
pragma solidity ^0.4.11;
contract hello
{
string world;
constructor() public
{
world = "Hello, World!";
}
function sayHello() public view returns (string)
{
return world;
}
}
Solidity Code (Smart Contract)
./contracts/hello.sol
Python Code
./tests/test_HelloWorld.py
def test_HelloWorld(chain):
hi, _ = chain.provider.get_or_deploy_contract(hello)
helloString = hi.call().sayHello()
assert helloString == “Hello, World!” #Test Only
def test_HelloWorld(chain):
hi, _ = chain.provider.get_or_deploy_contract(hello)
helloString = hi.call().sayHello()
assert helloString == “Hello, World!” #Test Only
SMART CONTRACT INTEGRATION
WRITING A “HELLO WORLD” SMART CONTRACT
& INTEGRATING SOLIDITY CODE WITH PYTHON
pragma solidity ^0.4.11;
contract hello
{
string world;
constructor() public
{
world = "Hello, World!";
}
function sayHello() public view returns (string)
{
return world;
}
}
Solidity Code (Smart Contract)
./contracts/hello.sol
Python Code
./tests/test_HelloWorld.py
1. chain argument: py.test fixture, provided by populus’ pytest plugin
- chain object provided by populus, creates & calls a temp blockchain (“tester”) on memory
2. Creates a web3 contract object instance that corresponds to the hello contract written in Solidity
- The hi object created here acts as a wrapper for Solidity code for use within Python
3. Call the sayHello() function
defined within the hello contract
4. (Used with pytest) Check whether the hello contract was executed successfully
SMART CONTRACT INTEGRATION
TESTING SMART CONTRACT INTEGRATION WITH PYTEST
# Create a new Populus Project
$ mkdir helloTest
$ cd helloTest
$ populus init
$ rm contracts/Greeter
$ rm tests/test_greeter.py
# Copy Solidity & Python source code
$ cp ~/sources/hello.sol contracts/hello.sol
$ cp ~/sources/test_HelloWorld.py tests/test_HelloWorld.py
# Compile & Deploy on a test blockchain
$ populus compile
$ populus deploy —chain tester hello
# Run pytest
$ py.test
SMART CONTRACT INTEGRATION
TESTING SMART CONTRACT INTEGRATION WITH PYTEST
$ populus compile
SMART CONTRACT INTEGRATION
TESTING SMART CONTRACT INTEGRATION WITH PYTEST
$ populus deploy —chain tester hello
SMART CONTRACT INTEGRATION
TESTING SMART CONTRACT INTEGRATION WITH PYTEST
$ py.test
PYTHON TO THE RESCUE
Integrating Smart Contracts with existing
Python code and applications
Writing & Compiling Ethereum Smart Contracts
with Python
Modifying & Running the EVM
on embedded devices for IoT system development
PRIVATE BLOCKCHAIN SETUP FOR IOT
Private Ethereum Blockchain
Controller Smart Contract
Django Controller Server
Web Browser Mobile App
Raspberry Pi Raspberry Pi
Raspberry Pi Raspberry Pi
Coffee Machine Curtains
Light Controllers A/C
PRIVATE BLOCKCHAIN SETUP FOR IOT
Private Ethereum Blockchain
Controller Smart Contract
Django Controller Server
Web Browser Mobile App
Raspberry Pi Raspberry Pi
Raspberry Pi Raspberry Pi
Coffee Machine Curtains
Light Controllers A/C
?
EVM CODE EXECUTION OVERVIEW
THE ETHEREUM BLOCKCHAIN
Block N Header:
Previous Block Hash Nonce Timestamp Uncle Hash Beneficiary
Logs Bloom PoW Difficulty Extra Data Block Number
Gas Limit Used Gas Amount Mix Hash
State Root Transaction Root Receipt Root
Block N+1 Header:
Previous Block Hash Nonce Timestamp Uncle Hash Beneficiary
Logs Bloom PoW Difficulty Extra Data Block Number
Gas Limit Used Gas Amount Mix Hash
State Root Transaction Root Receipt Root
Receipt Merkle Tree
Transaction Merkle Tree
Receipt Merkle Tree
Transaction Merkle Tree
Nonce Code Hash Balance Storage Root
Code
Nonce Code Hash Balance Storage Root
Merkle-Patricia State Trie for block N Merkle-Patricia State Trie for block N+1
73 95
Uncle Block Headers List Uncle Block Headers List
THE ETHEREUM BLOCKCHAIN
Block N Header:
Previous Block Hash Nonce Timestamp Uncle Hash Beneficiary
Logs Bloom PoW Difficulty Extra Data Block Number
Gas Limit Used Gas Amount Mix Hash
State Root Transaction Root Receipt Root
Block N+1 Header:
Previous Block Hash Nonce Timestamp Uncle Hash Beneficiary
Logs Bloom PoW Difficulty Extra Data Block Number
Gas Limit Used Gas Amount Mix Hash
State Root Transaction Root Receipt Root
Receipt Merkle Tree
Transaction Merkle Tree
Receipt Merkle Tree
Transaction Merkle Tree
Nonce Code Hash Balance Storage Root
Code
Nonce Code Hash Balance Storage Root
Merkle-Patricia State Trie for block N Merkle-Patricia State Trie for block N+1
73 95
Uncle Block Headers List Uncle Block Headers List
EVM CODE EXECUTION OVERVIEW
THE ETHEREUM VIRTUAL MACHINE: AN OVERVIEW (MEMORY MANAGEMENT)
‣ Memory: A temporary storage area used when calling functions, or when during
regular memory operations
‣ Stack: No concepts of “registers” are provided; a virtual stack is used instead for operations
such as opcode parameters
‣ Storage: A permanent key-value storage mapping 256-bit words to 256-bit words;
memory space declared outside user-defined functions & within the contract context are stored here
Reference: https://github.com/comaeio/porosity/wiki/Ethereum-Internals
EVM CODE EXECUTION OVERVIEW
THE ETHEREUM VIRTUAL MACHINE: OPCODES & ASSEMBLY
‣ The EVM is (theoretically) language independent; however, due to its architectural limitations
the EVM cannot take full advantage of all features present in modern programming languages
& requires some unique language syntax (to access unique EVM features)
‣ The EVM implements a simple instruction set to make up EVM bytecode (to ensure platform / ISA
independence)
‣ The EVM can also be directly programmed at a low-level using an Assembly Language provided
by Solidity; Assembly can be used along with Solidity code with inline Assembly
EVM CODE EXECUTION OVERVIEW
THE ETHEREUM VIRTUAL MACHINE: OPCODES & ASSEMBLY
‣ The EVM is (theoretically) language independent; however, due to its architectural limitations
the EVM cannot take full advantage of all features present in modern programming languages
& requires some unique language syntax (to access unique EVM features)
‣ The EVM can also be directly programmed at a low-level using an Assembly Language provided
by Solidity; Assembly can be used along with Solidity code with inline Assembly
EVM CODE EXECUTION OVERVIEW
‣ The EVM implements a simple instruction set to make up EVM bytecode (to ensure platform / ISA
independence)
Reference: https://ethereum.github.io/yellowpaper/paper.pdf
Reference: http://unpyc.sourceforge.net/Opcodes.html
WILL IT BE POSSIBLE
TO DEVELOP A SMART CONTRACT
USING PYTHON?
SOME METHODS TO PORTING PYTHON TO THE EVM
2. ADDING EVM-SPECIFIC SYNTAX TO PYTHON AS A SUPERSET
OF THE PYTHON LANGUAGE
3. (OUR APPROACH) ALLOWING PYTHON CODE TO COMPILE DIRECTLY TO EVM BYTECODE
WITHOUT LARGELY MODIFYING OR ADDING PYTHON LANGUAGE SYNTAX
1. IMPLEMENTING THE PYTHON INTERPRETER ITSELF AS A SMART CONTRACT
IN SOLIDITY
SOME METHODS TO PORTING PYTHON TO THE EVM
1. IMPLEMENTING THE PYTHON INTERPRETER ITSELF AS A SMART CONTRACT
IN SOLIDITY
‣ However, as the EVM is a distributed execution environment, this method may consume
excessive compute power & Gas (which is very inefficient in terms of extensibility)
‣ Jython (the JVM implementation of Python) uses this method to run Python code on the JVM
(Reimplementing the Python language with Java, rather than C as used by standard CPython)
‣ Because this method abstracts the language compilation process through a
modular implementation, existing pure Python code is almost completely reusable
SOME METHODS TO PORTING PYTHON TO THE EVM
‣ The problem: adding new syntax to Python means backwards compatibility cannot be ensured
with existing Python code (Can Python with added custom syntax be still considered as Python?)
‣ Similar to how Objective-C added object-oriented programming capabilities with added syntax
while also maintaining full backwards compatibility with C
‣ The Ethereum Foundation chose a similar approach with a new language called Vyper,
which also targets the EVM (like Solidity) but with Pythonic syntax
2. ADDING EVM-SPECIFIC SYNTAX TO PYTHON AS A SUPERSET
OF THE PYTHON LANGUAGE
OUR SOLUTION: A FULL PYTHON PORT
BUILDING A PYTHON COMPILER THAT TARGETS THE EVM
pragma solidity ^0.4.11;
contract Wallet
{
mapping (address => uint) public balance;
function deposit()
{
balance[msg.sender] += 1;
}
function withdraw(uint value)
{
if(balance[msg.sender] < value) throw;
balance[msg.sender] -= 1;
if(!msg.sender.call.value(value)()) throw;
}
}
Solidity Code (Smart Contract)
OUR SOLUTION: A FULL PYTHON PORT
BUILDING A PYTHON COMPILER THAT TARGETS THE EVM
pragma solidity ^0.4.11;
contract Wallet
{
mapping (address => uint) public balance;
function deposit()
{
balance[msg.sender] += 1;
}
function withdraw(uint value)
{
if(balance[msg.sender] < value) throw;
balance[msg.sender] -= 1;
if(!msg.sender.call.value(value)()) throw;
}
}
Solidity Code (Smart Contract) Python Code (Smart Contract)
import ethereum as eth
class Wallet(eth.contract):
balance = eth.mapping(eth.address, int)
def deposit():
balance[eth.msg.sender] += 1
def withdraw(value: int):
if balance[eth.msg.sender] < value:
raise ValueError
balance[eth.msg.sender] -= 1
if not eth.msg.sender.call.value(value)():
raise ValueError
OUR SOLUTION: A FULL PYTHON PORT
BUILDING A PYTHON COMPILER THAT TARGETS THE EVM
Python Source Code
Bytecode Translation
Python Bytecode
(.pyc)
Python Virtual Machine
Library Modules
Code Execution
A standard CPython implementation of Python
OUR SOLUTION: A FULL PYTHON PORT
BUILDING A PYTHON COMPILER THAT TARGETS THE EVM
Python Source Code
Grammar
Python Bytecode
(.pyc)
Python Virtual Machine
Library Modules
Code Execution
A standard CPython implementation of Python
Lexer
Parser
Compiler
OUR SOLUTION: A FULL PYTHON PORT
BUILDING A PYTHON COMPILER THAT TARGETS THE EVM
Python Source Code
On-the-fly
EVM Bytecode Translation
EVM Bytecode
Modified EVM
Code Execution
Precompiled EVM bytecode
(Imported as Python Library)
Deploy
Our Python-EVM Implementation Structure
OUR SOLUTION: A FULL PYTHON PORT
BUILDING A PYTHON COMPILER THAT TARGETS THE EVM
Python Source Code
EVM Bytecode
Code Execution
Our Python-EVM Implementation Structure
Precompiled EVM bytecode
(Imported as Python Library)
Deploy
Grammar (CPython)
Modified Lexer
(Added EVM-specific tokens)
Modified Parser
(Generates Solidity-style structure)
Compiler with solc backend
Modified EVM
OUR SOLUTION: A FULL PYTHON PORT
BUILDING A PYTHON COMPILER THAT TARGETS THE EVM
pragma solidity ^0.4.11;
contract Wallet
{
mapping (address => uint) public balance;
function deposit()
{
balance[msg.sender] += 1;
}
function withdraw(uint value)
{
if(balance[msg.sender] < value) throw;
balance[msg.sender] -= 1;
if(!msg.sender.call.value(value)()) throw;
}
}
Solidity Code (Smart Contract) Python Code (Smart Contract)
import ethereum as eth
class Wallet (eth.contract):
balance = eth.mapping(eth.address, int)
def deposit():
balance[eth.msg.sender] += 1
def withdraw(value: int):
if balance[eth.msg.sender] < value:
raise ValueError
balance[eth.msg.sender] -= 1
if not eth.msg.sender.call.value(value)():
raise ValueError
1. ethereum module: A Python wrapper that allows
EVM-specific features to be called within
Python code
2. Wallet class: inherits the contract class
defined within the ethereum module
to define a Contract
3. eth.mapping: returns an access token
to the Mapping type value ;
eth.address: same as the address type defined
with Solidity (20 byte value)
4. Modified syntax to access
Mapping type variable
OUR SOLUTION: A FULL PYTHON PORT
DYNAMIC PYTHON-STYLE ETHEREUM VIRTUAL MACHINE
Python Source Code
EVM Bytecode
Code Execution
Our Python-EVM Implementation Structure
Precompiled EVM bytecode
(Imported as Python Library)
Grammar (CPython)
Modified Lexer
(Added EVM-specific tokens)
Modified Parser
(Generates Solidity-style structure)
Compiler with solc backend
Modified EVM
Deploy
‣ …but I cannot disclose all of them in detail just yet
‣ Execution Logic Improvements: No simultaneous code execution on devices
marked as “embedded”; only codehash checks (integrity insurance) are performed on-device
‣ AOT Compiler: Allows ahead-of-time EVM bytecode compilation with embedded devices
OUR SOLUTION: A FULL PYTHON PORT
DYNAMIC PYTHON-STYLE ETHEREUM VIRTUAL MACHINE
ONE MORE THING…
“IS THE EVM
EFFICIENT ENOUGH?”
BLOCKCHAIN PLATFORMS AS A COMPUTER
Ethereum Virtual Machine (EVM)
Poor development environment support
Confusing language syntax
Inefficient Gas system
(The Extensibility Issue)
Language compatibility
Resource-intensive;
not suitable for embedded systems
GEMER: AN OPEN SOURCE, DISTRIBUTED RUNTIME
THANK YOU
Further inquiries: me@unifiedh.com
Personal GitHub: github.com/unifiedh

More Related Content

What's hot

Metamorphosing Indian Blockchain Ecosystem
Metamorphosing Indian Blockchain EcosystemMetamorphosing Indian Blockchain Ecosystem
Metamorphosing Indian Blockchain EcosystemDr. Amarjeet Singh
 
Cryptocurrency products from hashCash
Cryptocurrency products from hashCashCryptocurrency products from hashCash
Cryptocurrency products from hashCashHashCash Consultants
 
Challenges of applying Blockchain to enterprise systems in NTTDATA
Challenges of applying Blockchain to enterprise systems in NTTDATAChallenges of applying Blockchain to enterprise systems in NTTDATA
Challenges of applying Blockchain to enterprise systems in NTTDATAHyperleger Tokyo Meetup
 
Blockchain, Hyperledger and the Oracle Blockchain Platform
Blockchain, Hyperledger and the Oracle Blockchain PlatformBlockchain, Hyperledger and the Oracle Blockchain Platform
Blockchain, Hyperledger and the Oracle Blockchain PlatformJuarez Junior
 
Top 10 Reasons to Learn Blockchain | Blockchain Training | Blockchain Tutoria...
Top 10 Reasons to Learn Blockchain | Blockchain Training | Blockchain Tutoria...Top 10 Reasons to Learn Blockchain | Blockchain Training | Blockchain Tutoria...
Top 10 Reasons to Learn Blockchain | Blockchain Training | Blockchain Tutoria...Edureka!
 
Blockchain Technology and its role in the process of public sector innovation
Blockchain Technology and its role in the process of public sector innovationBlockchain Technology and its role in the process of public sector innovation
Blockchain Technology and its role in the process of public sector innovationsamossummit
 
Smart Contracts Programming Tutorial | Solidity Programming Language | Solidi...
Smart Contracts Programming Tutorial | Solidity Programming Language | Solidi...Smart Contracts Programming Tutorial | Solidity Programming Language | Solidi...
Smart Contracts Programming Tutorial | Solidity Programming Language | Solidi...Edureka!
 
The GeeqChain Project Summary
The GeeqChain Project SummaryThe GeeqChain Project Summary
The GeeqChain Project SummaryKris Bruynson
 
Blockchain technology overview
Blockchain technology overviewBlockchain technology overview
Blockchain technology overviewRishabhMalik32
 
How to Build a Decentralized Blockchain App with the Oracle Blockchain Platform
How to Build a Decentralized BlockchainApp with the Oracle Blockchain PlatformHow to Build a Decentralized BlockchainApp with the Oracle Blockchain Platform
How to Build a Decentralized Blockchain App with the Oracle Blockchain PlatformJuarez Junior
 
An architectural approach for decentralized applications
An architectural approach for decentralized applicationsAn architectural approach for decentralized applications
An architectural approach for decentralized applicationsOWASP Indonesia Chapter
 
Eco [3 c] introduction of national pki-sg-jaejung kim-15_apr10
Eco [3 c] introduction of national pki-sg-jaejung kim-15_apr10Eco [3 c] introduction of national pki-sg-jaejung kim-15_apr10
Eco [3 c] introduction of national pki-sg-jaejung kim-15_apr10Hai Nguyen
 
Alexander Shulgin, founder & CEO, Gruppa Kompaniy Familia - What do we mine n...
Alexander Shulgin, founder & CEO, Gruppa Kompaniy Familia - What do we mine n...Alexander Shulgin, founder & CEO, Gruppa Kompaniy Familia - What do we mine n...
Alexander Shulgin, founder & CEO, Gruppa Kompaniy Familia - What do we mine n...Techsylvania
 
Blockchain Technology | Blockchain Explained | Blockchain Tutorial | Blockcha...
Blockchain Technology | Blockchain Explained | Blockchain Tutorial | Blockcha...Blockchain Technology | Blockchain Explained | Blockchain Tutorial | Blockcha...
Blockchain Technology | Blockchain Explained | Blockchain Tutorial | Blockcha...Edureka!
 
Apidays x api3 9th dec
Apidays x api3   9th decApidays x api3   9th dec
Apidays x api3 9th decBenCarvill1
 
ICON Smart Contract Development
ICON Smart Contract DevelopmentICON Smart Contract Development
ICON Smart Contract DevelopmentICON Foundation
 
Jincor - investment attractiveness report (Digital Rating Agency)
Jincor - investment attractiveness report (Digital Rating Agency)Jincor - investment attractiveness report (Digital Rating Agency)
Jincor - investment attractiveness report (Digital Rating Agency)digitalrating
 

What's hot (20)

Metamorphosing Indian Blockchain Ecosystem
Metamorphosing Indian Blockchain EcosystemMetamorphosing Indian Blockchain Ecosystem
Metamorphosing Indian Blockchain Ecosystem
 
Cryptocurrency products from hashCash
Cryptocurrency products from hashCashCryptocurrency products from hashCash
Cryptocurrency products from hashCash
 
Challenges of applying Blockchain to enterprise systems in NTTDATA
Challenges of applying Blockchain to enterprise systems in NTTDATAChallenges of applying Blockchain to enterprise systems in NTTDATA
Challenges of applying Blockchain to enterprise systems in NTTDATA
 
Blockchain, Hyperledger and the Oracle Blockchain Platform
Blockchain, Hyperledger and the Oracle Blockchain PlatformBlockchain, Hyperledger and the Oracle Blockchain Platform
Blockchain, Hyperledger and the Oracle Blockchain Platform
 
WIPO Blockchain Whitepaper
WIPO Blockchain WhitepaperWIPO Blockchain Whitepaper
WIPO Blockchain Whitepaper
 
Top 10 Reasons to Learn Blockchain | Blockchain Training | Blockchain Tutoria...
Top 10 Reasons to Learn Blockchain | Blockchain Training | Blockchain Tutoria...Top 10 Reasons to Learn Blockchain | Blockchain Training | Blockchain Tutoria...
Top 10 Reasons to Learn Blockchain | Blockchain Training | Blockchain Tutoria...
 
Blockchain with iot
Blockchain with iotBlockchain with iot
Blockchain with iot
 
Blockchain Technology and its role in the process of public sector innovation
Blockchain Technology and its role in the process of public sector innovationBlockchain Technology and its role in the process of public sector innovation
Blockchain Technology and its role in the process of public sector innovation
 
Smart Contracts Programming Tutorial | Solidity Programming Language | Solidi...
Smart Contracts Programming Tutorial | Solidity Programming Language | Solidi...Smart Contracts Programming Tutorial | Solidity Programming Language | Solidi...
Smart Contracts Programming Tutorial | Solidity Programming Language | Solidi...
 
The GeeqChain Project Summary
The GeeqChain Project SummaryThe GeeqChain Project Summary
The GeeqChain Project Summary
 
Blockchain technology overview
Blockchain technology overviewBlockchain technology overview
Blockchain technology overview
 
How to Build a Decentralized Blockchain App with the Oracle Blockchain Platform
How to Build a Decentralized BlockchainApp with the Oracle Blockchain PlatformHow to Build a Decentralized BlockchainApp with the Oracle Blockchain Platform
How to Build a Decentralized Blockchain App with the Oracle Blockchain Platform
 
Blockchain for Marketing & Insights
Blockchain for Marketing & InsightsBlockchain for Marketing & Insights
Blockchain for Marketing & Insights
 
An architectural approach for decentralized applications
An architectural approach for decentralized applicationsAn architectural approach for decentralized applications
An architectural approach for decentralized applications
 
Eco [3 c] introduction of national pki-sg-jaejung kim-15_apr10
Eco [3 c] introduction of national pki-sg-jaejung kim-15_apr10Eco [3 c] introduction of national pki-sg-jaejung kim-15_apr10
Eco [3 c] introduction of national pki-sg-jaejung kim-15_apr10
 
Alexander Shulgin, founder & CEO, Gruppa Kompaniy Familia - What do we mine n...
Alexander Shulgin, founder & CEO, Gruppa Kompaniy Familia - What do we mine n...Alexander Shulgin, founder & CEO, Gruppa Kompaniy Familia - What do we mine n...
Alexander Shulgin, founder & CEO, Gruppa Kompaniy Familia - What do we mine n...
 
Blockchain Technology | Blockchain Explained | Blockchain Tutorial | Blockcha...
Blockchain Technology | Blockchain Explained | Blockchain Tutorial | Blockcha...Blockchain Technology | Blockchain Explained | Blockchain Tutorial | Blockcha...
Blockchain Technology | Blockchain Explained | Blockchain Tutorial | Blockcha...
 
Apidays x api3 9th dec
Apidays x api3   9th decApidays x api3   9th dec
Apidays x api3 9th dec
 
ICON Smart Contract Development
ICON Smart Contract DevelopmentICON Smart Contract Development
ICON Smart Contract Development
 
Jincor - investment attractiveness report (Digital Rating Agency)
Jincor - investment attractiveness report (Digital Rating Agency)Jincor - investment attractiveness report (Digital Rating Agency)
Jincor - investment attractiveness report (Digital Rating Agency)
 

Similar to [PyCon Korea 2018] Python in Chains: Running Python Code for IoT Projects on a custom-built Blockchain Network

Developing Blockchain Applications
Developing Blockchain Applications Developing Blockchain Applications
Developing Blockchain Applications malikmayank
 
Ethereum Devcon1 Report (summary writing)
Ethereum Devcon1 Report (summary writing)Ethereum Devcon1 Report (summary writing)
Ethereum Devcon1 Report (summary writing)Tomoaki Sato
 
Ethereum introduction
Ethereum introductionEthereum introduction
Ethereum introductionkesavan N B
 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microserviceGiulio De Donato
 
Python for IoT, A return of experience
Python for IoT, A return of experiencePython for IoT, A return of experience
Python for IoT, A return of experienceAlexandre Abadie
 
Using Python for IoT: a return of experience, Alexandre Abadie
Using Python for IoT: a return of experience, Alexandre AbadieUsing Python for IoT: a return of experience, Alexandre Abadie
Using Python for IoT: a return of experience, Alexandre AbadiePôle Systematic Paris-Region
 
Ethereum Smart Contracts on Hyperledger Fabric
Ethereum Smart Contracts on Hyperledger Fabric Ethereum Smart Contracts on Hyperledger Fabric
Ethereum Smart Contracts on Hyperledger Fabric Horea Porutiu
 
EOSIO Distributed Application Use Cases
EOSIO Distributed Application Use CasesEOSIO Distributed Application Use Cases
EOSIO Distributed Application Use CasesRobert Konsdorf
 
Build your own Blockchain with the right tool for your application
Build your own Blockchain with the right tool for your applicationBuild your own Blockchain with the right tool for your application
Build your own Blockchain with the right tool for your applicationAnthony Chow
 
Top open source blockchain platforms of 2018
Top open source blockchain platforms of 2018Top open source blockchain platforms of 2018
Top open source blockchain platforms of 2018Parangat Technologies
 
Python Training in Pune - Ethans Tech Pune
Python Training in Pune - Ethans Tech PunePython Training in Pune - Ethans Tech Pune
Python Training in Pune - Ethans Tech PuneEthan's Tech
 
Ethereum Block Chain
Ethereum Block ChainEthereum Block Chain
Ethereum Block ChainSanatPandoh
 
tezos_hands-on-training.pdf
tezos_hands-on-training.pdftezos_hands-on-training.pdf
tezos_hands-on-training.pdfNeven6
 
Encode x Tezos Hack: Hands-on dApp Training
Encode x Tezos Hack: Hands-on dApp Training Encode x Tezos Hack: Hands-on dApp Training
Encode x Tezos Hack: Hands-on dApp Training KlaraOrban
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthingtonoscon2007
 
[Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발
[Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발 [Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발
[Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발 Yunho Maeng
 
Building IoT Products: Developer Experiences
Building IoT Products: Developer ExperiencesBuilding IoT Products: Developer Experiences
Building IoT Products: Developer ExperiencesAllSeen Alliance
 

Similar to [PyCon Korea 2018] Python in Chains: Running Python Code for IoT Projects on a custom-built Blockchain Network (20)

Developing Blockchain Applications
Developing Blockchain Applications Developing Blockchain Applications
Developing Blockchain Applications
 
Ethereum Devcon1 Report (summary writing)
Ethereum Devcon1 Report (summary writing)Ethereum Devcon1 Report (summary writing)
Ethereum Devcon1 Report (summary writing)
 
Ethereum introduction
Ethereum introductionEthereum introduction
Ethereum introduction
 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microservice
 
Python for IoT, A return of experience
Python for IoT, A return of experiencePython for IoT, A return of experience
Python for IoT, A return of experience
 
Using Python for IoT: a return of experience, Alexandre Abadie
Using Python for IoT: a return of experience, Alexandre AbadieUsing Python for IoT: a return of experience, Alexandre Abadie
Using Python for IoT: a return of experience, Alexandre Abadie
 
Ethereum Smart Contracts on Hyperledger Fabric
Ethereum Smart Contracts on Hyperledger Fabric Ethereum Smart Contracts on Hyperledger Fabric
Ethereum Smart Contracts on Hyperledger Fabric
 
EOSIO Distributed Application Use Cases
EOSIO Distributed Application Use CasesEOSIO Distributed Application Use Cases
EOSIO Distributed Application Use Cases
 
Ethereum
EthereumEthereum
Ethereum
 
Build your own Blockchain with the right tool for your application
Build your own Blockchain with the right tool for your applicationBuild your own Blockchain with the right tool for your application
Build your own Blockchain with the right tool for your application
 
Top open source blockchain platforms of 2018
Top open source blockchain platforms of 2018Top open source blockchain platforms of 2018
Top open source blockchain platforms of 2018
 
Python Training in Pune - Ethans Tech Pune
Python Training in Pune - Ethans Tech PunePython Training in Pune - Ethans Tech Pune
Python Training in Pune - Ethans Tech Pune
 
Ethereum Block Chain
Ethereum Block ChainEthereum Block Chain
Ethereum Block Chain
 
tezos_hands-on-training.pdf
tezos_hands-on-training.pdftezos_hands-on-training.pdf
tezos_hands-on-training.pdf
 
Encode x Tezos Hack: Hands-on dApp Training
Encode x Tezos Hack: Hands-on dApp Training Encode x Tezos Hack: Hands-on dApp Training
Encode x Tezos Hack: Hands-on dApp Training
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthington
 
[Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발
[Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발 [Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발
[Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발
 
All About Ethereum
All About EthereumAll About Ethereum
All About Ethereum
 
Building IoT Products: Developer Experiences
Building IoT Products: Developer ExperiencesBuilding IoT Products: Developer Experiences
Building IoT Products: Developer Experiences
 
Etherium Intro for techies
Etherium Intro for techiesEtherium Intro for techies
Etherium Intro for techies
 

Recently uploaded

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Recently uploaded (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

[PyCon Korea 2018] Python in Chains: Running Python Code for IoT Projects on a custom-built Blockchain Network

  • 1. PYTHON IN CHAINS RUNNING PYTHON CODE FOR IOT PROJECTS ON A CUSTOM-BUILT BLOCKCHAIN NETWORK Daniel Hong (홍석현) | @unifiedh
  • 2. “I KNOW THERE HAS BEEN A LOT OF HYPE SURROUNDING BLOCKCHAIN TECH, BUT… PYTHON ON THE BLOCKCHAIN? ISN’T THAT LIKE…”
  • 3. Photo courtesy of: Hyunse Lee “지역주민과 함께 읽는 한국학: 파이썬으로 읽는 디지털 인문학” “Korean Studies with local residents: Learning Digital Humanities using Python”
  • 5. 1. Python is a universal language that can run on almost every computer. SOME BASIC FACTS: 2. Blockchain platforms can also act as a computer, and be programmed like any other computer. 3. Python and some blockchain platforms share a similarly structured runtime architecture.
  • 6. BLOCKCHAIN PLATFORMS AS A COMPUTER Ethereum Virtual Machine (EVM)
  • 7. BLOCKCHAIN PLATFORMS AS A COMPUTER Ethereum Virtual Machine (EVM) Provides a Turing-complete execution environment Provides a high level programming language & easier code deployment support Adjustable code execution fees (Gas) Better blockchain extensibility for application usage
  • 8. CODE EXECUTION ON THE EVM pragma solidity ^0.4.11; contract hello { string world; constructor() public { world = "Hello, World!"; } function sayHello() public view returns (string) { return world; } } Solidity Code (Smart Contract)
  • 9. CODE EXECUTION ON THE EVM pragma solidity ^0.4.11; contract hello { string world; constructor() public { world = "Hello, World!"; } function sayHello() public view returns (string) { return world; } } Solidity Code (Smart Contract) Ethereum Blockchain Compile & Deploy
  • 10. CODE EXECUTION ON THE EVM pragma solidity ^0 .4 .1 1 ; contract hello { string world; constructor() public { world = "Hello, World!"; } function sayHello() public view returns (string) { return world; } } Solidity Code (Smart Contract) Ethereum Blockchain Compile & Deploy Application Code Smart Contract Interaction Library Access Smart Contract via Contract ABI
  • 11. BLOCKCHAIN PLATFORMS AS A COMPUTER Ethereum Virtual Machine (EVM) Poor development environment support Confusing language syntax Inefficient Gas system (The Extensibility Issue) Language compatibility Resource-intensive; not suitable for embedded systems
  • 12. BLOCKCHAIN PLATFORMS AS A COMPUTER Ethereum Virtual Machine (EVM) Poor development environment support Confusing language syntax Inefficient Gas system (The Extensibility Issue) Language compatibility Resource-intensive; not suitable for embedded systems
  • 13. PYTHON TO THE RESCUE
  • 14. PYTHON TO THE RESCUE Integrating Smart Contracts with existing Python code and applications Writing & Compiling Ethereum Smart Contracts with Python Modifying & Running the EVM on embedded devices for IoT system development
  • 15. PYTHON TO THE RESCUE Integrating Smart Contracts with existing Python code and applications Writing & Compiling Ethereum Smart Contracts with Python Modifying & Running the EVM on embedded devices for IoT system development
  • 16. SMART CONTRACT INTEGRATION ‣ web3.py: A Python implementation of the web3.js library (originally written in JavaScript); used to call Smart Contract code within local Python code ‣ Populus: A Python-based Smart Contract development environment for Ethereum blockchain developers using Python ‣ Py-EVM: A Python implementation of the Ethereum Virtual Machine (EVM) itself; will modify this to build a custom implementation of the EVM optimized for embedded systems SOME PREREQUISITES: ‣ Trinity: An Ethereum blockchain client based on the Py-EVM project & completely written in Python
  • 17. SMART CONTRACT INTEGRATION INSTALLING REQUIRED SOFTWARE & LIBRARIES # Install solc & py-solc $ brew update; brew upgrade; brew tap ethereum/ethereum; brew install solidity $ python3 -m solc.install v0.4.11 # Install Populus $ brew install pkg-config libffi autoconf automake libtool openssl $ pip3 install populus # Install Trinity $ pip3 install -U trinity
  • 18. SMART CONTRACT INTEGRATION WRITING A “HELLO WORLD” SMART CONTRACT & INTEGRATING SOLIDITY CODE WITH PYTHON pragma solidity ^0.4.11; contract hello { string world; constructor() public { world = "Hello, World!"; } function sayHello() public view returns (string) { return world; } } Solidity Code (Smart Contract) ./contracts/hello.sol
  • 19. SMART CONTRACT INTEGRATION WRITING A “HELLO WORLD” SMART CONTRACT & INTEGRATING SOLIDITY CODE WITH PYTHON pragma solidity ^0.4.11; contract hello { string world; constructor() public { world = "Hello, World!"; } function sayHello() public view returns (string) { return world; } } Solidity Code (Smart Contract) ./contracts/hello.sol Python Code ./tests/test_HelloWorld.py def test_HelloWorld(chain): hi, _ = chain.provider.get_or_deploy_contract(hello) helloString = hi.call().sayHello() assert helloString == “Hello, World!” #Test Only
  • 20. def test_HelloWorld(chain): hi, _ = chain.provider.get_or_deploy_contract(hello) helloString = hi.call().sayHello() assert helloString == “Hello, World!” #Test Only SMART CONTRACT INTEGRATION WRITING A “HELLO WORLD” SMART CONTRACT & INTEGRATING SOLIDITY CODE WITH PYTHON pragma solidity ^0.4.11; contract hello { string world; constructor() public { world = "Hello, World!"; } function sayHello() public view returns (string) { return world; } } Solidity Code (Smart Contract) ./contracts/hello.sol Python Code ./tests/test_HelloWorld.py 1. chain argument: py.test fixture, provided by populus’ pytest plugin - chain object provided by populus, creates & calls a temp blockchain (“tester”) on memory 2. Creates a web3 contract object instance that corresponds to the hello contract written in Solidity - The hi object created here acts as a wrapper for Solidity code for use within Python 3. Call the sayHello() function defined within the hello contract 4. (Used with pytest) Check whether the hello contract was executed successfully
  • 21. SMART CONTRACT INTEGRATION TESTING SMART CONTRACT INTEGRATION WITH PYTEST # Create a new Populus Project $ mkdir helloTest $ cd helloTest $ populus init $ rm contracts/Greeter $ rm tests/test_greeter.py # Copy Solidity & Python source code $ cp ~/sources/hello.sol contracts/hello.sol $ cp ~/sources/test_HelloWorld.py tests/test_HelloWorld.py # Compile & Deploy on a test blockchain $ populus compile $ populus deploy —chain tester hello # Run pytest $ py.test
  • 22. SMART CONTRACT INTEGRATION TESTING SMART CONTRACT INTEGRATION WITH PYTEST $ populus compile
  • 23. SMART CONTRACT INTEGRATION TESTING SMART CONTRACT INTEGRATION WITH PYTEST $ populus deploy —chain tester hello
  • 24. SMART CONTRACT INTEGRATION TESTING SMART CONTRACT INTEGRATION WITH PYTEST $ py.test
  • 25. PYTHON TO THE RESCUE Integrating Smart Contracts with existing Python code and applications Writing & Compiling Ethereum Smart Contracts with Python Modifying & Running the EVM on embedded devices for IoT system development
  • 26. PRIVATE BLOCKCHAIN SETUP FOR IOT Private Ethereum Blockchain Controller Smart Contract Django Controller Server Web Browser Mobile App Raspberry Pi Raspberry Pi Raspberry Pi Raspberry Pi Coffee Machine Curtains Light Controllers A/C
  • 27.
  • 28. PRIVATE BLOCKCHAIN SETUP FOR IOT Private Ethereum Blockchain Controller Smart Contract Django Controller Server Web Browser Mobile App Raspberry Pi Raspberry Pi Raspberry Pi Raspberry Pi Coffee Machine Curtains Light Controllers A/C ?
  • 29. EVM CODE EXECUTION OVERVIEW THE ETHEREUM BLOCKCHAIN Block N Header: Previous Block Hash Nonce Timestamp Uncle Hash Beneficiary Logs Bloom PoW Difficulty Extra Data Block Number Gas Limit Used Gas Amount Mix Hash State Root Transaction Root Receipt Root Block N+1 Header: Previous Block Hash Nonce Timestamp Uncle Hash Beneficiary Logs Bloom PoW Difficulty Extra Data Block Number Gas Limit Used Gas Amount Mix Hash State Root Transaction Root Receipt Root Receipt Merkle Tree Transaction Merkle Tree Receipt Merkle Tree Transaction Merkle Tree Nonce Code Hash Balance Storage Root Code Nonce Code Hash Balance Storage Root Merkle-Patricia State Trie for block N Merkle-Patricia State Trie for block N+1 73 95 Uncle Block Headers List Uncle Block Headers List
  • 30. THE ETHEREUM BLOCKCHAIN Block N Header: Previous Block Hash Nonce Timestamp Uncle Hash Beneficiary Logs Bloom PoW Difficulty Extra Data Block Number Gas Limit Used Gas Amount Mix Hash State Root Transaction Root Receipt Root Block N+1 Header: Previous Block Hash Nonce Timestamp Uncle Hash Beneficiary Logs Bloom PoW Difficulty Extra Data Block Number Gas Limit Used Gas Amount Mix Hash State Root Transaction Root Receipt Root Receipt Merkle Tree Transaction Merkle Tree Receipt Merkle Tree Transaction Merkle Tree Nonce Code Hash Balance Storage Root Code Nonce Code Hash Balance Storage Root Merkle-Patricia State Trie for block N Merkle-Patricia State Trie for block N+1 73 95 Uncle Block Headers List Uncle Block Headers List EVM CODE EXECUTION OVERVIEW
  • 31. THE ETHEREUM VIRTUAL MACHINE: AN OVERVIEW (MEMORY MANAGEMENT) ‣ Memory: A temporary storage area used when calling functions, or when during regular memory operations ‣ Stack: No concepts of “registers” are provided; a virtual stack is used instead for operations such as opcode parameters ‣ Storage: A permanent key-value storage mapping 256-bit words to 256-bit words; memory space declared outside user-defined functions & within the contract context are stored here Reference: https://github.com/comaeio/porosity/wiki/Ethereum-Internals EVM CODE EXECUTION OVERVIEW
  • 32. THE ETHEREUM VIRTUAL MACHINE: OPCODES & ASSEMBLY ‣ The EVM is (theoretically) language independent; however, due to its architectural limitations the EVM cannot take full advantage of all features present in modern programming languages & requires some unique language syntax (to access unique EVM features) ‣ The EVM implements a simple instruction set to make up EVM bytecode (to ensure platform / ISA independence) ‣ The EVM can also be directly programmed at a low-level using an Assembly Language provided by Solidity; Assembly can be used along with Solidity code with inline Assembly EVM CODE EXECUTION OVERVIEW
  • 33. THE ETHEREUM VIRTUAL MACHINE: OPCODES & ASSEMBLY ‣ The EVM is (theoretically) language independent; however, due to its architectural limitations the EVM cannot take full advantage of all features present in modern programming languages & requires some unique language syntax (to access unique EVM features) ‣ The EVM can also be directly programmed at a low-level using an Assembly Language provided by Solidity; Assembly can be used along with Solidity code with inline Assembly EVM CODE EXECUTION OVERVIEW ‣ The EVM implements a simple instruction set to make up EVM bytecode (to ensure platform / ISA independence)
  • 36. WILL IT BE POSSIBLE TO DEVELOP A SMART CONTRACT USING PYTHON?
  • 37. SOME METHODS TO PORTING PYTHON TO THE EVM 2. ADDING EVM-SPECIFIC SYNTAX TO PYTHON AS A SUPERSET OF THE PYTHON LANGUAGE 3. (OUR APPROACH) ALLOWING PYTHON CODE TO COMPILE DIRECTLY TO EVM BYTECODE WITHOUT LARGELY MODIFYING OR ADDING PYTHON LANGUAGE SYNTAX 1. IMPLEMENTING THE PYTHON INTERPRETER ITSELF AS A SMART CONTRACT IN SOLIDITY
  • 38. SOME METHODS TO PORTING PYTHON TO THE EVM 1. IMPLEMENTING THE PYTHON INTERPRETER ITSELF AS A SMART CONTRACT IN SOLIDITY ‣ However, as the EVM is a distributed execution environment, this method may consume excessive compute power & Gas (which is very inefficient in terms of extensibility) ‣ Jython (the JVM implementation of Python) uses this method to run Python code on the JVM (Reimplementing the Python language with Java, rather than C as used by standard CPython) ‣ Because this method abstracts the language compilation process through a modular implementation, existing pure Python code is almost completely reusable
  • 39. SOME METHODS TO PORTING PYTHON TO THE EVM ‣ The problem: adding new syntax to Python means backwards compatibility cannot be ensured with existing Python code (Can Python with added custom syntax be still considered as Python?) ‣ Similar to how Objective-C added object-oriented programming capabilities with added syntax while also maintaining full backwards compatibility with C ‣ The Ethereum Foundation chose a similar approach with a new language called Vyper, which also targets the EVM (like Solidity) but with Pythonic syntax 2. ADDING EVM-SPECIFIC SYNTAX TO PYTHON AS A SUPERSET OF THE PYTHON LANGUAGE
  • 40. OUR SOLUTION: A FULL PYTHON PORT BUILDING A PYTHON COMPILER THAT TARGETS THE EVM pragma solidity ^0.4.11; contract Wallet { mapping (address => uint) public balance; function deposit() { balance[msg.sender] += 1; } function withdraw(uint value) { if(balance[msg.sender] < value) throw; balance[msg.sender] -= 1; if(!msg.sender.call.value(value)()) throw; } } Solidity Code (Smart Contract)
  • 41. OUR SOLUTION: A FULL PYTHON PORT BUILDING A PYTHON COMPILER THAT TARGETS THE EVM pragma solidity ^0.4.11; contract Wallet { mapping (address => uint) public balance; function deposit() { balance[msg.sender] += 1; } function withdraw(uint value) { if(balance[msg.sender] < value) throw; balance[msg.sender] -= 1; if(!msg.sender.call.value(value)()) throw; } } Solidity Code (Smart Contract) Python Code (Smart Contract) import ethereum as eth class Wallet(eth.contract): balance = eth.mapping(eth.address, int) def deposit(): balance[eth.msg.sender] += 1 def withdraw(value: int): if balance[eth.msg.sender] < value: raise ValueError balance[eth.msg.sender] -= 1 if not eth.msg.sender.call.value(value)(): raise ValueError
  • 42. OUR SOLUTION: A FULL PYTHON PORT BUILDING A PYTHON COMPILER THAT TARGETS THE EVM Python Source Code Bytecode Translation Python Bytecode (.pyc) Python Virtual Machine Library Modules Code Execution A standard CPython implementation of Python
  • 43. OUR SOLUTION: A FULL PYTHON PORT BUILDING A PYTHON COMPILER THAT TARGETS THE EVM Python Source Code Grammar Python Bytecode (.pyc) Python Virtual Machine Library Modules Code Execution A standard CPython implementation of Python Lexer Parser Compiler
  • 44. OUR SOLUTION: A FULL PYTHON PORT BUILDING A PYTHON COMPILER THAT TARGETS THE EVM Python Source Code On-the-fly EVM Bytecode Translation EVM Bytecode Modified EVM Code Execution Precompiled EVM bytecode (Imported as Python Library) Deploy Our Python-EVM Implementation Structure
  • 45. OUR SOLUTION: A FULL PYTHON PORT BUILDING A PYTHON COMPILER THAT TARGETS THE EVM Python Source Code EVM Bytecode Code Execution Our Python-EVM Implementation Structure Precompiled EVM bytecode (Imported as Python Library) Deploy Grammar (CPython) Modified Lexer (Added EVM-specific tokens) Modified Parser (Generates Solidity-style structure) Compiler with solc backend Modified EVM
  • 46. OUR SOLUTION: A FULL PYTHON PORT BUILDING A PYTHON COMPILER THAT TARGETS THE EVM pragma solidity ^0.4.11; contract Wallet { mapping (address => uint) public balance; function deposit() { balance[msg.sender] += 1; } function withdraw(uint value) { if(balance[msg.sender] < value) throw; balance[msg.sender] -= 1; if(!msg.sender.call.value(value)()) throw; } } Solidity Code (Smart Contract) Python Code (Smart Contract) import ethereum as eth class Wallet (eth.contract): balance = eth.mapping(eth.address, int) def deposit(): balance[eth.msg.sender] += 1 def withdraw(value: int): if balance[eth.msg.sender] < value: raise ValueError balance[eth.msg.sender] -= 1 if not eth.msg.sender.call.value(value)(): raise ValueError 1. ethereum module: A Python wrapper that allows EVM-specific features to be called within Python code 2. Wallet class: inherits the contract class defined within the ethereum module to define a Contract 3. eth.mapping: returns an access token to the Mapping type value ; eth.address: same as the address type defined with Solidity (20 byte value) 4. Modified syntax to access Mapping type variable
  • 47. OUR SOLUTION: A FULL PYTHON PORT DYNAMIC PYTHON-STYLE ETHEREUM VIRTUAL MACHINE Python Source Code EVM Bytecode Code Execution Our Python-EVM Implementation Structure Precompiled EVM bytecode (Imported as Python Library) Grammar (CPython) Modified Lexer (Added EVM-specific tokens) Modified Parser (Generates Solidity-style structure) Compiler with solc backend Modified EVM Deploy
  • 48. ‣ …but I cannot disclose all of them in detail just yet ‣ Execution Logic Improvements: No simultaneous code execution on devices marked as “embedded”; only codehash checks (integrity insurance) are performed on-device ‣ AOT Compiler: Allows ahead-of-time EVM bytecode compilation with embedded devices OUR SOLUTION: A FULL PYTHON PORT DYNAMIC PYTHON-STYLE ETHEREUM VIRTUAL MACHINE
  • 51. BLOCKCHAIN PLATFORMS AS A COMPUTER Ethereum Virtual Machine (EVM) Poor development environment support Confusing language syntax Inefficient Gas system (The Extensibility Issue) Language compatibility Resource-intensive; not suitable for embedded systems
  • 52. GEMER: AN OPEN SOURCE, DISTRIBUTED RUNTIME
  • 53. THANK YOU Further inquiries: me@unifiedh.com Personal GitHub: github.com/unifiedh