hyperledger-labs / blockchain-carbon-accounting

This project implements blockchain applications for climate action and accounting, including emissions calculations, carbon trading, and validation of climate claims. It is part of the Linux Foundation's Hyperledger Climate Action and Accounting SIG.
https://wiki.hyperledger.org/display/CASIG/Carbon+Accounting+and+Certification+WG
Apache License 2.0
188 stars 104 forks source link

deployment changes to net emissions tokens network #108

Closed sichen1234 closed 3 years ago

sichen1234 commented 3 years ago

The open source code can stay as it is for testing/demonstration but for net emissions tokens network in production deployment, to avoid creating a security, we can make these changes (as settings or as a fork):

  1. Only the owner can add accounts to the network in any role, including consumer.
  2. Carbon offsets and REC dealers can only propose new tokens and not issue them. The tokens can only be issued by the DAO.
  3. The tokens are always issued to the contract owner.
  4. Once the contract owner transfers them to any account, they are automatically retired and cannot be held for further transfers (ie investment or trading.)
jamesondh commented 3 years ago

WIP - https://github.com/opentaps/blockchain-carbon-accounting/commit/1c05af7c3edf3fc9c73e85e8663fa55f4b7c1bf6

There is now a private var limitedMode (that only the deployer/admin can toggle through the setLimitedMode() function) that will enable these features. It is set by default to false.

Currently implemented:

Still working on:

jamesondh commented 3 years ago

Created hook called before transfers: https://github.com/opentaps/blockchain-carbon-accounting/commit/ee5b34cf8824de272dc4ab9dbc6a3e624433de08

If to address is not the admin and limitedMode is on, then the tokens being sent will be retired -- preventing the transfer. More testing required.

jamesondh commented 3 years ago

See commit https://github.com/opentaps/blockchain-carbon-accounting/commit/03c93b25f8696a0b5947614870b84bb810a40167

More tests added to test limited functionality. Instead of retiring tokens after the initial issuance, all transfers except those executed by the admin account are prevented when limitedMode = true.

sichen1234 commented 3 years ago

Can you change some of these error messages:

  1. When trying to assign roles, "Only contract owner can assign roles in limited mode."
  2. When trying to issue tokens directly, "Direct issuance is not allowed in limited mode. Please make a proposal to DAO instead."

Also please check toggling the limited mode on and off. I could turn it on but not off.

sichen1234 commented 3 years ago

These work:

  1. Only admin can assign roles
  2. Offset dealer can only propose issuance and not issue directly
  3. Proposed tokens must be issued to admin user (contract owner) to be executed

Need to fix:

  1. After the admin user transfers tokens to another account, the account must be able to retire them, or better the tokens should be automatically retired when transferred.
  2. Emissions auditors, rec dealers, offsets dealers should not be able to transfer tokens either. Emissions auditors can issue emissions audit tokens only, which are automatically retired when issued. REC dealer and offset dealers can propose new tokens to the DAO only.
jamesondh commented 3 years ago

Updated in commit https://github.com/opentaps/blockchain-carbon-accounting/commit/6f161dab45c0049a125f4cf97e6517d2746d43e

Retiring in limitedMode works now, though it cannot be done automatically after arbitrary transfers with the current design as we use the hook function _beforeTokenTransfer() the ERC-1155 standard provides us. This function is called before minting new tokens, burning tokens, and transferring tokens, and in limited mode it will check to make sure only the admin can transfer tokens, only the DAO can issue token types 1 and 2, only audited emissions dealers can issue tokens directly, and only dealers of type 1 and 2 can make DAO proposals.

sichen1234 commented 3 years ago

Great. This all works well now. Thank you!