Peer-to-peer electricity trading system: smart contracts based proof-of-benefit consensus protocol

  • Chao LiuEmail author
  • Kok Keong Chai
  • Xiaoshuai Zhang
  • Yue Chen
Open Access


Nowadays, people trade electricity through centralized companies or organizations which is vulnerable to cyber attacks and incapable of coping with increasing demands from stakeholders. In this paper, we propose a new Peer-to-Peer Electricity Blockchain Trading (P2PEBT) system based on the current charging and discharging schemes for electric vehicles (EV) in the smart grid to enable users to participate in the trading process. In order to cope with the current situation of the high volume of EV integration, the proof-of-Benefit (PoB) consensus primitives are proposed for P2PEBT to achieve demand response by providing incentives to balance local electricity demand in the novel blockchain system. PoB is implemented by executing the smart contracts on the Ethereum platform, and the process of achieving the maximal benefits is completed by submitting the transaction in the decentralized network. Security analysis shows that the P2PEBT system is able to manage a potential protection against up to a number of attacks. We demonstrate that the proposed system using the PoB consensus mechanism can achieve lower power fluctuation without requiring a third-party intermediary.


Electric vehicles Distributed trading system Transactional energy Blockchain technology Consensus mechanism Smart grid 

1 Introduction

The large-scale integration of renewable energy sources imposes huge challenges in the current grid systems, mostly due to the fact that the power generation and management from renewable energy sources are intermittent and fluctuating. Moreover, the fast-growing adoption of EVs brings challenges to the traditional power grid system, where the significant load demand precipitated through the integration of EVs burdens the power transmission substation and affects voltage stability in the power consumption during the peak time.

Traditional power grid system is becoming more vulnerable, so the smart grid which combines the stand-alone microgrids and large-scale electric power plants is envisaged to be the next generation power grid [1]. It enables two-way flows concerning electricity and information which enables an automated operation and the capability of the distributed network operator to preserve the stability and resilience of the grid system [2]. Also, EV can be treated as mobile energy storage with the bi-directional electricity flow features to provide ancillary services, such as load flattening, peak shaving, and frequency fluctuation mitigation [3]. Then the vehicle-to-grid and grid-to-vehicle concepts are designed that act as the provision of promoting greener energy from the surplus energy in EV to the grid system [4].

To realize a stabilized grid network by favoring the balance of the excess electricity amount in the EV, various charging and discharging scheduling techniques are proposed. The author [5] proposed an optimal scheduling and overall load reduction problem in the islanded operation mode, and it used the distributed computation method to run the optimization problem for the microgrid operation. The proposed solution finds out the minimal amount of power load reduction while ensuring the basic requirements for reliable grid network operation. Moreover, a stochastic program that incorporates the risk management in [6] is proposed to provide frequency regulation service with the aid of EVs and an aggregator. The author [7] proposes an aggregation-based optimization model for EV charging considering the random features in the charging procedure including arrival time and state-of-charge. In [8], the proposed scheme used centralized aggregator to optimize the power loads which lacks individual decision and undermines the autonomy of the grid participants. However, the aforementioned schemes rely on electricity consumption or bill predictions, and the training data is based on historical power consumption and user profiles. In [9], a dynamic price incentives market mechanism is proposed to balance the local renewable energy production and support flexible demand. In [10], the blockchain based trading platform is proposed to support decentralized energy market with distributed optimization and control. In [11], a more sophisticated dynamic power network infrastructure is able to advance the small-scale generators and overall resilience. In [12], a transactional energy system is introduced to increase the flexibility of the energy transaction. Transactional energy is a sequence of energy transactions for a delivery of an amount of energy commodity in the specified timeframe and location to support business for all parties including power generators and distributed system operator. Henceforth, the distributed electricity trading platform is based on the frequent communication of offers and demands among the power consumers and operators respectively.

In the traditional energy trading system, it normally involves order generation, broker-dealer, trade compliance, order management, price delivery, exchange execution and settlement accounting, which are time-consuming and lack of flexibity [13]. Based on the aforementioned studies, the energy trading process in the decentralized system can achieve demand response by incentivizing EV owners to trade electricity regarding their self-interest [14]. Applying the market-based electricity trading system to the grid network is envisaged to reduce the dependency of agents on the aggregator, wherein the present energy management architectures the lack of coordination among actors limits the capability of peer-to-peer trading. Motivated by these studies, this paper exploits the feasibility of applying the blockchain technology to the electricity trading market to develop a transparent and stable power system. The current blockchain primitives can be designed to support public audit and share transactions records without relying on a trusted intermediary. Moreover, since electricity consumption along with the overall power grid performance needs to be optimized, a proof-of-benefit (PoB) consensus mechanism is presented to achieve better economic benefits compared to other consensus mechanisms such as proof-of-work (PoW) and proof-of-stake (PoS) in the grid.

The contribution of this paper are summarized as follows:
  1. 1.

    We develop a Peer-to-Peer Electricity Blockchain Trading (P2PEBT) System to achieve transparent and stable electricity trading.

  2. 2.

    We propose a novel consensus primitive—PoB—and a blockchain design that uses it to adapt electricity trading system to stabilize the smart grid system.

  3. 3.

    To flatten the power consumption profile, we further propose the benefit index to select the winning block in the consensus mechanism to achieve the minimum power fluctuation.

The remainder of this paper is as follow. In Sect. 2, it introduces the state-of-the-art of the blockchain technology and its application in the peer-to-peer electricity trading market compositions. In Sect. 3, the concept model is presented for the distributed energy market with components in smart grids. The problem definition and the solution PoB consensus mechanism are proposed in Sect. 4. Then, security analysis and simulation results for a local area trading platform with the EV market and the concept model evaluation are presented in Sect. 5, and the paper is concluded in Sect. 6.

2 State-of-arts of blockchain applications

The blockchain technology promises to provide a shared and secure decentralized ledger for individuals and companies to exchange digital assets and track ownership over a distributed encrypted network [15]. The advanced features of blockchain is a genuine combination of several technologies including distributed computing, cryptography, and game theory, where the technological and economic primitives are elegantly considered [16]. The data integrity is guaranteed via the nature of the distributed feature. The encryption system that uses public and private keys offer the capabilities for users to sign transactions. Moreover, the consensus mechanism guarantees its robustness against misbehaving and malicious participants and incentivizes participants maintain to validate transactions. Henceforth, the blockchain is a promising technology for broad business sectors where transparency, trust, and efficiency are needed. The author [17] proposed a novel energy trading mechanism based on blockchain technology to adopt the decentralized locally generated electricity. However the blockchain technology in this paper is only used as a database to record transactions. In [18], the authors evaluate the economic features of the market mechanism for local energy trading based on the distributed information and communication technology. A comprehensive internet of thing business model is designed in [19] to enable P2P trade for paid data based on the blockchain and smart contract. However, the trading model does not perfectly adapt to the energy sector trading to address frequent transaction needs and overall system performance consideration.

Bitcoin is one of the most widely-used blockchain systems that uses PoW to solve the critical challenge of reaching consensus among participants [20]. PoW requires participants to dedicate computation time and energy towards “work”, where the processes of initiating this consensus protocol are called miners. Miners are required to solve a hash code crypto puzzle before encapsulating the transactions into a new block [21]. The miners repeatedly select a nonce which is the difficulty for solving the puzzle to obtain a result lower than the threshold, where the network peers are fighting using their computation source. Undoubtedly, there is a huge waste of energy and requires a constant global effort. Moreover, in order to reduce the number of forks of the chain, Bitcoin’s PoW is designed to produce a new block on average of 10 min and the difficulty in mining a new block is increasing. Thus, the recommended waiting frame is 6 blocks before accepting a transaction, which makes it impossible for many applications such as electricity trading [22].

To address the energy consumption waste of PoW consensus mechanism, various alternative consensus mechanisms have been proposed, such as proof-of-stake [23] and proof-of-luck [24]. These approaches aim to replace the useless work of solving puzzles by selecting a leader for deciding the next block according to their stake shares or the pure luck of the participants. Though making energy consumption less wasteful, they still require a fair amount of available computation resources. The practical Byzantine fault tolerance algorithm enables a system to reach consensus and proceed transaction within a few network information exchange which against up to one-third participants attack [25]. But this algorithm requires the network having the global knowledge of the participants and does not scale in the number of participants. The problem of consensus is that participants of the distributed system must agree on and accept a single shared state [24]. In order to adapt the frequent trading demands and consider the global power network delivery quality in the energy sector, an adaptable consensus mechanism is needed.

The QuorumChain developed by JPMorgan Chase executes smart contracts with the Ethereum virtual machine which designs an alternative consensus protocol of the public Ethereum blockchain [26]. The smart contract in blockchain is implemented by open-source agreements, which is used by this protocol to validate blocks. In [27], the authors presented the insight of using smart contract to allow the automation of multi-step processes to self-execute the distributed and heavy workflows, which is envisaged in the energy industry and the internet of things. The use of smart contract offers flexibility to implement alternative consensus primitives, which in consequence provides the potential to balance supply and demand in the transactional energy market.

In summary, the uncontrolled EV charging or discharging bahavior may result in instability of the overall grid system operation. In order to adapt frequent trading demands in the smart grids in a secure and efficient way and ensure a robust grid network, it is critical to design a consensus protocol for efficient distributed grid operations on the blockchain based trading platform.

3 Peer-to-peer electricity blockchain trading system model

The revolution towards the P2P power exchange system can be achieved predicated on the diminutive-scale energy generators and EVs, where they may produce, consume, and sell excess electricity capacity like a commodity. The hierarchical structure is instead replaced by energy transactions and agreements. In this way, power loads including domestic and business users are capable of connecting to both the retail for end users and wholesale market from the conventional power generators. This paper proposes a peer-to-peer electricity trading system that sanctions prosumers to trade energy while ensures the overall network quality with its designed consensus mechanism.

3.1 Overview of P2PEBT system

