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

Implement Serde for fields and curves #48

Merged
merged 2 commits into from
Nov 19, 2022
Merged

Conversation

vmx
Copy link
Contributor

@vmx vmx commented Sep 6, 2022

Currently Serde is only implemented for Fp, Fq, EpAffine and EqAffine.
Support can be enabled with the serde feature.

It's based on the implementation in blstrs: https://github.com/filecoin-project/blstrs/blob/master/src/serde_impl.rs

Please let me know if that's the correct approach, or e.g. you'd like to serialize them to four u64s.

I've only implemented it for the things I currently need, but I'm happy to provide an implementation for all curves.

test_roundtrip(&f);
assert_eq!(
serde_json::from_slice::<EpAffine>(
b"[0,0,0,0,237,48,45,153,27,249,76,9,252,152,70,34,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64]"
Copy link
Contributor

Choose a reason for hiding this comment

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

I have not checked this value (or the one for EqAffine::generator() below).

Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

utACK. Serialising the byte representations looks good to me.

src/serde_impl.rs Outdated Show resolved Hide resolved
src/serde_impl.rs Outdated Show resolved Hide resolved
@vmx vmx marked this pull request as ready for review September 8, 2022 07:42
@codecov-commenter
Copy link

Codecov Report

Base: 66.15% // Head: 72.35% // Increases project coverage by +6.20% 🎉

Coverage data is based on head (d9b9fe1) compared to base (682a0e6).
Patch coverage: 95.18% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #48      +/-   ##
==========================================
+ Coverage   66.15%   72.35%   +6.20%     
==========================================
  Files          12       13       +1     
  Lines        1427     1530     +103     
==========================================
+ Hits          944     1107     +163     
+ Misses        483      423      -60     
Impacted Files Coverage Δ
src/lib.rs 62.50% <ø> (-37.50%) ⬇️
src/serde_impl.rs 95.18% <95.18%> (ø)
src/vesta.rs 74.07% <0.00%> (-25.93%) ⬇️
src/pallas.rs 84.48% <0.00%> (-15.52%) ⬇️
src/macros.rs 51.61% <0.00%> (-1.73%) ⬇️
src/fields/fp.rs 84.65% <0.00%> (+4.37%) ⬆️
src/fields/fq.rs 84.09% <0.00%> (+4.37%) ⬆️
src/curves.rs 54.66% <0.00%> (+15.89%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@parazyd
Copy link

parazyd commented Sep 8, 2022

@vmx Would you also consider adding borsh support or is that out of scope?

@vmx
Copy link
Contributor Author

vmx commented Sep 8, 2022

@parazyd I won't have time working on borsh support.

@parazyd
Copy link

parazyd commented Sep 8, 2022

@vmx Alright, I will then add it after this PR is merged. Thank you.

Cargo.toml Outdated Show resolved Hide resolved
@FrankC01
Copy link

Is this going to be merged in?

src/serde_impl.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
@str4d
Copy link
Contributor

str4d commented Oct 13, 2022

This PR needs to be rebased (GitHub's UI indicates there is a merge conflict).

Currently Serde is only implemented for `Fp`, `Fq`, `EpAffine` and `EqAffine`.
Support can be enabled with the `serde` feature.
@vmx
Copy link
Contributor Author

vmx commented Oct 14, 2022

As I needed to rebase, I did merged all commits into a single one. It should now include all the things mentioned in the review.

Notable things are:

  • I've also added bincode to test the non human readable version.
  • I've kept serde as feature name. The "hack" renaming the crate was inspired https://github.com/RustCrypto/RSA/pull/41/files. Once the minimum required Rust version is 1.60, the dep:serde can be used in the feature flag definitions

Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

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

Human-readable serialization change looks good.

src/serde_impl.rs Outdated Show resolved Hide resolved
src/serde_impl.rs Outdated Show resolved Hide resolved
src/serde_impl.rs Outdated Show resolved Hide resolved
src/serde_impl.rs Outdated Show resolved Hide resolved
src/serde_impl.rs Outdated Show resolved Hide resolved
src/serde_impl.rs Outdated Show resolved Hide resolved
@samuelburnham
Copy link
Contributor

samuelburnham commented Nov 16, 2022

Following this model, I have also implemented Serde for the Ep and Eq types. Should I open a separate PR or wait till this one is merged?

vmx pushed a commit to ipld/libipld that referenced this pull request Nov 17, 2022
Currently, the Serializer sets `is_human_readable` to false, but the Deserializer implicitly sets it to true. This causes issues when other types try to use serde based on this value, as in zcash/pasta_curves#48, so this PR makes them consistently false.

BREAKING CHANGE: the Serde deserializer is now defined as non human readable
vmx added a commit to filecoin-project/fil_pasta_curves that referenced this pull request Nov 17, 2022
Implement serde for fields and curves.

Those changes are based on zcash#48 and will
eventually also land upstream.
Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

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

utACK 025362a

@str4d str4d merged commit f8ba48d into zcash:main Nov 19, 2022
@vmx vmx deleted the impl-serde branch November 19, 2022 13:41
tyshko5 pushed a commit to tyshko5/libipld that referenced this pull request Nov 29, 2022
fix: make the deserializer human-unreadable (ipld#165)

Currently, the Serializer sets `is_human_readable` to false, but the Deserializer implicitly sets it to true. This causes issues when other types try to use serde based on this value, as in zcash/pasta_curves#48, so this PR makes them consistently false.

BREAKING CHANGE: the Serde deserializer is now defined as non human readable

lint fix

try fix CI

empty

revert

try fix 2

fix ci 2

fix ci 3

less branches no dep:, arb feature

fix arb

lint fixes

fix wasm ci

fix arb 3

fix wasm ci

fix wasm ci 2

fix no_std build

requested changes

getrandom optional

remove getrandom

fix recursion

requested changes

shrink

fix duplicate code

update `multihash` in other crates

fix

(cargo-release) version 0.15.0

(cargo-release) version 0.15.0

(cargo-release) version 0.15.0

(cargo-release) version 0.15.0

(cargo-release) version 0.15.0

(cargo-release) version 0.15.0

(cargo-release) version 0.15.0

fixes

minor

remove custom generator

remove arbitrary_ipld_vec/map fn_s

remove filtering of fleat nans

make arbitrary_ipld private

copy size to avoid too small lists/maps

fix arbitrary_size with actual size

fix size == 0 edgecase

fmt && clippy

cliipy

chore: fix Android build on CI (ipld#169)

Also cache `cargo-apk` for faster CI run times.

move everything to arb module

fmt
vmx pushed a commit to ipld/rust-ipld-core that referenced this pull request Feb 22, 2024
Currently, the Serializer sets `is_human_readable` to false, but the Deserializer implicitly sets it to true. This causes issues when other types try to use serde based on this value, as in zcash/pasta_curves#48, so this PR makes them consistently false.

BREAKING CHANGE: the Serde deserializer is now defined as non human readable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants