Skip to content

Commit

Permalink
fixup! feat(core): add support for Zcash unified addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
krnak committed Jul 22, 2022
1 parent ee68a69 commit 6f2bf03
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 140 deletions.
3 changes: 2 additions & 1 deletion core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ FIRMWARE_P1_MAXSIZE = 786432
FIRMWARE_P2_MAXSIZE = 917504
FIRMWARE_MAXSIZE = 1703936

CFLAGS += -DSCM_REVISION='\"$(shell git rev-parse HEAD | sed 's:\(..\):\\x\1:g')\"'
#CFLAGS += -DSCM_REVISION='\"$(shell git rev-parse HEAD | sed 's:\(..\):\\x\1:g')\"'
CFLAGS += -DSCM_REVISION='\"\xee\x68\xa6\x94\xc1\x8c\xf6\x65\xd9\xf9\x6a\x37\x4a\x7f\x68\xec\x6c\x0d\xe0\x6d\"'

TESTPATH = $(CURDIR)/../tests

Expand Down
12 changes: 4 additions & 8 deletions core/SConscript.firmware
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import os

BITCOIN_ONLY = ARGUMENTS.get('BITCOIN_ONLY', '0')
EVERYTHING = BITCOIN_ONLY != '1'
USE_ZCASH = BITCOIN_ONLY == '1' # Zcash parasitizes on BITCOIN_ONLY free memory
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
UI2 = ARGUMENTS.get('UI2', '0') == '1' or TREZOR_MODEL in ('1', 'R')

