Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evm t8n calculate difficulty #23249

Closed
winsvega opened this issue Jul 22, 2021 · 2 comments · Fixed by #23353
Closed

evm t8n calculate difficulty #23249

winsvega opened this issue Jul 22, 2021 · 2 comments · Fixed by #23353

Comments

@winsvega
Copy link
Contributor

The current env format is

{
   "currentCoinbase" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
   "currentDifficulty" : "0x020000",
   "currentGasLimit" : "0x05f5e100",
   "currentNumber" : "0x01",
   "currentTimestamp" : "0x03e8",
   "previousHash" : "0xe729de3fec21e30bea3d56adb01ed14bc107273c2775f9355afb10f594a10d9e",
   "blockHashes" : {
       "0" : "0xe729de3fec21e30bea3d56adb01ed14bc107273c2775f9355afb10f594a10d9e"
   }
}

want to extend the following format to be acceptable (as well as the old one)

{
   "currentCoinbase" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
   "parentDifficulty" : "0x020000",
   "currentGasLimit" : "0x05f5e100",
   "currentNumber" : "0x01",
   "parentTimestamp" : "0x03e7",
   "currentTimestamp" : "0x03e8",
   "previousHash" : "0xe729de3fec21e30bea3d56adb01ed14bc107273c2775f9355afb10f594a10d9e",
   "blockHashes" : {
       "0" : "0xe729de3fec21e30bea3d56adb01ed14bc107273c2775f9355afb10f594a10d9e"
   }
}

new fields: parentDifficulty instead of currentDifficulty
and parentTimestamp

the result file then

{
  "currentDifficulty" : "0x020001"
  "stateRoot": "0x1c99b01120e7a2fa1301b3505f20100e72362e5ac3f96854420e56ba8984d716",
  "txRoot": "0xb5eee60b45801179cbde3781b9a5dee9b3111554618c9cda3d6f7e351fd41e0b",
  "receiptRoot": "0x86ceb80cb6bef8fe4ac0f1c99409f67cb2554c4432f374e399b94884eb3e6562",
  "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "receipts": [
  ]
}

would report the new difficulty calculated with geth formula currentDifficulty

Rationale
To avoid point of failure when generating the tests. Currently retesteth calculates the difficulty, but retesteth difficulty formula might be wrong. Since we test the clients, it would make sense that retesteth asks t8ntool what geth evm thinks would be the new difficulty given parentTimestamp and parentDifficulty and currentTimestamp.

@holiman
Copy link
Contributor

holiman commented Aug 8, 2021

SGTM. So just to clarify even further, I'd propose:

  1. The currentDifficulty can be given as input. If so, goto 4, If not, then
  2. Verify parentDifficulty, parentTimestamp and currentTimestamp are present (otherwise fail), and
  3. Calculate the currentDifficulty.
  4. Continue the execution

And lastly, the output env always provides the currentDifficulty, regardless of whether it was given or calculated.

@holiman
Copy link
Contributor

holiman commented Aug 8, 2021

Actually, there's one snag; the parent may or may not have uncles. And whether the parent has uncles, affects the difficulty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants