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

feat(revm): revert EIP-2935 BLOCKHASH opcode changes #1450

Merged
merged 5 commits into from
May 24, 2024

Conversation

shekhirin
Copy link
Collaborator

@shekhirin shekhirin commented May 24, 2024

As per ethereum/EIPs#8577

Change explanation: #1450 (comment)

@shekhirin shekhirin added feature New feature or lib ability hf-prague Prague related EIPs labels May 24, 2024
Copy link
Contributor

github-actions bot commented May 24, 2024

Valgrind Results:

==3762== Cachegrind, a cache and branch-prediction profiler
==3762== Copyright (C) 2002-2017, and GNU GPL'd, by Nicholas Nethercote et al.
==3762== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==3762== Command: target/release/snailtracer
==3762== 
--3762-- warning: L3 cache found, using its data for the LL simulation.
Running snailtracer example!
elapsed: 1.827643523s
==3762== 
==3762== I   refs:      429,371,833
==3762== I1  misses:          3,118
==3762== LLi misses:          2,801
==3762== I1  miss rate:        0.00%
==3762== LLi miss rate:        0.00%
==3762== 
==3762== D   refs:      206,205,188  (133,650,687 rd   + 72,554,501 wr)
==3762== D1  misses:        344,946  (    204,870 rd   +    140,076 wr)
==3762== LLd misses:        137,605  (      4,255 rd   +    133,350 wr)
==3762== D1  miss rate:         0.2% (        0.2%     +        0.2%  )
==3762== LLd miss rate:         0.1% (        0.0%     +        0.2%  )
==3762== 
==3762== LL refs:           348,064  (    207,988 rd   +    140,076 wr)
==3762== LL misses:         140,406  (      7,056 rd   +    133,350 wr)
==3762== LL miss rate:          0.0% (        0.0%     +        0.2%  )

.ok();
}

if self.evm.journaled_state.spec.is_enabled_in(PRAGUE) && diff <= BLOCKHASH_SERVE_WINDOW {
Copy link
Collaborator

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...)

Copy link
Collaborator Author

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.

fn block_hash(&mut self, number: U256) -> Option<B256> {
self.evm
.block_hash(number)
.map_err(|e| self.evm.error = Err(e))
.ok()
}

Copy link
Collaborator

@DaniPopes DaniPopes May 24, 2024

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:

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, my bad, fixing

Copy link
Member

@rakita rakita left a 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:

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;

Copy link
Member

@rakita rakita left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, clippy pending

@rakita rakita marked this pull request as ready for review May 24, 2024 15:52
@rakita rakita merged commit 8b6ab31 into main May 24, 2024
25 checks passed
@github-actions github-actions bot mentioned this pull request May 24, 2024
@rakita rakita deleted the alexey/revert-eip-2935-changes branch June 1, 2024 12:54
This was referenced Jun 3, 2024
This was referenced Jun 11, 2024
@github-actions github-actions bot mentioned this pull request Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or lib ability hf-prague Prague related EIPs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants