
Ethereum Query Language Santiago Bragagnolo Henrique Rocha Inria Lille - Nord Europe Inria Lille - Nord Europe Villeneuve D’ascq, France Villeneuve D’ascq, France [email protected] [email protected] Marcus Denker Stéphane Ducasse Inria Lille - Nord Europe Inria Lille - Nord Europe Villeneuve D’ascq, France Villeneuve D’ascq, France [email protected] [email protected] ABSTRACT that append new information to the current state of the blockchain. Blockchains store a massive amount of heterogeneous data which Transactions are packed into blocks and the blocks are linked in a will only grow in time. When searching for data on the Ethereum sequence forming a chain. Thus, the name blockchain. platform, one is required to either access the records (blocks) di- Ethereum [5] is a popular blockchain platform that is capable of rectly by using a unique identifier, or sequentially search several executing Turing-complete programs, called Smart Contracts [10]. records to find the desired information. Therefore, we propose Ethereum also has its own cryptocurrency for monetary interac- the Ethereum Query Language (EQL), a query language that al- tions, called Ether [5]. lows users to retrieve information from the blockchain by writing Ethereum and other blockchains store a massive amount of het- SQL-like queries. The queries provide a rich syntax to specify data erogeneous data. Ethereum is estimated to have approximately elements to search information scattered through several records. 300GB of data [1]. Retrieving information from this massive data We claim that EQL makes it easier to search, acquire, format, and is not an easy task. Moreover, the Ethereum platform only allows present information from the blockchain. direct access to its first-class data elements, which includes blocks, transactions, accounts, and contracts [5]. Therefore, if we search CCS CONCEPTS for a particular information inside a data element, we would need a unique identifier (i.e., either the number or its hash) to access • Information systems → Query languages; Information re- the block containing such information. Another alternative would trieval query processing; Database query processing; Computing be to direct access one block and sequentially access its parents platforms; Digital cash; to search for a data. Moreover, the information returned by the KEYWORDS Ethereum platform when we access its blocks is encoded into a JSON-like structure that we need to interpret to acquire a specific Ethereum, Blockchain, Query Language, SQL item. Therefore, the Ethereum platform does not provide a semantic ACM Reference Format: way to search for information and neither an easy form to present Santiago Bragagnolo, Henrique Rocha, Marcus Denker, and Stéphane Ducasse. such information. 2018. Ethereum Query Language. In Proceedings of the 1st International Work- For example, let’s consider a blockchain application that man- shop on Emerging Trends in Software Engineering for Blockchain (WETSEB’18). ages a custom cryptocurrency controlled by a single person (i.e., ACM, New York, NY, USA, 8 pages. https://doi.org/10.1145/3194113.3194123 an owner).1 The owner needs to look for suspicious and possible malicious behavior in the history of one specific account. Currently, 1 INTRODUCTION the owner would have two options to gather that account’s data: Blockchain was initially used as a distributed ledger allowing mon- (i) direct access each block with the specific information, which etary interactions without the need of central trusted authority [2, would require for the owner to know beforehand the blocks’ hashes 8, 10–12]. We prefer a more formal definition that blockchain isa or numbers; or (ii) access the most recent block and sequentially globally shared transactional database managed by a peer-to-peer search every parent block for any information related to the ac- network [7]. Each peer in that network stores a complete copy count. After the owner acquires the information he still needs to of the blockchain database. The records are database transactions extract it from the stored representation and reformat it for a better visualization. Permission to make digital or hard copies of all or part of this work for personal or In a classical database, when we need to search for a particular classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation information, we usually write a query to fetch, present, filter, and on the first page. Copyrights for components of this work owned by others than the format such information. Database query languages like SQL pro- author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or vide a rich syntax to describe the data we want to acquire from the republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]. database. Since blockchain can be considered a database, it would WETSEB’18, May 27, 2018, Gothenburg, Sweden be better if we could use a similar way to fetch information inside © 2018 Copyright held by the owner/author(s). Publication rights licensed to the Association for Computing Machinery. ACM ISBN 978-1-4503-5726-5/18/05...$15.00 1 There is an example in the Solidity documentation called Subcurrency [7]. We present https://doi.org/10.1145/3194113.3194123 a modified version of this same example in Section 2.2. WETSEB’18, May 27, 2018, Gothenburg, Sweden Bragagnolo et al. the blocks. In this paper, we propose the Ethereum Query Language Listing 1 shows a Solidity contract example (adapted from the (EQL), a query language that enables its users to acquire informa- subcurrency example on the Solidity documentation [7]) that man- tion in the blockchain by writing SQL-like queries. Our goal is to ages a simple cryptocurrency controlled by a single person. The provide an easier way to fetch, format, and present information contract stores the balances of its accounts using a “mapping” (line extracted from the blockchain database. 7) that works like a hash table by mapping blockchain addresses The remainder of this paper is organized as follows. Section 2 to unsigned integers. The constructor (lines 13-15) stores the ad- present basic concepts on Structured Query Language and Ethereum dress of who deployed the contract (i.e., the owner of this contract smart contracts. Section 3 describes the problems and challenges instance). Only the owner can call the function “mint” (lines 18-21), to search and retrieve information from the blockchain. Section 4 which creates new coins for a specific account. The function “send” present EQL along with its syntax, examples, internal structure (lines 24-30) allows the caller of this function to transfer his coins (indexes), and limitations. In Section 5, we show a preliminary eval- to another account, provided that the caller has sufficient funds for uation describing the performance of EQL queries. In Section 6, we such operation. present related work in blockchain. Finally, Section 7 concludes the paper and outlines future work ideas. Listing 1: Solidity Simple Cryptocurrency Contract, Adapted 2 BACKGROUND Example In this section, we present basic concepts on Structured Query 1 pragma solidity ^0.4.20; Language (Section 2.1), and Ethereum Smart Contracts (Section 2.2). 2 3 contract CustomCoin { 2.1 Structured Query Language 4 address private owner; 5 Structure Query Language (SQL) is considered the standard rela- 6 /* The keyword"public" makes it readable tional database language [4, 14]. Even though SQL is well estab- from outside */ lished as a query language, it can also perform other operations 7 mapping (address => uint) public balances; such as manipulating data or specifying integrity constraints. The 8 commercial success of relational databases is greatly due to SQL 9 /* Events allow light clients to react on being a well-adopted standard [4]. changes efficiently */ In SQL, the “SELECT” statement is used to query data (i.e., re- 10 event Sent(address from, address to, uint trieve information) [14]. Basically, a “SELECT” query consists of the amount); clauses: select, from, where, group by, and order by. The select clause 11 specifies what to show from the query results; the from clauses 12 /* Constructor: only executed when the defines which tables to gather the data; the where clause defines a contract is deployed */ condition the information must satisfy to be returned as a result; 13 function CustomCoin() public { the group by clause groups the gathered data based on a condition; 14 owner = msg.sender; and finally, the order by clause specifies how the query orders its 15 } results. 16 We based our proposed query language on SQL, due to its pop- 17 /* Creates new coins */ ularity and broad user base. More specifically, our queries use an 18 function mint(address receiver, uint adapted form of the “SELECT” statement. amount) public { if (msg.sender != owner) return; 2.2 Ethereum Smart Contracts 19 20 balances[receiver] += amount; Smart contracts are programs that are executed in the blockchain 21 } platform [8, 10]. A smart contract is like a class; it contains attributes 22 and functions, and it can use inheritance on other contracts [7]. The 23 /* Allows the caller to send coins to correct execution of smart contracts, as well as their resulting states, another user/account */ is ensured by a consensus protocol [10]. Solidity [7] is the primary 24 function send(address receiver, uint language to specify smart contracts in the Ethereum blockchain. amount) public { Since the Ethereum platform is Turing-complete, contracts can 25 if (balances[msg.sender] < amount) define any rules by using the Solidity language. 26 revert(); // abort transaction Solidity is a high-level language based on JavaScript, C++, and 27 balances[msg.sender] -= amount; Phyton [7]. The contracts written in Solidity are compiled into a 28 balances[receiver] += amount; specific bytecode to run on the Ethereum Virtual Machine (EVM).
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages8 Page
-
File Size-