cleaner output, and log writer

This commit is contained in:
gluaxspeed 2021-07-11 23:42:14 -07:00
parent c0628a04c7
commit a4575c8a00
6 changed files with 11 additions and 32 deletions

View File

@ -21,9 +21,6 @@ use snarkvm_r1cs::SynthesisError;
pub enum GroupError {
#[error("{}", _0)]
Error(#[from] FormattedError),
#[error("Failed to represent group as log string.")]
LogError,
}
impl LeoError for GroupError {}
@ -33,10 +30,6 @@ impl GroupError {
GroupError::Error(FormattedError::new_from_span(message, span))
}
pub fn failed_to_create_log_string() -> Self {
GroupError::LogError
}
pub fn negate_operation(error: SynthesisError, span: &Span) -> Self {
let message = format!("group negation failed due to the synthesis error `{:?}`", error,);

View File

@ -155,8 +155,6 @@ impl Output {
format!("({})", values)
}
ConstrainedValue::Field(field) => format!("{:?}", field),
ConstrainedValue::Group(group) => format!("{:?}", group),
_ => value.to_string(),
};

View File

@ -247,6 +247,9 @@ impl<F: PrimeField> ToBytesGadget<F> for FieldType<F> {
impl<F: PrimeField> std::fmt::Display for FieldType<F> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self.get_value().ok_or(std::fmt::Error))
match self.get_value().ok_or(std::fmt::Error) {
Ok(value) => write!(f, "{}", value),
value => write!(f, "{:?}", value),
}
}
}

View File

@ -45,8 +45,6 @@ pub trait GroupType<F: Field>:
+ ToBitsBEGadget<F>
+ ToBytesGadget<F>
{
fn log_string(&self) -> Result<String, GroupError>;
fn constant(value: &GroupValue, span: &Span) -> Result<Self, GroupError>;
fn to_allocated<CS: ConstraintSystem<F>>(&self, cs: CS, span: &Span) -> Result<Self, GroupError>;

View File

@ -52,16 +52,6 @@ pub enum EdwardsGroupType {
}
impl GroupType<Fq> for EdwardsGroupType {
fn log_string(&self) -> Result<String, GroupError> {
match self {
EdwardsGroupType::Constant(constant) => Ok(format!("({}, {})group", constant.x, constant.y)),
EdwardsGroupType::Allocated(allocated) => match (allocated.x.get_value(), allocated.y.get_value()) {
(Some(x), Some(y)) => Ok(format!("({}, {})group", x, y)),
_ => Err(GroupError::failed_to_create_log_string()),
},
}
}
fn constant(group: &GroupValue, span: &Span) -> Result<Self, GroupError> {
let value = Self::edwards_affine_from_value(group, span)?;
@ -549,8 +539,11 @@ impl One for EdwardsGroupType {
impl std::fmt::Display for EdwardsGroupType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
EdwardsGroupType::Constant(constant) => write!(f, "{:?}", constant),
EdwardsGroupType::Allocated(allocated) => write!(f, "{:?}", allocated),
EdwardsGroupType::Constant(constant) => write!(f, "({}, {})group", constant.x, constant.y),
EdwardsGroupType::Allocated(allocated) => match (allocated.x.get_value(), allocated.y.get_value()) {
(Some(x), Some(y)) => write!(f, "({}, {})group", x, y),
allocated => write!(f, "{:?}", allocated),
},
}
}
}

View File

@ -96,14 +96,8 @@ impl<'a, F: PrimeField, G: GroupType<F>> fmt::Display for ConstrainedValue<'a, F
.unwrap_or_else(|| "[allocated]".to_string())
),
ConstrainedValue::Char(ref value) => write!(f, "{}", value),
ConstrainedValue::Field(ref value) => {
if let Some(value) = value.get_value() {
write!(f, "{}", value)
} else {
Err(std::fmt::Error)
}
}
ConstrainedValue::Group(ref value) => write!(f, "{}", value.log_string().unwrap_or_else(|e| e.to_string())),
ConstrainedValue::Field(ref value) => write!(f, "{}", value),
ConstrainedValue::Group(ref value) => write!(f, "{}", value),
ConstrainedValue::Integer(ref value) => write!(f, "{}", value),
// Data type wrappers