diff --git a/src/extra_tokens.c b/src/extra_tokens.c deleted file mode 100644 index 9faefcb..0000000 --- a/src/extra_tokens.c +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Ledger Ethereum App - * (c) 2016-2019 Ledger - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ********************************************************************************/ - -#ifdef HAVE_TOKENS_EXTRA_LIST - -#include "extra_tokens.h" - -const tokenDefinition_t TOKENS_EXTRA[NUM_TOKENS_EXTRA] = { - - // Ropsten DeversiFi tokens - {{0x4c, 0x5f, 0x66, 0x59, 0x61, 0x97, 0xa8, 0x6f, 0xb3, 0x0a, - 0x24, 0x35, 0xe2, 0xef, 0x4d, 0xdc, 0xb3, 0x93, 0x42, 0xc9}, - "tUSDT", - 6}, - {{0x1c, 0x0f, 0x17, 0x43, 0x67, 0x40, 0xbf, 0xb9, 0x2c, 0x10, - 0x70, 0xee, 0x86, 0x32, 0x2d, 0xe8, 0x90, 0x83, 0x7c, 0x6a}, - "tUSDT", - 6}, - {{0xcd, 0x07, 0x7a, 0xbe, 0xdd, 0x83, 0x1a, 0x34, 0x43, 0xff, - 0xbe, 0x24, 0xfb, 0x76, 0x66, 0x1b, 0xbb, 0x17, 0xeb, 0x69}, - "tZRX", - 18}, - {{0x40, 0xd8, 0x97, 0x85, 0x00, 0xbf, 0x68, 0x32, 0x4a, 0x51, - 0x53, 0x3c, 0xd6, 0xa2, 0x1e, 0x3e, 0x59, 0xbe, 0x32, 0x4a}, - "tBTC", - 18}, - // Goerli DeversiFi tokens - {{0xd9, 0x97, 0xa8, 0x63, 0x46, 0xe7, 0x65, 0x18, 0xe6, 0x92, - 0x25, 0x56, 0xf3, 0x4d, 0x76, 0x61, 0x30, 0xc0, 0xbb, 0xfd}, - "tUSDT", - 6}, - {{0xc1, 0xd5, 0x79, 0xeb, 0xff, 0x7c, 0x0f, 0x6c, 0xfd, 0x9a, - 0xd5, 0xfb, 0x26, 0x7f, 0xec, 0x73, 0xbe, 0x70, 0xc8, 0xf7}, - "tBTC", - 18}, - {{0xa8, 0xf3, 0x14, 0x4f, 0xea, 0x2c, 0x37, 0x5a, 0xd0, 0x58, - 0xec, 0x12, 0x09, 0x9a, 0x5a, 0x21, 0xa2, 0x6f, 0xe9, 0x96}, - "tDVF", - 18}, - {{0x4c, 0xda, 0xbe, 0xc1, 0x2a, 0x39, 0x7f, 0xb6, 0xef, 0xaf, - 0x46, 0x13, 0xd5, 0xdf, 0xd7, 0x9b, 0x30, 0x9a, 0xe9, 0xfa}, - "tXDVF", - 18}, - -}; - -#endif diff --git a/src/extra_tokens.h b/src/extra_tokens.h deleted file mode 100644 index f6b012c..0000000 --- a/src/extra_tokens.h +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Ledger Ethereum App - * (c) 2016-2019 Ledger - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ********************************************************************************/ - -#pragma once - -#include "asset_info.h" - -#ifdef HAVE_TOKENS_EXTRA_LIST - -#define NUM_TOKENS_EXTRA 8 - -extern tokenDefinition_t const TOKENS_EXTRA[NUM_TOKENS_EXTRA]; - -#endif diff --git a/src_features/provideErc20TokenInformation/cmd_provideTokenInfo.c b/src_features/provideErc20TokenInformation/cmd_provideTokenInfo.c index d5ed912..e4f9e20 100644 --- a/src_features/provideErc20TokenInformation/cmd_provideTokenInfo.c +++ b/src_features/provideErc20TokenInformation/cmd_provideTokenInfo.c @@ -3,102 +3,9 @@ #include "public_keys.h" #include "common_ui.h" #include "os_io_seproxyhal.h" -#include "extra_tokens.h" #include "network.h" #include "manage_asset_info.h" -#ifdef HAVE_CONTRACT_NAME_IN_DESCRIPTOR - -void handleProvideErc20TokenInformation(uint8_t p1, - uint8_t p2, - const uint8_t *workBuffer, - uint8_t dataLength, - unsigned int *flags, - unsigned int *tx) { - UNUSED(p1); - UNUSED(p2); - UNUSED(flags); - uint32_t offset = 0; - uint8_t tickerLength, contractNameLength; - uint32_t chainId; - uint8_t hash[INT256_LENGTH]; - cx_sha256_t sha256; - cx_ecfp_public_key_t tokenKey; - - cx_sha256_init(&sha256); - - tokenDefinition_t *token = &get_current_asset_info()->token; - - if (dataLength < 1) { - THROW(0x6A80); - } - tickerLength = workBuffer[offset++]; - dataLength--; - if ((tickerLength + 2) >= sizeof(token->ticker)) { // +2 because ' \0' is appended to ticker - THROW(0x6A80); - } - if (dataLength < tickerLength + 1) { - THROW(0x6A80); - } - cx_hash((cx_hash_t *) &sha256, 0, workBuffer + offset, tickerLength, NULL, 0); - memmove(token->ticker, workBuffer + offset, tickerLength); - token->ticker[tickerLength] = '\0'; - offset += tickerLength; - dataLength -= tickerLength; - - contractNameLength = workBuffer[offset++]; - dataLength--; - if (dataLength < contractNameLength + 20 + 4 + 4) { - THROW(0x6A80); - } - cx_hash((cx_hash_t *) &sha256, - CX_LAST, - workBuffer + offset, - contractNameLength + 20 + 4 + 4, - hash, - 32); - memmove(token->contractName, - workBuffer + offset, - MIN(contractNameLength, sizeof(token->contractName) - 1)); - token->contractName[MIN(contractNameLength, sizeof(token->contractName) - 1)] = '\0'; - offset += contractNameLength; - dataLength -= contractNameLength; - - memmove(token->address, workBuffer + offset, 20); - offset += 20; - dataLength -= 20; - token->decimals = U4BE(workBuffer, offset); - offset += 4; - dataLength -= 4; - chainId = U4BE(workBuffer, offset); - if ((chainConfig->chainId != 0) && (chainConfig->chainId != chainId)) { - PRINTF("ChainId token mismatch\n"); - THROW(0x6A80); - } - offset += 4; - dataLength -= 4; - cx_ecfp_init_public_key(CX_CURVE_256K1, - LEDGER_SIGNATURE_PUBLIC_KEY, - sizeof(LEDGER_SIGNATURE_PUBLIC_KEY), - &tokenKey); - if (!cx_ecdsa_verify(&tokenKey, - CX_LAST, - CX_SHA256, - hash, - 32, - workBuffer + offset, - dataLength)) { -#ifndef HAVE_BYPASS_SIGNATURES - PRINTF("Invalid token signature\n"); - THROW(0x6A80); -#endif - } - validate_current_asset_info(); - THROW(0x9000); -} - -#else - void handleProvideErc20TokenInformation(uint8_t p1, uint8_t p2, const uint8_t *workBuffer, @@ -151,32 +58,15 @@ void handleProvideErc20TokenInformation(uint8_t p1, offset += 4; dataLength -= 4; -#ifdef HAVE_TOKENS_EXTRA_LIST - tokenDefinition_t *currentToken = NULL; - uint32_t index; - for (index = 0; index < NUM_TOKENS_EXTRA; index++) { - currentToken = (tokenDefinition_t *) PIC(&TOKENS_EXTRA[index]); - if (memcmp(currentToken->address, token->address, 20) == 0) { - strcpy((char *) token->ticker, (char *) currentToken->ticker); - token->decimals = currentToken->decimals; - break; - } - } - if (index < NUM_TOKENS_EXTRA) { - PRINTF("Descriptor whitelisted\n"); - } else -#endif - { - CX_ASSERT(cx_ecfp_init_public_key_no_throw(CX_CURVE_256K1, - LEDGER_SIGNATURE_PUBLIC_KEY, - sizeof(LEDGER_SIGNATURE_PUBLIC_KEY), - &tokenKey)); - if (!cx_ecdsa_verify_no_throw(&tokenKey, hash, 32, workBuffer + offset, dataLength)) { + CX_ASSERT(cx_ecfp_init_public_key_no_throw(CX_CURVE_256K1, + LEDGER_SIGNATURE_PUBLIC_KEY, + sizeof(LEDGER_SIGNATURE_PUBLIC_KEY), + &tokenKey)); + if (!cx_ecdsa_verify_no_throw(&tokenKey, hash, 32, workBuffer + offset, dataLength)) { #ifndef HAVE_BYPASS_SIGNATURES - PRINTF("Invalid token signature\n"); - THROW(0x6A80); + PRINTF("Invalid token signature\n"); + THROW(0x6A80); #endif - } } G_io_apdu_buffer[0] = tmpCtx.transactionContext.currentAssetIndex; @@ -184,5 +74,3 @@ void handleProvideErc20TokenInformation(uint8_t p1, U2BE_ENCODE(G_io_apdu_buffer, 1, APDU_RESPONSE_OK); io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 3); } - -#endif