Skip to content

Commit

Permalink
Merge pull request #565 from LedgerHQ/cev/B2CA-1558_Port-Flex
Browse files Browse the repository at this point in the history
B2CA-1558: Port Ethereum on Flex
  • Loading branch information
cedelavergne-ledger committed May 16, 2024
2 parents f023a88 + c0d19fd commit e434173
Show file tree
Hide file tree
Showing 876 changed files with 892 additions and 1,008 deletions.
2 changes: 0 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
BasedOnStyle: Google
IndentWidth: 4
---
Language: Cpp
ColumnLimit: 100
PointerAlignment: Right
Expand All @@ -12,7 +11,6 @@ SortIncludes: false
SpaceAfterCStyleCast: true
AllowShortCaseLabelsOnASingleLine: false
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortFunctionsOnASingleLine: None
BinPackArguments: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Misspelings CI
name: Misspellings CI

on:
workflow_dispatch:
Expand Down
11 changes: 11 additions & 0 deletions .mdl.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Style file for mdl
# https://github.com/markdownlint/markdownlint/blob/main/docs/creating_styles.md

# Include all rules
all

# Disable specific rules
#exclude_rule 'MD012'

# Update rules configuration
rule 'MD013', :line_length => 120
14 changes: 14 additions & 0 deletions .mdlrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# markdownlint config file

# Use custom style file
style "#{File.dirname(__FILE__)}/.mdl.rb"

# MD002 - First header in file should be a top level header
# MD005 - Inconsistent indentation for list items at the same level
# MD007 - Unordered list indentation
# MD014 - Dollar signs used before commands without showing output
# MD024 - Multiple headers with the same content
# MD029 - Ordered list item prefix
# MD033 - Inline HTML
# MD041 - First line in file should be a top level header
rules "~MD002,~MD005,~MD007,~MD014,~MD024,~MD029,~MD033,~MD041"
47 changes: 47 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# To install hooks, run:
# pre-commit install --hook-type pre-commit
# pre-commit install --hook-type commit-msg

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: mixed-line-ending
- id: check-added-large-files
- id: check-merge-conflict
- id: check-case-conflict

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
args: ['--ignore-words-list', 'ontop,shft,hte', '--skip', 'makefile_conf/chain/*,tests/ragger/eip712_input_files/*']

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v12.0.1
hooks:
- id: clang-format
types_or: [c]

- repo: https://github.com/Mateusz-Grzelinski/actionlint-py
rev: v1.6.27.13
hooks:
- id: actionlint
types_or: [yaml]
args: [-shellcheck='' -pyflakes='']

- repo: https://github.com/markdownlint/markdownlint
rev: v0.12.0
hooks:
- id: markdownlint
types_or: [markdown]

- repo: https://github.com/PyCQA/pylint
rev: v2.16.2
hooks:
- id: pylint
types: [python]
args: ['--jobs=0', '--rcfile=tests/ragger/setup.cfg']
files: '^tests/ragger/.*$'
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- EIP-191 improvements, now lets the user see the entire message one chunk at a time (255 characters for LNX & LNS+, 99 for LNS)
- EIP-191 improvements, now lets the user see the entire message one chunk at a time
(255 characters for LNX & LNS+, 99 for LNS)

### Fixed

Expand All @@ -145,7 +146,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- EIP-191 signatures now show (up to 99 characters on LNS and 255 on LNX & LNS+) the actual data contained in the message (clear-signing)
- EIP-191 signatures now show (up to 99 characters on LNS and 255 on LNX & LNS+) the actual data
contained in the message (clear-signing)

### Fixed

Expand Down Expand Up @@ -256,7 +258,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

- When blind signing is disabled in settings, and a transaction with smart conract interactions is sent to the app, a new warning screen pops to let the user know that the setting must be enabled to sign this kind of transactions.
- When blind signing is disabled in settings, and a transaction with smart conract interactions is sent to the app,
a new warning screen pops to let the user know that the setting must be enabled to sign this kind of transactions.

## [1.9.4](https://github.com/ledgerhq/app-ethereum/compare/1.9.3...1.9.4) - 2021-9-14

Expand Down
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ APPVERSION = $(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)-dev

# Application source files
APP_SOURCE_PATH += src src_features src_plugins
ifeq ($(TARGET_NAME),TARGET_STAX)
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_STAX TARGET_FLEX))
APP_SOURCE_PATH += src_nbgl
else
APP_SOURCE_PATH += src_bagl
Expand All @@ -55,7 +55,7 @@ APP_SOURCE_FILES += ${BOLOS_SDK}/lib_standard_app/crypto_helpers.c
APP_SOURCE_FILES += ${BOLOS_SDK}/lib_standard_app/format.c
INCLUDES_PATH += ${BOLOS_SDK}/lib_standard_app

ifeq ($(TARGET_NAME),TARGET_STAX)
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_STAX TARGET_FLEX))
NETWORK_ICONS_FILE = $(GEN_SRC_DIR)/net_icons.gen.c
NETWORK_ICONS_DIR = $(shell dirname "$(NETWORK_ICONS_FILE)")

Expand All @@ -71,12 +71,13 @@ ICON_NANOS = icons/nanos_app_chain_$(CHAIN_ID).gif
ICON_NANOX = icons/nanox_app_chain_$(CHAIN_ID).gif
ICON_NANOSP = icons/nanox_app_chain_$(CHAIN_ID).gif
ICON_STAX = icons/stax_app_chain_$(CHAIN_ID).gif
ICON_FLEX = icons/flex_app_chain_$(CHAIN_ID).gif

#prepare hsm generation
ifeq ($(TARGET_NAME),TARGET_STAX)
DEFINES += ICONGLYPH=C_stax_chain_$(CHAIN_ID)_64px
DEFINES += ICONBITMAP=C_stax_chain_$(CHAIN_ID)_64px_bitmap
DEFINES += ICONGLYPH_SMALL=C_stax_chain_$(CHAIN_ID)
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_STAX TARGET_FLEX))
DEFINES += ICONGLYPH=C_chain_$(CHAIN_ID)_64px
DEFINES += ICONBITMAP=C_chain_$(CHAIN_ID)_64px_bitmap
DEFINES += ICONGLYPH_SMALL=C_chain_$(CHAIN_ID)
endif


Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,11 @@ to compile and run them.

## Contributing

