Skip to content

Commit

Permalink
Merge pull request #19 from LedgerHQ/fbe/derive_sender_key
Browse files Browse the repository at this point in the history
Allow sender address in WRAP and UNWRAP & more
  • Loading branch information
fbeutin-ledger authored Sep 30, 2024
2 parents 7f88d33 + 6946952 commit 7f7031a
Show file tree
Hide file tree
Showing 342 changed files with 212 additions and 92 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ APPNAME = "Uniswap"

# Application version
APPVERSION_M = 1
APPVERSION_N = 2
APPVERSION_N = 3
APPVERSION_P = 0

APP_SOURCE_FILES += $(BOLOS_SDK)/lib_standard_app/crypto_helpers.c
INCLUDES_PATH += $(BOLOS_SDK)/lib_standard_app

include ethereum-plugin-sdk/standard_plugin.mk
2 changes: 1 addition & 1 deletion ethereum-plugin-sdk
Submodule ethereum-plugin-sdk updated 37 files
+44 −0 .github/workflows/publish_doc_website.yml
+2 −0 .gitignore
+3 −2 README.md
+ docs/img/Ledger-logo-696.webp
+51 −0 docs/index.md
+4 −0 docs/requirements.txt
+57 −0 docs/technical_informations/diagram.md
+15 −0 docs/technical_informations/globals.md
+11 −0 docs/technical_informations/handlers/handle_finalize.md
+11 −0 docs/technical_informations/handlers/handle_init_contract.md
+11 −0 docs/technical_informations/handlers/handle_provide_parameter.md
+19 −0 docs/technical_informations/handlers/handle_provide_token.md
+11 −0 docs/technical_informations/handlers/handle_query_contract_id.md
+19 −0 docs/technical_informations/handlers/handle_query_contract_ui.md
+10 −0 docs/technical_informations/handlers/index.md
+3 −0 docs/technical_informations/index.md
+5 −0 docs/technical_informations/tx_content.md
+3 −0 docs/technical_informations/utils/common_utils.md
+3 −0 docs/technical_informations/utils/index.md
+3 −0 docs/technical_informations/utils/plugin_utils.md
+1 −0 docs/test_framework/ci.md
+1 −0 docs/test_framework/fuzzing.md
+9 −0 docs/test_framework/index.md
+1 −0 docs/test_framework/ragger.md
+ docs/walkthrough/img/uniswap.webp
+52 −0 docs/walkthrough/index.md
+75 −0 mkdocs.yml
+2 −3 src/asset_info.h
+9 −0 src/bip32_utils.h
+44 −12 src/common_utils.c
+212 −31 src/common_utils.h
+4 −2 src/eth_internals.h
+297 −57 src/eth_plugin_interface.h
+3 −10 src/main.c
+8 −5 src/plugin_utils.c
+81 −9 src/plugin_utils.h
+15 −3 src/tx_content.h
11 changes: 11 additions & 0 deletions fuzzing/fuzz_plugin.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "plugin.h"
#include "bip32_utils.h"

// set a small size to detect possible overflows
#define NAME_LENGTH 3u
Expand Down Expand Up @@ -51,12 +52,22 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
}
memcpy(&content, data + 4, sizeof(txContent_t));

// Use path: m/44'/60'/0'/0/0
bip32_path_t bip32;
bip32.length = 5;
bip32.path[0] = 44 | 0x80000000;
bip32.path[1] = 60 | 0x80000000;
bip32.path[2] = 0 | 0x80000000;
bip32.path[3] = 0;
bip32.path[4] = 0;

init_contract.interfaceVersion = ETH_PLUGIN_INTERFACE_VERSION_LATEST;
init_contract.selector = data;
init_contract.pluginSharedRO = &shared_ro;
init_contract.pluginSharedRW = &shared_rw;
init_contract.pluginContext = (uint8_t *) &context;
init_contract.pluginContextLength = sizeof(context);
init_contract.bip32 = &bip32;

handle_init_contract(&init_contract);
if (init_contract.result != ETH_PLUGIN_RESULT_OK) {
Expand Down
14 changes: 14 additions & 0 deletions fuzzing/mocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,23 @@ size_t strlcpy(char *dst, const char *src, size_t size) {
cx_err_t cx_keccak_256_hash_iovec(const cx_iovec_t *iovec,
size_t iovec_len,
uint8_t digest[static CX_KECCAK_256_SIZE]) {
memset(digest, 0, CX_KECCAK_256_SIZE);
return CX_OK;
}

void os_sched_exit(bolos_task_status_t exit_code) {
return;
}

WARN_UNUSED_RESULT cx_err_t bip32_derive_with_seed_get_pubkey_256(unsigned int derivation_mode,
cx_curve_t curve,
const uint32_t *path,
size_t path_len,
uint8_t raw_pubkey[static 65],
uint8_t *chain_code,
cx_md_t hashID,
unsigned char *seed,
size_t seed_len) {
memset(raw_pubkey, 0, 65);
return CX_OK;
}
2 changes: 1 addition & 1 deletion src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void handle_finalize(ethPluginFinalize_t *msg) {
return;
}

if (!is_sender_address(context->recipient)) {
if (!is_sender_address(context->recipient, context->own_address)) {
PRINTF("Displaying recipient\n");
++msg->numScreens;
}
Expand Down
12 changes: 8 additions & 4 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "plugin_utils.h"
#include "plugin.h"
#include "os.h"
#include "check_tx_content.h"
#include "uniswap_contract_helpers.h"

// Called once to init.
void handle_init_contract(ethPluginInitContract_t *msg) {
Expand Down Expand Up @@ -30,6 +32,12 @@ void handle_init_contract(ethPluginInitContract_t *msg) {
// Initialize the context (to 0).
memset(context, 0, sizeof(*context));

if (get_self_address(context->own_address, msg->bip32) != 0) {
PRINTF("Error: get_self_address failed\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
}

size_t index;
if (!find_selector(U4BE(msg->selector, 0), SELECTORS, SELECTOR_COUNT, &index)) {
PRINTF("Error: selector not found!\n");
Expand All @@ -51,10 +59,6 @@ void handle_init_contract(ethPluginInitContract_t *msg) {
case EXECUTE:
context->next_param = COMMANDS_OFFSET;
break;
// case BOILERPLATE_DUMMY_2:
// context->next_param = TOKEN_RECEIVED;
// break;
// Keep this
default:
PRINTF("Missing selectorIndex: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
Loading

0 comments on commit 7f7031a

Please sign in to comment.