Value Arrays in Solidity

Jules Goddard
Coinmonks

--

This article discusses using Value Arrays as a way to reduce gas consumption in Solidity, the defacto smart contract language for the Ethereum blockchain.

Photo by Pierre Bamin on Unsplash

Background

During the development and testing of Datona Labs’ Solidity Smart-Data-Access-Contract (S-DAC) templates, we often need to use small arrays of small values. In the examples for this article, I investigate whether using Value Arrays will help me to do that more efficiently than Reference Arrays.

Discussion

Solidity supports arrays in memory which can be wasteful of space (see here), and in storage which consume a lot of gas to allocate and access. But Solidity also runs on the Ethereum Virtual Machine (EVM) which has a very large machine word of 256bits (32bytes). It is this latter feature that enables us to consider using Value Arrays. In languages with smaller word types e.g. 32bits (4bytes), Value Arrays are unlikely to be practical.

Can we reduce our storage space and gas consumption using Value Arrays?

Value Arrays compared to Reference Arrays

Reference Arrays

In Solidity, arrays are normally reference types. That means that a pointer to the array is used whenever the variable symbol is encountered in the program…

--

--

Jules Goddard
Coinmonks

Experienced high-integrity software engineer, crypto code compactor and Datona Labs founder — providing smart contracts to protect your digital information.