Crate ark_scale

Source
Expand description

§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.

Re-exports§

pub use ark_serialize;
pub use scale_codec as scale;

Modules§

rw

Macros§

impl_body_max_encode_len
Implement body of scale::MaxEncodedLen by delegation to ark_std::Zero and CanonicalSerialize, usable from polymorphic code.
impl_decode_via_ark
Implement body of scale::Decode by delegation to ArkScale, usable from polymorphic code.
impl_encode_via_ark
Implement body of scale::Encode by delegation to ArkScale, usable from polymorphic code.
impl_scale_via_ark
Implement scale::{Encode,Decode} by delegation to ArkScale, but lacks support for polymorphic code.

Structs§

ArkScale
Arkworks type wrapped for serialization by Scale
ArkScaleLen
Arkworks type wrapped for serialization by Scale
ArkScaleRef

Constants§

HOST_CALL
ArkScale usage which neither compresses nor validates inputs, only for usage in host calls and on-chain storage where the runtime already performed validation checks.
WIRE
ArkScale usage for typical wire formats, like block data and gossip messages. Always safe.

Traits§

ArkScaleMaxEncodedLen
An orphan rules helper which provides impl scale::MaxEncodedLen for ArkScale<T,WIRE>
MaxEncodedLen
Items implementing MaxEncodedLen have a statically known maximum encoded size.

Functions§

is_compressed
is_validated
iter_ark_to_ark_bytes
Arkworks’ CanonicalSerialize cannot consume Iterators directly, but iter_ark_to_ark_bytes serializes exactly like Vec<T>, &'a [T], or [T] do with CanonicalSerialize.
iter_ark_to_scale_bytes
Arkworks’ CanonicalSerialize cannot consume Iterators directly, but iter_ark_to_scale_bytes serializes exactly like ArkScale(Vec<T>), ArkScale(&'a [T]), or ArkScale([T]) do under parity_scale_codec::Encode.
make_usage
Arkworks’ serialization modes hack.

Type Aliases§

Usage
Arkworks’ serialization modes, morally (Compress, Validate) but const generics only supports integers, bool and char right now.

Derive Macros§

MaxEncodedLen
Derive parity_scale_codec::MaxEncodedLen for struct and enum.