Generate a valid Jubjub point for SpendDescription test vectors

This commit is contained in:
Jack Grigg 2018-10-11 18:37:24 +01:00
parent 284942d46b
commit 3f9edde19f
No known key found for this signature in database
GPG Key ID: 1B8D649257DB0829
3 changed files with 12 additions and 4 deletions

View File

@ -142,6 +142,14 @@ JUBJUB_D = Fq(-10240) / Fq(10241)
JUBJUB_COFACTOR = Fr(8)
class Point(object):
@staticmethod
def rand(rand):
while True:
data = rand.b(32)
p = Point.from_bytes(data)
if p:
return p
@staticmethod
def from_bytes(buf):
assert len(buf) == 32

View File

@ -2,7 +2,7 @@
import struct
from sapling_generators import find_group_hash, SPENDING_KEY_BASE
from sapling_jubjub import Fq
from sapling_jubjub import Fq, Point
from sapling_utils import leos2ip
from zc_utils import write_compact_size
@ -80,7 +80,7 @@ class SpendDescription(object):
self.cv = find_group_hash(b'TVRandPt', rand.b(32))
self.anchor = Fq(leos2ip(rand.b(32)))
self.nullifier = rand.b(32)
self.rk = rand.b(32)
self.rk = Point.rand(rand)
self.proof = GrothProof(rand)
self.spendAuthSig = rand.b(64) # Invalid
@ -89,7 +89,7 @@ class SpendDescription(object):
bytes(self.cv) +
bytes(self.anchor) +
self.nullifier +
self.rk +
bytes(self.rk) +
bytes(self.proof) +
self.spendAuthSig
)

View File

@ -31,7 +31,7 @@ def getHashShieldedSpends(tx):
digest.update(bytes(desc.cv))
digest.update(bytes(desc.anchor))
digest.update(desc.nullifier)
digest.update(desc.rk)
digest.update(bytes(desc.rk))
digest.update(bytes(desc.proof))
return digest.digest()