Kinglory

Technical Account Information

1. Kinglory Account

In the system, an account is a 20-byte address, and the address is a hash value of the public key of the account. 

When displayed in plain text, there are two formats: 

  1. Base58 encoding format, for example:
 14xfJr1DArtYR156XBs28FoYk6sQqirT2s 
  1. Hexadecimal format, for example:
 0x9156a7cdab767ffe161ed21a0cb0b688b545b01f 

UTXO model, Account/balance model, Zero-knowledge protocols (zkSNARKs) 

Kinglory supports the UTXO model and account/balance model. In the UTXO model, a user’s wallet keeps track of a list of unspent transactions associated with the owner’s addresses, and the balance is calculated by summing up those unspent transactions.  

In the account/balance model, an account stores three things below: 

  1. The latest transaction serial number (check number), a counter used to determine that each transaction can only be processed once 
  2. Current digital currency balance of the account 
  3. The account’s nickname (domain name), contract code (Code) and storage (Data), set to empty by default 

The address in zero-knowledge protocols is a one-time address. the sender and receiver create a random obfuscated address for each transaction. The account has a private viewkey, a private payment key, and a public address. 

Sharding 

The system uses sharding based on account addresses. In each shard, a “full node” stores all transactions, contracts and states of the shard.  

First level: 256 shards based on the first byte, index 0 being beacon-chain 
Second level: 65536 shards based on the first two bytes 
Third level: 16777261 shards based on the first three bytes 

 

2. Bitcoin and UTXO model

UTXO stands for Unspent Transaction Outputs, which is harder to understand compared to the account/balance model.  

In the Bitcoin world, there’s no ledger keeping a balance of all accounts. Then how will you know the balance of an address? Generally, you need to review all transactions made, and all bitcoins received, you will know the balance by adding all of them.  

Input and output in transactions  

Transactions in Bitcoin are relatively complicated. Assume that Fred gave two BTC to Alice, and Ted gave three BTC to Alice. We send the two transactions to Alice, and a total of five BTC are called Unspent Transaction Outputs, which can be used as input when she wants to transfer to others.  

If Alice wants to transfer 5 BTC to Bob, she needs to spend the UTXO above as input of the transaction. What miners need to do is to verify no transaction in previous blocks has spent this unspent output. If a transaction has been spent, it is not considered an unspent transaction, which is how Bitcoin avoids double-spending.  

Bitcoin is a point-to-point digital cash system, and the UTXO model has many features in common with the cash payment model. If Andrew has two $50 bills and pays John $80, he needs to give the bills to John and receives $20 from John. Money in their wallets is not displayed in a number, but waiting for counting. We can say cash payment is a simplified version of the UTXO model.

What UTXO model and cash payment in common: 

  1. Every UTXO has a value, as every bill has its face value. 
  2. One UTXO needs to be consumed as a whole, as bills can’t be torn apart into two. 
  3. UTXO model has the smallest amount of satoshi, which is 0.00000001 BTC, and cash has the smallest amount as well.

Difference between UTXO model and cash payment 

  1. In cash payment, change is done by the payee, while in Bitcoin, change is set by the transaction initiator. 
  2. The amount of bills is fixed, while UTXO can have a different amount of value 
  3. Cash cannot be double-spent, while Bitcoin is possible to be double-spent. 

A transaction of Bitcoin being spent twice or more times is called double-spend. Bitcoin as a digital currency is a format of data that has no entity, making it possible to be spent twice. 

When Andrew sent $80 to John, the $80 is a transaction output for Andrew and a transaction input for John. If someday John sends the $80 out, it becomes transaction input for John. So before John spends the $80, it is an unspent transaction output, the UTXO.  

As a miner, there are three things to consider before verifying: 

Does the address that initiated the transaction have enough UTXO? 

It is the same as having enough BTC. Miners will check the UTXO set of the address to see if it has enough balance. The transaction is invalid if the balance is not enough. 

Is BTC used in the transaction double-spend? 

Miners check data in the blockchain ledger to see if the BTC has been used in another transaction. If the UTXO has been transferred to another address, there’s a double-spending problem, leading to an invalid transaction.  

Is there a legal private key signature provided?  

A legal private key signature is used to verify that the user owns the BTC. If a private key signature cannot be provided, miners will tell that the transaction is illegal.  

The scripting language is an abstract concept in blockchain, but also an important feature. We say that Bitcoin is not Turing complete while Ethereum is Turing complete. What we really mean is whether their scripts are Turing complete. A Turing complete system means it can be used to solve any computation problem. 

A Turing complete scripting language can give full play to computers’ abilities. In the Bitcoin system, the scripts are not Turing complete, which are only capable of BTC receiving and sending. Ethereum scripts are Turing complete. Besides receiving and sending ETH, it can deploy smart contracts and realize more functions. The Bitcoin script is a prototype of a smart contract, but it’s not Turing complete. However, not being Turing complete is not a disadvantage, since Turing completeness relates to complicated technology, increasing possibilities of security breaches. 

Bitcoin was created as a way for people to send money so it was developed with currency, security of transactions, and network circulation as the top concerns. The founder of Ethereum, Vitalik, once advised the core development team at Bitcoin to enrich the scripts but they refused, so Vitalik decided to create Ethereum with more scripts. 

Bitcoin scripts system is a first-in-last-out stack model.

What is a stack?

A stack is a frequently used computer science data type. The last thing you put into the stack will be taken out first. We can imagine the stack as a box; you put a book, a cap, and a pair of scissors in this order. When you take out items from the box, it will be scissors first, followed by the cap, and then the book. That’s why a stack is called the first-in-last-out, or last-in-first-out model. There are two important operations in a stack: push and pop. The push operation is to add one element into the stack, while the pop operation is to remove one element from the stack. 

Verifying the transaction 

By now, all the information to verify whether the transaction is legitimate has been pushed into the stack, the next step is to verify. 

Step 1 is equal verify (equal means the same person or thing, verify is to verify). Equal verify is verifying to determine whether two things are equal (whether the two data at the top of the comparison stack are equal). 

Why do we need to do this step? In a stack, the public key hash in layer 3 is derived from the input script, while the public key hash in layer 4 is taken from the output script, which is also called the locking script. But the public key hash of the input script can only be calculated by the person who has the corresponding public key.

As mentioned earlier, the private key and public key have asymmetric encryption. The private key is to be kept by oneself and the public key can be shared with others. The private key to the public key is a one-way derivation process, which cannot be back-propelled. However, with the emergence of the quantum computer, which is a very powerful computer, it is possible to do back-propelled from the public key to the private key. 

In the beginning, Satoshi Nakamoto took the public key directly as the address, which is extremely insecure. Later, programmers encoded the hash of the public key as the address, so there is no way for quantum computers to do this directly from the address to reverse the private key. 

So on the current Bitcoin blockchain, private and public keys are not easily shared with others. If you want to use Bitcoins in an address to transfer money, then you first have to provide the corresponding public key so that miners can check that you are the owner of the address because you have the corresponding public key. The first step of this checking process is to correspond the hash in the initiator’s input script to the hash in the output script to see if it is the same, and if it is, it passes the first check. 

Then comes the second check called check sig (check and signature), which is to check the signature using the initiator’s public key, and after the check passes you can confirm that the transaction was initiated by you. 

The above is the process of bitcoin’s UTXO model verification. 

3. Ethereum and account/balance model 

Ethereum is a big state machine, and its states consist of multiple accounts, each account containing four segments (nonce, either_balance, contact_code, storage). 

There’re two types of accounts in Ethereum:

  1. Accounts owned by private key; it has no codes and has almost the same functions as Bitcoin address, capable of sending signed transactions to the network.
  2. Accounts owned by contract code; it can operate code saved in contract_code whenever it receives messages. All contracts can respond to requests from other accounts and provides some services.  

Nonce of all accounts needs to increase from 0. The current account will increase the nonce by one when it uses nonce to sign and broadcast a transaction. The account/balance model doesn’t have UTXO; the transaction is only changed to ether_balance, so nonce is used to prevent the double-spend problem. 

Contract accounts are accounts owned by a private key and are similar to a Bitcoin address. Presently most common contract accounts in the Ethereum network is ERC20. The tokens are contracts in Ethereum, under Ethereum accounts.  

contract ERC20Interface { 
   function totalSupply() public constant returns (uint);
    function balanceOf(address tokenOwner) public constant returns (uint balance);
    function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
    function transfer(address to, uint tokens) public returns (bool success);
    function approve(address spender, uint tokens) public returns (bool success);
    function transferFrom(address from, address to, uint tokens) public returns (bool success);
    event Transfer(address indexed from, address indexed to, uint tokens);
    event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
} 

The transfer of tokens is a contract call. All account balance stores in the contract’s balance: mapping(address => uint256) balances. Every token transfer will change the mapping address and initiate a transfer event. Deploying token smart contracts is very simple, with many cryptocurrency projects being ERC20 tokens.  

Nonce, from, to, value and input are important segments in a transaction. Nonce prevents double-spend attack; from and to represent payer and payee of the transaction; value is Ether amount in a transaction, and input includes binary information for contract calls.  

When a transaction is mined by the Ethereum mainnet, the balance of the from and to accounts will change. Ethereum is like a state machine that keeps accepting transactions and updates its state. 

Blocks in Bitcoin and Ethereum 

To understand what a block is, the easiest way is to analyze its data structure. Take block #514095 in Bitcoin as an example:

{ 
"hash":"00000000000000000018b0a6ae560fa33c469b6528bc9e0fb0c669319a186c33",
  "confirmations":1009,
  "strippedsize":956228,
  "size":1112639,
  "weight":3981323,
  "height":514095,
  "version":536870912,
  "versionHex":"20000000",
  "merkleroot":"5f8f8e053fd4c0c3175c10ac5189c15e6ba218909319850936fe54934dcbfeac",
  "tx":[
    // ...
  ],
  "time":1521380124,
  "mediantime":1521377506,
  "nonce":3001236454,
  "bits":"17514a49",
  "difficulty":3462542391191.563,
"chainwork":"0000000000000000000000000000000000000000014d2b41a340e60b72292430",
"previousblockhash":"000000000000000000481ab128418847dc25db4dafec464baa5a33e66490990b",
"nextblockhash":"0000000000000000000c74966205813839ad1c6d55d75f95c9c5f821db9c3510"
} 

In this block, previousblockhash and merkleroot are the two most important segments. The first one is a hash pointer which is the hash of the previous block. Through previousblockhash we can find all blocks recursively, which is the main blockchain. Merklerroot is the root of a Merkle tree, while the merkle tree stores all transactions in the block. By storing the merkleroot, any transaction in the block is guaranteed to be not modified.  

The Ethereum blockchain model is very different from Bitcoin, but its block structure has similar information: 

{ 
   "jsonrpc":"2.0",
   "result":{
      "author":"0x00d8ae40d9a06d0e7a2877b62e32eb959afbe16d",
      "difficulty":"0x785042b0",
      "extraData":"0x414952412f7630",
      "gasLimit":"0x47b784",
      "gasUsed":"0x44218a",
      "hash":"0x4de91e4af8d135e061d50ddd6d0d6f4119cd0f7062ebe8ff2d79c5af0e8344b9",
"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
      "miner":"0x00d8ae40d9a06d0e7a2877b62e32eb959afbe16d",
   "mixHash":"0xb8155224974967443d8b83e484402fb6e1e18ff69a8fc5acdda32f2bcc6dd443",
      "nonce":"0xad14fb6803147c7c",
      "number":"0x2000f1",
"parentHash":"0x31919e2bf29306778f50bbc376bd490a7d056ddfd5b1f615752e79f32c7f1a38",
"receiptsRoot":"0xa2a7af5e3b9e1bbb6252ba82a09302321b8f0eea7ec8e3bb977401e4f473e672",
      "sealFields":[
         "0xa0b8155224974967443d8b83e484402fb6e1e18ff69a8fc5acdda32f2bcc6dd443",
         "0x88ad14fb6803147c7c"
      ],  "sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
      "size":"0x276",
"stateRoot":"0x87e7e54cf229003014f453d64f0344e2ba4fc7ee3b95c7dd2642cca389fa1efe",
      "timestamp":"0x5a10968a",
      "totalDifficulty":"0x1804de0c47ffe1",
      "transactions":[...],
"transactionsRoot":"0xc2091b032961ca23cf8323ea827e8956fe6dda9e68d75bcfaa8b910035397e35",
      "uncles":[]
   },
   "id":1
} 

ParentHash corresponds to previousblockhash, and transactionsRoot corresponds to merkleroot in Bitcoin; both of them are important in the blockchain network.   

Hash pointers in block structure in blockchain have two functions. It can connect different blocks, and verify the block, ensuring data in the block is not modified by other nodes.  

Except for the first block, prev_hash of every block is hash of the previous block. If a node wants to modify a transaction of a block in the main chain, it will change the hash of the block, which makes the nodes after the node not able to find the chain, so the modification of the transaction will be noticed.    

Merkle Tree 

Merkleroot is the root node of a Merkle tree. It is a data structure connected by hash pointers. Merkle tree has leaf nodes and non-leaf nodes; only leaf nodes stores data and non-leaf nodes are hash used for verifying data consistency.  

All transactions in a block are stored in the Merkle tree, and merkleroot is stored in the block structure, ensuring all modification in any transactions of the block can be noticed immediately. 

4. Quantum Computer

Quantum encryption is the 7th generation of cryptography, and its predecessor is the RSA cryptosystem, which is now the most widely used encryption method. Bitcoin uses the elliptic curve ECC algorithm, which is stronger than the RSA algorithm in terms of unit security strength. However, whether it is ECC or RSA, both encryption algorithms are not strong enough when faced with quantum computers and will be easily broken. Once quantum computers succeed, they will pose a threat to the current RSA encryption algorithm on networks, communications, communications, and banks. 

There are two kinds of encryption algorithms in the Bitcoin system, one is the elliptic curve algorithm and the other is the hash algorithm. The elliptic curve algorithm is used for the private key to the public key. The hash algorithm is used for the public key address. The process of pushing down the private key to the public key is originally irreversible and one-way, and it is impossible for the public key to reverse the derivation of the private key, because the workload of the public key to reverse the private key is tremendous, and the current computer is not capable of such a large workload. The latest quantum computers are thought to be able to reverse the derivation of private keys from public keys, and some even say that when quantum computers are put into use it will be the end of Bitcoin. 

Recently, there have been many media reports that the quantum computer developed by Google has made considerable progress. Google’s researchers said that Google’s processor can complete a calculation within 3 minutes and 20 seconds while the world’s current top-ranked supercomputer needs 10,000 years to complete the calculation. According to the estimates of a Plymouth University professor, the quantum computer can figure out what the private key is from calculating the public key within minutes. Knowing all the private keys grants you Bitcoin transfer rights from a corresponding address. 

So instead of taking the public key directly as the address, the Bitcoin system takes the public key hash and encodes it afterwards as the address. This extra step of hashing between the public key and the address is to put an extra barrier in front of the quantum computer, and with this hash function, the current quantum computer is not yet able to effectively crack the private key of Bitcoin and directly reverse the private key from an address, which is something the quantum computer is not yet able to do. 

But in the UTXO model, we see that when you initiate a transfer at an address, your script exposes the public key corresponding to that address. So when you use a bitcoin address, we recommend that you only use a one-time address, which means that once the address has been used for an outgoing transfer, you should not use it again. You should also transfer all your money when you make the transfer, because at the time of the transfer, the public key is already exposed on the blockchain, and quantum computers are powerful enough that they can do it within a few minutes. If an address is used repeatedly and the public key is exposed on the network, it’s very insecure. We can transfer these Bitcoins to a new address that hasn’t been used yet, so the public key is not exposed and it’s safe in the meantime. 

5. Blockchain address? 

Folks in the cryptocurrency and blockchain fields know about wallet addresses because they are needed for top-ups and withdrawals. So what is a wallet address? Where does the address come from? Is it safe to give the address to others? Why is the ETH address the same as the EOS address? With these questions let’s talk about blockchain addresses. 

Symmetric encryption 

Speaking of address, we have to talk about cryptography first. As a technical means to protect the security of information transmission, cryptography is widely used in human society, and its basic idea is to realize encryption and decryption through character substitution. 

Symmetric encryption is where both the encryption algorithm and decryption algorithm are in the same mode, and the secret key is used to encrypt and decrypt the message. Usually, the longer the key is, the more difficult it is to represent the ciphertext to be cracked. Symmetric encryption has one biggest weakness: there is only one key to guarantee encrypting and decrypting data, so party A must tell party B the key, otherwise, party B cannot decrypt it. And saving and passing the key becomes the biggest headache. 

Asymmetric encryption 

Based on the weakness of symmetric encryption, how can we complete the decryption of ciphertext without directly passing the key? Based on this idea of a public-key mechanism, a series of asymmetric encryption algorithms began to appear. Cryptography in the 1990s further developed where public-key algorithms based on elliptic curve multiplication, prime power and other mathematical functions were born. They made digital keys and unforgeable digital signatures possible. The following diagram represents the differences between symmetric and asymmetric encryption. 

Asymmetric encryption requires two keys (one pair): a public key and private key. After encrypting the data with the public key, only the corresponding private key can be decrypted; conversely, if the private key is used for encryption, only the corresponding public key can be decrypted. This can ensure that the communication data is private and can confirm the identity of both parties.

Public key and private key 

Secure Hash Algorithm (SHA) is an algorithm that calculates a fixed-length string (also known as a message digest) for any length of data, and the string is unique. 

A bitcoin private key is actually a 32-byte (256-bit) random number generated using SHA-256, and the range of valid private keys depends on the secp256k1 elliptic curve digital signature standard used by bitcoin. A number between 0x1 and 0xFFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFE BAAE DCE6 AF48 A03B BFD2 5E8C D036 4140 is almost always a legitimate private key. 

Add the version number in front of the private key, and add the compression mark and additional checksum at the end (the so-called additional checksum is to take the first four bytes of the two hash results after two SHA-256 operations on the private key), and then encode it with Base58 to get our common WIF (Wallet import Format) format private key.

The private key is multiplied by the elliptic curve to get the public key. The public key is a point on the elliptic curve and has X and Y coordinates. There are two forms of public keys: compressed and uncompressed. Early Bitcoin used uncompressed public keys, but now most clients use compressed public keys by default. 

Due to mathematical principles, it is possible to extrapolate a public key from a private key, and impossible to extrapolate a private key backwards from a public key. 

People who are new to Bitcoin often have the misconception that the Bitcoin public key is the address, which is incorrect. There are a few more operations to go through to get from a public key to an address. 

Address generation (Bitcoin) 

The elliptic curve algorithm generates a relatively long public key message, 33 bytes for the compressed format and 65 bytes for the uncompressed one. The address is to reduce the number of bytes required to identify the recipient. The steps for generating a bitcoin address are as follows:

  1. Generate the private key and public key 
  2. Process the public key through the SHA256 hash algorithm to get a 32-byte hash value 
  3. Use the RIPEMD-160 algorithm to get a 20-byte hash – Hash160 
  4. Perform double SHA256 hashing on the 21-byte array consisting of version number + Hash160, and place the first 4 bytes of the hash value as checksum at the end of the 21-byte array. 
  5. Base58 encoding of the array of 25 bits to get the address. 

We do not need to figure out the specific process, which involves a lot of mathematical formulas and principles. But we need to understand the following points: 

Because of the elliptic curve multiplication and the nature of the hash function, we can derive the public key from the private key, and we can derive the address from the public key, and this process is irreversible. Because of this, the public key is publicly available throughout the Bitcoin (Ethereum, etc.) system, which means that the wallet address is secure. The private key is the most critical part. 

COMPROMISING YOUR PRIVATE KEY MEANS LOSING EVERYTHING. 

Anonymity and traceable source 

Anyone can easily generate a large number of private keys, public keys, and addresses. The address itself is anonymous, and the anonymity can be further enhanced by multiple address transactions. However, all transactions are transparent. All transactions at one address can be checked, and the source can be tracked. Anyone can track all incoming and outgoing accounts and balances at the address you give. 

Why is the ETH address the same as the EOS address? 

This is a difficult question to answer and a good one. Simply put, EOS is the ERC20 token on top of ETH (aside: EOS itself is a public chain, and the existing EOS holdings will need to be transferred after the EOS native public chain is online, so the address will be different), and of course other tokens on top of ETH basically have the same address as the ETH address. 

6. Comparison of UTXO and account/balance model  

Prev_hash and merkleroot use a hash pointer to make sure all blocks and transactions are connected, guaranteeing that the blocks and transactions are not modified by attackers and hackers. Almost all blockchain projects use similar ways to connect blocks and transactions.  

In a blockchain network based on UTXO, besides change, consolidating multi UTXO into one UTXO is very common. In the Bitcoin network, no matter how much BTC is in a UTXO, the size of the UTXO is close. To make a large amount of transfer will need multiple UTXO as input, which will significantly increase the gas fee.  

Since there’s no account in UTXO, processing transactions in parallel will cause no problem. The unchangeable ledger allows us to analyze snapshots of the network when Bitcoin nodes update. 

The unchangeable ledger in the UTXO model has its advantages, however, if we want to calculate the balance of an address, we need to go through all related blocks in the whole network. At the same time, parallel transactions will cause a double-spend problem.  

UTXO model can solve problems in the blockchain world. Its main idea is to guarantee that the written data is not modified. Chain UTXO uses hash pointers to connect inputs and outputs of different transactions, ensuring the legibility of transactions.   

Both the UTXO model and account/balance model solve the security problem in blockchain, making sure that transactions are legal and prevent a possible attack from design. The difference in implementation is because of different points of view. UTXO model has the following advantages over the account/balance model: 

  1. If a user uses a new address for transactions, the relationship between the new and old address is hard to be tracked, protecting user privacy. 
  2. It is possible to string multiple transactions using different UTXO in parallel and broadcast them to the network. 

While account/balance model has its advantages: 

  1. Very easy to develop and implement.
  2. Each transaction needs only one signature. Input and output of transaction is an address, saving storage space. 
  3. No origin of token in blockchain, making it hard to track the originality. 
  4. Doesn’t need to sign previous UTXO in the transaction, making it possible to synchronize block state anytime, easier for implementing light clients.