KR102187293B1 - Apparatus and method for analyzing smart contracts being capable of saving GAS - Google Patents

Apparatus and method for analyzing smart contracts being capable of saving GAS Download PDF

Info

Publication number
KR102187293B1
KR102187293B1 KR1020180134285A KR20180134285A KR102187293B1 KR 102187293 B1 KR102187293 B1 KR 102187293B1 KR 1020180134285 A KR1020180134285 A KR 1020180134285A KR 20180134285 A KR20180134285 A KR 20180134285A KR 102187293 B1 KR102187293 B1 KR 102187293B1
Authority
KR
South Korea
Prior art keywords
pattern
smart contract
statement
code
gas
Prior art date
Application number
KR1020180134285A
Other languages
Korean (ko)
Other versions
KR20200051218A (en
Inventor
정다은
박수용
Original Assignee
서강대학교 산학협력단
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by 서강대학교 산학협력단 filed Critical 서강대학교 산학협력단
Priority to KR1020180134285A priority Critical patent/KR102187293B1/en
Publication of KR20200051218A publication Critical patent/KR20200051218A/en
Application granted granted Critical
Publication of KR102187293B1 publication Critical patent/KR102187293B1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/30Payment architectures, schemes or protocols characterised by the use of specific devices or networks
    • G06Q20/36Payment architectures, schemes or protocols characterised by the use of specific devices or networks using electronic wallets or electronic money safes
    • G06Q20/367Payment architectures, schemes or protocols characterised by the use of specific devices or networks using electronic wallets or electronic money safes involving electronic purses or money safes
    • G06Q20/3678Payment architectures, schemes or protocols characterised by the use of specific devices or networks using electronic wallets or electronic money safes involving electronic purses or money safes e-cash details, e.g. blinded, divisible or detecting double spending
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q10/00Administration; Management
    • G06Q10/04Forecasting or optimisation specially adapted for administrative or management purposes, e.g. linear programming or "cutting stock problem"
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/06Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols the encryption apparatus using shift registers or memories for block-wise or stream coding, e.g. DES systems or RC4; Hash functions; Pseudorandom sequence generators
    • H04L9/0643Hash functions, e.g. MD5, SHA, HMAC or f9 MAC
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L2209/00Additional information or applications relating to cryptographic mechanisms or cryptographic arrangements for secret or secure communication H04L9/00
    • H04L2209/56Financial cryptography, e.g. electronic payment or e-cash

Abstract

본 발명은 GAS 절감이 가능한 스마트 컨트랙트 분석 장치 및 방법에 관한 것이다. 상기 블록체인 네트워크의 스마트 컨트랙트 분석 장치에 의한 스마트 컨트랙트 분석 방법은, (a) 스마트 컨트랙트의 코드를 파싱하는 단계; (b) 상기 파싱된 스마트 컨트랙트 코드로부터 GAS 소모가 많은 사전 설정된 패턴을 검출하는 단계; (c) 상기 (b)단계에서 사전 설정된 패턴이 검출된 결과를 출력하는 단계; 를 구비하고, 상기 사전 설정된 패턴은 분리형 증감문 패턴 또는 AND 연산자 다중 조건문 패턴이다. 본 발명에 따른 스마트 컨트랙트 분석 장치는, 스마트 컨트랙트 코드에서 GAS 소모가 많은 분리형 증감문 패턴 또는 AND 연산자 다중 조건문 패턴을 검출하여 GAS 소모가 작은 패턴으로 개선하도록 함으로써, GAS 소모를 절약할 수 있도록 한다. The present invention relates to a smart contract analysis apparatus and method capable of reducing GAS. The smart contract analysis method by the smart contract analysis device of the blockchain network includes the steps of: (a) parsing the code of the smart contract; (b) detecting a preset pattern that consumes a lot of GAS from the parsed smart contract code; (c) outputting a result of detecting a preset pattern in step (b); And the preset pattern is a separate augmented sentence pattern or an AND operator multiple conditional sentence pattern. The smart contract analysis apparatus according to the present invention detects a separate augmented statement pattern or an AND operator multiple conditional statement pattern that consumes a lot of GAS in a smart contract code and improves it to a pattern with a small GAS consumption, thereby saving GAS consumption.

Figure 112018109312841-pat00002
Figure 112018109312841-pat00002

Description

GAS 절감이 가능한 스마트 컨트랙트 분석 장치 및 방법{Apparatus and method for analyzing smart contracts being capable of saving GAS} Apparatus and method for analyzing smart contracts being capable of saving GAS}

본 발명은 스마트 컨트랙트 분석 장치에 관한 것으로서, 더욱 구체적으로는, 스마트 컨트랙트 코드를 분석하여 GAS를 낭비시키는 패턴들을 검출하고 이를 출력함으로써, 이더리움의 거래 수수료인 GAS를 절약할 수 있도록 하는 스마트 컨트랙트 분석 장치 및 방법에 관한 것이다. The present invention relates to a smart contract analysis device, and more specifically, a smart contract analysis that analyzes a smart contract code to detect and output patterns that waste GAS, thereby saving GAS, which is a transaction fee of Ethereum. It relates to an apparatus and method.

블록체인(Blockchain) 기술은 P2P 네트워크를 이루는 노드들이 네트워크에 전송하는 트랜잭션들을 블록에 저장하고, 각 노드들에 전술한 블록들을 체인 형태로 저장하는 기술이다. Blockchain technology is a technology that stores transactions that nodes forming a P2P network transmit to the network in blocks, and stores the aforementioned blocks in each node in a chain form.

2013년 러시아 출신 캐나다 개발자인 비탈릭 부테린이 "차세대 스마트 컨트랙트 & 분산 응용 애플리케이션 플랫폼"이라는 제목으로 이더리움 백서를 발간했고, 차세대 스마트 컨트랙트는 이더리움의 가장 중요한 특징 중 하나이다. In 2013, Russian developer Vitalik Buterin published an Ethereum white paper titled "Next Generation Smart Contract & Distributed Application Platform", and next-generation smart contracts are one of the most important features of Ethereum.

스마트 컨트랙트(Smart Contract)는 코드에 적힌 계약 조건이 만족되면 즉시 계약이 성사되도록 구성되어 있으며, 스크립트 언어인 솔리디티(Solidity)로 작성 가능하다. 이와 같이 솔리디티로 작성된 스마트 컨트랙트 코드가 컴파일되어 바이트 코드가 생성되며, 이 바이트 코드는 이더리움 클라이언트를 통해 블록에 기록된다. 블록체인 네트워크에 참여하는 노드들이 해당 스마트 컨트랙트를 이더리움 가상 머신(Ethereum Virtual Machine; 'EVM')으로 실행시킬 수 있게 된다. Smart Contracts are configured so that the contract is concluded immediately when the contract conditions written in the code are satisfied, and can be written in Solidity, a script language. In this way, the smart contract code written in Solidity is compiled to generate byte code, and this byte code is recorded in the block through the Ethereum client. Nodes participating in the blockchain network will be able to run the smart contract as an Ethereum Virtual Machine (EVM).

블록에 기록된 스마트 컨트랙트를 EVM으로 실행할 때 GAS를 지불해야 된다. GAS는 이더리움에서 스마트 컨트랙트를 실행시키는 대가로서 지불되는 네트워크 수수료이자 연산량의 대가이기도 하다. 대부분의 블록체인은 데이터를 저장하고 동일한 연산을 중복되게 실시하므로 사용할 수 있는 자원에 한계가 있다. 이더리움은 계약의 실행을 위한 연산력이 한정된 자원이므로 이를 사용하는 댓가로서 가스(GAS)를 지불해야 한다. When executing the smart contract recorded in the block with EVM, GAS must be paid. GAS is a network fee paid in exchange for executing a smart contract on Ethereum and also a price for the amount of computation. Since most blockchains store data and perform the same operation redundantly, there is a limit to the available resources. Ethereum is a resource with limited computational power for contract execution, so gas (GAS) must be paid as a price for using it.

그런데, 스마트 컨트랙트 코드에 분리형 증감문과 AND 연산자 다중 조건문과 같이 GAS를 많이 소모하는 패턴들이 포함된 경우에는 GAS를 낭비하게 되는 문제가 발생하게 된다. However, when the smart contract code includes patterns that consume a lot of GAS, such as a separate incremental statement and an AND operator multiple conditional statement, a problem of wasting GAS occurs.

한국등록특허공보 제 10-1849917호Korean Registered Patent Publication No. 10-1849917

전술한 문제점을 해결하기 위한 본 발명의 목적은 스마트 컨트랙트 코드를 분석하여 분리형 증감문과 ADN 연산자 다중 조건문과 같은 패턴이 포함되어 있는지 여부를 판단하고 보고함으로써, GAS를 절약시킬 수 있도록 하는 스마트 컨트랙트 분석 장치 및 방법을 제공하는 것이다. An object of the present invention for solving the above-described problem is a smart contract analysis device that analyzes a smart contract code to determine and report whether a pattern such as a separate increase/decrease statement and an ADN operator multiple conditional statement are included, thereby saving GAS. And to provide a method.

전술한 기술적 과제를 달성하기 위한 본 발명의 제1 특징에 따른 스마트 컨트랙트 분석 장치는, 스마트 컨트랙트의 코드를 파싱하는 코드 파싱부; 상기 파싱된 스마트 컨트랙트 코드로부터 GAS 소모가 많은 사전 설정된 패턴들을 검출하는 패턴 검출부; 및 상기 패턴 검출부에 의한 검출 결과를 출력하는 패턴 보고서 출력부;를 구비하고, 상기 사전 설정된 패턴은 분리형 증감문 패턴 또는 AND 연산자 다중 조건문 패턴을 포함한다. A smart contract analysis apparatus according to a first aspect of the present invention for achieving the above-described technical problem includes: a code parsing unit for parsing a code of a smart contract; A pattern detection unit detecting preset patterns that consume a lot of GAS from the parsed smart contract code; And a pattern report output unit for outputting a detection result by the pattern detection unit, wherein the preset pattern includes a separate augmented sentence pattern or an AND operator multiple conditional sentence pattern.

