1. i
A Blockchain based Banking System
MINOR PROJECT II
Submitted by:
Davis Stephen (9915103012)
Gaurav Singh (9915103252)
Kshitij Jain (9915103122)
Under the supervision of
Dr. Mukta Goyal
Department of CSE/IT
Jaypee Institute of Information Technology University, Noida
MAY 2018
2. ii
ACKNOWLEDGEMENT
The completion of any inter-disciplinary project depends upon cooperation, co-
ordination and combined efforts of several sources of knowledge. Weare grateful
to Dr. Mukta Goyal for her even willingness to give us valuable advice and
direction whenever we approached him with a problem. We are thankful to her
for providing us with immense guidance for this project.
We are also thankful Mukta Goyal ma’am for giving her valuable time for
evaluating our project. We would also like to thank our College authorities and
Head/Dean for giving us the opportunity to pursue our project in this field and
helping us to successfully complete this project.
Signature:
Names:
Davis Stephen (9915103012)
Gaurav Singh (9915103252)
Kshitij Jain (9915103122)
3. iii
ABSTRACT
Blockchain has emerged as an important financial software system. They rely on a secure
distributed ledger data structure. They are increasingly becoming more popular in the world
today. People seem to be finding newer ways to leverage the power of the blockchain for intuitive
applications that provide solutions to real-world problems.
An integral part of such systems, Mining adds records of past transactions to the distributed
ledger. On average, a block (the structure containing transactions) is mined every 10 minutes.
Miners compete to solve a difficult mathematical problem based on a cryptographic hash
algorithm. When a block is 'solved', the transactions contained are considered confirmed, and
the bitcoin concerned in the transactions can be spend.
The Blockchain, it allows users to have secure, robust consensus for each transaction. One of
the major application of blockchain is Cryptocurrencies. They require strong, secure mining
algorithms and since they lack a central authority to mediate transactions because they were
designed as p2p systems, they rely on miners to validate the transactions.
The ways in whichemerging blockchain and distributed ledger technology (DLT)could transform
the industry are enticing to companies constantly on the lookout for lower costs and greater
efficiency.
If fully adopted, it will enable banks to process payments morequickly and more accurately while
reducing transaction processing costs and the requirement for exceptions.
Therefore, we find the need to upgrade our banking system to mediate transactions and to this
new technology
4. iv
TABLE OF CONTENTS
Abstract i
List of Figures iii
List of UML Diagrams iii
List of Abbreviations and Nomenclature vi
Chapter 1: Introduction 1
Chapter 2: Background study 2
2.1 Blockchains 2
2.2 Blocks 2
2.3 Ordering Facts 2
2.4 Mining 3
Chapter 3: Detailed design 4
Chapter 4: Implementation 6
Chapter 5: Conclusion of the Report 8
Chapter 6: Gantt chart 9
Chapter 7: References in IEEE format 10
6. vi
LIST OF FIGURES
Figure Title Page
1)Blocks 8
2)Mining 9
3)Testrpc 10
4) Metamask 11
5)Block Creation 13
6)Token 16
7)Front-End 25
UML DIAGRAMS
1)Use Case Dig 13
2)Class Dig 14
7. vii
ABBREVIATIONS AND NOMENCLATURE
1) P2P: Peer to peer
2) Bitcoin: It is a cryptocurrency and worldwide payment system. It is the first decentralized
digital currency, as the system works without a central bank or single administrator.
3) Hash: A hash function is any function that can be used to map data of arbitrary size to data
of fixed size.
4) vue: View, a JavaScript library for Chrome webpages.
5) DLT: Distributed Ledger Technology
6) PnP: In computing, a device or computer bus, is one with a specification that facilitates the
discovery of a hardware component in a system without the need for physical device
configuration or user intervention in resolving resource conflicts.
7) Distributed ledger: A consensus of replicated, shared, and synchronized digital data
geographically spread across multiple sites, countries, or institutions.
8) Blockchain: A continuously growing list of records, called blocks, which are linked and
secured using cryptography.
9) Ethereum: An open-source, public, blockchain-based distributed computing platform and
operating system featuring smart contract (scripting) functionality.
10) Smart contract: A computer protocol intended to digitally facilitate, verify, or enforce the
negotiation or performance of a contract.
11) Blocks: Transaction data is permanently recorded in files called blocks.
12) Mining: Mining is the process of adding transaction records to Bitcoin's public ledger of past
transactions.
13) Node: Any computer that connects to the Bitcoin network.
14) Double-spending: A potential flaw in a digital cash scheme in which the same single digital
token can be spent more than once.
8. viii
15) Solidity: A contract-oriented programming language for writing smart contracts. It is used for
implementing smart contracts on various blockchain platforms.
16) Nonce: In cryptography, a nonce is an arbitrary number that can only be used once.
9. ix
INTRODUCTION
A blockchain is a data structure that makes it possible to create a digital ledger of transactions
and share it amongst a distributed network of computers. It uses cryptography to allow each
participant on the network to manipulate the ledger in a secureway without the need for a central
authority.
Once a block of data is recorded on the blockchain ledger, it’s extremely difficult to change or
remove. When someone wants to add to it, participants in the network (called miners) — all of
which have copies of the existing blockchain — run algorithms to evaluate and verify the
proposed transaction.
Blockchain technology is emerging as the way to let companies make and verify financial
transactions on a network instantaneously without a central authority.
Traditionally, banking and payment transactions have relied on a central authority or middleman
for making or enabling payments. The blockchain architecture allows a distributed network of
computers to reach consensus without the need for this middleman. In banking there are many
existing and developing use cases to implement blockchain.
We will set potential use cases for banks, concentrating on the use case of payments, in
considering the possibility of utilising blockchain technology in banking.
10. x
BACKGROUND STUDY
Blockchains
A blockchain is a ledger of facts, replicated across several computers assembled in a p2p
network. Facts can be anything from monetary transactions to content signature. Members of
the network are anonymous individuals called nodes. All communication inside the network
takes advantage of cryptography to securely identify the sender and the receiver. When a node
wants to add a fact to the ledger, a consensus forms in the network to determine where this fact
should appear in the ledger, this consensus is called a block.
Blocks
Blocks are a smarttrick to order facts in a network of non-trusted peers. The idea is simple:facts
are grouped in blocks,and there is only a single chain of blocks, replicated in the entire network.
Each block references the previous one. So, if fact F is in block 21, and fact E is in block 22,
then fact E is considered by the entire network to be posterior to fact F. Before being added to
a block, facts are pending, i.e. unconfirmed.
Fig 1: Blocks
Ordering Facts
Decentralized p2p networks aren't new. Napster and Bit Torrent are P2P networks. Instead of
exchanging movies, members of the blockchain network exchange facts. Then what's the real
deal about blockchains?
P2P networks, like other distributed systems, have to solve a very difficult computer science
problem: the resolution of conflicts, or reconciliation. Relational databases offer referential
integrity, but there is no such thing in distributed system. If two incompatible facts arrive at the
11. xi
sametime, the system must have rules to determine which fact is considered valid. To guarantee
integrity over a P2P network, you need a way to make everyone agree on the ordering of facts.
Mining
Some nodes in the chain create a new local block with pending facts. They compete to see if
their local block is going to become the next block in the chain for the entire network, by rolling
dice. If a node makes a double six, then it earns the ability to publish their local block, and all
facts in this block become confirmed. This block is sent to all other nodes in the network. All
nodes check that the block is correct, add it to their copy of the chain, and try to build a new
block with new pending facts.
Fig 2: Mining
But nodes don't just roll a couple dice. Blockchain challenges imply rolling a huge number of
dice. Finding the random key to validate a block is veryunlikely, by design. This prevents fraud
and makes the network safe (unless a malicious user owns more than half of the nodes in the
network). As a consequence, new blocks get published to the chain at a fixed time interval. In
Bitcoin, blocks are published every 10 minutes on average.
The process of looking for blocks is called mining. This is because, just like gold mining, block
mining brings an economical reward - some form of money. That's the reason why people who
run nodes in a blockchain are also called miners.
Cryptocurrencies rapidly became convertible to real money. Their facial value is only
determined by offer and demand, so it's subject to speculation. At the time of writing, but in near
future it will be very stable.
12. xii
Some nodes in the chain create a new local block with pending facts. They compete to see if
their loca
Testrpc (Ganache)
Ganache is a personal blockchain for Ethereum development you can use to deploy contracts,
develop your applications, and run tests. It is available as both a desktop application as well as
a command-line tool (formerly known as the TestRPC).
It provides 10 addresses and Ethereum test accounts to use.
Fig 3: Testrpc
13. xiii
Metamask
MetaMask is a browser plugin that allows users to make Ethereum transactions through regular
websites. It facilitates the adoption of Ethereum because it bridges the gap between the user
interfaces for Ethereum (eg. Mist browsers, Dapps) and the regular web (eg. Chrome, Firefox,
websites). Without this, Ethereum cannot become mainstream because the regular web has a
strong network effect which inhibits the average user from switching.
MetaMask injects a javascript library called web3.js into the namespace of each page your
browser loads. web3.js is written by the Ethereum core team, and has functions that regular
webpages can use to make read and write requests on the blockchain that are consistent with
the existing protocol.
Furthermore, MetaMask allows users to specify which Ethereum node to send these requests
to. The ability to send requests to nodes outside of the user’s computers is important because
it means that people can use Ethereum without having to download a node consisting the
10+GB blockchain on to their computers.
Fig 4: Metamask
14. xiv
Web3
Web3.js is a collection of libraries which allow you to interact with a local or remote ethereum
node, using a HTTP or IPC connection. The web3-eth is for the ethereum blockchain and
smart contracts.
15. xv
DETAILED DESIGN
Transactions can be created on the behalf of any client using client application, once a
transaction is submitted into the system, a transaction is generated that is pushed into the
blockchain node network. A miner node intercepts this to do some sanity checking, once done,
it is determined that this is a legit transaction and it is fed into a cryptographic hash function as
depicted to generate a unique string of digits. It is then also combined with other transactions
as shown.
,
Fig 5: Block Creation
The generated hash is then stored with other metadata into the header of a data structure called
a block. The header is key as it becomes the basis for running the hash function once again to
create a child block.
UML Dig.1: Use Case Dig
16. xvi
The hash function is used as the math puzzle that the miners race to solve by looking over
virtually trillions of possibilities. The miner that solves it first submits it for a check by other nodes
and once confirmed, the block is stored into the blockchain for posterity.
,
UML Dig 2: Class Dig
17. xvii
IMPLEMENTATION
1)Token Creation
contract MyToken {
/* Public variables of the token */
string public name;
string public symbol;
uint8 public decimals;
/* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
/* This generates a public event on the blockchain that will notify clients */
event Transfer(address indexed from, address indexed to, uint256 value);
/* Initializes contract with initial supply tokens to the creator of the contract */
function MyToken (uint256 _supply, string _name, string _symbol, uint8 _decimals) {
/* if supply not given then generate 1 million of the smallest unit of the token */
if (_supply == 0) _supply = 1000000;
/* Unless you add other functions these variables will never change */
balanceOf[msg.sender] = _supply;
name = _name;
symbol = _symbol;
/* If you want a divisible token then add the amount of decimals the base unit has */
decimals = _decimals;
}
/* Send coins */
function transfer (address _to, uint256 _value) {
/* if the sender doesn’t have enough balance then stop */
if (balanceOf[msg.sender] < _value) throw;
if (balanceOf[_to] + _value < balanceOf[_to]) throw;
/* Add and subtract new balances */
19. xix
2) SafeMath.sol
pragma solidity ^0.4.11;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
function mul(uint256 a, uint256 b) internal returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint256 a, uint256 b) internal returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
3) StandardToken.sol
20. xx
pragma solidity ^0.4.11;
import './BasicToken.sol';
import './ERC20.sol';
/**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood:
https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amout of tokens to be transfered
*/
function transferFrom(address _from, address _to, uint256 _value) {
var _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is
not met
// if (_value > _allowance) throw;
balances[_to] = balances[_to].add(_value);
balances[_from] = balances[_from].sub(_value);
allowed[_from][msg.sender] = _allowance.sub(_value);
Transfer(_from, _to, _value);
}
21. xxi
/**
* @dev Aprove the passed address to spend the specified amount of tokens on behalf of
msg.sender.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve (_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
if ((_value != 0) && (allowed[msg.sender][_spender] != 0)) throw;
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifing the amount of tokens still avaible for the spender.
*/
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
}
4) FuncToken.sol
pragma solidity ^0.4.11;
import "./StandardToken.sol";
22. xxii
/**
* @title SimpleToken
* @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
* Note they can later distribute these tokens as they wish using `transfer` and other
* `StandardToken` functions.
*/
contract FuncToken is StandardToken {
string public name = "Func Token";
string public symbol = "FUNC";
uint256 public decimals = 18;
uint256 public INITIAL_SUPPLY = 100000000 * 1 ether;
/**
* @dev Contructor that gives msg.sender all of existing tokens.
*/
function FuncToken() {
totalSupply = INITIAL_SUPPLY;
balances[msg.sender] = INITIAL_SUPPLY;
}
}
5) Main.js
import Vue from 'vue'
import App from './App.vue'
import Vuetify from 'vuetify'
Vue.use(Vuetify)
new Vue({
el: '#app',
render: h => h(App)
})
6) config.js
export default {
26. xxvi
CONCLUSION
1) We found out how can we use the Block-Chain or Cloud Computing or combination
of Both to make our system more efficient, secure and transparent.
2) They now need to take a long-term view and work with technology partners, regulators,
and other service providers to define a framework that can act as the platform for a
distributed ledger that is universally accepted.
3) As a real-time, trusted platform that securely transmits data and value, distributed ledger
technology promises to reduce the cost of processing payments.
4) Machine based electronic platform uses internet and underlying security for quick and
more accurate transactions.
5) Ethereum is the broader potential of blockchain vastly above blockchain. It ensures
fewer errors and exceptions, and new revenue opportunities
. F
Fig 4: Front End
27. xxvii
FUTURE SCOPE
Potentially beneficial, but blockchain in banking sector would need to handle an extraordinarily
huge data set, therefore scalability must be there. Also, it would need to comply with the privacy
laws of today as well as the future. Still a long way to go before ensuring its practical
implementation in the financial world.
GANTT CHART
28. xxviii
REFERENCES IN IEEE FORMAT
Research Paper
[1] Jeton Memeti, Mehmet Ali Bekooglu, Simon Kaeser,” Bitcoin in practice”, University of
Zurich Department of Informatics (IFI) Binzmühlestrasse 14, CH-8050 Zürich, Switzerland,
March 14, 2014
[2] Nayak, K., Kumar, S., Miller, A., and Shi, E. Stubborn mining: Generalizing sel_sh mining
and combining with an eclipse attack. IACR Cryptology ePrint Archive 2015 (2015), 796.
[3] Marco Mamei and Franco Zambonelli,” Self-Maintaining Overlay Data Structures for
Pervasive Autonomic Services”, University of Modena and Reggio Emilia Via Allegri 13, 42100
Reggio Emilia, Italy {mamei.marco, franco.zambonelli}@unimore.it
[4] Benoit Donnet, Bamba Gueye, Mohamed Ali Kaafar,” A Survey on Network Coordinates
Systems, Design, and Security”, INRIA Rhone-Alpes – Grenoble, France
Web Links
[1] https://www.edgeverve.com/blog/the-impact-of-blockchain-techn/
[2] https://www.ethereum.org/
[3] https://www.coursera.org/learn/cryptocurrency