SlideShare a Scribd company logo
DEVELOPER’S PERSPECTIVE
BLOCKCHAIN
TEXT
HOW TO BECOME RICH
INVESTOR’S PERSPECTIVE
BITCOINAIRE
BLOCKCHAIN, ANYBODY ?
BITCOINAIRE
MtGox Fraud
Initial Whitepaper
Original Peak
WTF?
Initial Whitepaper
WTF
Blockchain: Developer's Perspective (Java Edition)
TEXT
George Soros
LIBERTARIANS
KILL THE BANKS AND BANKERS
TEXT
INVESTORS
UNCORRELATED ASSET
DEVELOPERS
BLOCKCHAIN TECHNOLOGY
TEXT
TEXT
TEXT
BLOCKCHAIN
Blockchain: Developer's Perspective (Java Edition)
Blockchain: Developer's Perspective (Java Edition)
DOUBLE SPENDING
TEXT
DUPLICATION OF INFORMATION
?
TEXT
SCARICY OF MONEY
TEXT
LEDGER
CENTRALISED
TEXT
TRUST
TEXT
TRUST-AS-A-SERVICE?
TEXT
DISTRIBUTED LEDGER ?
POLITICALLY DECENTRALISED
ARCHITECTURALLY DECENTRALISED LOGICALLY DECENTRALISED
TEXT
CONSENSUS TECHNIQUE…
TEXT
…USING MATH
TEXT
LET’S CODEBASED ON NAIVECHAIN BY @LHARTIKK
@ARTURSKOWRONSKI/NAIVECHAIN-JAVA
TEXT
P2P (WebSockets) P2P (WebSockets)
P2P (WebSockets)
public class Block {
protected int index;
protected String hash;
protected String previousHash;
protected long timestamp;
protected Object data;
protected int nonce;
}
BLOCK PART
BLOCK PART
public class Block {
protected int index;
protected String hash;
protected String previousHash;
protected long timestamp;
protected Object data;
protected int nonce;
}
BLOCK PART
public class Block {
protected int index;
protected String hash;
protected String previousHash;
protected long timestamp;
protected Object data;
protected int nonce;
}
BLOCK PART
public class Block {
protected int index;
protected String hash;
protected String previousHash;
protected long timestamp;
protected Object data;
protected int nonce;
}
BLOCK PART
public class Block {
protected int index;
protected String hash;
protected String previousHash;
protected long timestamp;
protected Object data;
protected int nonce;
}
CHAIN PART
public class Blockchain extends LinkedList<Block> {
public Blockchain(Block block) {
this.add(GENESIS_BLOCK);
}
}
CHAIN PART
public class Blockchain extends LinkedList<Block> {
public Blockchain(Block block) {
this.add(GENESIS_BLOCK);
}
}
CHAIN PART
public class Blockchain extends LinkedList<Block> {
public Blockchain(Block block) {
this.add(GENESIS_BLOCK);
}
}
CHAIN PART
public class Blockchain extends LinkedList<Block> {
public Blockchain(Block block) {
this.add(GENESIS_BLOCK);
}
}
GENESIS BLOCK
public static final Block GENESIS_BLOCK = new Block(
0, //index
“e6337db8a921823784c14378abed4f7d7", //hash
null, //previousHash
1465154705, //timestamp
"Pozdro Bielsko-Biala!”, //data
0 //nonce
);
MINING BLOCK
public class BlockchainService {
Blockchain chain = new Blockchain();
public Block mineBlock(Object data) => {
Block newBlock = nextBlock(chain.getLast(), data);
chain.addBlock(newBlock);
return chain.getLast();
};
}
MINING BLOCK
public class BlockchainService {
Blockchain chain = new Blockchain();
public Block mineBlock(Object data) => {
Block newBlock = nextBlock(chain.getLast(), data);
chain.addBlock(newBlock);
return chain.getLast();
};
}
MINING BLOCK
public class BlockchainService {
Blockchain chain = new Blockchain();
public Block mineBlock(Object data) => {
Block newBlock = nextBlock(chain.getLast(), data);
chain.addBlock(newBlock);
return chain.getLast();
};
}
MINING BLOCK
public static Block nextBlock(Block prevBlock, Object data) {
int nextIndex = previousBlock.index + 1;
String prevHash = prevBlock.getHash();
long nextTime = new Date().getTime();
String nextHash = calculateHash(nextIndex, prevHash, nextTime, data);
return new Block(nextIndex, prevHash, nextHash, nextTime, data);
}
MINING BLOCK
public static Block nextBlock(Block prevBlock, Object data) {
int nextIndex = previousBlock.index + 1;
String prevHash = prevBlock.getHash();
long nextTime = new Date().getTime();
String nextHash = calculateHash(nextIndex, prevHash, nextTime, data);
return new Block(nextIndex, prevHash, nextHash, nextTime, data);
}
MINING BLOCK
public static Block nextBlock(Block prevBlock, Object data) {
int nextIndex = previousBlock.index + 1;
String prevHash = prevBlock.getHash();
long nextTime = new Date().getTime();
String nextHash = calculateHash(nextIndex, prevHash, nextTime, data);
return new Block(nextIndex, prevHash, nextHash, nextTime, data);
}
MINING BLOCK
public static Block nextBlock(Block prevBlock, Object data) {
int nextIndex = previousBlock.index + 1;
String prevHash = prevBlock.getHash();
long nextTime = new Date().getTime();
String nextHash = calculateHash(nextIndex, prevHash, nextTime, data);
return new Block(nextIndex, prevHash, nextHash, nextTime, data);
}
MINING BLOCK
public static Block nextBlock(Block prevBlock, Object data) {
int nextIndex = previousBlock.index + 1;
String prevHash = prevBlock.getHash();
long nextTime = new Date().getTime();
String nextHash = calculateHash(nextIndex, prevHash, nextTime, data);
return new Block(nextIndex, prevHash, nextHash, nextTime, data);
}
CALCULATE HASH
private String calculateHash(int index, String prevHash, long ts, Object data) {
return sha256Hex(index + prevHash + ts + data.hashCode());
}
MINING BLOCK
public static Block nextBlock(Block prevBlock, Object data) {
int nextIndex = previousBlock.index + 1;
String prevHash = prevBlock.getHash();
long nextTime = new Date().getTime();
String nextHash = calculateHash(nextIndex, prevHash, nextTime, data);
return new Block(nextIndex, prevHash, nextHash, nextTime, data);
}
MINING BLOCK
public class BlockchainService {
Blockchain chain = new Blockchain();
public Block mineBlock(Object data) => {
Block newBlock = nextBlock(chain.getLast(), data);
chain.addBlock(newBlock);
return chain.getLast();
};
}
ADDING BLOCK TO CHAIN
public class Blockchain extends LinkedList<Block> {
(...)
public BlockchainResponse addBlock(Block block){
if(isValidNewBlock(getLast(), block)) {
add(block);
}
return new BlockchainResponse(RESPONSE_BLOCKCHAIN, block);
}
(...)
}
ADDING BLOCK TO CHAIN
public class Blockchain extends LinkedList<Block> {
(...)
public BlockchainResponse addBlock(Block block){
if(isValidNewBlock(getLast(), block)) {
add(block);
}
return new BlockchainResponse(RESPONSE_BLOCKCHAIN, block);
}
(...)
}
BLOCK VALIDATION
public static boolean isValidNewBlock(Block previousBlock, Block newBlock){
if (previousBlock.getIndex() + 1 != newBlock.getIndex()) {
return false;
}
if (!previousBlock.getHash().equals(newBlock.getHash())) {
return false;
}
if (calculateHashForBlock(newBlock).equals(newBlock.getHash())) {
return false;
}
return true;
}
BLOCK VALIDATION
public static boolean isValidNewBlock(Block previousBlock, Block newBlock){
if (previousBlock.getIndex() + 1 != newBlock.getIndex()) {
return false;
}
if (!previousBlock.getHash().equals(newBlock.getHash())) {
return false;
}
if (calculateHashForBlock(newBlock).equals(newBlock.getHash())) {
return false;
}
return true;
}
BLOCK VALIDATION
public static boolean isValidNewBlock(Block previousBlock, Block newBlock){
if (previousBlock.getIndex() + 1 != newBlock.getIndex()) {
return false;
}
if (!previousBlock.getHash().equals(newBlock.getHash())) {
return false;
}
if (calculateHashForBlock(newBlock).equals(newBlock.getHash())) {
return false;
}
return true;
}
BLOCK VALIDATION
public static boolean isValidNewBlock(Block previousBlock, Block newBlock){
if (previousBlock.getIndex() + 1 != newBlock.getIndex()) {
return false;
}
if (!previousBlock.getHash().equals(newBlock.getHash())) {
return false;
}
if (calculateHashForBlock(newBlock).equals(newBlock.getHash())) {
return false;
}
return true;
}
ADDING BLOCK TO CHAIN
public class Blockchain extends LinkedList<Block> {
(...)
public BlockchainResponse addBlock(Block block){
if(isValidNewBlock(getLast(), block)) {
add(block);
}
return new BlockchainResponse(RESPONSE_BLOCKCHAIN, block);
}
(...)
}
TEXT
Hash #0
Genesis Block
Hash #1
PrevHash #0
Hash #2
PrevHash #1
BLOCKCHAIN
ADDING BLOCK TO CHAIN
public class Blockchain extends LinkedList<Block> {
(...)
public Response addBlock(Block block){
if(isValidNewBlock(getLast(), block)) {
add(block);
}
return new Response(RESPONSE_BLOCKCHAIN, block);
}
(...)
}
TEXT
New Block
New Block
GOSSIP PROTOCOL
NEW BLOCK HANDLING
public Response handleBlockchainResponse(Blockchain newChain) {
if (newChain.getLast().getIndex() > chain.getLast().getIndex()) {
if (chain.getLast().getHash().equals(newChain.getLast().getPreviousHash())){
chain.addBlock(latestBlockReceived);
return new Response(RESPONSE_BLOCKCHAIN, new Blockchain(chain.getLast()));
}
return exchangeChains(newChain);
}
return new Response(DO_NOTHING);
}
NEW BLOCK HANDLING
public Response handleBlockchainResponse(Blockchain newChain) {
if (newChain.getLast().getIndex() > chain.getLast().getIndex()) {
if (chain.getLast().getHash().equals(newChain.getLast().getPreviousHash())){
chain.addBlock(latestBlockReceived);
return new Response(RESPONSE_BLOCKCHAIN, new Blockchain(chain.getLast()));
}
return exchangeChains(newChain);
}
return new Response(DO_NOTHING);
}
NEW BLOCK HANDLING
public Response handleBlockchainResponse(Blockchain newChain) {
if (newChain.getLast().getIndex() > chain.getLast().getIndex()) {
if (chain.getLast().getHash().equals(newChain.getLast().getPreviousHash())){
chain.addBlock(latestBlockReceived);
return new Response(RESPONSE_BLOCKCHAIN, new Blockchain(chain.getLast()));
}
return exchangeChains(newChain);
}
return new Response(DO_NOTHING);
}
NEW BLOCK HANDLING
public Response handleBlockchainResponse(Blockchain newChain) {
if (newChain.getLast().getIndex() > chain.getLast().getIndex()) {
if (chain.getLast().getHash().equals(newChain.getLast().getPreviousHash())){
chain.addBlock(latestBlockReceived);
return new BlockchainResponse(RESPONSE_BLOCKCHAIN, new Blockchain(chain.getLast()));
}
return exchangeChains(newChain);
}
return new BlockchainResponse(DO_NOTHING);
}
TEXT
Hash #2
EXCHANGE CHAINS
TEXT
New Chain
New Chain
GOSSIP PROTOCOL
REPLACING CHAIN
private Response exchangeChain(Blockchain newBlockchain) {
if (newBlockchain.isValidChain() && newBlockchain.size() > chain.size()) {
chain = newBlockchain;
return new Response(RESPONSE_BLOCKCHAIN, new Blockchain(chain.getLast()));
} else {
return new Response(DO_NOTHING);
}

}
REPLACING CHAIN
private Response exchangeChain(Blockchain newBlockchain) {
if (newBlockchain.isValidChain() && newBlockchain.size() > chain.size()) {
chain = newBlockchain;
return new Response(RESPONSE_BLOCKCHAIN, new Blockchain(chain.getLast()));
} else {
return new Response(DO_NOTHING);
}

}
REPLACING CHAIN
private Response exchangeChain(Blockchain newBlockchain) {
if (newBlockchain.isValidChain() && newBlockchain.size() > chain.size()) {
chain = newBlockchain;
return new Response(RESPONSE_BLOCKCHAIN, new Blockchain(chain.getLast()));
} else {
return new Response(DO_NOTHING);
}

}
VALIDATING CHAIN
public boolean isValidChain(){
if (!this.getFirst().equals(GENESIS_BLOCK)){
return false;
}
for (int i = 1; i < this.size() - 1; i++) {
if (!Block.isValidNewBlock(this.get(i - 1), this.get(i))){
return false;
}
}
return true;
}
VALIDATING CHAIN
public boolean isValidChain(){
if (!this.getFirst().equals(GENESIS_BLOCK)){
return false;
}
for (int i = 1; i < this.size() - 1; i++) {
if (!Block.isValidNewBlock(this.get(i - 1), this.get(i))){
return false;
}
}
return true;
}
VALIDATING CHAIN
public boolean isValidChain(){
if (!this.getFirst().equals(GENESIS_BLOCK)){
return false;
}
for (int i = 1; i < this.size() - 1; i++) {
if (!Block.isValidNewBlock(this.get(i - 1), this.get(i))){
return false;
}
}
return true;
}
REPLACING CHAIN
private Response exchangeChain(Blockchain newBlockchain) {
if (newBlockchain.isValidChain() && newBlockchain.size() > chain.size()) {
chain = newBlockchain;
return new Response(RESPONSE_BLOCKCHAIN, new Blockchain(chain.getLast()));
} else {
return new Response(DO_NOTHING);
}

}
TEXT
LONGER HASH WINS
TEXT
SPINNING NEW BLOCKS
PROOF-OF-WORK
PROOF-OF-WORK
private static HashPair calculateHash(int index, String previousHash, Object data) {
int nonce = 0;
while (true) {
nonce++;
String value = sha256Hex(index + previousHash + data.hashCode() + nonce);
if (value.startsWith(“000")) {
return new HashPair(nounce, value);
}
}
}
PROOF-OF-WORK
private static HashPair calculateHash(int index, String previousHash, Object data) {
int nonce = 0;
while (true) {
nonce++;
String value = sha256Hex(index + previousHash + data.hashCode() + nonce);
if (value.startsWith(“000")) {
return new HashPair(nounce, value);
}
}
}
PROOF-OF-WORK
private static HashPair calculateHash(int index, String previousHash, Object data) {
int nonce = 0;
while (true) {
nonce++;
String value = sha256Hex(index + previousHash + data.hashCode() + nonce);
if (value.startsWith(“000")) {
return new HashPair(nonce, value);
}
}
}
PROOF-OF-WORK
private static HashPair calculateHash(int index, String previousHash, Object data) {
int nonce = 0;
while (true) {
nonce++;
String value = sha256Hex(index + previousHash + data.hashCode() + nonce);
if (value.startsWith(“000")) {
return new HashPair(nonce, value);
}
}
}
PROOF-OF-WORK
private static HashPair calculateHash(int index, String previousHash, Object data) {
int nonce = 0;
while (true) {
nonce++;
String value = sha256Hex(index + previousHash + data.hashCode() + nonce);
if (value.startsWith(“000")) {
return new HashPair(nonce, value);
}
}
}
PROOF-OF-WORK
private static HashPair calculateHash(int index, String previousHash, Object data) {
int nonce = 0;
while (true) {
nonce++;
String value = sha256Hex(index + previousHash + data.hashCode() + nonce);
if (value.startsWith(“000")) {
return new HashPair(nonce, value);
}
}
}
PROOF-OF-WORK
private static HashPair calculateHash(int index, String previousHash, Object data) {
int nonce = 0;
while (true) {
nonce++;
String value = sha256Hex(index + previousHash + data.hashCode() + nonce);
if (value.startsWith(“000")) {
return new HashPair(nonce, value);
}
}
}
TEXT
IDEAL HASH FUNCTION
f( )
f( )?
TEXT
I HAVE HASH! 000004CEEF5782B82C212CE725F15594!
00000ee187308970bb63446f3f910e98000004ceef5782b82c212ce725f15594
TEXT
Hash #0 Hash #1 Hash #2
SECURITY
Hash #0
Hash #1

Prev #0
Hash #2

Prev #1
Hash #3

Prev #2
Hash #4

Prev #3
Hash #1x
Hash #2x

Prev #1x
Hash #3x

Prev #2x
FORK
▸ =
50% OF WHOLE NETWORK
TEXT
BLOCKCHAIN
Hash #1

Prev #2
Hash #2

Prev #3
Hash #0

Prev #1
Hash #0
$ $ $
TEXT
PROBLEMS
TEXT
ENVIRONMENTAL UNFRIENDLY
TEXT
> ENERGY USAGE ICELAND
PROOF-OF-STAKE
PRIMECOIN
TEXT
SCALABILITY ISSUES
TEXT
VERTICAL SCALING HORIZONTAL SCALING
TEXT
VERTICAL SCALING
TEXT
HORIZANTAL SCALING
PROOF-OF-STAKE
DIRECT ACYCLIC GRAPH
LIGHTNING NETWORKS
TEXT
SMART CONTRACTS
INITIAL COIN OFFERINGS
SOFT & HARD FORKS
TEXT
DNS
IOT
SMART

CONTRACT
TEXT
THANK YOU AND
WAITING FOR
QUESTIONS
@ArturSkowronski
arturskowronski.com

More Related Content

PDF
Reutov, yunusov, nagibin random numbers take ii
PPTX
Blockchain - a simple implementation
PDF
Even the LastPass Will be Stolen Deal with It!
PDF
Di and Dagger
PDF
JSON Web Tokens (JWT)
PDF
apidays LIVE New York - WT* is JWT? by Maciej Treder
PPTX
The Burden of Proof
PDF
JSON Web Tokens Will Improve Your Life
Reutov, yunusov, nagibin random numbers take ii
Blockchain - a simple implementation
Even the LastPass Will be Stolen Deal with It!
Di and Dagger
JSON Web Tokens (JWT)
apidays LIVE New York - WT* is JWT? by Maciej Treder
The Burden of Proof
JSON Web Tokens Will Improve Your Life

What's hot (6)

PDF
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
PPTX
Mythbusting: Understanding How We Measure the Performance of MongoDB
PDF
Blockchain Technologies for Data Science
PDF
How to verify computation in the blink of an eye
PPTX
Cryptography 101 for Java developers
PDF
Heroku Postgres Cloud Database Webinar
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
Mythbusting: Understanding How We Measure the Performance of MongoDB
Blockchain Technologies for Data Science
How to verify computation in the blink of an eye
Cryptography 101 for Java developers
Heroku Postgres Cloud Database Webinar
Ad

Similar to Blockchain: Developer's Perspective (Java Edition) (19)

PDF
Blockchain: Developer Perspective
PPTX
Let's Build A Blockchain... in 40 minutes!
PDF
BlockChain implementation by python
PPTX
Meta X Blockchain Bootcamp
PPTX
Blockchain
PDF
A Comprehensive Guide To Create Blockchain In Python | Blockchain Development...
PDF
Real time and reliable processing with Apache Storm
PPTX
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
PPTX
Let's build a blockchain.... in 40 minutes!
PDF
Blockchain com JavaScript
PPTX
Introduction to Blockchain Web3 Session
PPTX
JDD2015: Where Test Doubles can lead you... - Sebastian Malaca
PDF
Part 2 Blockchain Programming Using Python.pdf
PDF
Mobile Web 5.0
PDF
Cracking JWT tokens: a tale of magic, Node.JS and parallel computing - Node.j...
PDF
Cracking JWT tokens: a tale of magic, Node.JS and parallel computing
PDF
Luciano Mammino - Cracking JWT tokens: a tale of magic, Node.JS and parallel...
PDF
BITCOIN FORENSICS : Bsides Delhi Conference
PDF
DIY-Blockchain
Blockchain: Developer Perspective
Let's Build A Blockchain... in 40 minutes!
BlockChain implementation by python
Meta X Blockchain Bootcamp
Blockchain
A Comprehensive Guide To Create Blockchain In Python | Blockchain Development...
Real time and reliable processing with Apache Storm
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Let's build a blockchain.... in 40 minutes!
Blockchain com JavaScript
Introduction to Blockchain Web3 Session
JDD2015: Where Test Doubles can lead you... - Sebastian Malaca
Part 2 Blockchain Programming Using Python.pdf
Mobile Web 5.0
Cracking JWT tokens: a tale of magic, Node.JS and parallel computing - Node.j...
Cracking JWT tokens: a tale of magic, Node.JS and parallel computing
Luciano Mammino - Cracking JWT tokens: a tale of magic, Node.JS and parallel...
BITCOIN FORENSICS : Bsides Delhi Conference
DIY-Blockchain
Ad

More from Artur Skowroński (20)

PDF
Build your own NES Emulator... with Kotlin
PDF
Running Java on Arm - Is it worth it in 2025?
PDF
JVM in the Age of AI: Babylon, Valhalla, TornadoVM and friends
PDF
Kopiąc Trufle - Odkrywanie tajemnic najmniej zrozumiałego elementu GraalVM
PDF
The State of the Green IT at the beginning of 2024
PDF
My chcemy grać w Zielone! Czyli stan świata Green Technology końcówką 2023
PDF
GraalVM, CRaC, Leyden and friends
PDF
Od Czarnoksiężnik z krainy Oz do modeli na produkcji
PDF
JVM Iceberg... we need to go deeper
PDF
JVM Iceberg... we need to go deeper
PDF
Panie, kto tu Panu tak ... - czyli porozmawiajmy o Legacy
PDF
Panie, kto tu Panu tak ... - czyli porozmawiajmy o Legacy
PDF
Ciąg dalszy nastąpi - o wielowątkowości, Projekcie Loom i kotlinowych Korutynach
PDF
Artur Skowroński – Ten Typ tak ma - O systemach typów na przykładzie TypeScri...
PDF
Ten Typ tak ma - O systemach typów na przykładzie TypeScript’a
PDF
Type Systems on the example of TypeScript
PDF
Google Assistant po polsku - developerski punkt widzenia
PDF
Google Assistant & Alexa - Asystenci głosowi: możliwości, podobieństwa, różnice
PDF
To Be Continued - multithreading with Project Loom and Kotlin's Coroutines
PDF
To be Continued - multithreading with Project Loom and Kotlin's Coroutines
Build your own NES Emulator... with Kotlin
Running Java on Arm - Is it worth it in 2025?
JVM in the Age of AI: Babylon, Valhalla, TornadoVM and friends
Kopiąc Trufle - Odkrywanie tajemnic najmniej zrozumiałego elementu GraalVM
The State of the Green IT at the beginning of 2024
My chcemy grać w Zielone! Czyli stan świata Green Technology końcówką 2023
GraalVM, CRaC, Leyden and friends
Od Czarnoksiężnik z krainy Oz do modeli na produkcji
JVM Iceberg... we need to go deeper
JVM Iceberg... we need to go deeper
Panie, kto tu Panu tak ... - czyli porozmawiajmy o Legacy
Panie, kto tu Panu tak ... - czyli porozmawiajmy o Legacy
Ciąg dalszy nastąpi - o wielowątkowości, Projekcie Loom i kotlinowych Korutynach
Artur Skowroński – Ten Typ tak ma - O systemach typów na przykładzie TypeScri...
Ten Typ tak ma - O systemach typów na przykładzie TypeScript’a
Type Systems on the example of TypeScript
Google Assistant po polsku - developerski punkt widzenia
Google Assistant & Alexa - Asystenci głosowi: możliwości, podobieństwa, różnice
To Be Continued - multithreading with Project Loom and Kotlin's Coroutines
To be Continued - multithreading with Project Loom and Kotlin's Coroutines

Recently uploaded (20)

PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
PPT
Ethics in Information System - Management Information System
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPTX
innovation process that make everything different.pptx
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PDF
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
PDF
Sims 4 Historia para lo sims 4 para jugar
PPTX
Mathew Digital SEO Checklist Guidlines 2025
PDF
Introduction to the IoT system, how the IoT system works
DOCX
Unit-3 cyber security network security of internet system
PPTX
presentation_pfe-universite-molay-seltan.pptx
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PPTX
SAP Ariba Sourcing PPT for learning material
PPTX
artificial intelligence overview of it and more
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PPTX
newyork.pptxirantrafgshenepalchinachinane
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PPTX
Power Point - Lesson 3_2.pptx grad school presentation
PPTX
Introduction to Information and Communication Technology
PptxGenJS_Demo_Chart_20250317130215833.pptx
Ethics in Information System - Management Information System
Module 1 - Cyber Law and Ethics 101.pptx
innovation process that make everything different.pptx
Decoding a Decade: 10 Years of Applied CTI Discipline
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
Sims 4 Historia para lo sims 4 para jugar
Mathew Digital SEO Checklist Guidlines 2025
Introduction to the IoT system, how the IoT system works
Unit-3 cyber security network security of internet system
presentation_pfe-universite-molay-seltan.pptx
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
SAP Ariba Sourcing PPT for learning material
artificial intelligence overview of it and more
Unit-1 introduction to cyber security discuss about how to secure a system
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
newyork.pptxirantrafgshenepalchinachinane
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
Power Point - Lesson 3_2.pptx grad school presentation
Introduction to Information and Communication Technology

Blockchain: Developer's Perspective (Java Edition)

  • 2. TEXT HOW TO BECOME RICH INVESTOR’S PERSPECTIVE
  • 11. TEXT
  • 12. TEXT
  • 13. TEXT
  • 19. ?
  • 29. TEXT LET’S CODEBASED ON NAIVECHAIN BY @LHARTIKK @ARTURSKOWRONSKI/NAIVECHAIN-JAVA
  • 30. TEXT P2P (WebSockets) P2P (WebSockets) P2P (WebSockets)
  • 31. public class Block { protected int index; protected String hash; protected String previousHash; protected long timestamp; protected Object data; protected int nonce; } BLOCK PART
  • 32. BLOCK PART public class Block { protected int index; protected String hash; protected String previousHash; protected long timestamp; protected Object data; protected int nonce; }
  • 33. BLOCK PART public class Block { protected int index; protected String hash; protected String previousHash; protected long timestamp; protected Object data; protected int nonce; }
  • 34. BLOCK PART public class Block { protected int index; protected String hash; protected String previousHash; protected long timestamp; protected Object data; protected int nonce; }
  • 35. BLOCK PART public class Block { protected int index; protected String hash; protected String previousHash; protected long timestamp; protected Object data; protected int nonce; }
  • 36. CHAIN PART public class Blockchain extends LinkedList<Block> { public Blockchain(Block block) { this.add(GENESIS_BLOCK); } }
  • 37. CHAIN PART public class Blockchain extends LinkedList<Block> { public Blockchain(Block block) { this.add(GENESIS_BLOCK); } }
  • 38. CHAIN PART public class Blockchain extends LinkedList<Block> { public Blockchain(Block block) { this.add(GENESIS_BLOCK); } }
  • 39. CHAIN PART public class Blockchain extends LinkedList<Block> { public Blockchain(Block block) { this.add(GENESIS_BLOCK); } }
  • 40. GENESIS BLOCK public static final Block GENESIS_BLOCK = new Block( 0, //index “e6337db8a921823784c14378abed4f7d7", //hash null, //previousHash 1465154705, //timestamp "Pozdro Bielsko-Biala!”, //data 0 //nonce );
  • 41. MINING BLOCK public class BlockchainService { Blockchain chain = new Blockchain(); public Block mineBlock(Object data) => { Block newBlock = nextBlock(chain.getLast(), data); chain.addBlock(newBlock); return chain.getLast(); }; }
  • 42. MINING BLOCK public class BlockchainService { Blockchain chain = new Blockchain(); public Block mineBlock(Object data) => { Block newBlock = nextBlock(chain.getLast(), data); chain.addBlock(newBlock); return chain.getLast(); }; }
  • 43. MINING BLOCK public class BlockchainService { Blockchain chain = new Blockchain(); public Block mineBlock(Object data) => { Block newBlock = nextBlock(chain.getLast(), data); chain.addBlock(newBlock); return chain.getLast(); }; }
  • 44. MINING BLOCK public static Block nextBlock(Block prevBlock, Object data) { int nextIndex = previousBlock.index + 1; String prevHash = prevBlock.getHash(); long nextTime = new Date().getTime(); String nextHash = calculateHash(nextIndex, prevHash, nextTime, data); return new Block(nextIndex, prevHash, nextHash, nextTime, data); }
  • 45. MINING BLOCK public static Block nextBlock(Block prevBlock, Object data) { int nextIndex = previousBlock.index + 1; String prevHash = prevBlock.getHash(); long nextTime = new Date().getTime(); String nextHash = calculateHash(nextIndex, prevHash, nextTime, data); return new Block(nextIndex, prevHash, nextHash, nextTime, data); }
  • 46. MINING BLOCK public static Block nextBlock(Block prevBlock, Object data) { int nextIndex = previousBlock.index + 1; String prevHash = prevBlock.getHash(); long nextTime = new Date().getTime(); String nextHash = calculateHash(nextIndex, prevHash, nextTime, data); return new Block(nextIndex, prevHash, nextHash, nextTime, data); }
  • 47. MINING BLOCK public static Block nextBlock(Block prevBlock, Object data) { int nextIndex = previousBlock.index + 1; String prevHash = prevBlock.getHash(); long nextTime = new Date().getTime(); String nextHash = calculateHash(nextIndex, prevHash, nextTime, data); return new Block(nextIndex, prevHash, nextHash, nextTime, data); }
  • 48. MINING BLOCK public static Block nextBlock(Block prevBlock, Object data) { int nextIndex = previousBlock.index + 1; String prevHash = prevBlock.getHash(); long nextTime = new Date().getTime(); String nextHash = calculateHash(nextIndex, prevHash, nextTime, data); return new Block(nextIndex, prevHash, nextHash, nextTime, data); }
  • 49. CALCULATE HASH private String calculateHash(int index, String prevHash, long ts, Object data) { return sha256Hex(index + prevHash + ts + data.hashCode()); }
  • 50. MINING BLOCK public static Block nextBlock(Block prevBlock, Object data) { int nextIndex = previousBlock.index + 1; String prevHash = prevBlock.getHash(); long nextTime = new Date().getTime(); String nextHash = calculateHash(nextIndex, prevHash, nextTime, data); return new Block(nextIndex, prevHash, nextHash, nextTime, data); }
  • 51. MINING BLOCK public class BlockchainService { Blockchain chain = new Blockchain(); public Block mineBlock(Object data) => { Block newBlock = nextBlock(chain.getLast(), data); chain.addBlock(newBlock); return chain.getLast(); }; }
  • 52. ADDING BLOCK TO CHAIN public class Blockchain extends LinkedList<Block> { (...) public BlockchainResponse addBlock(Block block){ if(isValidNewBlock(getLast(), block)) { add(block); } return new BlockchainResponse(RESPONSE_BLOCKCHAIN, block); } (...) }
  • 53. ADDING BLOCK TO CHAIN public class Blockchain extends LinkedList<Block> { (...) public BlockchainResponse addBlock(Block block){ if(isValidNewBlock(getLast(), block)) { add(block); } return new BlockchainResponse(RESPONSE_BLOCKCHAIN, block); } (...) }
  • 54. BLOCK VALIDATION public static boolean isValidNewBlock(Block previousBlock, Block newBlock){ if (previousBlock.getIndex() + 1 != newBlock.getIndex()) { return false; } if (!previousBlock.getHash().equals(newBlock.getHash())) { return false; } if (calculateHashForBlock(newBlock).equals(newBlock.getHash())) { return false; } return true; }
  • 55. BLOCK VALIDATION public static boolean isValidNewBlock(Block previousBlock, Block newBlock){ if (previousBlock.getIndex() + 1 != newBlock.getIndex()) { return false; } if (!previousBlock.getHash().equals(newBlock.getHash())) { return false; } if (calculateHashForBlock(newBlock).equals(newBlock.getHash())) { return false; } return true; }
  • 56. BLOCK VALIDATION public static boolean isValidNewBlock(Block previousBlock, Block newBlock){ if (previousBlock.getIndex() + 1 != newBlock.getIndex()) { return false; } if (!previousBlock.getHash().equals(newBlock.getHash())) { return false; } if (calculateHashForBlock(newBlock).equals(newBlock.getHash())) { return false; } return true; }
  • 57. BLOCK VALIDATION public static boolean isValidNewBlock(Block previousBlock, Block newBlock){ if (previousBlock.getIndex() + 1 != newBlock.getIndex()) { return false; } if (!previousBlock.getHash().equals(newBlock.getHash())) { return false; } if (calculateHashForBlock(newBlock).equals(newBlock.getHash())) { return false; } return true; }
  • 58. ADDING BLOCK TO CHAIN public class Blockchain extends LinkedList<Block> { (...) public BlockchainResponse addBlock(Block block){ if(isValidNewBlock(getLast(), block)) { add(block); } return new BlockchainResponse(RESPONSE_BLOCKCHAIN, block); } (...) }
  • 59. TEXT Hash #0 Genesis Block Hash #1 PrevHash #0 Hash #2 PrevHash #1 BLOCKCHAIN
  • 60. ADDING BLOCK TO CHAIN public class Blockchain extends LinkedList<Block> { (...) public Response addBlock(Block block){ if(isValidNewBlock(getLast(), block)) { add(block); } return new Response(RESPONSE_BLOCKCHAIN, block); } (...) }
  • 62. NEW BLOCK HANDLING public Response handleBlockchainResponse(Blockchain newChain) { if (newChain.getLast().getIndex() > chain.getLast().getIndex()) { if (chain.getLast().getHash().equals(newChain.getLast().getPreviousHash())){ chain.addBlock(latestBlockReceived); return new Response(RESPONSE_BLOCKCHAIN, new Blockchain(chain.getLast())); } return exchangeChains(newChain); } return new Response(DO_NOTHING); }
  • 63. NEW BLOCK HANDLING public Response handleBlockchainResponse(Blockchain newChain) { if (newChain.getLast().getIndex() > chain.getLast().getIndex()) { if (chain.getLast().getHash().equals(newChain.getLast().getPreviousHash())){ chain.addBlock(latestBlockReceived); return new Response(RESPONSE_BLOCKCHAIN, new Blockchain(chain.getLast())); } return exchangeChains(newChain); } return new Response(DO_NOTHING); }
  • 64. NEW BLOCK HANDLING public Response handleBlockchainResponse(Blockchain newChain) { if (newChain.getLast().getIndex() > chain.getLast().getIndex()) { if (chain.getLast().getHash().equals(newChain.getLast().getPreviousHash())){ chain.addBlock(latestBlockReceived); return new Response(RESPONSE_BLOCKCHAIN, new Blockchain(chain.getLast())); } return exchangeChains(newChain); } return new Response(DO_NOTHING); }
  • 65. NEW BLOCK HANDLING public Response handleBlockchainResponse(Blockchain newChain) { if (newChain.getLast().getIndex() > chain.getLast().getIndex()) { if (chain.getLast().getHash().equals(newChain.getLast().getPreviousHash())){ chain.addBlock(latestBlockReceived); return new BlockchainResponse(RESPONSE_BLOCKCHAIN, new Blockchain(chain.getLast())); } return exchangeChains(newChain); } return new BlockchainResponse(DO_NOTHING); }
  • 68. REPLACING CHAIN private Response exchangeChain(Blockchain newBlockchain) { if (newBlockchain.isValidChain() && newBlockchain.size() > chain.size()) { chain = newBlockchain; return new Response(RESPONSE_BLOCKCHAIN, new Blockchain(chain.getLast())); } else { return new Response(DO_NOTHING); }
 }
  • 69. REPLACING CHAIN private Response exchangeChain(Blockchain newBlockchain) { if (newBlockchain.isValidChain() && newBlockchain.size() > chain.size()) { chain = newBlockchain; return new Response(RESPONSE_BLOCKCHAIN, new Blockchain(chain.getLast())); } else { return new Response(DO_NOTHING); }
 }
  • 70. REPLACING CHAIN private Response exchangeChain(Blockchain newBlockchain) { if (newBlockchain.isValidChain() && newBlockchain.size() > chain.size()) { chain = newBlockchain; return new Response(RESPONSE_BLOCKCHAIN, new Blockchain(chain.getLast())); } else { return new Response(DO_NOTHING); }
 }
  • 71. VALIDATING CHAIN public boolean isValidChain(){ if (!this.getFirst().equals(GENESIS_BLOCK)){ return false; } for (int i = 1; i < this.size() - 1; i++) { if (!Block.isValidNewBlock(this.get(i - 1), this.get(i))){ return false; } } return true; }
  • 72. VALIDATING CHAIN public boolean isValidChain(){ if (!this.getFirst().equals(GENESIS_BLOCK)){ return false; } for (int i = 1; i < this.size() - 1; i++) { if (!Block.isValidNewBlock(this.get(i - 1), this.get(i))){ return false; } } return true; }
  • 73. VALIDATING CHAIN public boolean isValidChain(){ if (!this.getFirst().equals(GENESIS_BLOCK)){ return false; } for (int i = 1; i < this.size() - 1; i++) { if (!Block.isValidNewBlock(this.get(i - 1), this.get(i))){ return false; } } return true; }
  • 74. REPLACING CHAIN private Response exchangeChain(Blockchain newBlockchain) { if (newBlockchain.isValidChain() && newBlockchain.size() > chain.size()) { chain = newBlockchain; return new Response(RESPONSE_BLOCKCHAIN, new Blockchain(chain.getLast())); } else { return new Response(DO_NOTHING); }
 }
  • 78. PROOF-OF-WORK private static HashPair calculateHash(int index, String previousHash, Object data) { int nonce = 0; while (true) { nonce++; String value = sha256Hex(index + previousHash + data.hashCode() + nonce); if (value.startsWith(“000")) { return new HashPair(nounce, value); } } }
  • 79. PROOF-OF-WORK private static HashPair calculateHash(int index, String previousHash, Object data) { int nonce = 0; while (true) { nonce++; String value = sha256Hex(index + previousHash + data.hashCode() + nonce); if (value.startsWith(“000")) { return new HashPair(nounce, value); } } }
  • 80. PROOF-OF-WORK private static HashPair calculateHash(int index, String previousHash, Object data) { int nonce = 0; while (true) { nonce++; String value = sha256Hex(index + previousHash + data.hashCode() + nonce); if (value.startsWith(“000")) { return new HashPair(nonce, value); } } }
  • 81. PROOF-OF-WORK private static HashPair calculateHash(int index, String previousHash, Object data) { int nonce = 0; while (true) { nonce++; String value = sha256Hex(index + previousHash + data.hashCode() + nonce); if (value.startsWith(“000")) { return new HashPair(nonce, value); } } }
  • 82. PROOF-OF-WORK private static HashPair calculateHash(int index, String previousHash, Object data) { int nonce = 0; while (true) { nonce++; String value = sha256Hex(index + previousHash + data.hashCode() + nonce); if (value.startsWith(“000")) { return new HashPair(nonce, value); } } }
  • 83. PROOF-OF-WORK private static HashPair calculateHash(int index, String previousHash, Object data) { int nonce = 0; while (true) { nonce++; String value = sha256Hex(index + previousHash + data.hashCode() + nonce); if (value.startsWith(“000")) { return new HashPair(nonce, value); } } }
  • 84. PROOF-OF-WORK private static HashPair calculateHash(int index, String previousHash, Object data) { int nonce = 0; while (true) { nonce++; String value = sha256Hex(index + previousHash + data.hashCode() + nonce); if (value.startsWith(“000")) { return new HashPair(nonce, value); } } }
  • 86. TEXT I HAVE HASH! 000004CEEF5782B82C212CE725F15594! 00000ee187308970bb63446f3f910e98000004ceef5782b82c212ce725f15594
  • 87. TEXT Hash #0 Hash #1 Hash #2 SECURITY Hash #0 Hash #1
 Prev #0 Hash #2
 Prev #1 Hash #3
 Prev #2 Hash #4
 Prev #3 Hash #1x Hash #2x
 Prev #1x Hash #3x
 Prev #2x FORK
  • 88. ▸ = 50% OF WHOLE NETWORK
  • 89. TEXT BLOCKCHAIN Hash #1
 Prev #2 Hash #2
 Prev #3 Hash #0
 Prev #1 Hash #0 $ $ $
  • 99. TEXT SMART CONTRACTS INITIAL COIN OFFERINGS SOFT & HARD FORKS
  • 101. TEXT
  • 102. THANK YOU AND WAITING FOR QUESTIONS @ArturSkowronski arturskowronski.com