Next Article in Journal
A Grey Incidence Based Group Decision-Making Approach and Its Application
Previous Article in Journal
Stochastic Triad Topology Based Particle Swarm Optimization for Global Numerical Optimization
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Auction and Classification of Smart Contracts

by
Damián-Emilio Gibaja-Romero
1,*,† and
Rosa-María Cantón-Croda
2,†
1
Department of Mathematics, UPAEP-University, C. 17 Sur 901, Barrio de Santiago, Puebla 72410, Mexico
2
Deanship of Engineering, UPAEP-University, C. 17 Sur 901, Barrio de Santiago, Puebla 72410, Mexico
*
Author to whom correspondence should be addressed.
These authors contributed equally to this work.
Mathematics 2022, 10(7), 1033; https://doi.org/10.3390/math10071033
Submission received: 2 February 2022 / Revised: 4 March 2022 / Accepted: 11 March 2022 / Published: 24 March 2022
(This article belongs to the Topic Game Theory and Applications)

Abstract

:
The execution of smart contracts (SCs) relies on consensus algorithms that validate the miner who executes the contract and gets a fee to cover her expenditure. In this sense, miners are strategic agents who may focus on executing those contracts with the largest fee, to the detriment of other SCs’ execution times, which also harms the blockchain’s reputation. This paper analyzes the impact of miners’ competition on SCs’ execution times in a public blockchain. First, we explain that the Proof-of-Work mechanism casts similarities with a time auction, where the one who first adds blocks is the one who executes the contract and gets the fee. At equilibrium, costs negatively affect execution times, while the opposite holds concerning fees. However, this result does not capture the competition for other contracts; hence, we apply the Naïve Bayes method to classify SCs by considering a simulated database that comprises miners’ competition for several contracts. We observe that simultaneous competition generates patterns that differ from the ones expected by the auction solution. For example, miners’ valuation does not accelerate contracts’ execution, and high-cost smart contracts do not necessarily execute at last places.

1. Introduction

Blockchain networks have boosted the implementation of smart contracts (SCs) since they provide a decentralized process that self-activates such agreements when certain conditions are satisfied. During this process, the network’s nodes (miners) create blocks by solving mathematical puzzles, which is an activity that requires resources like hash power in Ethereum [1]. Later, a ‘consensus algorithm’ determines the miner who adds the block that the SC’s execution needs and this miner gets a fee as a reward [2]. So, consensus mechanisms promote miners’ competition because miners only get fees by adding the blocks that smart contracts need [3,4].
Consequently, miners follow an economic and strategic behavior since they choose those SCs that provide them the largest benefit [5] and join pools to share resources, which allows them to compete for a larger number of smart contracts [6]. So, public blockchain platforms deal with the issues associated with peer-to-peer networks, such as lack of security and coordination [7]. Nevertheless, SCs’ execution times also rely on miners’ decision-making. Specifically, miners may slow the activation of smart contracts because puzzles are costly to solve [8] or there are simultaneous requisitions to execute contracts due to an increasing number of SCs’ applications [9,10]. In general, it is not clear the impact of miners’ interactions, mining costs, and contracts’ fees on the time that independent smart contracts last to be executed [11]. In this sense, by considering that miners simultaneously compete to add blocks in other contracts, this paper addresses the following research question: How do costs, fees, and miners’ valuation impact SCs’ execution times? To answer this question, we first propose a game-theoretical model to determine the execution time that miners last in executing a contract characterized by its cost and fee. Later, we use the previous result to simulate the simultaneous execution of several smart contracts. Finally, we use machine learning techniques to classify execution times by considering costs, fees, and miners’ features.
It is worth recalling that consensus algorithms play a major role in activating smart contracts since they determine the miner who adds a contract to the blockchain. To build our game-theoretical model, we assume the blockchain uses the proof-of-work (PoW) algorithm because it assigns a contract to the miner who first solves the contract’s puzzle after spending her resources. Furthermore, we simplify the analysis by considering that contracts are independent among, which means that contracts do not trigger other contracts’ variables [12].
By the previous discussion, miners’ competition resembles a sealed bid time auction because the miner who sets the minimum time to create a node is the one who executes the contract’s code. So, we model the miners’ competition as a simultaneous game of incomplete information where miners observe each contract’s features but do not know other miners’ valuations. The equilibrium analysis provides a closed-form solution concerning the time each miner bids, which is described in terms of the miners’ and contracts’ features. At equilibrium, the comparative statics point out that execution times diminish as the number of miners and the fee increase, while the opposite happens when cost increases. Nevertheless, this result ignores the fact that miners can compete to get other contracts [9]. Although we can understand the previous interaction as a simultaneous auction problem [13], this framework is not necessary since SCs’ are not interrelated, miners independently value each smart contract, and the consensus algorithms serially allocate contracts among miners. Thus, we propose a Naïve Bayes classification to determine how competing for other contracts impacts execution times. The Naïve Bayes technique groups SCs by considering the execution time as the independent variable. In contrast, miners’ and contracts’ features are the independent variables. Then, we simulate the competition between 1000 miners and 10,000 contracts by considering the auction solution.
Surprisingly, our classification’s results differ from those we expected, given the comparative statics analysis. First, miners’ valuation does not increase or decrease execution times; specifically, we get that miners’ valuation induces an almost uniform conditional probability distribution. Second, fees and costs modify how fast a smart contract is executed, observing counter-intuitive results. For example, low cost and high fees slow the execution of some contracts.
Our paper is closely related to the literature that analyzes how miners impact the execution of smart contracts [14]. For example, miners pool resources as the contracts’ complexity increases [15] to maximize their benefits [16]. Moreover, consensus algorithms are coordination mechanisms that transparently determine who has the right to execute a smart contract without interfering in how miners pick contracts, which also may cause dishonest behavior from them [17]. So, miners can manipulate the consensus mechanism by centralizing resources in mining pools [18], which tends to happen in those platforms that use algorithms that do not require the explicit use of resources for mining blocks, such as the Proof-of-Stake (PoS) and the Proof-of-Authority (PoA) algorithms [19,20]. In this sense, our contributions unfold in two streams. First, we describe the PoW mechanism as a time auction that allows us to find a closed-form solution that echoes empirical findings: the execution time of a contract increases as the contracts need more resources to be executed (costs) [21], and large fees reduce execution times [22]. This shows that game-theoretical models serve for designing consensus algorithms, which is of growing interest to avoid manipulation and safeguard users’ welfare [23,24]. Second, we extend the applications of the Naïves Bayes technique to classify smart contracts based on the features that characterize their time of execution.
Typically, classification techniques have widely used to determine if a SC is not legal or duplicates a transaction [25,26] because not all smart contracts are secure [27] or well-defined [28]. Furthermore, we can classify miners to identify pools that try to prioritize the execution of certain contracts over others [14]. Our classification shows that the probability of being executed with a certain priority is independent of miners’ valuation, while economic variables (fee and costs) are the ones that change this probability. This result supports the necessity of designing consensus mechanisms based on auctions to prevent miners’ collusion [29] and reduce the use of resources [30].
The paper is organized as follows. The next section presents the auction game in which miners interact to set execution times. Later, in Section 3, we describe the game´s solution, which we use to build the dataset. The theoretical model allows us to create a Naïve Bayes classifier, in Section 4, such that dependent variables are the contracts’ features. Section 5 discusses the main results concerning Naïve Bayes evaluation and classification. The last section presents the paper’s conclusions.

2. Model

In a public blockchain platform, miners compete to execute a SC. Specifically, we focus on a public blockchain that uses the proof-of-work consensus mechanism. To model miners’ competition in such a structure, we first consider a market where agents a and p exogenously establish a smart contract x with a fee f x . To simplify the notation, we refer to the previous smart contract as x ( f x ) . The fee is a reward expressed as a positive amount of the digital coin used in the public blockchain P where the SC stands. Miners can use f x to get resources exchanged in P .
We assume the existence of a trustworthy oracle that points out the necessity to execute x ( f x ) . For instance, we say that the oracle is not strategic. Moreover, all miners observe the need of adding nodes to P .

2.1. Basic Elements

Let M = { 1 , 2 , , m } be the set of all miners in the digital platform; we use i to denote a generic miner in M. The time that miner i lasts to pick x ( f x ) is denoted by t i , where t i T i = [ 0 , ) . Given that smart contracts execution requires miners’ resources as time passes, miner i faces a cost function c i ( t i ) for picking the contract in a time t i . We consider that c i is a function from T i to R such that d c i / d t i < 0 , which captures the fact that miners can get better resources to solve puzzles with more time [31]. We characterize miners by a valuation v i about picking the contract x ( f x ) to get f x coins. Let V i be the set of all valuations of miner i.
The state of the market is a vector v = ( v 1 , v 2 , , v m ) that is an element of V = V 1 × × V m R m . We consider that miners’ valuation is private information, i.e., each miner i knows their valuation v i but does not know other miners’ valuations. Furthermore, agents p and a do not observe v. So, the market state v is the realization of a random vector V = ( V 1 , V 2 , , V m ) that is drawn from a probability density function f : V R , which we assume common knowledge.

2.2. The Game

Regardless of digital platforms’ architecture, they have similar rules concerning their application on smart contracts. Specifically, digital platforms establish that miners should compete among them to execute the smart contract, i.e., the miner who solves the puzzle as soon as possible is the one who adds the block to the blockchain and gets the associated fee. Thus, we model the competition between miners as a time auction where the winner is the one that sets the minimum time to pick x ( f x ) .
The interaction between miners starts when all of them observe the request to execute x ( f x ) . Hence, the game proceeds in the following two stages:
Stage 1.
Nature draws the market state v = ( v 1 , v 2 , , v m ) by following the probability density function f.
Stage 2.
Each miner i observes their valuation v i , but no other miners’ valuations. Simultaneously, each miner sets the time t i to pick x ( f x ) .
All nodes in the platform P observe the profile of picking times t = ( t 1 , t 2 , , t m ) . Since picking times represent how fast miners mine a block, the miner who sets the lowest picking time is the one who executes x ( f x ) . If two or more miners set the lowest picking time, the tie is randomly broken, i.e., the probability of executing the code is the same for all these miners. The game finishes with the execution of the smart contract, and the miner who runs it gets f x .
Let u i be the payoff function of i that depends on σ , and the amount of (digital) money μ i that miner i gets when the game finishes.

2.3. The Solution Concept

The set of all possible actions of miner i is T i . Recalling that miners’ valuation are private information, a pure strategy is a decision rule σ i that maps i’s valuation into a picking time t i , i.e., σ i is a function from V i to T i . So, Σ i = { σ i | σ i : V i T i } is the set of all possible decision rules of miner i.
A profile of strategies is a vector of decision rules σ = ( σ 1 , σ 2 , , σ m ) Σ , where Σ = Σ 1 × Σ 2 × × Σ m . As usual, σ i is the decision rules’ profile of all miners that are different to i.
Remembering that miners’ valuation is private information, miners have no certainty concerning the payoff that they get when the game finishes with a profile of decision rules σ ( v ) = ( σ 1 ( v 1 ) , σ 2 ( v 2 ) . . . , σ m ( v m ) ) . We denote by E [ u i ( σ ) ] the expected payoff of miner i at the end of the game; and we consider the Bayesian Nash equilibrium as the solution concept for the game described in Section 2.2.
Definition 1.
We say that σ * = ( σ 1 , σ 2 , , σ m ) is a Bayesian Nash equilibrium if
E [ u i ( σ i * , σ i * ) ] E [ u i ( σ i , σ i * ) ]
for all i M and σ i Σ i .
In other words, a Bayesian Nash equilibrium is a profile of decision rules under which all miners do not have incentives to deviate from the action that they choose concerning the state of the market v.

3. Picking Times at Equilibrium

This section searches for the Bayesian Nash equilibria of the game described in the previous section. To simplify the analysis, we assume that miners follow symmetric behavior, and later we perform some comparative statics by considering that random variables V i are independent and uniformly distributed.

3.1. Solving the Game

