Skip to content

Commit

Permalink
Merge pull request #17 from blooo-io/fix/LDG-492-fix-don-t-apply-eip1…
Browse files Browse the repository at this point in the history
…55-to-v-anymore

fix: correct computation of v
  • Loading branch information
keiff3r authored Nov 15, 2024
2 parents 241a280 + 5efbada commit c3aa610
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ APP_LOAD_PARAMS= --curve secp256k1 $(COMMON_LOAD_PARAMS)

APPVERSION_M=1
APPVERSION_N=3
APPVERSION_P=1
APPVERSION_P=2
APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)

# Celo
Expand Down
19 changes: 5 additions & 14 deletions src/ui_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ unsigned int io_seproxyhal_touch_tx_ok(void) {
uint8_t signature[100];
cx_ecfp_private_key_t privateKey;
uint32_t tx = 0;
uint32_t v = getV(&tmpContent.txContent);
io_seproxyhal_io_heartbeat();
CX_THROW(os_derive_bip32_no_throw(CX_CURVE_256K1, tmpCtx.transactionContext.derivationPath.path,
tmpCtx.transactionContext.derivationPath.len,
Expand All @@ -105,22 +104,14 @@ unsigned int io_seproxyhal_touch_tx_ok(void) {
tmpCtx.transactionContext.hash,
sizeof(tmpCtx.transactionContext.hash), signature, &sig_len, &info));
explicit_bzero(&privateKey, sizeof(privateKey));
// Parity is present in the sequence tag in the legacy API
if (tmpContent.txContent.vLength == 0) {
// Legacy API
G_io_apdu_buffer[0] = 27;
}
else {
// New API
// Note that this is wrong for a large v, but the client can always recover
G_io_apdu_buffer[0] = (v * 2) + 35;
}

// For EIP1559 and CIP64 transactions, the Ledger SDK expects v to be
// the parity: 0 | 1
G_io_apdu_buffer[0] = 0;
if (info & CX_ECCINFO_PARITY_ODD) {
G_io_apdu_buffer[0]++;
}
if (info & CX_ECCINFO_xGTn) {
G_io_apdu_buffer[0] += 2;
}

format_signature_out(signature);
tx = 65;
G_io_apdu_buffer[tx++] = 0x90;
Expand Down
12 changes: 7 additions & 5 deletions tests/python/test_sign_new_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def sign_transaction_with_rawTx(test_name, backend, navigator, instructions, raw
navigator.navigate_and_compare(TESTS_ROOT_DIR, test_name, instructions)

response: bytes = get_async_response(backend)
return response.status
return response

def test_sign_transaction_eip1559_no_data(test_name, backend, firmware, navigator):
if firmware.device == "nanos":
Expand All @@ -33,9 +33,10 @@ def test_sign_transaction_eip1559_no_data(test_name, backend, firmware, navigato
instructions = get_stax_review_instructions(1)

rawTx = "02f86c82aef380830f42408506fc35fb8082520894da52c9ffebd4d54c94a072776126069d43e74f9e8080c080a099059ce0f1fe1f4fe27a583a6fd6a12274780d358f332d6e5901953900b8fb22a046ce6d625369fdc8a521c22793d188afbf61500cd3095fc09b761b518560f101"
status = sign_transaction_with_rawTx(test_name, backend, navigator, instructions, rawTx)
response = sign_transaction_with_rawTx(test_name, backend, navigator, instructions, rawTx)

assert(status == StatusCode.STATUS_OK)
assert(response.data[0] == 0x01 or response.data[0] == 0x00)
assert(response.status == StatusCode.STATUS_OK)

def test_sign_transaction_eip1559_with_data(test_name, backend, firmware):
rawTx = "02f8d482a4ec820808839b34b4850fbc63d144830204e094004626a008b1acdc4c74ab51644093b155e59a2380b864ba0876520000000000000000000000000000000000000000000000009458660c5b865f23000000000000000000000000e3b72489968f11c15282514f33df24634440393f000000000000000000000000e3b72489968f11c15282514f33df24634440393fc001a0b0799073a2aa771c5e32b88933ff19982dc30f9e4523fde47137ae504793b880a07014a6e3c32a3b34d4118beb298f2200e858599b5e97766dfaa6fea192cde993"
Expand Down Expand Up @@ -71,5 +72,6 @@ def test_sign_transaction_cip64(test_name, backend, firmware, navigator):
instructions = get_stax_review_instructions(1)

rawTx = "7bf84382a4ec8084773594008503a11f9db58301688c94da52c9ffebd4d54c94a072776126069d43e74f9e8080c094765DE816845861E75A25FCA122BB6898B8B1282A018080"
status = sign_transaction_with_rawTx(test_name, backend, navigator, instructions, rawTx)
assert(status == StatusCode.STATUS_OK)
response = sign_transaction_with_rawTx(test_name, backend, navigator, instructions, rawTx)
assert(response.data[0] == 0x01 or response.data[0] == 0x00)
assert(response.status == StatusCode.STATUS_OK)

0 comments on commit c3aa610

Please sign in to comment.