Sunday, December 15, 2024

 My new books 4th edition 


https://amzn.eu/d/iZ4SsCs

Mastering Blockchain, Fourth Edition

 my new book 


https://link.springer.com/book/10.1007/978-1-4842-8179-6



Regulated Autonomous Organization - RAO

AI and DLT convergence may produce "super smart contracts," where AI augments the decision-making within smart contracts.

Regulations can be implemented directly "on-chain" through a "Regulated Autonomous Organization" - RAO. "Autonomous" does not imply an absence of oversight but a system that operates independently with predefined rules, capable of accepting external regulatory intervention when necessary. 

Wednesday, March 24, 2021

Thrilled to see that my book Mastering blockchain - the third edition is a best-seller at Amazon! 

https://www.amazon.com/Mastering-Blockchain-distributed-consensus-cryptocurrencies/dp/1839213191/



Thursday, September 3, 2020

Mastering Blockchain: Third edition

Very pleased to announce a new edition of my book with four new chapters on consensus, tokenization, Ethereum 2.0 and enterprise blockchains. 

Available here:


and on Amazon

Mastering Blockchain: A deep dive into distributed ledgers, consensus protocols ... https://www.amazon.com/dp/1839213191/ref=cm_sw_r_tw_dp_x_CguuFb4KFCPT6



Sunday, June 17, 2018

How SHA256 works

SHA-256
SHA-256 has the input message size < 2^64-bits. Block size is 512-bits and has a word size of 32-bits. The output is a 256-bit digest.

The compression function processes a 512-bit message block and a 256-bit intermediate hash value. There are two main components of this function: compression function and a message schedule.

The algorithm works as follows:

Pre-processing:

1.   Padding of the message, which is used to make the length of a block to 512-bits if it is smaller than the required block size of 512-bits.
2.   Parsing the message into message blocks that ensure that the message and its padding is divided into equal blocks of 512-bits.
3.   Setting up the initial hash value, which is the eight 32-bit words obtained by taking the first 32-bits of the fractional parts of the square roots of the first eight prime numbers. These initial values are randomly chosen to initialize the process and gives a level of confidence that no backdoor exists in the algorithm.


Hash computation:

1.   Each message block is processed in a sequence and requires 64 rounds to compute the full hash output. Each round uses slightly different constants to ensure that no two rounds are the same.
2.  First, the message schedule is prepared.
3.  Then, eight working variables are initialized.
4.  Then, the intermediate hash value is calculated.
5.  Finally, the message is processed, and the output hash is produced:


one round of SHA256 compression function


 
In the preceding diagram, a, b, c,d, e, f, g, and h are the registers. Maj and Ch are applied bitwise.   performs the bitwise rotation. Round constants are Wjand Kj, which are added mod 2^32.

Saturday, June 16, 2018

How Advanced Encryption Standard (AES) works

Advanced Encryption Standard

In 2001 after an open competition an encryption algorithm named Rijndael that was invented by cryptographers Joan Daemen and Vincent Rijmen was standardized as AES with minor modifications by NIST in 2001. So far there is no attack found against AES that is better than brute force method.  Original Rijandaeil allows different key and block sizes of 128,192 and 256 bits but in AES standard only 128-bit block size is allowed. However key sizes of 128, 192 and 256 bit are allowed.

AES Steps

During AES Algorithm processing a 4 by 4 array of bytes knows as state is modified using multiple rounds. Full encryption requires 10 to 14 rounds depending on the size of the key. Following table shows the key sizes and required number of rounds.
Key Size
Number of rounds required
128 bit
10 rounds
192 bit
12 rounds
256 bit
14 rounds

Once the state is initialized with the input to the cipher, four operations are performed in four stages in order to encrypt the input. These stages are AddRoundKey, SubBytes, ShiftRows, and MixColumns.
1.    In AddRoundKey step, the state array is XORed with a subkey which is derived from the master key.
2.    This is the substitution step where a lookup table (S-box) is used to replace all bytes of the state array.
3.    This step is used to shift each row except the first one in the state array to the left in a cyclic and incremental manner.
4.    Finally, all bytes are mixed in this step in a linear fashion column-wise.

The steps above describe one round of AES. In the Final round (either 10, 12 or 14 depending on the key size), Stage 4 is replaced with Addroundkey to ensure that first three steps cannot just be simply inverted back.
AES block diagram, showing 1stround, in last round mixing step is not performed
Various cryptocurrency wallets use AES encryption to encrypt locally stored data. Especially in bitcoin wallet, AES 256 in CBC mode is used.

Saturday, June 2, 2018

How Ethereum Virtual Machine (EVM) works

