From b2eb4b12e658046cb4b215cc1cba95279f7f739f Mon Sep 17 00:00:00 2001 From: volta2030 Date: Sun, 8 Sep 2024 22:18:00 +0900 Subject: [PATCH] Update README.md --- README.md | 265 +++++++++++++++--------------------------------------- 1 file changed, 73 insertions(+), 192 deletions(-) diff --git a/README.md b/README.md index 0687015..200873a 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ ## Block Chain Framework powered by Kotlin # Node +- It configures 3 parts. Fuel, Full and Light Nodes ## Fuel Node @@ -25,230 +26,110 @@ - Mine Block. powered by kokonut - Check Chain is valid -# Kokonut Protocol +# Kokonut Protocol -## Definition +## Version : 4 -### Block +## Abstract -The block has unique 64-digit hex string hash +This protocol describes block chain systems & rules of kokonut -The version(it means protocol version) of next block is greater or equals to last block +## Block -The nonce means times of 1 cycle of proven of work - -Block file format is JSON - -Block file name is [hash].json for example, 000000000000000000000000000038a5bf10897e309c984402d1b8132faaaa.json - -### Genesis Block - -The block is 0 index of chain which has nonce : 0 & previous hash : "0" - -The hash is made arificially - -Any blocks can't be added before genesis block - -## Version 1 (until kokonut:1.0.5) - -### Abstract - -Added : - -Proven Of Work is executed at least 1 full node - -### Block Structure +### Basic Structure ```json { - "version": 1, - "index": 0, - "previousHash": "00000000000000000000000000000000bf10897e359e874402dbb8132faaaa", - "timestamp": 1722064910519, - "ticker": "KNT", - "data": { - "comment": "When something is important enough, you do it even if the odds are not in your favor." - }, - "difficulty": 32, - "nonce": 12123345, - "hash": "000000000000000000000000000038a5bf10897e309c984402d1b8132faaaa" -} -``` - -### Proven Of Work - -```kotlin -val calculatedHash = Block.calculateHash( - previousBlock.version, - previousBlock.index, - previousBlock.previousHash, - currentBlock.timestamp, - previousBlock.ticker, - previousBlock.data, - previousBlock.difficulty, - currentBlock.nonce - ) - - fun calculateHash(version : Int, index: Long, previousHash: String, timestamp: Long, ticker: String, data: BlockData, difficulty: Int, nonce : Long): String { - val input = "$version$index$previousHash$timestamp$ticker$data$difficulty$nonce" - return MessageDigest.getInstance("SHA-256") - .digest(input.toByteArray()) - .fold("") { str, it -> str + "%02x".format(it) } - } -``` - ---- - -## Version 2 (until kokonut:1.0.7) - -### Abstract - -#### Inherit abstract of version 1 - -Added : -- Miner(64 digit hex string converted by public_key.pem) added to block -- Reward added for miner(KNT) (Unfortunately, version 2 reward is Invalid) -- The minimum unit of reward is 0.000001 - -### Block Structure -```json -{ - "version":2, - "index":13, - "previousHash":"000000187dcf778ee1661b74744ab5b2fada3e4771a410f47624a2de63a4b60e", - "timestamp":1723758087785, - "ticker":"KNT", + "version":4, + "index":1, + "previousHash":"00000000000000000000000000000000000000000000000061bdff5e59b8ff4c", + "timestamp":1724547179867, "data": { + "reward":16.230218, "miner":"6c60b7550766d5ae24ccc3327f0e47fbaa51e599172795bb9ad06ac82784a92d", - "comment":"Mining Kokonut" - }, + "transactions":[], + "comment":"kokonut version 4" + }, "difficulty":6, - "nonce":11602138, - "hash":"0000003564fa78d7c925342d2570700c9e2574bcbc5777db5d045b601d8dfe9a", - "reward":50.0 -} + "nonce":1502929, + "hash":"000000f31571551dacab93769546843d2ef483fd0d26181fe8950de617b919ec"} ``` -### Proven Of Work (Same as Version 1) - ---- +### Genesis Block -## Version 3 (until kokonut:1.3.0) +It is called genesis block which follows below : -### Abstract +- first block of chain +- previousHash is "0" +- reward is 0 +- miner is "0000000000000000000000000000000000000000000000000000000000000000" +- transactions is empty +- difficulty is 0 +- nonce is 0 +- hash isn't made by SHA-256 Hash Algorithm. it is artificially generated. -#### Inherit abstract of version 2 +#### Structure +``` +{ + "version":4, + "index":0, + "previousHash":"0", + "timestamp":1725108420520, + "data":{ + "reward":0.0, + "ticker":"KNT", + "miner":"0000000000000000000000000000000000000000000000000000000000000000", + "transactions":[], + "comment":"Navigate beyond computing oceans" + }, + "difficulty":0, + "nonce":0, + "hash":"000000000000000000000000000000000000000000000000190282d71244ac7a" +} +``` +## Proven Of Work -Added : -- Reward is valid (It is valuable) -- Optional : The minor number of kokonut framework is same to kokonut protocol version (for example kokonut:1.3.0 framework uses kokonut protocol version 3) -- Protocol version smaller or equal to 2 blocks use version 2's proven of work +## Mining -### Block Structure (Same as Version 2) +### Status -### Proven Of Work +* READY +* MINING +* FAILED +* MINED -```kotlin -val calculatedHash = Block.calculateHash( - previousBlock.version, - previousBlock.index, - previousBlock.previousHash, - currentBlock.timestamp, - previousBlock.ticker, - previousBlock.data, - previousBlock.difficulty, - currentBlock.nonce, - currentBlock.reward - ) +### State Machine Diagram - fun calculateHash(version : Int, index: Long, previousHash: String, timestamp: Long, ticker: String, data: BlockData, difficulty: Int, nonce : Long, reward : Double): String { - val input = "$version$index$previousHash$timestamp$ticker$data$difficulty$nonce$reward" - return MessageDigest.getInstance("SHA-256") - .digest(input.toByteArray()) - .fold("") { str, it -> str + "%02x".format(it) } - } -``` +![image](https://github.com/user-attachments/assets/d53c3d55-3678-4489-a250-5a7bea3d92ee) ---- -## Version 4 +### Difficulty -### Abstract +### Reward -#### Patial Inherit abstract of version 3 +#### Reduction Time +![image](https://github.com/user-attachments/assets/631d3d02-c8c6-491f-8ed0-073b11eb8fd5) -Added : +## Node -- Version 1, 2 and 3 are prohibited exist with version 4 in one block chain -- All blocks are fully integrity guranteed (prevent modulation) -- The mining reward is adjusted by Reduction Time, block generation term is predicted 10 minitues (Index of block starts from 1 and Total Blocks per Year is 365 day * 144 blocks/day ), whick follows +### Fuel Node -![image](https://github.com/user-attachments/assets/4cc1dc73-76c9-498c-b71a-0c5ee88cdbb1) +### Full Node - +### Light Node -Modified : +## Transaction -- Duty : The major number of kokonut framework is same to kokonut protocol version (for example kokonut:3.0.0 framework uses kokonut protocol version 3) - -#### Genesis Block +### Status -Given the following conditions, this block can be defined as the Genesis Block -- previous hash is "0" -- index is 0 -- miner is "0000000000000000000000000000000000000000000000000000000000000000" -- reward is 0.0 -- transaction is empty (not null) -- difficulty is 0 -- nonce is 0 +* INVALID +* PENDING +* READY +* RESERVED +* EXECUTED +### State Machine Diagram -#### Transaction -- Transaction is available it is added to block -- Transaction Validation - - Verify signed data with public key - - Sender retention is bigger or equal than remittance - - Sender and Receiver must be diffierent -- Tansaction State Diagram - ![image](https://github.com/user-attachments/assets/9650ce7a-817b-4bc2-ba35-0bb458b8df27) - 1. Sender request transaction to fuel node with public key & signed data - 2. Transaction is added to transaction pool with state PENDING - 3. Fuel node execute validation using public key & signed data - 4. If transaction is valid, transaction state changes to READY - 5. Else if it is invalid, state is INVALID - 6. Miner picks transaction, state is RESERVED - 7. Mine is done, state is EXECUTED and it is recorded to Block - 8. Sender cancels transaction, state is CANCELED - 9. Miner drops out mining, state RESERVED to READY - -### Block Structure +![image](https://github.com/user-attachments/assets/2f09706d-d207-416b-bd93-6955b2ff7850) -```json -{ - "version":4, - "index":1, - "previousHash":"00000000000000000000000000000000000000000000000061bdff5e59b8ff4c", - "timestamp":1724547179867, - "data": { - "reward":16.230218, - "miner":"6c60b7550766d5ae24ccc3327f0e47fbaa51e599172795bb9ad06ac82784a92d", - "transactions":[], - "comment":"kokonut version 4" - }, - "difficulty":6, - "nonce":1502929, - "hash":"000000f31571551dacab93769546843d2ef483fd0d26181fe8950de617b919ec"} -``` - - -### Proven Of Work - -```kotlin - fun calculateHash(): String { - val input = "$version$index$previousHash$timestamp$data$difficulty$nonce" - hash = MessageDigest.getInstance("SHA-256") - .digest(input.toByteArray()) - .fold("") { str, it -> str + "%02x".format(it) } - return hash - } -``` +## Wallet