Contributions are what makes the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
Contributions are what makes the open source community such an amazing place to learn, inspire, and create.
Any contributions you make are **greatly appreciated**.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag `enhancement`.
If you have a suggestion that would make this better, please fork the repo and create a pull request.
You can also simply open an issue with the tag `enhancement`.

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/my-feature`)
Expand Down
8 changes: 8 additions & 0 deletions client/src/ledger_app_clients/ethereum/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ def get_eth2_public_addr(self,
return self._exchange_async(self._cmd_builder.get_eth2_public_addr(display,
bip32_path))

def perform_privacy_operation(self,
display: bool = True,
bip32_path: str = "m/44'/60'/0'/0/0",
pubkey: bytes = bytes()):
return self._exchange(self._cmd_builder.perform_privacy_operation(display,
bip32_path,
pubkey))

def provide_domain_name(self, challenge: int, name: str, addr: bytes) -> RAPDU:
payload = format_tlv(DomainNameTag.STRUCTURE_TYPE, 3) # TrustedDomainName
payload += format_tlv(DomainNameTag.STRUCTURE_VERSION, 1)
Expand Down
11 changes: 11 additions & 0 deletions client/src/ledger_app_clients/ethereum/command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class InsType(IntEnum):
PROVIDE_ERC20_TOKEN_INFORMATION = 0x0a
PROVIDE_NFT_INFORMATION = 0x14
SET_PLUGIN = 0x16
PERFORM_PRIVACY_OPERATION = 0x18
EIP712_SEND_STRUCT_DEF = 0x1a
EIP712_SEND_STRUCT_IMPL = 0x1c
EIP712_SEND_FILTERING = 0x1e
Expand Down Expand Up @@ -260,6 +261,16 @@ def get_eth2_public_addr(self,
0x00,
payload)

def perform_privacy_operation(self,
display: bool,
bip32_path: str,
pubkey: bytes) -> bytes:
payload = pack_derivation_path(bip32_path)
return self._serialize(InsType.PERFORM_PRIVACY_OPERATION,
int(display),
0x01 if pubkey else 0x00,
payload + pubkey)

def set_plugin(self,
type_: int,
version: int,
Expand Down
5 changes: 1 addition & 4 deletions client/src/ledger_app_clients/ethereum/eip712/InputData.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,7 @@ def next_timeout(_signum: int, _frame):


def enable_autonext():
if app_client._client.firmware.device == 'stax': # Stax Speculos is slow
delay = 1.5
else:
delay = 1/4
delay = 1/5
signal.setitimer(signal.ITIMER_REAL, delay, delay)


Expand Down
25 changes: 18 additions & 7 deletions client/src/ledger_app_clients/ethereum/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_device_settings(device: str) -> list[SettingID]:
SettingID.DEBUG_DATA,
SettingID.NONCE
]
if (device == "nanox") or (device == "nanosp") or (device == "stax"):
if device in ("nanox", "nanosp", "stax", "flex"):
return [
SettingID.BLIND_SIGNING,
SettingID.DEBUG_DATA,
Expand All @@ -30,17 +30,28 @@ def get_device_settings(device: str) -> list[SettingID]:
return []


settings_per_page = 3
def get_setting_per_page(device: str) -> int:
if device == "stax":
return 3
return 2


def get_setting_position(device: str, setting: Union[NavInsID, SettingID]) -> tuple[int, int]:
screen_height = 672 # px
header_height = 85 # px
footer_height = 124 # px
settings_per_page = get_setting_per_page(device)
if device == "stax":
screen_height = 672 # px
header_height = 85 # px
footer_height = 132 # px
option_offset = 350 # px
else:
screen_height = 600 # px
header_height = 92 # px
footer_height = 97 # px
option_offset = 420 # px
usable_height = screen_height - (header_height + footer_height)
setting_height = usable_height // settings_per_page
index_in_page = get_device_settings(device).index(SettingID(setting)) % settings_per_page
return 350, header_height + (setting_height * index_in_page) + (setting_height // 2)
return option_offset, header_height + (setting_height * index_in_page) + (setting_height // 2)


def settings_toggle(fw: Firmware, nav: Navigator, to_toggle: list[SettingID]):
Expand All @@ -57,7 +68,7 @@ def settings_toggle(fw: Firmware, nav: Navigator, to_toggle: list[SettingID]):
moves += [NavInsID.BOTH_CLICK] # Back
else:
moves += [NavInsID.USE_CASE_HOME_SETTINGS]
moves += [NavInsID.USE_CASE_SETTINGS_NEXT]
settings_per_page = get_setting_per_page(fw.device)
for setting in settings:
setting_idx = settings.index(setting)
if (setting_idx > 0) and (setting_idx % settings_per_page) == 0:
Expand Down
2 changes: 1 addition & 1 deletion ethereum-plugin-sdk
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
1 change: 1 addition & 0 deletions glyphs/chain_11155111_64px.gif
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
1 change: 1 addition & 0 deletions glyphs/chain_17000_64px.gif
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
1 change: 0 additions & 1 deletion glyphs/stax_chain_11155111_64px.gif

This file was deleted.

1 change: 0 additions & 1 deletion glyphs/stax_chain_17000_64px.gif

This file was deleted.

Binary file added icons/flex_app_chain_1.gif
Binary file added icons/flex_app_chain_1030.gif
Binary file added icons/flex_app_chain_108.gif
Binary file added icons/flex_app_chain_1284.gif
Binary file added icons/flex_app_chain_1285.gif
Binary file added icons/flex_app_chain_1313114.gif
Binary file added icons/flex_app_chain_137.gif
Binary file added icons/flex_app_chain_1620.gif
Binary file added icons/flex_app_chain_1818.gif
Binary file added icons/flex_app_chain_19.gif
Binary file added icons/flex_app_chain_1987.gif
Binary file added icons/flex_app_chain_199.gif
Binary file added icons/flex_app_chain_2.gif
Binary file added icons/flex_app_chain_200625.gif
Binary file added icons/flex_app_chain_20531811.gif
Binary file added icons/flex_app_chain_20531812.gif
Binary file added icons/flex_app_chain_237.gif
Binary file added icons/flex_app_chain_24.gif
Binary file added icons/flex_app_chain_24484.gif
Binary file added icons/flex_app_chain_246.gif
Binary file added icons/flex_app_chain_246529.gif
Binary file added icons/flex_app_chain_246785.gif
Binary file added icons/flex_app_chain_248.gif
Binary file added icons/flex_app_chain_269.gif
Binary file added icons/flex_app_chain_2894.gif
Binary file added icons/flex_app_chain_30.gif
Binary file added icons/flex_app_chain_31.gif
Binary file added icons/flex_app_chain_31102.gif
Binary file added icons/flex_app_chain_3125659152.gif
Binary file added icons/flex_app_chain_336.gif
Binary file added icons/flex_app_chain_50.gif
Binary file added icons/flex_app_chain_51.gif
Binary file added icons/flex_app_chain_56.gif
Binary file added icons/flex_app_chain_592.gif
Binary file added icons/flex_app_chain_60.gif
Binary file added icons/flex_app_chain_61.gif
Binary file added icons/flex_app_chain_62621.gif
Binary file added icons/flex_app_chain_64.gif
Binary file added icons/flex_app_chain_66.gif
Binary file added icons/flex_app_chain_7341.gif
Binary file added icons/flex_app_chain_73799.gif
Binary file added icons/flex_app_chain_76.gif
Binary file added icons/flex_app_chain_7762959.gif
Binary file added icons/flex_app_chain_78.gif
Binary file added icons/flex_app_chain_8.gif
Binary file added icons/flex_app_chain_82.gif
Binary file added icons/flex_app_chain_820.gif
Binary file added icons/flex_app_chain_846000.gif
Binary file added icons/flex_app_chain_88.gif
Binary file added icons/flex_app_chain_888.gif
Binary file added icons/flex_app_chain_99.gif
Binary file removed icons/nanos_app_chain_401697.gif
Diff not rendered.
Binary file removed icons/stax_app_chain_401697.gif
Diff not rendered.
2 changes: 1 addition & 1 deletion ledger_app.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[app]
build_directory = "./"
sdk = "C"
devices = ["nanos", "nanox", "nanos+", "stax"]
devices = ["nanos", "nanox", "nanos+", "stax", "flex"]

[use_cases] # Coherent build options that make sense for your application
debug = "DEBUG=1"
Expand Down
1 change: 1 addition & 0 deletions src/common_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void ui_display_public_key(const uint64_t *chain_id);
void ui_sign_712_v0(void);
void ui_confirm_selector(void);
void ui_confirm_parameter(void);
void app_quit(void);

// EIP-191
void ui_191_start(void);
Expand Down
17 changes: 0 additions & 17 deletions src/uint_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,3 @@ void reverseString(char *const str, uint32_t length) {
str[j] = c;
}
}

int bytes_to_string(char *out, size_t outl, const void *value, size_t len) {
if (outl <= 2) {
// Need at least '0x' and 1 digit
return -1;
}
if (strlcpy(out, "0x", outl) != 2) {
goto err;
}
if (format_hex(value, len, out + 2, outl - 2) < 0) {
goto err;
}
return 0;
err:
*out = '\0';
return -1;
}
2 changes: 0 additions & 2 deletions src/uint_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,4 @@ void read_u64_be(const uint8_t *const in, uint64_t *const out);
uint64_t readUint64BE(const uint8_t *const buffer);
void reverseString(char *const str, uint32_t length);

int bytes_to_string(char *out, size_t outl, const void *value, size_t len);

#endif //_UINT_COMMON_H_
8 changes: 4 additions & 4 deletions src_bagl/ui_flow_getEth2PublicKey.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include "uint_common.h"

void prepare_eth2_public_key() {
bytes_to_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
tmpCtx.publicKeyContext.publicKey.W,
48);
array_bytes_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
tmpCtx.publicKeyContext.publicKey.W,
48);
}

// clang-format off
Expand Down
2 changes: 1 addition & 1 deletion src_bagl/ui_flow_signMessage.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ UX_STEP_NOCB(
pnn,
{
&C_icon_certificate,
"Sign",
"Review",
"message",
});
UX_STEP_NOCB(
Expand Down
18 changes: 9 additions & 9 deletions src_bagl/ui_flow_signMessage712_v0.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
#include "uint_common.h"

void prepare_domain_hash_v0() {
bytes_to_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
tmpCtx.messageSigningContext712.domainHash,
KECCAK256_HASH_BYTESIZE);
array_bytes_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
tmpCtx.messageSigningContext712.domainHash,
KECCAK256_HASH_BYTESIZE);
}

void prepare_message_hash_v0() {
bytes_to_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
tmpCtx.messageSigningContext712.messageHash,
KECCAK256_HASH_BYTESIZE);
array_bytes_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
tmpCtx.messageSigningContext712.messageHash,
KECCAK256_HASH_BYTESIZE);
}

// clang-format off
Expand All @@ -23,7 +23,7 @@ UX_STEP_NOCB(
pnn,
{
&C_icon_certificate,
"Sign",
"Review",
"typed message",
});
UX_STEP_NOCB_INIT(
Expand Down

0 comments on commit e434173

Please sign in to comment.