-
Notifications
You must be signed in to change notification settings - Fork 551
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(revm): revert EIP-2935 BLOCKHASH opcode changes #1450
Conversation
Valgrind Results:
|
.ok(); | ||
} | ||
|
||
if self.evm.journaled_state.spec.is_enabled_in(PRAGUE) && diff <= BLOCKHASH_SERVE_WINDOW { |
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.
only this PRAGUE branch should be removed, the rest is still valid (diff == 0, diff <= HISTORY...)
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.
are you sure? from the EIP:
The
BLOCKHASH
opcode semantics remains the same as before.
revm/crates/revm/src/context.rs
Lines 108 to 113 in eed27d9
fn block_hash(&mut self, number: U256) -> Option<B256> { | |
self.evm | |
.block_hash(number) | |
.map_err(|e| self.evm.error = Err(e)) | |
.ok() | |
} |
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.
Yes, this is the before:
revm/crates/interpreter/src/instructions/host.rs
Lines 106 to 123 in 688c36c
pub fn blockhash<H: Host + ?Sized>(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 diff = as_usize_saturated!(diff); | |
// blockhash should push zero if number is same as current block number. | |
if diff <= BLOCK_HASH_HISTORY && diff != 0 { | |
let Some(hash) = host.block_hash(*number) else { | |
interpreter.instruction_result = InstructionResult::FatalExternalError; | |
return; | |
}; | |
*number = U256::from_be_bytes(hash.0); | |
return; | |
} | |
} | |
*number = U256::ZERO; | |
} |
This implementation was moved from the blockhash instruction to the host implementation in #1427, and was refactored in #1430
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.
oh, my bad, fixing
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.
Logic can stay inside EvmContext, previously it was inside instruction.
This is old logic before EIP-2935:
revm/crates/interpreter/src/instructions/host.rs
Lines 127 to 139 in 1640b8f
if let Some(diff) = host.env().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 { | |
let Some(hash) = host.block_hash(*number) else { | |
interpreter.instruction_result = InstructionResult::FatalExternalError; | |
return; | |
}; | |
*number = U256::from_be_bytes(hash.0); | |
return; | |
} | |
} | |
*number = U256::ZERO; |
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.
lgtm, clippy pending
As per ethereum/EIPs#8577
Change explanation: #1450 (comment)