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

Serialize and deserialize program #1458

Merged
merged 27 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9edddbc
make `ProgramJson` serializable
kariy Jun 22, 2023
f398373
refactor: impl `From` `Program` for `ProgramJson`
kariy Jun 28, 2023
f9195e8
Restore lockfile
kariy Jun 28, 2023
73d8cd9
Merge branch 'main' into serialize-and-deserialize-program
pefontana Oct 6, 2023
4ab3344
rfc: implement From to convert HintsCollection to BTreeMap
Oppen Oct 9, 2023
c1bd539
add dummy test
pefontana Oct 9, 2023
5190028
Merge branch 'rfc/hints_collection_to_bmap' into serialize-and-deseri…
pefontana Oct 9, 2023
8d8cd6b
Fix ProgramJson::from(Program)
pefontana Oct 10, 2023
d78f9f7
Add integration test
pefontana Oct 10, 2023
39a8079
User &Program
pefontana Oct 11, 2023
c118e13
Implement ProgramDeserializer
pefontana Oct 11, 2023
eaafc56
add integration test
pefontana Oct 11, 2023
9f6f05d
Add error handling
pefontana Oct 12, 2023
fd791ed
Merge branch 'main' into serialize-and-deserialize-program
pefontana Oct 12, 2023
943c9d9
Restore Cargo.lock
pefontana Oct 12, 2023
fba991c
update CHANGELOG.md
pefontana Oct 12, 2023
0ddb38a
rename variables
pefontana Oct 12, 2023
348e3e3
Add doc
pefontana Oct 12, 2023
b1cbdba
Add doc
pefontana Oct 12, 2023
8a8c8a5
typo
pefontana Oct 12, 2023
deaee13
Merge branch 'main' into serialize-and-deserialize-program
pefontana Oct 12, 2023
9dda03f
Merge branch 'main' into serialize-and-deserialize-program
pefontana Oct 17, 2023
feeb7a5
Update CHANGELOG.md
pefontana Oct 17, 2023
7e8c529
Remove unnecesary code
pefontana Oct 17, 2023
3b7f0b6
update CHANGELOG.md
pefontana Oct 17, 2023
afa1dea
Remove ProgramJson Serialize
pefontana Oct 19, 2023
5df44fc
Merge branch 'main' into serialize-and-deserialize-program
pefontana Oct 24, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

#### Upcoming Changes

* feat: Implement the Serialize and Deserialize methods fot the Program struct [#1458](https://github.com/lambdaclass/cairo-vm/pull/1458)
pefontana marked this conversation as resolved.
Show resolved Hide resolved

* feat: Implement a CLI to run cairo programs [#1370](https://github.com/lambdaclass/cairo-vm/pull/1370)


* fix: Fix string code of `BLAKE2S_ADD_UINT256` hint [#1454](https://github.com/lambdaclass/cairo-vm/pull/1454)

#### [0.9.0] - 2023-10-03
Expand Down
29 changes: 21 additions & 8 deletions vm/src/serde/deserialize_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use felt::{Felt252, PRIME_STR};
use num_traits::float::FloatCore;
use num_traits::{Num, Pow};
use serde::{de, de::MapAccess, de::SeqAccess, Deserialize, Deserializer, Serialize};
use serde::{de, de::MapAccess, de::SeqAccess, Deserialize, Deserializer, Serialize, Serializer};
use serde_json::Number;

#[cfg(all(feature = "arbitrary", feature = "std"))]
Expand Down Expand Up @@ -70,7 +70,7 @@
}

#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary, Clone))]
#[derive(Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, PartialEq)]
fmoletta marked this conversation as resolved.
Show resolved Hide resolved
pub struct ProgramJson {
pub prime: String,
pub builtins: Vec<BuiltinName>,
Expand Down Expand Up @@ -195,13 +195,10 @@
})
}

#[cfg_attr(
all(feature = "arbitrary", feature = "std"),
derive(Arbitrary, Clone, Serialize)
)]
#[derive(Deserialize, Debug, PartialEq, Eq)]
#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary, Clone))]
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct DebugInfo {
instruction_locations: HashMap<usize, InstructionLocation>,
pub(crate) instruction_locations: HashMap<usize, InstructionLocation>,
}

#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))]
Expand Down Expand Up @@ -415,6 +412,22 @@
d.deserialize_str(Felt252Visitor)
}

pub fn serialize_program_data<S: Serializer>(
v: &[MaybeRelocatable],
serializer: S,
) -> Result<S::Ok, S::Error> {
let v = v
.iter()
.map(|val| match val {
MaybeRelocatable::Int(value) => format!("0x{:x}", value.to_biguint()),

Check warning on line 422 in vm/src/serde/deserialize_program.rs

View check run for this annotation

Codecov / codecov/patch

vm/src/serde/deserialize_program.rs#L415-L422

Added lines #L415 - L422 were not covered by tests
fmoletta marked this conversation as resolved.
Show resolved Hide resolved
MaybeRelocatable::RelocatableValue(_) => {
panic!("Got unexpected relocatable value in program data")

Check warning on line 424 in vm/src/serde/deserialize_program.rs

View check run for this annotation

Codecov / codecov/patch

vm/src/serde/deserialize_program.rs#L424

Added line #L424 was not covered by tests
}
})
.collect::<Vec<String>>();
v.serialize(serializer)
}

Check warning on line 429 in vm/src/serde/deserialize_program.rs

View check run for this annotation

Codecov / codecov/patch

vm/src/serde/deserialize_program.rs#L426-L429

Added lines #L426 - L429 were not covered by tests

pub fn deserialize_array_of_bigint_hex<'de, D: Deserializer<'de>>(
d: D,
) -> Result<Vec<MaybeRelocatable>, D::Error> {
Expand Down
1 change: 1 addition & 0 deletions vm/src/serde/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod deserialize_program;
mod deserialize_utils;
pub(crate) mod serialize_program;
Loading