As shown in Fig. 1, in the traditional power grid system (Fig. 1a), the electricity flow is hierarchical and the electricity exchange process relies on the retailers to participate in the price negotiation process. In order to adapt the existing conventional power system, we can refer to the Fig. 1b that we adopt the conventional power delivery system. The system reformation lies in the middle to the low voltage level where the power loads are delegated in microgrid containing renewables, small power storage, and EV. Besides providing the wholesale market in the conventional grid system, transactional energy enables coordination of retail customers utilizing frequent tranching transactions to be executed automatically by blockchain embedded system, consequently reducing the centralized features of the next generation grid system [28].
Fig. 1

Electricity trading system model comparison. a Traditional hierarchical power distribution system. b Proposed decentralized power exchange system with microgrids

In the P2PEBT system, all components in the microgrids such as domestic users, batteries, solar panels, and EVs are capable of drawing and injecting electricity into the power network. The electricity asset is assumed as a smart property as ownership of this asset can be controlled by smart contracts. The advantage of treating electricity as the smart property is that it can be controlled via digital devices and the asset ownership transfer can be achieved at low cost. For EVs, the charging and discharging process can be realized by a programmable charge installation which enables the instant on/off switching the electricity flow as instructed by EVs (assuming the sophisticated design of switches). The demands for buying and selling electricity is defined as transactions, in which the information is broadcast in the grid system via an appropriate wireless network [29]. The transactions can also be executed between retail and wholesale markets which equalizes the opportunity for all components. Moreover, the exchange procedure must account for the transmission and distribution limits and other physical constraints on the grid.

As discussed above, the P2PEBT system conforms to the following rules:
  1. 1.

    Adaptable The fundamental components of the P2PEBT system is taken as the reference to the current market compositions, which also have been modified to adopt the blockchain technology. P2PEBT system remains the integrity of the traditional model and complies to the market rules.

  2. 2.

    Efficient The transaction process eliminates the involvement of the third party comparing to the traditional retail process, thus the amount of time consumed is decreased while the efficiency is improved in a transparent exchange way.

  3. 3.

    Flexible The proposed model deploys an open trading platform which allows more energy prosumer types to enter the exchange market in a more flexible manner.

  4. 4.

    Cost effective The new electricity system builds a direct connection between buyers and sellers while ensuring the overall power network stability, which maximizes the economic return for both the grid system operators and individual users.


3.2 P2P trading model in P2PEBT system

As depicted in Fig. 2, the microgrid components are the nodes in the P2PEBT system and they are able to publish transactions according to their demands. The demands of buying and selling electricity are encapsulated as transactions in the P2PEBT system, where each transaction period is defined as
Fig. 2

Structure of proposed P2PEBT system transaction process

