mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 07:28:10 +00:00
refactor(core,legacy): remove Wanchain special handling
now that Wanchain has proper chainID and we don't need to detect it by magic. [no changelog]
This commit is contained in:
parent
639406b01f
commit
96ed53cc1c
8
common/tests/fixtures/ethereum/sign_tx.json
vendored
8
common/tests/fixtures/ethereum/sign_tx.json
vendored
@ -50,7 +50,7 @@
|
||||
"data": "",
|
||||
"path": "44'/5718350'/0'/0/0",
|
||||
"to_address": "0xd0d6d6c5fe4a677d343cc433536bb717bae167dd",
|
||||
"chain_id": 1,
|
||||
"chain_id": 888,
|
||||
"nonce": 0,
|
||||
"gas_price": 20,
|
||||
"gas_limit": 20,
|
||||
@ -58,9 +58,9 @@
|
||||
"value": 100
|
||||
},
|
||||
"result": {
|
||||
"sig_v": 38,
|
||||
"sig_r": "d6e197029031ec90b53ed14e8233aa78b592400513ac0386d2d55cdedc3d796f",
|
||||
"sig_s": "326e0d600dd1b7ee606eb531b998a6a3b3293d4995fb8cfe0677962e8a43cff6"
|
||||
"sig_v": 1811,
|
||||
"sig_r": "93648ad45524a896b1f465e868bb7c0427502e218b135e53b55f7a1e7e2293aa",
|
||||
"sig_s": "2fd3882fbeb8968041d463d7c61526cdb36a80f53b2b217221b879b0d275d179"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
from trezor import wire
|
||||
from trezor.messages import EthereumSignTxEIP1559
|
||||
|
||||
from apps.common import paths
|
||||
from apps.common.keychain import get_keychain
|
||||
@ -73,10 +72,6 @@ def _schemas_from_chain_id(msg: EthereumSignTx) -> Iterable[paths.PathSchema]:
|
||||
if info is None:
|
||||
# allow Ethereum or testnet paths for unknown networks
|
||||
slip44_id = (60, 1)
|
||||
elif not EthereumSignTxEIP1559.is_type_of(msg) and networks.is_wanchain(
|
||||
msg.chain_id, msg.tx_type
|
||||
):
|
||||
slip44_id = (networks.SLIP44_WANCHAIN,)
|
||||
elif info.slip44 != 60 and info.slip44 != 1:
|
||||
# allow cross-signing with Ethereum unless it's testnet
|
||||
slip44_id = (info.slip44, 60)
|
||||
|
@ -15,7 +15,7 @@ from . import networks, tokens
|
||||
from .address import address_from_bytes
|
||||
|
||||
|
||||
async def require_confirm_tx(ctx, to_bytes, value, chain_id, token=None, tx_type=None):
|
||||
async def require_confirm_tx(ctx, to_bytes, value, chain_id, token=None):
|
||||
if to_bytes:
|
||||
to_str = address_from_bytes(to_bytes, networks.by_chain_id(chain_id))
|
||||
else:
|
||||
@ -23,7 +23,7 @@ async def require_confirm_tx(ctx, to_bytes, value, chain_id, token=None, tx_type
|
||||
await confirm_output(
|
||||
ctx,
|
||||
address=to_str,
|
||||
amount=format_ethereum_amount(value, token, chain_id, tx_type),
|
||||
amount=format_ethereum_amount(value, token, chain_id),
|
||||
font_amount=ui.BOLD,
|
||||
color_to=ui.GREY,
|
||||
br_code=ButtonRequestType.SignTx,
|
||||
@ -31,13 +31,13 @@ async def require_confirm_tx(ctx, to_bytes, value, chain_id, token=None, tx_type
|
||||
|
||||
|
||||
async def require_confirm_fee(
|
||||
ctx, spending, gas_price, gas_limit, chain_id, token=None, tx_type=None
|
||||
ctx, spending, gas_price, gas_limit, chain_id, token=None
|
||||
):
|
||||
await confirm_total_ethereum(
|
||||
ctx,
|
||||
format_ethereum_amount(spending, token, chain_id, tx_type),
|
||||
format_ethereum_amount(gas_price, None, chain_id, tx_type),
|
||||
format_ethereum_amount(gas_price * gas_limit, None, chain_id, tx_type),
|
||||
format_ethereum_amount(spending, token, chain_id),
|
||||
format_ethereum_amount(gas_price, None, chain_id),
|
||||
format_ethereum_amount(gas_price * gas_limit, None, chain_id),
|
||||
)
|
||||
|
||||
|
||||
@ -88,7 +88,7 @@ async def require_confirm_data(ctx, data, data_total):
|
||||
)
|
||||
|
||||
|
||||
def format_ethereum_amount(value: int, token, chain_id: int, tx_type=None):
|
||||
def format_ethereum_amount(value: int, token, chain_id: int):
|
||||
if token is tokens.UNKNOWN_TOKEN:
|
||||
suffix = "Wei UNKN"
|
||||
decimals = 0
|
||||
@ -96,7 +96,7 @@ def format_ethereum_amount(value: int, token, chain_id: int, tx_type=None):
|
||||
suffix = token[2]
|
||||
decimals = token[3]
|
||||
else:
|
||||
suffix = networks.shortcut_by_chain_id(chain_id, tx_type)
|
||||
suffix = networks.shortcut_by_chain_id(chain_id)
|
||||
decimals = 18
|
||||
|
||||
# Don't want to display wei values for tokens with small decimal numbers
|
||||
|
@ -5,23 +5,13 @@ from micropython import const
|
||||
|
||||
from apps.common.paths import HARDENED
|
||||
|
||||
SLIP44_WANCHAIN = const(5718350)
|
||||
SLIP44_ETHEREUM = const(60)
|
||||
|
||||
if False:
|
||||
from typing import Iterator
|
||||
|
||||
|
||||
def is_wanchain(chain_id: int, tx_type: int) -> bool:
|
||||
return tx_type in (1, 6) and chain_id in (1, 3)
|
||||
|
||||
|
||||
def shortcut_by_chain_id(chain_id: int, tx_type: int = None) -> str:
|
||||
if is_wanchain(chain_id, tx_type):
|
||||
return "WAN"
|
||||
else:
|
||||
n = by_chain_id(chain_id)
|
||||
return n.shortcut if n is not None else "UNKN"
|
||||
def shortcut_by_chain_id(chain_id: int) -> str:
|
||||
n = by_chain_id(chain_id)
|
||||
return n.shortcut if n is not None else "UNKN"
|
||||
|
||||
|
||||
def by_chain_id(chain_id: int) -> "NetworkInfo" | None:
|
||||
@ -32,9 +22,6 @@ def by_chain_id(chain_id: int) -> "NetworkInfo" | None:
|
||||
|
||||
|
||||
def by_slip44(slip44: int) -> "NetworkInfo" | None:
|
||||
if slip44 == SLIP44_WANCHAIN:
|
||||
# Coerce to Ethereum
|
||||
slip44 = SLIP44_ETHEREUM
|
||||
for n in _networks_iterator():
|
||||
if n.slip44 == slip44:
|
||||
return n
|
||||
@ -44,7 +31,6 @@ def by_slip44(slip44: int) -> "NetworkInfo" | None:
|
||||
def all_slip44_ids_hardened() -> Iterator[int]:
|
||||
for n in _networks_iterator():
|
||||
yield n.slip44 | HARDENED
|
||||
yield SLIP44_WANCHAIN | HARDENED
|
||||
|
||||
|
||||
class NetworkInfo:
|
||||
|
@ -5,23 +5,13 @@ from micropython import const
|
||||
|
||||
from apps.common.paths import HARDENED
|
||||
|
||||
SLIP44_WANCHAIN = const(5718350)
|
||||
SLIP44_ETHEREUM = const(60)
|
||||
|
||||
if False:
|
||||
from typing import Iterator
|
||||
|
||||
|
||||
def is_wanchain(chain_id: int, tx_type: int) -> bool:
|
||||
return tx_type in (1, 6) and chain_id in (1, 3)
|
||||
|
||||
|
||||
def shortcut_by_chain_id(chain_id: int, tx_type: int = None) -> str:
|
||||
if is_wanchain(chain_id, tx_type):
|
||||
return "WAN"
|
||||
else:
|
||||
n = by_chain_id(chain_id)
|
||||
return n.shortcut if n is not None else "UNKN"
|
||||
def shortcut_by_chain_id(chain_id: int) -> str:
|
||||
n = by_chain_id(chain_id)
|
||||
return n.shortcut if n is not None else "UNKN"
|
||||
|
||||
|
||||
def by_chain_id(chain_id: int) -> "NetworkInfo" | None:
|
||||
@ -32,9 +22,6 @@ def by_chain_id(chain_id: int) -> "NetworkInfo" | None:
|
||||
|
||||
|
||||
def by_slip44(slip44: int) -> "NetworkInfo" | None:
|
||||
if slip44 == SLIP44_WANCHAIN:
|
||||
# Coerce to Ethereum
|
||||
slip44 = SLIP44_ETHEREUM
|
||||
for n in _networks_iterator():
|
||||
if n.slip44 == slip44:
|
||||
return n
|
||||
@ -44,7 +31,6 @@ def by_slip44(slip44: int) -> "NetworkInfo" | None:
|
||||
def all_slip44_ids_hardened() -> Iterator[int]:
|
||||
for n in _networks_iterator():
|
||||
yield n.slip44 | HARDENED
|
||||
yield SLIP44_WANCHAIN | HARDENED
|
||||
|
||||
|
||||
class NetworkInfo:
|
||||
|
@ -34,7 +34,7 @@ async def sign_tx(ctx, msg, keychain):
|
||||
|
||||
data_total = msg.data_length
|
||||
|
||||
await require_confirm_tx(ctx, recipient, value, msg.chain_id, token, msg.tx_type)
|
||||
await require_confirm_tx(ctx, recipient, value, msg.chain_id, token)
|
||||
if token is None and msg.data_length > 0:
|
||||
await require_confirm_data(ctx, msg.data_initial_chunk, data_total)
|
||||
|
||||
@ -45,7 +45,6 @@ async def sign_tx(ctx, msg, keychain):
|
||||
int.from_bytes(msg.gas_limit, "big"),
|
||||
msg.chain_id,
|
||||
token,
|
||||
msg.tx_type,
|
||||
)
|
||||
|
||||
data = bytearray()
|
||||
|
@ -155,24 +155,6 @@ class TestEthereumKeychain(unittest.TestCase):
|
||||
)
|
||||
)
|
||||
|
||||
def test_wanchain(self):
|
||||
@with_keychain_from_chain_id
|
||||
async def handler_wanchain(ctx, msg, keychain):
|
||||
self._check_keychain(keychain, 5718350)
|
||||
# provided address should succeed too
|
||||
keychain.derive(msg.address_n)
|
||||
|
||||
await_result(
|
||||
handler_wanchain(
|
||||
wire.DUMMY_CONTEXT,
|
||||
EthereumSignTx(
|
||||
address_n=[44 | HARDENED, 5718350 | HARDENED, 0 | HARDENED],
|
||||
chain_id=3,
|
||||
tx_type=6,
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
@ -250,11 +250,7 @@ static void ethereumFormatAmount(const bignum256 *amnt, const TokenType *token,
|
||||
suffix = " Wei";
|
||||
decimals = 0;
|
||||
} else {
|
||||
if (tx_type == 1 || tx_type == 6) {
|
||||
suffix = " WAN";
|
||||
} else {
|
||||
ASSIGN_ETHEREUM_SUFFIX(suffix, chain_id);
|
||||
}
|
||||
ASSIGN_ETHEREUM_SUFFIX(suffix, chain_id);
|
||||
}
|
||||
bn_format(amnt, NULL, suffix, decimals, 0, false, buf, buflen);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user