question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

solc gas output different from remix

See original GitHub issue

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.

Screen Shot 2022-06-15 at 11 07 24 AM

The optimizer is enabled with 200 runs in remix.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
PatrickAlphaCcommented, Jul 7, 2022

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!

0reactions
cameelcommented, Jul 7, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found