-
Notifications
You must be signed in to change notification settings - Fork 784
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
Implement EIP 2935 #3268
Implement EIP 2935 #3268
Changes from 23 commits
4cbb9c4
2c6b70e
c2d8aa2
4e31fbe
c172e04
2a8a64f
29f2a81
44c0fbb
4427858
afabbec
cf673e0
07b5707
eee0e7f
da2cde6
08cf2ca
63950f0
2066f08
fec979b
516a7be
9c79a10
4ddd63a
f3fca59
f4d96c8
f9ce54c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,12 @@ | |
Account, | ||
Address, | ||
BIGINT_0, | ||
BIGINT_1, | ||
BIGINT_8, | ||
GWEI_TO_WEI, | ||
KECCAK256_RLP, | ||
bigIntToBytes, | ||
bigIntToHex, | ||
bytesToHex, | ||
concatBytes, | ||
equalsBytes, | ||
|
@@ -350,6 +352,13 @@ | |
block.header.timestamp | ||
) | ||
} | ||
if (this.common.isActivatedEIP(2935)) { | ||
if (this.DEBUG) { | ||
debug(`accumulate parentBlockHash `) | ||
} | ||
|
||
await accumulateParentBlockHash.bind(this)(block) | ||
} | ||
|
||
if (enableProfiler) { | ||
// eslint-disable-next-line no-console | ||
|
@@ -407,6 +416,51 @@ | |
return blockResults | ||
} | ||
|
||
/** | ||
* This method runs the logic of EIP 2935 (save blockhashes to state) | ||
* It will put the `parentHash` of the block to the storage slot of `block.number - 1` of the history storage contract. | ||
* This contract is used to retrieve BLOCKHASHes in EVM if EIP 2935 is activated. | ||
* In case that the previous block of `block` is pre-EIP-2935 (so we are on the EIP 2935 fork block), additionally | ||
* also add the currently available past blockhashes which are available by BLOCKHASH (so, the past 256 block hashes) | ||
* @param this The VM to run on | ||
* @param block The current block to save the parent block hash of | ||
*/ | ||
export async function accumulateParentBlockHash(this: VM, block: Block) { | ||
jochem-brouwer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const historyAddress = Address.fromString( | ||
bigIntToHex(this.common.param('vm', 'historyStorageAddress')) | ||
) | ||
|
||
if ((await this.stateManager.getAccount(historyAddress)) === undefined) { | ||
await this.evm.journal.putAccount(historyAddress, new Account()) | ||
} | ||
|
||
async function putBlockHash(vm: VM, hash: Uint8Array, number: bigint) { | ||
const key = setLengthLeft(bigIntToBytes(number), 32) | ||
await vm.stateManager.putContractStorage(historyAddress, key, hash) | ||
} | ||
await putBlockHash(this, block.header.parentHash, block.header.number - BIGINT_1) | ||
|
||
// Check if we are on the fork block | ||
const forkTime = this.common.eipTimestamp(2935) | ||
if (forkTime === null) { | ||
throw new Error('EIP 2935 should be activated by timestamp') | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that we need this extra Also: such a check should likely be at the beginning of the method (?). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added this because I need to detect we are on the first fork block. The reason is that on the first fork block, we have to store all the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, you are right, sorry, please dismiss! 🙂 Should then the whole method get a check at the beginning if 2935 is activated and throw otherwise? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am comparing it with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, maybe do (for both). |
||
const parentBlock = await this.blockchain.getBlock(block.header.parentHash) | ||
|
||
if (parentBlock.header.timestamp < forkTime) { | ||
let ancestor = parentBlock | ||
const range = this.common.param('vm', 'minHistoryServeWindow') | ||
for (let i = 0; i < Number(range) - 1; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would cautiously think that this Since the code from the EIP states (maybe confirm with edge case tests?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is correct (but this is definitely off-by-one error prone! 😄 ) From EIP: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
if (ancestor.header.number === BIGINT_0) { | ||
break | ||
} | ||
|
||
ancestor = await this.blockchain.getBlock(ancestor.header.parentHash) | ||
await putBlockHash(this, ancestor.hash(), ancestor.header.number) | ||
} | ||
} | ||
} | ||
|
||
export async function accumulateParentBeaconBlockRoot( | ||
this: VM, | ||
root: Uint8Array, | ||
|
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.
Can we add some addition like
...state (Verkle related usage, likely not stable yet)
or so?(let me know if the comment does not make sense "as is")
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.
It does, I normally just copy the EIP title but you are right this definitely should get an unstable warning.
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.
👍
Take whatever text you like, just that people know this is not "one of the normal EIPs they can integrate" (and DRAFT status is not that much of a warning, even EIPs close to hardfork often still in DRAFT 😂 ).