The game described in Section 2.2 establishes that miners simultaneously set the time to pick x ( f x ) whereas each miner’s valuation is private information. Furthermore, each miner i knows that other miners picking times depend on valuations v j , for all j M { j } , i.e., i knows that others decision rules profile σ i ( v i ) = ( t j ( v j ) ) j i depends on the market state. Then, at the end of the game, i faces three possible scenarios: (a) i executes the smart contract because he sets the lowest picking time, (b) i ties with other miners in setting the lowest time to pick the contract, or (c) i does not set the lowest picking time which means that i does not execute the code.
If i gets the right to execute the contract’s code, i gets the fee associated with x ( f x ) , and he also spends resources to mine blocks that guarantee x ( f x ) execution. For example, in Ethereum, these resources are gas and ether. In the opposite case, miners do not get f x and do not spend resources to execute the code. Hence, the payoff function of miner i is
u i ( t i , t i ; v i ) = f x + v i c i ( t i ) if t i < min j i { t j } , f x + v i c i ( t i ) k if | { j M | t j = t i = min { t k | k M } } | = k , 0 if t i > min j i { t j } .
Thus, the expected payoff function of miner i is
E [ u i ( σ i , σ i ) ; v ] = P r [ W ] ( f x + v i c i ( t i ) ) + P r [ T ] f x + v i c i ( t i ) k + P r [ L ] 0 ,
where W, T, and L are the probability events associated with scenarios (a), (b) and (c), respectively.
Note that σ ( v ) i = ( t j ( v j ) ) j i is the realization of the random vector σ ( V ) i = ( t j ( V j ) ) j i , i.e., each decision rule t j is a transformation of the random variable V j for all j M { j } . By assuming that V j is a continuous random variable for all j M , we have that
P r [ T ] = P r [ | { j M | t j = t i = min { t k | k M } } | = k ] = P r [ | { j M | t j ( v j ) = t i = min { t k ( v k ) | k M } } | = k ] = 0 .
Consequently, we can rewrite the expected payoff function of i as follows
E [ u i ( σ i , σ i ) ; v ] = ( f x + v i k ) P r [ W ] ,
where
P r [ W ] = P r t i < min j i { t j ( v j ) } .
To search for the best decision rules of miner i to σ ( v ) i , we maximize their expected payoff. By expression (1), we first compute the probability P r [ W ] of winning the right to execute x ( f x ) . Note that P r [ W ] depends on the profile σ i ( v i ) ; as in Auction theory, we assume that all miners behave symmetrically picking x ( f x ) in a time that is inversely proportional to their valuation, i.e., all miners j i choose the decision rule
t j = α v j ,
where α is a positive constant.
Intuitively, expression (2) captures the fact that miners pick the contracts as soon as their valuation on x ( f x ) increases. For example, the previous case arises when miners need money to acquire resources in P .
Now, given that t j ( v j ) = α / v j is the realization of the random variable α / V j , the probability of winning the right to execute x ( f x ) is
P r t i < min j i α v j .
By assuming that V = ( V 1 , , V m ) is a random vector of independent and identically distributed random variables, the definition of the minimum order statistic implies that
P r t i < min j i α v j = P r t i < α v j m 1 .
Finally, we consider that V j follows a uniform distribution on the interval [ 0 , 1 ] , which means that
P r [ W ] = P r t i < α v j m 1 = P r v j < α t i m 1 = α t i m 1 .
To simplify the calculation of miners’ best decision rules, we consider that c i ( t i ) = 1 / t i + κ , where κ is a fixed cost to mine x ( f x ) , and 1 / t i are the variables costs, in accordance with the assumption that c i / t i < 0 . The previous cost function, together with expression (3), implies that the expected payoff function in (1) can be rewritten as follows
E [ u i ] = α m 1 t i m 1 f x + v i 1 t i κ .
Then, we compute the best response of i to σ i by considering that other miners decision rules profile is σ i = ( α / v j ) j M { i } .
We use the criterion of the first derivative to search for the best response of i; that is to say, we need to solve the equation E [ u i ] / t i = 0 where
E [ u i ] t i = ( m 1 ) α m 1 ( v i + f x κ ) t i m + m α m 1 t i m + 1 .
So, the critical points of the expected payoff function of i are the solutions of
( m 1 ) α m 1 ( v i + f x κ ) t i m + m α m 1 t i m + 1 = 0 .
Note that the previous expression is equivalent to
( m 1 ) α m 1 ( v i + f x κ ) t i m = m α m 1 t i m + 1 ( m 1 ) ( v i + f x κ ) t i m = m t i m + 1 t i ( v i + f x κ ) ( m 1 ) = m ,
which is a linear equation on t i . Consequently, the unique solution of the first order condition E [ u i ] / t i = 0 is
t i = m ( m 1 ) ( v i + f x κ ) .
In other words, E [ u i ] has a unique critical point t i that depends on v i . The next theorem demonstrates that t i ( v i ) , as in expression (5), maximizes the expected payoff function of i when other miners set a picking time that is inversely proportional to their valuation.
Theorem 1.
Consider that | M | > 2 and v i + f x > κ . The best response of miner i to σ i = ( α / v j ) j i is
σ i * ( v i ) = t i ( v i ) = m ( m 1 ) ( v i + f x κ ) .
Proof. 
By expression (5), t i = m / [ ( m 1 ) ( v i + f x κ ) ] is a critical point of E [ u i ] ; to guarantee that such decision rule is best response of i to σ i , we need to verify that such rule induces the maximum expected payoff for i. For this end, we follow the second order condition. Thus, we first compute the second derivative of E [ u i ]
2 E [ u i ] t i 2 = m ( m 1 ) α m 1 ( v i + f x κ ) t i m + 1 m ( m + 1 ) α m 1 t i m + 2 .
By performing some algebraic simplifications on the previous expression, we have that
2 E [ u i ] t i 2 = m α m 1 t i m + 2 ( m 1 ) ( v i + f x κ ) t i ( m + 1 ) .
Notice that t i ( v i ) m + 2 > 0 because v i + f x > κ . Furthermore, m α m 1 is a positive constant. So, to verify if the expected payoff function reaches a maximum, or a minimum, on t i , we focus on identifying the sign of
Δ ( t i ) = ( m 1 ) ( v i + f x κ ) t i ( m + 1 )
when Δ ( t i ) is evaluated on t i ( v i ) .
Δ ( t i ( v i ) ) = ( m 1 ) ( v i + f x κ ) m ( m 1 ) ( v i + f x κ ) ( m + 1 ) ,
where m 1 and v i + f x κ are greater than zero. So
Δ ( t i ( v i ) ) = m ( m + 1 ) = 1 .
Consequently, we have that
2 E [ u i ] t i 2 t i = t i ( v i ) = m α m 1 t i ( v i ) m + 2 ( 1 ) < 0 .
In other words, miner i maximizes their expected utility function by picking x ( f x ) in a time
t i ( v i ) = m ( m 1 ) ( v i + f x κ ) .
Corollary 1.
If v i + f x κ > 0 , the game described in Section 2.1 has a unique symmetric Bayesian Nash equilibrium σ * ( v ) = ( σ 1 * ( v 1 ) , , σ m * ) where
σ i * = m ( m 1 ) ( v i + f x κ )
for all i M .
Proof. 
It follows from Theorem 1. □
Expression (5) establishes a closed-form solution for miners’ decision rule at the symmetric Bayesian Nash equilibrium (SBNE). Aside from the fact that such an equilibrium decision rule is unique and single-value, we observe that picking times are inversely proportional to the net revenue that each miner gets, after covering fixed costs, when they get the right to execute the smart contract. The following corollary shows that picking times tend to be such net revenue as the number of miners increases to infinity.
Corollary 2.
As m , the equilibrium decision rule of i tends to 1 v i + f x κ .
Proof. 
From Theorem 1, the equilibrium decision rule of miner i is σ i * ( v i ) = m / ( m 1 ) ( v i + f x κ ) . Then, we have that
lim m σ i * ( v i ) = lim m ( m 1 ) ( v i + f x κ ) = lim m m m 1 1 v i + f x κ = 1 v i + f x κ lim m m m 1 .
Since lim m m / ( m 1 ) = 1 , we conclude that
lim m σ i ( v i ) * = 1 v i + f x κ .

3.2. Comparative Statics

As we mentioned before, one of the main advantages of establishing smart contracts relies on the fact that agents p and a do not need the intervention of a third party agent to guarantee the fulfillment of all agreements in x ( f x ) . By an almost immediate execution, smart contracts provide security and transparency to agents p and a. However, there exogenous factors that may slow or accelerate the execution of smart contracts.
Specifically, expression (5) points out that picking times at equilibrium depend on the number of miners m, the fee f x provided by x ( f x ) , and the fixed cost κ that miners face by belonging to P . Moreover, Theorem 1 and Corollary 1 imply that the equilibrium decision rule σ i * is single-value, which allow us to perform some comparative statics with respect to the exogenous variables m, f x and κ . The following propositions summarizes the relationship between equilibrium picking times and exogenous variables.
First, picking times reduce as the number of miners increases. Intuitively, a larger number of miners promote competition among them since the consensus algorithm drive a strategic behavior.
Proposition 1.
At equilibrium, if v i + f x κ > 0 , then picking times diminish as the number of miners increases.
Proof. 
To demonstrate this proposition, we take the partial derivative of expression (5) concerning m. So, we have that
σ i * m = 1 v i + f x k m 1 m ( m 1 ) 2 = 1 v i + f x k 1 ( m 1 ) 2 .
Since v i + f x κ > 0 , we have that
σ i * m < 0 .
In words, there is negative relationship between the time that i lasts to pick x ( f x ) and the number of miners in P . □
As a consequence of Corollary 2 and Proposition 1, we have that picking times monotonically decreases to 1 / ( v i + f x κ ) as the number of miners m increases to infinity. In other words, after covering fixed costs, the inverse of the net revenue represents a lower bound for the time that miners last to pick the smart contract x ( f x ) . Consequently, smart contracts do not immediately execute. Thus, a large number of miners does not guarantee the execution of a smart contract despite that picking times diminish as there are more miners in the public blockchain.
The existence of a lower bound for picking a contract, different from zero, implies that the need for resources plays a major role in the execution of a smart contract x ( f x ) . The following proposition shows the relationship between the equilibrium decision rule and the economic variables that characterize the contract.
Proposition 2.
Consider σ i * , the equilibrium decision rule of miner i. The relationship between σ i * and f x is negative, and the relationship with respect to κ is positive.
Proof. 
First, we compute the partial derivative of σ i * with respect to κ . So, we have that
σ i * κ = m m 1 1 ( 1 ) ( v i + f k κ ) 2 = m m 1 1 ( v i + f k κ ) 2 .
Since v i + f k κ > 0 , we conclude that σ i * / κ > 0 .
Now, the partial derivative of σ i * with respect to f k is
σ i * f x = m m 1 1 ( v i + f k κ ) 2 = m m 1 1 ( v i + f k κ ) 2 .
Given that v i + f k κ > 0 , the relationship between σ i * and f x is negative. □
The previous proposition establishes that higher costs of belonging to P may discourage miners from picking a contract in case of not having enough resources. So, picking times increase as the fixed cost increases. Moreover, the relationship between the equilibrium picking time and the fee is negative, which means execution times reduce as p and a provide a larger reward for executing x ( f x ) .

4. Contracts Classification

Blockchain platforms provide a decentralized environment for executing smart contracts. The decision rule in Corollary 1 shows the equilibrium picking time that each miner spends to execute contract x ( f x ) ; hence, the minimum picking time is the execution time of x ( f x ) . So, Corollary 1 allows us to analyze the relationship between the execution time and the exogenous variables v i , f x and k. However, the equilibrium decision rule σ i * does not indicate how the simultaneous competition to execute other contracts y ( f y ) x ( f x ) impact the execution time. This section analyzes the implications of simultaneous competition on the SCs’ execution times.
It is worth recalling that we consider independent smart contracts, which means that x ( f x ) ’s features and execution does not depend on other contract y ( f y ) features and execution. So, if miner i gets a set of contracts { x 1 ( f x 1 ) , x 2 ( f x 2 ) , , x K ( f x K ) } , her benefit is
E [ u i ( x 1 ( f x 1 ) , x 2 ( f x 2 ) , , x K ( f x K ) ) ] = k = 1 K E [ u i ( x k ( f k ) ) ] .
Consequently, we do not follow a simultaneous auction approach to analyze how the competition for getting other contracts impacts execution times since such an interaction is different from classical simultaneous auctions [13]. Hence, we use machine learning techniques to analyze execution times when miners simultaneously compete to get other contracts.
First, we simulate the game in Section 2.2. The previous simulation provides a database that comprises execution times, fee, cost, and miner’s valuations. Then, we classify execution times in terms of the contracts and miners’ features.

4.1. Building the Data

At equilibrium, miners pick smart contracts by considering the decision rule in Corollary 1. Such a closed-form solution is appealing for classifying smart contracts since it summarizes the SCs’ features and the equilibrium behavior of miners. By using the software R, we build a database that comprises the interaction of 1000 miners to execute 10,000 smart contracts. The simulation considers as basis values maximum and minimum costs and fees from the Ethereum platform [32]. Below, we present the code we use to create such a database; it is divided into sections describing the platform, miners, and contracts’ features.
Mathematics 10 01033 i001aMathematics 10 01033 i001b
Note that all variables in the database Contracts_ex are continuous. By applying the classification technique, we get back the mean and standard deviation of the random numbers we used to create the database. So, we need to transform fee, cost, valuation, and picking time into categorical variables to classify contracts.
The transformation of variables is based on quantiles of five levels, and each of them represents a qualitative feature. In the case of fee and cost, each level refers to magnitude, that is to say, how large fees and costs are. Specifically, the fee or cost of a smart contract can be considered as Low, Medium-Low, Medium, Medium-High, and High. Concerning valuation, each level represents preference. Then, we can say that the SC x is the Top, Second-best, Third-best, Fourth-best, or Bottom for a miner i depending on her valuation v i . Finally, the picking time categories refer to how fast a smart contract is executed; in this sense, a smart contract can be executed in First, Second, Third, Fourth, and Fifth place. Table 1 shows the labels of each quantile with respect to variables f x , c x , v and t x .
Below, we explain the code that we use to perform the previous transformation in R.
Mathematics 10 01033 i002aMathematics 10 01033 i002b

4.2. The Näive Bayes Classifier

To analyze the impact of cost, fee and valuation on the simultaneous execution of smart contracts, we classify them through the Naïve Bayes (NB) technique. We also consider NB’s variations to check the classification’s accuracy since the database Contracts_ex is the result of a qualitative transformation of continuous variables. Table 1 summarizes the categorical values that each variable can take. We consider that execution time ( t x ) is the independent variable, while fee ( f x ), fixed cost (k) and valuation (v) are the dependent variables. In other words, we classify execution times through the main features of contracts and miners.
Note that our database satisfies the naïve assumption since its variables are independent by construction. Then, the Naïve Bayes method classifies smart contracts through the Bayes’ theorem. Mathematically, this technique computes
P r ( t x = t | f x , c x , v ) = P r ( f x , c x , v s . | t x = t ) P r ( t x = t ) P r ( f x , c x ) ,
which refers to the conditional probability of being executed at place t F i r s t , S e c o n d , T h i r d , F o u r t h , F i f t h , given the features that characterize the contract (fee, cost) and miners’ valuation.

4.3. Naïve Bayes Implementation

Remember, the Contracts_ex summarizes a simulated interaction between 1000 miners that compete for executing 10,000 contracts. Thus, contracts’ classification identifies those features that accelerate or slow the execution of SCHence, we use the Contracts_ex database that comprises categorical values related to miners’ preferences, magnitude, and velocity (see Table 1).
We build the classification model by splitting the database into two databases for training and testing. We use the NaïveBayes and e1072 packages of R to verify the robustness of our results. Furthermore, we apply the Kernel and Laplace correction methods.
First, note that execution times classes (First, Second, Third, Fourth, and Fifth) are (almost) perfectly balanced. In other words, each class has an a priori probability of around 20 % (see Table 2).
Second, Table 3 illustrates the accuracy, for the training and the testing database, concerning the different packages and the correction methods that we use. We observe that accuracy is the same regardless of the package or the correction method. Although accuracy is lower than 50 % , this is not surprising since the five classes are almost perfectly balanced. In other words, random guessing provides an accuracy of around 50 % for each execution time, which is relatively high by considering that the smart contracts variables take five values.
Finally, in Table 4, we present the statistics concerning the execution time classes. Contracts executed at fifth place, the slowest category, have the highest sensitivity. Then, the classifier correctly predicts those contracts that have a slow execution. In other words, the simultaneous competition for getting SCs makes it difficult to predict which contracts are executed as far as possible. In contrast, the correct identification of false cases concerning how fast an SC is executed is around 80 % or more for each execution time level. Thus, the classifier correctly identifies those contracts that do not cope with the features to be executed almost immediately.
Even though high sensitivity is desirable, the trust and credibility of Blockchain networks rely on preventing execution times manipulation, which holds when we look out for the Positive Predicted Value (PPV) and the Negative Predicted Value (NPV). So, the NPV is larger than the PPV for all execution time categories, which means that miners’ interaction is trustworthy. Even more, the auction mechanism does not execute those contracts incorrectly identified as first class. This is important since most results are false positive according to the sensitivity measure. In other words, the Naïve Bayes classifier identifies those contracts that do not cope with the features for being executed in first, second, third, or fourth place. Hence, a large specificity contributes to identifying miners who try to cheat the blockchain. In this sense, the classification may prevent the blockchain platform’s loss of trust and credibility.

4.4. Conditional Probabilities

