I am writing smart contracts for a private EVM-compatible blockchain. Due to that, the gas cost isn't as relevant as it would otherwise be. Instead, we are more focused on the size of the blockchain over time, with data written into it over each transaction.
However, while two functions() might be storing
the same amount of data in the blockchain, their complexity can vary a lot, and thus the gas cost.
Here is a simple example:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.3;
contract WastingGas {
uint256 number;
// Gas cost: 43768
function addData(uint256 _number) public {
number = _number;
}
// Gas cost: 92258
function addDataBadWay(uint256 _number) public {
wasteGas();
number = _number;
}
// Mocking some complex/expensive function that isn't writing anything into the storage
function wasteGas() internal {
for(uint i; i<100; i++) {
uint wastingGas = number + i;
}
}
}
My question is: Will the addDataBadWay()
increase the size of the blockchain more than addData()
?? Both functions only store a single uint
variable; therefore, they should increase the blockchain size by the same 256 bits
. But it still seemed prudent to ask this question.