#serialization #scale #arkworks #parity #wrapped #codec #traits

no-std ark-scale

Arkworks serialization wrapped in Parity SCALE codec

7 releases

0.0.12 Dec 5, 2023
0.0.11 Sep 23, 2023
0.0.10 Aug 29, 2023
0.0.3 May 16, 2023
0.0.2 Apr 14, 2023

#1049 in Magic Beans

Download history 54433/week @ 2024-03-14 66379/week @ 2024-03-21 70064/week @ 2024-03-28 84790/week @ 2024-04-04 75764/week @ 2024-04-11 66814/week @ 2024-04-18 54136/week @ 2024-04-25 52359/week @ 2024-05-02 49825/week @ 2024-05-09 48874/week @ 2024-05-16 75148/week @ 2024-05-23 64553/week @ 2024-05-30 45375/week @ 2024-06-06 54362/week @ 2024-06-13 56889/week @ 2024-06-20 39650/week @ 2024-06-27

206,513 downloads per month
Used in 17 crates (10 directly)

MIT/Apache

34KB
611 lines

Arkworks serialization wrapped in Parity SCALE codec

ArkScale(T) can be serialized or deserialized using parity-scale-codec, provided T can be serialized or deserialized using ark-serialize.

Arkworks serializes via the std::io::{Read,Write} traits, or its no_std fork of those traits, as do other zcash sapling derivatives. At its core, Parity SCALE codec also consists of traits {Input,Output} analogous to std::io::{Read,Write} respectively, as well as traits {Decode,Encode} also quite similar to ark-serialize::{CanonicalDeserialize,CanonicalSerialize}. We simply translate between these extremely similar traits, including wrapping and unwrapping errors appropriately.

ArkScale cannot easily implement MaxEncodedLen or ConstEncodedLen from SCALE, due to the orphan rules. You'll need these if using weights in Frame, so you should usually create wrapper types around ArkScale. As a rule, anytime you choose curves then you'll have a conditionanl ark-substrate dependence anyways, so wrapper types should not become too onerous, and they likely improve documentation, errors, etc anyways.

ArkScale panics if serialization fails because SCALE does not propogate serialization failures. As scale outputs cannot fail, and ark-scale-derive does not introduce failures, we therefore cannot trigger this panic except by some explicit impl CanonicalSerialize for T intrpducing a failure. ArkScale users should therefore be responcible for reviewing non-derived CanonicalSerialize in their dependencies. In particular, there are no fresh failures in arkworks/algebra:

git clone https://github.com/arkworks-rs/algebra
cd algebra
grep -r --include '*.rs' 'CanonicalSerialize for' -A 10 ff* ec* poly/ | less

This becomes slightly harder if Implementable trait aliases lands.

Dependencies

~4–5MB
~107K SLoC