From 76729bebff7ecd701d439b07f00f0f7828e1e5cd Mon Sep 17 00:00:00 2001 From: Dusan Klinec Date: Wed, 12 Sep 2018 16:19:54 +0200 Subject: [PATCH] xmr: tsx_sign removed --- src/apps/monero/protocol/tsx_sign.py | 266 --------------------------- 1 file changed, 266 deletions(-) delete mode 100644 src/apps/monero/protocol/tsx_sign.py diff --git a/src/apps/monero/protocol/tsx_sign.py b/src/apps/monero/protocol/tsx_sign.py deleted file mode 100644 index 5524a1f08..000000000 --- a/src/apps/monero/protocol/tsx_sign.py +++ /dev/null @@ -1,266 +0,0 @@ -import gc - -from trezor import log - -from apps.monero.controller import misc - - -class TsxSigner(object): - """ - Monero Transaction signer. - Provides interface to the host, packages messages. - """ - - def __init__(self): - self.ctx = None - self.tsx_ctr = 0 - self.err_ctr = 0 - self.tsx_obj = None # type: TTransactionBuilder - self.creds = None # type: apps.monero.xmr.sub.creds.AccountCreds - self.iface = None - self.purge = False - - async def tsx_exc_handler(self, e): - """ - Handles the exception thrown in the Trezor processing. Clears transaction state. - We could use decorator/wrapper for message calls but not sure how uPython handles them - so now are entry points wrapped in try-catch. - """ - if __debug__: - log.warning(__name__, "Transaction exception: %s: %s", type(e), e) - - self.err_ctr += 1 - self.purge = True - self.tsx_obj = None # clear transaction object - await self.iface.transaction_error(e) - - async def should_purge(self): - """ - Delete global state? - """ - return self.purge or (self.tsx_obj and self.tsx_obj.is_terminal()) - - def _mem_trace(self, x=None, collect=False): - if __debug__: - log.debug( - __name__, - "Log trace: %s, ... F: %s A: %s", - x, - gc.mem_free(), - gc.mem_alloc(), - ) - if collect: - gc.collect() - - async def setup(self, msg): - from apps.monero.controller import wrapper - - self.creds = await wrapper.monero_get_creds( - self.ctx, msg.address_n or (), msg.network_type - ) - - async def restore(self, state): - from apps.monero.protocol.tsx_sign_builder import TTransactionBuilder - - self.tsx_obj = TTransactionBuilder(self, creds=self.creds, state=state) - self._mem_trace("Restored", True) - - async def state_save(self): - s = self.tsx_obj.state_save() - self.tsx_obj = None - self._mem_trace("State saved", True) - return s - - async def wake_up(self, ctx, state, msg): - """ - Restore from the stored state - """ - from apps.monero.controller import iface - - self.ctx = ctx - self.iface = iface.get_iface(ctx) - gc.collect() - - self._mem_trace("wake_up()", True) - - if msg.init: - self._mem_trace("init") - await self.setup(msg.init) - - await self.restore(state if not msg.init else None) - self._mem_trace("wake_up() end", True) - - async def sign(self, msg): - """ - Main multiplex point - """ - self._mem_trace("sign()", True) - if msg.init: - self._mem_trace("sign_init") - return await self.tsx_init(msg.init.tsx_data) - elif msg.set_input: - self._mem_trace("sign_inp") - return await self.tsx_set_input(msg.set_input) - elif msg.input_permutation: - self._mem_trace("sign_perm") - return await self.tsx_inputs_permutation(msg.input_permutation) - elif msg.input_vini: - self._mem_trace("sign_vin") - return await self.tsx_input_vini(msg.input_vini) - elif msg.all_in_set: - self._mem_trace("all_in_set") - return await self.tsx_all_in_set(msg.all_in_set) - elif msg.set_output: - self._mem_trace("sign_out") - return await self.tsx_set_output1(msg.set_output) - elif msg.all_out_set: - self._mem_trace("sign_out_set") - return await self.tsx_all_out1_set(msg.all_out_set) - elif msg.mlsag_done: - self._mem_trace("sign_done") - return await self.tsx_mlsag_done() - elif msg.sign_input: - self._mem_trace("sign_sinp") - return await self.tsx_sign_input(msg.sign_input) - elif msg.final_msg: - self._mem_trace("sign_final") - return await self.tsx_sign_final(msg.final_msg) - else: - raise ValueError("Unknown message") - - async def tsx_init(self, tsx_data): - self.tsx_ctr += 1 - try: - return await self.tsx_obj.init_transaction(tsx_data, self.tsx_ctr) - except Exception as e: - await self.tsx_exc_handler(e) - raise - - async def tsx_set_input(self, msg): - """ - Sets UTXO one by one. - Computes spending secret key, key image. tx.vin[i] + HMAC, Pedersen commitment on amount. - - If number of inputs is small, in-memory mode is used = alpha, pseudo_outs are kept in the Trezor. - Otherwise pseudo_outs are offloaded with HMAC, alpha is offloaded encrypted under AES-GCM() with - key derived for exactly this purpose. - """ - try: - return await self.tsx_obj.set_input(msg.src_entr) - except Exception as e: - await self.tsx_exc_handler(e) - raise - - async def tsx_inputs_permutation(self, msg): - """ - Set permutation on the inputs - sorted by key image on host. - """ - try: - return await self.tsx_obj.tsx_inputs_permutation(msg.perm) - except Exception as e: - await self.tsx_exc_handler(e) - raise - - async def tsx_input_vini(self, msg): - """ - Set tx.vin[i] for incremental tx prefix hash computation. - After sorting by key images on host. - """ - try: - vini = await misc.parse_vini(msg.vini) - del msg.vini - - return await self.tsx_obj.input_vini( - msg.src_entr, vini, msg.vini_hmac, msg.pseudo_out, msg.pseudo_out_hmac - ) - except Exception as e: - await self.tsx_exc_handler(e) - raise - - async def tsx_all_in_set(self, msg): - """ - All inputs set. Defining rsig parameters. - """ - try: - return await self.tsx_obj.all_in_set(msg.rsig_data) - except Exception as e: - await self.tsx_exc_handler(e) - raise - - async def tsx_set_output1(self, msg): - """ - Set destination entry one by one. - Computes destination stealth address, amount key, range proof + HMAC, out_pk, ecdh_info. - """ - try: - dst, dst_hmac, rsig_data = msg.dst_entr, msg.dst_entr_hmac, msg.rsig_data - del (msg) - - return await self.tsx_obj.set_out1(dst, dst_hmac, rsig_data) - except Exception as e: - await self.tsx_exc_handler(e) - raise - - async def tsx_all_out1_set(self, msg=None): - """ - All outputs were set in this phase. Computes additional public keys (if needed), tx.extra and - transaction prefix hash. - Adds additional public keys to the tx.extra - - :return: tx.extra, tx_prefix_hash - """ - try: - return await self.tsx_obj.all_out1_set() - - except misc.TrezorTxPrefixHashNotMatchingError as e: - await self.tsx_exc_handler(e) - - from trezor.messages.Failure import Failure - - return Failure(code=10, message=str(e)) - - except Exception as e: - await self.tsx_exc_handler(e) - raise - - async def tsx_mlsag_done(self, msg=None): - """ - MLSAG message computed. - """ - try: - return await self.tsx_obj.mlsag_done() - except Exception as e: - await self.tsx_exc_handler(e) - raise - - async def tsx_sign_input(self, msg): - """ - Generates a signature for one input. - """ - try: - vini = await misc.parse_vini(msg.vini) - del msg.vini - - return await self.tsx_obj.sign_input( - msg.src_entr, - vini, - msg.vini_hmac, - msg.pseudo_out, - msg.pseudo_out_hmac, - msg.alpha_enc, - msg.spend_enc, - ) - except Exception as e: - await self.tsx_exc_handler(e) - raise - - async def tsx_sign_final(self, msg=None): - """ - Final message. - Offloading tx related data, encrypted. - """ - try: - return await self.tsx_obj.final_msg() - except Exception as e: - await self.tsx_exc_handler(e) - raise