Expand Down Expand Up @@ -199,7 +198,7 @@ SOURCE_MOD += [
SOURCE_MOD += [
'embed/extmod/rustmods/modtrezorproto.c',
]
if USE_ZCASH:
if EVERYTHING:
SOURCE_MOD += [
'embed/extmod/rustmods/modtrezororchardlib.c',
]
Expand Down Expand Up @@ -422,7 +421,7 @@ if FEATURE_FLAGS["SYSTEM_VIEW"]:

SOURCE_QSTR = SOURCE_MOD + SOURCE_MICROPYTHON + SOURCE_MICROPYTHON_SPEED

env = Environment(ENV=os.environ, CFLAGS='%s -DPYOPT=%s -DBITCOIN_ONLY=%s -DUSE_ZCASH=%s' % (ARGUMENTS.get('CFLAGS', ''), PYOPT, BITCOIN_ONLY, '1' if USE_ZCASH else '0'))
env = Environment(ENV=os.environ, CFLAGS='%s -DPYOPT=%s -DBITCOIN_ONLY=%s' % (ARGUMENTS.get('CFLAGS', ''), PYOPT, BITCOIN_ONLY))

env.Tool('micropython')

Expand Down Expand Up @@ -677,7 +676,6 @@ if FROZEN:

SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/decred.py'))

if EVERYTHING or USE_ZCASH:
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/bitcoinlike.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/zcash_v4.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/zcash/*.py'))
Expand Down Expand Up @@ -718,10 +716,8 @@ def cargo_build():
profile = ''

features = ['micropython', 'protobuf', f'model_t{TREZOR_MODEL.lower()}']
if USE_ZCASH:
features.append('use_zcash')
if BITCOIN_ONLY == '1':
features.append('bitcoin_only')
if BITCOIN_ONLY != '1':
features.append('use_altcoins')
if UI2:
features.append('ui')
if PYOPT == '0':
Expand Down
12 changes: 4 additions & 8 deletions core/SConscript.unix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import os

BITCOIN_ONLY = ARGUMENTS.get('BITCOIN_ONLY', '0')
EVERYTHING = BITCOIN_ONLY != '1'
USE_ZCASH = True
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
UI2 = ARGUMENTS.get('UI2', '0') == '1' or TREZOR_MODEL in ('1', 'R')

Expand Down Expand Up @@ -199,7 +198,7 @@ SOURCE_MOD += [
SOURCE_MOD += [
'embed/extmod/rustmods/modtrezorproto.c',
]
if USE_ZCASH:
if EVERYTHING:
SOURCE_MOD += [
'embed/extmod/rustmods/modtrezororchardlib.c',
]
Expand Down Expand Up @@ -368,7 +367,7 @@ if PYOPT == '0' or not FROZEN:
else:
STATIC=""

env = Environment(ENV=os.environ, CFLAGS='%s -DPYOPT=%s -DBITCOIN_ONLY=%s -DUSE_ZCASH=%s %s' % (ARGUMENTS.get('CFLAGS', ''), PYOPT, BITCOIN_ONLY, '1' if USE_ZCASH else '0', STATIC))
env = Environment(ENV=os.environ, CFLAGS='%s -DPYOPT=%s -DBITCOIN_ONLY=%s %s' % (ARGUMENTS.get('CFLAGS', ''), PYOPT, BITCOIN_ONLY, STATIC))

env.Tool('micropython')

Expand Down Expand Up @@ -633,7 +632,6 @@ if FROZEN:

SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/decred.py'))

if EVERYTHING or USE_ZCASH:
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/bitcoinlike.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/zcash_v4.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/zcash/*.py'))
Expand Down Expand Up @@ -672,10 +670,8 @@ RUST_LIBPATH = f'{RUST_LIBDIR}/lib{RUST_LIB}.a'

def cargo_build():
features = ['micropython', 'protobuf', f'model_t{TREZOR_MODEL.lower()}']
if USE_ZCASH:
features.append('use_zcash')
if BITCOIN_ONLY == '1':
features.append('bitcoin_only')
if BITCOIN_ONLY != '1':
features.append('use_altcoins')
if UI2:
features.append('ui')
if PYOPT == '0':
Expand Down
6 changes: 0 additions & 6 deletions core/embed/extmod/modtrezorutils/modtrezorutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ STATIC mp_obj_str_t mod_trezorutils_revision_obj = {
/// MODEL: str
/// EMULATOR: bool
/// BITCOIN_ONLY: bool
/// USE_ZCASH: bool
/// FIRMWARE_SECTORS_COUNT: int

STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = {
Expand Down Expand Up @@ -317,11 +316,6 @@ STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = {
#else
{MP_ROM_QSTR(MP_QSTR_BITCOIN_ONLY), mp_const_false},
#endif
#if USE_ZCASH
{MP_ROM_QSTR(MP_QSTR_USE_ZCASH), mp_const_true},
#else
{MP_ROM_QSTR(MP_QSTR_USE_ZCASH), mp_const_false},
#endif
};

STATIC MP_DEFINE_CONST_DICT(mp_module_trezorutils_globals,
Expand Down
6 changes: 3 additions & 3 deletions core/embed/extmod/rustmods/modtrezororchardlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "py/runtime.h"

#if USE_ZCASH
#if MICROPY_PY_TREZORORCHARDLIB

#include "librust.h"

Expand Down Expand Up @@ -49,6 +49,6 @@ const mp_obj_module_t mp_module_trezororchardlib = {
};

MP_REGISTER_MODULE(MP_QSTR_trezororchardlib, mp_module_trezororchardlib,
USE_ZCASH);
MICROPY_PY_TREZORORCHARDLIB);

#endif // USE_ZCASH
#endif // MICROPY_PY_TREZORORCHARDLIB
1 change: 1 addition & 0 deletions core/embed/firmware/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
#define MICROPY_PY_TREZORUTILS (1)
#define MICROPY_PY_TREZORPROTO (1)
#define MICROPY_PY_TREZORUI2 (1)
#define MICROPY_PY_TREZORORCHARDLIB (1)

#ifdef SYSTEM_VIEW
#define MP_PLAT_PRINT_STRN(str, len) segger_print(str, len)
Expand Down
1 change: 1 addition & 0 deletions core/embed/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions core/embed/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ edition = "2021"
build = "build.rs"

[features]
default = ["model_tt"]
bitcoin_only = []
default = ["model_tt", "use_altcoins"]
use_altcoins = ["use_zcash"]
model_tt = ["touch"]
model_t1 = ["buttons"]
model_tr = ["buttons"]
micropython = []
protobuf = ["micropython"]
use_zcash = ["micropython", "f4jumble"]
use_zcash = ["micropython", "f4jumble", "blake2b_simd"]
ui = []
ui_debug = []
buttons = []
Expand Down Expand Up @@ -55,6 +55,14 @@ version = "0.1.0"
default-features = false
optional = true

[dependencies.blake2b_simd]
# this is a dependency of f4jumble crate
# we recall it here to enable its `uninline_portable` feature
version = "1"
default_features = false
features = ["uninline_portable"]
optional = true

# Build dependencies

[build-dependencies.bindgen]
Expand Down
2 changes: 1 addition & 1 deletion core/embed/rust/librust.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mp_obj_t ui_debug_layout_type();
#endif

// Zcash
#if USE_ZCASH
#if !BITCOIN_ONLY
mp_obj_t orchardlib_f4jumble(mp_obj_t message);
mp_obj_t orchardlib_f4jumble_inv(mp_obj_t message);
#endif
1 change: 1 addition & 0 deletions core/embed/unix/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ extern const struct _mp_print_t mp_stderr_print;
#define MICROPY_PY_TREZORUTILS (1)
#define MICROPY_PY_TREZORPROTO (1)
#define MICROPY_PY_TREZORUI2 (1)
#define MICROPY_PY_TREZORORCHARDLIB (1)

#define MP_STATE_PORT MP_STATE_VM

Expand Down
1 change: 0 additions & 1 deletion core/mocks/generated/trezorutils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,4 @@ VERSION_PATCH: int
MODEL: str
EMULATOR: bool
BITCOIN_ONLY: bool
USE_ZCASH: bool
FIRMWARE_SECTORS_COUNT: int
17 changes: 7 additions & 10 deletions core/src/apps/bitcoin/sign_tx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
from . import approvers, bitcoin, helpers, progress

if not utils.BITCOIN_ONLY:
from . import bitcoinlike, decred

if utils.USE_ZCASH:
from . import zcash_v4
from . import bitcoinlike, decred, zcash_v4
from apps.zcash.signer import Zcash

if TYPE_CHECKING:
Expand Down Expand Up @@ -70,13 +67,13 @@ async def sign_tx(

if coin.coin_name in BITCOIN_NAMES:
signer_class: type[SignerClass] = bitcoin.Bitcoin
elif (utils.USE_ZCASH or not utils.BITCOIN_ONLY) and coin.overwintered:
if msg.version == 5:
signer_class = Zcash
else:
signer_class = zcash_v4.ZcashV4
elif not utils.BITCOIN_ONLY:
if coin.decred:
if coin.overwintered:
if msg.version == 5:
signer_class = Zcash
else:
signer_class = zcash_v4.ZcashV4
elif coin.decred:
signer_class = decred.Decred
else:
signer_class = bitcoinlike.Bitcoinlike
Expand Down
117 changes: 58 additions & 59 deletions core/src/apps/common/coininfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,65 +178,6 @@ def by_name(name: str) -> CoinInfo:
overwintered=False,
confidential_assets=None,
)
if utils.USE_ZCASH:
if name == "Zcash":
return CoinInfo(
coin_name=name,
coin_shortcut="ZEC",
decimals=8,
address_type=7352,
address_type_p2sh=7357,
maxfee_kb=51000000,
signed_message_header="Zcash Signed Message:\n",
xpub_magic=0x0488b21e,
xpub_magic_segwit_p2sh=None,
xpub_magic_segwit_native=None,
xpub_magic_multisig_segwit_p2sh=None,
xpub_magic_multisig_segwit_native=None,
bech32_prefix=None,
cashaddr_prefix=None,
slip44=133,
segwit=False,
taproot=False,
fork_id=None,
force_bip143=False,
decred=False,
negative_fee=False,
curve_name='secp256k1',
extra_data=True,
timestamp=False,
overwintered=True,
confidential_assets=None,
)
if name == "Zcash Testnet":
return CoinInfo(
coin_name=name,
coin_shortcut="TAZ",
decimals=8,
address_type=7461,
address_type_p2sh=7354,
maxfee_kb=10000000,
signed_message_header="Zcash Signed Message:\n",
xpub_magic=0x043587cf,
xpub_magic_segwit_p2sh=None,
xpub_magic_segwit_native=None,
xpub_magic_multisig_segwit_p2sh=None,
xpub_magic_multisig_segwit_native=None,
bech32_prefix=None,
cashaddr_prefix=None,
slip44=1,
segwit=False,
taproot=False,
fork_id=None,
force_bip143=False,
decred=False,
negative_fee=False,
curve_name='secp256k1',
extra_data=True,
timestamp=False,
overwintered=True,
confidential_assets=None,
)
if not utils.BITCOIN_ONLY:
if name == "Actinium":
return CoinInfo(
Expand Down Expand Up @@ -1659,6 +1600,64 @@ def by_name(name: str) -> CoinInfo:
overwintered=False,
confidential_assets=None,
)
if name == "Zcash":
return CoinInfo(
coin_name=name,
coin_shortcut="ZEC",
decimals=8,
address_type=7352,
address_type_p2sh=7357,
maxfee_kb=51000000,
signed_message_header="Zcash Signed Message:\n",
xpub_magic=0x0488b21e,
xpub_magic_segwit_p2sh=None,
xpub_magic_segwit_native=None,
xpub_magic_multisig_segwit_p2sh=None,
xpub_magic_multisig_segwit_native=None,
bech32_prefix=None,
cashaddr_prefix=None,
slip44=133,
segwit=False,
taproot=False,
fork_id=None,
force_bip143=False,
decred=False,
negative_fee=False,
curve_name='secp256k1',
extra_data=True,
timestamp=False,
overwintered=True,
confidential_assets=None,
)
if name == "Zcash Testnet":
return CoinInfo(
coin_name=name,
coin_shortcut="TAZ",
decimals=8,
address_type=7461,
address_type_p2sh=7354,
maxfee_kb=10000000,
signed_message_header="Zcash Signed Message:\n",
xpub_magic=0x043587cf,
xpub_magic_segwit_p2sh=None,
xpub_magic_segwit_native=None,
xpub_magic_multisig_segwit_p2sh=None,
xpub_magic_multisig_segwit_native=None,
bech32_prefix=None,
cashaddr_prefix=None,
slip44=1,
segwit=False,
taproot=False,
fork_id=None,
force_bip143=False,
decred=False,
negative_fee=False,
curve_name='secp256k1',
extra_data=True,
timestamp=False,
overwintered=True,
confidential_assets=None,
)
if name == "Brhodium":
return CoinInfo(
coin_name=name,
Expand Down
Loading

0 comments on commit 6f2bf03

Please sign in to comment.