Skip to content

Commit 6cbe019

Browse files
authored
Implement display and error for precompile error (#777)
1 parent 821d287 commit 6cbe019

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

crates/primitives/src/precompile.rs

+31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::Env;
22
use alloc::vec::Vec;
3+
use core::fmt;
34

45
/// A precompile operation result.
56
///
@@ -32,3 +33,33 @@ pub enum PrecompileError {
3233
/// The proof verification failed.
3334
BlobVerifyKzgProofFailed,
3435
}
36+
37+
#[cfg(feature = "std")]
38+
impl std::error::Error for PrecompileError {}
39+
40+
impl fmt::Display for PrecompileError {
41+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
42+
match self {
43+
PrecompileError::OutOfGas => write!(f, "out of gas"),
44+
PrecompileError::Blake2WrongLength => write!(f, "wrong input length for blake2"),
45+
PrecompileError::Blake2WrongFinalIndicatorFlag => {
46+
write!(f, "wrong final indicator flag for blake2")
47+
}
48+
PrecompileError::ModexpExpOverflow => write!(f, "modexp exp overflow"),
49+
PrecompileError::ModexpBaseOverflow => write!(f, "modexp base overflow"),
50+
PrecompileError::ModexpModOverflow => write!(f, "modexp mod overflow"),
51+
PrecompileError::Bn128FieldPointNotAMember => {
52+
write!(f, "field point not a member of bn128 curve")
53+
}
54+
PrecompileError::Bn128AffineGFailedToCreate => {
55+
write!(f, "failed to create affine g point for bn128 curve")
56+
}
57+
PrecompileError::Bn128PairLength => write!(f, "bn128 invalid pair length"),
58+
PrecompileError::BlobInvalidInputLength => write!(f, "invalid blob input length"),
59+
PrecompileError::BlobMismatchedVersion => write!(f, "mismatched blob version"),
60+
PrecompileError::BlobVerifyKzgProofFailed => {
61+
write!(f, "verifying blob kzg proof failed")
62+
}
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)