# Privacy-Preserving Electricity Trading for Connected Microgrids
## 5 System Description
### Basic Procedures  
Electricity is traded in small pieces of energy specified as a \"power-time\" tuple. For instance, \"10 W-10 min\" (10 watts of energy for 10 min). There is only one type of piece whose content is set before the system starts to operate. Transactions in which an offered piece of energy is matched with an energy request are paid by means of an e-coin transaction. Each e-coin is worth the price of a piece of energy. The basic procedures composing the trading system can be divided into:  
* Procedures for e-coin transactions, namely, \"withdrawal\", \"payment\" and \"deposit\";
* Procedures for energy trading, namely, \"offer\", \"request\" and \"pairing and payment\". These procedures are next explained in detail:  
1. E-coin withdrawal. Each meter manages a digital wallet which stores e-coins. An e-coin is withdrawn as follows: 1. The meter generates a random bitstring which is the payload of the e-coin to be minted. Let us denote it as \(Payload\). 2. The meter asks the substation to engage in an execution of a blind signature protocol in which \(\mathcal{H}(Payload)\) is provided as input. As a result, the meter gets the substation's signature \(\mathrm{Sign}_{SubT}(\mathcal{H}(Payload))\), while the substation learns nothing about \(Payload\) nor its resulting signature. 3. The generated e-coin is the tuple \[C=\{Payload,\text{Sign}_{SubT}(\mathcal{H}(Payload))\}\] which is stored by the meter. As is explained later, in some situations, the meter identifies itself before running the withdrawal protocol, while in some others, it runs it anonymously. 2. E-coin payment. An e-coin payment from a payer to a payee is performed as follows: 1. The payer takes an unspent e-coin \(C\) and transmits it to the payee. 2. Upon receiving \(C\), the payee parses it as \(C=\{Payload,Signature\}\) and checks whether \(Signature\) is a correct signature of \(\mathcal{H}(Payload)\) under the substation's public key or not. 3. Next, the payee sends \(C\) to the substation so as to verify that it has not been spent before. Then, \(C\) is recorded as an already spent e-coin by the substation. 4. If the previous checkings are both satisfied, the payee will be allowed to withdraw a new e-coin free of charge. This action can be carried out anonymously. 3. E-coin deposit. An unspent e-coin can be deposited to the substation. This procedure is as follows: 1. The meter identifies itself and sends an e-coin \(C\) to the substation. 2. The substation validates its digital signature and checks it has not been spent or deposited before. Then, \(C\) is recorded as an already deposited e-coin. 3. Finally, the substation pays or records the amount to be paid to the meter. 4. Energy offer. When a smart meter detects that its dwelling has available energy which can be poured into the microgrid, it partitions it into energy pieces and announces their availability by broadcasting offer messages. Each available piece of energy is announced anonymously as follows: 1. The meter generates a random serial number, \(i\). 2. The meter generates a random private key, \(Priv_{i}\), and the corresponding public one, \(Pub_{i}\). 3. The meter checks its internal clock and records the current time. Let us denote it as \(TimeStamp\). 4. The meter generates the following offer message: \[\text{Offer}_{i}=\{\text{``Offer''},i,TimeStamp,Pub_{i}\}\] 5. This message is sent anonymously through the communication channel. The substation records it. 5. Energy request. When the energy produced locally in a dwelling is not enough to satisfy its internal demand, its smart meter sends energy request messages through the broadcast communication channel. It sends as many requests as needed in order to satisfy its demand. Each request message asks for a piece of energy. A request message is generated and sent as follows: 1. The meter generates a random serial number, \(j\). 2. The meter generates the following request message: \[\text{Request}_{j}=\{\text{``Request''},j\}\] 3. This message is sent anonymously through the communication channel.