Skip to content

Commit

Permalink
Merge commit 'ba500bf4ec1ef9cd953bdf5a47888c5226db8d0b' into xmr
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/apps/monero/__init__.py
#	src/apps/monero/key_image_sync.py
#	src/apps/monero/protocol/tsx_sign_builder.py
#	src/apps/monero/sign_tx.py
  • Loading branch information
ph4r05 committed Sep 13, 2018
1 parent ebc5430 commit c6e6ffa
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 81 deletions.
4 changes: 2 additions & 2 deletions src/apps/monero/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def __init__(self):
def boot():
wire.add(MessageType.MoneroGetAddress, __name__, "get_address")
wire.add(MessageType.MoneroGetWatchKey, __name__, "get_watch_only")
wire.add(MessageType.MoneroTransactionSignRequest, __name__, "sign_tx", STATE)
wire.add(MessageType.MoneroKeyImageSyncRequest, __name__, "key_image_sync", STATE)
wire.add(MessageType.MoneroTransactionSignRequest, __name__, "sign_tx")
wire.add(MessageType.MoneroKeyImageSyncRequest, __name__, "key_image_sync")

if hasattr(MessageType, "MoneroLiteInitRequest"):
wire.add(MessageType.MoneroLiteInitRequest, "lite_protocol", STATE, 1)
Expand Down
68 changes: 27 additions & 41 deletions src/apps/monero/key_image_sync.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,43 @@
import gc
import micropython

from trezor import log
from trezor.messages import MessageType


async def key_image_sync(ctx, msg, state):
log.debug(
__name__,
"### KI SYNC. Free: {} Allocated: {}".format(gc.mem_free(), gc.mem_alloc()),
)
log.debug(__name__, "KI sync state: %s", state.ctx_ki)
async def key_image_sync(ctx, msg):
state = None

from apps.monero.protocol import key_image_sync
while True:
res, state = await key_image_sync_step(ctx, msg, state)
if msg.final_msg:
break
msg = await ctx.call(res, MessageType.MoneroKeyImageSyncRequest)

log.debug(
__name__,
"### KI sync imported. Free: {} Allocated: {}".format(
gc.mem_free(), gc.mem_alloc()
),
)
return res

gc.collect()
micropython.mem_info()
micropython.mem_info(1)

try:
if msg.init:
log.debug(__name__, "ki_sync, init")
from apps.monero.controller import iface
async def key_image_sync_step(ctx, msg, state):
if __debug__:
log.debug(__name__, "f: %s a: %s", gc.mem_free(), gc.mem_alloc())
log.debug(__name__, "s: %s", state)

state.ctx_ki = key_image_sync.KeyImageSync(
ctx=ctx, iface=iface.get_iface(ctx)
)
return await state.ctx_ki.init(ctx, msg.init)
from apps.monero.protocol import key_image_sync

elif msg.step:
log.debug(__name__, "ki_sync, step")
return await state.ctx_ki.sync(ctx, msg.step)
if __debug__:
log.debug(__name__, "f: %s a: %s", gc.mem_free(), gc.mem_alloc())
gc.collect()

elif msg.final_msg:
log.debug(__name__, "ki_sync, final")
res = await state.ctx_ki.final(ctx, msg.final_msg)
state.ctx_ki = None
return res
if msg.init:
from apps.monero.controller import iface

else:
raise ValueError("Unknown error")
state = key_image_sync.KeyImageSync(ctx=ctx, iface=iface.get_iface(ctx))
return await state.init(ctx, msg.init), state

except Exception as e:
state.ctx_ki = None
elif msg.step:
return await state.sync(ctx, msg.step), state

log.debug(__name__, "KI error, %s: %s", type(e), e)
raise
# from trezor.messages.Failure import Failure
elif msg.final_msg:
return await state.final(ctx, msg.final_msg), None

# return Failure()
else:
raise ValueError("Unknown error")
26 changes: 13 additions & 13 deletions src/apps/monero/protocol/tsx_sign_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class TTransactionBuilder(object):
STEP_MLSAG = const(600)
STEP_SIGN = const(700)

