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

feat(acir): add method on Circuit to return assert message #551

Merged
merged 1 commit into from
Sep 17, 2023
Merged
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
11 changes: 11 additions & 0 deletions acir/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@
pub assert_messages: Vec<(OpcodeLocation, String)>,
}

impl Circuit {
/// Returns the assert message associated with the provided [`OpcodeLocation`].
/// Returns `None` if no such assert message exists.
pub fn get_assert_message(&self, opcode_location: OpcodeLocation) -> Option<&str> {
self.assert_messages
.iter()
.find(|(loc, _)| *loc == opcode_location)
.map(|(_, message)| message.as_str())
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
/// Opcodes are locatable so that callers can
/// map opcodes to debug information related to their context.
Expand Down Expand Up @@ -114,7 +125,7 @@
PublicInputs(public_inputs)
}

#[cfg(feature = "serialize-messagepack")]

Check warning on line 128 in acir/src/circuit/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (messagepack)
pub fn write<W: std::io::Write>(&self, writer: W) -> std::io::Result<()> {
let buf = rmp_serde::to_vec(&self).unwrap();
let mut deflater = flate2::write::DeflateEncoder::new(writer, Compression::best());
Expand All @@ -122,7 +133,7 @@

Ok(())
}
#[cfg(feature = "serialize-messagepack")]

Check warning on line 136 in acir/src/circuit/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (messagepack)
pub fn read<R: std::io::Read>(reader: R) -> std::io::Result<Self> {
let mut deflater = flate2::read::DeflateDecoder::new(reader);
let mut buf_d = Vec::new();
Expand All @@ -131,21 +142,21 @@
Ok(circuit)
}

#[cfg(not(feature = "serialize-messagepack"))]

Check warning on line 145 in acir/src/circuit/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (messagepack)
pub fn write<W: std::io::Write>(&self, writer: W) -> std::io::Result<()> {
let buf = bincode::serialize(&self).unwrap();

Check warning on line 147 in acir/src/circuit/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (bincode)
let mut encoder = flate2::write::GzEncoder::new(writer, Compression::default());
encoder.write_all(&buf).unwrap();
encoder.finish().unwrap();
Ok(())
}

#[cfg(not(feature = "serialize-messagepack"))]

Check warning on line 154 in acir/src/circuit/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (messagepack)
pub fn read<R: std::io::Read>(reader: R) -> std::io::Result<Self> {
let mut gz_decoder = flate2::read::GzDecoder::new(reader);
let mut buf_d = Vec::new();
gz_decoder.read_to_end(&mut buf_d).unwrap();
let circuit = bincode::deserialize(&buf_d).unwrap();

Check warning on line 159 in acir/src/circuit/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (bincode)
Ok(circuit)
}
}
Expand Down