전술한 제1 특징에 따른 스마트 컨트랙트 분석 장치에 있어서, 상기 패턴 검출부는, 상기 파싱된 스마트 컨트랙트 코드에 'for 구문' 이 있는지 여부를 판단하고, 'for 구문'에 증감문이 있는지 여부를 판단하고, 증감되는 루프(loop) 변수가 'for 구문'의 Body에 사용되었는지 여부를 판단하여, 상기 스마트 컨트랙트 코드에서 분리형 증감문 패턴을 검출하는 것이 바람직하다. In the smart contract analysis apparatus according to the above-described first feature, the pattern detection unit determines whether there is a'for syntax' in the parsed smart contract code, and determines whether there is an increase or decrease in the'for syntax', and , It is preferable to determine whether a loop variable to be increased or decreased is used in the body of the'for statement', and to detect a separate type increase/decrease pattern in the smart contract code.

전술한 제1 특징에 따른 스마트 컨트랙트 분석 장치에 있어서, 상기 패턴 검출부는, 상기 파싱된 스마트 컨트랙트 코드에 조건문이 있는지 여부를 판단하고, 상기 조건문이 다중 조건문인지 여부를 판단하고, 다중 조건문이 AND로만 이루어져있는지 여부를 판단하여, 상기 스마트 컨트랙트 코드에서 AND 연산자 다중 조건문 패턴을 검출하는 것이 바람직하다. In the smart contract analysis apparatus according to the first feature described above, the pattern detection unit determines whether a conditional statement exists in the parsed smart contract code, determines whether the conditional statement is a multiple conditional statement, and the multiple conditional statement is only an AND. It is preferable to determine whether or not to detect the AND operator multiple conditional pattern in the smart contract code.

전술한 제1 특징에 따른 스마트 컨트랙트 분석 장치는, 상기 패턴 검출부에 의해 GAS 소모가 많은 사전 설정된 패턴이 검출된 경우, 검출된 패턴과 동일한 기능을 수행하면서도 GAS 소모가 작은 개선 패턴을 출력하는 개선 패턴 출력부;를 더 구비하는 것이 바람직하다. The smart contract analysis apparatus according to the above-described first feature, when a preset pattern with high GAS consumption is detected by the pattern detection unit, performs the same function as the detected pattern and outputs an improved pattern with low GAS consumption. It is preferable to further include an output unit.

본 발명의 제2 특징에 따른 GAS 절감이 가능한 스마트 컨트랙트 분석 방법은, 블록체인 네트워크의 스마트 컨트랙트 분석 장치에 의한 스마트 컨트랙트 분석 방법으로서, (a) 스마트 컨트랙트의 코드를 파싱하는 단계; (b) 상기 파싱된 스마트 컨트랙트 코드로부터 GAS 소모가 많은 사전 설정된 패턴을 검출하는 단계; (c) 상기 (b)단계에서 사전 설정된 패턴이 검출된 결과를 출력하는 단계; 를 구비하고, 상기 사전 설정된 패턴은 분리형 증감문 패턴 또는 AND 연산자 다중 조건문 패턴이다. A smart contract analysis method capable of reducing GAS according to a second aspect of the present invention is a smart contract analysis method using a smart contract analysis device of a blockchain network, comprising the steps of: (a) parsing the code of the smart contract; (b) detecting a preset pattern that consumes a lot of GAS from the parsed smart contract code; (c) outputting a result of detecting a preset pattern in step (b); And the preset pattern is a separate augmented sentence pattern or an AND operator multiple conditional sentence pattern.

전술한 제2 특징에 따른 GAS 절감이 가능한 스마트 컨트랙트 분석 방법에 있어서, 상기 (b) 단계는, 상기 파싱된 스마트 컨트랙트 코드에 'for 구문' 이 있는지 여부를 판단하고, 'for 구문'에 증감문이 있는지 여부를 판단하고, 증감되는 루프(loop) 변수가 'for 구문'의 Body에 사용되었는지 여부를 판단하여, 상기 스마트 컨트랙트 코드에서 분리형 증감문 패턴을 검출하는 것이 바람직하다. In the smart contract analysis method capable of reducing GAS according to the above-described second feature, the step (b) determines whether there is a'for statement' in the parsed smart contract code, and increases or decreases the'for statement'. It is preferable to determine whether there is a presence or not, determine whether a loop variable to be increased or decreased is used in the body of the'for statement', and detect a separate type increase/decrease pattern in the smart contract code.