def __init__(self, trezor=None, creds=None, state=None, **kwargs):
self.trezor = trezor
def __init__(self, iface=None, creds=None, state=None, **kwargs):
self.iface = iface
self.creds = creds
self.key_master = None
self.key_hmac = None
Expand Down Expand Up @@ -485,7 +485,7 @@ async def init_transaction(self, tsx_data, tsx_ctr):
self._log_trace(1)

# Ask for confirmation
confirmation = await self.trezor.iface.confirm_transaction(tsx_data, self.creds)
confirmation = await self.iface.confirm_transaction(tsx_data, self.creds)
if not confirmation:
from trezor.messages import FailureType
from trezor.messages.Failure import Failure
Expand Down Expand Up @@ -671,7 +671,7 @@ async def set_input(self, src_entr):
self.state.input()
self.inp_idx += 1

await self.trezor.iface.transaction_step(
await self.iface.transaction_step(
self.STEP_INP, self.inp_idx, self.num_inputs()
)

Expand Down Expand Up @@ -797,7 +797,7 @@ async def tsx_inputs_permutation(self, permutation):
MoneroTransactionInputsPermutationAck
)

await self.trezor.iface.transaction_step(self.STEP_PERM)
await self.iface.transaction_step(self.STEP_PERM)

if self.in_memory():
return
Expand Down Expand Up @@ -858,7 +858,7 @@ async def input_vini(self, src_entr, vini, hmac, pseudo_out, pseudo_out_hmac):
MoneroTransactionInputViniAck
)

await self.trezor.iface.transaction_step(
await self.iface.transaction_step(
self.STEP_VINI, self.inp_idx + 1, self.num_inputs()
)

Expand Down Expand Up @@ -921,7 +921,7 @@ async def all_in_set(self, rsig_data):
"""
self._log_trace(0)
self.state.input_all_done()
await self.trezor.iface.transaction_step(self.STEP_ALL_IN)
await self.iface.transaction_step(self.STEP_ALL_IN)

from trezor.messages.MoneroTransactionAllInputsSetAck import (
MoneroTransactionAllInputsSetAck
Expand Down Expand Up @@ -1249,7 +1249,7 @@ async def set_out1(self, dst_entr, dst_entr_hmac, rsig_data=None):
self._log_trace(0, True)
mods = utils.unimport_begin()

await self.trezor.iface.transaction_step(
await self.iface.transaction_step(
self.STEP_OUT, self.out_idx + 1, self.num_dests()
)
self._log_trace(1)
Expand Down Expand Up @@ -1366,7 +1366,7 @@ async def all_out1_set(self):
"""
self._log_trace(0)
self.state.set_output_done()
await self.trezor.iface.transaction_step(self.STEP_ALL_OUT)
await self.iface.transaction_step(self.STEP_ALL_OUT)
self._log_trace(1)

if self.out_idx + 1 != self.num_dests():
Expand Down Expand Up @@ -1461,7 +1461,7 @@ async def mlsag_done(self):
)

self.state.set_final_message_done()
await self.trezor.iface.transaction_step(self.STEP_MLSAG)
await self.iface.transaction_step(self.STEP_MLSAG)

await self.tsx_mlsag_ecdh_info()
await self.tsx_mlsag_out_pk()
Expand Down Expand Up @@ -1499,7 +1499,7 @@ async def sign_input(
:return: Generated signature MGs[i]
"""
self.state.set_signature()
await self.trezor.iface.transaction_step(
await self.iface.transaction_step(
self.STEP_SIGN, self.inp_idx + 1, self.num_inputs()
)

Expand Down Expand Up @@ -1644,7 +1644,7 @@ async def sign_input(
# Final state transition
if self.inp_idx + 1 == self.num_inputs():
self.state.set_signature_done()
await self.trezor.iface.transaction_signed()
await self.iface.transaction_signed()

gc.collect()
self._log_trace()
Expand Down Expand Up @@ -1684,7 +1684,7 @@ async def final_msg(self, *args, **kwargs):
)
tx_enc_keys = chacha_poly.encrypt_pack(tx_key, key_buff)

await self.trezor.iface.transaction_finished()
await self.iface.transaction_finished()
gc.collect()

return MoneroTransactionFinalAck(
Expand Down
Loading

0 comments on commit c6e6ffa

Please sign in to comment.