Skip to content

Commit e941395

Browse files
authored
Fixed serializations for range_check96 and empty signautre additional (#1785)
data.
1 parent bf27557 commit e941395

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#### Upcoming Changes
44

5+
* 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)
6+
57
* refactor + bugfix: Improve arg handling for cairo1-run [#1782](https://github.com/lambdaclass/cairo-vm/pull/1782)
68
* Now uses ascii whitespace as separator, preventing errors when using newlines in args file
79
* No longer gets stuck on improperly-formatted arrays

vm/src/types/builtin_name.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use arbitrary::{self, Arbitrary};
77
const OUTPUT_BUILTIN_NAME: &str = "output";
88
const HASH_BUILTIN_NAME: &str = "pedersen";
99
const RANGE_CHECK_BUILTIN_NAME: &str = "range_check";
10-
const RANGE_CHECK_96_BUILTIN_NAME: &str = "range_check_96";
10+
const RANGE_CHECK_96_BUILTIN_NAME: &str = "range_check96";
1111
const SIGNATURE_BUILTIN_NAME: &str = "ecdsa";
1212
const BITWISE_BUILTIN_NAME: &str = "bitwise";
1313
const EC_OP_BUILTIN_NAME: &str = "ec_op";
@@ -20,7 +20,7 @@ const MUL_MOD_BUILTIN_NAME: &str = "mul_mod";
2020
const OUTPUT_BUILTIN_NAME_WITH_SUFFIX: &str = "output_builtin";
2121
const HASH_BUILTIN_NAME_WITH_SUFFIX: &str = "pedersen_builtin";
2222
const RANGE_CHECK_BUILTIN_NAME_WITH_SUFFIX: &str = "range_check_builtin";
23-
const RANGE_CHECK_96_BUILTIN_NAME_WITH_SUFFIX: &str = "range_check_96_builtin";
23+
const RANGE_CHECK_96_BUILTIN_NAME_WITH_SUFFIX: &str = "range_check96_builtin";
2424
const SIGNATURE_BUILTIN_NAME_WITH_SUFFIX: &str = "ecdsa_builtin";
2525
const BITWISE_BUILTIN_NAME_WITH_SUFFIX: &str = "bitwise_builtin";
2626
const EC_OP_BUILTIN_NAME_WITH_SUFFIX: &str = "ec_op_builtin";

vm/src/vm/runners/builtin_runner/hash.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ impl HashBuiltinRunner {
125125
) -> Result<(), RunnerError> {
126126
let additional_data = match additional_data {
127127
BuiltinAdditionalData::Hash(d) => d,
128+
BuiltinAdditionalData::Empty(_) => return Ok(()),
128129
_ => return Err(RunnerError::InvalidAdditionalData(BuiltinName::pedersen)),
129130
};
130131
let mut verified_addresses = self.verified_addresses.borrow_mut();

vm/src/vm/runners/builtin_runner/signature.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ impl SignatureBuiltinRunner {
188188
) -> Result<(), RunnerError> {
189189
let additional_data = match additional_data {
190190
BuiltinAdditionalData::Signature(d) => d,
191+
BuiltinAdditionalData::Empty(_) => return Ok(()),
191192
_ => return Err(RunnerError::InvalidAdditionalData(BuiltinName::ecdsa)),
192193
};
193194
for (addr, (r, s)) in additional_data {

vm/src/vm/runners/cairo_pie.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ pub struct OutputBuiltinAdditionalData {
7272
pub attributes: Attributes,
7373
}
7474

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

90+
impl BuiltinAdditionalData {
91+
fn is_empty(&self) -> bool {
92+
match self {
93+
Self::Empty(_) => true,
94+
Self::Hash(data) => data.is_empty(),
95+
Self::Signature(data) => data.is_empty(),
96+
Self::Output(_) => false,
97+
Self::None => false,
98+
}
99+
}
100+
}
101+
102+
impl PartialEq for BuiltinAdditionalData {
103+
fn eq(&self, other: &BuiltinAdditionalData) -> bool {
104+
match (self, other) {
105+
(Self::Hash(data), Self::Hash(other_data)) => data == other_data,
106+
(Self::Signature(data), Self::Signature(other_data)) => data == other_data,
107+
(Self::Output(data), Self::Output(other_data)) => data == other_data,
108+
(Self::None, Self::None) => true,
109+
(Self::Empty(_), x) | (x, Self::Empty(_)) => x.is_empty(),
110+
_ => false,
111+
}
112+
}
113+
}
114+
88115
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
89116
pub struct CairoPieAdditionalData(
90117
#[serde(with = "crate::types::builtin_name::serde_generic_map_impl")]

0 commit comments

Comments
 (0)