\(T_{round}\). \(T_{round}\) is the time for mining a new block in the blockchain which is defined by the consensus primitives. And each node is capable of setting the price for the electricity transaction to incentivize users to balance the supply and demand, in the meantime, to reduce the power generation and consumption peaks. For each transaction (\(\overrightarrow{TX_{i}}\)) that is published by the prosumer i in the P2PEBT system, it is formulated as Eq. (1) in the form of a vector.
$$\begin{aligned} \overrightarrow{TX_{i}} = (\gamma , Id_{i}, \sigma _{i}, Q_{i}), \end{aligned}$$
where the \(Id_{i}\) is the identifer for the transaction initiators , the \(\sigma _{i}\) is the unit price for the electricity transaction, the \(Q_{i}\) is the transaction quantity, and \(\gamma\) is a status matrix:
$$\begin{aligned} \gamma = \left\{ \begin{array}{ll} 1, &{}\quad \text {buy\, order}\\ 0, &{} \quad \text {sell\, order} \end{array}. \right. \end{aligned}$$
1. Transaction initialization In order to protect users’ privacy, the transaction payload is encrypted by the transaction manager where the actual contents of the transaction are presented by hash. In P2PEBT, the transaction details can only be accessed by the deal nodes and the real contents can be revealed by identity registration with the transaction manager.

2. Transaction aggregation After completion of order preparation, all transactions are aggregated including the amount of electricity and expected serving time. The system will count the total electricity demands and call the smart contracts to execute energy trading.

3. Consensus commitment The consensus mechanism is applied to the transactions to select a leader of the current process. The leader broadcasts block data and its PoB to other authorized nodes. The nodes then audit the block data to see if the hash matches its local records in the nodes hash verification process. If the hash results are matched, nodes will accept the new data block and proceed to the next step. If not, then the new block generation process will be terminated and the system waits for the next round. More details of the PoB mechanism will be given in Sect. 5.

4. Block generation The agreed transaction data is then broadcast to the whole network and only participants being selected in the new block are able to decrypt the block contents to execute the transactions. Then the encrypted block contents can be executed in the network.

3.3 Problem definition for electricity trading

In this section, we present the problem definition for the amount of electricity for EVs in the P2PEBT system to charge and discharge to minimize the overall power fluctuation in a grid system composed of microgrids. We define that the component in the P2PEBT node with the characteristics of EV that is capable of both drawing and injecting energy into the same entity, and we will refer them as EVs for simplicity. We define that the components in the P2PEBT node can draw and inject energy into the grid. In this paper, we assume all components are EV with the capabilities of drawing and injecting energy into the grid. Within and between each microgrid, the prosumers including EV are denoted as nodes and they are able to draw or inject electricity into the grid. A set of microgrids (denoted as \(M_n\)) is indexed by n, where \(n\in \omega :=\{1, 2, \ldots , n\}\). We denote that a set of charging EVs in \(M_n\) as \(\chi :=(CV_{i}^{n} | i\in \mathbb {Z}, n\in \omega ), \mathbb {Z}= \{0, 1, 2, \ldots , I\}\), where i is the charging EV index and I denotes for the total number of charging EVs. The discharging EVs in \(M_n\) denoted as \(\psi :=(DV_{j}^{n} | j\in \mathbb {Z}, n\in \omega ), \mathbb {Z}= \{0, 1, 2, \ldots , J\}\), where j indexes the discharging EV and J is the total number of discharging EVs. \(\chi _{i}^{n, min}\) and \(\chi _{i}^{n, max}\) are the minimum and maximum electricity charging demands in \(M_n\), which correspond to the minimal energy for EV normal use and battery capacity respectively for \(CV_{i}^{n}\).

Then we define \(\chi _{ij}^{n}\) is the power demand of \(CV_{i}^{n}\) for directly obtaining electricity from the EV \(DV_{j}^{n}\) in \(M_n\). The electricity demand vector of \(CV_{i}^{n}\) is \(X_{i}^{n} :=\{\chi _{ij}^{n} | j\in \mathbb {Z}\}\). Considering that we need to satisfy the minimal charging demand for EV, the energy demand (\(C_i\)) function at round time \(t\in [1, 2, \ldots , T]\) is defined as follows:
$$\begin{aligned} C_i\big (X_{i}^{n}(t)\big ) ={\upsilon \sum _{j=1}^{J}\chi _{ij}^{n}(t) - \chi _{i}^{n, min}(t)}, \end{aligned}$$
where \(\upsilon\) is the electricity charging efficiency in the power exchange process.
For the discharging EV in P2PEBT system, the amount of available electricity supply is \(o_{j}^{n}\) from discharging EV \(DV_{j}^{n}\) in \(M_n\). And the corresponding electricity supply vector is \(O_{j}^{n} :=\{o_{j}^{n} | j\in \mathbb {Z}\}\). Then we can define the maximum electricity supply (\(H_j\)) from discharging devices at round time \(t\in [1, 2, \ldots , T]\) as follows:
$$\begin{aligned} H_j\big (O_{j}^{n}(t)\big ) = \varpi \sum _{j=1}^{J}\big (o_{j}^{n}(t)\big ), \end{aligned}$$
where \(\varpi\) is the discharging efficiency taking into account of transmission line loss.
Furthermore, we define the electricity consumption from the microgrid \(M_{n}\) at round time t as \(P^{n}(t)\), where \(P^{n}(t)\) excludes the charging and discharging loads from EVs. Since we aim to minimize the overall electricity consumption fluctuation to increase the smart grid stability, the consumption curve of a day should be as gentle as possible to achieve power balance. The objective function is to minimize the variance of slope for a period of electricity exchange, thus to achieve the network power balance. We first define the overall grid power fluctuation amount with respect to time as follows:
$$\begin{aligned} \begin{aligned} \Theta (t)&=\sum _{n=1}^{N} \left( \sum _{i=1}^{I}\big (C_i(X_{i}^{n}(t)\big ) - \sum _{j=1}^{J}H_j\big (O_{j}^{n}(t)\big ) + P^{n}(t)\right) \\&=\sum _{n=1}^{N} \left( \upsilon \left[ \sum _{j=1}^{J}\chi _{1j}^{n}(t) + \sum _{j=1}^{J}\chi _{2j}^{n}(t) +\cdots + \sum _{j=1}^{J}\chi _{Ij}^{n}(t) \right] \right. \\&\quad - \left[ \chi _{1}^{n, min}(t)+ \chi _{2}^{n, min}(t) + \cdots \right. \\&\quad \left. +\, \chi _{I}^{n, min}(t) \big ] -\varpi \sum _{j=1}^{J}o_{j}^{n}(t) + P^{n}(t)\right) \\&= \sum _{n=1}^{N} \left( \upsilon \sum _{i=1}^{I}X_{i}^{n} - \sum _{i=1}^{I}\chi _{i}^{n, min}(t) - \varpi \sum _{j=1}^{J}o_{j}^{n}(t) + P^{n}(t)\right) \end{aligned} \end{aligned}$$
then the slope of the power fluctuation curve is the derivative of the function \(\Theta (t)\) which can be represented as follows:
$$\begin{aligned} l(t) = \frac{d}{dt}\Theta (t) \end{aligned}$$
Finally, the objective function can be represented as the variance of the slope function l(t) as follows:
$$\begin{aligned}&PF: \min _{C_i, H_i}\bigg \{ \frac{1}{T}\big [ \big ( l(t_1) - \overline{l(t)}\big )^2 + \big ( l(t_2) - \overline{l(t)}\big )^2 + \big ( l(t_T) - \overline{l(t)}\big )^2 \big ] \bigg \} \text{ S.T. }\end{aligned}$$
$$\begin{aligned}&\upsilon \sum _{j=1}^{J}\chi _{ij}^{n}(t) \geqslant x_{i}^{n,min}(t), \quad \forall i \in \mathbb {Z},\nonumber \\&\chi _{ij}^{n}(t) \geqslant 0, \quad \forall i \in \mathbb {Z}, \forall j \in \mathbb {Z}, \nonumber \\&\quad \sum _{j=1}^{J}\big (o_{j}^{n}(t)\big ) \leqslant \sum \big ( Q_i(t) | \gamma = 0\big ), \quad \forall j \in \mathbb {Z}, \nonumber \\&\quad \varpi O_{j}^{n}(t) = \chi _{ij}^{n}(t), \quad \forall i \in \mathbb {Z}, \forall j \in \mathbb {Z}. \end{aligned}$$
The first constraint ensures that there is sufficient amount of charging electricity for EV to use. Then we constrain that all EV power demands shall be considered so that the charging amount is greater than 0. In the third constraint, the amount of discharging power to be optimized shall not exceed the electricity amount from the transaction records. At last, we set the amount of discharging power from EV with consideration of the power loss is completely absorbed to guarantee the energy efficiency.
By taking the second derivative of the objective function, we can obtain the following functions:
$$\begin{aligned} (PF)^{'}:= & {} \frac{2}{T} \big [ l(t_1) + l(t_2) + \cdots + l(t_T) - T \overline{l(t)}\big ] \end{aligned}$$
$$\begin{aligned} (PF)^{''}:= & {} \frac{2}{T} \sum _{t=1}^{T} l^{'}(t) \end{aligned}$$
The objective function in (10) is strictly convex with the constraints, thus there exists a unique optimal solution as the result of the second derivative is greater than 0. The optimal solution for the objective function is denoted in the Eq. (11), where T is defined by the total round number for the electricity exchange and \(P^{n}(t-1)\) is the last round electricity consumption by other loads in the microgrid. And the reciprocal of the result of the objective function is used as the benefit for this transaction \(\lambda\).
$$\begin{aligned}{}[C_i, H_j] :=T\overline{l(t)} - P^{n}(t-1) \end{aligned}$$

4 Proposed proof-of-benefit consensus mechanism

In this section, a proof-of-benefit consensus mechanism is proposed to proceed the transactions for P2PEBT system in order to minimize the objective function. In this consensus mechanism protocol, participants are the main principals who are required to perform routines to maintain and extend the blockchain. Participants of the trading system rely on the blockchain to execute the transactions. The matching and execution processes are implemented via the grid infrastructure settings. According to the proposed P2PEBT system, the charging and discharging EVs need to submit the transactions with the required inputs. The calculation process of solving the overall benefit problem is completed in each node’s local network, where the result is then uploaded along with the launch of the proposed blockchain protocol.

As described in Algorithm 1, there are two parts of functions which are the round preparation and mining execution respectively. At the beginning of each round, peers in the network prepare to mine on a particular chain by calling the function PoBRound and pass the latest block in the network. The mining process is executed after waiting a specified round time when the nodes call the function PoBMine to mine a new block. The node passes the header of the latest and last block to be extended (previousBlock). In this process, we have to make sure that the previousBlock and the roundBlock have the same parent and each node needs to wait for mandatory ROUNDTIME for choosing the most beneficial block for the grid system. Then a benefit value is generated in the local network based on the benefit number calculated from the objective function result, which is then used to determine the winning block with transactions to be executed in the next round. A higher benefit value means that the charging and discharging schedules have a more positive impact on the overall grid performance. Furthermore, a monotonic counter is used to prevent concurrent invocations between the network peers.

In the Algorithm 2, the details to execute transactions are described. Each node in the network receives transactions from other nodes and maintains a copy of the current chain with labeled blocks. In every round, nodes call the function IMPLEMENT to proceed the pending transactions into a new block and generate a proof along with it. Then the new chain is broadcast to the network peers, in the meantime, where the chain with more benefits will be accepted if received.

The nodes will return an updated chain with the new block from the set of new transactions after executing function IMPLEMENT. The newBlock contains the hash value of root (parent) blocks, the new block made from newTXs and a proof of benefit (proof). In the function BENEFIT, it computes the overall benefits of the chain by summing up the benefit value (proof) so that we can use it to determine the authenticate blockchain with the highest benefit value. In this way, it will incentivize the system nodes to act more desirable to contribute to the overall grid performance.

In a complete execution process, each node starts with an empty blockchain, a set of pending transactions and an initial empty roundBlock. After initializing the states, nodes listen for the transactions from the network. When receiving transactions from the network, the node adds them to the block and broadcast to the network peers. Before the start of each new round, the node calls again the function PoBROUND to bind mining to the current up-to-date chain and start the next round after waiting the required timeframe roundTime.

5 Analysis

In this section, we present the security analysis of the proposed PoB consensus mechanism used in the P2PEBT system and numerical results for the power fluctuation performance after applying our electricity trading strategy.

5.1 Security analysis

P2PEBT system is designed to adapt to the electricity trading demands, where transaction and processing time should be controlled. In the meantime, we need to ensure the privacy of nodes so that the transaction data cannot be accessed by the third party. Furthermore, the system has ability against potential traditional security attacks via standard cryptographic primitives. Hence, we analyze the security aspect of our PoB consensus-based P2PEBT system.
  1. 1.

    Control of blocks: Consider a set of participants \(\alpha \in (CV_{i}^{n}, DV_{j}^{n})\), all the charging and discharging vehicles in microgrids \(CV_{i}^{n}, DV_{j}^{n} \in M_n\). The well-behaved nodes will act according to the PoB consensus mechanism where they are supposed to append the longest chain, and the new chain with the largest benefit value \(\lambda\) will be chosen as the newly added block. During each round, each node will obtain the proof which includes the benefit value based on the pre-defined algorithms. Hence, the number of new blocks that are mined by a set of nodes \(\alpha\) is proportional to the number of nodes in \(\alpha\).

  2. 2.

    Round and processing time: We propose a ROUNDTIME of 5 min, where the block confirmation time is slightly larger than 5 min. Compared to the Bitcoin blockchain, the block confirmation time is 10 min which cannot meet the requirement for frequent trading commands from participants. Furthermore, the confirmation time is longer than the Ethereum network which is normally 15 s as we need to ensure the minimal time frame for the charging and discharging process. Thus, we have chosen this value based on an evaluation of block propagation time in those networks. In the block processing time, the selection of the winning block with maximal benefit can be implemented without transmitting the complete block, and only after the winner is determined should the whole block be transmitted.

  3. 3.

    Data integrity: In P2PEBT system, we rely on the transaction manager to encrypt the transaction contents into the hash value so that the transaction contents cannot be accessed by the third party. Without corresponding keys for the hash value, a potential attacker cannot alter the contents of the transaction. The decentralized nature of the blockchain features on the data unforgeable as all transactions require digital signatures and the only way to corrupt the network is to gain the majority (51%) computing power of the system resources.


5.2 Numerical results

We evaluate the performance of the proposed PoB consensus mechanism for P2PEBT system based on the Austrian residential power consumption data from Europe Network of Transmission System Operators for Electricity [30]. A residential area with 200 households within one microgrid with the power capacity of 800 kW is considered to simulate the EV-integrated electricity trading system (N = 1). We assume that the initial number of EV in the area to be 100. According to [31], there are mainly three charging types, up to 3 kW for slow charging, 7–22 kW for fast charging points, and 43, 50, or 120 kW for rapid charging units, where the charging speed depends on the connector types.

The PoB mechanism is implemented using Python to execute the charging and discharging orders. We randomly generate the transaction demands according to the distribution of charging unit types and assign them to the charging and discharging transactions. The transactions are in chronological order in which the older transactions have higher priority in the execution process. Moreover, the EV charge connection status is modeled as two parts in half-hour manner according to the charging demand distribution throughout a day [32]. Then we randomly generate the EV connection profile where the number of transactions is the total number of connected EVs in each time slot. And the number of charging and discharging transactions are set to be 2:1. The optimization problem is strictly convex, so the optimal results can be obtained by obtaining the global maximum benefit number with the PoB mechanism.

The daily residential power consumption served as an input to the P2PEBT-enabled system with PoB consensus mechanism for simulation; more precisely as the consumption forecast for each round calculation. In each round iteration, the P2PEBT system refers to the power consumption quantity from the last time slot and calculates the overall power consumption curve slope accordingly. In Fig. 3, it demonstrates the charging and discharging electricity demand changes after applying the P2PEBT system, where we can infer the system ability to optimize the 24-h electricity flow. The blue bars are the charging and discharging demands sent from the EVs in each time slot respectively, where the green bars are the demand quantity after optimization in the P2PEBT system. The results are shown as aggregation quantity in each time slot (1 h) in a day with arbitrarily generated power demands. For example, in hour 1, the simulation result shows the effect of the PoB consensus mechanism on the electricity transaction execution. Note that we assume each transaction has a maximal waiting for two rounds which means that the transaction will be enforced to execute after two rounds to ensure that the system does not intervene EV owner’s daily routine, so the total amount of transaction quantity is ensured in this process. The darker blue and green bars represent the demands before optimization, where we can see clear peaks at 07:00–09:00 and 18:00–21:00 corresponding to the work hours, reflecting market consistency. As shown in Fig. 4, it depicts the objective function PF value from Sect. 3 to quantify the power fluctuation level with and without the P2PEBT system. The black line with circle mark is the PF value without the P2PEBT system, where the value is calculated from the last 24-h power consumption profile with the electricity demands from EV charging and discharging. The red dashed line with asterisk mark is the PF value in a day which the value changes based on the different charging and discharging demands fed from the EV users. We can see that the PF value with P2PEBT system is more stable and shows a much lower PF value by the end of the day. Moreover, the trend of the PF value change is generally growing as the number of EVs in the microgrid has limited capability to stabilize the system.
Fig. 3

Charging and discharging demands collected from EVs in 24 h

Fig. 4

PF value of the overall power grid with and without P2PEBT system

In the Fig. 5, it shows the overall power consumption including the charging transactions that consume electricity, discharging transactions that inject electricity back to the grid and the residential power loads. According to Eq. (7), we can calculate the cube root of the PF value which is 48.5. With the proposed PoB consensus mechanism enabled P2PEBT system, EV can trade electricity through placing charging or discharging transactions to the market concerning their connection statuses, charging connector types and charging/discharging constraints. This enables the reduction of the overall power consumption fluctuation level where the optimized result PF with the proposed system is 32.4, which is 33.2% lower compared to the result without optmization. We can infer that the system uses the last time slot electricity consumption data to schedule the charging and discharging transactions have significantly flattened the overall power consumption curve which will increase the stability of the smart grid. In this case, the cost for starting the subsidiary generators (power generators with less response time) to supplement the power consumption can be reduced.
Fig. 5

Power consumption profile in a residential area

6 Conclusion

The electricity industry is undergoing major evolutions that works far more than the infrastructure upgrade, where people focus more on renewable and sustainable energy. In this paper, we proposed a proof-of-benefit consensus protocol in blockchain system and further presented the P2PEBT system that works with EV in the electricity market to minimize the power fluctuation in a day. By achieving the objective, the stability is enhanced with more flattened power consumption and the operation cost is accordingly reduced corresponding to the emergent situation operation. We analyzed the state-of-art blockchain technology and the consensus mechanisms including proof-of-work and proof-of-stake where the motivation is identified with respect to the disadvantages in these mechanisms. Then, the PoB is proposed along with the P2PEBT system to support EV participating in the electricity trading with local peers. Security analysis has shown that the proposed mechanism is capable of protecting the transaction execution against potential attacks and adapting to the electricity trading scenario. Simulation results present the charging and discharging demand changes using the P2PEBT system and further implies the capability of the proposed system in substantially decreasing the PF value.

We use the real dataset from Austrian households to analyze the customer electricity consumption behavior and currently available charging speed types are adapted to simulate the proposed system. The P2PEBT system provides a brand new way to practice the transactional energy market, and the blockchain technology not only decentralizes the hierarchical power grid system but also increases the system security. In the future, it is necessary to implement the system in the blockchain platform to feed with real-time data in order to test its scalability and performance.



  1. 1.
    Liu, C., Lau, E. T., Chai, K. K., & Chen, Y. (2017). A review of wireless power transfer electric vehicles in vehicle-to-grid systems. In E. Lau et al. (Eds.) Smart grid inspired future technologies. SmartGift 2017. Lecture notes of the institute for computer sciences, social informatics and telecommunications engineering (Vol. 203). Cham: Springer.Google Scholar
  2. 2.
    Moslehi, K., & Kumar, R. (2010). A reliability perspective of the smart grid. IEEE Transactions on Smart Grid, 1(1), 57–64.CrossRefGoogle Scholar
  3. 3.
    Liu, C., Chai, K. K., Lau, E. T., Wang, Y., & Chen, Y. (2017) Optimised electric vehicles charging scheme with uncertain user-behaviours in smart grids. In 2017 IEEE 28th annual international symposium on personal, indoor, and mobile radio communications (PIMRC) (pp. 1–5). IEEE.Google Scholar
  4. 4.
    Han, S., Han, S., & Sezaki, K. (2010). Development of an optimal vehicle-to-grid aggregator for frequency regulation. IEEE Transactions on Smart Grid, 1(1), 65–72.CrossRefGoogle Scholar
  5. 5.
    Nguyen, H. K., Khodaei, A., & Han, Z. (2018). A big data scale algorithm for optimal scheduling of integrated microgrids. IEEE Transactions on Smart Grid, 9(1), 274–282.CrossRefGoogle Scholar
  6. 6.
    Yao, E., Wong, V. W. S., & Schober, R. (2015). Risk-averse forward contract for electric vehicle frequency regulation service. In 2015 IEEE international conference on smart grid communications (SmartGridComm) (pp. 750–755).Google Scholar
  7. 7.
    Zheng, J., Wang, X., Men, K., Zhu, C., & Zhu, S. (2013). Aggregation model-based optimization for electric vehicle charging strategy. IEEE Transactions on Smart Grid, 4(2), 1058–1066.CrossRefGoogle Scholar
  8. 8.
    Cazalet, E. G. (2010). Transactional energy market information exchange (temix). An OASIS Energy Market Information Exchange Technical Committee White Paper. Available online: (Assessed on August 9, 2012).
  9. 9.
    Horta, J., Kofman, D., Menga, D., & Silva, A. (2017). Novel market approach for locally balancing renewable energy production and flexible demand. arXiv preprint arXiv:1711.09565
  10. 10.
    Münsing, E., Mather, J., & Moura, S. (2017). Blockchains for decentralized optimization of energy resources in microgrid networks. In 2017 IEEE conference on control technology and applications (CCTA) (pp. 2164–2171).Google Scholar
  11. 11.
    Ilic, D., Silva, P. G. D., Karnouskos, S., & Griesemer, M. (2012) An energy market for trading electricity in smart grid neighbourhoods. In 2012 6th IEEE international conference on digital ecosystems and technologies (DEST) (pp. 1–6).Google Scholar
  12. 12.
    Oh, S. C., D’Arcy, J. B., Arinez, J. F., Biller, S. R., & Hildreth, A. J. (2011). Assessment of energy demand response options in smart grid utilizing the stochastic programming approach. In 2011 IEEE power and energy society general meeting (pp. 1–5).Google Scholar
  13. 13.
    Bunn, D. W., & Oliveira, F. S. (2001). Agent-based simulation-an application to the new electricity trading arrangements of england and wales. IEEE Transactions on Evolutionary Computation, 5(5), 493–503.CrossRefGoogle Scholar
  14. 14.
    Mihaylov, M., Jurado, S., Avellana, N., Moffaert, K. V., de Abril, I. M., & Nowé, A. (2014). Nrgcoin: Virtual currency for trading of renewable energy in smart grids. In 11th International conference on the European energy market (EEM14) (pp. 1–6).Google Scholar
  15. 15.
    Aste, T., Tasca, P., & Matteo, T. D. (2017). Blockchain technologies: The foreseeable impact on society and industry. Computer, 50(9), 18–28.CrossRefGoogle Scholar
  16. 16.
    Gramoli, V. (2017). From blockchain consensus back to byzantine consensus. Future Generation Computer Systems [Online]. Available:
  17. 17.
    Mihaylov, M., Jurado, S., Van Moffaert, K., Avellana, N., & Nowe, A. (2014). NRG-X-change a novel mechanism for trading of renewable energy in smart grids. In SMARTGREENS 2014—Proceedings of the 3rd International Conference on Smart Grids and Green IT Systems (pp. 101–106). Google Scholar
  18. 18.
    Mengelkamp, E., Notheisen, B., Beer, C., Dauer, D., & Weinhardt, C. (2017). A blockchain-based smart grid: Towards sustainable local energy markets. Computer Science—Research and Development [Online]. Available:
  19. 19.
    Zhang, Y., & Wen, J. (2017). The iot electric business model: Using blockchain technology for the internet of things. Peer-to-Peer Networking and Applications, 10(4), 983–994. Scholar
  20. 20.
    Nakamoto, S. (2008). Bitcoin: A peer-to-peer electronic cash system. Retrieved 12 Nov 2018.
  21. 21.
    Back, A. (2002). Hashcash—a denial of service counter-measure. Retrieved 12 Nov 2018.
  22. 22.
    Rosenfeld, M. (2014). Analysis of hashrate-based double spending. arXiv preprint arXiv:1402.2009.
  23. 23.
    King, S., & Nadal, S. (2018). Ppcoin: Peer-to-peer crypto-currency with proof-of-stake. Retrieved 12 Nov 2018.
  24. 24.
    Milutinovic, M., He, W., Wu, H., & Kanwal, M. (2016). Proof of luck: an efficient blockchain consensus protocol. In Proceedings of the 1st workshop on system software for trusted execution (p. 2). ACM.Google Scholar
  25. 25.
    Castro, M., Liskov, B., et al. (1999). Practical byzantine fault tolerance. OSDI, 99, 173–186.Google Scholar
  26. 26.
    Cachin, C., & Vukolić, M. (2017). Blockchains consensus protocols in the wild. arXiv preprint arXiv:1707.01873.
  27. 27.
    Christidis, K., & Devetsikiotis, M. (2016). Blockchains and smart contracts for the internet of things. IEEE Access, 4, 2292–2303.CrossRefGoogle Scholar
  28. 28.
    Patterson, B. T., & Geary, D. E. (2016). Real-time transactional power management in a microgrid mesh network: The enernet. In 2016 IEEE international telecommunications energy conference (INTELEC) (pp. 1–7).Google Scholar
  29. 29.
    Pilkington, M. (2016). Blockchain technology: Principles and applications. In: F. X. Olleros & M. Zhegu (Eds.), Research handbook on digital transformations. Edward Elgar.
  30. 30.
    ENTSOE. (2015). Consumption and production data for individual countries,, accessed June, 2018.
  31. 31.
    Lane, B., Shufflebotham, M., Lilly, C., Halley, T., Kaya, I., & Newman, C. (2017). Connector selector,, accessed May, 2017.
  32. 32.
    A. U. D. of Energy National Laboratory, Spatial resolution,, accessed April, 2017.

Copyright information

© The Author(s) 2019

Open AccessThis article is distributed under the terms of the Creative Commons Attribution 4.0 International License (, which permits unrestricted use, distribution, and reproduction in any medium, provided you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license, and indicate if changes were made.

Authors and Affiliations

  1. 1.School of Electrical Engineering and Computer ScienceQueen Mary University of LondonLondonUK

Personalised recommendations