mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Correct derives on errors
This commit is contained in:
@@ -33,10 +33,10 @@ lazy_static! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Errors returned when CLSAG signing fails.
|
/// Errors returned when CLSAG signing fails.
|
||||||
#[derive(Clone, Error, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Error)]
|
||||||
pub enum ClsagError {
|
pub enum ClsagError {
|
||||||
#[error("internal error ({0})")]
|
#[error("internal error ({0})")]
|
||||||
InternalError(String),
|
InternalError(&'static str),
|
||||||
#[error("invalid ring")]
|
#[error("invalid ring")]
|
||||||
InvalidRing,
|
InvalidRing,
|
||||||
#[error("invalid ring member (member {0}, ring size {1})")]
|
#[error("invalid ring member (member {0}, ring size {1})")]
|
||||||
@@ -66,7 +66,7 @@ impl ClsagInput {
|
|||||||
pub fn new(commitment: Commitment, decoys: Decoys) -> Result<ClsagInput, ClsagError> {
|
pub fn new(commitment: Commitment, decoys: Decoys) -> Result<ClsagInput, ClsagError> {
|
||||||
let n = decoys.len();
|
let n = decoys.len();
|
||||||
if n > u8::MAX.into() {
|
if n > u8::MAX.into() {
|
||||||
Err(ClsagError::InternalError("max ring size in this library is u8 max".to_string()))?;
|
Err(ClsagError::InternalError("max ring size in this library is u8 max"))?;
|
||||||
}
|
}
|
||||||
let n = u8::try_from(n).unwrap();
|
let n = u8::try_from(n).unwrap();
|
||||||
if decoys.i >= n {
|
if decoys.i >= n {
|
||||||
|
|||||||
@@ -38,10 +38,10 @@ struct TransactionsResponse {
|
|||||||
txs: Vec<TransactionResponse>,
|
txs: Vec<TransactionResponse>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Error, Debug)]
|
#[derive(Clone, PartialEq, Eq, Debug, Error)]
|
||||||
pub enum RpcError {
|
pub enum RpcError {
|
||||||
#[error("internal error ({0})")]
|
#[error("internal error ({0})")]
|
||||||
InternalError(String),
|
InternalError(&'static str),
|
||||||
#[error("connection error")]
|
#[error("connection error")]
|
||||||
ConnectionError,
|
ConnectionError,
|
||||||
#[error("invalid node")]
|
#[error("invalid node")]
|
||||||
@@ -184,10 +184,10 @@ impl Rpc {
|
|||||||
|
|
||||||
Ok(if !method.ends_with(".bin") {
|
Ok(if !method.ends_with(".bin") {
|
||||||
serde_json::from_str(&res.text().await.map_err(|_| RpcError::ConnectionError)?)
|
serde_json::from_str(&res.text().await.map_err(|_| RpcError::ConnectionError)?)
|
||||||
.map_err(|_| RpcError::InternalError("Failed to parse JSON response".to_string()))?
|
.map_err(|_| RpcError::InternalError("Failed to parse JSON response"))?
|
||||||
} else {
|
} else {
|
||||||
monero_epee_bin_serde::from_bytes(&res.bytes().await.map_err(|_| RpcError::ConnectionError)?)
|
monero_epee_bin_serde::from_bytes(&res.bytes().await.map_err(|_| RpcError::ConnectionError)?)
|
||||||
.map_err(|_| RpcError::InternalError("Failed to parse binary response".to_string()))?
|
.map_err(|_| RpcError::InternalError("Failed to parse binary response"))?
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ impl<B: AddressBytes> Zeroize for AddressMeta<B> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Error when decoding an address.
|
/// Error when decoding an address.
|
||||||
#[derive(Clone, Error, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Error)]
|
||||||
pub enum AddressError {
|
pub enum AddressError {
|
||||||
#[error("invalid address byte")]
|
#[error("invalid address byte")]
|
||||||
InvalidByte,
|
InvalidByte,
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ async fn select_n<R: RngCore + CryptoRng>(
|
|||||||
iters += 1;
|
iters += 1;
|
||||||
// This is cheap and on fresh chains, thousands of rounds may be needed
|
// This is cheap and on fresh chains, thousands of rounds may be needed
|
||||||
if iters == 10000 {
|
if iters == 10000 {
|
||||||
Err(RpcError::InternalError("not enough decoy candidates".to_string()))?;
|
Err(RpcError::InternalError("not enough decoy candidates"))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use a gamma distribution
|
// Use a gamma distribution
|
||||||
@@ -178,7 +178,7 @@ impl Decoys {
|
|||||||
|
|
||||||
// TODO: Simply create a TX with less than the target amount
|
// TODO: Simply create a TX with less than the target amount
|
||||||
if (high - MATURITY) < u64::try_from(inputs.len() * ring_len).unwrap() {
|
if (high - MATURITY) < u64::try_from(inputs.len() * ring_len).unwrap() {
|
||||||
Err(RpcError::InternalError("not enough decoy candidates".to_string()))?;
|
Err(RpcError::InternalError("not enough decoy candidates"))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select all decoys for this transaction, assuming we generate a sane transaction
|
// Select all decoys for this transaction, assuming we generate a sane transaction
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ impl SendOutput {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Error, Debug)]
|
#[derive(Clone, PartialEq, Eq, Debug, Error)]
|
||||||
pub enum TransactionError {
|
pub enum TransactionError {
|
||||||
#[error("multiple addresses with payment IDs")]
|
#[error("multiple addresses with payment IDs")]
|
||||||
MultiplePaymentIds,
|
MultiplePaymentIds,
|
||||||
|
|||||||
@@ -33,6 +33,34 @@ pub mod promote;
|
|||||||
#[cfg(any(test, feature = "tests"))]
|
#[cfg(any(test, feature = "tests"))]
|
||||||
pub mod tests;
|
pub mod tests;
|
||||||
|
|
||||||
|
/// Various errors possible during key generation/signing.
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Error)]
|
||||||
|
pub enum DkgError {
|
||||||
|
#[error("a parameter was 0 (required {0}, participants {1})")]
|
||||||
|
ZeroParameter(u16, u16),
|
||||||
|
#[error("invalid amount of required participants (max {1}, got {0})")]
|
||||||
|
InvalidRequiredQuantity(u16, u16),
|
||||||
|
#[error("invalid participant index (0 < index <= {0}, yet index is {1})")]
|
||||||
|
InvalidParticipantIndex(u16, u16),
|
||||||
|
|
||||||
|
#[error("invalid signing set")]
|
||||||
|
InvalidSigningSet,
|
||||||
|
#[error("invalid participant quantity (expected {0}, got {1})")]
|
||||||
|
InvalidParticipantQuantity(usize, usize),
|
||||||
|
#[error("duplicated participant index ({0})")]
|
||||||
|
DuplicatedIndex(u16),
|
||||||
|
#[error("missing participant {0}")]
|
||||||
|
MissingParticipant(u16),
|
||||||
|
|
||||||
|
#[error("invalid proof of knowledge (participant {0})")]
|
||||||
|
InvalidProofOfKnowledge(u16),
|
||||||
|
#[error("invalid share (participant {0})")]
|
||||||
|
InvalidShare(u16),
|
||||||
|
|
||||||
|
#[error("internal error ({0})")]
|
||||||
|
InternalError(&'static str),
|
||||||
|
}
|
||||||
|
|
||||||
// Validate a map of values to have the expected included participants
|
// Validate a map of values to have the expected included participants
|
||||||
pub(crate) fn validate_map<T>(
|
pub(crate) fn validate_map<T>(
|
||||||
map: &HashMap<u16, T>,
|
map: &HashMap<u16, T>,
|
||||||
@@ -100,34 +128,6 @@ impl ThresholdParams {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Various errors possible during key generation/signing.
|
|
||||||
#[derive(Copy, Clone, Error, Debug)]
|
|
||||||
pub enum DkgError {
|
|
||||||
#[error("a parameter was 0 (required {0}, participants {1})")]
|
|
||||||
ZeroParameter(u16, u16),
|
|
||||||
#[error("invalid amount of required participants (max {1}, got {0})")]
|
|
||||||
InvalidRequiredQuantity(u16, u16),
|
|
||||||
#[error("invalid participant index (0 < index <= {0}, yet index is {1})")]
|
|
||||||
InvalidParticipantIndex(u16, u16),
|
|
||||||
|
|
||||||
#[error("invalid signing set")]
|
|
||||||
InvalidSigningSet,
|
|
||||||
#[error("invalid participant quantity (expected {0}, got {1})")]
|
|
||||||
InvalidParticipantQuantity(usize, usize),
|
|
||||||
#[error("duplicated participant index ({0})")]
|
|
||||||
DuplicatedIndex(u16),
|
|
||||||
#[error("missing participant {0}")]
|
|
||||||
MissingParticipant(u16),
|
|
||||||
|
|
||||||
#[error("invalid proof of knowledge (participant {0})")]
|
|
||||||
InvalidProofOfKnowledge(u16),
|
|
||||||
#[error("invalid share (participant {0})")]
|
|
||||||
InvalidShare(u16),
|
|
||||||
|
|
||||||
#[error("internal error ({0})")]
|
|
||||||
InternalError(&'static str),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Calculate the lagrange coefficient for a signing set.
|
/// Calculate the lagrange coefficient for a signing set.
|
||||||
pub fn lagrange<F: PrimeField>(i: u16, included: &[u16]) -> F {
|
pub fn lagrange<F: PrimeField>(i: u16, included: &[u16]) -> F {
|
||||||
let mut num = F::one();
|
let mut num = F::one();
|
||||||
|
|||||||
@@ -35,6 +35,29 @@ pub mod sign;
|
|||||||
#[cfg(any(test, feature = "tests"))]
|
#[cfg(any(test, feature = "tests"))]
|
||||||
pub mod tests;
|
pub mod tests;
|
||||||
|
|
||||||
|
/// Various errors possible during signing.
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Error)]
|
||||||
|
pub enum FrostError {
|
||||||
|
#[error("invalid participant index (0 < index <= {0}, yet index is {1})")]
|
||||||
|
InvalidParticipantIndex(u16, u16),
|
||||||
|
#[error("invalid signing set ({0})")]
|
||||||
|
InvalidSigningSet(&'static str),
|
||||||
|
#[error("invalid participant quantity (expected {0}, got {1})")]
|
||||||
|
InvalidParticipantQuantity(usize, usize),
|
||||||
|
#[error("duplicated participant index ({0})")]
|
||||||
|
DuplicatedIndex(u16),
|
||||||
|
#[error("missing participant {0}")]
|
||||||
|
MissingParticipant(u16),
|
||||||
|
|
||||||
|
#[error("invalid preprocess (participant {0})")]
|
||||||
|
InvalidPreprocess(u16),
|
||||||
|
#[error("invalid share (participant {0})")]
|
||||||
|
InvalidShare(u16),
|
||||||
|
|
||||||
|
#[error("internal error ({0})")]
|
||||||
|
InternalError(&'static str),
|
||||||
|
}
|
||||||
|
|
||||||
// Validate a map of values to have the expected included participants
|
// Validate a map of values to have the expected included participants
|
||||||
pub fn validate_map<T>(
|
pub fn validate_map<T>(
|
||||||
map: &HashMap<u16, T>,
|
map: &HashMap<u16, T>,
|
||||||
@@ -60,26 +83,3 @@ pub fn validate_map<T>(
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Various errors possible during signing.
|
|
||||||
#[derive(Copy, Clone, Error, Debug)]
|
|
||||||
pub enum FrostError {
|
|
||||||
#[error("invalid participant index (0 < index <= {0}, yet index is {1})")]
|
|
||||||
InvalidParticipantIndex(u16, u16),
|
|
||||||
#[error("invalid signing set ({0})")]
|
|
||||||
InvalidSigningSet(&'static str),
|
|
||||||
#[error("invalid participant quantity (expected {0}, got {1})")]
|
|
||||||
InvalidParticipantQuantity(usize, usize),
|
|
||||||
#[error("duplicated participant index ({0})")]
|
|
||||||
DuplicatedIndex(u16),
|
|
||||||
#[error("missing participant {0}")]
|
|
||||||
MissingParticipant(u16),
|
|
||||||
|
|
||||||
#[error("invalid preprocess (participant {0})")]
|
|
||||||
InvalidPreprocess(u16),
|
|
||||||
#[error("invalid share (participant {0})")]
|
|
||||||
InvalidShare(u16),
|
|
||||||
|
|
||||||
#[error("internal error ({0})")]
|
|
||||||
InternalError(&'static str),
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user