From d1d2e29c7f154651026c1c666c5eeb589396bc8e Mon Sep 17 00:00:00 2001 From: Dusan Klinec Date: Sun, 26 Aug 2018 17:10:50 +0200 Subject: [PATCH] xmr: bp - gc.collect --- src/apps/monero/xmr/bulletproof.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/apps/monero/xmr/bulletproof.py b/src/apps/monero/xmr/bulletproof.py index cf7858830..91fd22261 100644 --- a/src/apps/monero/xmr/bulletproof.py +++ b/src/apps/monero/xmr/bulletproof.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) @@ -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 @@ -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) @@ -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: @@ -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)