diff --git a/Ajay Kumar Block Chain/block.cpp b/Ajay Kumar Block Chain/block.cpp new file mode 100644 index 0000000..ed4daf5 --- /dev/null +++ b/Ajay Kumar Block Chain/block.cpp @@ -0,0 +1,40 @@ +#include "block.h" + +Block::Block(std::string _preBlockHash,std::list _transactionList) +{ + this->preBlockHash = _preBlockHash; + this->transactionList = _transactionList; + this->blockHash= generateHash(); +} + +std::string Block::generateHash() +{ + std::string message = preBlockHash; + + // Fetching transaction data + for(Transaction transaction: transactionList) + { + message += transaction.toString(); + } + + // Hashing the message + + std::hash hasher; + + return std::to_string(hasher(message)); +} + +std::string Block::getHash() +{ + return (std::string)this->blockHash; +} + +std::string Block::getPreHash() +{ + return this->preBlockHash; +} + +std::list Block::getTransactionList() +{ + return this->transactionList; +} diff --git a/Ajay Kumar Block Chain/block.h b/Ajay Kumar Block Chain/block.h new file mode 100644 index 0000000..dae5e2c --- /dev/null +++ b/Ajay Kumar Block Chain/block.h @@ -0,0 +1,30 @@ +#ifndef BLOCK_H +#define BLOCK_H +#include +// #include +#include +#include +#include "transaction.h" + +class Block +{ +private: + std::string blockHash; + std::string preBlockHash; + std::list transactionList; // linked list representation + +public: + + // Constructor + Block(std::string _preBlockHash,std::list _transactionList); + + // SHA256 Hashing + std::string generateHash(); + + // Getter methods + std::string getHash(); + std::string getPreHash(); + std::list getTransactionList(); +}; + +#endif \ No newline at end of file diff --git a/Ajay Kumar Block Chain/blockchain.cpp b/Ajay Kumar Block Chain/blockchain.cpp new file mode 100644 index 0000000..7617bed --- /dev/null +++ b/Ajay Kumar Block Chain/blockchain.cpp @@ -0,0 +1,83 @@ +#include "blockchain.h" + +void BlockChain::createGenisisBlock() +{ + // Genesis block dummy transaction data + std::list transactionList = + { + // senderId, receiverId, amount + Transaction("Genisis", "Genisis", 0) + }; + + // previous block hash, current transactions + chain.push_back(Block("0", transactionList)); +} + +BlockChain::BlockChain() +{ + createGenisisBlock(); +} + +void BlockChain::addBlock(std::list transaction) +{ + chain.push_back(Block(getLatestBlock().getHash(), transaction)); +} + +std::vector BlockChain::getChain() +{ + return chain; +} + +Block BlockChain::getLatestBlock() +{ + return chain[chain.size()-1]; +} + +int BlockChain::isChainValid() +{ + if(chain[0].getHash() != chain[0].generateHash()) + { + return 0; + } + + for(int i=1; i +#include +#include +#include "block.h" +#include "transaction.h" + +class BlockChain{ + +private: + + std::vector chain; + void createGenisisBlock(); + +public: + // constructor + BlockChain(); + + // new block insertion + void addBlock(std::list transaction); + + // getters + std::vector getChain(); + Block getLatestBlock(); + + // validation + int isChainValid(); + void validationReport(); + + // printing + void printChain(); +}; + +#endif \ No newline at end of file diff --git a/Ajay Kumar Block Chain/main.cpp b/Ajay Kumar Block Chain/main.cpp new file mode 100644 index 0000000..1db5553 --- /dev/null +++ b/Ajay Kumar Block Chain/main.cpp @@ -0,0 +1,61 @@ +#include +#include +#include "transaction.h" +#include "block.h" +#include "blockchain.h" + +int main(){ + + BlockChain blockChain; + + // New list of transactions + std::list transaction1= + { + Transaction("User1","User2",2000), + Transaction("User2","User3",1500), + Transaction("User3","User4",2700) + }; + + // Add new Block + blockChain.addBlock(transaction1); + + // another list + std::list transaction2= + { + Transaction("User1","User2",4000), + Transaction("User2","User3",8600), + Transaction("User3","User4",7300) + }; + blockChain.addBlock(transaction2); + + std::list transaction3= + { + Transaction("User4","User5",8000), + Transaction("User4","User6",2500), + Transaction("User4","User7",6300) + }; + + std::list transaction4= + { + Transaction("User1","User2",6000), + Transaction("User2","User3",3500), + Transaction("User3","User4",4500) + }; + + std::list transaction5= + { + Transaction("User1","User2",1000), + Transaction("User2","User3",9000), + Transaction("User3","User4",2300) + }; + + // adding blocks + blockChain.addBlock(transaction3); + blockChain.addBlock(transaction4); + blockChain.addBlock(transaction5); + + blockChain.printChain(); + blockChain.validationReport(); + + return 0; +} \ No newline at end of file diff --git a/Ajay Kumar Block Chain/main.exe b/Ajay Kumar Block Chain/main.exe new file mode 100644 index 0000000..fec4304 Binary files /dev/null and b/Ajay Kumar Block Chain/main.exe differ diff --git a/Ajay Kumar Block Chain/transaction.cpp b/Ajay Kumar Block Chain/transaction.cpp new file mode 100644 index 0000000..2b0c04f --- /dev/null +++ b/Ajay Kumar Block Chain/transaction.cpp @@ -0,0 +1,17 @@ +#include "transaction.h" + +Transaction::Transaction(){} + +Transaction::Transaction(std::string senderKey, std::string receiverKey, double amount) +{ + this->senderKey = senderKey; + this->receiverKey = receiverKey; + this->amount = amount; + this->timestamp = time(nullptr); +} + +std::string Transaction::toString() +{ + return senderKey +" "+ receiverKey+" "+ + std::to_string(amount)+" "+ std::to_string(timestamp); +} \ No newline at end of file diff --git a/Ajay Kumar Block Chain/transaction.h b/Ajay Kumar Block Chain/transaction.h new file mode 100644 index 0000000..dc3352d --- /dev/null +++ b/Ajay Kumar Block Chain/transaction.h @@ -0,0 +1,26 @@ +#ifndef TRANSACTION_H +#define TRANSACTION_H + +#include +#include +#include + +class Transaction +{ +private: + std::string senderKey; + std::string receiverKey; + double amount; + time_t timestamp; + +public: + + // Constructors + Transaction(); + Transaction(std::string _senderKey, std::string _receiverKey, double _amount); + + // convert transaction data to string (for hashing purpose) + std::string toString(); +}; + +#endif \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..85ae8de --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Block Chain +A blockchain is a decentralized and immutable digital ledger that records transactions across multiple computers. It ensures transparency, security, and trust in financial transactions by linking blocks of data together in a sequential and cryptographically secure manner. + +# Instructions to compile and run the code + +This project is written in C++ and requires Mingw C/C++ compiler to compile and run the code. + +## Installation + +1. Downlode and install MinGW compiler from the internet +2. Add `C:\MinGW\bin` path to the system environment variable `PATH` + +## Building and Running the Project + +1. Open the command prompt (CMD) or terminal. +2. Navigate to the project folder using the `cd` command. + For Example: `cd /d "D:\Ajay Kumar Block Chain"` +3. To compile the code, run the following command:`g++ -o main main.cpp block.cpp blockChain.cpp transaction.cpp` +4. Once the compilation is successful, you can run the project by executing the generated executable `main` file. diff --git a/Security Implication-Report.md b/Security Implication-Report.md new file mode 100644 index 0000000..82626a8 --- /dev/null +++ b/Security Implication-Report.md @@ -0,0 +1,27 @@ +# Security Implications of Using Blockchain for Financial Transaction + +Blockchain technology has gained significant attention for its potential to revolutionize financial transactions. However, it is essential to consider the security implications associated with its implementation. This report explores key security considerations when utilizing blockchain for financial transactions. + +## Data Integrity and Immutability + +One of the fundamental security benefits of blockchain technology is its ability to ensure data integrity and immutability. Once a transaction is recorded on the blockchain, it becomes nearly impossible to modify or tamper with the data. This feature mitigates the risk of fraudulent activities, unauthorized alterations, and data tampering, providing a reliable and trustworthy record of financial transactions. Furthermore, the provided code incorporates the use of timestamps for each transaction, thereby enhancing the uniqueness of the resulting hash values. + +## Distributed Consensus Mechanisms + +Blockchain networks rely on distributed consensus mechanisms to validate and confirm transactions. Consensus algorithms, such as Proof of Work (PoW) or Proof of Stake (PoS), ensure agreement among network participants on the validity of transactions. However, it's crucial to evaluate the security implications of the chosen consensus mechanism, as vulnerabilities or attacks targeting the consensus algorithm can compromise the integrity of financial transactions. + +## Smart Contract Security + +Smart contracts automate and enforce the terms of financial transactions on the blockchain. While they offer efficiency and transparency, they can introduce security risks. Vulnerabilities in smart contract code can lead to financial losses or unauthorized access. Thorough code audits, comprehensive testing, and adherence to secure coding practices are necessary to mitigate these risks and ensure the integrity of financial transactions. + +## Privacy and Confidentiality + +Privacy considerations arise when using blockchain for financial transactions. While blockchain provides transparency by design, protecting sensitive financial information is crucial. Techniques like encryption and zero-knowledge proofs can enhance privacy; however, finding the right balance between transparency and confidentiality remains a challenge. Organizations must carefully evaluate privacy requirements and implement appropriate measures to safeguard sensitive financial data. + +## Regulatory Compliance + +Integrating blockchain into financial transactions raises regulatory and compliance challenges. Compliance with regulations like anti-money laundering (AML) and know-your-customer (KYC) can be complex in a decentralized environment. Ensuring compliance while maintaining privacy and security requires collaboration with regulatory bodies, development of industry standards, and implementation of robust monitoring and reporting mechanisms. + +# Conclusion + +In conclusion, leveraging blockchain for financial transactions offers numerous security advantages. However, it is essential to address the potential security implications in areas such as data integrity, consensus mechanisms, smart contract security, privacy, and regulatory compliance. By implementing appropriate security measures and best practices, organizations can enhance the security and trustworthiness of financial transactions in the blockchain ecosystem.