1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-16 03:18:09 +00:00

nem: multisig correct serialization fix

This commit is contained in:
Tomas Susanka 2018-04-16 10:36:02 +02:00 committed by Jan Pochyla
parent 9a52039b25
commit 1355b19c77
8 changed files with 44 additions and 26 deletions

View File

@ -4,7 +4,10 @@ from trezor.messages.NEMSignTx import NEMSignTx
def serialize_mosaic_creation(msg: NEMSignTx, public_key: bytes):
w = write_common(msg.transaction, bytearray(public_key), NEM_TRANSACTION_TYPE_MOSAIC_CREATION)
common = msg.transaction
if msg.multisig:
common = msg.multisig
w = write_common(common, bytearray(public_key), NEM_TRANSACTION_TYPE_MOSAIC_CREATION)
mosaics_w = bytearray()
write_bytes_with_length(mosaics_w, bytearray(public_key))
@ -42,7 +45,10 @@ def serialize_mosaic_creation(msg: NEMSignTx, public_key: bytes):
def serialize_mosaic_supply_change(msg: NEMSignTx, public_key: bytes):
w = write_common(msg.transaction, bytearray(public_key), NEM_TRANSACTION_TYPE_MOSAIC_SUPPLY_CHANGE)
common = msg.transaction
if msg.multisig:
common = msg.multisig
w = write_common(common, bytearray(public_key), NEM_TRANSACTION_TYPE_MOSAIC_SUPPLY_CHANGE)
identifier_length = 4 + len(msg.supply_change.namespace) + 4 + len(msg.supply_change.mosaic)
write_uint32(w, identifier_length)

View File

@ -6,15 +6,15 @@ async def ask(ctx, msg: NEMSignTx):
await ask_multisig(ctx, msg)
def initiate(public_key, msg: NEMSignTx, inner_tx: bytes) -> bytes:
return serialize_multisig(msg.multisig, public_key, inner_tx)
def initiate(public_key, common: NEMTransactionCommon, inner_tx: bytes) -> bytes:
return serialize_multisig(common, public_key, inner_tx)
def cosign(public_key, msg: NEMSignTx, inner_tx: bytes) -> bytes:
return serialize_multisig_signature(msg.multisig,
def cosign(public_key, common: NEMTransactionCommon, inner_tx: bytes, signer: bytes) -> bytes:
return serialize_multisig_signature(common,
public_key,
inner_tx,
msg.multisig.signer)
signer)
async def aggregate_modification(ctx, public_key: bytes, msg: NEMSignTx):

View File

@ -10,7 +10,7 @@ async def ask_multisig(ctx, msg: NEMSignTx):
await _require_confirm_address(ctx, 'Cosign transaction for', address)
else:
await _require_confirm_address(ctx, 'Initiate transaction for', address)
await require_confirm_fee(ctx, 'Confirm multisig fee', msg.multisig.fee)
await require_confirm_fee(ctx, 'Confirm multisig fee', msg.transaction.fee)
async def ask_aggregate_modification(ctx, msg: NEMSignTx):

View File