The Naïve Bayes classifier computes the conditional probabilities of how fast a SC is executed, given the features of a smart contract. Table 5 shows the features of some contracts and the execution time that the NB classifier predicts.
Table 6 presents the conditional probabilities concerning smart contracts features. This table provides some interesting insights concerning how fast SCs are executed during the simultaneous competition to execute several contracts. First, we observe that miners’ valuation induce a uniform distribution, reflecting the simulation’s features (see Figure 1). Specifically, results are balanced around a probability of 0.20, which means that the miners’ valuation balances the conditional probability. In other words, such a variable does not accelerate or slow the miners’ intervention to execute a contract.
Given the economic variables (cost and fee) that characterize smart contracts, conditional probabilities are not balanced as it happens with the miners valuation. In both cases, we observe different patterns that contrast with the relationships in Proposition 2.
First, we discuss the probability of execution times given a fee (see Figure 2). Table 6 shows that the probability of being executed in first or second place weakly increases as the SCs’ fee increases, in line with the positive relationship between picking times and fee that we find in Proposition 2. Furthermore, contracts with a low fee have a higher probability of being executed in fourth place. However, the probability of being executed at fifth place calls our attention since such a probability increases as the fee also increases; in other words, simultaneous competition. Even more, this probability is larger ( 0.275 ) in comparison with the execution of contracts at first ( 0.21 ) or second places ( 0.19 ). Finally, those contracts in the third category present a balanced probability distribution (0.20).
Finally, conditional probabilities related to costs present the most drastic results (see Figure 3). For example, given a low cost, the probability of being executed at fifth place is greater than 0.7 , which is surprising since we expect the opposite; that is to say, the prioritization of cheap contracts. Furthermore, we observe that low cost (cheap contracts) do not guarantee the immediate execution of smart contracts. A medium cost induces the highest probability of being executed at second ( 0.315 ) and third place ( 0.285 ), while smart contracts with medium-high costs have priority one to be executed; a probability equal to 0.283 . Nevertheless, we get zero probability of being executed in fifth place, given medium and medium-high costs; consequently, no smart contracts are classified in fifth place with such costs. We attribute the previous result to the low accuracy since variables take five values.
By the above discussion, the simultaneous competition to get several contracts modifies how fast a smart contract is executed. Particularly, given some combinations of qualitative features, we observe the opposite relationship that we expect from Proposition 2.

5. Conclusions

In this paper, we study the execution times of smart contracts by considering that miners simultaneously compete to get the right to execute more than one contract. Our analysis focuses on independent contracts that stand in a public blockchain that uses the Proof-of-Work mechanism since this consensus mechanism is secure and guarantees coordination among the blockchain’s members [16]. Given that PoW induces a direct use of resources, we model miners’ competition for a single contract as a time auction. In other words, the miner who first solves the contract’s puzzle is the one who gets the associated fee. The analysis of this game-theoretical framework provides a closed-form solution concerning each miner’s time to pick a single contract, which also echoes empirical findings. For example, the comparative statistics point out that picking times reduce as fee increases, while mining costs induce the opposite relationship [21,22].
The previous solution does not capture the fact that miners can compete to pick other contracts at the same time, an interaction that we analyze by classifying contracts. Given that contracts are independent, a simultaneous auction does not interrelate the miners’ interaction in multiple executions, while the Naïve Bayes classifier allows us to predict execution times based on the smart contracts and miners’ features.
Based on equilibrium picking times, we simulate the interaction of 1000 miners that compete for 10,000 contracts. Unsurprisingly, accuracy and sensitivity are below the standards since the independent variables are not dichotomous (we transform continuous variables into qualitative variables with five levels). However, the classification results show some interesting patterns that do not correspond with those expected from the comparative statics analysis. For example, miners’ valuation does not accelerate execution times, while costs induce counter-intuitive patterns (the probability of being executed in the last place increases as cost increases). Concerning the variable fee, there is no clear patron of their impact on execution times.
It is worth recalling that the Naïve Bayes classifier provides interesting insights concerning the possibility that miners manipulate the consensus mechanism when multiple contracts are executed. Although the classification results are not good for identifying those contracts that should be executed in a certain order (low sensitivity and positive predicted value), the opposite happens with the identification of contracts that should not be executed by considering a certain priority (high specificity and negative predicted value). We pretend to verify the previous results in future works by considering real data from public blockchains such as Ethereum.
Finally, our main contribution relies on providing a theoretical framework to analyze concurrent operations, whose efficient performance in public blockchains is of interest given the increasing popularity of smart contracts [9,33]. Particularly, the auction model points out the possibility of designing transparent consensus mechanisms that allow the monitoring of dishonest behavior of miners. Such a game-theoretical framework is suitable for including regulatory agents (such as time oracles) to take care of SC users’ welfare, which is also a research topic of growing interest [23]. Moreover, smart contracts classification may predict the features that drive miners to follow dishonest behavior, such as manipulating the consensus algorithm. Avoiding dishonest behavior from miners is crucial for blockchains since it compromises their reputation. In this sense, we explain how the Naïve Bayes method is able to identify if miners’ interactions modify the execution order of a smart contract and consequently prevent miners’ misbehavior.

Author Contributions

Conceptualization, D.-E.G.-R. and R.-M.C.-C.; methodology, D.-E.G.-R.; software, R.-M.C.-C.; formal analysis, D.-E.G.-R.; investigation, D.-E.G.-R. and R.-M.C.-C.; data curation, R.-M.C.-C.; writing—original draft preparation, D.-E.G.-R.; writing—review and editing, D.-E.G.-R. and R.-M.C.-C.; visualization, R.-M.C.-C. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

Not applicable.

Conflicts of Interest

The authors declare no conflict of interest.

