remix-project
remix-project copied to clipboard
solc gas output different from remix
I have a file that looks as such:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;
contract BasicSolContract {
uint256 public myVar;
function updateVar(uint256 myNewVar) external {
myVar = myNewVar;
}
}
When I compile it with solc and look for a gas estimate, I get the following:
solc --gas --base-path . -o ./build ./contracts/solidity/BasicSolContract.sol
Gas estimation:
construction:
111 + 61400 = 61511
external:
myVar(): 2429
updateVar(uint256): 22498
However in remix, when I deploy it, I can see the gas is different.
The optimizer is enabled with 200 runs in remix.
@PatrickAlphaC Have you compared with other ways of sending transactions?
I think this is not specific to Remix or VM. Without optimization, Remix shows gas cost as 119683 which is similar If contract is deployed on Goerli

Yeah... I'm not sure who is right. I'm thinking someone's compiler is doing something funky.
@PatrickAlphaC I have asked Solidity team to have a look. Let's see.
This is known issue: https://github.com/ethereum/solidity/issues/8920
Wow! Thanks for this!
Are there any alternative libraries that Remix could use for gas estimation? Honestly, there's so much that the estimator in the compiler does not cover that we're debating if it's even useful in practice. And even if we fix the constructor quirk, it's unlikely we'll be putting much more work into it in the near future...
It looks like the remix gas estimator is actually "good" right?
Ah, right. I mean, it's not estimation, it's the cost of actual execution, but yeah, the numbers from screenshots do not need fixing.
I just thought that Remix uses compiler's estimator for something but maybe I was wrong about that. I vaguely remember someone complaining about wrong estimations from Remix that in the end turned out to be compiler's estimations.
Makes sense, I think people might have just confused the two. I thought remix was wrong too ahah. Yeah it looks like remix just mocks deploying the contract to do gas estimation (I think). In any case, it looks like this issue can be closed in favor of https://github.com/ethereum/solidity/issues/8920 @Aniket-Engg
Thanks for everyone's work on these!