The diagram below shows the design of the EVM where virtual ROM (right) stores the program code which is copied into main memory by using CODECOPY. Main memory is then read by the EVM by referring to the Program counter and executes instructions step by step. Program counter and EVM stack are updated accordingly with each instruction execution.
EVM is an entirely isolated and sandboxed runtime environment. The code that runs on the EVM does not have access to any external resources such as network or file system.
As discussed above EVM is based on a stack-based architecture. EVM is big endian by design, and it uses 256 bit wide words. This word size allows for Keccak 256 bit hash and Elliptic curve cryptography computations.
There are two types of storage available to contracts and EVM. First is called memory which is a byte array. When a smart contract finishes the code execution, the memory is cleared. It is akin to the concept of RAM. The other type called storage is permanently stored on the blockchain. It is a key-value store. 
Memory is unlimited but constrained by gas fee requirements. The storage associated with the virtual machine is a word addressable word array which is non-volatile and is maintained as part of the system state. Keys and value are 32 bytes in size in storage. The program code is stored in a virtual read-only memory (Virtual ROM) which is accessible by using CODECOPY instruction. CODECOPY instruction is used to copy the program code into main memory. Initially, all storage and memory are set to zero in the EVM.

Friday, June 1, 2018

Symmetric cryptography - Cipher Block chaining mode (CBC)

In this mode, each block of plaintext is XORed with the previous encrypted block. CBC mode uses initialization vector IV to encrypt the first block. It is recommended that IV is randomly chosen.









Saturday, May 12, 2018

What exactly is a Smart contract

A smart contract is a secure and unstoppable computer program representing an agreement that is automatically executable and enforceable.
Dissecting this definition further reveals that smart contract is, in fact, a computer program that is written in a language that a computer or target machine can understand. Also, it encompasses agreement between parties in the form of business logic. Another fundamental idea is that smart contracts are automatically executed when certain conditions are met. Also, they are enforceable which means that all contractual terms are executed as defined and expected even in the presence of adversaries. Enforcement is a broader term that encompasses traditional enforcement in the form of law along with an implementation of specific measures and controls that makes it possible to execute contract terms without requiring any mediation. It should be noted that "real" smart contracts should not rely on traditional methods of enforcement instead they should work on the principle where “code is law” meaning that there is no need of an arbitrator or a third party that can control or influence the execution of the smart contract. The smart contracts are self-enforcing as opposed to legally enforceable. This might be regarded as a libertarian’s dream but is entirely possible and is in line with the true spirit of smart contracts.
Moreover, they are secure and unstoppable which means that these computer programmes are required to be designed in such a fashion that they are fault tolerant and executable in a reasonable amount of time. These programmes should be able to execute and maintain a healthy internal state even if external factors are unfavourable.
For example, imagine a standard computer programme which is encoded with some logic and performs according to the instruction coded within, but if the environment it is running in or external factors it relies on deviates from normal or expected state the programme may react arbitrarily or simply abort. It is essential that smart contracts are immune to this type of issue.
It will provide more significant benefit in the long run if security and unstoppable properties are included in the smart contract definition from the beginning. It will allow researchers to focus on these aspects from the start and will help to build strong foundations on which further research can then be based.

Monday, May 7, 2018

what is Ethereum Virtual Machine

EVM is a simple stack-based execution machine that runs bytecode instructions to transform the state from one state to another on the Ethereum blockchain. The word size of the virtual machine is set to 256-bit. The stack size is limited to 1024 elements and is based on the LIFO (Last in First Out) queue. EVM is a Turing-complete machine but is limited by the amount of gas that is required to run any instruction. This means that infinite loops that can result in denial of service due to malicious attacks or inadvertently are not possible due to gas requirements. EVM also supports exception handling in case exceptions occur, such as not having enough gas or invalid instructions, in which case the machine would immediately halt and return the error to the executing agent. EVM is a stack-based architecture. EVM is big-endian by design, and it uses 256-bit wide words. This word size allows for Keccak 256-bit hash and elliptic curve cryptography computations. EVM is a fully isolated and sandboxed runtime environment. The code that runs on the EVM does not have access to any external resources, such as a network or filesystem.

Saturday, May 5, 2018

Intelligent Smart Contracts (ISCs)

It is said that smart contracts are neither smart nor contracts. This is true to some extent, but smart contracts are and should be smart enough to do what they have been programmed to do, correctly and do it in a deterministic fashion. If contracts (business logic) are programmed within the smart contract and are enforceable, then they actually become contracts, just like real-life contracts enforceable by law. The issue, however, is that they are not really smart, or in other words intelligent.
I am proposing an idea to research building "Intelligent Smart Contracts (ISCs) " or "Smarter Contracts" or "Smart Intelligent Contracts (SICs)," which are genuinely smart and intelligent enough to learn and adapt themselves according to the external conditions and environment.
With the convergence of Artifical intelligence (AI) and machine learning with blockchain, this vision will become a reality. Soon this convergence will give rise to "Blockchain X.0"; the next generation of blockchains, where rational agents work for human beings and make intelligent decisions on behalf of humans in a truly decentralized environment.

Post trade settlement using Blockchain

This application is the most sought-after utilisation of blockchain technology. Currently, many financial institutions are exploring the possibility of using blockchain technology to simplify, automate, and speed up the costly and time-consuming post-trade settlement process. Australian Securities Exchange (ASX) is already replacing their legacy "CHESS" system with Distributed ledger technology.
To understand the problem better the trade lifecycle is described briefly. A trade lifecycle contains three steps: execution, clearing, and settlement.
Execution is concerned with the commitment of trading between two parties and can be entered into the system via the front office order management terminals or exchanges.
Clearing is the next step whereby the trade is matched between the seller and buyer based on specific attributes such as price and quantity. At this stage, accounts that are involved in payment are also identified.
Finally, the settlement is where eventually the security is exchanged for payment between the buyer and seller.
In the traditional trade lifecycle model, a central clearinghouse is required to facilitate trading between parties which bears the credit risk of both parties. The current scheme is somewhat complicated, whereby a seller and buyer have to take a complex path to trade with each other. This complexity comes from the composition of various firms, brokers, clearing houses, and custodians but with Blockchain, a single distributed ledger with appropriately designed smart contracts can simplify this whole process and can enable buyers and sellers to talk directly to each other, without the requirement of a trusted third party.
Notably, the post-trade settlement process takes two to three days and has a dependency on central clearing houses and reconciliation systems. With the shared ledger approach, all participants on the blockchain can immediately see a single version of truth regarding the state of the trade. Moreover, a peer-to-peer settlement is possible, which results in the reduction of complexity, cost, risk, and the time it takes to settle the trade. Finally, intermediaries can be eliminated by making use of appropriate smart contracts on the blockchain.

Tuesday, May 1, 2018

How Blockchains are immutable

Immutability is a crucial feature of blockchains: records once added in the blockchain are immutable. There is the possibility of rolling back the changes, but this is considered almost impossible to do as it will require an unaffordable amount of computing resources. For example, in case of bitcoin if a malicious user wants to alter the previous blocks, then it would need computing the Proof of Work (PoW) again for all those blocks that have already been added to the blockchain. This difficulty of redoing the PoW makes the records on a blockchain practically immutable.

Monday, April 30, 2018

Task of miners on Bitcoin network

Once a node connects to the Bitcoin network, there are several tasks that a Bitcoin miner performs.

  • Synching up with the network: Once a new node joins the bitcoin network, it downloads the blockchain by requesting historical blocks from other nodes. This is mentioned here in the context of the bitcoin miner; however, this not necessarily a task only for a miner.
  • Transaction validation: Transactions broadcasted on the network are validated by full nodes by verifying and validating signatures and outputs.
  • Block validation: Miners and full nodes can start validating blocks received by them by evaluating them against certain rules. This includes the verification of each transaction in the block along with verification of the nonce value.
  • Create a new block: Miners propose a new block by combining transactions broadcasted on the network after validating them.
  • Perform Proof of Work: This task is the core of the mining process and this is where miners find a valid block by solving a computational puzzle. The block header contains a 32-bit nonce field and miners are required to repeatedly vary the nonce until the resultant hash is less than a predetermined target.
  • Fetch reward: Once a node solves the hash puzzle, it immediately broadcasts the results, and other nodes verify it and accept the block. There is a slight chance that the newly minted block will not be accepted by other miners due to a clash with another block found at roughly the same time, but once accepted, the miner is rewarded with 12.5 bitcoins (as of 2018) and any associated transaction fees.

Sunday, April 29, 2018

CAP theorem and blockchain

It seems that the CAP theorem is violated in the blockchain, and especially in the most successful implementation: Bitcoin, but this is not the case. In blockchains, consistency is temporarily sacrificed in favour of availability and partition tolerance. In this scenario, Consistency (C) on the blockchain is not achieved simultaneously with Partition tolerance (P) and Availability (A), but it is achieved over time. This is called eventual consistency, where consistency is achieved as a result of validation from multiple nodes over time. For this purpose, the concept of mining was introduced in Bitcoin; this is a process that facilitates the achievement of consensus by using a consensus algorithm called Proof of Work (PoW). At a higher level, mining can be defined as a process that is used to add more blocks to the blockchain.

 My new books 4th edition  https://amzn.eu/d/iZ4SsCs