Green-Software-Foundation / hack

Carbon Hack 24 - The annual hackathon from the Green Software Foundation
https://grnsft.org/hack/github
14 stars 1 forks source link

Build a plugin for calculating SCI of blockchains #60

Open ktg9 opened 5 months ago

ktg9 commented 5 months ago

Type of project

Building a plug-in for Impact Framework

Overview

Background

The energy consumption of blockchain is a growing concern. Currently, according to some researches, Bitcoin alone accounts for 0.38 % of the whole global electricity consumption (https://www.jbs.cam.ac.uk/2023/bitcoin-electricity-consumption). Bitcoin mining process also consumes a lot of fresh water in their cooling process, some researchers estimate that US Bitcoin miners uses around 93 - 120 gigalitres (GL), equivalent to the average annual water consumption of around 300,000 U.S. households.

With the growing popularity of blockchain technology, more blockchains will be created in the future and more users will take part in the ecosystem. That means more nodes, more transactions and more resources like electricity or fresh water are used.

There have been some efforts by blockchain organizations to reduce the energy consumption by their nodes. For example, Ethereum switching from PoW (proof-of-work) consensus mechanism to Pos (proof-of-stake) reduces 99.99% energy consumption, a fantastic result. I think the Impact Framework can contribute to the process of raising blockchain users awareness about the impact their actions/software/systems can have over the environment.

About the plugin

Here is what I have in mind for this plugin right now. The plugin would calculate how much resources consumed for these types of users:

Questions to be answered

These are some issues I would like to discuss with Carbon hack team:

  1. The most important thing is data and researches concerning the energy consumption of blockchains. The Crypto Carbon Rating Institute (https://carbon-ratings.com/) provides an API service where we can get some of the data like energy consumption annually of a blockchain. Are you aware of any other data sources or researches that we can use to do calculation ourselves?

  2. The calculation for energy consumed by smart contracts is the hardest question here I think, I've done some researches and haven't found any solid researches, also found no data sources.

Have you got a project team yet?

Yes and we are still open to extras members

Project team

No response

Terms of Participation

Project Submission

Summary

EcoChain is a GSF plugin that helps measure environmental impacts (carbon emission, fresh water consumption, electronic waste, land conversion).

Problems

Blockchain, especially Bitcoin, has a profound environmental impact. While numerous studies have calculated the environmental impact of blockchains, they typically provide only an aggregate number reflecting the environmental impacts of entire blockchain networks. While such figures are meaningful for raising awareness among blockchain users, they fail to illustrate the environmental impacts of individual users' actions in utilizing blockchains.

Application

This plugin attempts to show users the impact of their own actions by calculating the environmental impacts of each specific blockchain transaction. The environmental impacts of blockchain transactions will serve as the basis for calculating users' environmental impacts when interacting with blockchains. With this data, we can assess the environmental footprint of various DeFi projects such as UniSwap, USDC coin, Vault, and others. Smart contract developers will be able to estimate the environmental impacts of their smart contracts on different platforms such as Solana, Avalanche, and others

Prize Category

Beyond Carbon

Judging criteria

  1. Measure impacts beyond carbon:
  1. Overall impact:
  1. Educational Value:
  1. Synthesizing

Video

https://youtu.be/KhUEAdZiwpw

Artefacts

https://github.com/ktg9/EcoChain

Usage

https://github.com/ktg9/EcoChain/blob/main/examples/Basic-Usage.md

Process

The process of building this plugin:

Inspiration

Two factors that inspired me to develop this plugin are my experiences working in the blockchain industry and my desire to contribute efforts towards reducing global warming.

Challenges

Challenges that I encountered building this plugin:

Accomplishments

Learning

What's next?

This plugin could be used as a background/reference for future development to cover many other blockchains environmental impacts.

jmcook1186 commented 5 months ago

Very interesting and potentially impactful idea - here's some initial feedback off the top of my head...!

Initial take is that it will be very difficult to do ground up estimates accurately for a) multiple blockchains, and b) the entire network, although if you can source enough reliable data you could certainly try.

If you are thinking about doing bottom-up estimates, a more manageable discrete plugin could be for a specific network's client, e.g. an Ethereum validator node. You could then examine how the carbon expenditure varies across different execution/consensus client pairs, different hardware choices, number of additional validators per node, etc etc. (I'm just using Ethereum validators as an example here, you could swap out another network). Generalizing over the whole network means accounting for the different configurations of different operators (home staker, institutions, exchanges, etc) and their different hardware choices, grid carbon intensities, etc.

Bitcoin is the network with the greatest energy consumption and maybe that is good justification for focusing on creating a plugin for that first? I think it could be difficult to account for the fact that most mining is done using ASICs whose TDP is probably not easily sourced and the grid carbon intensity of the power they consume is probably also quite uncertain, and variable across locations and time, but I am really just speculating - I'd say it's well worth investigating further if you are keen for it with some of these complexities in mind.

The smart contract idea is interesting, but would be very complicated to do - is it the contract deployment you want to capture, or specific contract function execution, or the second order effects of adding code to the state trie?

The other data source I'm aware of apart from the one you cited is this https://ccaf.io/cbnsi/cbeci

on the other hand maybe there's an API call you can use to abstract away all the complexity of a ground up estimate - if you can retrieve carbon or energy from an external API then you can use our existing plugins to convert it into an SCI score.

Just some initial thoughts for discussion - encourage you to push ahead with refining the idea!!

ktg9 commented 5 months ago

Hi @jmcook1186, thank you for your comment. Sorry It took me a while to respond, because I want to read as much materials as I can so that I can discuss about this intelligently with you.

You're absolutely right about the difficulty of doing a ground up estimate. It's super hard or even impossible, since each network has multiple nodes; each node in turn runs on different OS, hardwares (and we don't know their configuration). So calculation via a models is impractical.

Right now, most of my knowledge regarding this issue coming from Crypto Carbon Rating Institute (CCRI) researches and reports. CCRI chooses the measurement via real world data approaches (as you can see in their paper https://carbon-ratings.com/dl/whitepaper-pos-methods-2023). To simplify, here is what do:

So, about your suggestion of examine how the carbon expenditure varies across different execution/consensus client pairs, different hardware choices, number of additional validators per node, etc etc, I think it's a great idea. What I can do is relying on CCRI data and build a plugin that calculate SCI scores for different hardwares, consensus mechanisms,... but then the plugin is really just a look up (since CCRI produces data by measurement, so they only tests some standard configurations, for example Intel i3-8109U, 2 cores, 8GB RAM, Ubuntu 20.04). The plugin's users can't receive the results outside of these configurations.

This also answers your question about bitcoin mining is done using ASICs whose TDP is probably not easily sourced and the grid carbon intensity of the power they consume is probably also quite uncertain; it's absolutely right. That's why CCRI chose a different approach, analyzing the minimum requirement energy consumption, producing a best guess energy consumption number and multiplying it to the number of nodes. So in this case, if I choose to use their data, then I have to trust their methodology also.

Another idea I have to the plugin is calculating SCI for each blockchain transaction (this includes, transferring tokens like ETH, USDT, BNB,..), deploying smart contract, executing smart contract function, etc. To do this, we can rely on the concept of transaction fee / gas fee. Let's take an example of Ethereum, in this blockchain, there are 3 types of transactions:

Ethereum transactions cost gas, which refers to the unit that measures the amount of computational effort required to execute specific operations on the Ethereum network and we have these data:

Here are challenges I'm facing with the above approach:

After a few days of researches, I discover that blockchain energy consumption is a vast topic and also pose a lot of questions. With the time and resources I have, I cannot produce a calculating model or do measurement via real world data by myself so I think the best way is to combine the data available from trusted sources and do some computation on that.

I really hope we can produce a plugin allowing blockchain users to know how their actions impact the environment. Hope to receive some of your insightful perspectives, @jmcook1186 and others.

jmcook1186 commented 5 months ago

Love that you came back with such a detailed response.

Bottom up energy estimates based on gas is where my mind went first too, but there are some issues to think about:

None of these are blockers, just nuances to be consider as you refine the idea.

I would love to see you get a plugin out of this research, but there are other pathways to participating in the hackathon. I think the discussion in this thread could be worked up into a solid article to submit to the "best content" category (e.g. a detailed break down of why these bottom up estimates are hard plus recommendations for heuristics that can be applied), especially if you were to combine this with some IF-based estimates of SCI using our existing plugins (e.g. you could imagine a setup where you run some testnet validators on a cloud virtual machine, retrieve the usage stats via an API (our azure exporter plugin does this) then feeds that usage data through the sci-e -> sci-o -> sci-m -> sci pipeline to get an overall SCI score for your setup. Combined with some assumptions about hardware choices (maybe there's data?), validators per node etc etc you could potentially scale up to the network and compare with the existing data that you referenced earlier in the thread..?

Just throwing some ideas, but it seems like some combination of the concepts mentioned in this thread so far could become a pretty compelling project.

ktg9 commented 5 months ago

Hi @jmcook1186 , thank you for your answer. I spent some days to think about it as well as doing some research 😃 . I'm so happy to see you leave such insightful comments.

Here are my thoughts:

If you have time, please look through these points 😄

Regards.

canhuzmeli commented 5 months ago

This might not be the best way of doing it but to me it seems like we would have to run the nodes and measure the CPU usage by scanning the processs on the Operating System level (it is easier than it sounds). We can use one reference programming language for the node then do a relative calculation to estimate the nodes with other programming languages (we know the relative energy efficiency of programming languages anyway).

However, I am not sure why we would need a real time reporting of the energy efficiency of blockchains. This will not change drastically. An offline study done yearly will be more than enough. Am I missing something here?

jmcook1186 commented 4 months ago

Hi @ktg9 we've started having a few hackathon participants on our weekly livestream (Mondays at 1430 UTC) to chat through their ideas. If you are interested, you'd be welcome.

Sorry for slow response - we've been a bit tunnel-visioned overt he last week doing a big refactor. I'll respond to your last points soon!

jmcook1186 commented 4 months ago

Hi @canhuzmeli,

I agree you can just run some nodes and retrieve some usage stats and feed them into a pipeline to estimate e.g. carbon intensity. Similar things have been done by several groups already. I think you're right that this is sufficient for most users.

What's being proposed here is a just the ability to be more granular - I think it's nice to have both - for example, people might be able to use @ktg9 's approach to understand how to minimize the impact of their specific setup.

ktg9 commented 4 months ago

Hi @jmcook1186, I've registered this but still haven't received the email for next steps, can you check? 😃

ktg9 commented 4 months ago

Hi @russelltrow , can you check this for me?

russelltrow commented 4 months ago

Hi @ktg9 registration emails will be going out to all teams this week. Keep an eye on your inbox :)

Sophietn commented 4 months ago

Hi @ktg9 I see you have the 'recruiting' label for your Hackathon project! Would you be interested in taking a segment on any of our Weekly Live Hackathon Prep and Q&A Sessions taking place every Monday 2.30 GMT, to discuss your idea and attract participants?

ktg9 commented 4 months ago

Hi @Sophietn , I've decided to run this project solo 😄

Sophietn commented 4 months ago

Hi @ktg9 - No problem. I'll remove the recruiting label on this issue. Best of luck!