This repository was archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 684
feat: add support for the merge hardfork
#3658
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.11; | ||
|
|
||
| contract Merge { | ||
| uint256 public difficulty; | ||
|
|
||
| constructor() { | ||
| require(block.difficulty > 1); | ||
| difficulty = block.difficulty; | ||
| } | ||
|
|
||
| function getCurrentDifficulty() public view returns (uint256) { | ||
| require(block.difficulty > 1); | ||
| return uint256(block.difficulty); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import assert from "assert"; | ||
| import { join } from "path"; | ||
| import { EthereumProvider } from "../src/provider"; | ||
| import compile from "./helpers/compile"; | ||
| import getProvider from "./helpers/getProvider"; | ||
|
|
||
| describe("merge", () => { | ||
| let provider: EthereumProvider; | ||
| let accounts: string[]; | ||
| beforeEach("get provider", async () => { | ||
| provider = await getProvider({ | ||
| wallet: { seed: "temet nosce" }, | ||
| chain: { hardfork: "merge" } | ||
| }); | ||
| accounts = await provider.send("eth_accounts"); | ||
| }); | ||
| describe("safe", () => { | ||
| it("returns the safe block", async () => { | ||
| const safe = await provider.send("eth_getBlockByNumber", ["safe", true]); | ||
| const latest = await provider.send("eth_getBlockByNumber", [ | ||
| "latest", | ||
| true | ||
| ]); | ||
| assert.deepStrictEqual(safe, latest); | ||
| }); | ||
| }); | ||
| describe("finalized", () => { | ||
| it("returns the finalized block", async () => { | ||
| const finalized = await provider.send("eth_getBlockByNumber", [ | ||
| "finalized", | ||
| true | ||
| ]); | ||
| const latest = await provider.send("eth_getBlockByNumber", [ | ||
| "latest", | ||
| true | ||
| ]); | ||
| assert.deepStrictEqual(finalized, latest); | ||
| }); | ||
| }); | ||
|
|
||
| describe("difficulty", () => { | ||
| let contract: ReturnType<typeof compile>; | ||
| let contractAddress: string; | ||
| beforeEach("deploy contract", async () => { | ||
| contract = compile(join(__dirname, "./contracts/Merge.sol")); | ||
| const transaction = { | ||
| from: accounts[0], | ||
| data: contract.code, | ||
| gasLimit: "0x2fefd8" | ||
| }; | ||
| const txHash = await provider.send("eth_sendTransaction", [transaction]); | ||
| const receipt = await provider.send("eth_getTransactionReceipt", [ | ||
| txHash | ||
| ]); | ||
| contractAddress = receipt.contractAddress; | ||
| }); | ||
| it("uses the block's mixhash value as the PREVRANDAO opcode", async () => { | ||
| const block = await provider.send("eth_getBlockByNumber", [ | ||
| "latest", | ||
| false | ||
| ]); | ||
| assert.strictEqual(block.difficulty, "0x0"); | ||
|
|
||
| const constructorResult = await provider.send("eth_call", [ | ||
| { | ||
| from: accounts[0], | ||
| to: contractAddress, | ||
| data: `0x${contract.contract.evm.methodIdentifiers["difficulty()"]}` | ||
| }, | ||
| block.number | ||
| ]); | ||
|
|
||
| const txHash = await provider.send("eth_sendTransaction", [ | ||
| { | ||
| from: accounts[0], | ||
| to: contractAddress, | ||
| gasLimit: "0x2fefd8", | ||
| data: `0x${contract.contract.evm.methodIdentifiers["getCurrentDifficulty()"]}` | ||
| } | ||
| ]); | ||
| const receipt = await provider.send("eth_getTransactionReceipt", [ | ||
| txHash | ||
| ]); | ||
| // make sure it didn't revert, which is will do if `difficulty` is not > `1` | ||
| assert.strictEqual(receipt.status, "0x1"); | ||
|
|
||
| const viewResult1 = await provider.send("eth_call", [ | ||
| { | ||
| from: accounts[0], | ||
| to: contractAddress, | ||
| data: `0x${contract.contract.evm.methodIdentifiers["getCurrentDifficulty()"]}` | ||
| }, | ||
| block.number | ||
| ]); | ||
|
|
||
| // it shouldn't be all 0s for the merge: | ||
| assert.notStrictEqual( | ||
| block.mixHash, | ||
| "0x0000000000000000000000000000000000000000000000000000000000000000" | ||
| ); | ||
|
|
||
| // the results should match | ||
| assert.strictEqual(constructorResult, block.mixHash); | ||
| assert.strictEqual(viewResult1, block.mixHash); | ||
|
|
||
| const lastblock = await provider.send("eth_getBlockByNumber", [ | ||
| receipt.blockNumber, | ||
| false | ||
| ]); | ||
| assert.strictEqual(lastblock.difficulty, "0x0"); | ||
| const viewResult2 = await provider.send("eth_call", [ | ||
| { | ||
| from: accounts[0], | ||
| to: contractAddress, | ||
| data: `0x${contract.contract.evm.methodIdentifiers["getCurrentDifficulty()"]}` | ||
| }, | ||
| "latest" | ||
| ]); | ||
| // it changed | ||
| assert.notStrictEqual(viewResult1, viewResult2); | ||
| assert.strictEqual(viewResult2, lastblock.mixHash); | ||
| }).timeout(0); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For later when we clean up tech debt: does this make sense to define here? This flag is used all throughout the file, so it seems like it would make sense at the top.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably a good idea to move it up in the file, yeah.