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
data.
  • Loading branch information
Alon-Ti committed Jun 6, 2024
1 parent bf27557 commit 1575f3b
Show file tree
Hide file tree
Showing 5 changed files with 47 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
42 changes: 41 additions & 1 deletion vm/src/vm/runners/cairo_pie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +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 {
// Contains verified addresses as contiguous index, value pairs
Empty([usize; 0]),
#[serde(with = "serde_impl::hash_additional_data")]
Hash(Vec<Relocatable>),
Output(OutputBuiltinAdditionalData),
Expand All @@ -85,6 +86,45 @@ pub enum BuiltinAdditionalData {
None,
}

impl PartialEq for BuiltinAdditionalData {
fn eq(&self, other: &BuiltinAdditionalData) -> bool {
match self {
BuiltinAdditionalData::Empty(_) => match other {
BuiltinAdditionalData::Empty(_) => true,
BuiltinAdditionalData::Hash(hashes) => hashes.is_empty(),
BuiltinAdditionalData::Signature(signatures) => signatures.is_empty(),
_ => false,
},
BuiltinAdditionalData::Hash(data) => {
if let BuiltinAdditionalData::Hash(other_data) = other {
data == other_data
} else if let BuiltinAdditionalData::Empty(_) = other {
data.is_empty()
} else {
false
}
}
BuiltinAdditionalData::Signature(data) => {
if let BuiltinAdditionalData::Signature(other_data) = other {
data == other_data
} else if let BuiltinAdditionalData::Empty(_) = other {
data.is_empty()
} else {
false
}
}
BuiltinAdditionalData::Output(data) => {
if let BuiltinAdditionalData::Output(other_data) = other {
data == other_data
} else {
false
}
}
BuiltinAdditionalData::None => matches!(other, BuiltinAdditionalData::None),
}
}
}

#[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 1575f3b

Please sign in to comment.