Verifying Documents With a Blockchain System
This article aims to present a proposal for document validation using Blockchain. Even with the world moving quickly, validation processes are often slow and manual. The use of Smart Contracts and Blockchain is ideal for this manual and unreliable scenario. This decentralized system stores the history of assets and transactions on a network with no central point of failure. More resistant to malicious attacks, Blockchain allows the acceptance of documents securely and digitally.

Blockchain Sketch — Retrive from Upfolio

Stimulus

The world is changing faster as a result of accelerated technological development. Companies from all over the world invest heavily in innovation to create answers to the needs presented in the market. New technologies are part of this process, but it is important to emphasize that, more than opening different business opportunities, they provide a real revolution in society, enabling actions that were previously unimaginable and improving people’s quality of life. However, tasks that need trust usually do not follow this rapid progress.

It is common to require to confirm that we agree with a document. Currently, this process is done through intermediaries that do manual assignments or digital systems that emulate tasks that we would do personally. We can say that even efficient, none of the solutions is agile enough for today’s world. In this scenario of mistrust, it is possible to identify the advantages of implementing a Blockchain-based system. This is a decentralized database that stores a history of assets and transactions between computers on a network. The Blockchain is transmitted to all nodes that make it not have a central point of failure. This makes it more resistant to malicious attacks, allowing the acceptance of documents securely and digitally.

Proposal

The concept of asset validation through Blockchain is not something new. Standard Chartered and DBS Bank already announced a successful Blockchain proof of concept to prevent that the same document that shows title to goods, being used for trade finance more than once. Our proposal is in line with these solutions already created. Although it proposes to use a public Blockchain environment to ensure validation simply.

The best way to implement a verifying document process that uses Blockchain technology would be to develop a parallel system based on Smart Contracts. For this project, the asset would be the document and the transaction would be the act of verifying that document by a user. Smart Contracts are self-executing digital contracts that use technology to ensure that the agreements signed will be made. The validation of the contract rule is done through a Blockchain. This ensures that the contract cannot be changed.

How Smart Contracts Works — Retrive from Intellias

We think that it would be better to use a public blockchain network. In public Blockchains networks, access is completely open. This means that everyone can receive and send transactions from anyone in the world. The possibility to be audited by anyone is advantageous in a system that aims to validate a document. Among such networks, we understand that Ethereum would be the best choice. It is the largest network that allows the use of Smart Contracts. Before a transaction can be considered valid, it must be authorized by each of its constituent nodes through the chain consensus process. This guarantees the greatest equality and transparency in the system.

The system has a web UI so that the user could insert, validate and search documents in a simpler way. This system integrates directly with smart contracts stored at Ethereum. For accessing Ethereum distributed applications, or “Dapps” in your browser you will need to install some kind of plugin like MetaMask. The extension injects the Ethereum web3 API into every website’s javascript context so that Dapp can read from the blockchain. It also lets the user create and manage their own identities. So when a Dapp wants to perform a transaction the user gets a secure interface to review the transaction before approving or rejecting it.

Verifying Documents Through a Blockchain System

Each document is converted to a contract where ownership and data are immutably stored. We use another smart contract to keep track of the multiple contracts. This maintains the history of the documents created. We could do this in a system outside the Blockchain(off-chain). But we believe that this could generate a possible point of manipulation of the stored documents.

Implementation

In this section, we are going to show how to implement a smart contract to verify documents at Ethereum. For that, we need to write code in Solidity. This is an object-oriented programming language for writing smart contracts. It is used to implement smart contracts on various Blockchain platforms, most notably Ethereum. Let’s first define the private variables that will store the data of each of our contracts.

address private owner; string private filename; address[] private validators; mapping (address => bool) private validated;

To represent the document ownership we use the address of the user who is creating the contract. In Ethereum and Solidity, an address corresponds to the last 20 bytes of the Keccak-256 hash of the public key. Since each public key is unique, we can then use it to represent ownership.

We also use the addresses in an array to store users who have validated that document. To make it easier to check whether a specific person has validated that document or not, we use mapping. Mapping is generally recommended for this use case of a contract, which could have an unlimited number of documents and could be updated. The main advantage of an array is for iteration. But the iteration needs to be limited, not only for speed but also for the cost of operation.

We need to use a constructor to make each document convert to a contract where ownership and data are immutably stored. This is a special function that is used to initialize state variables of a contract. In our case, it defines the environment variable of the contract owner, the file name and issues an event. This is an inheritable member of a contract that stores the arguments passed in transaction logs. These logs are stored on Ethereum and are accessible using the address of the contract until the contract is present on the Blockchain.

event OwnerSet(address indexed oldOwner, address indexed newOwner);

constructor(string memory _filename) public { owner = msg.sender; filename = _filename; emit OwnerSet(address(0), owner); }

The main interaction that we have in this contract is to validate a document. So we have a function that receives the address from the validator and records the validation. As can be seen below, we store this through a array and a hashmap to facilitate responses by validators.

function validateFile(address newValidator) public { validators.push(newValidator); validated[newValidator] = true; }

As our variables are private, it is not possible to interact with them directly. So it is interesting to create external functions to return these values. This type of function cannot be accessed internally, only externally. For external functions, the compiler doesn’t need to allow internal calls, and so it allows arguments to be read directly from call data, saving the copying step. Since memory allocation is expensive, this type of solution becomes cheaper.

function hasValidated(address newValidator) external view returns(bool){ return validated[newValidator]; } function getOwner() external view returns (address) { return owner; }

function getFileName() external view returns (string memory) { return filename; }

For the whole implementation please access our Github repository. There you will also be able to find how we implemented another smart contract called DataTrack. This one is responsible for keeping track of the multiple ValidateData contracts.

Conclusion

Companies from all over the world invest heavily in innovation to create answers to the needs present in the market. However, tasks that need trust usually do not follow this rapid progress. In this scenario of mistrust, it is possible to identify the advantages of implementing a Blockchain-based system. Our proposal is in line with the solutions already created. Although it proposes to use a public Blockchain environment to ensure validation more simply. We presented how to implement a smart contract to verify documents at Ethereum. For the whole implementation please access our Github repository.
['Matheus Leal']
['Solidity', 'Technology', 'Ethereum', 'Blockchain', 'Smart Contracts']