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

Sunday, May 6, 2018

Solidity and Truffle Tips and Tricks - delete build folder


If you use solidity with truffle, sometimes it is a good idea to delete the entire build subdirectory, it will recreated anyway as you make a new compile. As an example if you get the following error message: "Attempting to run transaction which calls a contract function, but recipient address  ... is not a contract address" the resolution is simply delete and recreate the build folder. It happens regularly if you copy paste your solidity code for example between your local truffle environment and for instance remix.  

Tuesday, May 1, 2018

Geth commands summarized to handling accounts

Some of the most important accounts are summarized to handle accounts or wallets:

- personal.listAccounts - listing existing accounts from the local wallet and local user
- web3.accounts - listing all the accounts
- personal.newAccount() - creating new account - generating private / public key and protecting with passphrase - stored under datadir/keystore
- eth.coinbase - coinbase account
- personal.lockAccount('account_name') - locking an account
- personal.unlockAccount('account_name', 'passphrase') - locking an account
- personal.importRawKey(keydata, passphrase) - importing a
- eth.getBalance(''account') - getting ethereum balance for the account

Monday, April 30, 2018

Notes on cross-company business processes


Modelling business processes intern in a company might be totally different as speaking about processes between different companies. The reason for that that companies are built up based on different departments and the major challenge of a corporate business process is to describe the information flow of the department. If we speak about cross company processes however they have a little bit different characteristics. Companies working with each other mostly based on markets, either based on general free markets or some kind of a limited market. Another important difference is that information can not free flow freely, it has very strict private characteristics. As a result, if we want to define cross-company business processes we should much more concentrate and model the markets that are connecting the different enterprises. 

Sunday, April 29, 2018

Generating Solidity from Hyperledger Fabric Composer: asset inheritance


Inheritance can be translated from Hyperledger Composer to Solidity almost one to one. Both frameworks define inheritance among assets or smart contracts and there is the possibility to create abstract assets or smart contracts. The only difference is that Solidity supports multiply inheritance but Fabric Composer not really. 

Creating a blockchain integrated database


Integrating blockchain seems to be pretty straightforward for the first run. We can take an exisiting blockchain solution and validate all of the CRUD operations with the help of the blockchain. As in the following example implemented with Solidity, we can be sure that as soon as the blockchain raises our event, the given operation has been already validated by Ehereum. 

contract DB {

event CRUDOperationEvent (string operation);

    function CRUDOperation (string _operation) {
        CRUDOperationEvent(_operation);
    }
}

Certainly, it is questionable if such an integration makes sense at all, because the performance of the system will be surely dependent on the consensus algorithm itself, meaning that one has to wait for the operation around 15 second. Another issue might be the fact that the database is actually an external element from blockchain, so it is questionable how a real trusted integration can be realized. 

Generating Solidity from Hyperledger Fabric Composer: related assets

One of the idea of Hyperledger Fabric Composer is to have a domain specific language to model complex assets. Besides properties of an asset, connections or relations between assets can be defined as well. Like considering the following example:

asset TestAsset identified by primaryKey{
  o String primaryKey
  o String property1
  o String property2
  --> RelatedAsset relatedAsset
}

asset RelatedAsset{
}

The structure can be translated into several smart-contracts that reference to each other like in the following example:

contract RelatedAsset{
}

contract  TestAsset{
  string primaryKey;
  string property1;
  string property2;
  RelatedAsset public relatedAsset;
  
  function setRelatedAsset(RelatedAsset _relatedAsset) {
      relatedAsset = _relatedAsset;
  }
}

Certainly it is an open question how these contracts are created. On way is that there is an external factory contract that creates and administrates such a creation and calls only the setRelatedAsset function. Another way might be that the contracts realize the CRUD (Create Read Update Delete) operations on their own. 

A totally different way might be to use structs instead of contracts which makes things certainly much cheaper from a gas consumption perspective, however all CRUD operations must be handled externally.

contract Factory{

    struct RelatedAsset{
    }

    struct  TestAsset{
        string primaryKey;
        string property1;
        string property2;
        RelatedAsset  relatedAsset;
    }
}
 



Generating Solidity from Hyperledger Fabric Composer: enums

Translating enums from Hyperledger Fabric Composer to Solidity is pretty straightforward for the first run. You can one to one associate a Fabric Composer enum to a Solidity enum:

Hyperledger Fabric Composer:

enum TestEnum {
  o one
  o two
  o three
}

Solidity:

enum TestEnum {
   one,
   two,   
   three 
}
   
However the exact functioning might be a little bit different from time to time. As an example, in Fabric Composer enums are defined on the global level and handled generally, however in solidity enums are defined on a smart contract level, meaning that if you want to use the same enum  in more variables in several contracts you should define in each of the contracts or put it into an ancestor class and precisely define smart contract inheritance.

Generating Solidity from Hyperledger Fabric Composer: simple assets

Often it is a requirement to model and implement a requirements in different smart contract systems. For such a requirements it is important to know the differences between the different languages and abstraction possibilities. In our serial, we try to investigate the possibilities how Hyperledger Fabric Composer language elements can be translated into Solidity Ethereum.

A simple asset in Hyperledger Fabric Composer has some properties and some kind of a primary key:

asset TestAsset identified by primaryKey{
  o String primaryKey
  o String property1
  o String property2
}

one way to associate it with Solidity is to implement a Solidity smart contract for that, like:

contract TestAsset {
    string primaryKey;
    string property1;
    string property2;
}

However assets are not really handled as individual contracts but rather as a set of crypto-assets that are identified by the primaryKey. As a consequence such contracts should be embedded into a factory contract that creates and administrates the assets. One example might be:

contract TestAssetFactory {
    mapping (string => TestAsset) testAssets;

    function createTestAsset(string _primaryKey) {
       testAssets[_primaryKey] = new TestAsset();  
}}

Another option can be however that instead of contracts we use rather structs and the factory token creates a new struct instead of a new smart contract. From a point of view of gas consumption the second solutions will surely be cheaper. 


Consortium blockchains and business processes


Business processes describing consortium blockchain solutions should be fundamentally different than processes describing the operation of individual companies. The reason for that is that is that companies do not really communicate with  each other in an absolutely free manner. They regard company secrets as a very strong fundamental basis and they cooperate with each other only on a special interfaces. As interface I do not necessarily mean just a technical interface, the cooperation of the two companies usually mean that one provides a service, or sell goods that the other one can buy. So the major cooperation is actually the exchanging of goods and services and not some kind of another information sharing. This implies that best consortium blockchain processes must be able to describe different kind of crypto-assets, the relation, exchange, visibility and access rights of these crypto-assets as a primary goal. They must provide the way of putting most of this logic into the blockhain itself realizing with for example smart contracts and they should provide a way to create and configure things with the help of graphical user interfaces. In this sense Hyperledger Fabric has a good direction, even if they can not provide graphical user interface at the moment.  

Combining conveyor belt with artificial intelligence



Combining a conveyor belt with artificial intelligence is a dream that sounds for the first run pretty much as science fiction. However there a realistic chance of realizing such an algorithms. Let we imagine a configuration space with CU = {cu1,cu2,cu3 ... cuN} different configuration units where each cui configuration unit has a cui = {c1,c2 ... cki} set of different configuration possibilities. General software architectures can be regarded for instance to such systems, they provide many functionalities and which can be configured and put together in many different ways. In this example, we consider the configuration space as independent elements, however in general case they might be dependent from each other. 

A configurable conveyor belt is a subset of subsets of the whole configuration space CB =  {cb1,cb2,cb3 ... cuK}, where each cbi is a subset of a given cui. The cbi elements can be regarded as different steps of the conveyor belt and the elements in each cbi contains the different choices for each step. We can say that the conveyor belt is not configurable if each cbi step contains only one choice. We can say that the conveyor belt is human configurable if it contains 7 plus minus 2 steps and each step contain 7 plus minus 2  configuration choice. A conveyor belt might be hierarchical if each cbi configuration step can be regarded as a whole configuration space with configuration steps and sub-choices.

The major task of a conveyor belt learning algorithm is to analyse different choices of the configuration space and create or estimate a human configurable conveyor belt automatically with the help of statistical analysis or machine learning in order to capture the choice pattern that can be used in most of the situations.  

Domain specific languages can be also regarded in a way as special conveyor belts that are capable of realizing only parts of a theoretical configuration space. Unfortunately there is know known method to integrate with the artificial intelligence or machine learning. Perhaps such a theory could provide the basis for the integration. 

Another open question if conveyor belts can be built up a modular or even modular and hierarchical fashion and if they can be supported by efficient machine learning algorithms.