-
Notifications
You must be signed in to change notification settings - Fork 974
feat: implement EIP-2935 #1354
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
feat: implement EIP-2935 #1354
Changes from 3 commits
8334218
b95dbd3
214706d
379d951
74cea76
7758c8a
37ac22d
9cd780b
59eed4d
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 |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ use crate::{ | |
| Host, InstructionResult, SStoreResult, | ||
| }; | ||
| use core::cmp::min; | ||
| use revm_primitives::BLOCK_HASH_HISTORY; | ||
| use revm_primitives::{BLOCK_HASH_HISTORY, HISTORY_SERVE_WINDOW, HISTORY_STORAGE_ADDRESS}; | ||
| use std::vec::Vec; | ||
|
|
||
| pub fn balance<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) { | ||
|
|
@@ -103,14 +103,28 @@ pub fn extcodecopy<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, | |
| .set_data(memory_offset, code_offset, len, &code.original_bytes()); | ||
| } | ||
|
|
||
| pub fn blockhash<H: Host + ?Sized>(interpreter: &mut Interpreter, host: &mut H) { | ||
| pub fn blockhash<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) { | ||
| gas!(interpreter, gas::BLOCKHASH); | ||
| pop_top!(interpreter, number); | ||
|
|
||
| if let Some(diff) = host.env().block.number.checked_sub(*number) { | ||
| let block_number = host.env().block.number; | ||
|
|
||
| if let Some(diff) = block_number.checked_sub(*number) { | ||
| let diff = as_usize_saturated!(diff); | ||
|
|
||
| // blockhash should push zero if number is same as current block number. | ||
| if diff <= BLOCK_HASH_HISTORY && diff != 0 { | ||
| if SPEC::enabled(PRAGUE) && diff <= HISTORY_SERVE_WINDOW && diff != 0 { | ||
| let Some((value, is_cold)) = host.sload( | ||
| HISTORY_STORAGE_ADDRESS, | ||
| number.wrapping_rem(U256::from(HISTORY_SERVE_WINDOW)), | ||
| ) else { | ||
| interpreter.instruction_result = InstructionResult::FatalExternalError; | ||
| return; | ||
| }; | ||
| gas!(interpreter, gas::sload_cost(SPEC::SPEC_ID, is_cold)); | ||
|
||
| *number = value; | ||
| return; | ||
| } else if diff <= BLOCK_HASH_HISTORY && diff != 0 { | ||
| let Some(hash) = host.block_hash(*number) else { | ||
| interpreter.instruction_result = InstructionResult::FatalExternalError; | ||
| return; | ||
|
|
@@ -119,6 +133,7 @@ pub fn blockhash<H: Host + ?Sized>(interpreter: &mut Interpreter, host: &mut H) | |
| return; | ||
| } | ||
| } | ||
|
|
||
| *number = U256::ZERO; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.