# EngraveChain: A Blockchain-Based Tamper-Proof Distributed Log System
## 3 Our Solution
### Recovering the File  
To read a log file previously written to the blockchain a user can gather all the transactions in the blockchain associated with a particular FileID, order the transactions by timestamp, decrypt the chunks using the secret key that was used to encrypt them and thereby recover the file (see Scheme 1 and Figure 3). We should note that while encryption provides the confidentiality of data, some information may still leak. For example, the varying rate in which the information is being written. An organization may take further actions to ensure that such information does not leak (e.g., writing at constant rate). Still, the participating organizations (e.g., respectable banks) are not expected to apply significant effort using advanced cryptanalysis towards decrypting log information of other banks. These entities already face high levels of oversight and regulation and would face significant backlash for carrying out a cyber-attack of that sort. **Write (filename, message):**  
//Participant \(P_{i}\) writes a message to a file  
1. \(E_{m}=\) Encrypt(message, public_key\({}_{i}\)) //Encrypt message with public key  
2. Submit_Transaction_to_Blockchain( \(E_{m}\), filename, \(P_{i}\) )  
**Read (filename)**:  
//Retrieve all file parts from the blockchain  
1. GET all \(m_{j}\) messages from the blockchain where FileID = filename  
2. For each message \(m_{j}\) in filename:  
\(D_{m_{j}}\)=Decrypt(message, secret_key\({}_{i}\)) //Decrypt using the secret_key\({}_{i}\)  
3. Combine(All \(D_{m_{j}}\)) //Append the retrieved message parts to a single logical file  
**Recover Process:**  
For compromised peer node \(k_{i}\):  
1. Remove attacker from infected system. 2. Submit blockchain transaction to revoke compromised peer node certificates. 3. Certificate Authority revises blockchain certificates if they were compromised. 4. Sync blockchain state with uncompromised participants to obtain  
blockchain consensus state. **Scheme 1. ** Pseudocode for the three basic operations through the blockchain: Write, Read and Recover. For very large files, one could use a method similar to that of [21; 22] where they uploaded a hash of a file to the bitcoin blockchain. In our case we could save the large file to cloud storage or a distributed storage system (e.g., storj [32]) and then only include a hash of the file on our blockchain (see Figure 4). This hash could then be compared to later versions of the file to ensure the authenticity of the file. Nonetheless, this method involves a tradeoff as if the file is corrupted, one cannot necessarily obtain an accurate version of the file unless there are other copies stored elsewhere. As such, we only suggest using this method for particularly large files where including them on the blockchain involves too much overhead or where knowledge of file integrity is more important than actually having an accurate copy of the file. Figure 3: To reconstruct a log file, first the relevant lines of the file are gathered from the various blocks and ordered by their timestamps. The organization or peer that wrote the file will then use their unique private key to decrypt the file in order to recover the file. A further consideration that can be added to our system is the possibility of 'closing' a file and preventing any further logs from being written to it. While we did not include such a capability in our current implementation we note that it could be desirable for some use cases. Compromised systems will often notice different system behaviors that lead them to suspect and discover the presence of an attacker. For example, a user that notices that their machine's performance has decreased significantly, will often choose to scan their machine for malware. Upon discovering an attacker, the system administrator can then initiate a process to remove the attacker. If the attacker deleted information from the infected computer, then a recovery process is also necessary to restore the previous data.