SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
© Copyright IBM Corporation 2018
IBM東京基礎研究所の取り組み
スマートコントラクト開発について
IBM東京基礎研究所
立石 孝彰
© Copyright IBM Corporation 2018
スマートコントラクト
• ブロックチェーンプラットフォーム上で動くプログラム
• Hyperledger Fabric*1ではchaincodeと呼ぶ
• 契約の自動執行や監視のためのプロトコル
• 契約者間の手順や義務の定義
2
契約書
// mycc.go
func Invoke(…) {
…
}
プロトコル スマートコントラクト
顧客: 商品を発注する
店舗: 在庫確認後に承認する
店舗: 商品を発送する
配送: 商品を受領する
配送: 商品を配達する
顧客: 商品を受領する
1) Hyperledger FabricはLinux Foundationのプロジェクトです。
© Copyright IBM Corporation 2018
例: 購買契約とプロトコル
3
店舗:
発注を受けたら承諾・拒否の応答を返す。
承諾した場合、発送処理を行う。
発送するまでは注文変更を受け付ける。
配送業者:
商品を受領したら配送しなければならない。
顧客:
数量0の発注は行えない。
商品の配送を受けたら支払いを行う。
契約内容(の要約)
プロトコルと条件
シナリオ1:
顧客: 注文する。(数量 > 0)
店舗: 承諾する。
顧客: 再注文する。
店舗: 承諾する。
店舗: 発送する。
配送: 受領する。
配送: 配達する。
顧客: 支払いを行う。(注文金額 == 支払額)
シナリオ2:
顧客: 注文する。
店舗: 拒否する。
0回以上の
繰り返し
© Copyright IBM Corporation 2018
スマートコントラクトの開発
4
// mycc.go
func Invoke(…) {
…
}
契約書 スマートコントラクト
顧客: 商品を発注する
店舗: 在庫確認後に承認する
店舗: 商品を発送する
配送: 商品を受領する
配送: 商品を配達する
顧客: 支払いを行う
プロトコル
1. 契約者間におけるメッセージ
と扱うデータの識別
2. 正しいメッセージ順序の定義
プロトコルに従いコーディング
法律家
エンジニア Blockchain技術者
© Copyright IBM Corporation 2018
デモ
5
Webアプリ
func Invoke(…)
{
}
Chaincode
SCXML engine
KVS
read/
write
event
Brower Node.js server Peer
REST proxy
顧客、店舗、配送
業者の活動を記録
顧客、店舗、配送
業者が操作
© Copyright IBM Corporation 2018
6
© Copyright IBM Corporation 2018
デモ: 発注一覧画面
7
© Copyright IBM Corporation 2018
デモ: 発注
8
© Copyright IBM Corporation 2018
デモ: 状態遷移図
9
© Copyright IBM Corporation 2018
スマートコントラクトの再利用
10
// mycc.go
func Invoke(…) {
…
}
契約書(海外用) スマートコントラクト
顧客: 商品を発注する
店舗: 在庫確認後に承認する
店舗: 商品を発送する
配送: 商品を受領する
配送: 税関通過する
配送: 商品を納品する
顧客: 支払いを行う
プロトコル
国内配送条件
+ 海外配送条件
// mycc.go
func Invoke(…) {
…
(配送処理に対応
するコード)
}
契約書(国内用) スマートコントラクト
顧客: 商品を発注する
店舗: 在庫確認後に承認する
店舗: 商品を発送する
配送: 商品を受領する
配送: 商品を納品する
顧客: 支払いを行う
プロトコル
国内配送条件
再利用
どこを修正する?
修正して影響ない?
バグ修正した。
不足条件追加した。
© Copyright IBM Corporation 2018
スマートコントラクトテンプレートによる自動化
• 可変項目(値や条件)をパラメータとした契約書とスマートコントラクト
• 契約条件の大枠は同じ
• 細かい部分が異なる
• 契約書テンプレートを埋めて実行可能なスマートコントラクトを生成
• 可変条件が自動的にプログラム化できれば全自動化は容易
11
// mycc.go
func Invoke(…) {
…
[ 配送処理に対応
するコード ]
}
契約書テンプレート スマートコントラクト
のテンプレート
顧客: 商品を発注する
店舗: 在庫確認後に承認する
店舗: 商品を発送する
[ 配送用プロトコル ]
顧客: 支払いを行う
プロトコルのテンプレート
[ 配送条件 ]
© Copyright IBM Corporation 2018
Smart Contract Development Tools (SCDT)
• テンプレートに基づく契約書からスマートコントラクトを自動生成
• プロトコル定義(動作仕様)にStatechartとDSL4SCを利用
• 形式仕様(DSL4SC)を用いることによって正しい動作を保証
• 3つの変換器から構成され、それぞれ独立に利用可能
• 汎用の監視・制御用クライアント
• アセット毎の状態確認と制御
12
契約書 Statechart
(SCXML*1)
DSL4SC Rules
protocol
(day_close;
day_open)*
property …
on day_open do {
…
}
Chaincode
(Go)
// mycc.go
func Invoke(…) {
…
}
SCXML
Live Viewer
state
event
SCT rule2scxml scxmlcc
プロトコル定義 *1) SCXML = State Chart XML (W3C標準)
© Copyright IBM Corporation 2018
SCT (Smart Contract Template)
• ANTLR4とEJS(JSテンプレート)の組み合わせ
• ANTLR4によって契約書中の文章を構文解析
• EJSによって構文解析結果を用いてDSL4SCルールを生成
13
<%
var paymentCondition =
translate(xpath.select(
'//value_PCond', document)[0]);
%>
on pay when {
<%- paymentCondition %>
} do { ... };
商品の配送を受けたら支払いを行う。
( [支払い金額は商品代金と同じとする。])
<contract>
<placeholder name=“PCond”>
<value_PCond>
<proposition>
<object>支払い代金</object>
<predicate>同じ</predicate>
<object>商品代金</object>
</proposition>
</value_PCond></placeholder>…
on pay when {
_data.amount == _event.data.amount
} do { ... };
契約書テンプレート
DSL4SCテンプレート(EJS)
構文解析
document
にバインド
DSL4SCルール
生成
© Copyright IBM Corporation 2018
DSL4SC
• 正規表現: プロトコル(イベント列のパターン)の記述
• 選択 “+”, 連接 “;” , 繰り返し “*” によりパターンを記述
• LDL式*1: 状態列に対する制約を記述
• canOrder: 注文可能状態
• ordered: 注文済状態
14
店舗:
発注を受けたら承諾・拒否の応答を返す。
承諾した場合、発送処理を行う。
発送するまでは注文変更を受け付ける。
注文後は再注文できない。
…
protocol (order; accept; ...) + ;;
property
canOrder // 初期状態
& [{true}*;{ordered}] !canOrder
& ...
;;
rule
on order
when canOrder { ... }// 事前状態 & 条件
do ordered { ... } // 事後状態 & アクション
...
*1) LDL = Linear Dynamic Logic
状態とイベント
イベントパターンの定義
状態列の性質
© Copyright IBM Corporation 2018
例: DSL4SCによるプロトコル定義
15
protocol
order; accept; (order; accept)*;
ship; receive; deliver; pay
+
order; reject;;
rule
on order when {
_event.data.quantity > 0
} do {
_data.item = _event.data.item;
_data.quantity = _event.data.quantity;
_data.amount = _event.data.amount;
_data.orderDate = _event.data.date;
};
…
on pay when {
_data.amount == _event.data.amount
} do { ... };
DSL4SC rule
プロトコルと条件
シナリオ1:
顧客: 注文する。(数量 > 0)
店舗: 承諾する。
顧客: 再注文する。
店舗: 承諾する。
店舗: 発送する。
配送: 受領する。
配送: 配達する。
顧客: 支払いを行う。(注文金額 == 支払額)
シナリオ2:
顧客: 注文する。
店舗: 拒否する。
0回以上の
繰り返し
© Copyright IBM Corporation 2018
DSL4SC (LDLについて)
• 契約(義務)に対応するように性質を記述
• 手続きではなく「常に」「いつかは」という時間に関する性質を記述可能
• 「どんな場合でもいつかはAの状態になる」 [{true}*] <{true}*> A
• 「Aの後にBの状態になる」  < {true}*; A > B
• 「Aの後は常にBの状態になる」  [ {true}*; A ] B
16
店舗:
発注を受けたら承諾・拒否の応答を返す。
承諾した場合、発送処理を行う。
発送するまでは注文変更を受け付けても良い。
注文後は再注文できない。
…
protocol ...;;
property
canOrder // 初期状態
& [{true}*;{ordered}] !canOrder
& ...
;;
rule
on order
when canOrder // 事前状態
do ordered { ... } // 事後状態
...
*1) LDL = Linear Dynamic Logic
© Copyright IBM Corporation 2018
DSL4SCからStatechartへの変換例
17
protocol
order; accept; (order; accept)*;
ship; receive; deliver; pay
+
order; reject;;
rule
on order when {
_event.data.quantity > 0
} do {
_data.item = _event.data.item;
_data.quantity = _event.data.quantity;
_data.amount = _event.data.amount;
_data.orderDate = _event.data.date;
};
…
on pay when {
_data.amount == _event.data.amount
} do { ... };
DSL4SC rule
Statechart
© Copyright IBM Corporation 2018
Scxmlcc & CCFlow
• CCFlow: 状態遷移機械を実装したGoパッケージ
• 条件/アクションの実行のためにOttoパッケージ(JSインタプリタ)を利用
• 条件/アクションとしてGoの関数も利用可能
• Chaincode中で利用されることを想定 (単独でも利用可能)
• scxmlcc: CCFlowを利用するchaincodeの生成器
• 生成したファイルはそのままchaincodeとしてデプロイ可能
• SCXMLのサブセットをサポート
18
SCXML
<scxml>
…
</scxml>
scxmlcc
CCFlow
Statechart
definition
Chaincode
Otto
© Copyright IBM Corporation 2018
Scxmlccで生成されたchaincodeの動作
19
Client Main I/F Ledger Main I/F SCXML
Invoke(…)
“order”
transaction
“order” event
Update the state
& Store the state
into KVS
Record the
transaction
Peer Chaincode
• イベントによる状態遷移
• 現在状態(と属性値)の取得
• Statechartインスタンスの
操作(作成,削除など)
© Copyright IBM Corporation 2018
Statechart (SCXML)
• Statechartはシステムの動作を定義するモデル
• 階層化、平行状態を用いて複雑な動作を簡潔に記述
• SCXMLはStatechartのXML表現のW3C標準
• オープンソースのSCXMLエディタ/ツールを利用可能
• 例: https://github.com/fmorbini/scxmlgui
20
Derivative Bond issuing
© Copyright IBM Corporation 2018
Statechartのテスト
• CCFlowを用いてローカル環境(コマンドライン)で実行
• デプロイする前にStatechartとしてのバグを発見
21
…
["day_close”, {"price": 90}]
["day_open"]
…
…
true
{"State":“4","Subflows":{}}
{"bought_shares":2,"cur_date":0,
"spot_price":90}
true
{"State":“2","Subflows":{}}
{"bought_shares":2,"cur_date":1,
"spot_price":90}
…
$ scxmlrun
-t trace.txt
-f events.txt
purchase.scxml
events.txt
trace.txt
purchase.scxml
© Copyright IBM Corporation 2018
参考情報
• ldltools: https://github.com/ldltools
• ldlsatとdsl4sc(rules2scxml)を提供
• Blockchainとは独立したLDLおよびSCXMLのためのツール
• DSL4SCにおける形式検証ツールも提供
• scdtools: https://github.com/scdtools
• ccflow(scxmlcc, scxmlrun)とデモのためのDocker環境を提供予定
22

Weitere ähnliche Inhalte

Kürzlich hochgeladen

クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfクラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfFumieNakayama
 
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?akihisamiyanaga1
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NTT DATA Technology & Innovation
 
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...博三 太田
 
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineerYuki Kikuchi
 
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)UEHARA, Tetsutaro
 
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfAWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfFumieNakayama
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)Hiroshi Tomioka
 

Kürzlich hochgeladen (8)

クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfクラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
 
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
 
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
 
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
 
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
 
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfAWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
 

Empfohlen

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming LanguageSimplilearn
 

Empfohlen (20)

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

Scdt

  • 1. © Copyright IBM Corporation 2018 IBM東京基礎研究所の取り組み スマートコントラクト開発について IBM東京基礎研究所 立石 孝彰
  • 2. © Copyright IBM Corporation 2018 スマートコントラクト • ブロックチェーンプラットフォーム上で動くプログラム • Hyperledger Fabric*1ではchaincodeと呼ぶ • 契約の自動執行や監視のためのプロトコル • 契約者間の手順や義務の定義 2 契約書 // mycc.go func Invoke(…) { … } プロトコル スマートコントラクト 顧客: 商品を発注する 店舗: 在庫確認後に承認する 店舗: 商品を発送する 配送: 商品を受領する 配送: 商品を配達する 顧客: 商品を受領する 1) Hyperledger FabricはLinux Foundationのプロジェクトです。
  • 3. © Copyright IBM Corporation 2018 例: 購買契約とプロトコル 3 店舗: 発注を受けたら承諾・拒否の応答を返す。 承諾した場合、発送処理を行う。 発送するまでは注文変更を受け付ける。 配送業者: 商品を受領したら配送しなければならない。 顧客: 数量0の発注は行えない。 商品の配送を受けたら支払いを行う。 契約内容(の要約) プロトコルと条件 シナリオ1: 顧客: 注文する。(数量 > 0) 店舗: 承諾する。 顧客: 再注文する。 店舗: 承諾する。 店舗: 発送する。 配送: 受領する。 配送: 配達する。 顧客: 支払いを行う。(注文金額 == 支払額) シナリオ2: 顧客: 注文する。 店舗: 拒否する。 0回以上の 繰り返し
  • 4. © Copyright IBM Corporation 2018 スマートコントラクトの開発 4 // mycc.go func Invoke(…) { … } 契約書 スマートコントラクト 顧客: 商品を発注する 店舗: 在庫確認後に承認する 店舗: 商品を発送する 配送: 商品を受領する 配送: 商品を配達する 顧客: 支払いを行う プロトコル 1. 契約者間におけるメッセージ と扱うデータの識別 2. 正しいメッセージ順序の定義 プロトコルに従いコーディング 法律家 エンジニア Blockchain技術者
  • 5. © Copyright IBM Corporation 2018 デモ 5 Webアプリ func Invoke(…) { } Chaincode SCXML engine KVS read/ write event Brower Node.js server Peer REST proxy 顧客、店舗、配送 業者の活動を記録 顧客、店舗、配送 業者が操作
  • 6. © Copyright IBM Corporation 2018 6
  • 7. © Copyright IBM Corporation 2018 デモ: 発注一覧画面 7
  • 8. © Copyright IBM Corporation 2018 デモ: 発注 8
  • 9. © Copyright IBM Corporation 2018 デモ: 状態遷移図 9
  • 10. © Copyright IBM Corporation 2018 スマートコントラクトの再利用 10 // mycc.go func Invoke(…) { … } 契約書(海外用) スマートコントラクト 顧客: 商品を発注する 店舗: 在庫確認後に承認する 店舗: 商品を発送する 配送: 商品を受領する 配送: 税関通過する 配送: 商品を納品する 顧客: 支払いを行う プロトコル 国内配送条件 + 海外配送条件 // mycc.go func Invoke(…) { … (配送処理に対応 するコード) } 契約書(国内用) スマートコントラクト 顧客: 商品を発注する 店舗: 在庫確認後に承認する 店舗: 商品を発送する 配送: 商品を受領する 配送: 商品を納品する 顧客: 支払いを行う プロトコル 国内配送条件 再利用 どこを修正する? 修正して影響ない? バグ修正した。 不足条件追加した。
  • 11. © Copyright IBM Corporation 2018 スマートコントラクトテンプレートによる自動化 • 可変項目(値や条件)をパラメータとした契約書とスマートコントラクト • 契約条件の大枠は同じ • 細かい部分が異なる • 契約書テンプレートを埋めて実行可能なスマートコントラクトを生成 • 可変条件が自動的にプログラム化できれば全自動化は容易 11 // mycc.go func Invoke(…) { … [ 配送処理に対応 するコード ] } 契約書テンプレート スマートコントラクト のテンプレート 顧客: 商品を発注する 店舗: 在庫確認後に承認する 店舗: 商品を発送する [ 配送用プロトコル ] 顧客: 支払いを行う プロトコルのテンプレート [ 配送条件 ]
  • 12. © Copyright IBM Corporation 2018 Smart Contract Development Tools (SCDT) • テンプレートに基づく契約書からスマートコントラクトを自動生成 • プロトコル定義(動作仕様)にStatechartとDSL4SCを利用 • 形式仕様(DSL4SC)を用いることによって正しい動作を保証 • 3つの変換器から構成され、それぞれ独立に利用可能 • 汎用の監視・制御用クライアント • アセット毎の状態確認と制御 12 契約書 Statechart (SCXML*1) DSL4SC Rules protocol (day_close; day_open)* property … on day_open do { … } Chaincode (Go) // mycc.go func Invoke(…) { … } SCXML Live Viewer state event SCT rule2scxml scxmlcc プロトコル定義 *1) SCXML = State Chart XML (W3C標準)
  • 13. © Copyright IBM Corporation 2018 SCT (Smart Contract Template) • ANTLR4とEJS(JSテンプレート)の組み合わせ • ANTLR4によって契約書中の文章を構文解析 • EJSによって構文解析結果を用いてDSL4SCルールを生成 13 <% var paymentCondition = translate(xpath.select( '//value_PCond', document)[0]); %> on pay when { <%- paymentCondition %> } do { ... }; 商品の配送を受けたら支払いを行う。 ( [支払い金額は商品代金と同じとする。]) <contract> <placeholder name=“PCond”> <value_PCond> <proposition> <object>支払い代金</object> <predicate>同じ</predicate> <object>商品代金</object> </proposition> </value_PCond></placeholder>… on pay when { _data.amount == _event.data.amount } do { ... }; 契約書テンプレート DSL4SCテンプレート(EJS) 構文解析 document にバインド DSL4SCルール 生成
  • 14. © Copyright IBM Corporation 2018 DSL4SC • 正規表現: プロトコル(イベント列のパターン)の記述 • 選択 “+”, 連接 “;” , 繰り返し “*” によりパターンを記述 • LDL式*1: 状態列に対する制約を記述 • canOrder: 注文可能状態 • ordered: 注文済状態 14 店舗: 発注を受けたら承諾・拒否の応答を返す。 承諾した場合、発送処理を行う。 発送するまでは注文変更を受け付ける。 注文後は再注文できない。 … protocol (order; accept; ...) + ;; property canOrder // 初期状態 & [{true}*;{ordered}] !canOrder & ... ;; rule on order when canOrder { ... }// 事前状態 & 条件 do ordered { ... } // 事後状態 & アクション ... *1) LDL = Linear Dynamic Logic 状態とイベント イベントパターンの定義 状態列の性質
  • 15. © Copyright IBM Corporation 2018 例: DSL4SCによるプロトコル定義 15 protocol order; accept; (order; accept)*; ship; receive; deliver; pay + order; reject;; rule on order when { _event.data.quantity > 0 } do { _data.item = _event.data.item; _data.quantity = _event.data.quantity; _data.amount = _event.data.amount; _data.orderDate = _event.data.date; }; … on pay when { _data.amount == _event.data.amount } do { ... }; DSL4SC rule プロトコルと条件 シナリオ1: 顧客: 注文する。(数量 > 0) 店舗: 承諾する。 顧客: 再注文する。 店舗: 承諾する。 店舗: 発送する。 配送: 受領する。 配送: 配達する。 顧客: 支払いを行う。(注文金額 == 支払額) シナリオ2: 顧客: 注文する。 店舗: 拒否する。 0回以上の 繰り返し
  • 16. © Copyright IBM Corporation 2018 DSL4SC (LDLについて) • 契約(義務)に対応するように性質を記述 • 手続きではなく「常に」「いつかは」という時間に関する性質を記述可能 • 「どんな場合でもいつかはAの状態になる」 [{true}*] <{true}*> A • 「Aの後にBの状態になる」  < {true}*; A > B • 「Aの後は常にBの状態になる」  [ {true}*; A ] B 16 店舗: 発注を受けたら承諾・拒否の応答を返す。 承諾した場合、発送処理を行う。 発送するまでは注文変更を受け付けても良い。 注文後は再注文できない。 … protocol ...;; property canOrder // 初期状態 & [{true}*;{ordered}] !canOrder & ... ;; rule on order when canOrder // 事前状態 do ordered { ... } // 事後状態 ... *1) LDL = Linear Dynamic Logic
  • 17. © Copyright IBM Corporation 2018 DSL4SCからStatechartへの変換例 17 protocol order; accept; (order; accept)*; ship; receive; deliver; pay + order; reject;; rule on order when { _event.data.quantity > 0 } do { _data.item = _event.data.item; _data.quantity = _event.data.quantity; _data.amount = _event.data.amount; _data.orderDate = _event.data.date; }; … on pay when { _data.amount == _event.data.amount } do { ... }; DSL4SC rule Statechart
  • 18. © Copyright IBM Corporation 2018 Scxmlcc & CCFlow • CCFlow: 状態遷移機械を実装したGoパッケージ • 条件/アクションの実行のためにOttoパッケージ(JSインタプリタ)を利用 • 条件/アクションとしてGoの関数も利用可能 • Chaincode中で利用されることを想定 (単独でも利用可能) • scxmlcc: CCFlowを利用するchaincodeの生成器 • 生成したファイルはそのままchaincodeとしてデプロイ可能 • SCXMLのサブセットをサポート 18 SCXML <scxml> … </scxml> scxmlcc CCFlow Statechart definition Chaincode Otto
  • 19. © Copyright IBM Corporation 2018 Scxmlccで生成されたchaincodeの動作 19 Client Main I/F Ledger Main I/F SCXML Invoke(…) “order” transaction “order” event Update the state & Store the state into KVS Record the transaction Peer Chaincode • イベントによる状態遷移 • 現在状態(と属性値)の取得 • Statechartインスタンスの 操作(作成,削除など)
  • 20. © Copyright IBM Corporation 2018 Statechart (SCXML) • Statechartはシステムの動作を定義するモデル • 階層化、平行状態を用いて複雑な動作を簡潔に記述 • SCXMLはStatechartのXML表現のW3C標準 • オープンソースのSCXMLエディタ/ツールを利用可能 • 例: https://github.com/fmorbini/scxmlgui 20 Derivative Bond issuing
  • 21. © Copyright IBM Corporation 2018 Statechartのテスト • CCFlowを用いてローカル環境(コマンドライン)で実行 • デプロイする前にStatechartとしてのバグを発見 21 … ["day_close”, {"price": 90}] ["day_open"] … … true {"State":“4","Subflows":{}} {"bought_shares":2,"cur_date":0, "spot_price":90} true {"State":“2","Subflows":{}} {"bought_shares":2,"cur_date":1, "spot_price":90} … $ scxmlrun -t trace.txt -f events.txt purchase.scxml events.txt trace.txt purchase.scxml
  • 22. © Copyright IBM Corporation 2018 参考情報 • ldltools: https://github.com/ldltools • ldlsatとdsl4sc(rules2scxml)を提供 • Blockchainとは独立したLDLおよびSCXMLのためのツール • DSL4SCにおける形式検証ツールも提供 • scdtools: https://github.com/scdtools • ccflow(scxmlcc, scxmlrun)とデモのためのDocker環境を提供予定 22