diff --git a/src/apps/monero/protocol/tsx_sign_builder.py b/src/apps/monero/protocol/tsx_sign_builder.py index 88f0a2cd8..886c352fc 100644 --- a/src/apps/monero/protocol/tsx_sign_builder.py +++ b/src/apps/monero/protocol/tsx_sign_builder.py @@ -29,7 +29,7 @@ class TTransactionBuilder: STEP_MLSAG = const(600) STEP_SIGN = const(700) - def __init__(self, iface=None, creds=None, state=None, **kwargs): + def __init__(self, iface=None, creds=None): self.iface = iface self.creds = creds self.key_master = None @@ -78,11 +78,7 @@ def __init__(self, iface=None, creds=None, state=None, **kwargs): self.full_message_hasher = None self.full_message = None self.exp_tx_prefix_hash = None - - if state is None: - self._init() - else: - self.state_load(state) + self._init() def _init(self): from apps.monero.xmr.sub.keccak_hasher import KeccakXmrArchive @@ -94,63 +90,6 @@ def _init(self): self.tx_prefix_hasher = KeccakXmrArchive() self.full_message_hasher = PreMlsagHasher() - def state_load(self, t): - from apps.monero.protocol.tsx_sign_state import TState - - self._mem_trace("Restore: %s" % str(t.state) if __debug__ else None, True) - - for attr in t.__dict__: - if attr.startswith("_"): - continue - - cval = getattr(t, attr) - if cval is None: - setattr(self, attr, cval) - continue - - if attr == "state": - self.state = TState() - self.state.state_load(t.state) - elif attr == "tx_prefix_hasher": - from apps.monero.xmr.sub.keccak_hasher import KeccakXmrArchive - - self.tx_prefix_hasher = KeccakXmrArchive(ctx=t.tx_prefix_hasher) - elif attr == "full_message_hasher": - from apps.monero.xmr.sub.mlsag_hasher import PreMlsagHasher - - self.full_message_hasher = PreMlsagHasher(state=t.full_message_hasher) - else: - setattr(self, attr, cval) - gc.collect() - - def state_save(self): - from apps.monero.protocol.tsx_sign_state_holder import TsxSignStateHolder - - t = TsxSignStateHolder() - - for attr in self.__dict__: - if attr.startswith("_"): - continue - - cval = getattr(self, attr) - if cval is None: - setattr(t, attr, cval) - continue - - if attr == "state": - t.state = self.state.state_save() - elif attr in ["iface"]: - continue - elif attr.startswith("STEP"): - continue - elif attr == "tx_prefix_hasher": - t.tx_prefix_hasher = self.tx_prefix_hasher.ctx() - elif attr == "full_message_hasher": - t.full_message_hasher = self.full_message_hasher.state_save() - else: - setattr(t, attr, cval) - return t - def _mem_trace(self, x=None, collect=False): if __debug__: log.debug( diff --git a/src/apps/monero/protocol/tsx_sign_state_holder.py b/src/apps/monero/protocol/tsx_sign_state_holder.py deleted file mode 100644 index b17fda1eb..000000000 --- a/src/apps/monero/protocol/tsx_sign_state_holder.py +++ /dev/null @@ -1,56 +0,0 @@ -class TsxSignStateHolder: - """ - Simple transaction signer state holder. - Externalized state uses smaller amount of memory compared to storing the builder instance in the state. - Moreover the state contains stripped down attributes, i.e., instead of heavy hashers only sha3 context - is preserved and hashers are re-initialized on the next protocol step. - """ - - def __init__(self, **kwargs): - self.creds = None - self.key_master = None - self.key_hmac = None - self.key_enc = None - - self.r = None # txkey - self.r_pub = None - self.state = None - - self.multi_sig = False - self.need_additional_txkeys = False - self.use_bulletproof = False - self.use_rct = True - self.use_simple_rct = False - self.input_count = 0 - self.output_count = 0 - self.output_change = None - self.mixin = 0 - self.fee = 0 - self.account_idx = 0 - - self.additional_tx_private_keys = [] - self.additional_tx_public_keys = [] - self.inp_idx = -1 - self.out_idx = -1 - self.summary_inputs_money = 0 - self.summary_outs_money = 0 - self.input_secrets = [] - self.input_alphas = [] - self.input_pseudo_outs = [] - self.output_sk = [] - self.output_pk = [] - self.output_amounts = [] - self.output_masks = [] - self.rsig_type = 0 - self.rsig_grp = [] - self.rsig_offload = 0 - self.sumout = None - self.sumpouts_alphas = None - self.subaddresses = {} - self.tx = None - self.source_permutation = [] # sorted by key images - self.tx_prefix_hasher = None - self.tx_prefix_hash = None - self.full_message_hasher = None - self.full_message = None - self.exp_tx_prefix_hash = None diff --git a/src/apps/monero/sign_tx.py b/src/apps/monero/sign_tx.py index 5bdea9d97..0fd679199 100644 --- a/src/apps/monero/sign_tx.py +++ b/src/apps/monero/sign_tx.py @@ -37,24 +37,15 @@ async def sign_tx_step(ctx, msg, state): if msg.init: init = msg.init creds = await wrapper.monero_get_creds(ctx, init.address_n, init.network_type) - state = None - else: - creds = None - - tsx = TTransactionBuilder(iface.get_iface(ctx), creds, state) - del creds - del state + state = TTransactionBuilder(iface.get_iface(ctx), creds) + del creds gc.collect() - res = await sign_tx_dispatch(tsx, msg) + res = await sign_tx_dispatch(state, msg) gc.collect() - if tsx.is_terminal(): + if state.is_terminal(): state = None - else: - state = tsx.state_save() - - gc.collect() return res, state