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

Commit

Permalink
avoid misaligned dereference + more testing
Browse files Browse the repository at this point in the history
cleaner switch/cases
  • Loading branch information
jleni committed May 4, 2020
1 parent 41a5ed9 commit 7cdc9ae
Show file tree
Hide file tree
Showing 22 changed files with 1,054 additions and 1,063 deletions.
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
APPVERSION_M=0
APPVERSION_N=1058
APPVERSION_P=0
APPVERSION_P=2
4 changes: 3 additions & 1 deletion app/src/coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ typedef enum {

#define MENU_MAIN_APP_LINE1 "Kusama"
#define MENU_MAIN_APP_LINE2 "Web3"
#define APPVERSION_LINE2 ""

#define APPVERSION_LINE1 "Kusama"
#define APPVERSION_LINE2 "v"APPVERSION

// Specific to Kusama
#define PK_ADDRESS_TYPE 02
Expand Down
10 changes: 8 additions & 2 deletions app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,14 @@ parser_error_t _checkSpecVersion(parser_context_t *c) {
return parser_unexpected_buffer_end;
}

const uint32_t *const p = (uint32_t *) (c->buffer + c->bufferLen - specOffsetFromBack);
if (*p != SUPPORTED_SPEC_VERSION) {
uint8_t *p = (uint8_t *) (c->buffer + c->bufferLen - specOffsetFromBack);
uint32_t tmp = 0;
tmp += p[0] << 0u;
tmp += p[1] << 8u;
tmp += p[2] << 16u;
tmp += p[3] << 24u;

if (tmp != (SUPPORTED_SPEC_VERSION)) {
return parser_spec_not_supported;
}

Expand Down
2,008 changes: 1,004 additions & 1,004 deletions app/src/polkadot_dispatch.c

Large diffs are not rendered by default.

39 changes: 20 additions & 19 deletions app/src/polkadot_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ parser_error_t _readVestingInfo(parser_context_t *c, pd_VestingInfo_t *v) {
CHECK_ERROR(_readBalanceOf(c, &v->locked))
CHECK_ERROR(_readBalanceOf(c, &v->per_block))
CHECK_ERROR(_readBlockNumber(c, &v->starting_block))
return parser_ok;
}

parser_error_t _readVote(parser_context_t *c, pd_Vote_t *v) {
Expand Down Expand Up @@ -668,7 +669,7 @@ parser_error_t _toStringAttestedCandidate(
uint8_t pageIdx,
uint8_t *pageCount) {
CLEAN_AND_CHECK()

return parser_print_not_supported;
}

Expand Down Expand Up @@ -710,7 +711,7 @@ parser_error_t _toStringCall(
uint8_t pageIdx,
uint8_t *pageCount) {
CLEAN_AND_CHECK()

return parser_print_not_supported;
}

Expand All @@ -721,7 +722,7 @@ parser_error_t _toStringChangesTrieConfiguration(
uint8_t pageIdx,
uint8_t *pageCount) {
CLEAN_AND_CHECK()

return parser_print_not_supported;
}

Expand Down Expand Up @@ -807,7 +808,7 @@ parser_error_t _toStringDoubleVoteReport(
uint8_t pageIdx,
uint8_t *pageCount) {
CLEAN_AND_CHECK()

return parser_print_not_supported;
}

Expand Down Expand Up @@ -845,7 +846,7 @@ parser_error_t _toStringHeadData(
uint8_t pageIdx,
uint8_t *pageCount) {
CLEAN_AND_CHECK()

return parser_print_not_supported;
}

Expand All @@ -856,7 +857,7 @@ parser_error_t _toStringHeader(
uint8_t pageIdx,
uint8_t *pageCount) {
CLEAN_AND_CHECK()

return parser_print_not_supported;
}

Expand All @@ -867,7 +868,7 @@ parser_error_t _toStringHeartbeat(
uint8_t pageIdx,
uint8_t *pageCount) {
CLEAN_AND_CHECK()

return parser_print_not_supported;
}

Expand All @@ -878,7 +879,7 @@ parser_error_t _toStringIdentityFields(
uint8_t pageIdx,
uint8_t *pageCount) {
CLEAN_AND_CHECK()

return parser_print_not_supported;
}

Expand Down Expand Up @@ -999,7 +1000,7 @@ parser_error_t _toStringIdentityJudgement(
uint8_t pageIdx,
uint8_t *pageCount) {
CLEAN_AND_CHECK()

return parser_print_not_supported;
}

Expand All @@ -1010,7 +1011,7 @@ parser_error_t _toStringKeyValue(
uint8_t pageIdx,
uint8_t *pageCount) {
CLEAN_AND_CHECK()

return parser_print_not_supported;
}

Expand All @@ -1021,7 +1022,7 @@ parser_error_t _toStringKey(
uint8_t pageIdx,
uint8_t *pageCount) {
CLEAN_AND_CHECK()

return parser_print_not_supported;
}

Expand All @@ -1041,7 +1042,7 @@ parser_error_t _toStringMoreAttestations(
uint8_t pageIdx,
uint8_t *pageCount) {
CLEAN_AND_CHECK()

return parser_print_not_supported;
}

Expand Down Expand Up @@ -1084,7 +1085,7 @@ parser_error_t _toStringPhragmenScore(
uint8_t pageIdx,
uint8_t *pageCount) {
CLEAN_AND_CHECK()

return parser_print_not_supported;
}

Expand Down Expand Up @@ -1148,7 +1149,7 @@ parser_error_t _toStringSocietyJudgement(
uint8_t pageIdx,
uint8_t *pageCount) {
CLEAN_AND_CHECK()

return parser_print_not_supported;
}

Expand All @@ -1159,7 +1160,7 @@ parser_error_t _toStringTimepoint(
uint8_t pageIdx,
uint8_t *pageCount) {
CLEAN_AND_CHECK()

return parser_print_not_supported;
}

Expand All @@ -1170,7 +1171,7 @@ parser_error_t _toStringTupleAccountIdData(
uint8_t pageIdx,
uint8_t *pageCount) {
CLEAN_AND_CHECK()

return parser_print_not_supported;
}

Expand Down Expand Up @@ -1291,7 +1292,7 @@ parser_error_t _toStringValidationCode(
uint8_t pageIdx,
uint8_t *pageCount) {
CLEAN_AND_CHECK()

return parser_print_not_supported;
}

Expand All @@ -1302,7 +1303,7 @@ parser_error_t _toStringValidatorIndex(
uint8_t pageIdx,
uint8_t *pageCount) {
CLEAN_AND_CHECK()

return parser_print_not_supported;
}

Expand Down Expand Up @@ -1346,7 +1347,7 @@ parser_error_t _toStringVestingInfo(
return parser_ok;
}
pageIdx -= pages[1];

//////
if (pageIdx < pages[2]) {
CHECK_ERROR(_toStringBlockNumber(&v->starting_block, outValue, outValueLen, pageIdx, &pages[2]))
Expand Down
4 changes: 3 additions & 1 deletion deps/ledger-zxlib/app/common/view_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ void os_exit(uint32_t id) {

const ux_menu_entry_t menu_main[] = {
{NULL, NULL, 0, &C_icon_app, MENU_MAIN_APP_LINE1, MENU_MAIN_APP_LINE2, 33, 12},
{NULL, NULL, 0, &C_icon_app, "v"APPVERSION, APPVERSION_LINE2, 33, 12},
{NULL, NULL, 0, &C_icon_app, APPVERSION_LINE1, APPVERSION_LINE2, 33, 12},
{NULL, NULL, 0, &C_icon_app, "Developed by", "Zondax.ch", 33, 12},
{NULL, NULL, 0, &C_icon_app, "under Apache", "License 2.0", 33, 12},
{NULL, os_exit, 0, &C_icon_dashboard, "Quit", NULL, 50, 29},
UX_MENU_END
};
Expand Down
2 changes: 1 addition & 1 deletion deps/ledger-zxlib/include/zxversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@

#define ZXLIB_MAJOR 1
#define ZXLIB_MINOR 0
#define ZXLIB_PATCH 2
#define ZXLIB_PATCH 3
Binary file added tests_zemu/snapshots/sign-basic/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sign-basic/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sign-basic/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sign-basic/11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sign-basic/12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sign-basic/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sign-basic/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sign-basic/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sign-basic/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sign-basic/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sign-basic/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sign-basic/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sign-basic/9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 4 additions & 5 deletions tests_zemu/tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('Basic checks', function () {
}
});

test.skip('sign basic', async function () {
test('sign basic', async function () {
const snapshotPrefixGolden = "snapshots/sign-basic/";
const snapshotPrefixTmp = "snapshots-tmp/sign-basic/";
let snapshotCount = 0;
Expand All @@ -135,9 +135,7 @@ describe('Basic checks', function () {
const pathChange = 0x80000000;
const pathIndex = 0x80000000;

let txBlobStr = "04008fd68d096fb488a2718871e9d93005e75612401bc1a7c2ddcbf8a848e8c76c468ed73e0dd5030000" +
"22040000b0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafeb0a8d493285c2df73290dfb7" +
"e61f870f17b41801197a149ca93654499ea3dafe";
let txBlobStr = "0400ffbc10f71d63e0da1b9e7ee2eb4037466551dc32b9d4641aafd73a65970fae4202286beed502000022040000b0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe280b332587f46c556aa806781884284f50d90b8c1b02488a059700673c93f41c";

const txBlob = Buffer.from(txBlobStr, "hex");

Expand Down Expand Up @@ -172,7 +170,8 @@ describe('Basic checks', function () {
prehash = Buffer.from(blake2bFinal(context));
}
const valid = ed25519.verify(signatureResponse.signature.slice(1), prehash, pubKey);
expect(valid).toEqual(true);
// FIXME: Zemu/Speculos cannot yet emulate Ed25519 HD
// expect(valid).toEqual(true);
} finally {
await sim.close();
}
Expand Down
39 changes: 10 additions & 29 deletions tests_zemu/tools/debug.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Zemu from "@zondax/zemu";
import OasisApp from "ledger-oasis-js";
import LedgerApp from "ledger-polkadot";
import path from "path";

const APP_PATH = path.resolve(`./../../app/bin/app.elf`);
Expand Down Expand Up @@ -27,35 +27,16 @@ async function beforeEnd() {

async function debugScenario(sim, app) {
// Here you can customize what you want to do :)
const path = [44, 474, 5, 0, 3];
const addrRequest = await app.getAddressAndPubKey(path);
const pathAccount = 0x80000000;
const pathChange = 0x80000000;
const pathIndex = 0x80000000;

await Zemu.default.sleep(1000);
// await sim.clickRight();
await sim.clickBoth();
let txBlobStr = "0400ffbc10f71d63e0da1b9e7ee2eb4037466551dc32b9d4641aafd73a65970fae4202286beed502000022040000b0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe280b332587f46c556aa806781884284f50d90b8c1b02488a059700673c93f41c";
const txBlob = Buffer.from(txBlobStr, "hex");

const addr = await addrRequest;
console.log(addr)

// From https://iancoleman.io/bip39/
const expected_pk = "";
const expected_addr = "";

if (addr.return_code !== 0x9000) {
console.log("INVALID RESPONSE")
return;
}

const pk = addr.address_raw.toString('hex');
console.log(pk)
if (expected_pk !== pk) {
console.log("INCORRECT PK!")
}

console.log(addr.address)
if (expected_addr !== addr.address) {
console.log("INVALID ADDRESS!")
}
// do not wait here.. we need to navigate
const signature = await app.sign(pathAccount, pathChange, pathIndex, txBlob);
console.log(signature);
}

async function main() {
Expand All @@ -69,7 +50,7 @@ async function main() {

try {
await sim.start(SIM_OPTIONS);
const app = new OasisApp.default(sim.getTransport());
const app = new LedgerApp.default(sim.getTransport());

////////////
/// TIP you can use zemu commands here to take the app to the point where you trigger a breakpoint
Expand Down

0 comments on commit 7cdc9ae

Please sign in to comment.