Skip to content

Commit

Permalink
xmr: bp - gc.collect
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed Aug 26, 2018
1 parent 1bb6b5b commit d1d2e29
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/apps/monero/xmr/bulletproof.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,9 @@ def vector_exponent_custom(A, B, a, b, dst=None):
crypto.decodepoint_into(tmp_pt_4, B[i])
crypto.add_keys3_into(tmp_pt_1, tmp_sc_1, tmp_pt_3, tmp_sc_2, tmp_pt_4)
crypto.point_add_into(tmp_pt_2, tmp_pt_2, tmp_pt_1)
if i & 31 == 0:
gc.collect()

crypto.encodepoint_into(tmp_pt_2, dst)
return dst

Expand Down Expand Up @@ -602,6 +605,9 @@ def inner_product(a, b, dst=None):
crypto.decodeint_into_noreduce(tmp_sc_2, a[i])
crypto.decodeint_into_noreduce(tmp_sc_3, b[i])
crypto.sc_muladd_into(tmp_sc_1, tmp_sc_2, tmp_sc_3, tmp_sc_1)
if i & 31 == 0:
gc.collect()

crypto.encodeint_into(tmp_sc_1, dst)
return dst

Expand All @@ -610,6 +616,8 @@ def hadamard(a, b, dst=None):
dst = _ensure_dst_keyvect(dst, len(a))
for i in range(len(a)):
sc_mul(dst[i], a[i], b[i])
if i & 31 == 0:
gc.collect()
return dst


Expand Down Expand Up @@ -640,6 +648,9 @@ def hadamard_fold(v, a, b):
crypto.decodepoint_into(tmp_pt_2, v[h + i])
crypto.add_keys3_into(tmp_pt_3, tmp_sc_1, tmp_pt_1, tmp_sc_2, tmp_pt_2)
crypto.encodepoint_into(tmp_pt_3, v[i])
if i & 31 == 0:
gc.collect()

v.resize(h, realloc=True)
return v

Expand All @@ -665,6 +676,9 @@ def scalar_fold(v, a, b):
crypto.sc_mul_into(tmp_sc_4, tmp_sc_4, tmp_sc_2)
crypto.sc_add_into(tmp_sc_3, tmp_sc_3, tmp_sc_4)
crypto.encodeint_into(tmp_sc_3, v[i])
if i & 31 == 0:
gc.collect()

v.resize(h, realloc=True)
return v

Expand All @@ -686,6 +700,8 @@ def cross_inner_product(l0, r0, l1, r1):
crypto.sc_muladd_into(sc_t1_1, cl0, cr1, sc_t1_1)
crypto.sc_muladd_into(sc_t1_2, cl1, cr0, sc_t1_2)
crypto.sc_muladd_into(sc_t2, cl1, cr1, sc_t2)
if i & 31 == 0:
gc.collect()

crypto.sc_add_into(sc_t1_1, sc_t1_1, sc_t1_2)
return crypto.encodeint(sc_t1_1), crypto.encodeint(sc_t2)
Expand All @@ -695,6 +711,9 @@ def vector_gen(dst, size, op):
dst = _ensure_dst_keyvect(dst, size)
for i in range(size):
op(i, dst[i])
if i & 31 == 0:
gc.collect()

return dst


Expand Down Expand Up @@ -1546,6 +1565,9 @@ def _prove_batch_main(self, V, gamma, aL, aR, hash_cache, logM, logN, M, N):
Gprime[i] = Gprec[i]
scalarmult_key(Hprime[i], Hprec[i], yinvpow)
sc_mul(yinvpow, yinvpow, yinv)
if i & 31 == 0:
gc.collect()
self.gc(21)

L = _ensure_dst_keyvect(None, logMN)
R = _ensure_dst_keyvect(None, logMN)
Expand All @@ -1559,7 +1581,6 @@ def _prove_batch_main(self, V, gamma, aL, aR, hash_cache, logM, logN, M, N):

round = 0
_tmp_k_1 = _ensure_dst_key()
self.gc(21)

# PAPER LINE 13
while nprime > 1:
Expand Down Expand Up @@ -1976,7 +1997,8 @@ def verify_batch(self, proofs, single_optim=True):
if i != MN - 1:
sc_mul(yinvpow, yinvpow, yinv)
sc_mul(ypow, ypow, y)
self.gc(62)
if i & 15 == 0:
self.gc(62)

del (g_scalar, h_scalar, twoN)
self.gc(63)
Expand Down

0 comments on commit d1d2e29

Please sign in to comment.