Thursday, January 27, 2022

Study Reveals a Costly Side to Smart Contracts

Study Reveals a Costly Side to Smart Contracts

On March 11th, a research paper was submitted to Cornell University’s “ArXiv.” In it, researchers discovered that many smart contracts are quite cost ineffective. Additionally, they found that Solidity, Ethereum’s recommended compiler, was generally unsuccessful at curbing this cost.

Also read: Major Japanese Department Store to Begin Bitcoin Payment Trial

According to the paper, researchers found seven costly programming patterns which end up overcharging smart contract users. They divided these patterns into two categories: useless-code related patterns, and loop-related patterns.

Together, these two categories of programming patterns explain the costliness of imperfectly programmed smart contracts.

First Ever Investigation of Solidity

The report itself claims to represent a first-of-its-kind investigation into the Solidity compiler and its ability to efficiently convert smart contract instructions into machine code. This investigation proved that it failed at optimizing or improving on “gas-costly” programming procedures.

To save money, developers must follow gas-efficient programming patterns. Unfortunately, there are no such guidelines yet, and it is difficult for developers to recognize what the paper identifies as gas-costly bytecode — or, in other words, inefficient machine code.

The difficulty is due, in part, to the technical nature of the Ethereum Virtual Machine (EVM). More precisely, the difficulty comes in understanding the inner workings of the EVM — a virtual machine (an emulation of a computer) which executes the binary code of programs such as smart contracts on the Ethereum platform.

Some specific knowledge required to understand EVM instructions include the gas consumption (cost in ether units) for different operations, the data locations accessed by operations, the amount of data read or written etc. Hence, the report notes that for this reason a compiler that can optimize the binary code for minimizing gas consumption is highly demanded.

GASPER: the Smart Contracts Solution

In response to their findings, the researchers developed and proposed a solution to the inefficiencies prevalent in programming patterns, called GASPER. Short for GAS-costly Patterns checkER, GASPER is a new tool for discovering inefficient patterns in bytecode automatically.

The tool leverages symbolic execution and it currently can locate three representative patterns, which cover the two categories. By applying GASPER to analyze all smart contracts executed until November 5th, 2016, the researchers found that 93.5%, 90.1% and 80% smart contracts suffer from these three patterns, respectively.

In developing GASPER the researchers hope to limit the two kinds of inefficient programming patterns that they pointed to before: useless-code related patterns and loop-related patterns. The former introduces additional costs due to the increased size of bytecode during the deployment and the removable bytecode in runtime, while the latter involves using expensive operations in the loop.

They assessed Solidity’s performance regarding these patterns by feeding it inefficient programming instructions, or “gas-costly” patterns in source-code, and checked to see if it efficiently converted the source code into machine code. The results of these tests demonstrated that Solidity was unable to optimize these programming patterns.

Furthermore, GASPER can now detect all programming patterns that belong to Category 1 and one representative pattern that belongs to Category 2. Going forward, they plan to develop the tool further to make smart contracts more efficient and cost effective for both present and future users.

What do you think of the study’s findings on smart contracts? What do you think of their solution? Let us know in the comments below.

Images via Solidity,, and

Bitsonline Email Newsletter