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

Wednesday, March 14, 2018

Blockchain as a high-available system architecture




The whole Blockchain area can be regarded from a pretty practical, engineering point of view as well: 

You want to design a high-availability system that is resistant even to byzantine attacks or errors ? 
Pick a distributed ledger technology with an adequate consensus algorithm.

Tuesday, March 13, 2018

Model of faulty nodes in a P2P network


From a conceptual point of view, there might be a good idea to distinguish different kind of a faulty nodes and behaviors in a distributed system:
- Altruistic behavior: the node works correctly and tries to be conform maximally with the protocol
- Rational behavior: the node works rational meaning that it follows the protocol only if it is profitable, otherwise if it is more profitable to show non-conform behavior, the node will behave in such a way. 
- Byzantine behavior: real byzantine behavior can be motivated by anything or it can be really faulty so might behave anyhow.

It is important to note that as altruistic and rational behavior can be motivated by correctly engineered cryptoeconomical incentive mechanisms. However, real byzantine behaviors can not be motivated by such a factors, because either the node is completely faulty or is motivated by non-economical incentives, like preparing a gold finger attack. 

Monday, March 12, 2018

Two-phase commit on blockchain


Two-phase commit is a classical way to record highly reliable transaction into a classical database system. It makes however sense to implement in a Blockchain context as well as a basic blockchain protocol. In such a protocol on the one hand transactions and somehow the committing phase as well are supported by cryptography like all information processing phase are signed by a private key of the node that initiates, resulting that the whole voting process can be much less hacked. On the other hand transaction manager is usually a centralized role that can be easily imagined by a decentralized P2P network working with a consensus protocol providing Byzantine fault tolerance. If the transaction is committed both by the voters and the blockchain network it can be saved into the transaction database. Certainly it is a question if both voters and validators are required or we might as well mix somehow the two roles. Another interesting question might be how much more security does such a system provide comparing to other solutions.   

Monday, February 12, 2018

Ethereum and smart contract security tools summarized


Some of the most important tools for testing ensuring or improving the security for your smart contract are the followings. Even if some of them are pretty much in a beta phase, it is practical to list them:

- OpenZeppelin: Solidity library for writing secure smart contracts:

- Oyente: analysis tool for smart contracts:

- SolCover: Solidity testing code coverage

- SolGraph: visualizing structure and control flow of solidity contracts

- Vyper: new experimental and more secure programming language for Ethereum smart contracts

- Securify: formal verification initiative for solidity smart contracts
https://securify.ch/

- SmartCheck: another verification tool for looking for wrongly implemented patterns
https://tool.smartdec.net/

- Ganache: more UI and user friendly testrpc



Sunday, February 11, 2018

Solidity and Truffle Tips and Tricks - default visibility


Dafault visibility in Solidity:
- for variables: private
- for functions: public

Solidity and Truffle Tips and Tricks - delete


Deleting objects and different variables are usually possible, however delete actually does not delete objects in solidity but it sets the values to the default value, like 0. As in the following examples, setMyMapping creates a new mapping element and initializes with _value. However deleteMyMapping does not actually deletes that element, instead it sets the value to zero. 


contract TetDelete{

mapping(string => uint) myMapping ;

  function getMyMapping (string _input) returns (uint){
      return myMapping[_input];
  }
  
    function setMyMapping (string _input, uint _value){
      myMapping[_input] = _value;
  }

  function deleteMyMapping(string _input){
      delete  myMapping[_input];
  }
}


Solidity and Truffle Tips and Tricks - function pointers


There is a possibility to use function pointers in solidity. Practically you can define a function and set a variable defining the type of the variable as var:

contract TetFunctionPointer{

  function myFunction (uint256 input){
  }

  function testFunction(){
      var fvPointer = this.myFunction;
      fvPointer(22);
  }
}

Saturday, February 10, 2018

Solidity and Truffle Tips and Tricks - overriding built-in functions


Some items in solidity like the type address has a couple of built in function for transferring ether or querying balance. The functions are the followings:

<address>.balance (uint256):
balance of the Address in Wei

<address>.transfer(uint256 amount):
send given amount of Wei to Address, throws on failure

<address>.send(uint256 amount) returns (bool):
send given amount of Wei to Address, returns false on failure
 
you can not make inheritance from a built in type, however what you can do is to define the same functions in a custom class, indirectly overwriting these functions. 

contract ExtAddress{

  function balance (uint256){
  }

  function transfer(uint256 amount){
  }

  function send(uint256 amount) returns (bool){
  }
}

They do not directly overwrite the address functions, however in certain situations the functions can be exchanged for the first site. 

Sunday, February 4, 2018

Solidity and Truffle Tips and Tricks - blockchash


you can use the blockchash() function to query the hash of a block from the blockchain. However, it is important to note that the hash of the latest or actually block is actually not known in execution time, because the block is still being minded. As a consequence block.blockhash(block.number) results always null.

Otherwise the blockchash might be zero for old blocks as well, as Ethereum stores only the last 256 block hashes for scalability reasons. 

Solidity and Truffle Tips and Tricks - order of modifiers


If you have several modifiers in a solidity function these modifiers might be dependent from each other, hence they might self modify the world state giving the possibility for another precondition for the next check. Anyway, the order of evaluation is from left to right as probably expected. So executing the test() function in the following code results "three"in the num variable. 

contract TestContract {
    string public num = "zero";
    
    modifier one(){
        num = "one";
        _;        
    }
    
    modifier two(){
        num = "two";
        _;        
    }

    modifier three(){
        num = "three";
        _;        
    }

    function test() one two three {
    }
}