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.

`eth_estimateGas` does not use blockchain's `adjustedTime`

See original GitHub issue

In the blockchain, when a block is being prepared to be mined, the timestamp is adjusted by the chain’s internal offset:

if (timestamp == null) {
    timestamp = this.#adjustedTime(previousHeader.timestamp);
  }

  return new RuntimeBlock(
    Quantity.from(previousNumber + 1n),
    previousBlock.hash(),
    this.coinbase,
    minerOptions.blockGasLimit.toBuffer(),
    BUFFER_ZERO,
    Quantity.from(timestamp),
    minerOptions.difficulty,
    previousHeader.totalDifficulty,
    Block.calcNextBaseFee(previousBlock)
  );

However, eth_estimateGas just uses the parent block’s timestamp:

const block = new RuntimeBlock(
  Quantity.from((parentHeader.number.toBigInt() || 0n) + 1n),
  parentHeader.parentHash,
  parentHeader.miner,
  tx.gas.toBuffer(),
  parentHeader.gasUsed.toBuffer(),
  parentHeader.timestamp,
  options.miner.difficulty,
  parentHeader.totalDifficulty,
  0n // no baseFeePerGas for estimates
);

This is particularly annoying if you are using Truffle to test a contract that is time dependent because truffle calls an eth_estimateGas before sending your actual transaction. If you use evm_setTime to the time needed for your contract to do what it needs to do, the actual transaction would pass, but Truffle doesn’t let you get that far because the eth_estimateGas fails beforehand.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
jeffsmale90commented, Aug 14, 2022

Also related to: #3425 ?

0reactions
MicaiahReidcommented, Aug 12, 2022

Oh duh. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Truth About Blockchain - Harvard Business Review
The technology behind bitcoin, blockchain is an open, distributed ledger that ... We can't predict exactly how many years the transformation will take, ......
Read more >
Blockchain Facts: What Is It, How It Works, and How It Can Be ...
A blockchain is a digitally distributed, decentralized, public ledger that exists across a network. It is most noteworthy in its use with cryptocurrencies ......
Read more >
A Blockchain Platform for User Data Sharing Ensuring User ...
We propose a new platform for user modeling with blockchains that allows users to share data without losing control and ownership of it...
Read more >
How secure is blockchain really? - MIT Technology Review
The whole point of using a blockchain is to let people—in particular, people who don't trust one another—share valuable data in a secure, ......
Read more >
The Privacy Questions Raised by Blockchain | Insights & Events
This article seeks to establish a framework for understanding the privacy and security challenges so that the industry can address them, cut ...
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