HarryR / ethsnarks

A toolkit for viable zk-SNARKS on Ethereum, Web, Mobile and Desktop
GNU Lesser General Public License v3.0
240 stars 57 forks source link

No tests for EdDSA.sol #117

Open HarryR opened 5 years ago

HarryR commented 5 years ago

The EdDSA.sol file doesn't have any tests for it, it also seems to be incompatible for the following reasons:

The following code should produce valid signatures for the scheme in EdDSA.sol, but whenever I try testing in Remix it hangs the browser.

from ethsnarks.eddsa import _SignatureScheme, as_scalar
from hashlib import sha256

class SHA256EdDSA(_SignatureScheme):
    @classmethod
    def hash_public(cls, R, A, M):
        args = [R.x.n, R.y.n, A.x.n, A.y, M]
        msg = b''.join([int.to_bytes(_, 32, 'big') for _ in as_scalar(*args)])
        hashed_msg = sha256(msg).digest()
        return int.from_bytes(hashed_msg, 'big') & ((2<<249) - 1)

msg = 1234
k, A = SHA256EdDSA.random_keypair()
smsg = SHA256EdDSA.sign(1234, k)
SHA256EdDSA.verify(A, smsg.sig, msg)

args_for_contract = [A, msg, smsg.sig.R, smsg.sig.s]