Skip to content

Commit

Permalink
feat(precompile): Add precompile key type
Browse files Browse the repository at this point in the history
Adds the new global precompile preimage key type, as described in [the
spec](https://specs.optimism.io/experimental/fault-proof/index.html#type-6-global-precompile-key)
  • Loading branch information
clabby committed May 23, 2024
1 parent 0e63a92 commit 3762a51
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion crates/preimage/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ pub enum PreimageKeyType {
/// `keccak256(commitment ++ z)`, and then the high-order byte of the digest is set to the
/// type byte.
Blob = 5,
/// Precompile key types are global and context independent. Precompile keys are constructed as
/// `keccak256(precompile_addr ++ input)`, and then the high-order byte of the digest is set to
/// the type byte.
Precompile = 6,
}

impl TryFrom<u8> for PreimageKeyType {
Expand All @@ -35,6 +39,7 @@ impl TryFrom<u8> for PreimageKeyType {
3 => PreimageKeyType::GlobalGeneric,
4 => PreimageKeyType::Sha256,
5 => PreimageKeyType::Blob,
6 => PreimageKeyType::Precompile,
_ => anyhow::bail!("Invalid preimage key type"),
})
}
Expand Down Expand Up @@ -108,7 +113,14 @@ mod test {

#[test]
fn test_preimage_keys() {
let types = [PreimageKeyType::Local, PreimageKeyType::Keccak256];
let types = [
PreimageKeyType::Local,
PreimageKeyType::Keccak256,
PreimageKeyType::GlobalGeneric,
PreimageKeyType::Sha256,
PreimageKeyType::Blob,
PreimageKeyType::Precompile,
];

for key_type in types {
let key = PreimageKey::new([0xFFu8; 32], key_type);
Expand Down

0 comments on commit 3762a51

Please sign in to comment.