Skip to content

Commit

Permalink
Fixed serializations for range_check96 and empty signautre additional (
Browse files Browse the repository at this point in the history
…#1785)

data.
  • Loading branch information
Alon-Ti authored Jun 7, 2024
1 parent bf27557 commit e941395
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### Upcoming Changes

* fix: Fixed deserialization issue when signature additional data is empty, and the name of the builtin range_check96 [#1785](https://github.com/lambdaclass/cairo-vm/pull/1785)

* refactor + bugfix: Improve arg handling for cairo1-run [#1782](https://github.com/lambdaclass/cairo-vm/pull/1782)
* Now uses ascii whitespace as separator, preventing errors when using newlines in args file
* No longer gets stuck on improperly-formatted arrays
Expand Down
4 changes: 2 additions & 2 deletions vm/src/types/builtin_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use arbitrary::{self, Arbitrary};
const OUTPUT_BUILTIN_NAME: &str = "output";
const HASH_BUILTIN_NAME: &str = "pedersen";
const RANGE_CHECK_BUILTIN_NAME: &str = "range_check";
const RANGE_CHECK_96_BUILTIN_NAME: &str = "range_check_96";
const RANGE_CHECK_96_BUILTIN_NAME: &str = "range_check96";
const SIGNATURE_BUILTIN_NAME: &str = "ecdsa";
const BITWISE_BUILTIN_NAME: &str = "bitwise";
const EC_OP_BUILTIN_NAME: &str = "ec_op";
Expand All @@ -20,7 +20,7 @@ const MUL_MOD_BUILTIN_NAME: &str = "mul_mod";
const OUTPUT_BUILTIN_NAME_WITH_SUFFIX: &str = "output_builtin";
const HASH_BUILTIN_NAME_WITH_SUFFIX: &str = "pedersen_builtin";
const RANGE_CHECK_BUILTIN_NAME_WITH_SUFFIX: &str = "range_check_builtin";
const RANGE_CHECK_96_BUILTIN_NAME_WITH_SUFFIX: &str = "range_check_96_builtin";
const RANGE_CHECK_96_BUILTIN_NAME_WITH_SUFFIX: &str = "range_check96_builtin";
const SIGNATURE_BUILTIN_NAME_WITH_SUFFIX: &str = "ecdsa_builtin";
const BITWISE_BUILTIN_NAME_WITH_SUFFIX: &str = "bitwise_builtin";
const EC_OP_BUILTIN_NAME_WITH_SUFFIX: &str = "ec_op_builtin";
Expand Down
1 change: 1 addition & 0 deletions vm/src/vm/runners/builtin_runner/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl HashBuiltinRunner {
) -> Result<(), RunnerError> {
let additional_data = match additional_data {
BuiltinAdditionalData::Hash(d) => d,
BuiltinAdditionalData::Empty(_) => return Ok(()),
_ => return Err(RunnerError::InvalidAdditionalData(BuiltinName::pedersen)),
};
let mut verified_addresses = self.verified_addresses.borrow_mut();
Expand Down
1 change: 1 addition & 0 deletions vm/src/vm/runners/builtin_runner/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ impl SignatureBuiltinRunner {
) -> Result<(), RunnerError> {
let additional_data = match additional_data {
BuiltinAdditionalData::Signature(d) => d,
BuiltinAdditionalData::Empty(_) => return Ok(()),
_ => return Err(RunnerError::InvalidAdditionalData(BuiltinName::ecdsa)),
};
for (addr, (r, s)) in additional_data {
Expand Down
29 changes: 28 additions & 1 deletion vm/src/vm/runners/cairo_pie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ pub struct OutputBuiltinAdditionalData {
pub attributes: Attributes,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[derive(Serialize, Deserialize, Clone, Debug, Eq)]
#[serde(untagged)]
pub enum BuiltinAdditionalData {
// Catch empty lists under the `Empty` variant.
Empty([(); 0]),
// Contains verified addresses as contiguous index, value pairs
#[serde(with = "serde_impl::hash_additional_data")]
Hash(Vec<Relocatable>),
Expand All @@ -85,6 +87,31 @@ pub enum BuiltinAdditionalData {
None,
}

impl BuiltinAdditionalData {
fn is_empty(&self) -> bool {
match self {
Self::Empty(_) => true,
Self::Hash(data) => data.is_empty(),
Self::Signature(data) => data.is_empty(),
Self::Output(_) => false,
Self::None => false,
}
}
}

impl PartialEq for BuiltinAdditionalData {
fn eq(&self, other: &BuiltinAdditionalData) -> bool {
match (self, other) {
(Self::Hash(data), Self::Hash(other_data)) => data == other_data,
(Self::Signature(data), Self::Signature(other_data)) => data == other_data,
(Self::Output(data), Self::Output(other_data)) => data == other_data,
(Self::None, Self::None) => true,
(Self::Empty(_), x) | (x, Self::Empty(_)) => x.is_empty(),
_ => false,
}
}
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct CairoPieAdditionalData(
#[serde(with = "crate::types::builtin_name::serde_generic_map_impl")]
Expand Down

0 comments on commit e941395

Please sign in to comment.