Smarter smart contract

Paper
Github Repo

Abstract

Different from traditional programs, which run on local machines or in the clouds, smart contracts run mostly on miners’ devices; moreover, users of smart contracts have to pay fees (i.e., gases in Ethereum) to miners for executing the transactions on the blockchain. Lack of enough experience in developing smart contracts makes writing low cost and highly efficient smart contracts a very challenging task. During this work, by collating existing approaches and developing new methods for reducing gas consumption, a set of systematical step-by-step guidelines for developing low-cost smart contracts is proposed. To prove its usefulness, ZoKrates verifier, a very complicated and costly contract, is used to demonstrate how our scheme can effectively decrease gas consumption.

img13.png Figure 1. The workflow of the proposed smart contract smartening scheme for reducing gas consumption

Initialization

img14 Figure 2. The workflow of Initializing Input and Variables step.

function StackTooDeep(uint a, uint b, uint c, uint d,
     uint e, uint f, uint g, uint h, uint i) 
     public returns (uint) {
        return a + b + c + d + e + f + g + h + i;
} 

CompilerError: Stack too deep, try removing local variables. while too many inputs

Comparison between the usage of multiple variables and an array as input formats. Using an array as input type causes a gas consumption increase by 18508 (16.8%) in deployment and 190 (0.86%) in execution, respectively.

Function Design

The workflow of Merging functions step.

Figure 3. The workflow of Merging functions step.

Final Adjustments

Hello

Figure 4. If the closer the Method ID is to the root, the smaller the searching cost is.

Evaluation

Case study Zokrates verifier contract img17 Figure 5. The gas reduction in each step

Conclusion