Abstract:
This technical article details the process of leveraging blockchain technology to secure complex financial forecasting parameters and reports for a Singapore company that provides financial forecasting systems to commercial real estate management companies. By utilizing the Ethereum blockchain to store hashed values of forecasting settings and completed reports, the integrity and security of the data are ensured, while maintaining confidentiality.
Note: Only high level technical knowledge sharing, no confidential or workflow details revealed.
-
Introduction
A Singapore-based company provides a complex financial forecasting system for commercial real estate management companies in Singapore and China. The system takes in 100+ parameters to generate a 5-year forecast report, which is updated quarterly for comparison and analysis. The clients' finance directors require that forecasting parameters and report values remain secure and unaltered after completion.
-
Solution Design
To meet the clients' security requirements, the following solution is proposed:
- Create an Ethereum wallet
- Generate a hash of the forecasting settings and completion timestamp
- Store the hashed value on the Ethereum blockchain by sending a zero-value transaction with the hash as the transaction note
- Verify the integrity of the settings by comparing the stored hash with the hash of the saved settings and updated timestamp
Pre-request:
In the .NET project, install the Nethereum library using NuGet Package Manager:
Install-Package Nethereum.Web3
- Implementation
3.1 Creating an Ethereum Wallet
An Ethereum wallet is created to store the hashed values of the forecasting settings and completed reports. This wallet will be used to send zero-value transactions to store the hashed data on the Ethereum blockchain.
using Nethereum.KeyStore;
using Nethereum.Web3.Accounts;
var password = "your-strong-password";
var ecKey = Nethereum.Signer.EthECKey.GenerateKey();
var privateKey = ecKey.GetPrivateKeyAsBytes();
var account = new Account(privateKey);
var keyStoreService = new KeyStoreService();
var json = keyStoreService.EncryptAndGenerateDefaultKeyStoreAsJson(password, privateKey, account.Address);
3.2 Generating a Hash of the Forecasting Settings and Completion Timestamp
After a forecast report is completed and finalized by users, all settings values and the current datetime are combined to form a long text string. A hash of this string is generated, ensuring the uniqueness and integrity of the data.
using System.Security.Cryptography;
using System.Text;
string settings = "your-settings-values" + DateTime.UtcNow.ToString("O");
byte[] bytes = Encoding.UTF8.GetBytes(settings);
byte[] hashBytes;
using (SHA256 sha256 = SHA256.Create())
{
hashBytes = sha256.ComputeHash(bytes);
}
string hashedSettings = BitConverter.ToString(hashBytes).Replace("-", "");
3.3 Storing the Hashed Value on the Ethereum Blockchain
To store the hashed value on the Ethereum blockchain, a zero-value transaction is sent from the created Ethereum wallet to itself, with the hashed value included in the transaction note. This process incurs a small transaction fee (gas fee) to execute the transaction on the Ethereum network.
using Nethereum.Hex.HexConvertors.Extensions;
using Nethereum.Web3;
var web3 = new Web3(account, "https://your-ethereum-node-url");
var toAddress = account.Address;
var inputData = hashedSettings.HexToByteArray();
var gasPrice = await web3.Eth.GasPrice.SendRequestAsync();
var estimateGas = await web3.Eth.Transactions.EstimateGas.SendRequestAsync(new Nethereum.RPC.Eth.DTOs.TransactionInput(null, toAddress, account.Address, data: inputData));
var transaction = await web3.Eth.GetEtherTransferService()
.TransferEtherAndWaitForReceiptAsync(toAddress, 0m, gasPrice, estimateGas, inputData);
3.4 Verifying the Integrity of the Settings
To verify the integrity of the settings and ensure they have not been altered after publication, the stored hash on the blockchain can be queried and compared with the hash value of the saved settings and updated datetime. If the hash values match, it proves that the settings have not been changed since publication.
var blockNumber = transaction.BlockNumber;
var transactionFromBlock = await web3.Eth.Transactions.GetTransactionByBlockNumberAndIndex.SendRequestAsync(blockNumber, transaction.TransactionIndex);
var retrievedHashedSettings = transactionFromBlock.Input.HexToString();
if (hashedSettings == retrievedHashedSettings)
{
Console.WriteLine("Settings have not been altered since initial publication.");
}
else
{
Console.WriteLine("Settings have been tampered with.");
}
- Conclusion
By utilizing blockchain technology, specifically the Ethereum blockchain, the Singapore company can provide a secure and tamper-proof method for storing and verifying the integrity of financial forecasting parameters and report values. This solution not only meets the clients' security requirements but also maintains the confidentiality of sensitive data. While Ethereum gas fees have increased since the initial implementation, alternative and more affordable public blockchain networks can be considered to achieve the same objectives.