1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

fix(core/eos): review usages of write_bytes_unchecked

This commit is contained in:
matejcik 2021-01-14 16:15:55 +01:00 committed by Tomas Susanka
parent 6acc1cd6ab
commit 5b5ed8cce1
3 changed files with 14 additions and 16 deletions

View File

@ -67,8 +67,7 @@ async def process_action(
await process_unknown_action(ctx, w, action) await process_unknown_action(ctx, w, action)
writers.write_action_common(sha, action.common) writers.write_action_common(sha, action.common)
writers.write_variant32(sha, len(w)) writers.write_bytes_prefixed(sha, w)
writers.write_bytes_unchecked(sha, w)
async def process_unknown_action( async def process_unknown_action(

View File

@ -32,7 +32,7 @@ async def sign_tx(ctx: wire.Context, msg: EosSignTx, keychain: Keychain) -> EosS
await _init(ctx, sha, msg) await _init(ctx, sha, msg)
await _actions(ctx, sha, msg.num_actions) await _actions(ctx, sha, msg.num_actions)
writers.write_variant32(sha, 0) writers.write_variant32(sha, 0)
writers.write_bytes_unchecked(sha, bytearray(32)) writers.write_bytes_fixed(sha, bytearray(32), 32)
digest = sha.get_digest() digest = sha.get_digest()
signature = secp256k1.sign( signature = secp256k1.sign(
@ -43,7 +43,7 @@ async def sign_tx(ctx: wire.Context, msg: EosSignTx, keychain: Keychain) -> EosS
async def _init(ctx: wire.Context, sha: HashWriter, msg: EosSignTx) -> None: async def _init(ctx: wire.Context, sha: HashWriter, msg: EosSignTx) -> None:
writers.write_bytes_unchecked(sha, msg.chain_id) writers.write_bytes_fixed(sha, msg.chain_id, 32)
writers.write_header(sha, msg.header) writers.write_header(sha, msg.header)
writers.write_variant32(sha, 0) writers.write_variant32(sha, 0)
writers.write_variant32(sha, msg.num_actions) writers.write_variant32(sha, msg.num_actions)

View File

@ -1,4 +1,7 @@
from protobuf import dump_uvarint
from apps.common.writers import ( from apps.common.writers import (
write_bytes_fixed,
write_bytes_unchecked, write_bytes_unchecked,
write_uint8, write_uint8,
write_uint16_le, write_uint16_le,
@ -31,7 +34,7 @@ def write_auth(w: Writer, auth: EosAuthorization) -> None:
write_variant32(w, len(auth.keys)) write_variant32(w, len(auth.keys))
for key in auth.keys: for key in auth.keys:
write_variant32(w, key.type) write_variant32(w, key.type)
write_bytes_unchecked(w, key.key) write_bytes_fixed(w, key.key, 33)
write_uint16_le(w, key.weight) write_uint16_le(w, key.weight)
write_variant32(w, len(auth.accounts)) write_variant32(w, len(auth.accounts))
@ -59,8 +62,7 @@ def write_action_transfer(w: Writer, msg: EosActionTransfer) -> None:
write_uint64_le(w, msg.sender) write_uint64_le(w, msg.sender)
write_uint64_le(w, msg.receiver) write_uint64_le(w, msg.receiver)
write_asset(w, msg.quantity) write_asset(w, msg.quantity)
write_variant32(w, len(msg.memo)) write_bytes_prefixed(w, msg.memo)
write_bytes_unchecked(w, msg.memo)
def write_action_buyram(w: Writer, msg: EosActionBuyRam) -> None: def write_action_buyram(w: Writer, msg: EosActionBuyRam) -> None:
@ -154,12 +156,9 @@ def write_asset(w: Writer, asset: EosAsset) -> None:
def write_variant32(w: Writer, value: int) -> None: def write_variant32(w: Writer, value: int) -> None:
variant = bytearray() dump_uvarint(w.extend, value)
while True:
b = value & 0x7F
value >>= 7 def write_bytes_prefixed(w: Writer, data: bytes) -> None:
b |= (value > 0) << 7 write_variant32(w, len(data))
variant.append(b) write_bytes_unchecked(w, data)
if value == 0:
break
write_bytes_unchecked(w, bytes(variant))