| Crates.io | taceo-ark-serde-compat |
| lib.rs | taceo-ark-serde-compat |
| version | 0.3.0 |
| created_at | 2025-10-29 12:08:09.679199+00 |
| updated_at | 2025-12-10 13:20:03.07294+00 |
| description | Various serde compatibility implementations for arkworks-rs types, supporting both human-readable formats (JSON with decimal strings) and non-human readable formats (binary serialization using ark-serialize with compressed mode). The design choices are heavily influenced to work with Circom. |
| homepage | |
| repository | https://github.com/TaceoLabs/circom-helpers |
| max_upload_size | |
| id | 1906486 |
| size | 92,575 |
Various serialization helpers for serializing arkworks types using serde.
This crate provides serde-compatible serialization and deserialization functions for arkworks-rs types, supporting both human-readable and non-human readable formats:
ark-serialize with compressed mode for efficient binary serialization.bn254: Enables serialization support for BN254 curve typesbls12-381: Enables serialization support for BLS12-381 curve typesbabyjubjub: Enables serialization support for BabyJubJub curve typesNone of the features is enabled by default.
Use the provided functions with serde's field attributes:
use serde::{Serialize, Deserialize};
use ark_bn254::{Fr, G1Affine};
#[derive(Serialize, Deserialize)]
struct MyStruct {
#[serde(serialize_with = "taceo_ark_serde_compat::bn254::serialize_fr")]
#[serde(deserialize_with = "taceo_ark_serde_compat::bn254::deserialize_fr")]
scalar: Fr,
#[serde(serialize_with = "taceo_ark_serde_compat::bn254::serialize_g1")]
#[serde(deserialize_with = "taceo_ark_serde_compat::bn254::deserialize_g1")]
point: G1Affine,
}
Field elements (Fr, Fq) are serialized as decimal strings:
"12345678901234567890"
G1 points are serialized in projective coordinates [x, y, z]:
["1", "2", "1"]
The point at infinity is represented as:
["0", "1", "0"]
G2 points are serialized as [[x0, x1], [y0, y1], [z0, z1]]:
[["1", "2"], ["3", "4"], ["1", "0"]]
BabyJubJub points are serialized in affine coordinates [x, y]:
["123", "456"]
For non-human readable serializers like bincode and CBOR, all arkworks types are serialized using ark-serialize in compressed mode. This provides efficient binary serialization that is significantly more compact than the JSON representation.
The same serde attributes work for both human-readable and non-human readable formats:
use serde::{Serialize, Deserialize};
use ark_bn254::Fr;
#[derive(Serialize, Deserialize)]
struct MyStruct {
#[serde(serialize_with = "taceo_ark_serde_compat::serialize_f")]
#[serde(deserialize_with = "taceo_ark_serde_compat::deserialize_f")]
field: Fr,
}
// Example usage
let my_struct = MyStruct { field: Fr::from(42u64) };
// Works with JSON
let json = serde_json::to_string(&my_struct)?;
// Also works with bincode (uses compressed ark-serialize)
let binary = bincode::serde::encode_to_vec(&my_struct, bincode::config::standard())?;
See the repository LICENSE file for details.