...by Daniel Szego
quote
"On a long enough timeline we will all become Satoshi Nakamoto.."
Daniel Szego

Sunday, December 31, 2017

Notes on Quorum private contracts and sharding


Quorum has a feature called private contracts in which a contract is executed only on specific nodes meaning that the data of the transaction is encrypted and it can be encrypted only on specific nodes, defined by the contract. The state model is spited into two major categories: 
- public state is validated by each node and made consistent on the whole network
- private state is validated only on specific nodes: only if the contract is in party with the node. 

From a practical point of view it is a special kind of sharding. As private contracts can not call a public ones, the public state is always consistent. However, considering the private contracts, there might be some unexpected result, if the similar logic is deployed with different parties and they confidently call the same private contract, it can be pretty much questionable how the consensus is created.  

Solidity and Truffle Tips and Tricks - Migration hangs


Sometimes if you migrate with truffle to a consortium blockchain network, especially if the network does not use proof of work, like at quorum, the migration hangs at the first transaction. Despite, if you check manually on the network with geth, the first contract seems to be deployed without errors, it is just somehow truffle does not get the feedback on that. Surprisingly, if you use the -- verbose-rp parameter, the migration continues without error. Do not ask why :)

truffle migrate --network quorum --verbose-rp



Notes on decentralized artificial intelligence algorithms and platforms


As there are many initiatives to create decentralized artificial intelligence algorithms, most of them work in a way that they weakly integrate the blockchain technology with different blockchain platforms, usually via interfaces and a common tokens that represent some kind of an exchange of the services. Similar projects that successfully made an ICO are for example Neureal, SingularityNET, or Neuromation. However it would be much more interesting to integrate a distributed ledger technology with a machine learning algorithm really on the algorithmic level. It would provide this way a whole integrated algorithm for decentralized artificial intelligence. Certainly it is an open question which AI algorithm can be efficiently integrated with which decentralized technology. 

Friday, December 29, 2017

Azure Blockchain walkthrough - Setting up a Quorum Blockchain Demo

Azure Blockchain platform have some pretty cool solutions to create consortium blockchain solutions. In this walkthrough we are going to demonstrate one step by step guideline for setting up a Quorum demo environment including, configuring the environment and deploy the first applications on top. Quorum is an extension / fork of Ethereum for consortium scenarios, including two useful extensions:
- increased performance with a Proof of Authority algorithm
- private and confidential transactions
- node privacy

1. Choosing the necessary Azure Blockchain template: Azure Blockchain has many different templates. Two of them are important for Quorum consortium blockchains: with the help of "Quorum Single Member Blockchain Network" you can create a minimal infrastructure, with "Quorum Demo" a preconfigured demo environment is delivered.

Figure 1. Quorum Azure templates

2. Delivering Infrastructure: In this tutorial we deliver the "Quorum Demo" template. It requires the configuration of a standard Azure image with the usual virtual machine sizing parameters. All blockchain specific installation step will be configured in the post configuration.

Figure 2. Setting up Quorum demo infrastructure

3. Post configuration of the infrastructure: 

 ssh <user>@<ip> -- logging in into the environment
 git clone https://github.com/jpmorganchase/quorum-examples.git -- cloning the repo
 cd quorum-examples/examples/7nodes -- the 7 nodes demo
 sudo su -- changing to root
 ./raft-init.sh -- initialising the environment (you have to probably use sudo)
 ./raft-start.sh -- starting the environment (you have to probably use sudo)

If you see the following screen, the Quorum demo started successfully.


Figure 3. Quorum demo started successfully

Optionally, before starting the nodes it might be a good idea to pre-allocate some ether. The 7nodes demo uses the genesis.json genesis file. You can pre-allocate ether to the coinbase address with the following command:

"alloc": 
 {"0xed9d02e382b34818e88b88a309c7fe71e65f419d": {"balance":
    "111111111"}}

4. To test if things working you can attach to the nodes with the help of the Geth console and make further configuration if necessary (make sure that you are in the 7nodes demo folder, if you get permission denied error message use sudo at the beginning, if the ipc file is not found than there was probably an error in the previous step at setting up the network):

 geth attach ipc:qdata/dd1/geth.ipc

Optionally, after attachment it might be a good idea to distribute some of the preallocated ether, with the following command:

eth.sendTransaction({from:"0xed9d02e382b34818e88b88a309c7fe71e65f419d",to:"<to_address>", value: 100000000})

5. Testing a pre-deployed private contract: with the 7nodes demo scenario, there is a private contract, called simple storage that has already been deployed at the setting up of the network, you can test as starting two windows and attaching to the node 1 and node 4:

geth attach ipc:qdata/dd1/geth.ipc
geth attach ipc:qdata/dd4/geth.ipc

then configuring the contract

var address = "0x1932c48b2bf8102ba33b4a6b545c32236e342f34";


var abi = [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initVal","type":"uint256"}],"type":"constructor"}];

var private = eth.contract(abi).at(address)

then calling get function should deliver 42 on node 1 and 0 on node 4:

private.get()

6. Configure Truffle: Truffle must be configured to the environment with a custom network configuration that can be set in truffle.js. It is important to set the public address to the public address of the virtual machine and configure the 22000 (Quorum rpc port to be open):


Figure 4. Live (Quorum Azure) network configuration

You can use the following command for migration:

truffle migrate --network live --verbose-rp

If you configured correctly, you should be able to start a migration with Truffle. There might be some issues however, as an example, if you Truffle deployment will remain hanging in some scenarios. The reason for that is that the development javascript expects that the transaction was actually mined. As however in Quorum there is no mining, the process might stay hanging. One workaround is to use only one javascript deployment script and based on the transaction hashes check explicitly if the given transaction was correctly validated. Another workaround that sometimes work is to start the Truffle console explicit on a given node and execute the migration from there. And last but not least, do not forget to open the 22000 - 22008 ports on the Azure environment.  

7. Configuring metamask with Quorum: configuring metamask with quorum is pretty similar to configuring another given network via the Custom RPC of Metamask. Simply use the IP address and the port with http:


Figure 5. Metamask configuration for Quorum















The rise of the new technology elite


With the current trends and dynamics of changing technologies and business environments, old fashioned company leading techniques and management techniques simply do not have the chance. High tech companies can be only lead with a real hard-core, real high-tech and geek mindset with first case experience in the field. Any other strategy will simply not be able to keep track of the changes and define strategy even in a couple of years ahead. 

It works even with very simple examples, a software development methodology can not be efficiently lead by people who never ever wrote a piece of code. Similarly, infrastructure management can be efficiently managed by people who already did configure live systems and perhaps made outages as well. However, perhaps the best example is general software strategy: if you want to predict the next generation of IT services, you must simply have the first-hand, in-depth experience with a couple of technology changes. The situation is perfectly demonstrated by the fact that old-fashioned management schools offer technology oriented courses, like Artificial Intelligence in sales, or Big Data in Human Resources.   

notes on the increasing need of enterprise IT support

Our IT systems are getting more and more complicated every day. That is actually not a surprising fact, what is however more surprising that the possibility for getting support does not seem to keep up with the technology changes. As an example about 15 years ago installing an enterprise software meant to have something as a stable release, that is tested and runs more or less in a stable way with an install guide install software sometimes checking prerequisites as well. Nowadays the situation seems to be more complicated, probably due to the lean agile methodologies. 

There is not anymore something as a stable release, check the releases on git and try to install the version that you like. There is no real documentation about the prerequisites, there is usually a list of software that surely needed but which version is compatible with the software that you want to install is pretty questionable. If there is something as an install, it is usually a script which runs sometime but does not run in other situations and well if it does not run it is actually for you to edit and modify. And on top you find usually zero documentation, at most some Readme.md files or some hints with the repository or in social forums. 

Solidity and Truffle Tips and Tricks - setting up Truffle development environment


As I install a brand new environment usually with a brand VMware image, it is time to summarize the necessary steps instead of google-ing them always again and again.

1. Install brand new Ubuntu, I usually use the 16.04 version.

2. Installing open vmware tools:

 sudo apt-get install open-vm-tools
 sudo apt-get install open-vm-tools-desktop

3. Install packages:

 sudo apt-get update && sudo apt-get -y upgrade
 sudo apt-get -y install curl git vim build-essential

4. Install NodeJS:

 curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
 sudo apt-get install -y nodejs
 sudo npm install -g express

5. Install Truffle

 sudo npm install -g truffle

6. Install TestRPC

 sudo npm install -g ethereumjs-testrpc

7. Test: you can test the whole installation for instance by initializing a new project by Truffle:

 mkdir test
 cd test
 truffle init
 truffle develop

8.  Install Visual Studio Code, you can install fully from command prompt with the help of the following commands:

 curl https://packages.microsoft.com/keys/microsoft.asc | gpg -- dearmor > microsoft.gpg
 sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
 sudo sh -c 'echo "deb [arch=amd64]  https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
 sudo apt-get update
 sudo apt-get install code

9. Last but not least, install the solidity extension under Visual Studio Code extentions

 









Azure Blockchain walkthrough - Setting up Ethereum Consortium Blockchain

Azure Blockchain platform have some pretty cool solutions to create consortium blockchain solutions. In this walkthrough we are going to demonstrate one step by step guideline for creating, configuring a consortium network and develop and deploy the first applications on top. 

1. Choosing the necessary Azure Blockchain template: Azure Blockchain has many different templates. Two of them are important for Ethereum consortium blockchains: with the help of "Ethereum Consortium Blockchain" you can create a consortium infrastructure up to 12 nodes in one configuration step. With "Consortium Leader" or "Consortium Member", there is the possibility to do the same configuration step-by-step, with other words dynamically if a new member joins.   

Figure 1. Azure Ethereum templates

2.  Configuring the template: After the necessary template have been chosen it has to be configured. Apart from the usual Azure parameters like resource group and administrator accounts, the structure of the network has to be set, like the number and size of the mining and translation nodes. or the number of consortium members. The last tab provides the possibility to configure the Ethereum specific settings, like the network ID or a custom genesis block.    


Figure 2. Configuring the Ethereum Consortium Blockchain

3. Creation finished: If the network creation finished, the most important parameters are to be found in the result page:
- Admin-site: a general page about the status of the network, including a faucet as well to distribute some pre-allocated ether.
- RPC-Endpoint: is an important parameter for communicating with the consortium blockchain for example from Truffle or Metamask.
- SSH Info: is important for logging in into the environment and configuring parameters, like most typical for unlocking the coinbase account.

Figure 3. important parameters for accessing the consortium blockchain

4. Unlocking the coinbase account: It might cause difficulties in the future so it is not a bad idea to explicitly unlock the coinbase account. With the help of ssh and the ssh command of the previous configuration window, you can attach to the first node of the ethereum consortium network (note that usually the first node is the transaction node, if it is confidently different, you can log in into further nodes with using -p 3001 3002 ... parameters).

If you logged in, you can use: 

  geth attach  -- to attach to a running geth instance

  personal.unlockAccount(eth.coinbase) -- unlocking the coinbase account, the default unlock time is 5 minutes.

 eth.coinbase -- getting the address of the coinbase account

 personal.unlockAccount('address', 'passphrase', 'duration')  -- unlocking the account for a longer time period. If you use 0 as duration, the account will be locked forever. 

5. Configuring Metamask: Based on the Ethereum-RPC-Endpoint, Metamask can be configured with changing from the Main Network to a custom RPC. With the help of the admin page faucet and newly generated accounts, the pre-allocated ether can be further allocated and the network basic network functionality can be tested.


Figure 4. Metamask configuration

6. Deploying contract: If Metamask set up you can directly or indirectly deploy contracts with the help of remix by selecting "Injected Web3" or "Web3 Provider" at the environment. "Injected Web3" deploys the contract with the help of the configured Metamask account.


Figure 5. Remix configuration


7. Configuring Truffle for the consortium network: if you want to deploy to the new Azure consortium network, make sure that you configured the new network in the truffle.js configuration file. You can get the host name as the Ethereum-RPC-Endpoint from the output window, and you can get the network_id from the initial configuration. You can deploy on your consortium network for instance with the truffle migrate --network azureNetwork command.


Figure 6. Truffle configuration


Thursday, December 28, 2017

Notes on Nakamoto Consensus



From a theoretical perspective in a blockchain protocol a Nakamoto consensus works as a lottery game, the one who wins the lottery gets the possibility to create the next block. If the next block is faulty or there is a cheat, than there is a huge possibility that the new block will be not propagated successfully to the network, so the winning node does not get a reward. The winning lottery combination or "ticket" is actually a nonce value of the block that is both consistent with the previous block hashed and with the difficulty of the system.

The analogy is actually not 100%, in a blockchain style lottery system the winning ticket might be different or individual for each miner because the coinbase transaction is different for each of them. There should be on a long term always one winning ticket, in short term however it is possible that winning tickets are competing to become final one, it is practically called as standard forking. 

Solidity and Truffle Tips and Tricks - gas limit, gas exceptions


If you reach different gas limits during the development and testing your contract and you get different exceptions like out of gas exception or gas limit exceeded, you can do the following things.
- configure the given gas explicitly at the contract creation or at the function execution, like:  

testContract.functionCall(_functionParameter, {gas:4700000});

- or configure the block gas limit in the truffle environment to your testRPC by modifying the truffle.js configuration file and adding explicit block gas limit, like:

  networks: {
    develop: {
      host: "localhost",
      port: 9545,
      network_id: "*",
      gas: 4700000
    }
  }

Note however that the block gas limit on the live network is around 4700000 at the moment, so truffle at this current release do not let you go above this parameter.