diff --git a/CHANGELOG.md b/CHANGELOG.md index e9a5c24b78..79c47cefc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/vm/src/types/builtin_name.rs b/vm/src/types/builtin_name.rs index af5bc2bfbe..5490f439a1 100644 --- a/vm/src/types/builtin_name.rs +++ b/vm/src/types/builtin_name.rs @@ -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"; @@ -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"; diff --git a/vm/src/vm/runners/builtin_runner/hash.rs b/vm/src/vm/runners/builtin_runner/hash.rs index a2183902ad..ad241e154b 100644 --- a/vm/src/vm/runners/builtin_runner/hash.rs +++ b/vm/src/vm/runners/builtin_runner/hash.rs @@ -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(); diff --git a/vm/src/vm/runners/builtin_runner/signature.rs b/vm/src/vm/runners/builtin_runner/signature.rs index 24eaa46541..f81f77181b 100644 --- a/vm/src/vm/runners/builtin_runner/signature.rs +++ b/vm/src/vm/runners/builtin_runner/signature.rs @@ -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 { diff --git a/vm/src/vm/runners/cairo_pie.rs b/vm/src/vm/runners/cairo_pie.rs index 6caeed250e..befd07f44f 100644 --- a/vm/src/vm/runners/cairo_pie.rs +++ b/vm/src/vm/runners/cairo_pie.rs @@ -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), @@ -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")]