전술한 제2 특징에 따른 GAS 절감이 가능한 스마트 컨트랙트 분석 방법에 있어서, 상기 (c) 단계는, 상기 파싱된 스마트 컨트랙트 코드에 조건문이 있는지 여부를 판단하고, 상기 조건문이 다중 조건문인지 여부를 판단하고, 다중 조건문이 AND로만 이루어져있는지 여부를 판단하여, 상기 스마트 컨트랙트 코드에서 AND 연산자 다중 조건문 패턴을 검출하는 것이 바람직하다. In the smart contract analysis method capable of reducing GAS according to the above-described second feature, the step (c) includes determining whether there is a conditional statement in the parsed smart contract code, determining whether the conditional statement is a multiple conditional statement, and , It is preferable to determine whether the multiple conditional statements consist only of AND, and to detect the AND operator multiple conditional pattern pattern in the smart contract code.

전술한 제2 특징에 따른 GAS 절감이 가능한 스마트 컨트랙트 분석 방법은, (e) GAS 소모가 많은 사전 설정된 패턴이 검출된 경우, 검출된 패턴과 동일한 기능을 수행하면서도 GAS 소모가 작은 개선 패턴을 출력하는 단계;를 더 구비하는 것이 바람직하다. The smart contract analysis method capable of reducing GAS according to the above-described second feature includes: (e) When a preset pattern with high GAS consumption is detected, it performs the same function as the detected pattern and outputs an improved pattern with low GAS consumption. It is preferable to further include a step.

본 발명에 따른 스마트 컨트랙트 분석 장치는, 스마트 컨트랙트 코드에서 GAS 소모가 많은 분리형 증감문 패턴 또는 AND 연산자 다중 조건문 패턴을 검출하고 이를 보고하게 된다. 한편, GAS 소모가 많은 패턴이 검출되었음을 보고함과 동시에, GAS 소모가 작은 개선된 패턴을 알려줌으로써, 사용자로 하여금 GAS 소모가 작은 패턴으로 개선할 수 있도록 하여, 스마트 컨트랙트의 실행에 따른 GAS 소모를 절약할 수 있도록 한다. The smart contract analysis apparatus according to the present invention detects and reports a separate augmented sentence pattern or an AND operator multiple conditional sentence pattern that consumes a lot of GAS in a smart contract code. On the other hand, by reporting that a pattern with a large amount of GAS consumption is detected, and by notifying an improved pattern with a small amount of GAS consumption, the user can improve the pattern with a small GAS consumption, thereby reducing GAS consumption by executing a smart contract. Make it possible to save.

도 1은 본 발명의 바람직한 실시예에 따른 스마트 컨트랙트 분석 장치를 개략적으로 도시한 블록도이다.
도 2는 본 발명의 바람직한 실시예에 따른 스마트 컨트랙트 분석 장치에 있어서, 스마트 컨트랙트 분석 과정을 전체적으로 도시한 흐름도이다.
도 3은 본 발명의 바람직한 실시예에 따른 스마트 컨트랙트 분석 장치에 있어서, GAS 소모가 많은 제1 패턴인 분리형 증감문 패턴에 대한 예제 코드이다.
도 4는 본 발명의 바람직한 실시예에 따른 스마트 컨트랙트 분석 장치에 있어서, GAS 소모가 많은 제2 패턴인 AND 연산자 다중 조건문 패턴에 대한 예제 코드이다.
도 5는 본 발명의 바람직한 실시예에 따른 스마트 컨트랙트 분석 장치에 있어서, 도 3의 제1 패턴에 대해 제시되는 개선 코드이다.
도 6은 본 발명의 바람직한 실시예에 따른 스마트 컨트랙트 분석 장치에 있어서, 도 4의 제2 패턴에 대해 제시되는 개선 코드이다.
1 is a block diagram schematically showing a smart contract analysis apparatus according to a preferred embodiment of the present invention.
2 is a flowchart showing an overall smart contract analysis process in the smart contract analysis apparatus according to a preferred embodiment of the present invention.
3 is an example code for a separate type increase/decrease door pattern, which is a first pattern that consumes a lot of GAS, in the smart contract analysis apparatus according to a preferred embodiment of the present invention.
4 is an example code for an AND operator multiple conditional pattern, a second pattern that consumes a lot of GAS in the smart contract analysis apparatus according to a preferred embodiment of the present invention.
5 is an improvement code presented for the first pattern of FIG. 3 in the smart contract analysis apparatus according to a preferred embodiment of the present invention.
6 is an improvement code presented for the second pattern of FIG. 4 in the smart contract analysis apparatus according to a preferred embodiment of the present invention.

본 발명에 따른 스마트 컨트랙트 분석 장치는, 스마트 컨트랙트 코드에서 GAS 소모가 많은 분리형 증감문 패턴 또는 AND 연산자 다중 조건문 패턴을 검출하고 이를 보고하여 사용자로 하여금 GAS 소모가 작은 패턴으로 개선하도록 함으로써, GAS 소모를 절약할 수 있도록 한다. The smart contract analysis apparatus according to the present invention detects and reports a separate increase/decrease pattern pattern or AND operator multiple conditional pattern pattern that consumes a lot of GAS in a smart contract code, and reports this to allow the user to improve the GAS consumption pattern to reduce GAS consumption. Make it possible to save.

