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

fix: do not attempt clique header sender recovery on genesis #6916

Merged
merged 1 commit into from Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 27 additions & 1 deletion crates/primitives/src/revm/env.rs
Expand Up @@ -49,7 +49,18 @@ pub fn fill_block_env_with_coinbase(

/// Return the coinbase address for the given header and chain spec.
pub fn block_coinbase(chain_spec: &ChainSpec, header: &Header, after_merge: bool) -> Address {
if chain_spec.chain == Chain::goerli() && !after_merge {
// Clique consensus fills the EXTRA_SEAL (last 65 bytes) of the extra data with the
// signer's signature.
//
// On the genesis block, the extra data is filled with zeros, so we should not attempt to
// recover the signer on the genesis block.
//
// From EIP-225:
//
// * `EXTRA_SEAL`: Fixed number of extra-data suffix bytes reserved for signer seal.
// * 65 bytes fixed as signatures are based on the standard `secp256k1` curve.
// * Filled with zeros on genesis block.
if chain_spec.chain == Chain::goerli() && !after_merge && header.number > 0 {
recover_header_signer(header).unwrap_or_else(|err| {
panic!(
"Failed to recover goerli Clique Consensus signer from header ({}, {}) using extradata {}: {:?}",
Expand Down Expand Up @@ -324,3 +335,18 @@ pub fn fill_op_tx_env<T: AsRef<Transaction>>(
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::GOERLI;

#[test]
fn test_recover_genesis_goerli_signer() {
// just ensures that `block_coinbase` does not panic on the genesis block
let chain_spec = GOERLI.clone();
let header = chain_spec.genesis_header();
let block_coinbase = block_coinbase(&chain_spec, &header, false);
assert_eq!(block_coinbase, header.beneficiary);
}
}