Immersion in Blockchain Technology: Combating Counterfeit Goods

    We continue a series of articles about 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 solutions.

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



    Series of articles “Immersion in Blockchain Technology”


    1. A series of materials on Emer technology:
    1.1. Secrets of EmerCoin .
    1.2. A decentralized, uncensored domain name system .
    1.3. World-wide public key infrastructure .
    1.4. Decentralized passwordless security system .
    2. Fast and secure transactions .
    3. The ecosystem of digital dentistry .
    4. The fight against counterfeit goods .
    5. Mutual animal insurance .
    6. What is an ICO and how to conduct it .
    7. Loading ...

    Buydentity: Counterfeiting


    The developers of the Buydentity project are enthusiastic friends who decided to try themselves in development using 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 turnover in the world. They found that:

    1. States do not have a systematic approach to regulating counterfeit goods.
    2. Most people find it difficult to distinguish a fake from a real product. Moreover, the quality of fakes is getting higher every year.
    3. Increasingly, they began to fake popular and inexpensive goods, rather than premium goods.
    4. Between the buyer and the manufacturer is a very long chain of various contractors and intermediaries. It is impossible to understand how a particular product fell on the shelves of a particular store.

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

    • The annual turnover of counterfeit products in the world in 2015 reached $ 461 billion;
    • Counterfeit products in the world account for approximately 2.5% of world imports;
    • In the market of European Union countries, fakes account for about 5% of total trade;
    • Most often counterfeit products from the USA (20%), Italy (15%), France and Switzerland (12% each), Japan and Germany (8% each).

    So the Buydentity project appeared (buy (purchase) and identity (authenticity)). The prototype platform allows you to track the entire life cycle of a product based on blockchain technology, which eliminates the creation of fakes and verifies the authenticity of the product at any time.

    At the moment, there are various solutions for counterfeiting: 2D barcode, barcode, hologram, various protective coatings, secret ink, microprinting and protective trace elements, radio frequency identifiers, and self-adhesive protective labels. But, all of the above methods do not give one hundred percent confidence that this is a real product, or they have a high cost, or can only be confirmed by the manufacturers themselves. The Buydentity project will improve reliability by updating product information at each stage of its life cycle from the manufacturer to the buyer, understand its characteristics, status, counterparties involved and exclude the sale of fakes or the re-sale of goods already sold.

    Buydentity: Realizing the Idea


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

    By the method described above, you can mark all products and solve the problem of their unique identification. However, this implementation does not solve the problem of creating counterfeit goods. Someone can buy one real product, copy and copy the QR code on similar fake products. The way out in this situation is as follows: on the blockchain, it is necessary to place the status of the product and its owner, which will change depending on the stage of its life cycle. To implement the above logic, the Ethereum network based on Azure Blockchain as a Service was deployed in the project. They made it possible to flexibly configure the rules for transferring property from one participant to another.

    To implement the logic described above, the Ethereum network was deployed in the project based on Azure Blockchain as a Service, which made it possible to flexibly configure the rules for transferring ownership from one participant to another. The general operation scheme is given below.



    Within the Buydentity system, the team developed:

    • Contractor’s personal account. The cabinet allows you to create goods and their individual units, track the status and movement of goods, create unique QR codes, transfer goods to another counterparty.
    • IOS mobile app for product authentication. The buyer scans the QR code and sees detailed information about the product on the screen of his mobile phone.

    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:

    • Framework: Angular 2, .Net Framework;
    • Platform: ASP.NET Core, Microsoft Azure (Ethereum Blockchain as a Service);
    • Programming Languages: C #, TypeScript, JavaScript;
    • Database: PostgreSQL;
    • Mobile application: Objective-C.

    Key issues and solutions


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

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

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

    Next, for each product, we create a smart contract that 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 protect important information and immediately start implementing business tasks. The presence of “smart” contracts greatly facilitates the implementation of the idea of ​​transferring ownership of a unit of goods from participant to participant. Here is how a smart contract for transferring goods in Solidity might 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:

    • _owners - an array of all unit owners;
    • _currentOwner - current owner of the goods;
    • _nextOwner - the next owner of the goods;
    • _productDigest- a hash calculated based on some fields of the product. When checking will allow you to check the immutability of the product description;
    • msg.sender - built-in environment variable, which contains the initiator of the transaction.

    When creating a unit of goods, information is entered into the blockchain in the form of the contract above. It is impossible to deceive a smart contract, therefore only the person specified in the _currentOwnercontract variable will be able to transfer a unit of goods into ownership . Further, when transferring ownership, a function is called setNextOwner(address next), setting the next possible owner. When the next owner takes ownership of the product, the method is called confirmOwnership().

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

    Requests that involve working with Ethereum are redirected to the queue. Then these messages are processed by separate services. The implementation looks exactly like this, because fixing transactions that change the state of the contract is a rather time-consuming operation and the user does not have to wait for the completion of these operations.

    Work with Ethereum


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

    public async Task 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 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 EthereumAccountand ContractMetadata, since the main 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, an exception may sometimes be raised about insufficient gas. To verify the 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 with the presence of “smart” contracts, however, for private blockchains it would be important to minimize the time it takes to form blocks in the database, so the team is currently looking for ways to solve this problem.

    Future plans


    After the hackathon, the Buydentity team actively began to develop their project and represent it at 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:

    • Integration of Buydentity with Offchain systems of manufacturers and retailers, which will quickly integrate our solution into existing business processes;
    • Extension of product labeling methods: RFID tags, NFC chips, laser marking and so on;
    • Development of a designer for creating goods to make the widest possible list of product data;
    • Compliance with existing international standards for product labeling;
    • Track suspicious product scans and send complaints about counterfeit goods.

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

    Also popular now: