Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Kusama v26.1002005 #209

Merged
merged 6 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
50 changes: 37 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#*******************************************************************************
#* (c) 2020 Zondax GmbH
#* (c) 2018 - 2024 Zondax AGs
#*
#* Licensed under the Apache License, Version 2.0 (the "License");
#* you may not use this file except in compliance with the License.
Expand All @@ -13,12 +13,32 @@
#* See the License for the specific language governing permissions and
#* limitations under the License.
#********************************************************************************
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.28)
include("cmake/HunterGate.cmake")
HunterGate(
URL "https://github.com/cpp-pm/hunter/archive/v0.25.5.tar.gz"
SHA1 "a20151e4c0740ee7d0f9994476856d813cdead29"
LOCAL
)

if(CMAKE_GENERATOR MATCHES "Ninja")
message(FATAL_ERROR "This project does not support the Ninja generator. "
"Please use Unix Makefiles or another supported generator. "
"This error is typical in CLion. In this case, switch to generator Unix Makefiles.")
endif()

########################################################

project(ledger-kusama VERSION 0.0.0)
enable_testing()

set(CMAKE_CXX_STANDARD 17)
cmake_policy(SET CMP0025 NEW)
set(CMAKE_CXX_STANDARD 11)
cmake_policy(SET CMP0144 NEW)

set(HUNTER_STATUS_DEBUG ON)
set(HUNTER_TLS_VERIFY OFF)

enable_testing()

option(ENABLE_FUZZING "Build with fuzzing instrumentation and build fuzz targets" OFF)
option(ENABLE_COVERAGE "Build with source code coverage instrumentation" OFF)
Expand All @@ -31,6 +51,15 @@ string(APPEND CMAKE_LINKER_FLAGS " -fno-omit-frame-pointer -g")
add_definitions(-DAPP_STANDARD)
add_definitions(-DSUBSTRATE_PARSER_FULL)

hunter_add_package(fmt)
find_package(fmt CONFIG REQUIRED)

hunter_add_package(jsoncpp)
find_package(jsoncpp CONFIG REQUIRED)

hunter_add_package(GTest)
find_package(GTest CONFIG REQUIRED)

if(ENABLE_FUZZING)
add_definitions(-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1)
SET(ENABLE_SANITIZERS ON CACHE BOOL "Sanitizer automatically enabled" FORCE)
Expand Down Expand Up @@ -71,9 +100,6 @@ if(ENABLE_SANITIZERS)
string(APPEND CMAKE_LINKER_FLAGS " -fsanitize=address,undefined -fsanitize-recover=address,undefined")
endif()

include(cmake/conan/CMakeLists.txt)
add_subdirectory(cmake/gtest)

set (RETRIEVE_MAJOR_CMD
"cat ${CMAKE_CURRENT_SOURCE_DIR}/app/Makefile.version | grep APPVERSION_M | cut -b 14- | tr -d '\n'"
)
Expand Down Expand Up @@ -140,20 +166,18 @@ add_executable(unittests ${TESTS_SRC})
target_include_directories(unittests PRIVATE
${gtest_SOURCE_DIR}/include
${gmock_SOURCE_DIR}/include
${CONAN_INCLUDE_DIRS_FMT}
${CONAN_INCLUDE_DIRS_JSONCPP}
${CMAKE_CURRENT_SOURCE_DIR}/app/src
${CMAKE_CURRENT_SOURCE_DIR}/app/src/lib
)

target_link_libraries(unittests PRIVATE
gtest_main
app_lib
CONAN_PKG::fmt
CONAN_PKG::jsoncpp)
GTest::gtest_main
fmt::fmt
JsonCpp::JsonCpp)

add_compile_definitions(TESTVECTORS_DIR="${CMAKE_CURRENT_SOURCE_DIR}/tests/")
add_test(unittests ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittests)
add_test(NAME unittests COMMAND unittests)
set_tests_properties(unittests PROPERTIES WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests)

##############################################################
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ifeq ($(BOLOS_SDK),)

ZXLIB_COMPILE_STAX ?= 1
SUBSTRATE_PARSER_FULL ?= 1
PRODUCTION_BUILD ?= 0
include $(CURDIR)/deps/ledger-zxlib/dockerized_build.mk

else
Expand All @@ -47,6 +48,7 @@ zemu_install: tests_tools_build

test_all:
make zemu_install
SUBSTRATE_PARSER_FULL=1 make
SUBSTRATE_PARSER_FULL=1 SUPPORT_SR25519=1 make buildS
PRODUCTION_BUILD=1 SUBSTRATE_PARSER_FULL=1 make
make clean_build
PRODUCTION_BUILD=1 SUBSTRATE_PARSER_FULL=1 SUPPORT_SR25519=1 make buildS
make zemu_test
615 changes: 322 additions & 293 deletions README.md

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,22 @@ include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.installer_script

include $(BOLOS_SDK)/Makefile.defines

# Set the default value for PRODUCTION_BUILD to 0 if not already defined
PRODUCTION_BUILD ?= 0

DEFINES += APP_SECRET_MODE_ENABLED

$(info ************ TARGET_NAME = [$(TARGET_NAME)])

# Display whether this is a production build or for internal use
ifeq ($(PRODUCTION_BUILD), 1)
$(info ************ PRODUCTION_BUILD = [PRODUCTION BUILD])
else
$(info ************ PRODUCTION_BUILD = [INTERNAL USE])
endif
# Add the PRODUCTION_BUILD definition to the compiler flags
DEFINES += PRODUCTION_BUILD=$(PRODUCTION_BUILD)

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.app_testing

ifeq ($(SUPPORT_SR25519),1)
Expand Down
4 changes: 2 additions & 2 deletions app/Makefile.version
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is the `transaction_version` field of `Runtime`
APPVERSION_M=25
APPVERSION_M=26
# This is the `spec_version` field of `Runtime`
APPVERSION_N=10100
APPVERSION_N=1002005
# This is the patch version of this release
APPVERSION_P=0
15 changes: 15 additions & 0 deletions app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,29 @@ parser_error_t _readTx(parser_context_t *c, parser_tx_t *v) {
// Now forward parse
CHECK_ERROR(_readCallIndex(c, &v->callIndex))
CHECK_ERROR(_readMethod(c, v->callIndex.moduleIdx, v->callIndex.idx, &v->method))
// SignedExtensions: included_in_extrinsic
CHECK_ERROR(_readEra(c, &v->era))
CHECK_ERROR(_readCompactIndex(c, &v->nonce))
CHECK_ERROR(_readCompactBalance(c, &v->tip))
if (v->transactionVersion == SUPPORTED_TX_VERSION_CURRENT) {
CHECK_ERROR(_readUInt8(c, &v->mode));
}

// SignedExtensions: included_in_signed_data
CHECK_ERROR(_readUInt32(c, &v->specVersion))
CHECK_ERROR(_readUInt32(c, &v->transactionVersion))
CHECK_ERROR(_readHash(c, &v->genesisHash))
CHECK_ERROR(_readHash(c, &v->blockHash))

if (v->transactionVersion == SUPPORTED_TX_VERSION_CURRENT) {
uint8_t optMetadataHash = 0;
CHECK_ERROR(_readUInt8(c, &optMetadataHash));
// Reject the transaction if Mode=Enabled or MetadataDigest is present
if (v->mode == 1 || optMetadataHash == 1) {
return parser_unexpected_value;
}
}

if (c->offset < c->bufferLen) {
return parser_unexpected_unparsed_bytes;
}
Expand Down
53 changes: 50 additions & 3 deletions app/src/parser_impl_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,46 @@ parser_error_t _toStringCompactBalance(const pd_CompactBalance_t *v,
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
static parser_error_t _checkVersionsV26(parser_context_t *c) {
// Methods are not length delimited so in order to retrieve the specVersion
// it is necessary to parse from the back.
// The transaction is expect to end in
// [4 bytes] specVersion
// [4 bytes] transactionVersion
// [32 bytes] genesisHash
// [32 bytes] blockHash
// [1 / 33 bytes] opt<checkMetadataHash> --> Only None is supported
const uint16_t specOffsetFromBack = 4 + 4 + 32 + 32 + 1;
if (c->bufferLen < specOffsetFromBack) {
return parser_unexpected_buffer_end;
}

parser_error_t _checkVersions(parser_context_t *c) {
uint8_t *p = (uint8_t *) (c->buffer + c->bufferLen - specOffsetFromBack);
uint32_t specVersion = 0;
specVersion += (uint32_t) p[0] << 0u;
specVersion += (uint32_t) p[1] << 8u;
specVersion += (uint32_t) p[2] << 16u;
specVersion += (uint32_t) p[3] << 24u;

p += 4;
uint32_t transactionVersion = 0;
transactionVersion += (uint32_t) p[0] << 0u;
transactionVersion += (uint32_t) p[1] << 8u;
transactionVersion += (uint32_t) p[2] << 16u;
transactionVersion += (uint32_t) p[3] << 24u;

if (transactionVersion != (SUPPORTED_TX_VERSION_CURRENT) ||
specVersion != SUPPORTED_SPEC_VERSION) {
return parser_tx_version_not_supported;
}

c->tx_obj->specVersion = specVersion;
c->tx_obj->transactionVersion = transactionVersion;
c->tx_obj->mode = 0;
return parser_ok;
}

static parser_error_t _checkVersionsV25(parser_context_t *c) {
// Methods are not length delimited so in order to retrieve the specVersion
// it is necessary to parse from the back.
// The transaction is expect to end in
Expand All @@ -351,8 +389,7 @@ parser_error_t _checkVersions(parser_context_t *c) {
transactionVersion += (uint32_t) p[2] << 16u;
transactionVersion += (uint32_t) p[3] << 24u;

if (transactionVersion != (SUPPORTED_TX_VERSION_CURRENT) &&
transactionVersion != (SUPPORTED_TX_VERSION_PREVIOUS)) {
if (transactionVersion != (SUPPORTED_TX_VERSION_PREVIOUS)) {
return parser_tx_version_not_supported;
}

Expand All @@ -366,6 +403,16 @@ parser_error_t _checkVersions(parser_context_t *c) {
return parser_ok;
}

parser_error_t _checkVersions(parser_context_t *c) {
const parser_error_t withoutMode = _checkVersionsV25(c);
const parser_error_t modeDisabled = _checkVersionsV26(c);

if (withoutMode != parser_ok && modeDisabled != parser_ok) {
return parser_tx_version_not_supported;
}
return parser_ok;
}

uint16_t __address_type;

uint16_t _getAddressType() {
Expand Down
1 change: 1 addition & 0 deletions app/src/parser_txdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef struct {
pd_CompactBalance_t tip;
uint32_t specVersion;
uint32_t transactionVersion;
uint8_t mode;

pd_Hash_t genesisHash;
pd_Hash_t blockHash;
Expand Down
17 changes: 17 additions & 0 deletions app/src/substrate/substrate_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ parser_error_t _readMethod(
pd_Method_t* method)
{
switch (c->tx_obj->transactionVersion) {
case 26:
return _readMethod_V26(c, moduleIdx, callIdx, &method->V26);
case 25:
return _readMethod_V25(c, moduleIdx, callIdx, &method->V25);
default:
Expand All @@ -36,6 +38,8 @@ parser_error_t _readMethod(
uint8_t _getMethod_NumItems(uint32_t transactionVersion, uint8_t moduleIdx, uint8_t callIdx)
{
switch (transactionVersion) {
case 26:
return _getMethod_NumItems_V26(moduleIdx, callIdx);
case 25:
return _getMethod_NumItems_V25(moduleIdx, callIdx);
default:
Expand All @@ -46,6 +50,8 @@ uint8_t _getMethod_NumItems(uint32_t transactionVersion, uint8_t moduleIdx, uint
const char* _getMethod_ModuleName(uint32_t transactionVersion, uint8_t moduleIdx)
{
switch (transactionVersion) {
case 26:
return _getMethod_ModuleName_V26(moduleIdx);
case 25:
return _getMethod_ModuleName_V25(moduleIdx);
default:
Expand All @@ -56,6 +62,8 @@ const char* _getMethod_ModuleName(uint32_t transactionVersion, uint8_t moduleIdx
const char* _getMethod_Name(uint32_t transactionVersion, uint8_t moduleIdx, uint8_t callIdx)
{
switch (transactionVersion) {
case 26:
return _getMethod_Name_V26(moduleIdx, callIdx);
case 25:
return _getMethod_Name_V25(moduleIdx, callIdx);
default:
Expand All @@ -66,6 +74,8 @@ const char* _getMethod_Name(uint32_t transactionVersion, uint8_t moduleIdx, uint
const char* _getMethod_ItemName(uint32_t transactionVersion, uint8_t moduleIdx, uint8_t callIdx, uint8_t itemIdx)
{
switch (transactionVersion) {
case 26:
return _getMethod_ItemName_V26(moduleIdx, callIdx, itemIdx);
case 25:
return _getMethod_ItemName_V25(moduleIdx, callIdx, itemIdx);
default:
Expand All @@ -78,6 +88,9 @@ parser_error_t _getMethod_ItemValue(uint32_t transactionVersion, pd_Method_t* m,
uint8_t pageIdx, uint8_t* pageCount)
{
switch (transactionVersion) {
case 26:
return _getMethod_ItemValue_V26(&m->V26, moduleIdx, callIdx, itemIdx, outValue,
outValueLen, pageIdx, pageCount);
case 25:
return _getMethod_ItemValue_V25(&m->V25, moduleIdx, callIdx, itemIdx, outValue,
outValueLen, pageIdx, pageCount);
Expand All @@ -89,6 +102,8 @@ parser_error_t _getMethod_ItemValue(uint32_t transactionVersion, pd_Method_t* m,
bool _getMethod_ItemIsExpert(uint32_t transactionVersion, uint8_t moduleIdx, uint8_t callIdx, uint8_t itemIdx)
{
switch (transactionVersion) {
case 26:
return _getMethod_ItemIsExpert_V26(moduleIdx, callIdx, itemIdx);
case 25:
return _getMethod_ItemIsExpert_V25(moduleIdx, callIdx, itemIdx);
default:
Expand All @@ -99,6 +114,8 @@ bool _getMethod_ItemIsExpert(uint32_t transactionVersion, uint8_t moduleIdx, uin
bool _getMethod_IsNestingSupported(uint32_t transactionVersion, uint8_t moduleIdx, uint8_t callIdx)
{
switch (transactionVersion) {
case 26:
return _getMethod_IsNestingSupported_V26(moduleIdx, callIdx);
case 25:
return _getMethod_IsNestingSupported_V25(moduleIdx, callIdx);
default:
Expand Down
4 changes: 4 additions & 0 deletions app/src/substrate/substrate_dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern "C" {
#include "parser_common.h"
#include "stdbool.h"
#include "substrate_dispatch_V25.h"
#include "substrate_dispatch_V26.h"
#include <stddef.h>
#include <stdint.h>

Expand All @@ -32,6 +33,9 @@ extern "C" {
{ \
switch (txVersion) { \
\
case 26: \
return PD_CALL_##CALL##_V26; \
\
case 25: \
return PD_CALL_##CALL##_V25; \
\
Expand Down
Loading
Loading