Content uploaded by Nadeem Javaid
Author content
All content in this area was uploaded by Nadeem Javaid on Aug 20, 2021
Content may be subject to copyright.
A Consortium Blockchain based Energy Trading
Scheme for Electric Vehicles in Smart Cities
Rabiya Khalida, Muhammad Waseem Malika,
Turki Ali Alghamdib, Nadeem Javaida,∗
aDepartment of Computer Science,
COMSATS University Islamabad, Islamabad 44000, Pakistan
bDepartment of Computer Science, Col lege of Computer and Information Systems,
Umm Al-Qura University, Makkah 21955, Saudi Arabia
Abstract
The real time Vehicle-to-Grid (V2G) and Vehicle-to-Vehicle (V2V) energy trad-
ing have ameliorated the smart city environment. Electric Vehicles (EVs) in
smart cities have made it possible to balance the energy demand and supply
without burdening the power grids. They also help in minimizing both the
heap amounts of pollution and the greenhouse gas emissions. EVs not only
charge their batteries from Charging Stations (CSs), but when the smart city
faces energy deficiency, they supply their surplus energy to the power grids to
fulfill energy demand as well. In addition, EVs also balance the energy demand
and supply through energy trading at the local level during peak hours, which
strengthens V2V energy trading. However, some issues, such as security threats
and privacy leakage prevent EVs from participating in the energy trading pro-
cess. In addition, the lack of incentives and knowledge about the cost of reaching
the energy trading place within minimum time are also big challenges. There-
fore, to solve the aforementioned challenges, a secure and efficient scheme for
V2V and V2G energy trading is proposed in this paper. The proposed scheme
also helps in promoting environmental friendliness and making the smart cities
sustainable and reliable. In the proposed scheme, energy trading transactions
are secured using consortium blockchain, wherein the Local Aggregators (LAGs)
are selected as authorized nodes. LAGs perform their role as energy brokers and
are responsible for validating the energy trading requests using Proof of Author-
ity (PoA) consensus mechanism. Moreover, a solution to find accurate distance
with required expenses and time to reach the charging destination is also pro-
posed, which effectively guides EVs to reach the relevant CSs and encourages
energy trading. Besides, we propose a fair payment mechanism using a smart
contract to avoid financial irregularities. An incentive provisioning mechanism
is also given in the proposed work to prevent EVs from acting selfishly. The
efficient power flow having minimized losses in the vehicular network is of much
importance. Therefore, the energy losses incurred in both V2G and V2V are dis-
cussed in this work. Furthermore, Oyente is used for smart contract’s security
analysis and for testing Ethereum’s resilience against different security flaws.
Two attacker models are proposed and the security analyses of the models are
∗Corresponding author
Email address: nadeemjavaidqau@gmail.com (Nadeem Javaid)
Preprint submitted to Elsevier June 29, 2021
also provided. The analyses show that the proposed system is robust against
the double spending and Sybil attacks. Finally, the efficient performance of our
proposed scheme is validated and analyzed. The simulation results proved that
our proposed work outperforms existing work in terms of providing a secure and
efficient energy trading platform for both V2G and V2V environments.
Keywords: Consortium blockchain, Energy trading, Smart contract, Electric
vehicles, Smart cities
1. Introduction1
A rapid increase in the awareness of efficient use of energy and tackling2
the increasing amounts of pollution has led to the demand for reliable, secure3
and sustainable power grids. The demand further leads to the evolution of the4
traditional grids into smart grids [1]. With the advancement in information5
and communication technologies, the smart grid gets the benefit of the two-way6
flow of electricity and information. Smart grids generate energy using renew-7
able energy resources [2], which are of intermittent nature. Therefore, energy8
management plays a very important role in maintaining the sustainability and9
reliability of the smart grid. Electric Vehicles (EVs) are considered an integral10
part of energy management systems. They play a key role in balancing the de-11
mand and supply of energy in smart grids. They rely on the usage of electricity12
rather than conventional fossil fuels, which remarkably reduces environmental13
pollution and minimizes greenhouse gas emissions. The aforementioned fac-14
tors help in making the cities smart, green and sustainable [3]. For energy15
trading, Vehicle-to-Grid (V2G) and Vehicle-to-Vehicle (V2V) energy trading16
systems have emerged drastically, which enable better utilization of energy in17
the presence of scarce energy resources [4]. EVs have the ability to act both18
as energy suppliers and energy consumers in the smart transportation infras-19
tructure. This ability of EVs helps in fostering reliability and sustainability in20
smart cities [5]. EVs sense and transmit the data about their environment us-21
ing different communication technologies in a smart transportation system [6].22
The built-in On-Board Unit (OBU) allows EVs to interact with each other for23
information sharing [7]. EVs can transmit energy trading requests to other EVs24
for buying and selling energy, price prediction, load forecasting, and optimal25
energy consumption scheduling [5].26
The development of EVs has led the masses towards the smart transporta-27
tion sector as they are providing various benefits apart from the transportation28
services [8]. To balance energy demands in the smart city, energy trading sys-29
tems need to be managed efficiently and EVs must practice self-sustainability30
in the smart city [8]. EVs not only get energy from Charging Stations (CSs),31
but also from other EVs to reduce load during peak hours through V2V energy32
trading [9] at the Parking Lots (PRKs). Moreover, they supply the surplus en-33
ergy back to the CSs (V2G energy trading), when the smart city faces an energy34
deficiency [8, 9]. However, there are various challenges in both energy trading35
environments, such as security threats and privacy leakage. Therefore, to ad-36
dress the security issues, authors in [2] - [12] have used blockchain technology.37
Blockchain is an emerging Peer-to-Peer (P2P) distributed and decentralized net-38
work [13] in which data is shared among network nodes. This technology has39
2
been widely used in different fields, such as Wireless Sensor Networks (WSNs)40
[14], Internet of Things (IoT) [15], Vehicular Ad-Hoc Networks (VANETs) [16],41
[17], cloud environment [18], energy and smart grids [19], [20], healthcare, agri-42
culture [21], etc., for secure, distributed, transparent, immutable and auditable43
storage of transactions records.44
Apart from the aforementioned issues, EVs with surplus energy are not45
motivated to participate as energy sellers in the energy trading environment46
due to the lack of incentive provisioning. It causes imbalance in energy demand47
and supply in the smart city. Therefore, motivating them for energy trading is a48
vital challenge. Zhou et al. [4] proposed an incentive mechanism using contract49
theory for V2G energy trading. In this scheme, EVs receive a higher reward to50
discharge their energy at CSs. Kang et al. [2] proposed a localized P2P energy51
trading model for local energy trading among EVs to achieve demand response52
and balance localized energy demand by providing an incentive mechanism using53
an iterative double auction method with a consortium blockchain. However,54
finding the nearest CSs’ information (such as price, distance, time slot) for EVs55
remains an important issue, which needs to be tackled. Authors in [8] and [22]56
proposed energy trading models to address this issue. Jindal et al. [8] proposed57
a mechanism for EVs to find the nearest CSs. However, they used equal-sized58
blocks of the smart city, which are not suitable when dealing with random-59
sized blocks. Chaudhary et al. [22] proposed a blockchain-based secure energy60
trading scheme for EVs. The proposed schemes of [2, 4, 8, 22] do not involve61
well-defined payment mechanisms and are prone to attacks.62
Motivated by the aforementioned developed energy trading schemes, we de-63
velop such a V2V and V2G energy trading environment for EVs and CSs, which64
leverages consortium blockchain with Proof of Authority (PoA) consensus mech-65
anism and smart contract for efficient energy trading. Consortium blockchain66
provides features of both the public and private blockchains. PoA mechanism67
requires less computational power as compared to Proof of Work (PoW) and68
has maximum throughput with less latency. In our scenario, four major entities69
are involved: Registration Authority (RA), EVs, CSs, and Local Aggregators70
(LAGs). Blockchain is deployed on LAGs to keep track of energy trading trans-71
actions of EVs and CSs.72
1.1. Problem statement73
Many researchers provide solutions to manage energy demand in smart cities74
by trading energy in V2V and V2G manner. In the V2G energy trading en-75
vironment, EVs charge and discharge their batteries at CSs; whereas, in V2V,76
energy trading occurs among EVs locally. However, EVs and CSs face vari-77
ous challenges in energy trading environments, such as security threats, privacy78
leakage, finding the nearest energy trading place, and lack of incentives.79
Trust and security have always been the biggest challenges in the trans-80
portation sector. In energy trading, it is very important to authenticate energy81
trading requests. In addition, the malicious attacks by the malicious nodes82
are also a challenge in this area because some adversaries modify the transac-83
tions for their benefits, which results in the financial loss of both the CSs and84
the EVs. In the literature, blockchain is widely used in WSNs, VANETs and85
smart grid network scenarios to address security, data tampering, and request86
tampering challenges. The authors in [8, 22] proposed blockchain-based energy87
trading mechanisms for EVs. In [8], Jindal et al. proposed an edge-as-a-service88
3
framework for energy trading in the V2G environment to reduce delay in en-89
ergy trading decisions taken at remote control centers. They also proposed a90
model to find the nearest CSs for an EV to save both energy and traveling time.91
Chaudhary et al. [22] proposed a blockchain-based secure energy trading and92
minimum distance finding scheme for EVs. However, both schemes failed to93
achieve accurate distance in the random-sized city blocks. In both schemes, the94
authors selected the EVs as miner nodes to validate the energy trading requests95
using the PoW consensus mechanism. However, EVs cannot perform the role of96
miners due to their limited resources [23]. Moreover, the PoW consensus mech-97
anism also requires a huge amount of computational power. Apart from that,98
the proposed schemes do not involve well-defined payment mechanisms and are99
prone to attacks. Additionally, no incentive mechanism is provided in [22] to100
motivate EVs to sell their surplus energy to CS while meeting the energy de-101
mand. Kang et al. [2] proposed a localized P2P energy trading model for local102
energy trading among EVs to balance localized energy demand by providing an103
incentive mechanism using iterative double auction method with a consortium104
blockchain. In [2] and [22], Transaction Server Controller (TSC) aggregates the105
requests of energy sellers and buyers from the local server and selects the pairs106
of sellers and buyers based on the auction price. However, no mechanism is107
specified to determine the locations of buyers and sellers to check either they108
are requesting from the same area or from different areas. We have discussed109
solutions to the aforementioned challenges in Section 3.110
1.2. Our contributions111
Our contributions in this paper are summarized as follows:112
consortium blockchain is deployed along with PoA consensus mechanism113
on the LAGs for secure energy trading,114
smart contracts are designed to ensure fair payment between EVs. More-115
over, an incentive mechanism is proposed to encourage EVs to participate116
in energy trading. Besides, a punishment mechanism is developed to pre-117
vent EVs from acting maliciously,118
an algorithm is developed for energy trading in which EVs find the list of119
the nearby CSs or PRKs with information about distance, required time120
and energy expenses to reach the destination in both V2V and V2G energy121
trading environments,122
the power flow in the vehicular network and the associated energy losses123
are discussed and124
this study designs two attacker models based on the double spending and125
Sybil attacks. Security analyses of the models show that the proposed126
system is robust against both attacks. Also, Oyente symbolic execution127
tool is used for smart contract’s security analysis, which is able to test128
common and well-known latest security flaws of Ethereum with Ethereum129
Virtual Machine (EVM) byte code.130
4
1.3. Organization131
In Section 2, the literature review of existing work on blockchain based132
energy trading is discussed. Section 3 describes our system model and problem133
formulation. Whereas, security objectives and analysis, and attacker models are134
given in Section 4. Simulation and discussion of results are given in Section 5.135
Finally, the conclusion of this paper is presented in Section 6.136
2. Related work137
During the past few decades, researchers are actively working in the area of138
the intelligent transportation system in research with the development of smart139
cities. The major aim behind this research is to make the cities smarter and140
greener. Using electricity instead of conventional fossil fuels helps in cutting141
down the heap amounts of pollution and greenhouse gas emissions. It leads to142
reliability and sustainability of the cities. In the literature, many solutions are143
proposed related to traffic management and smart energy management. The144
usage of EVs in smart cities has made it possible to balance the demand for145
electricity without relying on the power grids [8]. EVs are able to exchange their146
energy with the smart grid and are also used as a carrier to fulfill the energy147
requirements in smart cities.148
In literature, much work has been done on different aspects of promoting149
both V2G and V2V energy trading in the smart transportation sector. The fun-150
damental aims behind such work are to make the cities greener, reduce pollution,151
minimize greenhouse gas emissions, promote reliability and sustainability, etc.152
Chaudhary et al. [22] proposed a secure and efficient energy trading scheme153
for EVs using blockchain technology in Software Defined Networking (SDN)154
enabled Intelligent Transportation System (ITS). In this scheme, the authors155
provided real time processing of the energy trading ecosystem. They also ad-156
dressed conventional and centralized security issues. Wang et al. [23] addressed157
the external and internal adversarial attacks using the blockchain technique158
and developed a Proof of Reputation (PoR) consensus mechanism to improve159
selected validator’s security based on trust and credibility computing. In [24],160
authors considered different charging infrastructures in which the EVs can be161
charged. These infrastructures are compared using various performance param-162
eters, which prove that the proposed distributed infrastructure outperforms the163
other two. Moreover, three different charging strategies are also considered in164
the work in terms of load profiles and cost.165
In order to balance and stimulate energy demands in the smart city through166
EVs, Kang et al. [2] proposed a localized P2P energy trading model for local167
energy trading among EVs. In this scheme, the authors achieved demand re-168
sponse by providing an incentive-based mechanism. The role of an aggregator at169
PRKs also needs further consideration. Keeping this in mind, authors in [3] dis-170
cussed the multi EV charging scenarios in residential PRKs. The fast-charging171
services are further compared with slow-charging services in the proposed work.172
A real time planning approach being adopted by the EV users to alternate be-173
tween slow-charging and fast-charging services is also discussed in a stochastic174
manner. Zhou et al. [4] proposed a secure energy trading framework for EVs,175
using consortium blockchain technology. In this scheme, the authors proposed176
a contract theory-based incentive mechanism to motivate EVs to participate in177
5
an energy trading environment. Gao et al. [5] proposed a blockchain-based pay-178
ment mechanism for the V2G energy trading environment. They also introduced179
a registration scheme to secure users’ sensitive information.180
Jindal et al. [8] proposed an edge-as-a-service framework for energy trading181
using blockchain technology in the V2G environment. In this scheme, authors182
reduce delay and network overhead issues in communication using SDN. They183
also provided the nearest CS’s location with its distance and required time from184
an EV’s current location. Li et al. [9] proposed a blockchain-based energy trad-185
ing scheme to achieve security and privacy and improve trust and transparency186
in energy trading environment. They also introduced credit-based payment and187
loan schemes to support fast and frequent energy trading in the industrial Inter-188
net of Things (IoT). Zhou et al. [25] proposed a V2G energy trading framework189
using consortium blockchain for providing efficient and secure energy trading190
transactions. They also proposed an incentive mechanism using contract the-191
ory for V2G energy trading environment. In this scheme, EVs gained higher192
rewards to participate in discharging their energy at CSs.193
In [26], a decentralized security model is presented to ensure the security of194
energy trading between EVs in a P2P network. The work also aimed at schedul-195
ing the EVs’ charging time in an efficient manner using a realistic infrastructure.196
Authors in [27] proposed a trust based scheme for VANETs. The proposed work197
ensured locational privacy and identity protection of EV users. The trust man-198
agement method was devised based on Dirichlet distribution. The proposed199
scheme efficiently detected malicious EVs and removed them from the network.200
Dorri et al. in [28] proposed a blockchain based model for promoting the secu-201
rity of users and privacy of the vehicular network. The costs incurred due to202
the wireless software updates and EVs’ insurance are also included and dealt203
with in the proposed work. The service quality linked with wireless software is204
used to illustrate the efficiency of the proposed model.205
A V2G data trading and sharing method is proposed in [29]. To address the206
issues of high computations and high cost of mining for microtransactions, a new207
protocol based on directed acyclic graph network is proposed. The protocol is208
suitable for lightweight transactions between network nodes. The negotiation209
about data sharing and energy trading between EVs and the grid is carried210
out using a game theory based model. The model optimizes the cost of the211
negotiation, which makes the proposed method efficient. The authors in [30]212
present a survey on applications of blockchain in the energy sector. In the213
survey, a deep analysis is provided on how blockchain is used in the energy sector214
so far and what are its possible future applications. The authors discuss the215
applications of blockchain in energy trading between vehicles, V2G, vehicles, and216
CSs, prosumers, etc. The existing models are studied, and a detailed discussion217
is provided to make the reader aware of the security and privacy challenges of218
blockchain. It is concluded that the blockchain technology is revolutionizing the219
traditional energy trading mechanisms and it is playing a vital role in improving220
the power system. Apart from the positive aspects of blockchain, it also suffers221
from different types of attacks. Feather forking attack is one of them [31]. In222
this type of attack, a minor node refuses to mine a block containing a specific223
transaction. The Reason for a minor’s this kind of behavior can be that it may224
dislike the transaction or the node who is involved in the transaction. So, by225
refusing to mine the block it tries to blacklist the node or transaction. In [31],226
the feather forking attack is handled.227
6
All the aforementioned schemes have some limitations. The schemes are228
either based on the energy trading between EVs or the V2G trading system.229
The existing schemes and their limitations are given in Table 1. In this paper,230
we propose an energy trading mechanism for V2V and V2G environments to231
get better energy trading results in the smart city. The working of our proposed232
scheme is described in detail in Section 3.233
3. System model234
In this section, we describe the proposed system model in detail, as shown235
in Figure 1.236
3.1. Consortium blockchain for energy trading237
Blockchain networks are of three different types, which are public, pri-238
vate and consortium. A public blockchain is also known as a permissionless239
blockchain where everyone joins the network and participates in generating the240
blocks. Whereas, private and consortium blockchains are permissioned where no241
one can join the network without permission. Moreover, in a private blockchain,242
only a single organization has control over the entire blockchain network. Unlike243
private blockchain, the consortium blockchain provides some access rules to join244
the network. We select consortium blockchain in our proposed system because245
it inherits security features from public blockchain and its network access is246
similar to private blockchain.247
In the blockchain, the consensus process is quite important and it is used248
to verify the transactions before adding them in the blocks. In this work, the249
PoA consensus mechanism is used in which a validator is selected to validate250
transactions on the basis of the reputation values. In our proposed scheme, all251
LAGs are selected as validator nodes. Moreover, PoA requires less computa-252
tional power than PoW. A smart contract is a computer protocol that digitally253
facilitates and validates transactions and contract negotiations happening in the254
blockchain network. A smart contract allows the reliable execution of transac-255
tions without the involvement of a third party. We have used smart contracts in256
our proposed scheme to provide an efficient payment mechanism. By using the257
smart contracts, we first obtain the wallet addresses of energy sellers and buy-258
ers and then energy coins are transferred between them at a predefined energy259
price.260
3.1.1. The proof of authority consensus mechanism261
In the existing PoW consensus mechanism, a hash-based mathematical puz-
zle is solved by nodes with high computational resources. Moreover, the hash-
based puzzle is formulated as [32]
SHA256(SHA256(h, s)) <target,(1)
where his the content of the blockchain, sis the solution that solves the puzzle
and “target” is the level of difficulty for block mining. Because of the high
computational resources required to execute PoW consensus mechanism, it is
not suitable for our proposed scenario. Therefore, in this study, a new PoA
consensus mechanism based on the reputation of nodes is used. In PoA con-
sensus mechanism, reputation of each node is calculated instead of solving the
7
Table 1: Literature review
Techniques Goals Achievements Limitations
Blockchain technology with
PoW consensus mechanism [2]
Efficient localized P2P energy
trading
Improve localized demand re-
sponse in plug-in hybrid EVs
High computational power
consensus is used
Aggregator of EVs at residen-
tial PRKs [3]
Lower the charging cost and se-
lect the best charging service
Real time stochastic planning
approach is introduced for EV
users
Time complexity
Consortium blockchain tech-
nology with contract theory [4]
Provide incentive mechanism
to motivate EVs in Internet of
EVs
Energy trading framework is
designed for EVs
Security issues, and Sybil and
Re-Entry attacks are ignored
Hyperledger blockchain tech-
nology using proof of concept
consensus mechanism [5]
Privacy-preserving payment
mechanism for V2G network
Privacy preservation of data,
and reliable and efficient pay-
ment mechanism is achieved
Prone to differential attack
Blockchain with PoW, edge
nodes and SDN [8]
Reduce delay and network
overhead issue, decisions mak-
ing and provide nearest CS
with distance and required
time
Provide trading decisions
closer to EVs’ location using
edge nodes and SDN for
decreasing network latency
Accurate distance measure-
ment issue and not well defined
payment mechanism is given
Blockchain using PoW consen-
sus and SDN [22]
Real time processing for en-
ergy trading, overcome secu-
rity risks and reduce latency
Increase the overall security,
use SDN to transfer EVs re-
quest to global SDN controller
Wallet is not secure, EVs selec-
tion as miner to perform PoW
is tedious
Blockchain with Proof of Rep-
utation (PoR) consensus mech-
anism [23]
Safeguard against internal and
external attacks, and awing to
the selfishness EVs
Overcame security risks and
provide incentive mechanism
Focus only on EVs’ reputation
Different charging infrastruc-
tures for EVs [24]
Differentiate between various
charging infrastructures
Superiority of smart charging
is achieved over dumb charging
Time complexity and security
issues are not handled
Blockchain with edge comput-
ing and contract theory [25]
An efficient and secure energy
trading in V2G
Incentive-based V2G energy
trading framework is provided
CPA and CCA attacks are not
tackled
Blockchain technology in P2P
environment [26]
Scheduling of EVs’ charging Enhanced security and efficient
charging scheduling
Time complexity
Blockchain-enabled privacy
protection scheme in VANETs
[27]
Location privacy of EVs and
trust management
Trust based location privacy
protection scheme is developed
Security analysis is not per-
formed
Blockchain based architecture
in vehicular ecosystem [28]
Protect users’ privacy a secure vehicular architecture
is established
Trust issues are not handled
8
PRK
1
EV1
b
Blockchain
2
LAG
1
CS
2
RA
2
13
4
CS
1
EV2
s
EV1
s
PRK
1
EV3
s
EV2
s
RA
Number of Local Aggregators
LAGn
Number of Charging Stations
CSn
Number of EV Energy Buyers
EVn
b
Number of EV Energy Sellers
EVn
S
Number of Parking Lots
PRKn
Present State of Charging
Registration Authority
Peer-to-peer Connection
Two Way Communication
Figure 1: Proposed system model for energy trading. 1LAGs are interconnected in a P2P
manner, all energy trading transactions are stored, audited and verified by the authorized
LAGs. 2CSs send the energy trading request to the LAGs. They reply back with the
notification. 3Seller EV sends the energy selling request form PRKs to LAGs. 4Buyer EV
gets the information of nearest energy seller with distance and required time and expenses.
hash-based mathematical puzzle. The key idea of PoA consensus mechanism is
that a node rates another node based on direct interaction. In the blockchain,
each node has an asset known as Reputation Point (RP) that is needed be-
fore any transaction is completed. RP is dynamically determined based on the
Computation Factor (CF) as
CF =(θ
Pn
i=1 θi,if ρ > Φ,
0,otherwise, (2)
where CF lies within 0 and 1. nis the total number of nodes in the network, θ
is the number of computational resources each node has, which is determined by
hash rate and ρ∈[0,1] is the defined threshold that regulates malicious activities
of a node. It is also used as the threshold for determining the double spending
and Sybil attacks. Pn
i=1 θirepresents the overall computational resources of the
network and Φ is the defined reputation threshold (i.e., Φ ∈[0,1]). If CF > 0,
then it means that the node is eligible to rate another node and vice versa.
Based on CF value, the reputation of each node is calculated as
Reputation = CF ×rate,(3)
rate = (1,if there is an honest interaction,
0,otherwise. (4)
The mining task of each node in the blockchain network is given as
SHA256(SHA256(h, s)) <Reputation ×target.(5)
9
3.1.2. Creation of blocks and selection of miners262
In the proposed blockchain, three types of nodes are considered: ratee, rater263
and validators. The ratee is any node that receives ratings; whereas, a rater is264
any node that rates other nodes. Both rater and ratee nodes accept and relay265
ledger data in the blockchain. Validators are nodes with high reputation values266
while a node with the highest reputation value is the leader of the blockchain.267
Before any data is recorded in the blockchain, it is digitally signed, hashed and268
encrypted by the leader of the network. The signed data is encapsulated as269
transaction in the blockchain. At any given time, all nodes have the same copy270
of the ledger and they become miners if their reputation values are greater or271
equal to Φ. Any node with reputation value less than Φ will not participate272
in the block mining and validation processes. Once the transactional data of a273
node is received by the leader, each validator verifies the signature by comparing274
it with the previous created block. If the verification is successful, then K∈N275
confirmation messages are broadcasted by validators. Afterwards, the leader276
provides the necessary services to the concerned node. A block is published if277
there are more than Kconfirmation messages received; otherwise, the block is278
not published. The theorems and proofs given in this study are used to validate279
the theoretical assumptions of the proposed model.280
Theorem 3.1. The proposed PoA consensus mechanism solves the miner cen-281
tralization problem.282
Proof 3.1. The proof of Theorem 3.1 is given as follows. A miner central-283
ization problem occurs when the same leader is selected at different polynomial284
time. Thus, the entire system is not secure. The proposed PoA consensus mech-285
anism solves this problem based on CF , which means that at a given polynomial286
time t1, the probability for selecting a leader is 1
n. In subsequent polynomial time287
t2, another leader will be selected with the same probability. It implies that C F288
of a leader changes on the basis of ρ > Φ. Besides, θof each node is different.289
Thus, the proposed PoA resolves the miner centralization problem.290
Theorem 3.2. There is no similar reputation value for different nodes when291
using the proposed PoA consensus mechanism.292
Proof 3.2. The proof of Theorem 3.2 is given as follows. A node is given293
high score when it engages in an honest interaction with other nodes and vice294
versa. Thus, the behavior of a node influences its reputation value. When a295
node behaves honestly, its rate value is 1; otherwise, it is 0. This means that the296
reputation of a node depends on CF and rate value. Moreover, no two nodes297
have the same CF , which means that θvalues of the nodes are different. Thus,298
their reputation values can never be the same. Therefore, the proposed PoA299
consensus mechanism provides different nodes with reputation values that are300
not similar.301
Theorem 3.3. The proposed PoA consensus mechanism is robust against honest-302
but-curious nodes’ behavior.303
Proof 3.3. From Proof 3.2, it is clearly proven that the behavior of a node304
influences its reputation. It implies that at a given time, a node behaves honestly305
and at other time, its behaves dishonestly in order to exploit the vulnerability of306
10
the proposed system. Based on the proposed PoA consensus mechanism, once307
a node has been detected to exhibit dishonest behavior, its gets the rate value of308
0. Moreover, the defaulter node is penalized through reputation degradation and309
energy coin deduction. Thus, the proposed PoA consensus mechanism is robust310
against honest-but-curious behavior of a node.311
3.2. Work flow of the proposed system312
A typical scenario of our proposed model is illustrated in Figure 1. There313
are four major entities in the proposed model, which are RA, CSs, EVs and314
LAGs. In our proposed scheme, CSs and EVs both act as energy sellers and315
buyers to participate in energy trading. RA is responsible for the registration316
of both EVs and CSs. Moreover, it also generates public (PK) and private (SK)317
key pairs to authenticate the nodes in the network. Both CSs and EVs register318
with RA to become bonafide nodes. As shown in Figure 2, the step-wise flow319
of the proposed system model is described as follows.320
Step 1: in the first step, a CS denoted as Ui, and an EV represented as Vj,321
with real identities IDiand I Djjoin the energy trading system. iand jare322
the indices of a CS and an EV, respectively. All LAGs are interconnected in a323
P2P manner to store, audit and verify the energy transactions.324
Step 2: after joining the network, RA provides unique PK and SK key pairs325
to all participants for allowing them to participate in the energy trading envi-326
ronment.327
Step 3: in this step, seller EV sends the energy selling request from PRKs to328
LAGs. In this manner, the surrounding EVs and other entities come to realize329
that which entities are available for energy selling.330
Step 4: in this step, both Uiand Vjrequest for wallet addresses from the RA.331
RA generates a mapping list based on requests of both EVs and CSs, and pro-332
vides wallet addresses to them.333
Step 5: in this step, the coordinates of EVs and other charging entities are334
recorded, which further help in calculating the distance between different enti-335
ties. Buyer EV gets the nearest charging entity’s information with the required336
time, distance and expenses.337
Step 6: after the energy transaction takes place, energy coins are stored in the338
wallets in this step. These wallets have specified addresses and are accessible339
through the smart contract during energy trading.340
LAGs are considered as edge nodes with increased communicating and com-341
puting capabilities, which perform their role as energy brokers to provide in-342
formation about the nearby places where energy trading is to be performed.343
LAGs are interconnected in a P2P manner and blockchain technology is de-344
ployed on them. LAGs aggregate the energy trading requests from CSs and345
EVs to store, share and audit energy. Using the PoA consensus mechanism,346
trading transactions are verified and shared among LAGs.347
In a smart city, CSs and PRKs are deployed at various locations. EVs need to348
travel some distance to reach any CS for charging or discharging their batteries.349
For this purpose, EVs want to know the required parameters, such as required350
distance (Distrq ), required time (Trq ) and required expense (Erq ) to reach a351
destination for getting charged at better energy prices with maximum benefits352
[8]. Therefore, EVs send the request to LAGs to find the nearest CSs. LAGs353
then provide a list of nearest CSs with Distrq ,Trq and Erq . An EV selects the354
preferable CS for energy trading according to the aforementioned parameters.355
11
CSs and EVs become
part of the vehicular
network
Coordinates of EVs
and CSs are
recorded and the
distance between
them is calculated
Energy transaction
takes place and
energy coins are
stored in the wallets
The energy selling
buying requests are
broadcasted in the
network
RA provides a PK
and SK key pair to
the new entities
Wallet addresses
are assigned to all
EVs and CSs
Figure 2: Workflow of the proposed system model
LAGs carry the information of the pairs of energy sellers and buyers and send a356
notification to respective EVs and CSs regarding energy trading. During energy357
trading, smart contract calculates and records the energy amount in real time358
and then transfers coins accordingly. Finally, the buyer makes payment to the359
seller in response to the fulfillment of its requirement through the corresponding360
LAG.361
In our proposed scheme, CSs and EVs are divided into two groups, which362
are sellers and buyers. The entire process of energy trading is described in363
Algorithm 1 where CSs and EVs select their roles according to the present364
State of Charging SoC pr . Seller EV (EV s), having surplus energy, sends the365
request to the nearest LAG for getting the list of nearest CSs. In Algorithm 1,366
the first two lines are for declaring Input and Output. The request must be sent367
with IDi, Role (R), Location (Loccur ), SoCpr, Battery Capacity (Bcap) and368
Time of Stay (Tstay). The lines 4 and 5 calculate Present Energy Units (Epr
kw )369
and Available Energy (Eav
kw ), respectively using Equations 6 and 7. While, line370
7 calculates and Required Energy (Erq
kw ). Whereas, the lines 8 to 27 give the371
Nested−if loop in which the energy prices given by different CSs are recorded372
and then EV s are informed with these recorded prices. A LAG verifies whether373
Eav
kw units are more than 10 kw or not. If Eav
kw are less than the required amount,374
then the energy request is discarded; otherwise, the Algorithm 1 moves to the375
next step. Lines 28 to 32 calculate the Energy Sale Price (Ps
i) using Equation376
8 [8], find the exact location and store the results in transactions pool. The last377
set of lines in the algorithm, i.e., lines 33 to 49 again present a N ested −if378
loop, which first retrieves the energy requests from the transactions pool and379
then matches the EV with a preferable charging entity.380
Epr
kw =SoC pr
100 xBcap,(6)
Eav
kw =Bcap −Epr
kw ,(7)
Ps
i=aBcap
Epr
kw −Eth ,(8)
12
where Eth is a threshold value. We select 30 percent constant value for Eth
381
based on SoC for each EV’s battery and ais used for constant price value,382
which is equal to 0.32. However, Eth and acan be different in practice. In our383
proposed technique, we measure the Distance (Dist) using trusted third-party384
services, such as GPS, which provide accurate Dist by calculating the road’s385
length from EV’s Loccur to CS’s Loccur. LAG finds out the nearest CSs and386
broadcasts the EV’s energy demand to CSs with Ps
iand Eav
kw . If any CS accepts387
the request, LAG creates the pair of EV and CS. After that, the smart contract388
is executed between the selected EV and CS. In Figure 3, the execution of smart389
contract designed for payment method is shown.390
Smart Contract
1
22
3
Wallet of Seller EV
Wallet of Buyer EV
Figure 3: Energy trading using smart contract. 1LAG sends the confirmed pair to the seller
and buyer EVs. 2Smart contract runs and accesses addresses of both seller’s and buyer’s
wallets. Smart meter calculates the energy amount and sends the recored values to smart
contract. 3Smart contract transfers energy coins, and transaction stored and shared among
LAGs.
The smart contract accesses and verifies the seller’s and buyer’s wallet ad-391
dresses as given in Algorithm 2. Energy coins are provided to the seller ac-392
cording to the traded energy through the corresponding LAG using the smart393
contract. If energy coins are available, then the smart meter records the real394
energy amount and asks for the energy from the seller. The seller then transfers395
the energy to the buyer and gets required payment. The energy buyer also gives396
ratings to the seller for the fulfillment of its satisfaction. The LAG stores the397
validated transactions in the consortium blockchain ledger, which is shared by398
all LAGs.399
CS also sends the energy trading request to the LAG with IDi,R,Loccur ,400
SoC pr ,Bcap and Present Time Slot (Tslot). If value of SoC pr is up to SoCth ,401
then LAG performs PoA consensus mechanism to validate the transactions and402
store them in blockchain. Otherwise, LAG discards the energy request and403
sends the notification back to CS.404
13
Consequently, we describe the buyer’s energy trading process, when a buyer
EV (EV b) sends the request with required parameters to the LAG to find the
nearest available CS or PRK. LAG verifies the energy trading request and cal-
culates the distance from buyer’s location to seller’s location. After measuring
Dist, LAG provides the list of nearest CS and PRK with Distrq ,Trq ,Erq and
Ps
ito the EV.
Exrq =Disti,j
1000 xPs
i
8.21.(9)
In Equation 9, the calculated Disti,j is given in meters, we divide it by 1000 to405
get values in kilometers and with the help of provided information by [33], we406
are able to estimate that an EV travels at least 4.0 kilometers and maximum407
8.21 kilometers using energy of 1 kWh. The selected type of EVs and their408
properties for our proposed scheme are given in Table 2. Based on the provided409
information, we select the maximum energy consumption value that is 8.21410
kilometers.411
In the proposed model, an EV selects the preferable energy trading place from412
the list of available energy selling places based on the distance. LAG creates413
the pair of both buyer and seller and sends the notification for energy trading.414
As we explained above, a smart contract is executed during energy trading and415
smart meter calculates and records the energy units and price. Smart contract416
accesses the wallet addresses of both seller and buyer and according to the417
smart meter’s calculation, while coins are transferred from buyer’s wallet to418
seller’s wallet as shown in Figure 3. Finally, smart contract is executed and419
transactions are stored and shared among LAGs. Table 3 shows 1-1 mapping420
of the limitations identified in this work with their proposed solutions. In the421
table, the limitations are denoted as L.1-L.5. While, the proposed solutions are422
referred as S.1-S.5.423
3.3. Incentive provisioning and punishment mechanism424
In the proposed system model, EVs are provided with incentives based upon425
their reputation values. The aim of the incentive mechanism is to encourage the426
network node to participate in energy trading process. The reputation values of427
EVs further depend upon the credibility of the messages provided by the EVs.428
Moreover, the incentives are also given by the EVs to the charging entities upon429
efficient fulfillment of the energy requirements. The incentives ensure that no430
entity in the network act selfishly or maliciously. If any entity in the network431
act maliciously, it will not be given any incentive. Figure 4 shows the flowchart432
of the incentive provisioning mechanism used in this work. The flowchart starts433
with the authorization verification of an EV. If an EV is verified, then the434
credibility of the message broadcasted by that EV is checked. Else, the EV is435
marked as malicious. Later, if the received message is found to be credible, then436
the EV is awarded with incentives; else, it is not awarded with an incentive.437
In this study, each node in the blockchain network has different behavior438
orientations. It means that the node may behave selfishly for the purpose of en-439
dangering the network. A malicious node affects the stability and reliability of a440
network. It attempts to paralyze the network and also injects fake information.441
In a blockchain network, a malicious node tries to access and alter the infor-442
mation in an illegal way. Moreover, it creates fake transactions and flood the443
transaction pool with invalid transactions. As a result, the computational power444
14
Algorithm 1: Energy trading request
1Inputs: IDi,j, Ri,j , Loccur
i,j , SoC pr, Bcap, and T slot
2Output: Confirmed Pair
3Epr
kw =SoC pr
100 xBcap
4Eav
kw =Bcap −Epr
kw
5//calculate the required energy by EV
6Erq
kw =Bcap −Epr
kw
7if Rtype := EV s
ithen
8Eth =30
per xBcap
9if Eav
kw >10kw then
10 Loc =Loccur
i
11 Ps
i=aBcap
Epr
kw−Eth
12 //compute price
13 geocode(Loc)
14 // This function is called to get the nearest CSs.
15 for k=1 to No. of nearest CSs do
16 price announced to nearest CSs;
17 end
18 if CS select EV’s Request then
19 i, j pair confirmed
20 else
21 request stored in transactions pool with Loccur
iand Ps
22 end
23 else
24 reply: present energy is very low
25 end
26 end
27 if Rtype := CSs
jthen
28 Ps
i=aBcap
Epr
kw−Eth
29 geocode(Loc)
30 request stored in transactions pool with Loccur
iand Ps
31 end
32 if Rtype := EV b
ithen
33 get requests from transactions pool with seller’s Loccur
iand Ps
34 for j=1 to last 10 requests do
35 get Locsand Ps
36 Distrq
i,j =gmaps.distance matrix(Locb
i, Locs
i,j )
37 Exrq = (Disti,j /1000)x(Ps/8.21)
38 end
39 announce Exrq, Distr q
i,j , T rq and P sto buyer EV
40 if EV selects preferable CS or EV then
41 buyer and seller pair is confirmed
42 pair is sent to smart contract for energy trading
43 else
44 request discarded
45 end
46 else
47 send reply: select your energy trading role
48 end
15
Algorithm 2: Energy trading smart contract
1Inputs: IDs
i, IDb
iverif y(IDs
i)
2verif y(IDb
i)
3wallets=access wallet address according to IDs
i
4walletb=access wallet address according to IDb
i
5event Sent(from, to, amount)
6transf erEnergyCoin(wallets, walletb, P s
kw , Ekw){
7amountpayable =Ps
kw xEkw
8if amountpayable > balance[walletb]then
9insufficient balance please buy coins
10 end
11 balance[walletb]−=amountpayable
12 balance[wallets] + = amountpayable
13 emit Sent(sender, receiver, amountpayable)
14 }
Table 2: Different type of EVs
EVs type Battery capacity Range Consumption
Type 1 42 kWh 345 km 8.21 km/kWh
Type 2 30 kWh 160 km 5.3 km/kWh
Type 3 90 kWh 360 km 4.0 km/kWh
Type 4 75 kWh 496 km 6.61 km/kWh
Table 3: Mapping of limitations with proposed solutions
Limitation
number
Limitation identified Solution
number
Proposed solution
L.1 Excessive resource con-
sumption using PoW
consensus mechanism
S.1 PoA consensus mech-
anism used
L.2 Accurate distance mea-
surement
S.2 GPS used to measure
the distance
L.3 Energy coin wallets not
secured
S.3 Smart contract used
to ensure security
L.4 Excessive time consump-
tion by miners while se-
lecting EVs
S.4 Mining performed by
LAGs and EVs are se-
lected
L.5 Robustness against at-
tacks
S.5 Security analysis done
using Oyente
and time of validator nodes is wasted. Additionally, several attacks are gener-445
ated by malicious nodes in a blockchain network, 51% attack, double spending446
attack, selfish mining attack, sybil attack, replay attack, etc., which endanger447
the security, immutability, and decentralization of blockchain. If the number448
of malicious nodes increase in the network, the network is comprised. For ex-449
ample, if more than 50 percent of the blockchain nodes become malicious then450
51% attack can be generated, and malicious nodes will take over the blockchain451
16
network. So, an efficient mechanism is required to discourage the malicious ac-452
tivities of nodes in the network. In the literature [34, 35, 36], malicious nodes453
detection and removal mechanisms are proposed. In [34, 36], the vehicles are454
rated by other vehicles after providing the services. However, only service re-455
ceivers rate the service providers. In case of a malicious service receiver, the456
honest service provider will suffer. In [36], when the reputation score of vehicles457
decreases a certain limit, they are excluded from the network. On the other458
hand, in [34], the vehicles are temporarily banned from the network; however,459
it is not mentioned how vehicles will rejoin the network. Moreover, in [36], the460
reputation of vehicles is not updated on each transaction. After a fix interval,461
the reputation values of all vehicles are computed. So, the reputations of those462
vehicles is also computed, which did not take part in the transactions. It wastes463
both the computational time and efforts of the validator nodes. Additionally,464
a malicious node detection and avoidance mechanism is proposed in [35]. Here,465
the vehicles are identified as malicious on the basis of their past encounter with466
other vehicles. The malicious vehicles are removed from the network. Keeping467
all these points in view, a new malicious vehicles identification mechanism is468
proposed.469
In the proposed scenario, once a node is detected to commit fraudulent ac-470
tivities (i.e., malicious node), its Attitude Correction Factor (ACF) is degraded471
and a certain amount of coin is charged. In the strategy, an ACF is defined by472
the leader of the blockchain, which ranges between 1-10. The proposed system473
provides a way where the selfish or fraudulent nodes’ behavior can be reme-474
died through an attitude enhancement strategy, i.e., the selfish nodes are not475
removed from the network on their first malicious activity like [35]. It is nec-476
essary because an honest node may unknowingly commit a malicious activity477
and removing such node will not be fair. On a malicious activity, ACF value of478
the node degrades by 2 points and its reputation value becomes zero. Now it479
cannot take part in validation process; however, it can still participate in energy480
trading. With each valid transaction, the ACF score of the node increases by481
one point. When the ACF value of the node reaches 10, it means that the node’s482
selfish behavior has been remedied; thus, its reputation value starts increasing.483
On the other hand, if the node keeps on committing malicious activities, its484
ACF score decreases by 2 points. If the ACF of the node becomes less than485
or equal to 1, it implies that the node’s selfish behavior cannot be remedied;486
thus, the selfish node is blacklisted and its information is broadcasted over the487
network. Note that the ACF value is determined by the consensus of the leader488
and all validators. Therefore, a single validator or leader cannot manipulate the489
ACF value like [34, 36]. When a nodes acts maliciously, its ACF is reduced by490
2 points. However, when it acts normally its ACF is increase 1 points. In this491
way, a malicious node get chance to avoid the malicious activities.492
3.4. Power flow in vehicular networks493
In vehicular networks, efficient flow of information between different entities494
like EVs, CSs, Road Side Units (RSUs), etc., plays an important role. Moreover,495
lossless flow of power is also encouraged between EVs and other entities in496
vehicular networks. The charging of EVs in vehicular networks must be done in497
such a manner that minimum economic and power losses should be incurred [37].498
Otherwise, serious economic impacts in terms of infrastructure degradation,499
excessive power loss, increased charging rates, etc., are to be faced. These losses500
17
Start
Is EV
authorized?
Credible?
Give incentives Discard message Don t give
incentives
Stop
Yes
Message
received?
No
Mark EV as
malicious No
Yes
No
Yes
Figure 4: Flowchart of incentive provisioning
are further comprised of many other losses like cable loss, transformer loss,501
hysteresis loss, I2Rloss, etc. These losses are not just confined to a certain502
strategy, scheme or area, they exist everywhere, and in both V2G and V2V503
environments.504
3.5. Associated energy losses505
In Figure 5 the energy losses associated with the charging of EVs using V2G506
and V2V energy trading environments are shown. There exist different types507
of energy losses, which are broadly classified into three main classes: Grid loss508
Gloss, Vehicle loss Vloss and Infrastructure loss Iloss. The grid losses comprise of509
all the faults, which occur at the CSs like transformer loss, circuit breaker loss,510
copper loss, I2Rloss, etc., [38]. Whereas, the vehicle losses include the ones,511
which occur in the EVs like battery loss, inverter loss, etc. The infrastructure512
18
loss includes the cable loss, current loss and those caused by severe weather513
effects.
V2I
V2I
V2G
Electric Vehicles
Charging Station
Road Side Unit
V2G Communication
V2V Communication
V2I Communication
Associated losses
Loss 1. Grid losses
Loss 2. Vehicle losses
Loss 3. Infrastructure losses
Loss 3
Figure 5: V2G and V2V energy losses
514
3.6. Mathematical formulation of energy losses515
In this subsection, the energy loss associated with the power flow in both
V2G and V2V are mathematically formulated. As already discussed above that
there exist three different types of energy losses, which are Gloss,Vloss and
Iloss. All of these losses are summed up to provide us with the Total Power
Loss Ptotal
loss , given in Equation 10.
Ptotal
loss =Gloss +Vloss +Iloss.(10)
These losses are individually formulated in Equations 11-13 below.516
Gloss =transf omerloss +lineloss +miscloss ,(11)
19
Vloss =inverterloss +batteryloss,(12)
Iloss =cableloss +currentloss +weatherloss.(13)
During mathematical formulation of any phenomenon, the objective function517
and the subjected constraints must be kept in mind. Keeping this in view, the518
objective function is formulated to minimize the Ptotal
loss , given in Equation 14.519
The objective function can be achieved using updated and efficient grid infras-520
tructure, charging cables, vehicle inverters and batteries, increased insulation521
for protection against severe weather effects, etc.522
Obj ective F unction = min(Ptotal
loss ).(14)
Subjected to constraints provided in Equations 15 - 20 .523
16Amp ≤It≤32Amp, (15)
0% < transf ormerloss ≤5%,(16)
0% < lineloss ≤10%,(17)
0% < inverterloss ≤40%,(18)
0% < batteryloss ≤30%,(19)
0≤weatherloss ≤1.(20)
The total losses occurred in both V2G and V2V energy trading environments524
are given below in terms of two Cases. Cases 1 discusses the energy losses in525
V2G, whereas Case 2 presents the losses incurred in V2V. The mathematical526
formulation is also provided below.527
Case 1: Energy losses incurred in V2G528
In V2G charging of EVs, the losses incurred are transformer loss, line loss529
and some miscellaneous losses like hysteresis loss, corona effect loss, I2R530
loss, etc., [39]. The power losses incurred in V2G are calculated using531
Equation 10.532
Case 2: Energy losses incurred in V2V
The losses incurred in V2V include vehicle losses and infrastructure losses.
However, it does not include the grid loss. As energy trading is done
between two EVs, both equipped with energy inverters; therefore, the
inverter inefficiencies will be added up [40]. Moreover, the battery loss is
also incurred, which has a major contribution in accumulative power loss
as well. Equation 21 is used to calculate the power loss incurred in V2V
charging of EVs.
Ptotal
loss =Vloss +Iloss,(21)
20
where Gloss = 0.533
4. Security objectives and analysis, and attacker models of the pro-534
posed system535
In this section, we first discuss the security objectives of our proposed energy536
trading scheme. After that, we evaluate the security analysis of the proposed537
smart contract using the Oyente tool. Finally, two attacker models are formu-538
lated.539
4.1. Security objectives540
Unlike the traditional energy trading scheme’s security and privacy protec-541
tion, we use consortium blockchain in the proposed work. Instead of PoW,542
PoA consensus mechanism is used because only LAGs are selected as autho-543
rized nodes who validate the transaction data. While, EVs and CSs request544
LAGs for the buying and selling of energy. LAGs make a pair of the selected545
buyer and seller and then secure them using their identities. Likewise, all of the546
energy nodes (EVs, CSs and LAGs) are registered and permitted to join the547
energy trading network. The node must show its identity for getting permission548
to enter in the energy trading network. Thus, the energy trading network can549
be protected from both Sybil and double spending attacks.550
4.1.1. Data auditability551
Blockchain is used in our proposed scheme that keeps energy trading requests552
and payment records in an easily verifiable, timestamped and tamper-proof553
manner. It ensures that each node needs to get a license to join the network.554
Because of this, no adversary entity can become part of this network or add555
false blocks to the blockchain. Records in the blockchain network are tamper556
proof and there is a guarantee that data can be audited when required.557
4.1.2. Wal let security558
A smart contract is used for a fair payment system. The energy buyer559
requests LAGs for energy, which execute smart contracts and access the buyer’s560
and the seller’s wallet addresses. However, the wallet addresses are not shared561
publicly; therefore, without corresponding keys, no adversary can access the562
wallets and chances of stealing energy coins become zero.563
4.1.3. Transaction authentication564
Using PoA with blockchain, data of all transactions is validated by authentic565
LAGs. Therefore, it is impossible for the malicious nodes to compromise the566
system.567
4.1.4. No transaction tampering568
A financially-motivated attacker in an energy trading environment can tam-569
per energy price or energy selling and buying requests. However, in consor-570
tium blockchain, the attacker cannot modify transaction because blockchain is571
tamper-proof.572
21
4.1.5. Refusing to pay573
In this attack, the malicious EV may pretend that it has not received any574
energy from the seller CS or EV and may also refuse to pay the cost of purchased575
energy [22].576
4.1.6. Concurrency bug577
This is a bug that arises when two functions are executed at the same time.578
This problem is often encountered while updating a data structure or a database.579
In the proposed model, PoA based consortium blockchain is used, so, only one580
block will be appended to the blockchain at a time. Besides, in blockchain, even581
if two blocks are created at the same time there would be a difference of micro582
seconds in their creation. So, the first block will be kept and second will be583
discarded.584
4.2. Smart contract analysis585
A smart contract allows a reliable transaction without the involvement of a586
third party. Therefore, it is very important to analyze the smart contract for587
possible bugs and loopholes. Oyente symbolic execution tool is used for smart588
contract’s security analysis. It is developed by researchers from the National589
University of Singapore [41]. Oyente is able to test some of Ethereum’s security590
flaws including EVM code coverage, integer underflow, integer overflow, parity591
multisig bug 2, callstack depth attack vulnerability, transaction-ordering depen-592
dence, timestamp dependency and re-entrance vulnerability bugs. The details593
of these bugs are given below. The smart contract used in our proposed scheme594
is analyzed by Oyente and results of security analysis are shown in Figure 6 in595
which the result of all the above-mentioned attacks are seen as false.596
4.2.1. Integer underflow and overflow597
These bugs arise when the values of integers used in the smart contract598
exceed the predefined upper and lower limits. When the integer values exceed599
the set boundaries, the smart contract fails and whole system comes to a halt600
[42].601
4.2.2. Parity multisig bug 2602
This type of bug occurs when the attacker gets hold of multiple accounts603
and generate fake signatures for them. When a large number of such accounts604
are summed up, they cause the smart contract to stop, leading to the failure of605
the system [43].606
4.2.3. Cal lstack depth attack vulnerability607
This attack is also called a call depth attack. In this attack, the calling608
function fails if the call depth is equal to 1024 frames and it is only executed609
when its depth value is at most 1023 frames.610
4.2.4. Timestamp dependency611
In this attack, a miner manipulates the timestamp’s conditions to favor612
himself during transaction mining. Every machine has its own physical time,613
called timestamp.614
22
4.2.5. Re-entrancy vulnerability615
In this vulnerability, the path condition is used and verified. For example, if616
one smart contract in Ethereum calls another smart contract, then the current617
transaction waits for that call to end and the use of the caller’s intermediate618
state can cause problems.619
Figure 6: Security analysis result of smart contract
4.3. Attacker models for blockchain620
To design the attacker models, several assumptions and parameters are con-621
sidered in this study. Moreover, the attacker can be any member of the network.622
In this study, we consider the double spending, Sybil attacks and feather forking623
attacks [31]. These attacks are more suitable for our proposed scenario, which624
means that once the attacks are prevented, other related attacks, such as refuse625
to pay attack [22, 23], re-entry attacks [23], etc., cannot affect the proposed626
system.627
In the energy trading environment, attacker nodes not only pose a threat to628
network security, but also cause financial loss to CSs and EVs. Apart from the629
aforementioned attacks, there are some other attacks and vulnerabilities, such630
as call stack attack, time dependency attack, concurrency bug and re-entrance631
vulnerability, which can damage the blockchain-based systems [44]. Similar632
attacks are discussed in [21] to analyze the security of their model. In the early633
stages of the development of Ethereum, there was a big case of Decentralized634
Autonomous Organization (DAO) hacking, which occurred in June 2016 and635
caused a loss of 3.6 million ethers [41].636
4.3.1. Double spending attack model637
Double spending occurs when the same token is used twice for making pay-638
ment. In the double spending attack, the attacker behaves as an honest node639
in the network. Here, the attacker propagates two payment transactions and640
publishes them over the network. This implies that the attacker can mine the641
two transactions along with the honest nodes in the network. Before the re-642
ceiver node gets the payment, the attacker covertly releases the mined blocks643
for creating forks in the network. Once a fork is created, the transaction of644
the receiver node becomes invalid. It means that the request or response of the645
receiver node is discarded. In our scenario, we assume that the attacker is a646
malicious LAG and the receiver node is a CS. When an EV request for energy647
it makes pair of both buyer EV and seller CS. Now there are two cases, the648
attacker either pays himself or pays back to the EV, who got energy from the649
23
CS. In the first case, the CS will be befitted by getting money, while in the650
second case, it just performs a malicious activity to harm the energy trading651
process. Suppose, the LAG wants to pay himself, after energy trading, it cre-652
ates two payment transactions: paying himself and paying the CS. Once the653
attacker succeeds in mining the former, then a block is continuously added to654
the blockchain and afterwards, an incentive is given to the attacker. This im-655
plies that the attacker has created a false branch in the network. If the false656
branch of the attacker is the longest in the network, then honest nodes must657
accept it as the valid branch [45]. At the end, CS provides energy to the EV658
without receiving any payment. In this study, a time based double spending659
model is developed, which is motivated from [45]. The existing model in [45]660
considers time advantage while the proposed model considers both time and661
computational advantages of the attacker. It means that the attacker has time662
and computational advantages to mine nblocks given that an honest node mines663
the mth block. Besides, in this study, the same branch length of both honest and664
attacker nodes are assumed along with different mining time t. In the proposed665
double spending model, the following parameters are considered.666
1. The quantity q∈[0,1] is the probability that an attacker mines a block667
before the honest node. qcan also be defined as the percentage of com-668
putational power of an attacker to the total computational power of the669
network.670
2. The quantity τ∈R>0is the expected time (seconds) that is required for671
mining a block.672
This study defines a catch up function C(q, z) as the probability of accomplish-
ing the double spending attack where the branch length of the attacker is the
longest given the initial disadvantage of zblocks. A potential process func-
tion F(q, m, n) is the probability that an attacker mines exactly nblocks once
an honest node mines the mth block. Nevertheless, C(q, z) and F(q, m, n) are
required for formulating the probability of performing double spending attack
DS(q, K, t), which is derived as [45]
C(q, z) = ((q
p)z+1,if q < ρ ∧z > 0,
1,otherwise,(22)
where p= 1 −qis the probability that an attacker has less computational
resources.
F(q, m, n) = (1,if m=n= 0,
m+n−1
nqnpm,otherwise,(23)
where m+n−1
nqnpmis the negative binomial distribution.
P(q, m, n, t) =
n
X
z=0
a(q, t, z)F(q, m, n −z),(24)
a(q, t, n) =
1,if t=n= 0,
0,if t≤0,
(qt)n
n!exp−qt,otherwise,
(25)
24
where P(q, m, n, t) is the probability that an attacker mines nblocks before the
honest node mines the mth block. a(q, t, n) is the probability of mining the n
blocks in tτ seconds given q.
DS(q, K, t) = 1 −
K−n
X
n=0 (P(q, K, n, t))(1 −C(q, K −n−1)).(26)
4.3.2. Sybil attack model673
In the Sybil attack scenario, an attacker creates fake identities for deceiving
honest nodes into rating him highly. The idea of the Sybil attack is obtained
from [46]. This attack is necessary for the attacker as it receives high reputation
during energy trading. This paper determines the probability of successful Sybil
attack created by the attacker. We denote ns to be the number of successful
Sybil identities and Nto be the number of identities of honest nodes in the
network. The total identities are N+ns −1. Let wbe the number of identities
that are selected from N+ns −1 at the initial stage. In each trial of the attack,
the probability of successful Sybil attack is the number of Sybil identities created
by the attacker, which is broadcasted over the network. The attacker fails to
implement the Sybil attack if the number of Sybil identities are less than ρ.
The probability P[w] of selecting wSybil identities randomly from N+ns −1
identities in each trial is defined as
P[w] = ns
wN−1
N−w
N+ns−1
N.(27)
Equation (27) corresponds to a hypergeometric distribution where ns
w=ns!
w!(ns!−w!)
674
is a binomial coefficient.675
4.4. Feather forking attack676
A feather forking attack occurs when a miner refuses to mine a block because677
of the presence of a transaction, which it does not like. This attack is generated678
to blacklist an entity from the network. A miner node generates this attack when679
it becomes biased towards a node, and it does not allow its transactions to be680
added in the blockchain. In such a scenario, the attacker tries to involve other681
miners as well. The reason is that it needs 51% of the computational power682
of the whole network to blacklist a node. On the other hand, a victim node683
increases the transactional fee and pays other nodes more transactional fee to684
validate its transactions. In this way, it saves himself from being blacklisted from685
the network. The authors in [31] used this attack in their work. However, they686
have used it as a positive force. Using this attack, the energy providers who use687
non renewable energy resources for energy generation, pay more transactional688
cost. Besides, in our scenario, suppose a miner wants to blacklist an EV from689
the network and refuses to mine its transactions. On encountering such activity,690
other validators and miner nodes will reduce the ACF of the respective miner.691
So, if the miner will keep on refusing the transactions of an honest EV, after692
certain attempts, it will be declared malicious and removed from the network.693
However, if the miner starts working normally, its ACF value will be increased.694
Moreover, as we are using PoA consensus mechanism and miner node is selected695
on the basis of reputation value, so, a malicious node can not become a minor.696
25
It will only refuse to validate the transaction or block, which contain the specific697
transaction.698
5. Simulation results699
In this section, the mathematical results are presented in tabular form. Table700
4 gives the values of the losses incurred in V2G charging of EVs. Whereas,701
Table 5 provides the values of losses incurred in V2V charging. The results702
are obtained using three different values of SoC, i.e., 50%, 60% and 70%. The703
values are taken from [47] and [48]. It is observed that the loss values decrease704
with the increase in SoC values.705
Table 4: Losses incurred in V2G
Types of loss SoC=50% SoC=60% SoC=70%
Grid loss (%) 7.6% 6.5% 5.8%
Vehicle loss (%) 2.74% 2.50% 2.42%
Infrastructure loss (%) 3.5% 3.2% 2.95%
Total loss (%) 13.84% 12.5% 11.17%
Table 5: Losses incurred in V2V
Types of loss SoC=50% SoC=60% SoC=70%
Grid loss (%) 0 0 0
Vehicle loss (%) 6.85% 6.25% 5.86%
Infrastructure loss (%) 3.72% 3.45% 3.38%
Total loss (%) 10.57% 9.70% 9.24%
5.1. Experimental setup and results’ description706
A computer with a 1.61 GHz core m3-7y30 processor, 8 GB DDR4 RAM707
and Windows 10 operating system is used for simulations. The proposed model708
is implemented using Remix IDE, Ganache, MetaMask and Python 3.7. The709
hardware specification mentioned above are used for simulation purpose only. In710
real environment, the hardware specifications for LAGs will be different. Bitcoin711
is the common application of blockchain. The minimum system requirements712
to become a minor in bitcoin are given in Table 6 [49]. As the bitcoin uses713
PoW consensus algorithm, which is computationally more expansive than PoA;714
however, these are the minimum requirements. In our scenario, the required715
disk space and download and upload rates will vary because these parameters716
depend on the size of the network and amount of data being shared. The717
parameters given in Table 6 are presented to give the reader an idea of hardware718
requirements of LAGs in the real environment. However, the LAGs are not719
limited to these specifications.720
The performance of our proposed model is analyzed using a real dataset721
in a real city area of the energy trading environment. The selected area is722
approximately 9.33 x 12.45 km2including 13 CSs, 7 PRKs and 50 EVs as723
shown in Figure 7. The locations of the CSs shown in Figure 7 are actually724
the locations of the real gas stations, which we have designated as CSs so that725
26
Table 6: Minimum hardware requirements to become a minor
Hardware Requirements
Disk space 350 GB
Download 500 MB/day
Upload 5 GB/day
Memory (RAM) 1 GB
System Desktop, laptop, some ARM chipsets >1 GHz
Operating system Windows 7/8.x/10, Mac OS X, Linux
there is no problem of finding the distance from the EVs to the CSs. Real data726
has been used to calculate the accurate and efficient distance with the help of727
GPS when an EV traverses a fixed route from one place to another for energy728
trading. For instance, an EV wants to reach destination “D” from source “A”,729
it has to go through places “B” and “C” to reach destination “D”. Distances730
between all CSs are shown in Table 7.731
Figure 7: Distribution of CSs and PRKs in the real map
Table 7: Distance between CSs
CS1CS2CS3CS4CS5CS6CS7CS8CS9CS10 CS11 CS12 CS13
CS1– 3.9 km 4.1 km 2.9 km 6.5 km 7.8 km 14.6 km 11.4 km 13.5 km 14.4 km 16.1 km 15.3 km 17 km
CS2– – 3.8 km 3.1 km 6.7 km 7.5 km 14.3 km 11.1 km 13.7 km 14.5 km 16.1 km 13.3 km 16.7 km
CS3– – – 3.1 km 6.7 km 4.4 km 6.1 km 5.6 km 6.9 km 8.9 km 8.8 km 7.4 km 13 km
CS4– – – – 3.8 km 8.8 km 13.2 km 10 km 10.8 km 11.6 km 11.6 km 12.2 km 15.6 km
CS5– – – – – 10.5 km 9.2 km 11.8 km 7 km 7.9 km 9.5 km 13.6 km 15.1 km
CS6– – – – – – 5.1 km 1.3 km 7.2 km 8 km 7.9 km 5.2 km 8.6 km
CS7– – – – – – – 3.4 km 6.2 km 8.2 km 8.1 km 3.9 km 11 km
CS8– – – – – – – – 6.6 km 9 km 7.2 km 4.4 km 7.8 km
CS9– – – – – – – – – 3.6 km 3.3 km 4.5 km 10.1 km
CS10 – – – – – – – – – – 6.4 km 6.4 km 7.9 km
CS11 – – – – – – – – – – – 6.4 km 7.9 km
CS12 – – – – – – – – – – – – 4.9 km
As finding accurate distance is very important, so, we have used third-party732
services, such as GPS to measure the accurate distance. Besides, we have se-733
lected different types of EVs, which have different types of batteries. EVs and734
their battery specifications are shown in Table 2. However, SoC of the EV’s735
battery is an important factor for selling and buying energy. Energy trading736
27
between an EV, who wants to sell surplus energy at a CS or a PRK and an EV,737
who wants to get energy from CS or another EV, is dependent on the value of738
SoC pr . The values of SoCpr for EVs’ batteries are shown in Figure 8 and for739
CSs are shown in Figure 9.740
Figure 8: Present SoC value of EVs
Figure 9: Present SoC value of CSs
The price of energy announced by EVs and CSs is a major influence in741
the energy trading environment. The energy price in our proposed scheme is742
determined by the formula given in Algorithm 1, which is derived from [8]. This743
formula uses the existing SoCcur,Bcap and Eth values to determine the price. If744
the charging of the battery is full, the price would be 0.45, which is the current745
energy rate in the USA. Using this formula, the price of energy continues to746
increase as the level of charging decreases. The difference in price according to747
the level of charging for both EVs and CSs is illustrated in Figures 10 and 11,748
respectively.749
As we have explained earlier, EVs who participate in energy trading can750
charge and discharge their energies at any CS or any PRK based on energy re-751
quirements. The primary factor in the energy trading environment is the present752
SoC value in batteries, which decides about the buying and selling of energy.753
We have selected a 30 percent threshold value of SoC; however, the threshold754
value can be different in real energy trading practice. To verify the accuracy of755
28
Figure 10: Price announced by EVs
Figure 11: Price announced by CSs
computed distance between EVs, CSs and PRKs, five different locations of CSs756
and PRKs are selected as shown in Table 8. For a fair comparison, Scheme 1 [8],757
Scheme 2 [22] and our proposed scheme are executed using the same locations.758
Figure 12 shows the results’ comparison for the schemes used in [8], [22] and759
our proposed scheme.760
If we look at Figure 12, we see that the result of the detected distance by all761
three schemes is very different. The reason is that, in [8], the city’s geographical762
area is divided into equal-sized blocks, which is not applicable to the random763
sized geographical area. Moreover, in [22], an equation is used to find the764
distance between EVs to CSs with the help of latitude and longitude. However,765
in our proposed technique, the distance is calculated using third-party service.766
In Ethereum, gas is a small unit of cryptocurrency. The unit is deducted from767
the users’ accounts to perform a transaction in Ethereum. Figure 13 shows gas768
Table 8: Coordinates of EV, CSs and PRKs
EVs
(Loccur)
PRK1
(Loc)
PRK2
(Loc)
CS1
(Loc)
CS2
(Loc)
PRK3
(Loc)
33.664344 33.6459273 33.6669018 33.6879759 33.6440546 33.6493211
73.1494082 73.1583868 73.1375861 73.1074905 73.1624118 73.1572385
29
Figure 12: Comparison for accurate distance measurement
consumption of smart contract’s operations. There are five different functions in769
the smart contract that are used in the proposed work: (a) recharge wallet, (b)770
access buyer’s wallet address (c) access seller’s wallet address (d) transfer energy771
coin from one account to another account and (e) check current balance in the772
wallet. The gas consumption depends on the complexity of the smart contract.773
The deployment of a smart contract is an expensive operation in Ethereum. In774
Figure 13, the transactional costs of the functions are shown. Moreover, Figures775
14 and 15 show the comparison of transaction cost and execution cost using PoW776
and PoA, respectively. It can be observe from both figures that PoA consume777
less cost as compared to PoW and hence, it is beneficial in implementing the778
smart contract. In Figures 13-15, the functions used in the smart contract are779
labeled as a-e. These functions are get energy coins, get buyer address, get seller780
address, transfer amount and check balance. Table 9 represents the mapping of781
limitations to the proposed solutions and validations. The limitations identified782
in Subsection 1.1 and given in Table 3 are mentioned in Table 9 along with the783
proposed solutions and validation results, given in the 3rd and the 4th columns784
of Table 9, respectively.785
Figure 13: Gas consumption cost
30
Figure 14: Transaction cost comparison
Figure 15: Execution cost comparison
5.2. Complexity analysis786
The time complexity of our proposed Algorithm 1 is computed as follows.787
It runs ntimes for nrequests of EVs and CSs, so, it takes O(n) time to ver-788
ify and transmit the requests. Finding the nearest energy trading place (CSs,789
PRKs) also takes ntime because LAG selects the stored EVs and CSs from790
the transactions pool according to the buyer’s requirements. Furthermore, re-791
maining computations take O(1) time to compute the energy trading request.792
Therefore, the whole time complexity of the proposed algorithm is O(n).793
5.3. Evaluation of security analysis794
In this section, the evaluation results that analyze the double spending and795
Sybil attacks are provided. The computational resources of a node are calculated796
using gas values of the hash rate. Besides, the computational resources of an797
attacker are the proportion of its hash rate to the overall hash rate of the798
network. The block generation time and mining time and the random block799
disadvantage of [-5, 5] are considered for the analysis. This study considers800
31
Table 9: Mapping of limitations with validation results
Limitation
number
Limitation identified Proposed
solution
Validation results
L.1 Excessive resource con-
sumption using PoW
consensus mechanism
S.1 Figures 14 and 15
show the cost com-
parison between PoW
and PoA
L.2 Accurate distance mea-
surement
S.2 Figure 12 shows the
comparison between
accurate distance
measurement using 3
different techniques
L.3 Energy coin wallets not
secured
S.3 Algorithm 2 is used
for energy trading,
which also helps in
securing the energy
coin wallets
L.4 Excessive time con-
sumption by miners
while selecting EVs
S.4 No direct validation
L.5 Robustness against at-
tacks
S.5 Figure 6 shows the se-
curity analysis results
using Oyente. Figures
16, 17, 18, 19 show
the security results for
double spending and
Sybil attacks
different number of Sybil identities for the analysis. The parameters in this801
study are used for evaluating the effectiveness of the proposed system model and802
scenario. Moreover, the study is not limited to the above mentioned parameters,803
but can accept more parameters.804
5.3.1. Evaluation of the double spending attack805
The following parameters are used for analyzing the double spending attack:806
computational resources of the attack q= 0.30, number of confirmed messages807
K= 20, time advantage t= 1 and defined threshold ρ= 0.25. Figure 16808
shows the probability of successful double spending attack versus the number of809
confirmed messages. The proposed method is compared with existing method810
of [45] and the results show that the proposed method outperforms the existing811
method in terms of minimum probability of successful double spending attack.812
In this study, if the probability of successful double spending attack ap-813
proaches 1, then the attacker is successful in launching the attack and vice814
versa. From the results in Figure 16, it is observed that as the number of con-815
firmed messages increases, the probability of successful double spending attack816
decreases, which implies that the proposed method prevents the attack because817
of the PoA consensus mechanism. Also, it means that the false branch created818
by the attacker is the shortest; therefore, honest nodes will reject the branch. It819
32
Figure 16: Probability of successful double spending attack versus the number of confirmed
messages
is also observed that the proposed method has the least probability of successful820
double spending attack as compared to the existing method. This means that821
the proposed method efficiently utilizes ρfor regulating the malicious activi-822
ties of nodes in the network. Moreover, the proposed method considers both823
computational resource and time advantages instead of considering only time824
advantage like [45] for evaluating the double spending attack.
−4−2 0 2 4
Bloc k Pre-mined by Attacker
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
Probabi lit y of Succe ssfu l Dou ble Spen di ng Att ack
Exist ing Met hod
Propo sed Me tho d
Figure 17: Probability of successful double spending attack versus block pre-mined by attacker
825
Figure 17 shows the probability of successful double spending attack versus826
block pre-mined by attacker. It is observed from the figure that as the block827
pre-mined by attacker increases from -5 to 5, the probability of successful double828
spending attack increases. This shows the behavior of the attacker in a real life829
scenario. It also explains that if the attacker is successful in launching the attack830
with high computational resource and time, then it creates the longest branch in831
33
the network. It is also observed from the results in Figure 17 that the proposed832
method has the minimum probability of successful double spending attack as833
compared to the existing method. This implies that the proposed method is834
more effective in preventing double spending attack in a real life scenario as835
compared to the existing method.
Figure 18: Probability of successful double spending attack versus number of computational
resources
836
The advantages of computational resource of an attacker over the honest837
nodes in the network are analyzed and Figure 18 shows the results. It is ob-838
served from the figure that the number of computational resources increases839
along with the probability of successful double spending attack. This means840
that if an attacker has high computing resources in real life scenario, it can841
control the entire network and can get more incentives. The proposed PoA con-842
sensus mechanism is used in this study to mitigate the double spending attack.843
In the PoA consensus mechanism, the reputation is considered instead of the844
computational resources of nodes. It means that if a node has high computa-845
tional resources, but low reputation, then such a node cannot participate in the846
validation and mining processes. Generally, it is clearly shown from the eval-847
uation results that the proposed system is robust against the double spending848
attack.849
5.3.2. Evaluation of sybil attack850
The parameters considered for evaluating Sybil attack are as follows: num-851
ber of nodes n= 200, different Sybil identities ns = 4 and 8, and computational852
resources of an attacker q= 0.3. Figure 19 shows the impact of different identi-853
ties on the the probability of a successful Sybil attack. It is observed from the854
figure that when the attacker creates 4 Sybil identities, the probability of suc-855
cessful Sybil attack is zero as the computational resources increase from 0-100.856
Afterwards, the probability of successful Sybil attack increases along with the857
computational resources, i.e., greater than 100. This implies that if the attacker858
increases the computational resources of the 4 Sybil nodes, then there is a high859
possibility of launching the Sybil attack. On the other hand, when the attacker860
34
Figure 19: Probability of successful Sybil attack versus number of computational resources
increases the Sybil identities up to 8, the probability of successful Sybil attack is861
zero as the computational resources increases from 0-150. Although, the proba-862
bility of successful Sybil attack increases when the computational resources are863
above 150. The analysis of 4 and 8 Sybil identities explains that as the attacker864
increases the Sybil identities in the network, the probability of successful Sybil865
attack remains zero while increasing the computational resources. The proposed866
PoA consensus mechanism mitigates the attack by considering the reputation867
instead of computational resources of nodes. It means that the nodes with high868
reputation can perform validation and mining tasks. Therefore, the proposed869
system is robust against the Sybil attack.870
6. Conclusion871
We have implemented V2V and V2G energy trading environments in a smart872
city using consortium blockchain and smart contracts for a fair payment mech-873
anism where EVs and CSs can trade energy without reliance on the third party.874
Blockchain technology is deployed on authorized LAGs, which work as energy875
brokers to carry out the energy trading requests. We have used the PoA con-876
sensus mechanism instead of PoW because it uses less computational power as877
compared to PoW and provides maximum throughput with less latency. In our878
proposed scheme, an algorithm is proposed that provides accurate distance with879
the required time and minimum expenses to reach any CS and PRK for energy880
trading. The energy losses in both V2G and V2V energy trading environments881
are discussed in this work, which help in promoting efficient power flow in the882
vehicular networks. This study designs two attacker models based on the dou-883
ble spending and Sybil attacks. The evaluation of security analysis shows that884
the proposed system is robust against both attacks. Besides, We have used885
Oyente for smart contract security analysis, which can test common and well-886
known bugs including call stack depth attack vulnerability, transaction-ordering887
dependence, timestamp dependency, re-entrancy vulnerability, and DAO bugs.888
The experimental results and security analysis show that our proposed scheme889
35
improves transactional security and privacy. The results also show that the cost890
incurred using the PoA consensus mechanism is almost 25%-30% less than the891
cost incurred when using the PoW consensus mechanism. Moreover, the results892
also prove that our proposed scheme outperforms the existing schemes in terms893
of providing a secure energy trading environment for V2V and V2G charging of894
EVs. As a whole, the proposed scheme helps in making the smart cities reliable,895
sustainable, environment and user friendly and ensures energy efficiency.896
Conflict of Interest: The authors have declared no conflict of interest.897
References898
[1] Amini, M.H., Moghaddam, M.P. and Karabasoglu, O., 2017. Simultane-899
ous allocation of electric vehicles’ parking lots and distributed renewable900
resources in smart power distribution networks. Sustainable Cities and So-901
ciety, 28, pp.332-342.902
[2] Kang, J., Yu, R., Huang, X., Maharjan, S., Zhang, Y. and Hossain, E.,903
2017. Enabling localized peer-to-peer electricity trading among plug-in hy-904
brid electric vehicles using consortium blockchains. IEEE Transactions on905
Industrial Informatics, 13(6), pp.3154-3164.906
[3] Khalkhali, H. and Hosseinian, S.H., 2020. Multi-class EV charging907
and performance-based regulation service in a residential smart park-908
ing lot. Sustainable Energy, Grids and Networks, p.100354. DOI:909
10.1016/j.segan.2020.100354910
[4] Zhou, Z., Wang, B., Guo, Y. and Zhang, Y., 2019. Blockchain and com-911
putational intelligence inspired incentive-compatible demand response in912
internet of electric vehicles. IEEE Transactions on Emerging Topics in Com-913
putational Intelligence, 3(3), pp.205-216.914
[5] Gao, F., Zhu, L., Shen, M., Sharif, K., Wan, Z. and Ren, K., 2018.915
A blockchain-based privacy-preserving payment mechanism for vehicle-to-916
grid networks. IEEE network, 32(6), pp.184-192.917
[6] Liu, H., Zhang, Y. and Yang, T., 2018. Blockchain-enabled security in918
electric vehicles cloud and edge computing. IEEE Network, 32(3), pp.78-919
83.920
[7] Zheng, D., Jing, C., Guo, R., Gao, S. and Wang, L., 2019. A Traceable921
Blockchain-Based Access Authentication System With Privacy Preserva-922
tion in VANETs. IEEE Access, 7, pp.117716-117726.923
[8] Jindal, A., Aujla, G.S. and Kumar, N., 2019. SURVIVOR: A blockchain924
based edge-as-a-service framework for secure energy trading in SDN-925
enabled vehicle-to-grid environment. Computer Networks, 153, pp.36-48.926
[9] Li, Z., Kang, J., Yu, R., Ye, D., Deng, Q. and Zhang, Y., 2017. Consortium927
blockchain for secure energy trading in industrial internet of things. IEEE928
transactions on industrial informatics, 14(8), pp.3690-3700.929
36
[10] Aitzhan, N.Z. and Svetinovic, D., 2016. Security and privacy in decentral-930
ized energy trading through multi-signatures, blockchain and anonymous931
messaging streams. IEEE Transactions on Dependable and Secure Com-932
puting, 15(5), pp.840-852.933
[11] Yahaya, A.S., Javaid, N., Alzahrani, F.A., Rehman, A., Ullah, I., Shahid,934
A. and Shafiq, M., 2020. Blockchain Based Sustainable Local Energy Trad-935
ing Considering Home Energy Management and Demurrage Mechanism.936
Sustainability, 12(8), p.3385. DOI: 10.3390/su12083385937
[12] Samuel, O., Almogren, A., Javaid, A., Zuair, M., Ullah, I. and Javaid, N.,938
2020. Leveraging Blockchain Technology for Secure Energy Trading and939
Least-Cost Evaluation of Decentralized Contributions to Electrification in940
Sub-Saharan Africa. Entropy, 22(2), p.226. DOI: 10.3390/e22020226941
[13] Nakamoto, S., Bitcoin: A Peer-to-Peer Electronic Cash System. Available942
online: https://bitcoin.org/bitcoin.pdf (accessed 13-December-2019)943
[14] She, W., Liu, Q., Tian, Z., Chen, J.S., Wang, B. and Liu, W., 2019.944
Blockchain trust model for malicious node detection in wireless sensor net-945
works. IEEE Access, 7, pp.38947-38956.946
[15] Sultana, T., Almogren, A., Akbar, M., Zuair, M., Ullah, I. and Javaid,947
N., 2020. Data Sharing System Integrating Access Control Mechanism us-948
ing Blockchain-Based Smart Contracts for IoT Devices. Applied Sciences,949
10(2), p.488. DOI: 10.3390/app10020488950
[16] Feng, Q., He, D., Zeadally, S. and Liang, K., 2019. BPAS: Blockchain-951
Assisted Privacy-Preserving Authentication System for Vehicular Ad-Hoc952
Networks. IEEE Transactions on Industrial Informatics.953
[17] Javed, M.U., Rehman, M., Javaid, N., Aldegheishem, A., Alra jeh,954
N. and Tahir, M., 2020. Blockchain-Based Secure Data Storage for955
Distributed Vehicular Networks. Applied Sciences, 10(6), p.2011. DOI:956
10.3390/app10062011957
[18] Zhu, L., Wu, Y., Gai, K. and Choo, K.K.R., 2019. Controllable and trust-958
worthy blockchain-based cloud data management. Future Generation Com-959
puter Systems, 91, pp.527-535.960
[19] Gai, K., Wu, Y., Zhu, L., Qiu, M. and Shen, M., 2019. Privacy-preserving961
energy trading using consortium blockchain in smart grid. IEEE Transac-962
tions on Industrial Informatics, 15(6), pp.3548-3558.963
[20] Khalid, R., Javaid, N., Almogren, A., Javed, M.U., Javaid, S. and Zuair,964
M., 2020. A Blockchain-Based Load Balancing in Decentralized Hybrid P2P965
Energy Trading Market in Smart Grid. IEEE Access, 8, pp.47047-47062.966
[21] Shahid, A., Almogren, A., Javaid, N., Al-Zahrani, F.A., Zuair, M. and967
Alam, M., 2020. Blockchain-Based Agri-Food Supply Chain: A Complete968
Solution. IEEE Access, 8, pp.69230-69243.969
37
[22] Chaudhary, R., Jindal, A., Aujla, G.S., Aggarwal, S., Kumar, N. and970
Choo, K.K.R., 2019. BEST: Blockchain-based secure energy trading in971
SDN-enabled intelligent transportation system. Computers & Security, 85,972
pp.288-299.973
[23] Wang, Y., Su, Z. and Zhang, N., 2019. BSIS: Blockchain-based secure974
incentive scheme for energy delivery in vehicular energy network. IEEE975
Transactions on Industrial Informatics, 15(6), pp.3620-3631.976
[24] Sachan, S., Deb, S. and Singh, S.N., 2020. Different charging infrastructures977
along with smart charging strategies for electric vehicles. Sustainable Cities978
and Society, p.102238. DOI: 10.1016/j.scs.2020.102238979
[25] Zhou, Z., Wang, B., Dong, M. and Ota, K., 2019. Secure and efficient980
vehicle-to-grid energy trading in cyber physical systems: Integration of981
blockchain and edge computing. IEEE Transactions on Systems, Man, and982
Cybernetics: Systems, 50(1), pp.43-57.983
[26] Huang, X., Xu, C., Wang, P. and Liu, H., 2018. LNSC: A security model for984
electric vehicle and charging pile management based on blockchain ecosys-985
tem. IEEE Access, 6, pp.13565-13574.986
[27] Luo, B., Li, X., Weng, J., Guo, J. and Ma, J., 2019. Blockchain Enabled987
Trust-based Location Privacy Protection Scheme in VANET. IEEE Trans-988
actions on Vehicular Technology.989
[28] Dorri, A., Steger, M., Kanhere, S.S. and Jurdak, R., 2017. Blockchain: A990
distributed solution to automotive security and privacy. IEEE Communi-991
cations Magazine, 55(12), pp.119-125.992
[29] Hassija, V., Chamola, V., Garg, S., Krishna, D.N.G., Kaddoum, G. and993
Jayakody, D.N.K., 2020. A blockchain-based framework for lightweight data994
sharing and energy trading in V2G network. IEEE Transactions on Vehic-995
ular Technology, 69(6), pp.5799-5812.996
[30] Bao, J., He, D., Luo, M. and Choo, K.K.R., 2020. A survey of blockchain997
applications in the energy sector. IEEE Systems Journal.998
[31] Magnani, A., Calderoni, L. and Palmieri, P., 2018, June. Feather forking999
as a positive force: incentivising green energy production in a blockchain-1000
based smart grid. In Proceedings of the 1st Workshop on Cryptocurrencies1001
and Blockchains for Distributed Systems, Munich, Germany, pp.99-104.1002
[32] Xu, C., Wang, K., Li, P., Guo, S., Luo, J., Ye, B. and Guo, M., 2018. Mak-1003
ing big data open in edges: A resource-efficient blockchain-based approach.1004
IEEE Transactions on Parallel and Distributed Systems, 30(4), pp.870-882.1005
[33] BU-1003: Electric Vehicle (EV). Available online: https:1006
//batteryuniversity.com/learn/article/electric_vehicle_ev1007
(accessed 19-March-2020)1008
[34] Xie, L., Ding, Y., Yang, H. and Wang, X., 2019. Blockchain-based secure1009
and trustworthy Internet of Things in SDN-enabled 5G-VANETs. IEEE1010
Access, 7, pp.56656-56666.1011
38
[35] Yang, Y.T., Chou, L.D., Tseng, C.W., Tseng, F.H. and Liu, C.C.,1012
2019. Blockchain-based traffic event validation and trust verification for1013
VANETs. IEEE Access, 7, pp.30868-30877.1014
[36] Rathee, G., Sharma, A., Iqbal, R., Aloqaily, M., Jaglan, N. and Kumar,1015
R., 2019. A blockchain framework for securing connected and autonomous1016
vehicles. Sensors, 19(14), p.3165.1017
[37] Abdolmaleki, M., Masoud, N. and Yin, Y., 2019. Vehicle-to-vehicle wireless1018
power transfer: Paving the way toward an electrified transportation system.1019
Transportation Research Part C: Emerging Technologies, 103, pp.261-280.1020
[38] Load-No Load Losses Of Transformer-ECE Tutorials. Avail-1021
able online: https://ecetutorials.com/transformer/1022
losses-of-transformer-noload-and-load/ (accessed 15-April-2020)1023
[39] Losses In Distribution & Transmission Lines — Electrical In-1024
dia Magazine On Power & Electrical Products, Renewable En-1025
ergy, Transformers, Switchgear & Cables. Electrical India Magazine1026
On Power & Electrical Products, Renewable Energy, Transformers,1027
Switchgear & Cables. Available online: https://www.electricalindia.1028
in/losses-in-distribution-transmission-lines/1029
[40] Koufakis, A.M., Rigas, E.S., Bassiliades, N. and Ramchurn, S.D., 2019.1030
Offline and online electric vehicle charging scheduling with V2V energy1031
transfer. IEEE Transactions on Intelligent Transportation Systems.1032
[41] How To Use Oyente, A Smart Contract Security Analyzer - Solidity1033
Tutorial. Medium. Available online: https://medium.com/haloblock/1034
how-to-use-oyente-a-smart-contract-security-analyzer- solidity\1035
-tutorial-86671be93c4b (accessed 5-April-2020)1036
[42] Known Attacks - Ethereum Smart Contract Best Prac-1037
tices. Available online: https://consensys.github.io/1038
smart-contract-best-practices/known_attacks/ (accessed 5-April-1039
2020)1040
[43] A Postmortem On The Parity Multi-Sig Library Self-1041
Destruct. Blockchain Infrastructure For The Decen-1042
tralised Web. Available online: https://www.parity.io/1043
a-postmortem-on-the-parity-multi-sig-library-self- destruct/1044
(accessed 5-April-2020)1045
[44] Ethereum Smart Contract Best Practices, Known At-1046
tacks. Available online: https://consensys.github.io/1047
smart-contract-best-practices/known_attacks/ (accessed 5-April-1048
2020).1049
[45] Pinz´on, C. and Rocha, C., 2016. Double-spend attack models with time1050
advantange for bitcoin. Electronic Notes in Theoretical Computer Science,1051
329, pp.79-103.1052
39
[46] Landa, R., Griffin, D., Clegg, R.G., Mykoniati, E. and Rio, M., 2009, April.1053
A sybil proof indirect reciprocity mechanism for peer-to-peer networks. In1054
IEEE INFOCOM 2009, Rio de Janeiro, Brazil, pp.343-351.1055
[47] Apostolaki-Iosifidou, E., Codani, P. and Kempton, W., 2017. Measurement1056
of power loss during electric vehicle charging and discharging. Energy, 127,1057
pp.730-742.1058
[48] Kriukov, A. and Gavrilas, M., 2019, May. Energy/Cost efficiency study1059
on V2G operating mode for EVs and PREVs. In 2019 8th International1060
Conference on Modern Power Systems (MPS) (pp. 1-6). IEEE.1061
[49] Bitcoin Core Requirements and Warnings. Available online: https:1062
//bitcoin.org/en/bitcoin-core/features/requirements (accessed 2-1063
may-2021)1064
40