Skip to content

Commit

Permalink
xmr: protob messages refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed Oct 18, 2018
1 parent e83085e commit d172f86
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src/apps/monero/key_image_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def _sync_step(s, ctx, tds):
# Encrypt with enc_key
nonce, ciph, _ = chacha_poly.encrypt(s.enc_key, buff)

kis.append(MoneroExportedKeyImage(iv=nonce, blob=ciph, tag=b""))
kis.append(MoneroExportedKeyImage(iv=nonce, blob=ciph))

return MoneroKeyImageSyncStepAck(kis=kis)

Expand Down
2 changes: 0 additions & 2 deletions src/apps/monero/layout/confirms.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ async def transaction_step(ctx, step, sub_step=None, sub_step_total=None):
elif step == 500:
info = ["Postprocessing..."]
elif step == 600:
info = ["Postprocessing..."]
elif step == 700:
info = ["Signing inputs", "%d/%d" % (sub_step + 1, sub_step_total)]
else:
info = ["Processing..."]
Expand Down
3 changes: 1 addition & 2 deletions src/apps/monero/protocol/signing/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class State:
STEP_ALL_IN = const(350)
STEP_OUT = const(400)
STEP_ALL_OUT = const(500)
STEP_MLSAG = const(600)
STEP_SIGN = const(700)
STEP_SIGN = const(600)

def __init__(self, ctx):
from apps.monero.xmr.sub.keccak_hasher import KeccakXmrArchive
Expand Down
10 changes: 1 addition & 9 deletions src/apps/monero/protocol/signing/step_01_init_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ async def init_transaction(
state.mixin = tsx_data.mixin
state.fee = tsx_data.fee
state.account_idx = tsx_data.account
if tsx_data.is_multisig:
raise NotImplementedError("Multisig is not implemented")

# Ensure change is correct
_check_change(state, tsx_data.outputs)
Expand Down Expand Up @@ -96,13 +94,7 @@ async def init_transaction(

rsig_data = MoneroTransactionRsigData(offload_type=state.rsig_offload)

return MoneroTransactionInitAck(
in_memory=False,
many_inputs=True,
many_outputs=True,
hmacs=hmacs,
rsig_data=rsig_data,
)
return MoneroTransactionInitAck(hmacs=hmacs, rsig_data=rsig_data)


def _check_subaddresses(state: State, outputs: list):
Expand Down
4 changes: 2 additions & 2 deletions src/apps/monero/protocol/signing/step_02_set_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ async def set_input(state: State, src_entr: MoneroTransactionSourceEntry):
vini_hmac=hmac_vini,
pseudo_out=pseudo_out,
pseudo_out_hmac=pseudo_out_hmac,
alpha_enc=alpha_enc,
spend_enc=spend_enc,
pseudo_out_alpha=alpha_enc,
spend_key=spend_enc,
)


Expand Down
24 changes: 23 additions & 1 deletion src/apps/monero/protocol/signing/step_07_all_outputs_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,19 @@ async def all_outputs_set(state: State):
rv_type=misc.get_monero_rct_type(state.rct_type, state.rsig_type),
)

_out_pk(state)
state.full_message_hasher.rctsig_base_done()
state.current_output_index = -1
state.current_input_index = -1

state.full_message = state.full_message_hasher.get_digest()
state.full_message_hasher = None

return MoneroTransactionAllOutSetAck(
extra=extra_b, tx_prefix_hash=state.tx_prefix_hash, rv=rv_pb
extra=extra_b,
tx_prefix_hash=state.tx_prefix_hash,
rv=rv_pb,
full_message_hash=state.full_message,
)


Expand Down Expand Up @@ -145,3 +156,14 @@ def _add_additional_tx_pub_keys_to_extra(tx_extra, pub_keys):

tx_extra += buffer
return tx_extra


def _out_pk(state: State):
"""
Hashes out_pk into the full message.
"""
if state.output_count != len(state.output_pk_commitments):
raise ValueError("Invalid number of ecdh")

for out in state.output_pk_commitments:
state.full_message_hasher.set_out_pk_commitment(out)
40 changes: 0 additions & 40 deletions src/apps/monero/protocol/signing/step_08_mlsag_done.py

This file was deleted.

5 changes: 2 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 @@ -119,7 +119,7 @@ async def sign_input(
)
state.assrt(
crypto.point_eq(
crypto.decodepoint(src_entr.outputs[src_entr.real_output].key.mask),
crypto.decodepoint(src_entr.outputs[src_entr.real_output].key.commitment),
crypto.gen_commitment(input_secret_key.mask, src_entr.amount),
),
"Real source entry's mask does not equal spend key's",
Expand Down Expand Up @@ -162,7 +162,6 @@ async def sign_input(

# Encode
mgs = _recode_msg([mg])
cout = None

gc.collect()
state.mem_trace(6)
Expand All @@ -172,7 +171,7 @@ async def sign_input(
)

return MoneroTransactionSignInputAck(
signature=misc.dump_msg_gc(mgs[0], preallocate=488), cout=cout
signature=misc.dump_msg_gc(mgs[0], preallocate=488)
)


Expand Down
12 changes: 2 additions & 10 deletions src/apps/monero/sign_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,6 @@ async def sign_tx_dispatch(state, msg):

return (
await step_07_all_outputs_set.all_outputs_set(state),
(MessageType.MoneroTransactionMlsagDoneRequest,),
)

elif msg.MESSAGE_WIRE_TYPE == MessageType.MoneroTransactionMlsagDoneRequest:
from apps.monero.protocol.signing import step_08_mlsag_done

return (
await step_08_mlsag_done.mlsag_done(state),
(MessageType.MoneroTransactionSignInputRequest,),
)

Expand All @@ -129,8 +121,8 @@ async def sign_tx_dispatch(state, msg):
msg.vini_hmac,
msg.pseudo_out,
msg.pseudo_out_hmac,
msg.alpha_enc,
msg.spend_enc,
msg.pseudo_out_alpha,
msg.spend_key,
),
(
MessageType.MoneroTransactionSignInputRequest,
Expand Down
4 changes: 2 additions & 2 deletions src/apps/monero/xmr/mlsag.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def generate_mlsag_full(
for j in range(rows):
M[i][j] = crypto.decodepoint(pubs[i][j].dest)
M[i][rows] = crypto.point_add(
M[i][rows], crypto.decodepoint(pubs[i][j].mask)
M[i][rows], crypto.decodepoint(pubs[i][j].commitment)
)

sk[rows] = crypto.sc_0()
Expand Down Expand Up @@ -126,7 +126,7 @@ def generate_mlsag_simple(message, pubs, in_sk, a, cout, kLRki, index):

for i in range(cols):
M[i][0] = crypto.decodepoint(pubs[i].dest)
M[i][1] = crypto.point_sub(crypto.decodepoint(pubs[i].mask), cout)
M[i][1] = crypto.point_sub(crypto.decodepoint(pubs[i].commitment), cout)

return generate_mlsag(message, M, sk, kLRki, index, dsRows)

Expand Down

0 comments on commit d172f86

Please sign in to comment.