이하, 첨부된 도면을 참조하여 본 발명의 바람직한 실시예에 따른 스마트 컨트랙트 분석 장치 및 방법에 대하여 구체적으로 설명한다. Hereinafter, an apparatus and method for analyzing a smart contract according to a preferred embodiment of the present invention will be described in detail with reference to the accompanying drawings.

도 1은 본 발명의 바람직한 실시예에 따른 스마트 컨트랙트 분석 장치를 개략적으로 도시한 블록도이며, 도 2는 본 발명의 바람직한 실시예에 따른 스마트 컨트랙트 분석 장치에 있어서, 스마트 컨트랙트 분석 과정을 전체적으로 도시한 흐름도이다. 1 is a block diagram schematically showing a smart contract analysis apparatus according to a preferred embodiment of the present invention, and FIG. 2 is a general diagram illustrating a smart contract analysis process in a smart contract analysis apparatus according to a preferred embodiment of the present invention. It is a flow chart.

도 1 및 도 2를 참조하면, 본 발명의 바람직한 실시예에 따른 스마트 컨트랙트 분석 장치(1)는 코드 파싱부(100), 패턴 검출부(110), 패턴 보고서 출력부(120) 및 개선 패턴 출력부(130)을 구비한다. 1 and 2, the smart contract analysis apparatus 1 according to a preferred embodiment of the present invention includes a code parsing unit 100, a pattern detection unit 110, a pattern report output unit 120, and an improved pattern output unit. It has (130).

상기 코드 파싱부(100)는, 스마트 컨트랙트의 코드를 파싱(parsing)하여 제공한다. The code parsing unit 100 parses and provides a code of a smart contract.

상기 패턴 검출부(110)는, 상기 파싱된 스마트 컨트랙트 코드로부터 GAS 소모가 많은 사전 설정된 패턴들을 검출한다. 상기 사전 설정된 패턴은 분리형 증감문 패턴 또는 AND 연산자 다중 조건문 패턴인 것이 바람직하다. The pattern detection unit 110 detects preset patterns that consume a lot of GAS from the parsed smart contract code. It is preferable that the preset pattern is a separate augmented sentence pattern or an AND operator multiple conditional sentence pattern.

도 3은 본 발명의 바람직한 실시예에 따른 스마트 컨트랙트 분석 장치에 있어서, GAS 소모가 많은 제1 패턴인 분리형 증감문 패턴에 대한 예제 코드이며, 도 4는 GAS 소모가 많은 제2 패턴인 AND 연산자 다중 조건문 패턴에 대한 예제 코드이다. 3 is an example code for a separate incremental gate pattern, which is a first pattern that consumes a lot of GAS, in a smart contract analysis device according to a preferred embodiment of the present invention, and FIG. 4 is an AND operator multiplexing a second pattern that consumes a lot of GAS. This is an example code for a conditional pattern.

상기 패턴 보고서 출력부(120)는, 상기 패턴 검출부에 의한 검출 결과를 출력하여 제공한다. 상기 개선 패턴 출력부(130)는, 상기 패턴 검출부에 의해 GAS 소모가 많은 사전 설정된 패턴이 검출된 경우, 검출된 패턴과 동일한 기능을 수행하면서도 GAS 소모가 작은 개선 패턴을 출력한다. The pattern report output unit 120 outputs and provides a detection result by the pattern detection unit. When a preset pattern that consumes a lot of GAS is detected by the pattern detection unit, the improved pattern output unit 130 outputs an improved pattern having small GAS consumption while performing the same function as the detected pattern.

도 2를 참조하여 상기 패턴 검출부의 동작에 대하여 보다 구체적으로 설명한다. The operation of the pattern detection unit will be described in more detail with reference to FIG. 2.

상기 패턴 검출부는, 스마트 컨트랙트 코드에서 제1 패턴인 분리형 증감문 패턴을 검출하기 위하여, 상기 파싱된 스마트 컨트랙트 코드에 'for 구문' 이 있는지 여부를 판단하고, 'for 구문'에 증감문이 있는지 여부를 판단하고, 증감되는 루프(loop) 변수가 'for 구문'의 Body에 사용되었는지 여부를 판단한다. The pattern detection unit determines whether there is a'for statement' in the parsed smart contract code, and whether there is an increase or decrease statement in the'for statement' in order to detect a separate augmented gate pattern that is a first pattern in the smart contract code. Is determined, and it is determined whether the increasing or decreasing loop variable is used in the body of the'for statement'.

이러한 과정을 거쳐, 코드내에 증감문이 있는 'for 구문'이 있고, 증감되는 루프 변수가 'for 구문'의 Body에 사용된 경우, 상기 스마트 컨트랙트 코드에서 제1 패턴인 분리형 증감문 패턴을 검출한다. Through this process, if there is a'for statement' with an increase/decrease statement in the code, and the loop variable to be increased or decreased is used in the body of the'for statement', the first pattern, a separate type increase/decrease statement pattern, is detected in the smart contract code. .

또한, 상기 패턴 검출부는, 스마트 컨트랙트 코드에서 제2 패턴인 AND 연산자 다중 조건문 패턴을 검출하기 위하여, 상기 파싱된 스마트 컨트랙트 코드에 조건문이 있는지 여부를 판단하고, 상기 조건문이 다중 조건문인지 여부를 판단하고, 다중 조건문이 AND로만 이루어져있는지 여부를 판단한다. In addition, the pattern detection unit determines whether there is a conditional statement in the parsed smart contract code, and determines whether the conditional statement is a multiple conditional statement in order to detect the AND operator multiple conditional statement pattern, which is a second pattern in the smart contract code. , Determines whether multiple conditional statements consist only of AND.

이러한 과정을 거쳐, 코드 내에 다중 조건문이 있고 다중 조건문이 AND 만으로 이루어진 경우, 상기 스마트 컨트랙트 코드에서 제2 패턴인 AND 연산자 다중 조건문 패턴을 검출하게 된다. Through this process, when there are multiple conditional statements in the code and the multiple conditional statements consist of only AND, the second pattern of the AND operator multiple conditional statement pattern is detected in the smart contract code.

상기 개선 패턴 출력부는, 상기 패턴 검출부에 의해 GAS 소모가 많은 사전 설정된 패턴들이 검출된 경우, 검출된 패턴과 동일한 기능을 수행하면서도 GAS 소모가 작은 개선 패턴을 출력하게 된다. When preset patterns that consume a lot of GAS are detected by the pattern detection unit, the improved pattern output unit outputs an improved pattern having small GAS consumption while performing the same function as the detected pattern.

도 5는 본 발명의 바람직한 실시예에 따른 스마트 컨트랙트 분석 장치에 있어서, 도 3의 제1 패턴에 대해 제시되는 개선 코드이다. 도 5를 참조하면, 상기 제1 패턴에 대한 개선 패턴은, 제1 패턴에 있는 증감문을 Body에 있는 루프 변수에 one-line 형식으로 병합하도록 함으로써, GAS를 절약할 수 있게 된다. 5 is an improvement code presented for the first pattern of FIG. 3 in the smart contract analysis apparatus according to a preferred embodiment of the present invention. Referring to FIG. 5, in the improvement pattern for the first pattern, GAS can be saved by merging the increase/decrease statement in the first pattern into a loop variable in the body in a one-line format.

도 6은 본 발명의 바람직한 실시예에 따른 스마트 컨트랙트 분석 장치에 있어서, 도 4의 제2 패턴에 대해 제시되는 개선 코드이다. 도 6을 참조하면, 상기 제2 패턴에 대한 개선 패턴은, 제2 패턴의 다중 조건문을 (AND 연산자의 수)+1 개의 조건문으로 분리하여 Depth를 만듦으로써, GAS를 절약할 수 있게 된다. 6 is an improvement code presented for the second pattern of FIG. 4 in the smart contract analysis apparatus according to a preferred embodiment of the present invention. Referring to FIG. 6, in the improvement pattern for the second pattern, GAS can be saved by separating multiple conditional statements of the second pattern into (number of AND operators) + 1 conditional statements to create a depth.

이상에서 본 발명에 대하여 그 바람직한 실시예를 중심으로 설명하였으나, 이는 단지 예시일 뿐 본 발명을 한정하는 것이 아니며, 본 발명이 속하는 분야의 통상의 지식을 가진 자라면 본 발명의 본질적인 특성을 벗어나지 않는 범위에서 이상에 예시되지 않은 여러 가지의 변형과 응용이 가능함을 알 수 있을 것이다. 그리고, 이러한 변형과 응용에 관계된 차이점들은 첨부된 청구 범위에서 규정하는 본 발명의 범위에 포함되는 것으로 해석되어야 할 것이다. In the above, the present invention has been described with reference to its preferred embodiments, but these are only examples and do not limit the present invention, and those of ordinary skill in the field to which the present invention pertains will not depart from the essential characteristics of the present invention. It will be appreciated that various modifications and applications not illustrated above are possible in the range. And, differences related to these modifications and applications should be construed as being included in the scope of the present invention defined in the appended claims.

1 : 스마트 컨트랙트 분석 장치
100 : 코드 파싱부
110 : 패턴 검출부
120 : 패턴 보고서 출력부
130 : 개선 패턴 출력부
1: Smart contract analysis device
100: code parsing unit
110: pattern detection unit
120: pattern report output unit
130: improvement pattern output unit

Claims (8)

스마트 컨트랙트의 코드를 파싱하는 코드 파싱부;
상기 파싱된 스마트 컨트랙트 코드로부터 GAS 소모가 많은 사전 설정된 패턴들을 검출하는 패턴 검출부;
상기 패턴 검출부에 의한 검출 결과를 출력하는 패턴 보고서 출력부; 및
상기 패턴 검출부에 의해 GAS 소모가 많은 사전 설정된 패턴이 검출된 경우, 검출된 패턴과 동일한 기능을 수행하면서도 GAS 소모가 작은 개선 패턴을 출력하는 개선 패턴 출력부;
를 구비하고, 상기 사전 설정된 패턴은 분리형 증감문 패턴 또는 AND 연산자 다중 조건문 패턴인 것을 특징으로 하는 GAS 절감이 가능한 스마트 컨트랙트 분석 장치.
A code parsing unit that parses the code of the smart contract;
A pattern detection unit detecting preset patterns that consume a lot of GAS from the parsed smart contract code;
A pattern report output unit that outputs a detection result by the pattern detection unit; And
An improved pattern output unit that performs the same function as the detected pattern and outputs a small improvement pattern while performing the same function as the detected pattern when a preset pattern that consumes a lot of GAS is detected by the pattern detection unit;
A smart contract analysis device capable of reducing GAS, wherein the preset pattern is a separate incremental pattern or an AND operator multiple conditional pattern.
제1항에 있어서, 상기 패턴 검출부는,
상기 파싱된 스마트 컨트랙트 코드에 'for 구문' 이 있는지 여부를 판단하고, 'for 구문'에 증감문이 있는지 여부를 판단하고, 증감되는 루프(loop) 변수가 'for 구문'의 Body에 사용되었는지 여부를 판단하여,
상기 스마트 컨트랙트 코드에서 분리형 증감문 패턴을 검출하는 것을 특징으로 하는 GAS 절감이 가능한 스마트 컨트랙트 분석 장치.
The method of claim 1, wherein the pattern detection unit,
It determines whether there is a'for statement' in the parsed smart contract code, determines whether there is an increase/decrease statement in the'for statement', and whether the increasing or decreasing loop variable is used in the body of the'for statement' By judging,
A smart contract analysis device capable of reducing GAS, characterized in that detecting a separate increase/decrease door pattern in the smart contract code.
제1항에 있어서, 상기 패턴 검출부는
상기 파싱된 스마트 컨트랙트 코드에 조건문이 있는지 여부를 판단하고, 상기 조건문이 다중 조건문인지 여부를 판단하고, 다중 조건문이 AND로만 이루어져있는지 여부를 판단하여,
상기 스마트 컨트랙트 코드에서 AND 연산자 다중 조건문 패턴을 검출하는 것을 특징으로 하는 GAS 절감이 가능한 스마트 컨트랙트 분석 장치.
The method of claim 1, wherein the pattern detection unit
It is determined whether there is a conditional statement in the parsed smart contract code, it is determined whether the conditional statement is a multiple conditional statement, and it is determined whether the multiple conditional statement is composed of only AND,
A smart contract analysis device capable of reducing GAS, characterized in that detecting an AND operator multiple conditional pattern in the smart contract code.
삭제delete 블록체인 네트워크의 스마트 컨트랙트 분석 장치에 의한 스마트 컨트랙트 분석 방법에 있어서,
(a) 스마트 컨트랙트의 코드를 파싱하는 단계;
(b) 상기 파싱된 스마트 컨트랙트 코드로부터 GAS 소모가 많은 사전 설정된 패턴을 검출하는 단계;
(c) 상기 (b)단계에서 사전 설정된 패턴이 검출된 결과를 출력하는 단계; 및
(d) GAS 소모가 많은 사전 설정된 패턴이 검출된 경우, 검출된 패턴과 동일한 기능을 수행하면서도 GAS 소모가 작은 개선 패턴을 출력하는 단계;
를 구비하고, 상기 사전 설정된 패턴은 분리형 증감문 패턴 또는 AND 연산자 다중 조건문 패턴인 것을 특징으로 하는 GAS 절감이 가능한 스마트 컨트랙트 분석 방법.
In the smart contract analysis method using a smart contract analysis device of a blockchain network,
(a) parsing the code of the smart contract;
(b) detecting a preset pattern that consumes a lot of GAS from the parsed smart contract code;
(c) outputting a result of detecting a preset pattern in step (b); And
(d) when a preset pattern with high GAS consumption is detected, outputting an improved pattern with small GAS consumption while performing the same function as the detected pattern;
And wherein the preset pattern is a separate incremental pattern or an AND operator multiple conditional pattern.
제5항에 있어서, 상기 (b) 단계는,
상기 파싱된 스마트 컨트랙트 코드에 'for 구문' 이 있는지 여부를 판단하고, 'for 구문'에 증감문이 있는지 여부를 판단하고, 증감되는 루프(loop) 변수가 'for 구문'의 Body에 사용되었는지 여부를 판단하여,
상기 스마트 컨트랙트 코드에서 분리형 증감문 패턴을 검출하는 것을 특징으로 하는 GAS 절감이 가능한 스마트 컨트랙트 분석 방법.
The method of claim 5, wherein step (b),
It determines whether there is a'for statement' in the parsed smart contract code, determines whether there is an increase/decrease statement in the'for statement', and whether the increasing or decreasing loop variable is used in the body of the'for statement' By judging,
A smart contract analysis method capable of reducing GAS, characterized in that detecting a separate increase/decrease door pattern in the smart contract code.
제5항에 있어서, 상기 (b) 단계는,
상기 파싱된 스마트 컨트랙트 코드에 조건문이 있는지 여부를 판단하고, 상기 조건문이 다중 조건문인지 여부를 판단하고, 다중 조건문이 AND로만 이루어져있는지 여부를 판단하여,
상기 스마트 컨트랙트 코드에서 AND 연산자 다중 조건문 패턴을 검출하는 것을 특징으로 하는 GAS 절감이 가능한 스마트 컨트랙트 분석 방법.

