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

[utils] improve serialization when serializing to json #1044

Merged
merged 2 commits into from
Mar 22, 2023
Merged

Conversation

mimoo
Copy link
Contributor

@mimoo mimoo commented Mar 10, 2023

closes #1037

here's an example of a verifier index
{
  "domain": "20000000000000000500000020000000000000000000000000000000000000000000000000000000000000000100009865c763bc52910229346434210000000000000000000000000000003ecc789b927663a38fbcb7ce3e39a3ae3bed330856d19af2dae1f216c60d38c30c87a189965e1f4df0bafbc05f37cdfcc8edd344b81f32ce5c410fa94ba5bf2f1467666666f8797870713085d064704fa799999999999999999999999999999919",
  "max_poly_size": 32,
  "public": 5,
  "prev_challenges": 0,
  "sigma_comm": [
    {
      "unshifted": [
        "26fd31d1824baae274323cc4379bbefb51f445f0aef6a630b24afbf79f34c92600"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "31f5be1c7f7a59d456eff1fb8e08957640bd59e1f33535ce58bf4d4b5080af3580"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "d9cb6710fe7cd16ce5b4f87ea9800d06d58a182ade0b7d950b8579822fc8fd1c80"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "799e5fd806bc420e4e6a0073c36178b79a6534a58886d1cbf40e808707ba2a2600"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "6d43561d77acd27c23df7106fee13646f79d9daa5c0c80b582236c049d75510c80"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "e31db40a7724332968bf23178c6867120c03304c2fddf04c611f858f169b811800"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "f0eda702ac7c8224ad278573660af582a62ef552a8136a95a06f967001b9d81280"
      ],
      "shifted": null
    }
  ],
  "coefficients_comm": [
    {
      "unshifted": [
        "8dcb26c25c70a937bf06aabd97294fd668192a7d03dc6fe4334be183628b6f2c80"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "2e94340fae7b22dd723eced300be207afe0bb78a1a3b3241a32282c0da8c632a00"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "adb98835474a18cb434b82b03224e0b59849971a17d935b9bb564f22299ac73200"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "000000000000000000000000000000000000000000000000000000000000000040"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "fb9defe1f6185e95cf0db3111d10f3ffdccd5b8c66b009088eeb77a95971412380"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "5ce86c3af1501bd9b2f52cf4968348404ba87f62769a098a6f1fe6a6f946501c80"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "000000000000000000000000000000000000000000000000000000000000000040"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "adb98835474a18cb434b82b03224e0b59849971a17d935b9bb564f22299ac73200"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "b0a92faff6d8822367f6fe3317ee736cc4c3e94ac889e9325305088619fff10c80"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "8c07920f03cdc6167becbf317cd5813e0e1c1a6687288178808e3bf1b0818e0f00"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "000000000000000000000000000000000000000000000000000000000000000040"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "000000000000000000000000000000000000000000000000000000000000000040"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "000000000000000000000000000000000000000000000000000000000000000040"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "000000000000000000000000000000000000000000000000000000000000000040"
      ],
      "shifted": null
    },
    {
      "unshifted": [
        "000000000000000000000000000000000000000000000000000000000000000040"
      ],
      "shifted": null
    }
  ],
  "generic_comm": {
    "unshifted": [
      "08d265f081130655eaec85eed48165efe8ffec4a66da6149d1fb3adb200d261280"
    ],
    "shifted": null
  },
  "psm_comm": {
    "unshifted": [
      "012226265bceb2e5a8c78be27579a29c3636787563f2b4aa99c901633860200980"
    ],
    "shifted": null
  },
  "complete_add_comm": {
    "unshifted": [
      "000000000000000000000000000000000000000000000000000000000000000040"
    ],
    "shifted": null
  },
  "mul_comm": {
    "unshifted": [
      "000000000000000000000000000000000000000000000000000000000000000040"
    ],
    "shifted": null
  },
  "emul_comm": {
    "unshifted": [
      "000000000000000000000000000000000000000000000000000000000000000040"
    ],
    "shifted": null
  },
  "endomul_scalar_comm": {
    "unshifted": [
      "000000000000000000000000000000000000000000000000000000000000000040"
    ],
    "shifted": null
  },
  "range_check0_comm": null,
  "range_check1_comm": null,
  "foreign_field_add_comm": null,
  "foreign_field_mul_comm": null,
  "xor_comm": null,
  "rot_comm": null,
  "shift": [
    "0100000000000000000000000000000000000000000000000000000000000000",
    "e3a214e91334d0caf1eb85df5bd7524d73d5eb7aaf742a7eb2d40bfdc8cdb900",
    "5a696526fa309c412c10e86604c3c0ad2cd9443dd85b823203721281cfbf3300",
    "11848e2c0bf18b0e9f7c8c34db4621b6c75afaa1e32d0f96164e9529bbf48700",
    "9358be9d3ef26bb05bbaaba8c3262e0bb65d36479694d15ef16c9f3b3771ec00",
    "106d491c728c240cf04564b85c586b4072a1f1641fd3684c08554ccc9791f300",
    "a3ee5991230c1903d2dfc543013c3567e0839a29a4e6d212eedb999703ddb800"
  ],
  "lookup_index": null
}

the reason why the domain looks weird in the example above is that the type is a CanonicalSerialize:

#[derive(Copy, Clone, Hash, Eq, PartialEq, CanonicalSerialize, CanonicalDeserialize)]
pub struct Radix2EvaluationDomain<F: FftField> {
    /// The size of the domain.
    pub size: u64,
    /// `log_2(self.size)`.
    pub log_size_of_group: u32,
    /// Size of the domain as a field element.
    pub size_as_field_element: F,
    /// Inverse of the size in the field.
    pub size_inv: F,
    /// A generator of the subgroup.
    pub group_gen: F,
    /// Inverse of the generator of the subgroup.
    pub group_gen_inv: F,
    /// Multiplicative generator of the finite field.
    pub generator_inv: F,
}

as such, when we serialize it, we first serialize that in bytes (via our serialization helper in utils/) and then serialize that again. Unfortunately, since arkworks doesn't support serde, this is what we get.

@mimoo mimoo requested a review from jspada March 10, 2023 14:55
@mimoo
Copy link
Contributor Author

mimoo commented Mar 10, 2023

ping @jspada or @querolita for review

Copy link
Contributor

@jspada jspada left a comment

Choose a reason for hiding this comment

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

Nice and simple - looks good to me.

@mimoo mimoo merged commit 9a16615 into master Mar 22, 2023
@mimoo mimoo deleted the mimoo/ser3 branch March 22, 2023 13:29
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.

improve JSON serialization of bytearrays
2 participants