Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

fix(acir): Hide variants of WitnessMapError and export it from package #283

Merged
merged 2 commits into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions acir/src/native_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ mod witness_map;
pub use expression::Expression;
pub use witness::Witness;
pub use witness_map::WitnessMap;
pub use witness_map::WitnessMapError;
16 changes: 11 additions & 5 deletions acir/src/native_types/witness_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use thiserror::Error;
use crate::native_types::Witness;

#[derive(Debug, Error)]
pub enum WitnessMapError {
enum SerializationError {
#[error(transparent)]
MsgpackEncode(#[from] rmp_serde::encode::Error),

Expand All @@ -26,6 +26,10 @@ pub enum WitnessMapError {
Deflate(#[from] std::io::Error),
}

#[derive(Debug, Error)]
#[error(transparent)]
pub struct WitnessMapError(#[from] SerializationError);

/// A map from the witnesses in a constraint system to the field element values
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default, Serialize, Deserialize)]
pub struct WitnessMap(BTreeMap<Witness, FieldElement>);
Expand Down Expand Up @@ -85,10 +89,10 @@ impl TryFrom<WitnessMap> for Vec<u8> {
type Error = WitnessMapError;

fn try_from(val: WitnessMap) -> Result<Self, Self::Error> {
let buf = rmp_serde::to_vec(&val)?;
let buf = rmp_serde::to_vec(&val).map_err(|err| WitnessMapError(err.into()))?;
let mut deflater = DeflateEncoder::new(buf.as_slice(), Compression::best());
let mut buf_c = Vec::new();
deflater.read_to_end(&mut buf_c)?;
deflater.read_to_end(&mut buf_c).map_err(|err| WitnessMapError(err.into()))?;
Ok(buf_c)
}
}
Expand All @@ -99,7 +103,9 @@ impl TryFrom<&[u8]> for WitnessMap {
fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> {
let mut deflater = DeflateDecoder::new(bytes);
let mut buf_d = Vec::new();
deflater.read_to_end(&mut buf_d)?;
Ok(Self(rmp_serde::from_slice(buf_d.as_slice())?))
deflater.read_to_end(&mut buf_d).map_err(|err| WitnessMapError(err.into()))?;
let witness_map =
rmp_serde::from_slice(buf_d.as_slice()).map_err(|err| WitnessMapError(err.into()))?;
Ok(Self(witness_map))
}
}
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"stdlib",
"struct",
"TORADIX",
"Msgpack",
// Dependencies
//
"bufread",
Expand Down