The method of claim 5, wherein step (b),
It is determined whether there is a conditional statement in the parsed smart contract code, it is determined whether the conditional statement is a multiple conditional statement, and it is determined whether the multiple conditional statement is composed of only AND,
A smart contract analysis method capable of reducing GAS, characterized in that detecting an AND operator multiple conditional pattern in the smart contract code.

삭제delete
KR1020180134285A 2018-11-05 2018-11-05 Apparatus and method for analyzing smart contracts being capable of saving GAS KR102187293B1 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
KR1020180134285A KR102187293B1 (en) 2018-11-05 2018-11-05 Apparatus and method for analyzing smart contracts being capable of saving GAS

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
KR1020180134285A KR102187293B1 (en) 2018-11-05 2018-11-05 Apparatus and method for analyzing smart contracts being capable of saving GAS

Publications (2)

Publication Number Publication Date
KR20200051218A KR20200051218A (en) 2020-05-13
KR102187293B1 true KR102187293B1 (en) 2020-12-04

Family

ID=70729813

Family Applications (1)

Application Number Title Priority Date Filing Date
KR1020180134285A KR102187293B1 (en) 2018-11-05 2018-11-05 Apparatus and method for analyzing smart contracts being capable of saving GAS

Country Status (1)

Country Link
KR (1) KR102187293B1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112035350B (en) * 2020-08-27 2021-09-28 腾讯科技(深圳)有限公司 Test method and device for block chain system and computer equipment

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR100964582B1 (en) * 2008-08-20 2010-06-21 주식회사 컴퍼니원헌드레드 System for improement of performance of script language
WO2016000158A1 (en) * 2014-06-30 2016-01-07 Microsoft Technology Licensing, Llc Code recommendation
KR101761732B1 (en) * 2015-10-13 2017-07-26 재단법인대구경북과학기술원 Apparatus and method for detecting error of application source code
KR101849917B1 (en) 2016-10-13 2018-05-31 주식회사 코인플러그 Method for providing certificate service based on smart contract and server using the same

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
‘Under-Optimized Smart Contracts Devour Your Money’, 워드프레스(2017.04.12. 게재)*

Also Published As

Publication number Publication date
KR20200051218A (en) 2020-05-13

Similar Documents

Publication Publication Date Title
US8510237B2 (en) Machine learning method to identify independent tasks for parallel layout in web browsers
US10635435B2 (en) Collection of API documentations
US8296747B2 (en) Method for optimizing character string output processing
US10095602B2 (en) Automated code analyzer
US10269087B2 (en) Language translation using preprocessor macros
AU2017238633A1 (en) Efficient state machines for real-time dataflow programming
CN107643889B (en) Page rendering method and device based on template engine
CN103699637A (en) Code productivity statistic method and system
CN111061464B (en) Analysis code generation method, device, equipment and storage medium
US20200341738A1 (en) Relational logic integration
CN110704290A (en) Log analysis method and device
US20110265063A1 (en) Comparing source code using code statement structures
CN104462943A (en) Non-intrusive performance monitoring device and method for service system
KR102187293B1 (en) Apparatus and method for analyzing smart contracts being capable of saving GAS
CN109656567B (en) Dynamic method and system for heterogeneous service data processing logic
CN108509774B (en) Data processing method and device, electronic equipment and storage medium
CN113434147A (en) ProtoBuf protocol-based message analysis method and device
CA2498377A1 (en) An apparatus and method for processing web service descriptions
US8495595B2 (en) Method of selecting an expression evaluation technique for domain-specific language compilation
US8984492B2 (en) Incremental compilation of a script code in a distributed environment
CN115688108A (en) Webshell static detection method and system
CN115237399A (en) Method for collecting data, storage medium, processor and engineering vehicle
CN113742302A (en) Service request processing method and device
Degano et al. Typing context-dependent behavioural variation
CN106301819B (en) Parameter checking method and checking system

Legal Events

Date Code Title Description
E902 Notification of reason for refusal
E701 Decision to grant or registration of patent right
GRNT Written decision to grant