Pass rand instead of randbytes
Co-authored-by: str4d <jack@z.cash>
This commit is contained in:
parent
af04017407
commit
fb08eeeb39
|
@ -18,8 +18,8 @@ def homomorphic_pedersen_commitment(rcv: Scalar, D, v: Scalar):
|
||||||
def value_commit(rcv: Scalar, v: Scalar):
|
def value_commit(rcv: Scalar, v: Scalar):
|
||||||
return homomorphic_pedersen_commitment(rcv, b"z.cash:Orchard-cv", v)
|
return homomorphic_pedersen_commitment(rcv, b"z.cash:Orchard-cv", v)
|
||||||
|
|
||||||
def rcv_trapdoor(randbytes):
|
def rcv_trapdoor(rand):
|
||||||
return Scalar.random(randbytes)
|
return Scalar.random(rand)
|
||||||
|
|
||||||
# https://zips.z.cash/protocol/nu5.pdf#concretesinsemillacommit
|
# https://zips.z.cash/protocol/nu5.pdf#concretesinsemillacommit
|
||||||
def sinsemilla_commit(r: Scalar, D, M):
|
def sinsemilla_commit(r: Scalar, D, M):
|
||||||
|
@ -39,8 +39,8 @@ def note_commit(rcm, g_d, pk_d, v, rho, psi):
|
||||||
g_d + pk_d + i2lebsp(64, v) + i2lebsp(L_ORCHARD_BASE, rho.s) + i2lebsp(L_ORCHARD_BASE, psi.s)
|
g_d + pk_d + i2lebsp(64, v) + i2lebsp(L_ORCHARD_BASE, rho.s) + i2lebsp(L_ORCHARD_BASE, psi.s)
|
||||||
)
|
)
|
||||||
|
|
||||||
def rcm_trapdoor(randbytes):
|
def rcm_trapdoor(rand):
|
||||||
return Scalar.random(randbytes)
|
return Scalar.random(rand)
|
||||||
|
|
||||||
# https://zips.z.cash/protocol/nu5.pdf#concreteorchardnotecommit
|
# https://zips.z.cash/protocol/nu5.pdf#concreteorchardnotecommit
|
||||||
def commit_ivk(rivk: Scalar, ak: Fp, nk: Fp):
|
def commit_ivk(rivk: Scalar, ak: Fp, nk: Fp):
|
||||||
|
@ -50,12 +50,13 @@ def commit_ivk(rivk: Scalar, ak: Fp, nk: Fp):
|
||||||
i2lebsp(L_ORCHARD_BASE, ak.s) + i2lebsp(L_ORCHARD_BASE, nk.s)
|
i2lebsp(L_ORCHARD_BASE, ak.s) + i2lebsp(L_ORCHARD_BASE, nk.s)
|
||||||
).s)
|
).s)
|
||||||
|
|
||||||
def rivk_trapdoor(randbytes):
|
def rivk_trapdoor(rand):
|
||||||
return Scalar.random(randbytes)
|
return Scalar.random(rand)
|
||||||
|
|
||||||
# Test consistency of ValueCommit^{Orchard} with precomputed generators
|
# Test consistency of ValueCommit^{Orchard} with precomputed generators
|
||||||
def test_value_commit():
|
def test_value_commit():
|
||||||
from random import Random
|
from random import Random
|
||||||
|
from tv_rand import Rand
|
||||||
from orchard_generators import VALUE_COMMITMENT_RANDOMNESS_BASE, VALUE_COMMITMENT_VALUE_BASE
|
from orchard_generators import VALUE_COMMITMENT_RANDOMNESS_BASE, VALUE_COMMITMENT_VALUE_BASE
|
||||||
|
|
||||||
rng = Random(0xabad533d)
|
rng = Random(0xabad533d)
|
||||||
|
@ -64,8 +65,9 @@ def test_value_commit():
|
||||||
while len(ret) < l:
|
while len(ret) < l:
|
||||||
ret.append(rng.randrange(0, 256))
|
ret.append(rng.randrange(0, 256))
|
||||||
return bytes(ret)
|
return bytes(ret)
|
||||||
|
rand = Rand(randbytes)
|
||||||
|
|
||||||
rcv = rcv_trapdoor(randbytes)
|
rcv = rcv_trapdoor(rand)
|
||||||
v = Scalar(100000000)
|
v = Scalar(100000000)
|
||||||
|
|
||||||
assert value_commit(rcv, v) == VALUE_COMMITMENT_RANDOMNESS_BASE * rcv + VALUE_COMMITMENT_VALUE_BASE * v
|
assert value_commit(rcv, v) == VALUE_COMMITMENT_RANDOMNESS_BASE * rcv + VALUE_COMMITMENT_VALUE_BASE * v
|
||||||
|
|
|
@ -31,10 +31,10 @@ class Fp(FieldElement):
|
||||||
def from_bytes(buf):
|
def from_bytes(buf):
|
||||||
return Fp(leos2ip(buf), strict=True)
|
return Fp(leos2ip(buf), strict=True)
|
||||||
|
|
||||||
def random(randbytes):
|
def random(rand):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
return Fp(leos2ip(randbytes(32)), strict=True)
|
return Fp(leos2ip(rand.b(32)), strict=True)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -101,10 +101,10 @@ class Scalar(FieldElement):
|
||||||
def from_bytes(buf):
|
def from_bytes(buf):
|
||||||
return Scalar(leos2ip(buf), strict=True)
|
return Scalar(leos2ip(buf), strict=True)
|
||||||
|
|
||||||
def random(randbytes):
|
def random(rand):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
return Scalar(leos2ip(randbytes(32)), strict=True)
|
return Scalar(leos2ip(rand.b(32)), strict=True)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue