From eced04187074718c77d2a1085264b31093435535 Mon Sep 17 00:00:00 2001 From: markrypt0 Date: Thu, 26 Jan 2023 10:21:33 -0700 Subject: [PATCH] remove obsolete cfunc code --- deps/python-keepkey | 2 +- include/keepkey/firmware/ethereum_contracts.h | 5 - .../firmware/ethereum_contracts/confuncs.h | 34 ---- lib/firmware/CMakeLists.txt | 1 - lib/firmware/ethereum.c | 24 --- lib/firmware/ethereum_contracts.c | 14 -- .../ethereum_contracts/contractfuncs.c | 191 ------------------ 7 files changed, 1 insertion(+), 270 deletions(-) delete mode 100644 include/keepkey/firmware/ethereum_contracts/confuncs.h delete mode 100644 lib/firmware/ethereum_contracts/contractfuncs.c diff --git a/deps/python-keepkey b/deps/python-keepkey index 1e32069bd..b7af582e9 160000 --- a/deps/python-keepkey +++ b/deps/python-keepkey @@ -1 +1 @@ -Subproject commit 1e32069bd8e6f38d1d5a95c2fb17e23f1712a6df +Subproject commit b7af582e9a380ad5b440a533734857728966ac85 diff --git a/include/keepkey/firmware/ethereum_contracts.h b/include/keepkey/firmware/ethereum_contracts.h index ac1350714..78fe1c6c9 100644 --- a/include/keepkey/firmware/ethereum_contracts.h +++ b/include/keepkey/firmware/ethereum_contracts.h @@ -33,9 +33,4 @@ bool ethereum_contractHandled(uint32_t data_total, const EthereumSignTx *msg, /// \return true iff the user has confirmed the custom ETH signing request bool ethereum_contractConfirmed(uint32_t data_total, const EthereumSignTx *msg, const HDNode *node); - -bool ethereum_cFuncHandled(const EthereumSignTx *msg); - -bool ethereum_cFuncConfirmed(uint32_t data_total, const EthereumSignTx *msg); - #endif diff --git a/include/keepkey/firmware/ethereum_contracts/confuncs.h b/include/keepkey/firmware/ethereum_contracts/confuncs.h deleted file mode 100644 index 13ecbc9bb..000000000 --- a/include/keepkey/firmware/ethereum_contracts/confuncs.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * This file is part of the KeepKey project. - * - * Copyright (C) 2022 markrypto - * - * This library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - */ - -#ifndef KEEPKEY_FIRMWARE_CONTRACTFUNCS_H -#define KEEPKEY_FIRMWARE_CONTRACTFUNCS_H - -#include -#include - -// used by gnosis proxy contracts -#define EXEC_TRANSACTION "\x6a\x76\x12\x02" - -typedef struct _EthereumSignTx EthereumSignTx; - -bool cf_isExecTx(const EthereumSignTx *msg); -bool cf_confirmExecTx(uint32_t data_total, const EthereumSignTx *msg); - -#endif diff --git a/lib/firmware/CMakeLists.txt b/lib/firmware/CMakeLists.txt index f8d610865..edb553a39 100644 --- a/lib/firmware/CMakeLists.txt +++ b/lib/firmware/CMakeLists.txt @@ -12,7 +12,6 @@ set(sources ethereum.c ethereum_contracts.c ethereum_contracts/makerdao.c - ethereum_contracts/contractfuncs.c ethereum_contracts/saproxy.c ethereum_contracts/zxappliquid.c ethereum_contracts/thortx.c diff --git a/lib/firmware/ethereum.c b/lib/firmware/ethereum.c index 59c9b3d45..d96a3092d 100644 --- a/lib/firmware/ethereum.c +++ b/lib/firmware/ethereum.c @@ -698,30 +698,6 @@ void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node, data_needs_confirm = false; } - // contract function may be recognized even though contract is not, e.g., gnosis safe execTransaction - if (msg->to.size && ethereum_cFuncHandled(msg)) { - // confirm contract address - char addr[43] = "0x"; - ethereum_address_checksum(msg->to.bytes, addr + 2, false, chain_id); - - if (!confirm(ButtonRequestType_ButtonRequest_ConfirmOutput, "contract address", "%s", addr)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, - "Signing cancelled by user"); - ethereum_signing_abort(); - return; - } - - // confirm contract data - if (!ethereum_cFuncConfirmed(data_total, msg)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, - "Signing cancelled by user"); - ethereum_signing_abort(); - return; - } - needs_confirm = false; - data_needs_confirm = false; - } - // detect ERC-20 token if (data_total == 68 && ethereum_isStandardERC20Transfer(msg)) { token = tokenByChainAddress(chain_id, msg->to.bytes); diff --git a/lib/firmware/ethereum_contracts.c b/lib/firmware/ethereum_contracts.c index 047064c3c..69fc6e694 100644 --- a/lib/firmware/ethereum_contracts.c +++ b/lib/firmware/ethereum_contracts.c @@ -20,7 +20,6 @@ #include "keepkey/firmware/ethereum_contracts.h" -#include "keepkey/firmware/ethereum_contracts/confuncs.h" #include "keepkey/firmware/ethereum_contracts/saproxy.h" #include "keepkey/firmware/ethereum_contracts/thortx.h" #include "keepkey/firmware/ethereum_contracts/zxappliquid.h" @@ -29,19 +28,6 @@ #include "keepkey/firmware/ethereum_contracts/zxswap.h" #include "keepkey/firmware/ethereum_contracts/makerdao.h" - -bool ethereum_cFuncHandled(const EthereumSignTx *msg) { - if (cf_isExecTx(msg)) return true; // used in gnosis proxy contracts - return false; -} - -bool ethereum_cFuncConfirmed(uint32_t data_total, const EthereumSignTx *msg) { - if (cf_isExecTx(msg)) { - return cf_confirmExecTx(data_total, msg); - } - return false; -} - bool ethereum_contractHandled(uint32_t data_total, const EthereumSignTx *msg, const HDNode *node) { (void)node; diff --git a/lib/firmware/ethereum_contracts/contractfuncs.c b/lib/firmware/ethereum_contracts/contractfuncs.c deleted file mode 100644 index 6219acf27..000000000 --- a/lib/firmware/ethereum_contracts/contractfuncs.c +++ /dev/null @@ -1,191 +0,0 @@ -/* - * This file is part of the KeepKey project. - * - * Copyright (C) 2022 markrypto - * - * This library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - */ - -#include "keepkey/firmware/ethereum_contracts/confuncs.h" - -#include "keepkey/board/confirm_sm.h" -#include "keepkey/board/util.h" -#include "keepkey/firmware/ethereum.h" -#include "keepkey/firmware/ethereum_tokens.h" -#include "keepkey/firmware/fsm.h" -#include "trezor/crypto/address.h" - -bool cf_isExecTx(const EthereumSignTx *msg) { - if (memcmp(msg->data_initial_chunk.bytes, EXEC_TRANSACTION, 4) == 0) - return true; - - return false; -} - -bool cf_confirmExecTx(uint32_t data_total, const EthereumSignTx *msg) { - extern const ecdsa_curve secp256k1; - (void)data_total; - char confStr[131]; - char contractStr[41]; - uint8_t *to, *gasToken, *refundReceiver, *data; - bignum256 bnNum, gasPrice; - char txStr[32], safeGasStr[32], baseGasStr[32], gasPriceStr[32]; - TokenType const *TokenData; - int8_t *operation; - uint32_t offset, dlen; - char const *confDatStr, *confDatStr2; - unsigned ctr, n, chunk, chunkSize; - const char *title = "contract func exec_tx"; - - to = (uint8_t *)(msg->data_initial_chunk.bytes + 4 + 0*32 + 12); - for (ctr=0; ctr<20; ctr++) { - snprintf(&confStr[ctr*2], 3, "%02x", to[ctr]); - } - if (!confirm(ButtonRequestType_ButtonRequest_ConfirmOutput, - title, "Sending to %s", confStr)) { - return false; - } - - // value - bn_from_bytes(msg->data_initial_chunk.bytes + 4 + 1*32, 32, &bnNum); - ethereumFormatAmount(&bnNum, NULL, 1 /*chainId*/, txStr, sizeof(txStr)); - if (!confirm(ButtonRequestType_ButtonRequest_ConfirmOutput, - title, "amount %s", txStr)) { - return false; - } - - // get data bytes - bn_from_bytes(msg->data_initial_chunk.bytes + 4 + 2*32, 32, &bnNum); // data offset - offset = bn_write_uint32(&bnNum); - bn_from_bytes(msg->data_initial_chunk.bytes + 4 + offset, 32, &bnNum); // data len - dlen = bn_write_uint32(&bnNum); - data = (uint8_t *)(msg->data_initial_chunk.bytes + 4 + 32 + offset); - - n = 1; - chunkSize = 39; - while (true) { - chunk=chunkSize*(n-1); - for (ctr=chunk; ctr= dlen) { - break; - } - n++; - } - - // operation is an enum: https://github.com/safe-global/safe-contracts/blob/main/contracts/common/Enum.sol#L7 - operation = (int8_t *)(msg->data_initial_chunk.bytes + 4 + 3*32); - { - char *opStr; - switch (*operation) { - case 0: - opStr = "Call"; - break; - case 1: - opStr = "DelegateCall"; - break; - default: - opStr = "Unknown"; - } - if (!confirm(ButtonRequestType_ButtonRequest_ConfirmOutput, - title, "Operation: %s", opStr)) { - return false; - } - } - - bn_from_bytes(msg->data_initial_chunk.bytes + 4 + 6*32, 32, &gasPrice); // used for payment calc - ethereumFormatAmount(&gasPrice, NULL, 1 /*chainId*/, gasPriceStr, sizeof(gasPriceStr)); - - bn_from_bytes(msg->data_initial_chunk.bytes + 4 + 4*32, 32, &bnNum); // safe transaction gas - bn_multiply(&gasPrice, &bnNum, &secp256k1.prime); - ethereumFormatAmount(&bnNum, NULL, 1 /*chainId*/, safeGasStr, sizeof(safeGasStr)); - - bn_from_bytes(msg->data_initial_chunk.bytes + 4 + 5*32, 32, &bnNum); // independent gas needed - bn_multiply(&gasPrice, &bnNum, &secp256k1.prime); - ethereumFormatAmount(&bnNum, NULL, 1 /*chainId*/, baseGasStr, sizeof(baseGasStr)); - - if (!confirm(ButtonRequestType_ButtonRequest_ConfirmOutput, - title, "Safe tx gas: %s\nBase gas: %s\nGas price: %s", safeGasStr, baseGasStr, gasPriceStr)) { - return false; - } - - // gas token - gasToken = (uint8_t *)(msg->data_initial_chunk.bytes + 4 + 7*32 + 12); // token to be used for gas payment - bn_from_bytes(msg->data_initial_chunk.bytes + 4 + 7*32, 32, &bnNum); // used to check for zero - if (bn_is_zero(&bnNum)) { - // gas payment in ETH - confDatStr = "ETH"; - } else { - // gas payment in token - TokenData = tokenByChainAddress(1 /*chainId*/, (uint8_t *)gasToken); - if (strncmp(TokenData->ticker, " UNKN", 5) == 0) { - for (ctr=0; ctr<20; ctr++) { - snprintf(&contractStr[2*ctr], 3, "%02x", TokenData->address[ctr]); - } - confDatStr = contractStr; - } else { - confDatStr = TokenData->ticker; - } - } - - refundReceiver = (uint8_t *)(msg->data_initial_chunk.bytes + 4 + 8*32 + 12); // gas refund receiver - bn_from_bytes(msg->data_initial_chunk.bytes + 4 + 8*32, 32, &bnNum); // used to check for zero - if (bn_is_zero(&bnNum)) { - // gas refund receiver is origin - confDatStr2 = "tx origin"; - } else { - // gas refund receiver address - for (ctr=0; ctr<20; ctr++) { - snprintf(&contractStr[2*ctr], 3, "%02x", refundReceiver[ctr]); - } - confDatStr2 = contractStr; - } - - - if (!confirm(ButtonRequestType_ButtonRequest_ConfirmOutput, - title, "Gas payment token: %s\nGas refund address: %s", confDatStr, confDatStr2)) { - return false; - } - - // get signature data - bn_from_bytes(msg->data_initial_chunk.bytes + 4 + 9*32, 32, &bnNum); // sig offset - offset = bn_write_uint32(&bnNum); - bn_from_bytes(msg->data_initial_chunk.bytes + 4 + offset, 32, &bnNum); // sig data len - dlen = bn_write_uint32(&bnNum); - data = (uint8_t *)(msg->data_initial_chunk.bytes + 4 + 32 + offset); - - - n = 1; - chunkSize = 65; - while (true) { - chunk=chunkSize*(n-1); - for (ctr=chunk; ctr= dlen) { - break; - } - n++; - } - return true; -}