# Proof of Flow: A Design Pattern for the Green Energy Market
## 5 Discussion
### Gas Consumption  
To evaluate the efficiency and operational costs of the designed smart contracts, we performed a series of simulations, under various conditions, with the aim of quantifying the gas consumption in different scenarios. Table 5 shows the gas consumption of the smart contracts' deployment in the first three rows, then the gas consumption for executing the main functions. Of course, unless ARIA's logic must be updated, deployment is performed just once for each smart contract, hence the related gas consumption is one-shot. The Join() function has a fixed cost due to the allocation of space for storing the data that characterize DERs, which must be saved.  
We have analyzed the costs of SweepEpoch() considering three different cases and a varying total number of DERs. This quantity affects the cycles that access the lists of prospective and active DERs, while the scenarios \"supply start\", \"ongoing supply\", and \"supply end\", give different results due to some operations that are only carried out under specific circumstances. e.g., under normal conditions (i.e., a DER is compliant with the rules and the energy production is performed continuously), a DER is moved from onelist to another only at the beginning or at the end of its supply period. The selection of new DERs depends on the adopted criteria. In our experiments, DERs were selected in a first-come-first-served basis until the required aggregate power was reached.  
During each execution, the SweepEpoch() keeps track of the gas used and calculates the total cost by multiplying it with the tx.gasprice. The latter is set by the user when requesting a transaction and represents the price in wei per unit of gas (1 wei = 10\({}^{-18}\) ETH, the smallest unit of Ether). The function then splits the cost equally among the active DERs and the Aggregator, and deducts it from their respective rewards. This approach ensures fairness in the allocation of costs.  
In our analysis, the best-case scenario occurs with ten DERs in the \"supply start\" stage, consuming 73,543 gas units for each DER. The worst-case arises when a single DER is in the \"supply start\" phase, consuming 212,391 gas units.  
According to Etherscan ([[https://etherscan.io/chart/gasprice](https://etherscan.io/chart/gasprice)]([https://etherscan.io/chart/gasprice](https://etherscan.io/chart/gasprice)), accessed on 1 September 2023) from August 2022 to August 2023, the minimum gas cost was just less than two Gwei, while the maximum was around 97,456 Gwei (1 Gwei == 10\({}^{9}\) wei). It should be noted that this maximum value was much higher than other observed max values during the said period, and much higher than the average. If SweepEpoch() had been invoked with the gas price set to 20 Gwei per gas unit, the cost would have been 14,708,520 Gwei (ETH 0.01470852). Taking into account the average price (according to [[https://www.coingecko.com](https://www.coingecko.com)]([https://www.coingecko.com](https://www.coingecko.com)), accessed on 1 September 2023) between the relative minimum and maximum values of ETH during the cited time range--USD 1606.89 (EUR 1506.32)--the final fees would amount to USD 23.63 (EUR 22.16) to be split among DERs and Aggregator, resulting in USD 2.15 (EUR 2.01) for each.  
The significant gas price fluctuation demands monitoring it daily and setting an appropriate maximum gas price for the transaction that invokes the SweepEpoch(). This activity can be integrated into the Aggregator's listener that monitors the blockchain to generate blockstamps and detect the end of an epoch.