Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
xmr: getting rid of CtKey from the state
Browse files Browse the repository at this point in the history
- only lightweight objects are kept in the state. CtKey is import heavy object. Each set_out call locally imports a new own version of the Ctkey which causes a memory leak.
  • Loading branch information
ph4r05 committed Sep 27, 2018
1 parent c0cfc20 commit 14265eb
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/apps/monero/protocol/signing/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, ctx):
self.input_alphas = []
self.input_pseudo_outs = []
self.output_sk_masks = []
self.output_pk = []
self.output_pk_masks = [] # commitments
self.output_amounts = []
self.output_masks = []
self.rsig_type = 0
Expand Down
2 changes: 1 addition & 1 deletion src/apps/monero/protocol/signing/step_06_set_out1.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async def set_out1(state: State, dst_entr, dst_entr_hmac, rsig_data=None):

# Output_pk is stored to the state as it is used during the signature and hashed to the
# RctSigBase later.
state.output_pk.append(out_pk)
state.output_pk_masks.append(out_pk.mask)
state.mem_trace(14, True)

from trezor.messages.MoneroTransactionSetOutputAck import (
Expand Down
6 changes: 3 additions & 3 deletions src/apps/monero/protocol/signing/step_08_mlsag_done.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def _out_pk(state: State):
"""
Sets out_pk for the incremental hashing mlsag.
"""
if state.output_count != len(state.output_pk):
if state.output_count != len(state.output_pk_masks):
raise ValueError("Invalid number of ecdh")

for out in state.output_pk:
state.full_message_hasher.set_out_pk(out)
for out in state.output_pk_masks:
state.full_message_hasher.set_out_pk_mask(out)
2 changes: 1 addition & 1 deletion src/apps/monero/protocol/signing/step_09_sign_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ async def sign_input(
mix_ring,
[in_sk],
state.output_sk_masks,
state.output_pk,
state.output_pk_masks,
kLRki,
None,
index,
Expand Down
10 changes: 5 additions & 5 deletions src/apps/monero/xmr/mlsag2.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def gen_mlsag_ext(message, pk, xx, kLRki, mscout, index, dsRows):


def prove_rct_mg(
message, pubs, in_sk, out_sk_mask, out_pk, kLRki, mscout, index, txn_fee_key
message, pubs, in_sk, out_sk_mask, out_pk_mask, kLRki, mscout, index, txn_fee_key
):
"""
c.f. http://eprint.iacr.org/2015/1098 section 4. definition 10.
Expand All @@ -197,7 +197,7 @@ def prove_rct_mg(

if len(in_sk) != rows:
raise ValueError("Bad inSk size")
if len(out_sk_mask) != len(out_pk):
if len(out_sk_mask) != len(out_pk_mask):
raise ValueError("Bad outsk/putpk size")
if (not kLRki or not mscout) and (kLRki and mscout):
raise ValueError("Only one of kLRki/mscout is present")
Expand All @@ -221,15 +221,15 @@ def prove_rct_mg(
sk[rows] = crypto.sc_add(sk[rows], in_sk[j].mask) # add masks in last row

for i in range(cols):
for j in range(len(out_pk)):
for j in range(len(out_pk_mask)):
M[i][rows] = crypto.point_sub(
M[i][rows], crypto.decodepoint(out_pk[j].mask)
M[i][rows], crypto.decodepoint(out_pk_mask[j])
) # subtract output Ci's in last row

# Subtract txn fee output in last row
M[i][rows] = crypto.point_sub(M[i][rows], txn_fee_key)

for j in range(len(out_pk)):
for j in range(len(out_pk_mask)):
sk[rows] = crypto.sc_sub(
sk[rows], out_sk_mask[j]
) # subtract output masks in last row
Expand Down
4 changes: 2 additions & 2 deletions src/apps/monero/xmr/sub/mlsag_hasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ def set_ecdh(self, ecdh):
self.state = 4
self.rtcsig_hasher.buffer(ecdh)

def set_out_pk(self, out_pk):
def set_out_pk_mask(self, out_pk_mask):
if self.state != 4 and self.state != 5:
raise ValueError("State error")
self.state = 5
self.rtcsig_hasher.buffer(out_pk.mask) # ECKey
self.rtcsig_hasher.buffer(out_pk_mask) # ECKey

def rctsig_base_done(self):
if self.state != 5:
Expand Down

0 comments on commit 14265eb

Please sign in to comment.