Skip to content

Commit

Permalink
feat(precompile): add Prague hardfork specification (bluealloy#1387)
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin authored May 8, 2024
1 parent 5404a6a commit ab54cd5
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions crates/precompile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ impl Precompiles {
PrecompileSpecId::ISTANBUL => Self::istanbul(),
PrecompileSpecId::BERLIN => Self::berlin(),
PrecompileSpecId::CANCUN => Self::cancun(),
PrecompileSpecId::PRAGUE => Self::prague(),
PrecompileSpecId::LATEST => Self::latest(),
}
}
Expand Down Expand Up @@ -154,9 +155,21 @@ impl Precompiles {
})
}

/// Returns precompiles for Prague spec.
pub fn prague() -> &'static Self {
static INSTANCE: OnceBox<Precompiles> = OnceBox::new();
INSTANCE.get_or_init(|| {
let precompiles = Self::cancun().clone();
// EIP-2537: Precompile for BLS12-381 curve operations
// TODO(alexey): add BLS12-381 precompiles
// precompiles.extend(bls12_381::precompiles());
Box::new(precompiles)
})
}

/// Returns the precompiles for the latest spec.
pub fn latest() -> &'static Self {
Self::cancun()
Self::prague()
}

/// Returns an iterator over the precompiles addresses.
Expand Down Expand Up @@ -229,6 +242,7 @@ pub enum PrecompileSpecId {
ISTANBUL,
BERLIN,
CANCUN,
PRAGUE,
LATEST,
}

Expand All @@ -243,7 +257,8 @@ impl PrecompileSpecId {
BYZANTIUM | CONSTANTINOPLE | PETERSBURG => Self::BYZANTIUM,
ISTANBUL | MUIR_GLACIER => Self::ISTANBUL,
BERLIN | LONDON | ARROW_GLACIER | GRAY_GLACIER | MERGE | SHANGHAI => Self::BERLIN,
CANCUN | PRAGUE => Self::CANCUN,
CANCUN => Self::CANCUN,
PRAGUE => Self::PRAGUE,
LATEST => Self::LATEST,
#[cfg(feature = "optimism")]
BEDROCK | REGOLITH | CANYON => Self::BERLIN,
Expand Down

0 comments on commit ab54cd5

Please sign in to comment.