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(precompile): Add precompile key type #179

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading