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

Add serde_as regression test for pasta #2476

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion kimchi/src/tests/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ where
}

/// creates the indexes
#[must_use]
Copy link
Member Author

Choose a reason for hiding this comment

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

Offtop but: I removed this since it was giving a warning: setup_with_custom_srs is indeed used, but only in tests. must_use does not understand this and produces a warning.

Copy link
Member Author

Choose a reason for hiding this comment

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

This did not work.

pub(crate) fn setup_with_custom_srs<F: FnMut(D<G::ScalarField>, usize) -> OpeningProof::SRS>(
mut self,
get_srs: F,
Expand Down
1 change: 1 addition & 0 deletions utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ hex = { version = "0.4", features = ["serde"] }
num-bigint = { version = "0.4.3", features = ["rand"]}
num-integer = "0.1.45"
num-traits = "0.2"
rmp-serde = "1.1.1"
sha2 = "0.10.2"
thiserror = "1.0.30"
rand = "0.8.0"
Expand Down
60 changes: 60 additions & 0 deletions utils/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,63 @@ where
T::deserialize(&mut &bytes[..]).map_err(serde::de::Error::custom)
}
}

#[cfg(test)]
mod tests {

use ark_ec::AffineCurve;
use ark_serialize::Write;
use mina_curves::pasta::{Pallas, Vesta};
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use std::io::BufReader;

#[test]
pub fn serde_as_regression_pasta() {
#[serde_as]
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
struct TestStruct {
#[serde_as(as = "crate::serialization::SerdeAs")]
pallas: Pallas,
#[serde_as(as = "crate::serialization::SerdeAs")]
vesta: Vesta,
}

let data_expected = TestStruct {
pallas: Pallas::prime_subgroup_generator(),
vesta: Vesta::prime_subgroup_generator(),
};

// reference serialized value
let buf_expected: Vec<u8> = vec![
146, 196, 33, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 196, 33, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
];

let mut buf_written: Vec<u8> = vec![0; buf_expected.len()];

let serialized_bytes =
rmp_serde::to_vec(&data_expected).expect("TestStruct could not be serialized");
(buf_written.as_mut_slice())
.write_all(&serialized_bytes)
.expect("failed to write file");
(buf_written.as_mut_slice())
.flush()
.expect("failed to flush file");

assert!(
buf_written == buf_expected,
"Serialized (written) representation {buf_written:?} does not match the expected one {buf_expected:?}"
);

let reader = BufReader::new(buf_expected.as_slice());
let data_read: TestStruct =
rmp_serde::from_read(reader).expect("Could not deseralize TestStruct");

assert!(
data_read == data_expected,
"Deserialized value {data_read:?} does not match the expected one {data_expected:?}"
);
}
}
Loading