Skip to content

Commit

Permalink
fix: do not attempt clique header sender recovery on genesis (#6916)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected committed Mar 1, 2024
1 parent c353b06 commit e7018ca
Showing 1 changed file with 27 additions and 1 deletion.
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);
}
}

0 comments on commit e7018ca

Please sign in to comment.