Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M2 #1

Merged
merged 34 commits into from
Aug 26, 2024
Merged

M2 #1

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b681832
Parsing simple transaction
0xPxt Aug 8, 2024
4e8e117
Refactor parserGetItem
0xPxt Aug 9, 2024
7d81624
Create items files
0xPxt Aug 12, 2024
aaf4e42
Clean compilation warnings
0xPxt Aug 12, 2024
e033635
Stop storing duplicate data for items
0xPxt Aug 13, 2024
1650152
transfer.rotate + raise warnings when no clist
0xPxt Aug 13, 2024
6ef14c7
Crosschain transfers and some corner case handling
0xPxt Aug 14, 2024
86ccf9e
Item functions cleanup
0xPxt Aug 14, 2024
268ef65
Modularize items files
0xPxt Aug 16, 2024
9c0d73d
Page test vectors
0xPxt Aug 16, 2024
363e499
Error checking
0xPxt Aug 19, 2024
2be9fa0
Solve stack overflows
0xPxt Aug 19, 2024
e7f77db
Upload snapshots
0xPxt Aug 20, 2024
eea2ad8
Minor size adjustments
0xPxt Aug 20, 2024
83124ef
Change test name
0xPxt Aug 20, 2024
b57455a
Remove crypto from cpp_test
0xPxt Aug 20, 2024
eb61190
Clean Up TODOs
0xPxt Aug 21, 2024
f70be3e
Improved code readability and error checking
0xPxt Aug 21, 2024
765ee62
Formatting
0xPxt Aug 21, 2024
064852e
Sort includes
0xPxt Aug 21, 2024
218b384
Adjusted some values and conditions
0xPxt Aug 21, 2024
991d66a
Fixing edge cases shown when fuzzing
0xPxt Aug 22, 2024
204c23d
fix heap overflow
abenso Aug 22, 2024
bd85e73
fixes
abenso Aug 22, 2024
a58c5e3
Fix more heap overflows
0xPxt Aug 23, 2024
3c40156
check max_items are not surpassed
0xPxt Aug 23, 2024
486194c
Minor fixes
0xPxt Aug 23, 2024
4e5c71d
Remove unused values
0xPxt Aug 23, 2024
e4e1cbb
Remove more unused values
0xPxt Aug 23, 2024
68cc393
fix icons
abenso Aug 23, 2024
604f723
bump version and update snapshots
abenso Aug 23, 2024
b4fbcf7
fix ci
abenso Aug 23, 2024
e7e6e96
minimize string copies
abenso Aug 23, 2024
f3f2f8c
Improve code readability
0xPxt Aug 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,16 @@ add_definitions(
)


