Blockchain-based Life Cycle Inventory

Hello,

I am writing my master’s thesis at the moment. My topic revolves around supply chain management, Life Cycle Inventory (ecological footprint of a product) and blockchain.

One of my tasks is to find out if the structure of a supply chain can be retrieved by the financial transactions of companies on the blockchain.

The reason behind it is that the most of the companies get their data to calculate the ecological footprint only from tier1 suppliers, which means direct suppliers. But in most cases the suppliers also have suppliers (tier2) and so on. The data that companies can not easily retrieve, they take from a database like ecoinvent, where the data is categorized. If two companies make similar products, it is likely that the tier2 and tier3 data comes from a database, which makes it hard to compare the ecological footprints of these products. This is why the quality of this data is sometimes not very high.

My scenario is the following:
Company C buys Metal from its supplier Company A. Company C sends a financial transaction with a stable coin to A and in return gets information about the ecological footprint of the product in form of a ipfshash. Can this be done in one transaction, so it would be maybe easier to retrieve the data from the network later or what do you think how this could be done the best way?

(Also in the best case the data should be encrypted homomorphically, because that data is most likely confidential and it has to be possible to calculate the ecological footprint out of it. Moreover another competitor could extract information out of the transaction and have an advantage. I found the Microsoft SEAL library, however they only support single-key homomorphic encryption, which wouldn’t be of much use, because then all the companies would have to use the same secret key to encrypt the message. I found a paper in which multi-key homomorphic encryption is discussed which would solve the issue, but it is only a proof of concept. But this is not priority number one for now.)

Thank you,

Max

1 Like

Hi Max (@GiraeffleAeffle),

Welcome to the community :wave:

I don’t have any knowledge on this domain so struggling a bit to get my head around it. The below is some thinking out loud.

I’m not sure I understand the benefits of using blockchain over a centralized data provider for this usecase, unless there is a way to incentivize the suppliers as data providers.

I am cautious about how many companies would be prepared to put financial transactions on a public blockchain. Though I think projects such as Baseline Protocol (https://docs.baseline-protocol.org/) have the potential to change this.


That aside, thinking about your scenario

Assuming that for your purposes it is about the ecological footprint data rather than the amount of the transaction, you could separate this into a payment or a right to request the footprint data.

Company C creates a transaction requesting data from Company A (and either has an access token such as an ERC721 or makes a payment for the data).

Company A listens for these requests and then provides the data back to Company C. On chain, this could be storing a hash (showing proof of existence) and then providing the data off chain. The data could be encrypted using a key provided by Company A (if the data is specific to Company A).

The payment could be held in an escrow contract, until the data is provided, and then the payment is released.

Unless the data (or the hash) is already on-chain, then I am not sure how it could be done in a single transaction.

Feel free to ask all the questions that you need.

1 Like

Hi,

thank you for welcoming me and taking the time to try to help me!

The scenario is pure hypothetical and I also thought about the adaptions in real life before and incentives like they would safe taxes if they are part of the program or something but I will only mention them in the discussion part of my thesis.

Thank you I already had a look into the baseline protocol and more specifically the radish34 supply chain Proof of Concept.


Thank you that approach sounds interesting and I will think about it more deeply. I’m also questioning the task since the beginning, because I’m not sure how the financial transaction gives me any valuable information. That’s why I ignored the part of the financial transactions and only set up one Smart Contract where all the data comes to, because I was not sure how I can get the data from the network of several Smart Contracts (every company one) whose address and ABI I don’t know.

My biggest concern at the moment is how I would get the structure of an individual supply chain in a network of thousands transactions (in Ethereum), if in the transaction itself there is no information about that and even if it would be encrypted. For example like in the following picture which has two different supply chains red and blue.

image

I would have this relations:

A -> B
A -> B
B -> C
B -> D
E -> D

I imagine in the Ethereum Network the letters would be contract addresses and there would be a lot more transactions. How would I know which of the two A->B Transactions belongs to the red or the blue Supply chain?

Thank you

Max

1 Like

I think I got lost in what you are trying to do here.

I assume you know at least addresses A and E.

If you are trying to track groups of transactions, if they are public then this should be possible, though amounts may differ and they may be spread over time, so could be quite challenging.

I would look to see what information analytic tools such as https://tenderly.dev/ or https://aleth.io/ could provide.

I don’t know how you would do this due to the overlap.

1 Like

Thank you for the tools you provided me. I also checked out https://thegraph.com/ but I’m not sure if I even need it, if I would just send it to one smart contract.

So if I would make it easier just by letting the companies send their transactions to one Smart Contract, which would be mine. I take the role as a independent institution that checks the environmental footprint of every company (and they don’t have to expose private information because the data would be homomorphically encrypted). At the moment I send the information of a supplychainID in the transaction to give the supply chains a unique ID, but then you would have to know all participants that use the same supplychainID. The question is if it is somehow possible to get the structure of an individual supply chain without having the supplychainID.

Does that make sense?

1 Like

Hi @GiraeffleAeffle,

Unless a transaction for the entire supply chain is atomic, then to ensure that you capture all the transactions, I assume you need a registry with all of the contracts/addresses in the supply chain, or have the contracts emit events (implementing an interface) with the supply chain ID.

Without this, then I assume you would need to use analytic software to trace the transactions based on amounts and timing to map out the supply chain.

1 Like

I’m actually working on a basic SupplyChain SmartContract right now. I’ve read over your question and this thread several times. This is what I have created so far in solidity:

Company A Inc. Creates a Widget and stores the price of the widget in a SmartContract. An address is created for Company B. Inc to send a payment to. Once payment is sent to the address an event is triggered to notify Company A Inc. to ship Widget 1 to company B Inc.

What I wrote is a simple contract. From what I’ve read, correct me if I’m wrong, you’re looking for Company A Inc.'s products line to be stored in IPFS Data and be encrypted. Next, you are looking for Company B Inc to transact with Company A Inc., and have that transaction in a log via some type of analytics. All the while Company C Inc., is purchasing products from Company A Inc. as well. I seem to get lost at Company E.

Like @abcoathup stated I can see an ERC721 token working nicely to handle this. My Smartcontract is very basic, but I’m trying to visualize how I would scale it up to meet your question.

I imagine adding the IPFS Data to a createItem function so that you could input item creation on a large scale. The way my contract runs is for you to be the owner and have other companies transact with you. Are you also looking for the IFPS data of Widget 1 to automatically be sent to Company B Inc. in the same smartcontract?

If it helps here is the code from the tutorial I am taking.

import "./Ownable.sol";
import "./item.sol";

contract ItemManager is Ownable {
    
    enum SupplyChainSteps{Created, Paid, Delivered}
    
    struct S_Item {
        Item _item;
        ItemManager.SupplyChainSteps _step;
        string _identifier;
        uint _priceInWei;
    }
    mapping(uint => S_Item) public items;
    uint index;
    
    event SupplyChainStep(uint _itemIndex, uint _step, address _address);
    
    function createItem(string memory _identifier, uint _priceInWei) public onlyOwner {
        Item item = new Item(this, _priceInWei, index);
        items[index]._item = item;
        //items[index]._priceInWei = _priceInWei;
        items[index]._step = SupplyChainSteps.Created;
        items[index]._identifier = _identifier;
        emit SupplyChainStep(index, uint(items[index]._step), address(item));
        index++;
    }
    
    function triggerPayment(uint _index) public payable {
        Item item = items[_index]._item;
        require(address(item) == msg.sender, "Only item are allowed to update themselves");
        require(item.priceInWei() == msg.value, "Not Fully Paid Yet");
        require(items[index]._priceInWei <= msg.value, "Not Fully Paid");
        require(items[index]._step == SupplyChainSteps.Created, "Item is further in the Supply Chain");
        items[_index]._step = SupplyChainSteps.Paid;
        emit SupplyChainStep(_index, uint(items[_index]._step), address(item));
    }
    
    function triggerDelivery(uint _index) public onlyOwner {
        require(items[_index]._step == SupplyChainSteps.Paid, "Item is further in the Supply Chain");
        items[_index]._step = SupplyChainSteps.Delivered;
        emit SupplyChainStep(_index, uint(items[_index]._step), address(items[_index]._item));
    }
}

Item.sol

import "./ItemManager.sol";

contract Item {
    uint public priceInWei;
    uint public paidWei;
    uint public index;
    
    ItemManager parentContract;
    
    constructor(ItemManager _parentContract, uint _priceInWei, uint _index) public {
        priceInWei = _priceInWei;
        index = _index;
        parentContract = _parentContract;
    }
    
    receive() external payable {
        require(msg.value == priceInWei, "We don't support partial payments");
        require(paidWei == 0, "Item is already paid!");
        paidWei += msg.value;
        (bool success, ) = address(parentContract).call.value(msg.value)(abi.encodeWithSignature("TriggerPayment(uint256)", index));
        require(success, "Delivery did not work");
    }
    
    fallback () external {
        
    }
}
2 Likes

thank you for your reply. Your SupplyChain Smart Contract is very interesting and thanks for the code.

The contract that I use atm is very simple. It has just one function and an event with the parameter supplychainId, from, to, batchId, productInformation which is an ipfshash with information about which input and output was needed to produce the product to this step of the supply chain. If an event is emitted I just save that parameters and retrieve the data from the ipfshash. Like this I can clearly sort all transactions, but the companies that send this information and are in the same supply chain would of course have to use the same supplychainId, otherwise the calculation of the ecological footprint wouldn’t work. This puts me back to the start, because the companies would still have to communicate and know each other to come to an agreement which suppychainId they want to use.

If I also want to get the payment involved that would make it a lot harder, because I believe that every company would need a smart contract that has a price feed and data feed for the product information (from an oracle?). This price feed tells the value of how much the buyer has to pay and if the amount of money that is sent to pay is correct it executes the transaction to my smart contract. Or am I completely wrong?

On the other hand the most ideal scenario would be if the companies could just exchange the ecological footprint data in their transactions and I would be able to read this data from the public blockchain as an independent institution. But I’m not sure if that would even make any difference, because I would still need their contract address and ABI to be able to read their events.

So like in my post before in the example of the blue supply chain:

D is the final product. D only knows its tier 1 suppliers, which are in this case E and B. But B gets some resource from A. D doesn’t know A. So B would have to talk to A and tell him that they want to use the same supplychainId for the product that D produces. -> Problem

I want to find a way that the companies do not have to know each other and I would be able to calculate the ecological footprint of the product just by looking at the transactions (without the supplychainId) and sort them to the structure of the supply chain, but I’m really not sure if that is possible without having any id or anything to sort them.

2 Likes

You’re welcome, glad the code helped out a bit.

If I also want to get the payment involved that would make it a lot harder, because I believe that every company would need a smart contract that has a price feed and data feed for the product information (from an oracle?). This price feed tells the value of how much the buyer has to pay and if the amount of money that is sent to pay is correct it executes the transaction to my smart contract. Or am I completely wrong?

My knowledge of Oracles is minimal at best, but yes it sounds correct.

To answer what you are looking for, I can’t help but think of ZK-Snarks and their use in anonymous transactions.

Earlier you wrote:

How would I know which of the two A->B Transactions belongs to the red or the blue Supply chain?

“Suppose Bob is given a hash H of some value, and he wishes to have a proof that Alice knows the value s that hashes to H . Normally Alice would prove this by giving s to Bob, after which Bob would compute the hash and check that it equals H .
However, suppose Alice doesn’t want to reveal the value s to Bob but instead she just wants to prove that she knows the value. She can use a zk-SNARK for this.” (https://media.consensys.net/introduction-to-zksnarks-with-examples-3283b554fc3b)

If I’m not completely off base, you could use the logic behind ZK-Snarks to have A>B>C Transactions to have one secret and then use A>B>D Transaction to have a separate secret if I’m not mistaken. However my knowledge of ZK-Snarks is little to none and I could be completely wrong here! (I am most likely going to end up editing this reply.) Nevertheless, you wouldn’t be using the same supplychainId, but instead hashes. You would need some kind mechanism to coordinate the cross between the two smart contracts as complex as ZK-Snarks. You then would need to decipher the hashes and tell SmartContract 2 to know SmartContract 1 thus knowing A. I have no clue how to go about doing this, but first I would take a stab at ZK-Snarks. I also may need some kind of internal operator listening for a trigger hash in SmartContract 1.

Regardless, this is how you do anonymous transactions and does solve that problem. Maybe with some cleaver whiteboarding one could find a way to craft a mechanism like the example above to do what you want to do.

Also a good read: https://www.binance.vision/blockchain/zk-snarks-and-zk-starks-explained

2 Likes

@Proteu5 @abcoathup

Thanks a lot for your replies. Your approach sounds very nice, but unfortunately I don’t have much time anymore to finish my thesis. That’s why I will stick to my approach, although it doesn’t do what I want to do, but I think there is just not enough time to read in all of this topics like (zk-SNARKs, Oracles and the Baseline Protocol) to be able to fully understand them and find a solution, if there is one, in a scope of a master thesis, especially because I only started to learn about Ethereum and Solidity and Web3 and so on in the beginning of the year. I will just mention the drawbacks of the approach that I used in my discussion and possible solutions that maybe not yet exist.

Nevertheless I will have this in the back of my head and can maybe at some point come back to it.

Thank you

1 Like