Skip to content

Commit f3b0097

Browse files
committed
fix: add missing #[source]/#[from] to error variants wrapping inner errors
Group A — replace trivial manual `From` impls with `#[from]`: - `SynthesisError::IoError`: add `#[from]`, delete manual `From<std::io::Error>` impl - `AHPError::ConstraintSystemError`: add `#[from]`, delete manual `From<SynthesisError>` impl - `GroupError::FieldError`: add `#[from]`, delete manual `From<FieldError>` impl Group B — add `#[source]` to named-field variants in `CheckBlockError`: - `InvalidPrefix`: add `#[source]` on `error` field, fix typo ("as" → "has"), remove `{error:?}` interpolation - `SpeculationFailed`: add `#[source]` on `inner`, remove `{inner}` interpolation - `VerificationFailed`: add `#[source]` on `inner`, remove `{inner}` interpolation Format strings no longer interpolate `#[source]` fields, avoiding the duplication bug fixed in the prior commit. The inner errors remain accessible via `Error::source()`, enabling proper error chain traversal.
1 parent 43a88c8 commit f3b0097

4 files changed

Lines changed: 17 additions & 29 deletions

File tree

algorithms/src/r1cs/errors.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,12 @@ pub enum SynthesisError {
4040
#[error("Encountered an identity element in the CRS")]
4141
UnexpectedIdentity,
4242
/// During proof generation, we encountered an I/O error with the CRS
43-
#[error("Encountered an I/O error")]
44-
IoError(std::io::Error),
43+
#[error("I/O error")]
44+
IoError(#[from] std::io::Error),
4545
/// During verification, our verifying key was malformed.
4646
#[error("Malformed verifying key, public input count was {} but expected {}", _0, _1)]
4747
MalformedVerifyingKey(usize, usize),
4848
/// During CRS generation, we observed an unconstrained auxiliary variable
4949
#[error("Auxiliary variable was unconstrained")]
5050
UnconstrainedVariable,
5151
}
52-
53-
impl From<std::io::Error> for SynthesisError {
54-
fn from(e: std::io::Error) -> SynthesisError {
55-
SynthesisError::IoError(e)
56-
}
57-
}

algorithms/src/snark/varuna/ahp/errors.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ pub enum AHPError {
2222
#[error("Batch size was zero; must be at least 1.")]
2323
BatchSizeIsZero,
2424

25-
#[error("An error occurred during constraint generation.")]
26-
ConstraintSystemError(crate::r1cs::errors::SynthesisError),
25+
#[error("constraint generation error")]
26+
ConstraintSystemError(#[from] crate::r1cs::errors::SynthesisError),
2727

2828
#[error("The instance generated during proving does not match that in the index.")]
2929
InstanceDoesNotMatchIndex,
@@ -40,9 +40,3 @@ pub enum AHPError {
4040
#[error("During synthesis, our polynomials ended up being too high of degree.")]
4141
PolyTooLarge,
4242
}
43-
44-
impl From<crate::r1cs::errors::SynthesisError> for AHPError {
45-
fn from(other: crate::r1cs::errors::SynthesisError) -> Self {
46-
AHPError::ConstraintSystemError(other)
47-
}
48-
}

curves/src/errors.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ pub enum GroupError {
1818
#[error("{}: {}", _0, _1)]
1919
Crate(&'static str, String),
2020

21-
#[error("{}", _0)]
22-
FieldError(snarkvm_fields::FieldError),
21+
#[error("field error")]
22+
FieldError(#[from] snarkvm_fields::FieldError),
2323

2424
#[error("Invalid group element")]
2525
InvalidGroupElement,
@@ -37,12 +37,6 @@ pub enum GroupError {
3737
ParsingNonDigitCharacter,
3838
}
3939

40-
impl From<snarkvm_fields::FieldError> for GroupError {
41-
fn from(error: snarkvm_fields::FieldError) -> Self {
42-
GroupError::FieldError(error)
43-
}
44-
}
45-
4640
impl From<std::io::Error> for GroupError {
4741
fn from(error: std::io::Error) -> Self {
4842
GroupError::Crate("std::io", format!("{error:?}"))

ledger/src/check_next_block.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,20 @@ pub enum CheckBlockError<N: Network> {
5454
#[error("Block has invalid hash")]
5555
InvalidHash,
5656
/// An error related to the given prefix of pending blocks.
57-
#[error("The prefix as an error at index {index} - {error:?}")]
57+
#[error("The prefix has an error at index {index}")]
5858
InvalidPrefix { index: usize, error: Box<CheckBlockError<N>> },
5959
#[error("The block contains solution '{solution_id}', but it already exists in the ledger")]
6060
SolutionAlreadyExists { solution_id: SolutionID<N> },
61-
#[error("Failed to speculate over unconfirmed transactions - {inner}")]
62-
SpeculationFailed { inner: anyhow::Error },
63-
#[error("Failed to verify block - {inner}")]
64-
VerificationFailed { inner: anyhow::Error },
61+
#[error("Failed to speculate over unconfirmed transactions")]
62+
SpeculationFailed {
63+
#[source]
64+
inner: anyhow::Error,
65+
},
66+
#[error("Failed to verify block")]
67+
VerificationFailed {
68+
#[source]
69+
inner: anyhow::Error,
70+
},
6571
#[error("Prover '{prover_address}' has reached their solution limit for the current epoch")]
6672
SolutionLimitReached { prover_address: Address<N> },
6773
#[error("The previous block should contain solution '{solution_id}', but it does not exist in the ledger")]

0 commit comments

Comments
 (0)