Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions derivation/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use kona_preimage::PreimageKey;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("DuplicatePreimageKey: key={0:?}")]
UnexpectedDuplicatePreimageKey(PreimageKey),
#[error("InvalidClaim actual={0}, expected={1}")]
InvalidClaim(B256, B256),
#[error("UnexpectedKZGCommitment: err={0:?}")]
Expand Down
23 changes: 22 additions & 1 deletion derivation/src/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ impl TryFrom<Vec<Preimage>> for MemoryOracleClient {
PreimageKeyType::Sha256 => verify_sha256_preimage(&preimage_key, &preimage.data)?,
_ => {}
}
inner.insert(preimage_key, preimage.data);
if inner.insert(preimage_key, preimage.data).is_some() {
return Err(Error::UnexpectedDuplicatePreimageKey(preimage_key));
}
}

// Ensure blob preimage is valid
Expand Down Expand Up @@ -262,6 +264,7 @@ mod test {
use hashbrown::HashSet;
use kona_preimage::{PreimageKey, PreimageKeyType};
use kona_proof::l1::ROOTS_OF_UNITY;
use sha2::{Digest, Sha256};

#[test]
fn test_try_from_key_error() {
Expand All @@ -276,6 +279,24 @@ mod test {
}
}

#[test]
fn test_try_from_duplicate_preimage_error() {
let value = vec![0u8; 10];
let key: [u8; 32] = Sha256::digest(&value).try_into().unwrap();
let preimage = vec![
Preimage::new(
PreimageKey::new(key, PreimageKeyType::Sha256),
value.clone(),
),
Preimage::new(PreimageKey::new(key, PreimageKeyType::Sha256), value),
];
let err = MemoryOracleClient::try_from(preimage).unwrap_err();
match err {
Error::UnexpectedDuplicatePreimageKey(_) => {}
_ => panic!("Unexpected error, got: {:?}", err),
}
}

#[test]
fn test_try_from_sha256_error() {
let preimage = vec![Preimage::new(
Expand Down
Loading