📜 ⬆️ ⬇️

Immersion in the blockchain technology: Combating counterfeit goods

We continue a series of articles on the first projects in Russia, developed on the basis of blockchain technology. We remind you that we asked the participating teams of the InspiRussia hackathon about the technological component of their decisions.

This article will focus on the project Buydentity, which helps to deal with the problem of counterfeit goods.



The series of articles "Immersion in technology blockchain"


1. A series of materials on Emer technology:
1.1. The secrets of EmerCoin .
1.2. Decentralized uncensored domain name system .
1.3. Worldwide public key infrastructure .
1.4. Decentralized password-free security system .
2. Fast and secure transactions .
3. Ecosystem of digital dentistry .
4. Combating counterfeit goods .
5. Mutual insurance of animals .
6. What is ICO and how to conduct it .
7. Loading ...
')

Buydentity: Anti-counterfeiting


The developers of the Buydentity project are friends and enthusiasts who decided to try their hand at developing with the help of the blockchain.

The participants set themselves the task of developing a useful project, therefore, as a result, a topic was chosen on the problem of combating counterfeit goods. Before starting the development, the participants analyzed the problems of counterfeit goods circulation in the world. They found that:

  1. States do not have a systematic approach in the area of ​​counterfeit regulation.
  2. Most people find it difficult to distinguish a fake from a real product. Moreover, the quality of fakes every year is becoming higher.
  3. Increasingly, they began to forge sought-after and inexpensive goods, and not premium goods.
  4. Between the buyer and the manufacturer is a very long chain of various counterparties and intermediaries. It is impossible to understand how a particular product hit the shelves of a particular store.

Moreover, in general, there is a significant growth in the counterfeit market in the world. So according to the report of the Organization for Economic Cooperation and Development (OECD):


This is how the Buydentity project (buy (purchase) and identity (authenticity)) appeared. The platform's prototype allows you to track the entire product lifecycle based on the blockchain technology, which eliminates the creation of a fake and verifies the authenticity of the goods at any time.

At the moment, there are and implemented various solutions to combat counterfeit: 2D barcode, bar code, hologram, various protective coatings, secret ink, microprinting and protective microelements, radio frequency identifiers, protective self-adhesive labels. But all of the above methods do not give one hundred percent certainty that before you this product, or have a high cost, or can be confirmed only by the manufacturers. The Buydentity project will improve reliability by updating product information at each stage of its life cycle from manufacturer to buyer to understand its characteristics, status, involved contractors and to exclude the sale of a fake or re-sale of already sold goods.

Buydentity: Implementing an Idea


To implement this idea, each product must have a unique tracking code that will uniquely identify it at any time. For example, in the simplest case, this may be a QR code (NFC tags may also be used), which is pasted on the product. The code is associated with product identification data (color, weight, product number, batch number, photo, production date and place, manufacturer, etc.) that are recorded in the Ethereum private blockchain (platform for creating decentralized online services based on the blockchain). Such a record of product data does not allow changing its characteristics at any time, and you will be able to trace the entire path of the movement of goods.

As described above, you can mark all products and solve the problem of their unambiguous identification. However, this implementation does not solve the problem of creating counterfeit. Someone can buy one real product, copy and replicate the QR code for similar counterfeit goods. The way out in this situation is the following: it is necessary to place the status of the product and its owner in the blockchain, which will vary depending on the stage of its life cycle. To implement the logic described above, the project has deployed an Ethereum network based on the Azure Blockchain as a Service. They allowed the flexibility to customize the rules for transferring property from one member to another.

To implement the logic described above, the project deployed an Ethereum network based on the Azure Blockchain as a Service, which allowed us to flexibly configure the rules for transferring property from one participant to another. The general scheme of operation is given below.



As part of the Buydentity system, the team developed:


Below is an example of a product card in a mobile application.

Given the knowledge and experience, the following set of technologies was chosen for the implementation of the system:


Key problems and their solutions


To work with the Ethereum network, the team used the Geth client, which allows you to connect and perform transactions using the http protocol. A private blockchain was deployed for testing and debugging; however, when trying to access the management interface using the .NET-library Nethereum , a connection error to the client constantly occurred. The problem was in an outdated version of the client Geth. By the way, updates can be found in the repository on GitHub .

The next problem, which turned out to be relatively simple, arose with the connection of the Geth client to a remote client in the Microsoft Azure virtual machine. As it turned out, she was hiding not only in the client, but also in setting up the virtual machine firewall. This problem can be dealt with using the material on configuring the endpoints of the virtual machines . To access the Geth client from the outside, it is sufficient to specify the --wsaddr “0.0.0.0” flag (by default, localhost).

