Skip to content

Commit

Permalink
Implement display and error for precompile error (#777)
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Oct 6, 2023
1 parent 821d287 commit 6cbe019
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions crates/primitives/src/precompile.rs
@@ -1,5 +1,6 @@
use crate::Env;
use alloc::vec::Vec;
use core::fmt;

/// A precompile operation result.
///
Expand Down Expand Up @@ -32,3 +33,33 @@ pub enum PrecompileError {
/// The proof verification failed.
BlobVerifyKzgProofFailed,
}

#[cfg(feature = "std")]
impl std::error::Error for PrecompileError {}

impl fmt::Display for PrecompileError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
PrecompileError::OutOfGas => write!(f, "out of gas"),
PrecompileError::Blake2WrongLength => write!(f, "wrong input length for blake2"),
PrecompileError::Blake2WrongFinalIndicatorFlag => {
write!(f, "wrong final indicator flag for blake2")
}
PrecompileError::ModexpExpOverflow => write!(f, "modexp exp overflow"),
PrecompileError::ModexpBaseOverflow => write!(f, "modexp base overflow"),
PrecompileError::ModexpModOverflow => write!(f, "modexp mod overflow"),
PrecompileError::Bn128FieldPointNotAMember => {
write!(f, "field point not a member of bn128 curve")
}
PrecompileError::Bn128AffineGFailedToCreate => {
write!(f, "failed to create affine g point for bn128 curve")
}
PrecompileError::Bn128PairLength => write!(f, "bn128 invalid pair length"),
PrecompileError::BlobInvalidInputLength => write!(f, "invalid blob input length"),
PrecompileError::BlobMismatchedVersion => write!(f, "mismatched blob version"),
PrecompileError::BlobVerifyKzgProofFailed => {
write!(f, "verifying blob kzg proof failed")
}
}
}
}

0 comments on commit 6cbe019

Please sign in to comment.