Skip to content

Commit

Permalink
xmr: remove misc.StdObj
Browse files Browse the repository at this point in the history
  • Loading branch information
jpochyla authored and ph4r05 committed Sep 27, 2018
1 parent 8c8e3f3 commit 63cddd5
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 36 deletions.
17 changes: 0 additions & 17 deletions src/apps/monero/controller/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ class TrezorChangeAddressError(TrezorError):
pass


class StdObj:
def __init__(self, **kwargs):
for kw in kwargs:
setattr(self, kw, kwargs[kw])


def compute_tx_key(spend_key_private, tx_prefix_hash, salt=None, rand_mult=None):
from apps.monero.xmr import crypto

Expand Down Expand Up @@ -138,14 +132,3 @@ def dump_rsig_bp(rsig):
offset += 32
memcpy(buff, offset, rsig.t, 0, 32)
return buff


def dst_entry_to_stdobj(dst):
if dst is None:
return None

addr = StdObj(
spend_public_key=dst.addr.spend_public_key,
view_public_key=dst.addr.view_public_key,
)
return StdObj(amount=dst.amount, addr=addr, is_subaddress=dst.is_subaddress)
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 @@ -56,7 +56,7 @@ def __init__(self, ctx):
self.input_secrets = []
self.input_alphas = []
self.input_pseudo_outs = []
self.output_sk = []
self.output_sk_masks = []
self.output_pk = []
self.output_amounts = []
self.output_masks = []
Expand Down
6 changes: 4 additions & 2 deletions src/apps/monero/protocol/signing/step_01_init_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def init_transaction(state: State, address_n, network_type, tsx_data):
# Basic transaction parameters
state.input_count = tsx_data.num_inputs
state.output_count = len(tsx_data.outputs)
state.output_change = misc.dst_entry_to_stdobj(tsx_data.change_dts)
state.output_change = tsx_data.change_dts
state.mixin = tsx_data.mixin
state.fee = tsx_data.fee
state.account_idx = tsx_data.account
Expand Down Expand Up @@ -125,10 +125,12 @@ def get_primary_change_address(state: State):
"""
Computes primary change address for the current account index
"""
from trezor.messages.MoneroAccountPublicAddress import MoneroAccountPublicAddress

D, C = monero.generate_sub_address_keys(
state.creds.view_key_private, state.creds.spend_key_public, state.account_idx, 0
)
return misc.StdObj(
return MoneroAccountPublicAddress(
view_public_key=crypto.encodepoint(C), spend_public_key=crypto.encodepoint(D)
)

Expand Down
8 changes: 5 additions & 3 deletions src/apps/monero/protocol/signing/step_06_set_out1.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,21 @@ def _return_rsig_data(state, rsig):

def _set_out1_ecdh(state: State, dest_pub_key, amount, mask, amount_key):
from apps.monero.xmr import ring_ct
from apps.monero.xmr.serialize_messages.ct_keys import CtKey

# Mask sum
out_pk = misc.StdObj(
out_pk = CtKey(
dest=crypto.encodepoint(dest_pub_key),
mask=crypto.encodepoint(crypto.gen_commitment(mask, amount)),
)
state.sumout = crypto.sc_add(state.sumout, mask)
state.output_sk.append(misc.StdObj(mask=mask))
state.output_sk_masks.append(mask)

# ECDH masking
from apps.monero.xmr.serialize_messages.tx_ecdh import EcdhTuple
from apps.monero.xmr.sub.recode import recode_ecdh

ecdh_info = misc.StdObj(mask=mask, amount=crypto.sc_init(amount))
ecdh_info = EcdhTuple(mask=mask, amount=crypto.sc_init(amount))
ring_ct.ecdh_encode_into(
ecdh_info, ecdh_info, derivation=crypto.encodeint(amount_key)
)
Expand Down
7 changes: 4 additions & 3 deletions src/apps/monero/protocol/signing/step_09_sign_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from .state import State

from apps.monero.controller import misc
from apps.monero.xmr import common, crypto
from apps.monero.layout import confirms
from apps.monero.xmr import common, crypto


async def sign_input(
Expand Down Expand Up @@ -94,6 +94,7 @@ async def sign_input(

# Spending secret
from apps.monero.xmr.enc import chacha_poly
from apps.monero.xmr.serialize_messages.ct_keys import CtKey

input_secret = crypto.decodeint(
chacha_poly.decrypt_pack(
Expand All @@ -106,7 +107,7 @@ async def sign_input(

# Basic setup, sanity check
index = src_entr.real_output
in_sk = misc.StdObj(dest=input_secret, mask=crypto.decodeint(src_entr.mask))
in_sk = CtKey(dest=input_secret, mask=crypto.decodeint(src_entr.mask))
kLRki = src_entr.multisig_kLRki if state.multi_sig else None

# Private key correctness test
Expand Down Expand Up @@ -155,7 +156,7 @@ async def sign_input(
state.full_message,
mix_ring,
[in_sk],
state.output_sk,
state.output_sk_masks,
state.output_pk,
kLRki,
None,
Expand Down
7 changes: 5 additions & 2 deletions src/apps/monero/protocol_lite/lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,11 @@ async def mlsag_prehash_update(self):
return SW_OK

async def _req_dst(self, Aout, Bout, amount, is_sub=False):
addr = misc.StdObj(view_public_key=Aout, spend_public_key=Bout)
out = misc.StdObj(addr=addr, amount=amount, is_subaddress=is_sub)
from trezor.messages.MoneroAccountPublicAddress import MoneroAccountPublicAddress
from trezor.messages.MoneroTransactionDestinationEntry import MoneroTransactionDestinationEntry

addr = MoneroAccountPublicAddress(view_public_key=Aout, spend_public_key=Bout)
out = MoneroTransactionDestinationEntry(addr=addr, amount=amount, is_subaddress=is_sub)
await self.iface.confirm_out(out, False, self.creds, self.ctx)

async def mlsag_prehash_finalize(self):
Expand Down
6 changes: 3 additions & 3 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, out_pk, kLRki, mscout, index, txn_fee_key
message, pubs, in_sk, out_sk_mask, out_pk, 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) != len(out_pk):
if len(out_sk_mask) != len(out_pk):
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 Down Expand Up @@ -231,7 +231,7 @@ def prove_rct_mg(

for j in range(len(out_pk)):
sk[rows] = crypto.sc_sub(
sk[rows], out_sk[j].mask
sk[rows], out_sk_mask[j]
) # subtract output masks in last row

return gen_mlsag_ext(message, M, sk, kLRki, mscout, index, rows)
Expand Down
5 changes: 0 additions & 5 deletions src/apps/monero/xmr/sub/recode.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
from apps.monero.xmr import crypto
from apps.monero.xmr.serialize_messages.tx_ecdh import EcdhTuple


def copy_ecdh(ecdh):
return EcdhTuple(mask=ecdh.mask, amount=ecdh.amount)


def recode_ecdh(ecdh, encode=True):
Expand Down

0 comments on commit 63cddd5

Please sign in to comment.