Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CairoPie serialization. #1444

Merged
merged 19 commits into from
Sep 18, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add version field.
  • Loading branch information
azteca1998 committed Sep 14, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit cb436751a3c63dec336bbb99b466b2eac5112341
3 changes: 3 additions & 0 deletions vm/src/tests/cairo_pie_test_output.json
Original file line number Diff line number Diff line change
@@ -55,5 +55,8 @@
"size": 10,
"index": 0
}
},
"version": {
"cairo_pie": "1.1"
}
}
14 changes: 14 additions & 0 deletions vm/src/vm/runners/cairo_pie.rs
Original file line number Diff line number Diff line change
@@ -60,6 +60,7 @@ pub struct CairoPie {
pub memory: CairoPieMemory,
pub execution_resources: ExecutionResources,
pub additional_data: HashMap<String, BuiltinAdditionalData>,
pub version: CairoPieVersion,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it is possible, but can we use a String type for the version field.
Plus add a constant with the CairoPieVersion String, so it is easy to change

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it is possible, it'd need to be initialized every time the CairoPie object is created. Having it as it is now this cannot happen because the version field is zero-sized.

The constant is easy. Fixed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

}

#[derive(Serialize, Clone, Debug, PartialEq, Eq)]
@@ -85,6 +86,12 @@ pub struct StrippedProgram {
pub prime: (),
}

#[derive(Serialize, Clone, Debug, PartialEq, Eq)]
pub struct CairoPieVersion {
#[serde(serialize_with = "serde_impl::serialize_version")]
pub cairo_pie: (),
}

mod serde_impl {
use crate::{types::relocatable::MaybeRelocatable, utils::CAIRO_PRIME};
use felt::Felt252;
@@ -136,4 +143,11 @@ mod serde_impl {
// Note: This uses an API intended only for testing.
serde_json::Number::from_string_unchecked(CAIRO_PRIME.to_string()).serialize(serializer)
}

pub fn serialize_version<S>(_value: &(), serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str("1.1")
}
}
3 changes: 2 additions & 1 deletion vm/src/vm/runners/cairo_runner.rs
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ use serde::{Deserialize, Serialize};

use super::{
builtin_runner::{KeccakBuiltinRunner, PoseidonBuiltinRunner, OUTPUT_BUILTIN_NAME},
cairo_pie::{self, CairoPie, CairoPieMetadata},
cairo_pie::{self, CairoPie, CairoPieMetadata, CairoPieVersion},
};

#[derive(Clone, Debug, Eq, PartialEq)]
@@ -1251,6 +1251,7 @@ impl CairoRunner {
.iter()
.map(|b| (b.name().to_string(), b.get_additional_data()))
.collect(),
version: CairoPieVersion { cairo_pie: () },
})
}