2018年7月18日(水)、ブロックチェーンハブ主催で開催されたブロックチェーンアカデミー「イーサリアム実習 I」(【ハンズオン】スマートコントラクトプログラミング (2)) にて使用したスライドです。
I(2)CSO / SFC( https://speakerdeck.com/ks91 )[email protected]I — (2) — 2018-07-18 – p.1/38
View Slide
1.2.3.4.5.I — (2) — 2018-07-18 – p.2/38
1. : ERC202. ∼ ∼I — (2) — 2018-07-18 – p.3/38
1. : ERC20ERC20I — (2) — 2018-07-18 – p.4/38
(2018 7 18 )BcH-smart-contract-programming.zipSoliditypy.test solidity 0.4.22 + populusongoingsolidity 0.4.21contracts testsI — (2) — 2018-07-18 – p.5/38
SolidityJavaScript( , )(constructor)( )( )EtherI — (2) — 2018-07-18 – p.6/38
pragma solidity ˆ0.4.24;contract MyToken {( ):(EVM ):constructor (...) public { /* */:}function MyToken(...) { /* ( ) */:}:}constructorC (/* */ // )I — (2) — 2018-07-18 – p.7/38
ERC20ERC (Ethereum Request for Comment) 20https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.mdcontract ERC20 {function totalSupply() constant returns (uint totalSupply);function balanceOf(address _owner) constant returns (uint balance);function transfer(address _to, uint _value) returns (bool success);function transferFrom(address _from, address _to, uint _value) returns (bool success);function approve(address _spender, uint _value) returns (bool success);function allowance(address _owner, address _spender) constant returns (uint remaining);event Transfer(address indexed _from, address indexed _to, uint _value);event Approval(address indexed _owner, address indexed _spender, uint _value);}name/ , symbol/ , decimals/approve allowanceERC223 ( ), ERC721 (Non-Fungible)I — (2) — 2018-07-18 – p.8/38
MyTokenstring public _name;string public _symbol;uint8 public _decimals;mapping (address => uint256) public _balanceOf;uint256 _totalSupply;_name, _symbol_decimals: 2 100 1.00mapping _balanceOfI — (2) — 2018-07-18 – p.9/38
MyTokenevent Transfer(address indexed from, address indexed to, uint256 value);indexed (3 )MyToken function Transfer()I — (2) — 2018-07-18 – p.10/38
MyTokenconstructor (uint256 supply, string name, string symbol, uint8 decimals) public {if (supply == 0) {supply = 1000000; /* supply 1,000,000 */}_totalSupply = supply;_balanceOf[msg.sender] = supply;_name = name;_symbol = symbol;_decimals = decimals;}msg.sendersupplyI — (2) — 2018-07-18 – p.11/38
MyToken balanceOf()function balanceOf(address tokenOwner) external view returns (uint256) {return _balanceOf[tokenOwner];}I — (2) — 2018-07-18 – p.12/38
MyToken transfer()function transfer(address to, uint256 value) external returns (bool) {require(value <= _balanceOf[msg.sender]); /* */require(_balanceOf[to] + value >= _balanceOf[to]); /* */_balanceOf[msg.sender] -= value;_balanceOf[to] += value;Transfer(msg.sender, to, value);return true;}require (function )OpenZeppelinhttps://openzeppelin.orgI — (2) — 2018-07-18 – p.13/38
(1)import pytest@pytest.fixture()def token_contract(chain):TokenFactory = chain.provider.get_contract_factory(’MyToken’)deploy_txid = TokenFactory.deploy(args=[0,"BcH Coin","BcH",0,])contract_address = chain.wait.for_contract_address(deploy_txid)return TokenFactory(address=contract_address)populusI — (2) — 2018-07-18 – p.14/38
(2)def test_my_token(token_contract, chain):account0 = chain.web3.eth.accounts[0]account1 = chain.web3.eth.accounts[1]assert token_contract.call().balanceOf(account0) == 1000000assert token_contract.call().balanceOf(account1) == 0txid = token_contract.transact().transfer(account1, 10)chain.wait.for_receipt(txid)assert token_contract.call().balanceOf(account0) == 999990assert token_contract.call().balanceOf(account1) == 10account0 coinbaseaccount1account0 account1 10BcHI — (2) — 2018-07-18 – p.15/38
$ py.test -k test_my_token.pyI — (2) — 2018-07-18 – p.16/38
2.∼ ∼I — (2) — 2018-07-18 – p.17/38
A, BA-B mA B AB A B. . .I — (2) — 2018-07-18 – p.18/38
1. X2. X C3. C1.2.3.reliable multicastI — (2) — 2018-07-18 – p.19/38
:I — (2) — 2018-07-18 – p.20/38
(safety)(liveness)( )( = )I — (2) — 2018-07-18 – p.21/38
→ / (benign)→ (Byzantine)(malicious)I — (2) — 2018-07-18 – p.22/38
FLPFischer, Lynch, PatersonI — (2) — 2018-07-18 – p.23/38
CAPConsistency ( )Availability ( )Partition tolerance ( )⇒ 3CEventual consistency ( ). . .I — (2) — 2018-07-18 – p.24/38
Consistency ( )Strong consistency ( )(safety)Eventual consistency ( )(liveness)↑Weak consistency ( )↑ ( )I — (2) — 2018-07-18 – p.25/38
n=f( )⇒I — (2) — 2018-07-18 – p.26/38
(1)1 1, 2n ≤ 3fI — (2) — 2018-07-18 – p.27/38
(2)I — (2) — 2018-07-18 – p.28/38
CS1 :CS2 :CS3 :CL1 :CL2 :::(e.g. )I — (2) — 2018-07-18 – p.29/38
(B)FT-CUP (Consensus with Unknown Participants)( / ): FT (Fault-Tolerant): BFT (Byzantine Fault-Tolerant)P2Pn FT/BFTI — (2) — 2018-07-18 – p.30/38
State Machine Replication ( )(by ) (since 1984) ( )( ). . .( )I — (2) — 2018-07-18 – p.31/38
( )( ) ( ) ( )(by )⇒ ( )I — (2) — 2018-07-18 – p.32/38
P2P: P2P33( )strategyproofgroup strategyproofI — (2) — 2018-07-18 – p.33/38
(Sybil)16I — (2) — 2018-07-18 – p.34/38
againn > 3fR FR > 2F⇒I — (2) — 2018-07-18 – p.35/38
( )f = 1 ⇒ RI — (2) — 2018-07-18 – p.36/38
(centralized) (decentralized) (distributed)Paul Baran, “On Distributed Communications Networks”, 1964(C) (A)I — (2) — 2018-07-18 – p.37/38
II::/I — (2) — 2018-07-18 – p.38/38