References

  1. Massobrio, R.; Nesmachnow, S.; Tchernykh, A.; Avetisyan, A.; Radchenko, G. Towards a cloud computing paradigm for big data analysis in smart cities. Program. Comput. Softw. 2018, 44, 181–189. [Google Scholar] [CrossRef]
  2. Varnovskiy, N.; Martishin, S.; Khrapchenko, M.; Shokurov, A.V. Secure cloud computing based on threshold homomorphic encryption. Program. Comput. Softw. 2015, 41, 215–218. [Google Scholar] [CrossRef]
  3. Chang, C.H.; Molahosseini, A.S.; Zarandi, A.A.E.; Tay, T.F. Residue number systems: A new paradigm to datapath optimization for low-power and high-performance digital signal processing applications. IEEE Circuits Syst. Mag. 2015, 15, 26–44. [Google Scholar] [CrossRef]
  4. Sousa, L.; Antao, S.; Martins, P. Combining residue arithmetic to design efficient cryptographic circuits and systems. IEEE Circuits Syst. Mag. 2016, 16, 6–32. [Google Scholar] [CrossRef]
  5. Chervyakov, N.I.; Lyakhov, P.A.; Babenko, M.G. Digital filtering of images in a residue number system using finite-field wavelets. Autom. Control Comput. Sci. 2014, 48, 180–189. [Google Scholar] [CrossRef]
  6. Tchernykh, A.; Schwiegelsohn, U.; Talbi, E.g.; Babenko, M. Towards understanding uncertainty in cloud computing with risks of confidentiality, integrity, and availability. J. Comput. Sci. 2019, 36, 100581. [Google Scholar] [CrossRef]
  7. Ye, R.; Boukerche, A.; Wang, H.; Zhou, X.; Yan, B. RESIDENT: A reliable residue number system-based data transmission mechanism for wireless sensor networks. Wirel. Networks 2018, 24, 597–610. [Google Scholar] [CrossRef]
  8. Chervyakov, N.; Babenko, M.; Tchernykh, A.; Kucherov, N.; Miranda-López, V.; Cortés-Mendoza, J.M. AR-RRNS: Configurable reliable distributed data storage systems for Internet of Things to ensure security. Future Gener. Comput. Syst. 2019, 92, 1080–1092. [Google Scholar] [CrossRef]
  9. Dickerson, T.; Gazzillo, P.; Herlihy, M.; Koskinen, E. Adding concurrency to smart contracts. Distrib. Comput. 2020, 33, 209–225. [Google Scholar] [CrossRef] [Green Version]
  10. Singh, H.J.; Hafid, A.S. Prediction of transaction confirmation time in Ethereum blockchain using machine learning. arXiv 2004, arXiv:1911.11592. [Google Scholar]
  11. Miranda-López, V.; Tchernykh, A.; Cortés-Mendoza, J.M.; Babenko, M.; Radchenko, G.; Nesmachnow, S.; Du, Z. Experimental analysis of secret sharing schemes for cloud storage based on rns. In Proceedings of the Latin American High Performance Computing Conference, Buenos Aires, Argentina, 20–22 September 2017; Springer: Berlin, Germany, 2017; pp. 370–383. [Google Scholar]
  12. Vukolić, M. Rethinking permissioned blockchains. In Proceedings of the ACM Workshop on Blockchain, Cryptocurrencies and Contracts, Abu Dhabi, United Arab Emirates, 2 April 2017; pp. 3–7. [Google Scholar]
  13. Milgrom, P. Putting auction theory to work: The simultaneous ascending auction. J. Political Econ. 2000, 108, 245–272. [Google Scholar] [CrossRef] [Green Version]
  14. Babenko, M.; Chervyakov, N.; Tchernykh, A.; Kucherov, N.; Shabalina, M.; Vashchenko, I.; Radchenko, G.; Murga, D. Unfairness correction in P2P grids based on residue number system of a special form. In Proceedings of the 2017 28th International Workshop on Database and Expert Systems Applications (DEXA), Lyon, France, 28–31 August 2017; pp. 147–151. [Google Scholar]
  15. Dana Troutman, N.; Laszka, A. PoolParty: Efficient Blockchain-Agnostic Decentralized Mining Pool. In Proceedings of the 2021 The 3rd International Conference on Blockchain Technology, Shangai, China, 26–28 March 2021; pp. 20–27. [Google Scholar]
  16. Zheng, Z.; Xie, S.; Dai, H.N.; Chen, W.; Chen, X.; Weng, J.; Imran, M. An overview on smart contracts: Challenges, advances and platforms. Future Gener. Comput. Syst. 2020, 105, 475–491. [Google Scholar] [CrossRef] [Green Version]
  17. Motaqy, Z.; Almashaqbeh, G.; Bahrak, B.; Yazdani, N. Bet and Attack: Incentive Compatible Collaborative Attacks Using Smart Contracts. In Proceedings of the International Conference on Decision and Game Theory for Security, Prague, Czech Republic, 25–27 October 2021; Springer: Berlin, Germany, 2021; pp. 293–313. [Google Scholar]
  18. Dong, C.; Wang, Y.; Aldweesh, A.; McCorry, P.; van Moorsel, A. Betrayal, distrust, and rationality: Smart counter-collusion contracts for verifiable cloud computing. In Proceedings of the 2017 ACM SIGSAC Conference on Computer and Communications Security, Dallas, TX, USA, 30 October–3 November 2017; pp. 211–227. [Google Scholar]
  19. Lee, S.; Kim, S. Shorting attack: Predatory, destructive short selling on Proof-of-Stake cryptocurrencies. Concurr. Comput. Pract. Exp. 2021, 9, e6585. [Google Scholar] [CrossRef]
  20. Joshi, S. Feasibility of Proof of Authority as a Consensus Protocol Model. arXiv 2021, arXiv:2109.02480. [Google Scholar]
  21. Wüst, K.; Matetic, S.; Egli, S.; Kostiainen, K.; Capkun, S. ACE: Asynchronous and concurrent execution of complex smart contracts. In Proceedings of the 2020 ACM SIGSAC Conference on Computer and Communications Security, Virtual Event, USA, 9–13 November 2020; pp. 587–600. [Google Scholar]
  22. Aldweesh, A.; Alharby, M.; Solaiman, E.; van Moorsel, A. Performance benchmarking of smart contracts to assess miner incentives in Ethereum. In Proceedings of the 2018 14th European Dependable Computing Conference (EDCC), Iasi, Romania, 10–14 September 2018; pp. 144–149. [Google Scholar]
  23. Zhou, H.; Ouyang, X.; Su, J.; de Laat, C.; Zhao, Z. Enforcing trustworthy cloud sla with witnesses: A game theory–based model using smart contracts. Concurr. Comput. Pract. Exp. 2021, 33, e5511. [Google Scholar] [CrossRef] [Green Version]
  24. Patel, N.S.; Bhattacharya, P.; Patel, S.B.; Tanwar, S.; Kumar, N.; Song, H. Blockchain-envisioned trusted random oracles for IoT-enabled Probabilistic Smart Contracts. IEEE Internet Things J. 2021, 8, 14797–14809. [Google Scholar] [CrossRef]
  25. Hu, T.; Liu, X.; Chen, T.; Zhang, X.; Huang, X.; Niu, W.; Lu, J.; Zhou, K.; Liu, Y. Transaction-based classification and detection approach for Ethereum smart contract. Inf. Process. Manag. 2021, 58, 102462. [Google Scholar] [CrossRef]
  26. Tian, G.; Wang, Q.; Zhao, Y.; Guo, L.; Sun, Z.; Lv, L. Smart contract classification with a bi-LSTM based approach. IEEE Access 2020, 8, 43806–43816. [Google Scholar] [CrossRef]
  27. Chen, W.; Zheng, Z.; Cui, J.; Ngai, E.; Zheng, P.; Zhou, Y. Detecting ponzi schemes on ethereum: Towards healthier blockchain technology. In Proceedings of the 2018 World Wide Web Conference, Lyon, France, 23–27 April 2018; pp. 1409–1418. [Google Scholar]
  28. Norvill, R.; Pontiveros, B.B.F.; State, R.; Awan, I.; Cullen, A. Automated labeling of unknown contracts in Ethereum. In Proceedings of the 2017 26th International Conference on Computer Communication and Networks (ICCCN), Vancouver, BC, Canada, 31 July–3 August 2017; pp. 1–6. [Google Scholar]
  29. Wu, S.; Chen, Y.; Wang, Q.; Li, M.; Wang, C.; Luo, X. CReam: A smart contract enabled collusion-resistant e-auction. IEEE Trans. Inf. Forensics Secur. 2018, 14, 1687–1701. [Google Scholar] [CrossRef]
  30. Braghin, C.; Cimato, S.; Damiani, E.; Baronchelli, M. Designing smart-contract based auctions. In Proceedings of the International Conference on Security with Intelligent Computing and Big-Data Services, Guilin, China, 14–16 December 2018; Springer: Berlin, Germany, 2018; pp. 54–64. [Google Scholar]
  31. Wang, W.; Hoang, D.T.; Hu, P.; Xiong, Z.; Niyato, D.; Wang, P.; Wen, Y.; Kim, D.I. A survey on consensus mechanisms and mining strategy management in blockchain networks. IEEE Access 2019, 7, 22328–22370. [Google Scholar] [CrossRef]
  32. Corwintines. Gas and Fees. Ethereum 2022. Available online: https://ethereum.org/en/developers/docs/gas/ (accessed on 14 July 2021).
  33. Muchhala, Y.; Singhania, H.; Sheth, S.; Devadkar, K. Enabling MapReduce based parallel computation in smart contracts. In Proceedings of the 2021 6th International Conference on Inventive Computation Technologies (ICICT), Coimbatore, India, 20–22 January 2021; pp. 537–543. [Google Scholar]
