solc gas output different from remix
See original GitHub issueI 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.
Issue Analytics
- State:
- Created a year ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Discrepancy in Solidity compiler output for Remix and offline ...
I'm compiling the following contract locally and on Remix and getting two different bytecode results. Contract pragma solidity ^0.4.25; contract ...
Read more >Using the Compiler — Solidity 0.8.17 documentation
The compiler can produce various outputs, ranging from simple binaries and assembly over an abstract syntax tree (parse tree) to estimations of gas...
Read more >Generate Artifact — Remix - Ethereum IDE 1 documentation
Generate Artifact¶. When a compilation for a Solidity file succeeds, Remix creates three JSON files for each compiled contract.
Read more >Remix Documentation - Read the Docs
those compiler outputs — while debugging. These compiler outputs will appear in a separate .yul file in the Remix editor.
Read more >ethereum/remix - Gitter
not sure it helps in your case. but the byteCode that you get from the solc is necessarily different than the deployed bytecode...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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!
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.