boltlabs-inc / tezos-contract

Multi-sig Smart Contract for zkChannels protocol
MIT License
3 stars 1 forks source link

Pairing check fails if balance is 0 #11

Closed DariusParvin closed 3 years ago

DariusParvin commented 3 years ago

Right now, if the customer or merchant has a balance of 0, when @custClose is called, the pairing check will fail at the point where we multiply the merchant's PS pubkey (g2) by the balance (fr):

for i in range(0, len(msg)):
    prod1.value += sp.mul(pk[i], msg[i])

If msg[i] is 0 (as with a 0 balance), then it'll throw an error because the bls library won't let you multiply by a non positive integer.

The error comes from here: https://github.com/paulmillr/noble-bls12-381/blob/master/math.js#L833

@indomitableSwan @jakinyele

indomitableSwan commented 3 years ago

This is a giant red flag for this library. The library should handle point multiplication by zero automatically and give you back the point at infinity here (i.e., the identity element of G2).

indomitableSwan commented 3 years ago

@jakinyele What selection and vetting process did we use for this library?

jakinyele commented 3 years ago

@indomitableSwan um, to be clear ... this JavaScript lib is a pure reimplementation of BLS that is integrated into the SmartPy online IDE. So, not something we selected.

I suspect we'd get a different result if we tested against the BLS lib integrated directly into Michelson (from ECC and wrapped in Ocaml by NL). But in any case, @DariusParvin has reported the issue to the SmartPy devs.

DariusParvin commented 3 years ago

Yeah that's right. I just tested a custClose on testnet with a 0 balance and it went through fine. So this issue is limited to SmartPy