Ethereum smart contracts were not chosen by chance - the Solidity language syntax is simple, very similar to JavaScript, and it can be said that it is similar to C. Therefore, the first version of the contract was quickly implemented and tested using the Web IDE .

Next, for each product we create a smart contract, which stores information about the product, as well as a chain of all chain links from the manufacturer to the final seller. Only the previous owner specified in the contract can transfer ownership of the goods. Upon receipt of the goods, the new owner confirms his ownership through the same contract.

Thus, the Ethereum blockchain allows you to move away from the tasks of cryptography and the protection of important information and immediately begin to implement business tasks. The presence of "smart" contracts greatly facilitates the implementation of the idea of ​​transferring the property of a unit of goods from the participant to the participant. Here is how a smart contract for transferring goods in Solidity may look like:

 pragma solidity ^0.4.0: contract ProductItem { address[] _owners; address _currentOwner; address _nextOwner; string _productDigest; function ProductItem(string productDigest) { _currentOwner = msg.sender; _productDigest = productDigest; _owners.push(msg.sender); } function setNextOwner(address nextOwner) returns(bool set) { if (_currentOwner != msg.sender) { return false; } _nextOwner = nextOwner; return true; } function confirmOwnership() returns(bool confirmed) { if (_nextOwner != msg.sender) { return false; } _owners.push(_nextOwner); _currentOwner = _nextOwner; _nextOwner = address(0); return true; } } 

Here:


When creating a unit of goods, the information is entered into the blockchain in the form of the contract above. A smart contract cannot be deceived, therefore only the one specified in the contract _currentOwner variable can transfer a unit of goods to ownership. Further, when transferring the property, the setNextOwner(address next) function is setNextOwner(address next) , setting the next possible owner. When the next owner accepts the goods in the property, the confirmOwnership() method is confirmOwnership() .

As mentioned above, the contract cannot be deceived without having access to the wallets (that is, in fact, private keys) of the participants of the system. In order to minimize the compromise of user wallets, they are placed on a private server inside the Azure cloud. To calculate blocks in Ethereum, several servers are deployed using a separate template (can be found here ). The go-ethereum clients, which are automatically installed when the template is deployed, are connected to each other in a network (as described here ). In general, the application architecture is as follows:

Requests involving work with Ethereum are redirected to the queue. These messages are then processed by individual services. The implementation looks exactly like this, because fixing transactions that change the state of the contract is a rather time-consuming operation and it is not necessary for the user to wait for these operations to complete.

Work with Ethereum


Since the development language of the backend in the project is C #, the Nethereum library was chosen to interact with Ethereum. Below is an example of publishing a contract in the blockchain:

 public async Task<Contract> DeployContractAsync(EthereumAccount account, ContractMetadata metadata, HexBigInteger gas = null, params object[] ctorArgs) { gas = gas ?? new HexBigInteger(10*1000*1000); var tx = await _web3.Eth.DeployContract.SendRequestAsync(metadata.Abi, metadata.ByteCode, account.Address, gas, ctorArgs).ConfigureAwait(false); var receipt = await MineAndGetReceiptAsync(tx).ConfigureAwait(false); var code = await _web3.Eth.GetCode.SendRequestAsync(receipt.ContractAddress).ConfigureAwait(false); if (string.IsNullOrEmpty(code) || code.Length < 3) { throw new InvalidOperationException("Can't deploy contract. Check if gas is sufficient"); } return _web3.Eth.GetContract(metadata.Abi, receipt.ContractAddress); } public async Task<TransactionReceipt> MineAndGetReceiptAsync(string txHash) { TransactionReceipt receipt = await _web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txHash).ConfigureAwait(false); while (receipt == null) { receipt = await _web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txHash).ConfigureAwait(false); await Task.Delay(1000).ConfigureAwait(false); } return receipt; } 

Here you should not pay attention to data types, like EthereumAccount and ContractMetadata , since the basic idea should be clear. It is worth paying attention to the line:

 var code = await _web3.Eth.GetCode.SendRequestAsync(receipt.ContractAddress) 

When publishing a contract, sometimes an exception may arise about insufficient gas . To ensure successful publication of the contract, we check the result of the above code:

 if (string.IsNullOrEmpty(code) || code.Length < 3) { throw new InvalidOperationException("Can't deploy contract. Check if gas is sufficient"); } 

Ethereum blockchain is very convenient to have “smart” contracts, but for private blockchains it would be important to minimize the time of the formation of blocks in the database, so at this point the team is looking for ways to solve this problem.

Future plans


After the hackathon, the Buydentity team actively began to develop its project and represent it in various forums and public events. Detailed information about the project can be found on the website .

For the near future, the team identified the following main tasks:


Now the project team is looking for manufacturers of products for pilot implementation. For questions about the system, you can write to mail@buydentity.ru.

Source: https://habr.com/ru/post/312054/


All Articles