boltlabs-inc / libzkchannels-crypto

Zero knowledge signatures and more
MIT License
4 stars 0 forks source link

Explain types used for payment amounts in cryptocurrencies #50

Closed marsella closed 3 years ago

marsella commented 3 years ago

In a Tezos contract, how is a payment amount / account balance represented? (Typewise - is it an i64?)

The zkAbacus API needs to define a transformation between a currency value (e.g. using the same type as in the contract) and scalar field from the pairing group.

jakinyele commented 3 years ago

Correct! We use i64 to represent account balances in the contract. @marsella @gijsvl Does the bls12-381 lib still provide a way to convert signed/unsigned integers into scalar fields?

marsella commented 3 years ago

It has a from_raw method that converts (little-endian) bytes into a Scalar. I'm not sure if that would handle bytes corresponding to a signed integer, though.

marsella commented 3 years ago

The documentation of the scalar type says

// The internal representation of this type is four 64-bit unsigned
// integers in little-endian order. `Scalar` values are always in
// Montgomery form; i.e., Scalar(a) = aR mod q, with R = 2^256.</span>

and that function just drops the bytes directly into the Scalar type, so I'm guessing it does not handle signed values. I think for negative values, we'll have to do the same subtraction step that Gijs implemented in v1.

marsella commented 3 years ago

@indomitableSwan This clarifies things for me. Did you have other questions?

indomitableSwan commented 3 years ago

No, the above makes sense to me.