Figure 1. Graphical representation of the probability of executing a SC given the preference of a miner.
Figure 1. Graphical representation of the probability of executing a SC given the preference of a miner.
Mathematics 10 01033 g001
Figure 2. Graphical representation of the probability of executing a SC given the SCs fees.
Figure 2. Graphical representation of the probability of executing a SC given the SCs fees.
Mathematics 10 01033 g002
Figure 3. Graphical representation of the probability of executing a SC given the SCs’ cost.
Figure 3. Graphical representation of the probability of executing a SC given the SCs’ cost.
Mathematics 10 01033 g003
Table 1. Categorical values of the smart contracts execution main features.
Table 1. Categorical values of the smart contracts execution main features.
Quantiles f x c x v t x
1LowLowBottomFirst
2Medium-LowMedium-LowFourth-bestSecond
3MediumMediumThird-bestThird
4Medium-HighMedium-HighSecond-bestFourth
5HighHighTopFifth
Table 2. A priori probabilities.
Table 2. A priori probabilities.
ClassFirstSecondThirdFourthFifth
A priori probability0.1950.2040.200.2010.197
Table 3. Techniques’ accuracy.
Table 3. Techniques’ accuracy.
Accuracy (Train)Accuracy (Test)
Naïve Bayes 43.21 % 42.58 %
Naïve Bayes (e1072) 43.21 % 42.58 %
Naïve Bayes Laplace 43.21 % 42.58 %
Naïve Bayes 43.21 % 42.58 %
Table 4. Sensitivity, Specificity, PPV, and NPV concerning SCs’ execution times classification.
Table 4. Sensitivity, Specificity, PPV, and NPV concerning SCs’ execution times classification.
SensitivitySpecificityPos Pred ValueNeg Pred Value
First0.2750.8450.3030.827
Second0.3480.7980.3080.826
Third0.2480.8250.2650.813
Fourth0.5570.8870.5550.88
Fifth0.7320.9320.7250.934
Table 5. Predicted execution time given the features of some contracts.
Table 5. Predicted execution time given the features of some contracts.
FeeCostValuationExecution Place
LowMediumSecond-bestSecond
Medium-LowMedium-HighBottomFirst
MediumMedium-HighThird-bestFirst
HighMedium-HighBottomFirst
Table 6. Conditional probabilities of time execution given the smart contracts features and miners’ valuation.
Table 6. Conditional probabilities of time execution given the smart contracts features and miners’ valuation.
CFLabelFirstSecondThirdFourthFifth
vBottom0.1960.1990.1990.2050.194
Fourth-best0.2120.1890.1940.1910.195
Third-best0.2070.2050.1980.210.207
Second-best0.1850.2020.2130.2020.211
Top0.1980.2020.1940.190.19
f x High0.210.1960.2090.1070.275
Medium-High0.2060.2050.1820.1610.227
Medium0.2110.1960.1820.2290.187
Medium-Low0.1960.1910.2080.2410.152
Low0.1750.210.2170.2580.158
c x High0.1110.0990.0970.5570.14
Medium-High0.2830.2650.2650.1820
Medium0.2740.3150.2850.1120
Medium-Low0.2520.2470.270.1050.126
Low0.0760.0720.080.0420.732
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Share and Cite

MDPI and ACS Style

Gibaja-Romero, D.-E.; Cantón-Croda, R.-M. Auction and Classification of Smart Contracts. Mathematics 2022, 10, 1033. https://doi.org/10.3390/math10071033

AMA Style

Gibaja-Romero D-E, Cantón-Croda R-M. Auction and Classification of Smart Contracts. Mathematics. 2022; 10(7):1033. https://doi.org/10.3390/math10071033

Chicago/Turabian Style

Gibaja-Romero, Damián-Emilio, and Rosa-María Cantón-Croda. 2022. "Auction and Classification of Smart Contracts" Mathematics 10, no. 7: 1033. https://doi.org/10.3390/math10071033

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop