BANKEX: Essentials of Blockchain Cryptography
ethereum cryptography crypto blockchain bitcoin
Cryptography is the core of blockchain technology. All transactions information is encoded in blocks, which are linked together and form structure of the blockchain. In this article, we go over the fundamentals of blockchain cryptography.
The History of Cryptography
The need to encode information emerged concurrently with the development of writing. Encrypted writing was first used in ancient Egypt, Mesopotamia, and ancient India. With time, people learned to use special tools to encode text. One of the first known cryptographic devices was the scytale, used to send messages by the Spartan military. The technology of cryptography has been constantly evolving. As existing encryption methods stopped being effective, people would invent new ways to encode information.
During World War II, the Third Reich used very complex electro-mechanical rotor cipher devices called Enigma machines to encode its military communications. An Enigma machine consisted of a keyboard, rotors, circuit boards, and lamps. The input text was transformed into a cipher by the rotors, whose position would change with every keystroke. It took years of effort by a 10 000 person decryption center to crack the Enigma code.
With the arrival of computers, cryptography reached a new level. Many countries, especially the US, created new state-sponsored cryptography programs. Among them is the Security Hashing Algorithm SHA-256, developed by NIST. Now, among many other applications, this algorithm is used to create blocks in Bitcoin. The Ethereum blockchain network uses an algorithm Keccak, based on which a new standard of hashing algorithm SHA-3 was created, first published in 2015.
SHA-256 and the Block Creation Process
The process of creating a block consists of validating a transaction and recording it. This process is called mining. Transactions are recorded in a block through hashing. Hashing is the process of converting a text of any length to a fixed-length value. Bitcoin transactions are hashed using the SHA-256 algorithm.
Here is an example of text versus its hash:
As you can see, the length of the text converted using SHA-256 does not affect the length of the hash, which always consists of 64 symbols and is 256 bytes in size. The SHA-256 algorithm is even sensitive to the case of the input letters: the hashes for the words Hello and hello (capitalized vs not capitalized) are completely different.
The purpose of mining is to determine the hash of the block being generated that will be suitable to all transactions in a given network. The difficulty of mining increases as more computing power is needed to create an individual block. As the computing power to create blocks grows, the amount of zero in a hash-code grows, too. Currently there are 20 successive zeros in the beginning of Bitcoin hash, and a huge volume of computational resources are needed to create a block. The maximum time for generating a block remains constant, however, and stands at 10 minutes. The difficulty of mining is automatically compounded after every 2016 blocks are created. This switch rate was fixed by the initial Bitcoin code.
So, the process of creating a block consists in recording the hash of a certain amount of transactions contained within it. Each Bitcoin block includes the following fields: a magic number, a blocksize, a blockheader, a transaction counter and transactions field that contains information about transactions in it.
Each block header has the following components:
version, previous block header hash, Merkle root hash, timestamp, difficulty target and nonce value.
Merkle root shows the hash of current block transactions and computed according to a Merkle tree algorithm, also called a binary hash tree. It works as follows:
Here is a Merklel binary hash tree:
As can be seen, a Merkle tree has a binary structure so it must have an even number of elements. In the event that a Merkle tree emerges with an uneven number of elements, the system doubles it in order to form a pair.
A Merkle tree with an uneven number of elements might look like this:
In this way, all data about transactions in a given block is calculated and recorded .
Each block is linked with the previous and the following block in a blockchain series. If you try to modify even one transaction in a block, it will cause a chain reaction. At first, this will alter the hash of the modified transaction and this, in turn, will change Merkle tree branch and, ultimately, the Merkle Root. After this, a modified Merkle Root will change the block header and this will change of all subsequent blocks in the blockchain sequence. In this way, even one modification will force the recalculation of all computational work initially performed to create this particular sequence of blocks.
Cryptography in Verifying Bitcoin and Ethereum Transactions
Data in Bitcoin and Ethereum transactions is verified with the signature produced by something called an Elliptic Curve Digital Signature Algorithm (ECDSA). This algorithm uses elliptic curves and finite fields.
The processes of signing and verifying a transaction are distinct. A tool called a private key is used for signing a transaction and another called a public key is used to verify it. A private key is randomly generated in the process of creating a wallet. A public key is mathematically derived from the private key using elliptic curve multiplication on a finite field. The private key is to be known only to the person who signs a transaction and the public key — to anyone who wants to verify it.
An elliptic curve consists of following parametres: an equation, a prime modulo and a base point with a prime order. The equation of an elliptic curve has the form y² = x³ + ax + b.
In Bitcoin, Ethereum, BKX, EOS, Litecoin and many other cryptocurrencies, an elliptic curve called secp256k1 is used. The equation of this curve looks like y² = x³ + 7 mod p. The prime modulo of the secp256k1 curve is =2²⁵⁶–2³²–2⁹–2⁸–2⁷–2⁶–2⁴–1 (or FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFC2F in hex form). This is essentially a large prime number, hence the name prime modulo.
The elliptic curve over field of real numbers looks like this:
Base point G has a prime order n that can be thought of graphically as the number of times the point can be added to itself until its slope is infinite, or a vertical line. The base point is selected so that the order is a large prime number.
For the secp256k1, the base point G in compressed form is: G = 02 79BE667E F9DCBBAC 55A06295 CE870B07 029BFCDB 2DCE28D9 59F2815B 16F81798, and the order n of G is: n = FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364141.
To generate a public key, we should multiply the private key by G:
Keypub = Keypriv × G
It is not so difficult to discover a public key through a private key. However, Keypriv is a very large number, so to derive a private key through public key and hack the ECDSA algorithm, 2¹²⁸ operations for additional points need to be computed. For a regular computer, such an operation would take more than ten billion years, a process compatible with the age of the universe.
After private and public keys have been generated, the transactions must be signed using private key.
To do this, we need to complete the following operations:
Note that k is a temporary secret value and must be destroyed right after step 5. Leaking secret value k is just the same as leaking private key: if attacker knows k and signature, then she(or he) can calculate private key.
4. Compute r = x mod n. If r = 0 then return to step 1;
Function x mod p divides x on p and returns only the remainder of division. For example 78 mod 33 = 12 as 78 = (33x2)+12, or 98 mod 31 = 5 as 98 = (31x3)+5).
Note that the multiplicative inverse of s modulo n is denoted as 1/k mod n, and 1/k mod n is equal to the solution of equation kx = 1(mod n). This equation is solved with the help of Euclid’s algorithm in the following way. Let’s assume that s = 3 and n = 5, then the equation appears as 3x = 1(mod 5), or, with Euclid’s algorithm, as 3x = b(mod 5). This extends to the linear Diophantine equation ax — by = c, or sx — ny = b, or 3x — 5y = 1, where x = 2 and y = 1 (6–5=1), so s-1 will be 2.
5. Compute s = (1/k mod n) × (z + r × Keypriv) mod n. If s = 0 then go back to step 1;
6. The computed pair (r, s) will be the signature of the transaction.
After the signature of the transaction is generated and received, any third party can verify it with the help of public key in the following way:
As we can see, the security of the ECDSA algorithm relies on the randomness of the k integer and on the impossibility of deriving a private key within a reasonable time using ordinary computing power. Blockchain technology has the highest level of security through this new form of encryption and the only way to break it is to create a quantum computer with more than 2000 qubits of computing power, something impossible at the present time.
BANKEX is available at:
Website — Telegram — Twitter — Facebook — Bitcointalk — Youtube — LinkedIn — Reddit — GitHub — Steemit
Essentials of Blockchain Cryptography was originally published in BANKEX - Proof-of-Asset Protocol on Medium, where people are continuing the conversation by highlighting and responding to this story.
Original article was created by: BANKEX at blog.bankex.org
Disclaimer: This article should not be taken as, and is not intended to provide, investment advice. Please conduct your own thorough research before investing in any cryptocurrency or ICO.Interested in Cryptocurrencies and ICO's?
Follow our telegram channel for daily cryptomarket reports!
Join @cointrendsRelated Articles
pubDate | Newsline | Author | Category |
---|---|---|---|
1 month ago | Benefits of Blockchain to Any Industry | Monetha | blockchain |
1 month ago | Update — 12/10/2018 | iXledger | blockchain |
1 month ago | BANKEX Monthly Update: September 2018 | BANKEX | bitcoin |
1 month ago | Largest South Korean Exchange Launches Crypto Market Indices | Kevin Helms | bitcoin |
1 month ago | BANKEX Monthly Update: September 2018 | BANKEX | ethereum |
1 month ago | Blocktix Dev Update Q3 | Blocktix | ethereum |
1 month ago | Largest South Korean Exchange Launches Crypto Market Indices | Kevin Helms | crypto |
1 month ago | Nigerian Startup Kubitx Launches Bitcoin Exchange in Beta | Jeffrey Gogo | crypto |
2 months ago | What Is Symmetric and Asymmetric Cryptography? | Monetha | cryptography |
Stay on top of Altcoins and ICO trends.
Subscribe to our free Weekly Cryptomarket report
Delivered once a week, strongly to your inbox.
Subscribe to our mailing listOctober 12, 2018
BANKEX Monthly Update: September 2018October 2018 has begun, so it’s time to look back on everything BANKEX achieved in September. In the first month of autumn, we presented the first use case of BANKEX Plasma, made the BKX token available in Freewallet, updated BANKEX Pay, and, last but not least, we launched BANKEX... From: BANKEX |
October 11, 2018
BANKEX Wants You to Hack its Custody Service for $15K in Reward (If You Can)BANKEX Custody Service is a world-class decentralized cryptocurrency depository for enterprises and individuals.Our advanced features include multi-layer security, ease of access, flexible asset storage, and 24-hour customer service.Every member of the BANKEX team knows that Custody Service... From: BANKEX |
October 10, 2018
What Will Happen to Your Crypto Savings When You DieNot many pieces about cryptocurrencies can be called morbid, but this article aims to break from the norm. Not only that, but it will also actually inform you about what will happen to your cryptocurrency savings postmortem and how you can ensure that your hard-mined bitcoins don’t go up in... From: BANKEX |
October 04, 2018
October 01, 2018
BANKEX Custody Service Part 2: What Makes It TickIn the first part of this article, we looked at the issues inherent in crypto storage, and what an ideal solution to these issues looks like. Now, let’s look at how BANKEX Custody Service handles users’ assets.First Things First: KYCThe first step in BANKEX Custody Sevice is KYC. This... From: BANKEX |
September 29, 2018
BANKEX Community QnA: How We Earn, Our Target Audience and Even MoreThis week, in cooperation with BANKEX Community Managment we are starting a series of QnAs about our company. Today, we are going to tell you who is BANKEX target audience, how we earn and some insights about BANKEX Crypto Custody. Enjoy!Q: How do you earn? A: We have 5 business streams as for... From: BANKEX |