##############################################################
##{TODO}
##############################################################
# Static Libraries
file(GLOB_RECURSE LIB_SRC

file(GLOB_RECURSE BLAKE_SRC
${CMAKE_CURRENT_SOURCE_DIR}/deps/BLAKE2/ref/blake2b-ref.c
)

file(GLOB_RECURSE LIB_SRC
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/app_mode.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/base64.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/base58.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/bech32.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/bignum.c
Expand All @@ -139,20 +142,32 @@ file(GLOB_RECURSE LIB_SRC
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/zxformat.c
####
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/items.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/items_format.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser_impl.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/crypto_helper.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/json/json_parser.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/jsmn/jsmn.c
)

add_library(app_lib STATIC ${LIB_SRC})
add_library(app_lib STATIC
${LIB_SRC}
${JSMN_SRC}
${BLAKE_SRC}
)

target_include_directories(app_lib PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/deps/BLAKE2/ref
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/include
${CMAKE_CURRENT_SOURCE_DIR}/app/src
${CMAKE_CURRENT_SOURCE_DIR}/app/src/lib
${CMAKE_CURRENT_SOURCE_DIR}/app/src/common
${CMAKE_CURRENT_SOURCE_DIR}/app/src/json
${CMAKE_CURRENT_SOURCE_DIR}/app/src/jsmn
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/app/common
)

target_link_libraries(app_lib PUBLIC)

##############################################################
# Fuzz Targets
if(ENABLE_FUZZING)
Expand All @@ -177,6 +192,8 @@ else()
${gmock_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/app/src
${CMAKE_CURRENT_SOURCE_DIR}/app/src/lib
${CMAKE_CURRENT_SOURCE_DIR}/app/src/json
${CMAKE_CURRENT_SOURCE_DIR}/app/src/jsmn
)

target_link_libraries(unittests PRIVATE
Expand All @@ -188,4 +205,4 @@ else()
add_compile_definitions(TESTVECTORS_DIR="${CMAKE_CURRENT_SOURCE_DIR}/tests/")
add_test(NAME unittests COMMAND unittests)
set_tests_properties(unittests PROPERTIES WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests)
endif()
endif()
8 changes: 3 additions & 5 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ DEFINES += PRODUCTION_BUILD=$(PRODUCTION_BUILD)
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.app_testing

ifndef COIN
COIN=KDA
COIN=kadena
endif

include $(CURDIR)/Makefile.version

$(info COIN = [$(COIN)])

ifeq ($(COIN),KDA)
ifeq ($(COIN),kadena)
# Main app configuration
APPNAME = "Kadena"
APPPATH = "44'/626'"
Expand Down Expand Up @@ -99,12 +99,10 @@ endif

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.platform
CFLAGS += -Wvla
# #{TODO} --> Need Rust?
# LDFLAGS += -z muldefs
# LDLIBS += -Lrust/target/thumbv6m-none-eabi/release -lrslib
# APP_SOURCE_PATH += $(CURDIR)/rust/include

# #{TODO} --> Need Rust?
.PHONY: rust
rust:
@echo "No rust code"
Expand Down Expand Up @@ -141,7 +139,7 @@ dep/%.d: %.c Makefile

.PHONY: listvariants
listvariants:
@echo VARIANTS COIN KDA
@echo VARIANTS COIN kadena

.PHONY: version
version:
Expand Down
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ APPVERSION_M=0
# This is the minor version
APPVERSION_N=0
# This is the patch version
APPVERSION_P=1
APPVERSION_P=2
Binary file modified app/flex_icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/glyphs/icon_stax_32.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/glyphs/icon_stax_64.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ void extractHDPath(uint32_t rx, uint32_t offset) {

memcpy(hdPath, G_io_apdu_buffer + offset, sizeof(uint32_t) * HDPATH_LEN_DEFAULT);

// #{TODO} --> testnet necessary?
const bool mainnet = hdPath[0] == HDPATH_0_DEFAULT && hdPath[1] == HDPATH_1_DEFAULT;

if (!mainnet) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/common/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const char *parser_getErrorDescription(parser_error_t err);
const char *parser_getMsgPackTypeDescription(uint8_t type);

//// parses a tx buffer
parser_error_t parser_parse(parser_context_t *ctx, const uint8_t *data, size_t dataLen, parser_tx_t *tx_obj);
parser_error_t parser_parse(parser_context_t *ctx, const uint8_t *data, size_t dataLen, tx_json_t *tx_obj);

//// verifies tx fields
parser_error_t parser_validate(parser_context_t *ctx);
Expand Down
23 changes: 13 additions & 10 deletions app/src/common/parser_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ extern "C" {
#include <stddef.h>
#include <stdint.h>

#include "parser_txdef.h"

#define CHECK_ERROR(__CALL) \
{ \
parser_error_t __err = __CALL; \
Expand Down Expand Up @@ -56,15 +54,20 @@ typedef enum {
parser_missing_field,
paser_unknown_transaction,
parser_tx_obj_empty,
} parser_error_t;

typedef struct {
const uint8_t *buffer;
uint16_t bufferLen;
uint16_t offset;
parser_tx_t *tx_obj;
} parser_context_t;
// Coin Specific
parser_json_zero_tokens,
parser_json_too_many_tokens, // "NOMEM: JSON string contains too many tokens"
parser_json_incomplete_json, // "JSON string is not complete";
parser_json_not_a_transfer,
parser_invalid_meta_field,
parser_json_unexpected_error,
parser_name_tx_transfer,
parser_name_tx_transfer_xchain,
parser_name_rotate,
parser_name_gas,
} parser_error_t;

#ifdef __cplusplus
}
#endif
#endif
2 changes: 1 addition & 1 deletion app/src/common/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ storage_t NV_CONST N_appdata_impl __attribute__((aligned(64)));
#define N_appdata (*(NV_VOLATILE storage_t *)PIC(&N_appdata_impl))
#endif

static parser_tx_t tx_obj;
static tx_json_t tx_obj;
static parser_context_t ctx_parsed_tx;

void tx_initialize() {
Expand Down
Loading
Loading