algebra icon indicating copy to clipboard operation
algebra copied to clipboard

Serialization with modes

Open weikengchen opened this issue 3 years ago • 1 comments

When I was implementing serialization for certain data structures (manually), there appears to be a lot of repeated code that just calls the underlying function differently (e.g., deserialize vs deserialize_uncompressed).

This is similar to what has happened to AllocVar (https://github.com/arkworks-rs/r1cs-std/blob/master/src/alloc.rs#L9), which we eventually introduce modes:

/// Describes the mode that a variable should be allocated in within
/// a `ConstraintSystem`.
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Copy, Clone)]
pub enum AllocationMode {
    /// Indicate to the `ConstraintSystem` that the high-level variable should
    /// be allocated as a constant. That is, no `Variable`s should be
    /// generated.
    Constant = 0,

    /// Indicate to the `ConstraintSystem` that the high-level variable should
    /// be allocated as a public input to the `ConstraintSystem`.
    Input = 1,

    /// Indicate to the `ConstraintSystem` that the high-level variable should
    /// be allocated as a private witness to the `ConstraintSystem`.
    Witness = 2,
}

weikengchen avatar Dec 17 '20 10:12 weikengchen

See also the discussion here: https://github.com/arkworks-rs/algebra/pull/130#issuecomment-745746326

Pratyush avatar Dec 17 '20 10:12 Pratyush