$30 off During Our Annual Pro Sale. View Details »

スマートコントラクトプログラミング(3) イーサリアム実習 I / Ethereum Exercise I, Smart Contract Programming 3

スマートコントラクトプログラミング(3) イーサリアム実習 I / Ethereum Exercise I, Smart Contract Programming 3

ブロックチェーンハブ主催で開催しているブロックチェーン連続講義シリーズ「スマートコントラクトプログラミング」の第3回「イーサリアム実習 I」のスライドです。2016年10月21日(金) に使用しました。

Kenji Saito
PRO

October 21, 2016
Tweet

More Decks by Kenji Saito

Other Decks in Technology

Transcript

  1. I (3) SFC / CSO ks91@sfc.wide.ad.jp I — (3) –

    2016-10-21 – p.1/39
  2. 1. 2. 3. 4. 5. I — (3) – 2016-10-21

    – p.2/39
  3. 1. : 2. ∼ ∼ I — (3) – 2016-10-21

    – p.3/39
  4. 1. : I — (3) – 2016-10-21 – p.4/39

  5. ( ) $ geth --networkid 12345678 --port 50303 --maxpeers 0

    --nodiscover console 2>> node.log > > exit $ tail -f node.log (Mac OS X, Linux) > Get-Content node.log -Wait -Tail 10 (Windows PowerShell) I — (3) – 2016-10-21 – p.5/39
  6. ( ) geth > miner.start(2) true ‘2’ ( CPU )

    > miner.stop() I — (3) – 2016-10-21 – p.6/39
  7. Ethereum-Wallet “LAUNCH APPLICATION” I — (3) – 2016-10-21 – p.7/39

  8. (1) BcH Coin delete I — (3) – 2016-10-21 –

    p.8/39
  9. (2) CUSTOM TOKENS OK I — (3) – 2016-10-21 –

    p.9/39
  10. Solidity JavaScript ( , ) (constructor) ( ) ( )

    Ether I — (3) – 2016-10-21 – p.10/39
  11. pragma solidity ˆ0.4.2; contract MyToken { ( ) : (EVM

    ) : function MyToken(...) { /* */ : } : } function C (/* */ // ) I — (3) – 2016-10-21 – p.11/39
  12. MyToken string public name; string public symbol; uint8 public decimals;

    mapping (address => uint256) public balanceOf; name, symbol decimals : 2 100 1.00 mapping balanceOf I — (3) – 2016-10-21 – p.12/39
  13. MyToken event Transfer(address indexed from, address indexed to, uint256 value);

    indexed (3 ) MyToken function Transfer() Ethereum-Wallet I — (3) – 2016-10-21 – p.13/39
  14. MyToken function MyToken(uint256 _supply, string _name, string _symbol, uint8 _decimals)

    { if (_supply == 0) { _supply = 1000000; /* _supply 1,000,000 */ } balanceOf[msg.sender] = _supply; name = _name; symbol = _symbol; decimals = _decimals; } msg.sender _supply C++ _ I — (3) – 2016-10-21 – p.14/39
  15. MyToken transfer() function transfer(address _to, uint256 _value) { if (balanceOf[msg.sender]

    < _value) { /* */ throw; } if (balanceOf[_to] + _value < balanceOf[_to]) { /* */ throw; } balanceOf[msg.sender] -= _value; balanceOf[_to] += _value; Transfer(msg.sender, _to, _value); } throw (function ) catch I — (3) – 2016-10-21 – p.15/39
  16. _decimals 2 I — (3) – 2016-10-21 – p.16/39

  17. (1) 1.08 BcH Account 2 I — (3) – 2016-10-21

    – p.17/39
  18. (2) Account 2 1.08 BcH I — (3) – 2016-10-21

    – p.18/39
  19. (3) 1.08 BcH I — (3) – 2016-10-21 – p.19/39

  20. Ether (1) Account 2 BcH Ether 1 Ether Account 2

    BcH I — (3) – 2016-10-21 – p.20/39
  21. 2. ∼ ∼ I — (3) – 2016-10-21 – p.21/39

  22. A, B A-B m A B A B A B

    . . . I — (3) – 2016-10-21 – p.22/39
  23. 1. X 2. X C 3. C 1. 2. 3.

    reliable multicast I — (3) – 2016-10-21 – p.23/39
  24. : I — (3) – 2016-10-21 – p.24/39

  25. (safety) (liveness) ( ) ( = ) I — (3)

    – 2016-10-21 – p.25/39
  26. → / (benign) → (Byzantine) (malicious) I — (3) –

    2016-10-21 – p.26/39
  27. FLP Fischer, Lynch, Paterson I — (3) – 2016-10-21 –

    p.27/39
  28. CAP Consistency ( ) Availability ( ) Partition tolerance (

    ) ⇒ 3 C Eventual consistency ( ) . . . I — (3) – 2016-10-21 – p.28/39
  29. Consistency ( ) Strong consistency ( ) (safety) Eventual consistency

    ( ) (liveness) ↑ Weak consistency ( ) ← ( ) I — (3) – 2016-10-21 – p.29/39
  30. n = f ( ) I — (3) – 2016-10-21

    – p.30/39
  31. 1 1, 2 n ≤ 3f I — (3) –

    2016-10-21 – p.31/39
  32. CS1 : CS2 : CS3 : CL1 : CL2 :

    : : (e.g. ) I — (3) – 2016-10-21 – p.32/39
  33. (B)FT-CUP (Consensus with Unknown Participants) ( / ) : FT

    (Fault-Tolerant) : BFT (Byzantine Fault-Tolerant) P2P n FT/BFT I — (3) – 2016-10-21 – p.33/39
  34. P2P : P2P 3 3 I — (3) – 2016-10-21

    – p.34/39
  35. (Sybil) 16 I — (3) – 2016-10-21 – p.35/39

  36. again n > 3f R F R > 2F ⇒

    I — (3) – 2016-10-21 – p.36/39
  37. ( ) f = 1 ⇒ R I — (3)

    – 2016-10-21 – p.37/39
  38. ( ) 3 1. ( ) ⇒ 2. ( )

    ⇒ 3. ( ) TX ⇒ I — (3) – 2016-10-21 – p.38/39
  39. II I — (3) – 2016-10-21 – p.39/39