@ -5,8 +5,8 @@ from trezor.crypto import hashlib
from trezor.crypto import nem
def serialize_multisig(msg: NEMTransactionCommon, public_key: bytes, inner: bytes):
w = write_common(msg, bytearray(public_key), NEM_TRANSACTION_TYPE_MULTISIG)
def serialize_multisig(common: NEMTransactionCommon, public_key: bytes, inner: bytes):
w = write_common(common, bytearray(public_key), NEM_TRANSACTION_TYPE_MULTISIG)
write_bytes_with_length(w, bytearray(inner))
return w
@ -24,11 +24,14 @@ def serialize_multisig_signature(common: NEMTransactionCommon, public_key: bytes
def serialize_aggregate_modification(msg: NEMSignTx, public_key: bytes):
version = msg.transaction.network << 24 | 1
common = msg.transaction
if msg.multisig:
common = msg.multisig
version = common.network << 24 | 1
if msg.aggregate_modification.relative_change:
version = msg.transaction.network << 24 | 2
version = common.network << 24 | 2
w = write_common(msg.transaction,
w = write_common(common,
bytearray(public_key),
NEM_TRANSACTION_TYPE_AGGREGATE_MODIFICATION,
version)

View File

@ -4,7 +4,10 @@ from trezor.messages.NEMSignTx import NEMSignTx
def serialize_provision_namespace(msg: NEMSignTx, public_key: bytes) -> bytearray:
tx = write_common(msg.transaction,
common = msg.transaction
if msg.multisig:
common = msg.multisig
tx = write_common(common,
bytearray(public_key),
NEM_TRANSACTION_TYPE_PROVISION_NAMESPACE)

View File

@ -38,9 +38,9 @@ async def sign_tx(ctx, msg: NEMSignTx):
if msg.multisig:
# wrap transaction in multisig wrapper
if msg.cosigning:
tx = multisig.cosign(_get_public_key(node), msg, tx)
tx = multisig.cosign(_get_public_key(node), msg.transaction, tx, msg.multisig.signer)
else:
tx = multisig.initiate(_get_public_key(node), msg, tx)
tx = multisig.initiate(_get_public_key(node), msg.transaction, tx)
signature = ed25519.sign(node.private_key(), tx, NEM_HASH_ALG)

View File

@ -6,10 +6,13 @@ from trezor.crypto import random
def serialize_transfer(msg: NEMSignTx, public_key: bytes, payload: bytes=None, encrypted: bool=False) -> bytearray:
tx = write_common(msg.transaction,
common = msg.transaction
if msg.multisig:
common = msg.multisig
tx = write_common(common,
bytearray(public_key),
NEM_TRANSACTION_TYPE_TRANSFER,
_get_version(msg.transaction.network, msg.transfer.mosaics))
_get_version(common.network, msg.transfer.mosaics))
write_bytes_with_length(tx, bytearray(msg.transfer.recipient))
write_uint64(tx, msg.transfer.amount)
@ -42,7 +45,10 @@ def serialize_mosaic(w: bytearray, namespace: str, mosaic: str, quantity: int):
def serialize_importance_transfer(msg: NEMSignTx, public_key: bytes) -> bytearray:
w = write_common(msg.transaction, bytearray(public_key), NEM_TRANSACTION_TYPE_IMPORTANCE_TRANSFER)
common = msg.transaction
if msg.multisig:
common = msg.multisig
w = write_common(common, bytearray(public_key), NEM_TRANSACTION_TYPE_IMPORTANCE_TRANSFER)
write_uint32(w, msg.importance_transfer.mode)
write_bytes_with_length(w, bytearray(msg.importance_transfer.public_key))

View File

@ -20,6 +20,7 @@ def validate(msg: NEMSignTx):
_validate_common(msg.transaction)
if msg.multisig:
_validate_common(msg.multisig, True)
_validate_multisig(msg.multisig, msg.transaction.network)
if not msg.multisig and msg.cosigning:
raise ValueError('No multisig transaction to cosign')
@ -76,12 +77,12 @@ def _validate_common(common: NEMTransactionCommon, inner: bool=False):
if common.deadline is None:
err = 'deadline'
# is_signer = common.signer is not None todo !!
# if inner != is_signer:
# if not inner:
# raise ValueError('Signer not allowed in outer transaction')
# err = 'signer'
#
if not inner and common.signer:
raise ValueError('Signer not allowed in outer transaction')
if inner and common.signer is None:
err = 'signer'
if err:
if inner:
raise ValueError('No ' + err + ' provided in inner transaction')
@ -106,7 +107,6 @@ def _validate_importance_transfer(importance_transfer: NEMImportanceTransfer):
def _validate_multisig(multisig: NEMTransactionCommon, network: int):
_validate_common(multisig)
_validate_public_key(multisig.signer, 'Invalid multisig signer public key provided')
if multisig.network != network:
raise ValueError('Inner transaction network is different')