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

chore(primitives): Precompile Error Display + Error Trait Implementations #777

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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