JP2020038482A - Program verification program, program verification method and program verification device - Google Patents
Program verification program, program verification method and program verification device Download PDFInfo
- Publication number
- JP2020038482A JP2020038482A JP2018165145A JP2018165145A JP2020038482A JP 2020038482 A JP2020038482 A JP 2020038482A JP 2018165145 A JP2018165145 A JP 2018165145A JP 2018165145 A JP2018165145 A JP 2018165145A JP 2020038482 A JP2020038482 A JP 2020038482A
- Authority
- JP
- Japan
- Prior art keywords
- variable
- source code
- value
- instruction
- database
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Images
Landscapes
- Debugging And Monitoring (AREA)
- Stored Programmes (AREA)
Abstract
Description
本発明はプログラム検証プログラム、プログラム検証方法およびプログラム検証装置に関する。 The present invention relates to a program verification program, a program verification method, and a program verification device.
同一内容のデータを記憶する複数のデータベースをネットワーク上に配置した分散データベースシステムがある。例えば、トランザクション(取引)の履歴を示すブロックチェーンと呼ばれるデータベースを構築し、複数のサーバ装置が同一内容のブロックチェーンを保持することでトランザクションの正当性を担保するブロックチェーンシステムがある。分散データベースシステムにおけるデータベースの更新は、複数のサーバ装置に同じプログラムを配置しておき、それら複数のサーバ装置のプログラムに同一の入力を与えることで、複数のデータベースを並列に更新することによって行うことがある。 There is a distributed database system in which a plurality of databases storing data of the same content are arranged on a network. For example, there is a block chain system in which a database called a block chain indicating a history of a transaction (transaction) is constructed, and a plurality of server devices hold the same content of the block chain to ensure the validity of the transaction. Updating a database in a distributed database system is performed by arranging the same program in a plurality of server devices and providing the same input to the programs of the plurality of server devices, thereby updating the plurality of databases in parallel. There is.
なお、ソースコードのコンパイル時に、ソースコードから生成される中間コードに対して制御フローやデータフローの静的解析を行う静的解析方法が提案されている。提案の静的解析方法は、静的解析にあたって中間コードを静的単一代入(SSA: Static Single Assignment)形式に変換する。また、ソースコードから検証式を生成し、モデル検証ツールを用いてプログラム動作を検証するプログラム検証装置が提案されている。提案のプログラム検証装置は、ソースコードをSSA形式に変換し、元のソースコードとSSA形式ソースコードに基づいて検証対象の処理部分を決定する。 Note that a static analysis method has been proposed in which a control flow and a data flow are statically analyzed with respect to an intermediate code generated from the source code when compiling the source code. The proposed static analysis method converts an intermediate code into a static single assignment (SSA) format for static analysis. In addition, a program verification device that generates a verification formula from a source code and verifies a program operation using a model verification tool has been proposed. The proposed program verification device converts the source code into the SSA format, and determines a processing part to be verified based on the original source code and the SSA format source code.
分散データベースシステムの複数のサーバ装置に配置されるプログラムは、同一のデータベースの内容および同一の入力に対して、データベースに書き込まれる値が同一になるという決定性をもっていることが要求される。プログラムに非決定的動作が含まれると、複数のデータベースの同一性が失われ、トランザクションの正当性の担保といった分散データベースシステムの目的を達成できなくなるおそれがある。 A program arranged in a plurality of server devices of a distributed database system is required to have determinism that values written to the database are the same for the same database contents and the same input. If a program includes non-deterministic operations, the identity of a plurality of databases may be lost, and the purpose of a distributed database system such as ensuring the validity of a transaction may not be achieved.
プログラムの非決定的動作は、データベースに書き込む値が、乱数の取得やタイムスタンプの取得などの所定の種類の操作に依存することによって発生する。そこで、複数のサーバ装置に配置されるプログラムを開発する際に、データベースへの書き込みが非決定的動作になるという不具合を発見するため、プログラムを検証することが考えられる。しかし、抽象構文木(AST:Abstract Syntax Tree)の探索やシンボリック実行など、従来のソースコードの静的解析方法では、データベースへの書き込みに関連する命令の追跡が非効率となり検証時間が増大するという問題がある。 The non-deterministic operation of the program occurs when a value to be written to the database depends on a predetermined type of operation such as obtaining a random number or obtaining a time stamp. Therefore, when developing a program to be allocated to a plurality of server devices, it is conceivable to verify the program in order to discover a problem that writing to the database is an indeterminate operation. However, conventional static analysis of source code, such as searching for an abstract syntax tree (AST) or symbolic execution, inefficiently traces instructions related to writing to a database and increases verification time. There's a problem.
1つの側面では、本発明は、非決定的動作の検証を高速化できるプログラム検証プログラム、プログラム検証方法およびプログラム検証装置を提供することを目的とする。 In one aspect, an object of the present invention is to provide a program verification program, a program verification method, and a program verification device that can speed up verification of a non-deterministic operation.
1つの態様では、コンピュータに以下の処理を実行させるプログラム検証プログラムが提供される。同一の変数への複数回の値の代入を許容する第1のソースコードを、各変数への値の代入を1回に制限する静的単一代入形式の第2のソースコードに変換する。第2のソースコードから、データベースへの書き込みを示す第1の命令を検索し、第1の命令において書き込む値が格納されている変数を検出し、第2のソースコードから、検出した変数への値の代入を示す第2の命令を検索する。第2の命令における検出した変数に代入される値の取得方法に基づいて、データベースへの書き込みが、第1のソースコードの引数およびデータベースのデータ以外の実行状況に依存する非決定的動作であるか否か判定する。また、1つの態様では、コンピュータが実行するプログラム検証方法が提供される。また、1つの態様では、記憶部と処理部とを有するプログラム検証装置が提供される。 In one aspect, a program verification program for causing a computer to execute the following processing is provided. The first source code that allows multiple values to be assigned to the same variable is converted to a static single assignment type second source code that limits the assignment of a value to each variable to one. From the second source code, a first instruction indicating writing to the database is searched, a variable storing a value to be written in the first instruction is detected, and the second source code is searched for the detected variable. Search for a second instruction that indicates a value assignment. Based on the acquisition method of the value substituted for the detected variable in the second instruction, whether writing to the database is a non-deterministic operation that depends on the execution status other than the argument of the first source code and the data of the database. Determine whether or not. In one aspect, a program verification method executed by a computer is provided. In one aspect, a program verification device having a storage unit and a processing unit is provided.
1つの側面では、非決定的動作の検証を高速化できる。 In one aspect, non-deterministic operation verification can be speeded up.
以下、本実施の形態を図面を参照して説明する。
[第1の実施の形態]
第1の実施の形態を説明する。
Hereinafter, the present embodiment will be described with reference to the drawings.
[First Embodiment]
A first embodiment will be described.
図1は、第1の実施の形態のプログラム検証装置の例を説明する図である。
第1の実施の形態のプログラム検証装置10は、開発したプログラムを検証する。検証するプログラムは、同一内容のデータを記憶する複数のデータベースを並列に更新する分散データベースシステムに用いられるプログラムであってもよい。例えば、検証するプログラムは、ブロックチェーンを管理する複数のサーバ装置で並列に実行されるものである。プログラム検証装置10は、情報処理装置やコンピュータと呼ばれることもある。プログラム検証装置10は、クライアント装置でもよいしサーバ装置でもよい。
FIG. 1 is a diagram illustrating an example of a program verification device according to the first embodiment.
The
プログラム検証装置10は、記憶部11および処理部12を有する。記憶部11は、RAM(Random Access Memory)などの揮発性の半導体メモリでもよいし、HDD(Hard Disk Drive)やフラッシュメモリなどの不揮発性ストレージでもよい。処理部12は、例えば、CPU(Central Processing Unit)、GPU(Graphics Processing Unit)、DSP(Digital Signal Processor)などのプロセッサである。ただし、処理部12は、ASIC(Application Specific Integrated Circuit)やFPGA(Field Programmable Gate Array)などの特定用途の電子回路を含んでもよい。複数のプロセッサの集合を「マルチプロセッサ」または単に「プロセッサ」と言うことがある。
The
記憶部11は、検証対象のソースコード13(第1のソースコード)を記憶する。ソースコード13は、高水準言語であるプログラミング言語によって記述されている。ソースコード13は、同一の変数への複数回の値の代入を許容している。また、記憶部11は、後述するようにソースコード13から変換されたソースコード14(第2のソースコード)を記憶する。ソースコード14は、ソースコード13と同様に高水準言語であるプログラミング言語によって記述されている。ソースコード14は、静的単一代入形式(SSA形式)であり、各変数への値の代入を1回に制限している。
The
処理部12は、ソースコード13を検証するにあたり、まずソースコード13をソースコード14に変換する。SSA形式への変換では、処理部12は、ソースコード13の中から同一の変数に対する2回目の値の代入を検出する。すると、処理部12は、ソースコード13で使用されていない新たな変数を定義し、値の代入先を新たな変数に変更し、それ以降の当該変数の参照を当該新たな変数の参照に置換する。これによって、各変数への値の代入を高々1回に制限することができる。
When verifying the
例えば、ソースコード13は、引数の値を変数valueに代入する命令と、変数valueの値に乱数を加えた値を変数valueに代入する命令と、変数valueの値をデータベースに書き込む命令を含む。これに対してソースコード14は、引数の値を変数value0に代入する命令と、変数value0の値に乱数を加えた値を変数value1に代入する命令と、変数value1の値をデータベースに書き込む命令を含む。
For example, the
次に、処理部12は、ソースコード14から、データベースへの書き込みを示す命令15(第1の命令)を検索する。処理部12は、命令15において書き込む値が格納されている変数を検出する。書き込む値が格納されている変数は、例えば、命令15の右辺に記載されているオペランドである。処理部12は、ソースコード14から、検出した変数への値の代入を示す命令16(第2の命令)を検索する。検出した変数は、例えば、命令16の左辺に記載されている。処理部12は、例えば、命令15からソースコード14の先頭に向かって、ソースコード14の命令を走査することで命令16を検索する。
Next, the
例えば、処理部12は、ソースコード14から、PutState(”key”,value1)を命令15として検出する。この命令は、”key”に対応するバリューとして変数value1の値をデータベースに書き込むものである。すると、処理部12は、ソースコード14を命令15から遡って走査し、value1=value0+rand.Int32()を命令16として検出する。この命令は、変数value0の値に乱数を加えた値をvalue1に代入するものである。
For example, the
処理部12は、命令16における検出した変数に代入される値の取得方法を特定し、特定した取得方法に基づいて、データベースへの書き込みが非決定的動作であるか判定する。変数に代入される値の取得方法は、例えば、命令16の右辺から特定することができる。非決定的動作は、書き込まれる値が、ソースコード13の引数およびデータベースに格納されているデータ以外の実行状況に依存して変化し得る動作である。
The
非決定的動作の原因には、例えば、書き込まれる値が乱数またはタイムスタンプ(現在時刻)に依存することが含まれる。また、非決定的動作の原因には、例えば、書き込まれる値が、複数のスレッドによって共有されるグローバル変数に依存することが含まれる。また、非決定的動作の原因には、例えば、書き込まれる値が、ソースコード13に規定する処理を実行するサーバ装置の外部のAPI(Application Programming Interface)を呼び出すことで取得される値に依存することが含まれる。また、非決定的動作の原因には、例えば、書き込まれる値が、Mapオブジェクトなど、複数のデータ要素を保持しておりデータ要素間の順序が保証されないデータ構造に依存することが含まれる。
Causes of non-deterministic operation include, for example, that the value to be written depends on a random number or a time stamp (current time). Also, the cause of the non-deterministic operation includes, for example, that the value to be written depends on a global variable shared by a plurality of threads. The cause of the non-deterministic operation is, for example, that the value to be written depends on a value obtained by calling an API (Application Programming Interface) external to the server device that executes the processing specified in the
例えば、処理部12は、value1=value0+rand.Int32()を命令16として検出すると、変数value1に代入される値の取得方法の中に、乱数の使用が含まれていることを検出する。すると、処理部12は、命令16において変数value1に代入される値が非決定的であり、その結果として命令15でデータベースに書き込まれる値が非決定的であると判定する。
For example, the
処理部12は、データベースへの書き込みが非決定的動作であるか否かの判定結果を出力する。例えば、処理部12は、プログラム検証装置10が有するディスプレイに判定結果を表示する。ただし、処理部12は、プログラム検証装置10が有するストレージ装置に判定結果を記録してもよく、ディスプレイ以外の出力デバイスに判定結果を出力してもよい。また、処理部12は、他の情報処理装置に判定結果を送信してもよい。判定結果は、データベースへの書き込みを示す命令15を識別する情報を含んでもよく、書き込まれる値の代入を示す命令16を識別する情報を含んでもよい。命令16の右辺に乱数が含まれている場合、例えば、処理部12は、ソースコード13が規定するデータベースへの書き込みが非決定的動作であることを示す警告をディスプレイに表示する。
The
第1の実施の形態のプログラム検証装置10によれば、ソースコード13がSSA形式のソースコード14に変換される。そして、ソースコード14を用いて、データベースに書き込む値を保持する変数に関連する命令が検索され、データベースへの書き込みが非決定的動作であるか否か判定される。これにより、ソースコード13の開発時に、データベースに書き込まれる値が引数およびデータベースのデータ以外の実行状況に依存して変化するという不具合を検出することが可能となる。よって、ソースコード13に規定する処理を複数のコンピュータで並列に実行した場合に、ソースコード13の不具合によりデータベース間の整合性が失われることを抑制することができる。
According to the
また、SSA形式のソースコード14を利用することで、データベースに書き込む値に関連する命令を検索することが容易となり、非決定的動作の検証を高速化することができる。ソースコード14では、データベースに書き込む値を保持する変数への代入は1回のみ行われ、かつ、同一関数内ではデータフローの順に命令が並んでいる。よって、例えば、データベースへの書き込みを示す命令15から逆順に命令を走査することで、変数への値の代入を示す命令16を高速に検索することができる。また、ソースコード13に対応する抽象構文木を利用する方法と比べて、変数に関連する命令を追跡するために抽象構文木を繰り返し走査しなくてよく、検索が高速化される。また、シンボリック実行を利用する方法と比べて、複雑なパス抽出を行わなくてよく検索が高速化される。
Further, by using the
[第2の実施の形態]
次に、第2の実施の形態を説明する。
図2は、第2の実施の形態の情報処理システムの例を示す図である。
[Second embodiment]
Next, a second embodiment will be described.
FIG. 2 is a diagram illustrating an example of the information processing system according to the second embodiment.
第2の実施の形態の情報処理システムは、複数のサーバ装置を用いてブロックチェーンを管理する分散データベースシステムである。ブロックチェーンは、一連のトランザクションの履歴を示すデータベースであり、それらトランザクションに対応するブロックを連結したリストである。複数のサーバ装置が同一内容のブロックチェーンを保持して相互に確認することで、トランザクションの正当性を担保することができる。 The information processing system according to the second embodiment is a distributed database system that manages a block chain using a plurality of server devices. The block chain is a database showing the history of a series of transactions, and is a list in which blocks corresponding to those transactions are linked. A plurality of server devices hold the same contents of the block chain and mutually confirm each other, so that the legitimacy of the transaction can be secured.
第2の実施の形態の情報処理システムは、開発装置100およびサーバ装置200,200−1,200−2,200−3,200−4を含む。開発装置100およびサーバ装置200,200−1,200−2,200−3,200−4は、ネットワーク30に接続されている。ネットワーク30は、インターネットなどの広域ネットワークである。
The information processing system according to the second embodiment includes a
開発装置100は、サーバ装置200,200−1,200−2,200−3,200−4で実行されるプログラムであるスマートコントラクトの開発に用いられる情報処理装置である。スマートコントラクトは、新たなトランザクションの発生に応じて、ブロックチェーンの末尾に新たなブロックを追加する。開発装置100は、同一のスマートコントラクトをサーバ装置200,200−1,200−2,200−3,200−4に配布する。開発装置100は、クライアント装置でもよいしサーバ装置でもよい。
The
サーバ装置200,200−1,200−2,200−3,200−4は、同一内容のブロックチェーンを保持する情報処理装置である。サーバ装置200,200−1,200−2,200−3,200−4には同一のスマートコントラクトが配置されている。サーバ装置200,200−1,200−2,200−3,200−4は、新たに発生したトランザクションを示す入力情報を受信し、受信した入力情報を用いてスマートコントラクトを実行することで並列にブロックチェーンを更新する。
Each of the
サーバ装置200は、ブロックチェーン210を保持し、スマートコントラクトを実行してブロックチェーン210を更新する。サーバ装置200−1は、ブロックチェーン210−1を保持し、スマートコントラクトを実行してブロックチェーン210−1を更新する。サーバ装置200−2は、ブロックチェーン210−2を保持し、スマートコントラクトを実行してブロックチェーン210−2を更新する。サーバ装置200−3は、ブロックチェーン210−3を保持し、スマートコントラクトを実行してブロックチェーン210−3を更新する。サーバ装置200−4は、ブロックチェーン210−4を保持し、スマートコントラクトを実行してブロックチェーン210−4を更新する。
The
図3は、開発装置のハードウェア例を示すブロック図である。
開発装置100は、バスに接続されたCPU101、RAM102、HDD103、画像信号処理部104、入力信号処理部105、媒体リーダ106および通信インタフェース107を有する。開発装置100は、第1の実施の形態のプログラム検証装置10に対応する。CPU101は、第1の実施の形態の処理部12に対応する。RAM102またはHDD103は、第1の実施の形態の記憶部11に対応する。サーバ装置200,200−1,200−2,200−3,200−4も同様のハードウェアを有する。
FIG. 3 is a block diagram illustrating an example of hardware of the development device.
The
CPU101は、プログラムの命令を実行するプロセッサである。CPU101は、HDD103に記憶されたプログラムやデータの少なくとも一部をRAM102にロードし、プログラムを実行する。なお、CPU101は複数のプロセッサコアを備えてもよく、開発装置100は複数のプロセッサを備えてもよい。複数のプロセッサの集合を「マルチプロセッサ」または単に「プロセッサ」と言うことがある。
The
RAM102は、CPU101が実行するプログラムやCPU101が演算に使用するデータを一時的に記憶する揮発性の半導体メモリである。なお、開発装置100は、RAM以外の種類のメモリを備えてもよく、複数のメモリを備えてもよい。
The
HDD103は、OS(Operating System)やミドルウェアやアプリケーションソフトウェアなどのソフトウェアのプログラム、および、データを記憶する不揮発性ストレージである。なお、開発装置100は、フラッシュメモリやSSD(Solid State Drive)など他の種類のストレージを備えてもよく、複数のストレージを備えてもよい。
The
画像信号処理部104は、CPU101からの命令に従って、開発装置100に接続されたディスプレイ111に画像を出力する。ディスプレイ111としては、CRT(Cathode Ray Tube)ディスプレイ、液晶ディスプレイ(LCD:Liquid Crystal Display)、有機EL(OEL:Organic Electro-Luminescence)ディスプレイなど、任意の種類のディスプレイを使用することができる。
The image
入力信号処理部105は、開発装置100に接続された入力デバイス112から入力信号を受信する。入力デバイス112として、マウス、タッチパネル、タッチパッド、キーボードなど、任意の種類の入力デバイスを使用できる。また、開発装置100に複数の種類の入力デバイスが接続されてもよい。
The input
媒体リーダ106は、記録媒体113に記録されたプログラムやデータを読み取る読み取り装置である。記録媒体113として、例えば、フレキシブルディスク(FD:Flexible Disk)やHDDなどの磁気ディスク、CD(Compact Disc)やDVD(Digital Versatile Disc)などの光ディスク、光磁気ディスク(MO:Magneto-Optical disk)、半導体メモリなどを使用できる。媒体リーダ106は、例えば、記録媒体113から読み取ったプログラムやデータをRAM102またはHDD103に格納する。
The
通信インタフェース107は、ネットワーク30に接続され、ネットワーク30を介してサーバ装置200,200−1〜200−4などの情報処理装置と通信を行うインタフェースである。通信インタフェース107は、スイッチやルータなどの有線通信装置に接続される有線通信インタフェースである。ただし、基地局やアクセスポイントなどの無線通信装置に接続される無線通信インタフェースを利用してもよい。
The
図4は、ブロックチェーンのデータ構造例を示す図である。
サーバ装置200,200−1,200−2,200−3,200−4は、図4に示すようなデータ構造のブロックチェーンを保持する。ブロックチェーンは、ブロック40,40−1,40−2などの複数のブロックを含む。1つのブロックは1つのトランザクション(取引)を示す。ブロック40−1はブロック40の前段のブロックである。ブロック40−2はブロック40の後段のブロックである。各ブロックは、例えば、データをキーとバリューの組であるキーバリュー形式で保持することができる。ブロック40は、ハッシュ値41、取引データ42、公開鍵43および署名44を含む。ブロック40−1,40−2などの他のブロックも、ブロック40と同様のデータ構造をもつ。
FIG. 4 is a diagram illustrating an example of a data structure of a block chain.
Each of the
ハッシュ値41は、前段のブロック40−1の全体を所定のハッシュ関数に入力することで算出されるハッシュ値である。ハッシュ値41により、ブロック40とその前段のブロック40−1とが関連付けられる。また、ブロック40−2に含まれるハッシュ値により、ブロック40−2とその前段のブロック40とが関連付けられる。取引データ42は、取引金額などトランザクションの内容を示す。
The
公開鍵43は、取引相手の公開鍵である。ブロック40が示すトランザクションの取引相手は、後段のブロック40−2が示すトランザクションの取引主体になることが期待される。よって、公開鍵43を用いて、後段のブロック40−2に含まれる署名を検証することができる。署名44は、取引主体(取引元)の秘密鍵を用いて生成されたデジタル署名である。ブロック40が示すトランザクションの取引主体は、前段のブロック40−1が示すトランザクションの取引相手であることが期待される。よって、前段のブロック40−1の公開鍵を用いて、ブロック40の署名44を検証することができる。
The
次に、スマートコントラクトの開発における問題点について説明する。
図5は、スマートコントラクトの非決定的動作の例を示す図である。
サーバ装置200,200−1,200−2,200−3,200−4は、同一の入力情報を受信して同一のスマートコントラクトを実行し、並列にブロックチェーン210,210−1,210−2,210−3,210−4を更新する。更新後のブロックチェーン210,210−1,210−2,210−3,210−4の内容は同一であることが求められる。よって、スマートコントラクトは、ブロックチェーンに書き込む値が、入力情報および更新前のブロックチェーンの内容から一意に決定されるようにし、それ以外の外部状態に依存して決定されることがないようにすることが求められる。
Next, problems in the development of a smart contract will be described.
FIG. 5 is a diagram illustrating an example of a non-deterministic operation of the smart contract.
The
ブロックチェーンに書き込む値が、入力情報および更新前のブロックチェーンの内容のみに依存する場合、書き込みが決定的であると言うことができる。一方、ブロックチェーンに書き込む値が、入力情報および更新前のブロックチェーンの内容以外の外部状態に依存する場合、書き込みが非決定的であると言うことができる。外部状態への依存として、乱数の使用、タイムスタンプの使用、外部APIの呼び出し、グローバル変数の参照およびMapオブジェクトの反復参照が挙げられる。 If the value to be written to the blockchain depends only on the input information and the contents of the blockchain before updating, it can be said that the writing is deterministic. On the other hand, if the value to be written to the block chain depends on an external state other than the input information and the contents of the block chain before updating, it can be said that the writing is non-deterministic. Dependencies on external states include the use of random numbers, the use of timestamps, calling external APIs, referencing global variables, and iteratively referencing Map objects.
乱数を使用すると、ブロックチェーンに書き込む値がランダムに変化してしまう。タイムスタンプを使用すると、スマートコントラクトを実行する時刻の違いによってブロックチェーンに書き込む値が変化してしまう。外部APIを呼び出すと、外部APIを呼び出すことでサーバ装置の外部から受信される情報が不変であることが保証されず、ブロックチェーンに書き込む値がサーバ装置によって変化してしまう。 If a random number is used, the value written to the blockchain will change randomly. When a time stamp is used, the value written to the blockchain changes depending on the time at which the smart contract is executed. When an external API is called, it is not guaranteed that information received from outside the server device by calling the external API is unchanged, and the value to be written in the block chain changes depending on the server device.
グローバル変数を参照すると、あるスレッドが参照するグローバル変数の値が他のスレッドによって書き換えられることがあり、同一サーバ装置上の複数のスレッドの実行タイミングによってブロックチェーンに書き込む値が変化してしまう。Mapオブジェクトは、複数のデータ要素(エントリやレコードと言うこともある)を格納可能なデータ構造であって、それら複数のデータ要素の格納順序が保証されないデータ構造である。そのため、for文などの反復構造を用いてMapオブジェクトに格納された複数のデータ要素を順に参照すると、それら複数のデータ要素の参照順序がサーバ装置によって変わり、ブロックチェーンに書き込む値が変化してしまう。 When referring to a global variable, the value of the global variable referred to by a certain thread may be rewritten by another thread, and the value to be written to the block chain changes depending on the execution timing of a plurality of threads on the same server device. The Map object is a data structure capable of storing a plurality of data elements (sometimes called entries or records), and the storage order of the plurality of data elements is not guaranteed. Therefore, when a plurality of data elements stored in the Map object are sequentially referred to using a repetitive structure such as a for statement, the reference order of the plurality of data elements changes depending on the server device, and the value written in the block chain changes. .
例えば、タイムスタンプ(現在時刻)をブロックチェーンに書き込むスマートコントラクト51がサーバ装置200,200−1,200−2,200−3,200−4に配置されたとする。すると、ブロックチェーン210,210−1,210−2,210−3,210−4に書き込まれる値が同一になるとは限らない。例えば、ブロックチェーン210には時刻「10:20:06 430Z」が書き込まれる。ブロックチェーン210−1には時刻「10:20:06 450Z」が書き込まれる。ブロックチェーン210−2には時刻「10:20:06 450Z」が書き込まれる。ブロックチェーン210−3には時刻「10:20:06 400Z」が書き込まれる。ブロックチェーン210−4には時刻「10:20:06 419Z」が書き込まれる。
For example, it is assumed that the
ブロックチェーンへの書き込みが非決定的動作になるスマートコントラクトをサーバ装置200,200−1,200−2,200−3,200−4に配置すると、情報処理システムに不具合が発生する。そこで、開発装置100は、開発したスマートコントラクトに非決定的動作が含まれていないか検証する。
If a smart contract in which writing to the blockchain becomes a non-deterministic operation is arranged in the
図6は、スマートコントラクトの例を示す図である。
開発装置100は、開発したスマートコントラクトを記憶する。スマートコントラクト52,53は、検証対象のスマートコントラクトの例である。
FIG. 6 is a diagram illustrating an example of a smart contract.
The
スマートコントラクト52は、関数Initを含む。関数Initは、呼び出されるときに4つの引数args[0]〜args[3]を受け付ける。関数Initは、引数args[0]の文字列を変数Aに代入し、整数の乱数を変数Avalに代入し、引数args[2]の文字列を変数Bに代入し、引数args[3]の文字列が表す整数を変数Bvalに代入する。乱数は関数rand.Int32を呼び出すことで取得される。
The
引数args[3]の文字列を整数に変換できない場合、関数Initはエラーメッセージを出力する。関数Initは、変数Aの文字列をキーとし、変数Avalの整数を表す文字列をバリューとしてブロックチェーンに書き込む。ブロックチェーンへの書き込みは、関数PutStateを呼び出すことで行う。このときエラーが発生すると、関数Initはエラーメッセージを出力する。また、関数Initは、変数Bの文字列をキーとし、変数Bvalの整数を表す文字列をバリューとしてブロックチェーンに書き込む。このときエラーが発生すると、関数Initはエラーメッセージを出力する。 If the character string of the argument args [3] cannot be converted to an integer, the function Init outputs an error message. The function Init uses the character string of the variable A as a key and writes a character string representing an integer of the variable Aval as a value into the block chain. Writing to the block chain is performed by calling the function PutState. If an error occurs at this time, the function Init outputs an error message. The function Init uses the character string of the variable B as a key and writes a character string representing an integer of the variable Bval as a value into the block chain. If an error occurs at this time, the function Init outputs an error message.
スマートコントラクト53は、文字列型の変数A、整数型の変数Avalおよび整数型の変数Xを定義する。スマートコントラクト53は、文字列「key」を変数Aに代入し、整数「1」を変数Avalに代入し、整数の乱数を変数Xに代入する。スマートコントラクト53は、変数Avalの値に変数Xの値を加算し、加算結果を変数Avalに代入する。そして、スマートコントラクト53は、変数Aの文字列をキーとし、変数Avalの整数を表す文字列をバリューとしてブロックチェーンに書き込む。
The
スマートコントラクトの非決定的動作を検証する方法としては、抽象構文木を利用する方法やシンボリック実行を利用する方法も考えられる。以下では、抽象構文木を利用する方法とシンボリック実行を利用する方法について説明する。 As a method of verifying the nondeterministic operation of the smart contract, a method using an abstract syntax tree or a method using symbolic execution can be considered. In the following, a method using an abstract syntax tree and a method using symbolic execution will be described.
図7は、抽象構文木の第1の例を示す図である。
抽象構文木61は、スマートコントラクト52から生成される抽象構文木である。抽象構文木61は、ソースコードであるスマートコントラクト52の構文を表す木構造データである。抽象構文木61は、変数の宣言(変数宣言)を示すノードや、変数への値の代入(代入演算)を示すノードを含む。また、抽象構文木61は、代入演算を示すノードの子ノードとして、代入先の変数(左辺の変数)を示すノード、演算子を示すノード、代入値を格納している変数(右辺の変数)を示すノード、代入値を算出する関数の呼び出し(関数呼び出し)を示すノードなどを含む。また、抽象構文木61は、関数呼び出しを示すノードの子ノードとして、関数の引数としての変数を示すノードを含む。
FIG. 7 is a diagram illustrating a first example of an abstract syntax tree.
The
ブロックチェーンへの書き込みが非決定的であるか否かを抽象構文木61を用いて検証する場合、次のような検証方法が考えられる。まず、抽象構文木61をルートノードから順に幅優先探索または深さ優先探索により走査し、ブロックチェーンへの書き込みを示す関数呼び出しのノードを検索する。関数呼び出しのノードが検出されると、その子ノードに基づいてブロックチェーンに書き込む値が格納されている変数を特定する。
When verifying whether writing to the block chain is non-deterministic using the
すると、抽象構文木61をルートノードから順に再び走査して、当該変数に値を代入する代入演算を示すノードを検索する。検出された代入演算の右辺に変数が存在する場合、抽象構文木61をルートノードから順に再び走査して、当該変数に値を代入する代入演算を示すノードを検索する。これを繰り返すことで、ブロックチェーンに書き込む値を算出する過程が追跡される。書き込む値を算出する過程で、乱数を取得する関数の呼び出しやタイムスタンプを取得する関数の呼び出しなど、非決定性の原因となる操作が行われた場合、書き込みが非決定的動作であると判定される。
Then, the
例えば、図7の例では、まず関数PutStateの呼び出しを示すノードが検出され、関数PutStateの引数を示すノードとして変数Aを示すノードと変数Avalを示すノードが検出される。すると、抽象構文木61がルートノードから順に再び走査され、変数Aに引数args[0]の値を代入する代入演算を示すノードと、変数Avalに関数rand.Int32の戻り値を代入する代入演算を示すノードとが検出される。関数rand.Int32は乱数を取得する関数であるため、書き込む値が乱数に依存することになり、ブロックチェーンへの書き込みが非決定的であると判定される。
For example, in the example of FIG. 7, first, a node indicating a call to the function PutState is detected, and a node indicating a variable A and a node indicating a variable Aval are detected as nodes indicating arguments of the function PutState. Then, the
しかし、抽象構文木61は複数の演算の間の順序関係を表現していない。また、同一の変数に対する値の代入が複数回行われることがあり、同一の変数についての代入演算を示すノードが抽象構文木61に複数存在することがある。このため、ブロックチェーンに書き込む値を格納する変数に関連するノードが抽象構文木61の様々な箇所に分散している可能性があり、抽象構文木61の走査を何度も繰り返すことになる。
However, the
このため、スマートコントラクト52のサイズの増大に応じて抽象構文木61のノード数が増大し、プログラム検証の実行時間が増大する。例えば、約160行のソースコードから約600個のノードを含む抽象構文木が生成されることがある。また、約1700行のソースコードから約7500個のノードを含む抽象構文木が生成されることがある。その結果、プログラム検証が非効率になるおそれがある。
Therefore, the number of nodes in the
図8は、抽象構文木の第2の例を示す図である。
抽象構文木62は、スマートコントラクト53から生成される抽象構文木である。ブロックチェーンへの書き込みが非決定的であるか否かを抽象構文木62を用いて検証する場合、上記の抽象構文木61と同様の検証方法が行われる。
FIG. 8 is a diagram illustrating a second example of the abstract syntax tree.
The abstract syntax tree 62 is an abstract syntax tree generated from the
例えば、図8の例では、まず関数PutStateの呼び出しを示すノードが検出され、関数PutStateの引数を示すノードとして変数Aを示すノードと変数Avalを示すノードが検出される。すると、抽象構文木62がルートノードから順に再び走査され、変数Aに文字列「key」を代入する代入演算を示すノードが検出される。また、変数Avalの値に変数Xの値を加算して変数Avalに代入する代入演算を示すノードが検出される。これらの代入演算そのものには、非決定性の原因は存在しない。 For example, in the example of FIG. 8, a node indicating a call to the function PutState is detected, and a node indicating the variable A and a node indicating the variable Aval are detected as nodes indicating the arguments of the function PutState. Then, the abstract syntax tree 62 is scanned again in order from the root node, and a node indicating an assignment operation for assigning the character string “key” to the variable A is detected. Further, a node indicating an assignment operation of adding the value of the variable X to the value of the variable Aval and assigning the result to the variable Aval is detected. There is no cause of nondeterminism in these assignment operations themselves.
一方、変数Avalの代入演算には変数Avalの前の値と変数Xの値とが使用されている。そこで、抽象構文木62がルートノードから順に再び走査され、変数Avalに整数「1」を代入する代入演算を示すノードと、変数Xに関数rand.Int32の戻り値を代入する代入演算を示すノードとが検出される。関数rand.Int32は乱数を取得する関数であるため、書き込む値が乱数に依存することになり、ブロックチェーンへの書き込みが非決定的であると判定される。このように、抽象構文木62の走査を何度も繰り返すことになり、非決定的動作の検証が非効率になる。 On the other hand, the value before the variable Aval and the value of the variable X are used in the substitution operation of the variable Aval. Therefore, the abstract syntax tree 62 is scanned again in order from the root node, and a node indicating an assignment operation for assigning an integer “1” to a variable Aval and a function rand. A node indicating an assignment operation for assigning the return value of Int32 is detected. The function rand. Since Int32 is a function for obtaining a random number, the value to be written depends on the random number, and it is determined that writing to the block chain is non-deterministic. As described above, the scanning of the abstract syntax tree 62 is repeated many times, and the verification of the nondeterministic operation becomes inefficient.
図9は、シンボリック実行の例を示す図である。
シンボリック実行は、ソースコードを解析して異なる複数の実行パスを検出する静的解析方法である。シンボリック実行では、変数に具体的な値ではなく抽象的なシンボルを代入し、ソースコードを仮想的に実行して演算結果をシンボルを用いた式で表現する。シンボルを用いた式で表された変数の値の変化を追跡することで、実行パスを検出する。
FIG. 9 is a diagram illustrating an example of symbolic execution.
Symbolic execution is a static analysis method that analyzes a source code and detects a plurality of different execution paths. In symbolic execution, an abstract symbol is substituted for a variable instead of a specific value, and the source code is virtually executed, and the operation result is represented by an expression using the symbol. The execution path is detected by tracing a change in the value of a variable represented by an expression using a symbol.
シンボリック実行フロー63は、スマートコントラクト52のシンボリック実行の処理ステップを表す。処理p1は、変数Aにシンボルa0を代入し、変数Avalにシンボルaval0を代入し、変数Bにシンボルb0を代入し、変数Bvalにシンボルbval0を代入し、変数errにシンボルe0を代入する。処理p2は、変数errの値がnil(空文字)でないか、すなわち、シンボルe0がnilでないか判断する。シンボルe0とnilの比較に応じて、実行パスが処理p3と処理p4に分岐する。シンボルe0がnilである場合(条件「e0 != nil」が偽の場合)、処理p3が実行される。処理p3は、シンボルa0をキーとし、シンボルaval0を表す文字列をバリューとしてブロックチェーンに書き込む。シンボルe0がnilでない場合(条件「e0 != nil」が真の場合)、処理p4が実行される。処理p4は、エラーを出力する。
The
パステーブル64は、シンボリック実行によって検出された実行パスを示すテーブルである。パステーブル64は、パスID、パス条件およびパスの項目を含む。パスIDは、検出された実行パスを識別する識別子である。パス条件は、その実行パスが選択されるためにシンボルが満たすべき条件、すなわち、変数に代入されるべき値の条件である。パスは、その実行パスが通過する一連の処理ステップである。 The path table 64 is a table indicating execution paths detected by symbolic execution. The path table 64 includes items of a path ID, a path condition, and a path. The path ID is an identifier for identifying the detected execution path. The path condition is a condition to be satisfied by the symbol in order to select the execution path, that is, a condition of a value to be assigned to a variable. A path is a series of processing steps that the execution path passes.
シンボリック実行フロー63からは2つの実行パスが検出される。1つの実行パスは、シンボルe0がnilである場合に選択される実行パスであり、処理p1,p2,p3を通過する。もう1つの実行パスは、シンボルe0がnilでない場合に選択される実行パスであり、処理p1,p2,p4を通過する。
Two execution paths are detected from the
ブロックチェーンへの書き込みが非決定的であるか否かをシンボリック実行を用いて検証する場合、まずシンボリック実行によって実行パス毎のパス条件を判定し、各実行パスのパス条件に当てはまる複数の入力値をテストデータとして用意する。そして、スマートコントラクト52に複数の入力値を与えて実行結果を観察し、意図しない実行結果の変化が生じていないか判断する。意図しない実行結果の変化が存在する場合、スマートコントラクト52に非決定的動作が含まれると推定される。例えば、ある実行パスが選択されることを期待して与えた入力値から、別の実行パスが選択されて意図しない出力が得られた場合、シンボリック実行によって解析されなかった非決定性が存在すると判定される。
When using symbolic execution to verify whether writing to the block chain is non-deterministic, first determine the path conditions for each execution path by symbolic execution, and then enter multiple input values that match the path conditions for each execution path. Prepare as test data. Then, a plurality of input values are given to the
しかし、スマートコントラクト52のサイズの増大に応じてシンボリック実行フロー63の条件分岐が多くなり、検出される実行パスが増大してプログラム検証の実行時間が増大する。また、シンボリック実行では、実行パス毎のパス条件を算出するために、SMT(Satisfiability Modulo Theories)ソルバなどの数式処理を行う制約ソルバが用いられる。しかしながら、スマートコントラクト52の中にパス条件を判断するための情報が不足している場合など、制約ソルバによって実行パス毎のパス条件を算出できないことがある。その場合、テストデータを効率的に生成することができない。
However, as the size of the
そこで、第2の実施の形態の開発装置100は、スマートコントラクト52,53を静的単一代入(SSA)形式に変換し、SSAソースコードの静的解析によってスマートコントラクト52,53の非決定的動作を検証する。
Therefore, the
図10は、SSAソースコードの例を示す図である。
開発装置100は、スマートコントラクト52をSSAソースコード71に変換して記憶し、スマートコントラクト53をSSAソースコード72に変換して記憶する。SSAソースコード71,72は、スマートコントラクト52,53と意味的に等価である。ただし、SSAソースコード71,72は、スマートコントラクト52,53と異なり、1つの変数に対する代入演算は1回だけ行うという制約をもつ。スマートコントラクト52,53からSSAソースコード71,72への変換は次のように行うことができる。
FIG. 10 is a diagram illustrating an example of the SSA source code.
The
開発装置100は、あるスマートコントラクトを先頭から末尾に向かって走査し、同じ変数に対する2回目の代入演算を検出する。2回目の代入演算が検出されると、開発装置100は、当該スマートコントラクトで使用されていない新たな変数を定義し、2回目の代入演算の代入先を新たな変数に書き換える。そして、開発装置100は、それ以降の処理における当該変数の参照を当該新たな変数の参照に書き換える。3回目以降の代入演算についても、その都度新たな変数を定義してそれ以降の変数の参照を書き換える。これにより、プログラムの意味を変えずに1つの変数への値の代入を1回に制限できる。
The
SSAソースコード71は、スマートコントラクト52と同様に関数Initを含む。SSAソースコード71は、引数である4つの文字列を含む文字列型配列を変数t1に代入し、変数t1の1番目の文字列を変数t2に代入し、整数の乱数を変数t3に代入する。その後、SSAソースコード71は、変数t2,t3を引数として関数PutStateを呼び出し、関数PutStateの戻り値を変数t45に代入する。
The
SSAソースコード72は、変数t0として文字列型の変数Aを定義し、変数t1として整数型の変数Avalを定義し、変数t2として整数型の変数Xを定義する。SSAソースコード72は、変数t0に対応して新たに定義した変数t3に文字列「key」を代入する。また、SSAソースコード72は、変数t1に対応して新たに定義した変数t4に整数「1」を代入する。また、SSAソースコード72は、変数t2に対応して新たに定義した変数t5に整数の乱数を代入する。SSAソースコード72は、変数t4の値と変数t5の値の和を算出して新たな変数t6に代入する。そして、SSAソースコード72は、変数t3,t6を引数として関数PutStateを呼び出し、関数PutStateの戻り値を新たな変数t7に代入する。
The
このようなSSAソースコード71,72を利用することで、開発装置100は効率的にスマートコントラクト52,53の非決定的動作を検証することができる。開発装置100は、あるSSAソースコードを先頭から末尾に向かって走査し、ブロックチェーンへの書き込みを示す書き込み操作を検索する。書き込み操作を検出すると、開発装置100は、書き込み操作の引数に用いられている変数を特定し、当該SSAソースコードを逆方向に走査して、特定した変数への値の代入を示す代入操作を検索する。
By using such
代入操作を検出すると、開発装置100は、乱数を取得する関数の呼び出しなど非決定性の原因となる非決定的操作が、代入操作の右辺に存在するか確認する。代入操作の右辺に非決定的操作が存在しないものの他の変数が存在する場合、開発装置100は、当該SSAソースコードを更に逆方向に走査して当該他の変数への値の代入を示す代入操作を検索する。変数の代入操作を再帰的に検索することで、ブロックチェーンに書き込む値を格納する変数に影響を与える非決定的操作を探索することができる。
When detecting the assignment operation, the
例えば、SSAソースコード71について、開発装置100は、関数PutStateの呼び出しを検出し、引数である変数t2,t3を特定する。開発装置100は、関数PutStateの呼び出し位置からSSAソースコード71を先頭に向かって走査し、変数t3の代入操作を検出する。変数t3の代入操作の右辺では関数rand.Int32が呼び出されているため、開発装置100は、ブロックチェーンに書き込まれる変数t3の値が乱数に依存しており非決定的であると判定する。
For example, for the
また、SSAソースコード72について、開発装置100は、関数PutStateの呼び出しを検出し、引数である変数t3,t6を特定する。開発装置100は、関数PutStateの呼び出し位置からSSAソースコード72を先頭に向かって走査し、変数t6の代入操作を検出する。変数t6の代入操作の右辺は、非決定的操作を含まないものの変数t4,t5を含むため、開発装置100は変数t4,t5を検索対象に追加する。開発装置100は、SSAソースコード72を更に先頭に向かって走査し、変数t5の代入操作を検出する。変数t5の代入操作の右辺では関数rand.Int32が呼び出されているため、開発装置100は、ブロックチェーンに書き込まれる変数t6の値が乱数に依存しており非決定的であると判定する。
Further, with respect to the
このように、SSAソースコード71,72は、同一関数内ではデータフローの順に各種操作を記述している。また、SSAソースコード71,72は、1つの変数に対する代入操作を1回に限定し、それ以降は当該変数について参照のみ許容する。このため、開発装置100は、ブロックチェーンの書き込み操作の位置から逆順に1回だけSSAソースコード71,72を走査することで、非決定性を判定することができる。
Thus, the
次に、開発装置100の機能および処理手順について説明する。
図11は、開発装置の機能例を示すブロック図である。
開発装置100は、ソースコード記憶部121、SSAソースコード記憶部122、制御情報記憶部123、SSA変換部124、非決定性検出部125および結果表示部126を有する。ソースコード記憶部121、SSAソースコード記憶部122および制御情報記憶部123は、RAM102またはHDD103の記憶領域を用いて実装することができる。SSA変換部124、非決定性検出部125および結果表示部126は、CPU101が実行するプログラムを用いて実装することができる。
Next, functions and processing procedures of the
FIG. 11 is a block diagram illustrating an example of functions of the development device.
The
ソースコード記憶部121は、スマートコントラクト52,53など、検証対象のスマートコントラクトを記憶する。SSAソースコード記憶部122は、SSAソースコード71,72など、検証対象のスマートコントラクトから変換されたSSA形式のソースコードを記憶する。制御情報記憶部123は、スマートコントラクトの非決定的動作を検証する際に参照される制御情報を記憶する。制御情報は、ブロックチェーンの書き込み操作を示すプログラム記述や、非決定性の原因となる非決定的操作を示すプログラム記述を含む。これらのプログラム記述は、プログラミング言語毎に予め定義される。
The source
SSA変換部124は、ソースコード記憶部121から検証対象のスマートコントラクトを読み出し、スマートコントラクトをSSAソースコードに変換し、SSAソースコードをSSAソースコード記憶部122に格納する。非決定性検出部125は、SSAソースコード記憶部122からSSAソースコードを読み出し、制御情報記憶部123に記憶された制御情報を参照して、ブロックチェーンに書き込まれる値に影響する非決定的操作をSSAソースコードから検索する。結果表示部126は、非決定的動作の検出結果をディスプレイ111に表示する。検出結果には、ブロックチェーンへの書き込みが非決定的であるか否かを示すメッセージが含まれる。ブロックチェーンへの書き込みが非決定的である場合、検出結果には、問題となる非決定的操作の識別情報が含まれてもよい。
The
図12は、開発装置が保持するテーブルの例を示す図である。
書き込み操作テーブル131は、予め作成されて制御情報記憶部123に記憶されている。書き込み操作テーブル131は、プログラミング言語および操作の項目を含む。プログラミング言語は、ソースコードであるスマートコントラクトの記述に用いられている高水準言語である。書き込み操作テーブル131の操作は、特定のプログラミング言語においてブロックチェーンへの書き込みに用いられるプログラム記述である。例えば、書き込み操作に用いる関数の名称とその関数の引数の個数が定義される。
FIG. 12 is a diagram illustrating an example of a table held by the development device.
The write operation table 131 is created in advance and stored in the control
例えば、あるプログラミング言語(languageX)では、書き込み操作としてPutState(key,value)というプログラム記述が用いられる。また、別のプログラミング言語(languageY)では、書き込み操作としてputState(key,value)というプログラム記述が用いられる。 For example, in a certain programming language (languageX), a program description called PutState (key, value) is used as a write operation. In another programming language (languageY), a program description called putState (key, value) is used as a write operation.
非決定的操作テーブル132は、予め作成されて制御情報記憶部123に記憶されている。非決定的操作テーブル132は、プログラミング言語、カテゴリおよび操作の項目を含む。プログラミング言語は、ソースコードであるスマートコントラクトの記述に用いられている高水準言語である。カテゴリは、非決定性の原因となる非決定的操作の種類である。カテゴリには、前述のように、乱数、タイムスタンプ、外部API、グローバル変数およびMapオブジェクトが含まれる。非決定的操作テーブル132の操作は、特定のプログラミング言語において非決定的操作に用いられるプログラム記述である。例えば、非決定的操作に用いる関数の名称とその関数の引数の個数が定義される。
The non-deterministic operation table 132 is created in advance and stored in the control
例えば、あるプログラミング言語では、乱数を取得する非決定的操作として、rand.Int32()というプログラム記述やrand.Float32()というプログラム記述が用いられる。また、あるプログラミング言語では、タイムスタンプを取得する非決定的操作として、time.Now()というプログラム記述が用いられる。 For example, in some programming languages, the non-deterministic operation of obtaining random numbers is rand. Int32 () program description and rand. A program description called Float32 () is used. Also, in some programming languages, time.time. A program description called Now () is used.
検出結果テーブル133は、1つのスマートコントラクトの検証に対して非決定性検出部125によって生成される。検出結果テーブル133の情報は、RAM102やHDD103に保存されてもよく、ディスプレイ111に表示されてもよい。検出結果テーブル133は、位置、非決定的操作およびカテゴリの項目を含む。
The detection result table 133 is generated by the
位置は、ブロックチェーンに書き込む値に影響を与える非決定的操作が記述されているスマートコントラクト上の位置であり、例えば、スマートコントラクトの行番号で特定される。検出結果テーブル133の非決定的操作として、非決定的操作のプログラム記述が登録される。カテゴリは、非決定的操作テーブル132に定義されたカテゴリである。 The position is a position on the smart contract in which a non-deterministic operation affecting the value written to the block chain is described, and is specified by, for example, the line number of the smart contract. As the nondeterministic operation in the detection result table 133, a program description of the nondeterministic operation is registered. The category is a category defined in the non-deterministic operation table 132.
図13は、プログラム検証の手順例を示すフローチャートである。
(S10)SSA変換部124は、ソースコードであるスマートコントラクトを、SSA形式のソースコード(SSAソースコード)に変換する。SSAソースコードへの変換では、SSA変換部124は、同一の変数に対する2回目以降の代入操作を検出し、代入先の変数を新たな変数に置換し、それ以降の変数の参照を新たな変数の参照に置換する。
FIG. 13 is a flowchart illustrating an example of a procedure of program verification.
(S10) The
(S11)非決定性検出部125は、SSAソースコードの初回の読み出しではSSAソースコードの先頭行を読む。また、非決定性検出部125は、SSAソースコードの2回目以降の読み出しでは、前回読んだ行の次の行をSSAソースコードから読む。
(S11) In the first reading of the SSA source code, the
(S12)非決定性検出部125は、ステップS11で読んだ行が、書き込み操作テーブル131に定義された何れかの書き込み操作を含むか判断する。書き込み操作を含む場合はステップS14に進み、書き込み操作を含まない場合はステップS13に進む。
(S12) The
(S13)非決定性検出部125は、ステップS11でSSAソースコードの最終行まで読んだか判断する。SSAソースコードの最終行まで読んだ場合、検証対象のスマートコントラクトはブロックチェーンの書き込み操作を含まないとして、プログラム検証が終了する。SSAソースコードの最終行に到達していない場合、ステップS11に進む。
(S13) The
(S14)非決定性検出部125は、ステップS11で読んだ行から、ブロックチェーンに書き込む値を格納している変数を抽出する。非決定性検出部125は、抽出した変数を、以降の検索対象の変数として登録する。
(S14) The
(S15)非決定性検出部125は、SSAソースコードから1つ前の行を読む。
(S16)非決定性検出部125は、ステップS15で読んだ行が、検索対象として登録された何れかの変数に値を代入する代入文であるか判断する。登録された変数の代入文である場合はステップS17に進み、それ以外の場合はステップS20に進む。
(S15) The
(S16) The
(S17)非決定性検出部125は、ステップS15で読んだ行が、非決定的操作テーブル132に定義された何れかの非決定的操作を含むか判断する。非決定的操作を含む場合はステップS21に進み、非決定的操作を含まない場合はステップS18に進む。
(S17) The
(S18)非決定性検出部125は、ステップS15で読んだ行が代入値を示す変数を含むか、すなわち、代入文の右辺が他の変数を含むか判断する。代入値を示す変数を含む場合はステップS19に進み、含まない場合はステップS20に進む。
(S18) The
(S19)非決定性検出部125は、ステップS15で読んだ行から代入値を示す変数を抽出する。非決定性検出部125は、抽出した変数を検索対象の変数に追加登録する。
(S20)非決定性検出部125は、ステップS15でSSAソースコードの先頭行まで読んだか判断する。SSAソースコードの先頭行まで読んだ場合、非決定性検出部125は、ブロックチェーンの書き込み操作が非決定的動作ではないと判定する。そして、プログラム検証が終了する。このとき、結果表示部126は、非決定的動作が検出されなかった旨のメッセージをディスプレイ111に表示してもよい。一方、SSAソースコードの先頭行に到達していない場合、ステップS15に進む。
(S19) The
(S20) The
(S21)非決定性検出部125は、ブロックチェーンの書き込み操作が非決定的動作であると判定する。非決定性検出部125は、ステップS15で読んだ行について位置と非決定的操作とカテゴリを判定して検出結果テーブル133を生成する。そして、プログラム検証が終了する。このとき、結果表示部126は、非決定的動作が検出された旨のメッセージをディスプレイ111に表示してもよく、非決定的動作の原因として検出結果テーブル133の情報をディスプレイ111に表示してもよい。
(S21) The
上記では、非決定的動作として、乱数やタイムスタンプなど非決定的操作によって取得した値からブロックチェーンに書き込む値を算出する例について説明した。これに対し、非決定的操作によって取得した値を条件分岐などのフロー制御に用いることで、ブロックチェーンへの書き込み方法が切り替わって非決定的動作となることがある。開発装置100は、このようなフロー制御に起因する非決定的動作についても検出することができる。
In the above, an example in which a value to be written to the block chain is calculated from a value obtained by a non-deterministic operation such as a random number or a time stamp as the non-deterministic operation has been described. On the other hand, by using the value obtained by the non-deterministic operation for flow control such as conditional branching, the method of writing to the block chain may be switched to a non-deterministic operation. The
例えば、非決定性検出部125は、図13のフローチャートにおいて、SSAソースコードから1つ前の行を読み、読んだ行が登録された変数の代入文でない場合、読んだ行が何らかの変数の値に依存する条件分岐文であるか判断するようにする。何らかの変数の値に依存する条件分岐文である場合、非決定性検出部125は、条件分岐文に含まれる変数を検索対象として追加登録する。これにより、ある書き込み操作が実行されるか否かが乱数やタイムスタンプに依存するような非決定的動作を検出することができる。
For example, in the flowchart of FIG. 13, the
図14は、スマートコントラクトとSSAソースコードの他の例を示す図である。
スマートコントラクト54は、関数mainを含む。関数mainは、浮動小数点実数の乱数を変数Aに代入する。関数mainは、変数Aの値と実数「0.5」とを比較する。変数Aの値が0.5より大きい場合、関数mainは、文字列「Success」と真偽値「True」を引数として関数PutStateを呼び出す。一方、変数Aの値が0.5以下である場合、関数mainは、文字列「Success」と真偽値「False」を引数として関数PutStateを呼び出す。ブロックチェーンに書き込まれる真偽値が「True」になるか「False」になるかは乱数に依存する。
FIG. 14 is a diagram showing another example of the smart contract and the SSA source code.
The
開発装置100は、スマートコントラクト54をSSAソースコード73に変換する。SSAソースコード73は、浮動小数点実数の乱数を変数t0に代入し、変数t0の値が0.5より大きいか否かを示す真偽値を変数t1に代入する。SSAソースコード73は、変数t1が真を示しているときは第1番地にジャンプし、変数t1が偽を示しているときは第3番地にジャンプする。第1番地では、SSAソースコード73は、所定の文字列を変数t5に代入し、変数t5を引数に含めて関数PutStateを呼び出し、関数PutStateの戻り値を変数t6に代入する。第3番地では、SSAソースコード73は、所定の文字列を変数t10に代入し、変数t10を引数に含めて関数PutStateを呼び出し、関数PutStateの戻り値を変数t11に代入する。
The
ここで、関数PutStateの引数として使用される変数t5,t10などの変数と、条件分岐文に使用される変数t1とは、SSAソースコード73上で代入関係をもたない。しかし、開発装置100は、条件分岐文に使用される変数t1も追跡することで、制御フローに起因する非決定的動作をSSAソースコード73から検出できる。
Here, variables such as variables t5 and t10 used as arguments of the function PutState and the variable t1 used in the conditional branch statement do not have an assignment relationship on the
第2の実施の形態の情報処理システムによれば、スマートコントラクトがSSAソースコードに変換され、SSAソースコード上で所定の書き込み操作が検出され、SSAソースコードを逆順に走査して書き込み値に影響を与える非決定的操作が検出される。 According to the information processing system of the second embodiment, the smart contract is converted into the SSA source code, a predetermined write operation is detected on the SSA source code, and the SSA source code is scanned in reverse order to affect the write value. Is detected.
これにより、ブロックチェーンに書き込む値が入力情報および書き込み前のブロックチェーンの内容以外の外部状態に依存して変化するという不具合を検出することが可能となる。よって、複数のサーバ装置の間でブロックチェーンの整合性が失われることを防ぐことができる。また、SSAソースコードを利用することで、ブロックチェーンに書き込む値に関連する代入操作を少ない走査回数で高速に検索することができ、スマートコントラクトの非決定的動作の検証を短時間で実行することができる。 This makes it possible to detect a problem that the value to be written in the block chain changes depending on the input information and the external state other than the contents of the block chain before writing. Therefore, it is possible to prevent the blockchain from being lost in consistency among the plurality of server devices. In addition, by using the SSA source code, it is possible to quickly search for the assignment operation related to the value to be written to the block chain with a small number of scans, and to execute the non-deterministic operation verification of the smart contract in a short time. it can.
10 プログラム検証装置
11 記憶部
12 処理部
13,14 ソースコード
15,16 命令
Claims (6)
同一の変数への複数回の値の代入を許容する第1のソースコードを、各変数への値の代入を1回に制限する静的単一代入形式の第2のソースコードに変換し、
前記第2のソースコードから、データベースへの書き込みを示す第1の命令を検索し、前記第1の命令において書き込む値が格納されている変数を検出し、前記第2のソースコードから、前記検出した変数への値の代入を示す第2の命令を検索し、
前記第2の命令における前記検出した変数に代入される値の取得方法に基づいて、前記データベースへの書き込みが、前記第1のソースコードの引数および前記データベースのデータ以外の実行状況に依存する非決定的動作であるか否か判定する、
処理を実行させるプログラム検証プログラム。 On the computer,
Converting a first source code that allows multiple values to be assigned to the same variable into a second single source code in a static single assignment format that limits the assignment of a value to each variable to one time;
The second source code is searched for a first instruction indicating writing to a database, a variable storing a value to be written in the first instruction is detected, and the detection is performed from the second source code. Search for a second instruction indicating the assignment of a value to the assigned variable,
The non-determination that the writing to the database depends on the execution status other than the argument of the first source code and the data of the database based on a method of obtaining a value substituted for the detected variable in the second instruction. Judge whether it is a dynamic operation,
A program verification program that executes processing.
請求項1記載のプログラム検証プログラム。 In the search for the second instruction, an instruction included in the second source code is scanned from the first instruction toward the beginning of the second source code.
The program verification program according to claim 1.
前記第2の命令において前記検出した変数への値の代入の際に参照される他の変数を検出し、前記第2の命令から前記第2のソースコードの先頭に向かって命令を走査して、前記検出した他の変数への値の代入を示す第3の命令を検索し、
前記第3の命令に基づいて、前記検出した変数に代入される値の取得方法を追跡する、
処理を実行させる請求項1記載のプログラム検証プログラム。 The computer further comprises:
In the second instruction, another variable referred to when assigning a value to the detected variable is detected, and the instruction is scanned from the second instruction toward the head of the second source code. Searching for a third instruction indicating the assignment of a value to the other detected variable,
Tracking a method of obtaining a value to be assigned to the detected variable based on the third instruction;
The program verification program according to claim 1, wherein the program is executed.
請求項1記載のプログラム検証プログラム。 In the determination of the non-deterministic operation, when the acquisition method of the value substituted for the detected variable includes at least one of acquisition of a random number, acquisition of a time stamp, and reference to a global variable, the writing to the database is performed by the Determine that the operation is non-deterministic;
The program verification program according to claim 1.
同一の変数への複数回の値の代入を許容する第1のソースコードを、各変数への値の代入を1回に制限する静的単一代入形式の第2のソースコードに変換し、
前記第2のソースコードから、データベースへの書き込みを示す第1の命令を検索し、前記第1の命令において書き込む値が格納されている変数を検出し、前記第2のソースコードから、前記検出した変数への値の代入を示す第2の命令を検索し、
前記第2の命令における前記検出した変数に代入される値の取得方法に基づいて、前記データベースへの書き込みが、前記第1のソースコードの引数および前記データベースのデータ以外の実行状況に依存する非決定的動作であるか否か判定する、
プログラム検証方法。 Computer
Converting a first source code that allows multiple values to be assigned to the same variable into a static single assignment type second source code that limits the assignment of a value to each variable to one time;
The second source code is searched for a first instruction indicating writing to a database, a variable storing a value to be written in the first instruction is detected, and the detection is performed from the second source code. Search for a second instruction indicating the assignment of a value to the assigned variable,
The non-determination that the writing to the database depends on the execution status other than the argument of the first source code and the data of the database based on a method of obtaining a value substituted for the detected variable in the second instruction. Judge whether it is a dynamic operation,
Program verification method.
前記第1のソースコードを、各変数への値の代入を1回に制限する静的単一代入形式の第2のソースコードに変換し、前記第2のソースコードから、データベースへの書き込みを示す第1の命令を検索し、前記第1の命令において書き込む値が格納されている変数を検出し、前記第2のソースコードから、前記検出した変数への値の代入を示す第2の命令を検索し、前記第2の命令における前記検出した変数に代入される値の取得方法に基づいて、前記データベースへの書き込みが、前記第1のソースコードの引数および前記データベースのデータ以外の実行状況に依存する非決定的動作であるか否か判定する処理部と、
を有するプログラム検証装置。 A storage unit that stores a first source code that allows a plurality of values to be substituted for the same variable;
The first source code is converted to a second source code in a static single assignment format that limits assignment of a value to each variable to one time, and writing from the second source code to a database is performed. A second instruction that indicates a substitution of a value into the detected variable from the second source code by searching for a variable in which a value to be written in the first instruction is stored. Based on a method of acquiring a value to be substituted for the detected variable in the second instruction, the execution status of the writing to the database being other than the argument of the first source code and the data of the database. A processing unit that determines whether or not the non-deterministic operation depends on
A program verification device having:
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2018165145A JP7111967B2 (en) | 2018-09-04 | 2018-09-04 | Program verification program, program verification method and program verification device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2018165145A JP7111967B2 (en) | 2018-09-04 | 2018-09-04 | Program verification program, program verification method and program verification device |
Publications (2)
Publication Number | Publication Date |
---|---|
JP2020038482A true JP2020038482A (en) | 2020-03-12 |
JP7111967B2 JP7111967B2 (en) | 2022-08-03 |
Family
ID=69738032
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2018165145A Active JP7111967B2 (en) | 2018-09-04 | 2018-09-04 | Program verification program, program verification method and program verification device |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP7111967B2 (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111562906A (en) * | 2020-04-15 | 2020-08-21 | 杭州云象网络技术有限公司 | Intelligent contract development and verification method based on Noesis logic |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2014089700A (en) * | 2012-09-27 | 2014-05-15 | Tata Consultancy Services Ltd | System and method for discriminating source of run time execution fault |
WO2016121074A1 (en) * | 2015-01-30 | 2016-08-04 | 株式会社日立製作所 | Software inspection apparatus |
-
2018
- 2018-09-04 JP JP2018165145A patent/JP7111967B2/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2014089700A (en) * | 2012-09-27 | 2014-05-15 | Tata Consultancy Services Ltd | System and method for discriminating source of run time execution fault |
WO2016121074A1 (en) * | 2015-01-30 | 2016-08-04 | 株式会社日立製作所 | Software inspection apparatus |
Non-Patent Citations (2)
Title |
---|
樽井 翔 ほか: "脆弱性検出のための値範囲解析", 電子情報通信学会技術研究報告, vol. 107, no. 175, JPN6022025169, 2007, JP, pages 95 - 100, ISSN: 0004803175 * |
立石 孝彰 ほか: "ブロックチェーンアプリケーション開発の実践と今後の課題", ソフトウェアエンジニアリングシンポジウム2017論文集, JPN6022025167, 23 August 2017 (2017-08-23), pages 204 - 211, ISSN: 0004803174 * |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111562906A (en) * | 2020-04-15 | 2020-08-21 | 杭州云象网络技术有限公司 | Intelligent contract development and verification method based on Noesis logic |
CN111562906B (en) * | 2020-04-15 | 2023-06-06 | 杭州云象网络技术有限公司 | Intelligent contract development and verification method based on Noesis logic |
Also Published As
Publication number | Publication date |
---|---|
JP7111967B2 (en) | 2022-08-03 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110059009B (en) | Method and apparatus for testing code files | |
US8935673B1 (en) | System and method for debugging computer program based on execution history | |
US9158514B2 (en) | Method and apparatus for providing change-related information | |
JP2020510925A (en) | Method and apparatus for performing a test using a test case | |
US9588872B2 (en) | Discovery of code paths | |
US9645799B2 (en) | Method and system for model driven development | |
US9785416B2 (en) | Presenting a custom view in an integrated development environment based on a variable selection | |
JP2020119348A (en) | Analysis program, analysis method, and analysis device | |
CN114138281A (en) | Compiling method, device, equipment and medium of software engineering | |
Bouajjani et al. | Verifying robustness of event-driven asynchronous programs against concurrency | |
US10839124B1 (en) | Interactive compilation of software to a hardware language to satisfy formal verification constraints | |
CN116560683A (en) | Software updating method, device, equipment and storage medium | |
US10678864B2 (en) | Analysis model preparing system, programming apparatus, and analysis model preparing method | |
JP7111967B2 (en) | Program verification program, program verification method and program verification device | |
US11334475B1 (en) | Graph based event-driven computing | |
US11119761B2 (en) | Identifying implicit dependencies between code artifacts | |
JP6955162B2 (en) | Analytical equipment, analysis method and analysis program | |
US11256602B2 (en) | Source code file retrieval | |
US9354870B2 (en) | Maintaining integrity of output of code generators | |
US20210173639A1 (en) | System and method for interprocedural analysis | |
US20200134476A1 (en) | Generating code performance hints using source code coverage analytics, inspection, and unstructured programming documents | |
US20220414101A1 (en) | Shifting left database degradation detection | |
US20240045658A1 (en) | Reducing code path permutations | |
JP2020024533A (en) | Analysis support method and analysis support program | |
US9465723B2 (en) | Systems and/or methods for monitoring live software |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
A621 | Written request for application examination |
Free format text: JAPANESE INTERMEDIATE CODE: A621 Effective date: 20210610 |
|
RD02 | Notification of acceptance of power of attorney |
Free format text: JAPANESE INTERMEDIATE CODE: A7422 Effective date: 20210614 |
|
RD04 | Notification of resignation of power of attorney |
Free format text: JAPANESE INTERMEDIATE CODE: A7424 Effective date: 20210614 |
|
A977 | Report on retrieval |
Free format text: JAPANESE INTERMEDIATE CODE: A971007 Effective date: 20220531 |
|
TRDD | Decision of grant or rejection written | ||
A01 | Written decision to grant a patent or to grant a registration (utility model) |
Free format text: JAPANESE INTERMEDIATE CODE: A01 Effective date: 20220621 |
|
A61 | First payment of annual fees (during grant procedure) |
Free format text: JAPANESE INTERMEDIATE CODE: A61 Effective date: 20220704 |
|
R150 | Certificate of patent or registration of utility model |
Ref document number: 7111967 Country of ref document: JP Free format text: JAPANESE INTERMEDIATE CODE: R150 |