Skip to content

Commit

Permalink
fix(legacy): misc fix and bump version to 3.10.1 (#116)
Browse files Browse the repository at this point in the history
* fix(legacy): misc fix and bump version to 3.10.1

1. add miss filed in features
2. fix the mistake made in PSBT signing

* style(legacy): fix style check
  • Loading branch information
somebodyLi authored Dec 11, 2024
1 parent c93ccad commit eb12d12
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 63 deletions.
2 changes: 1 addition & 1 deletion legacy/firmware/fsm_msg_coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,7 @@ void fsm_msgSignPsbt(const SignPsbt *msg) {
return;
}

sig_hasher_final(&hasher);
for (int i = 0; i < psbt.inputs_len; i++) {
PartiallySignedInput *input = &psbt.inputs[i];
if (input->tap_bip32_path_lookuped) {
Expand All @@ -1156,7 +1157,6 @@ void fsm_msgSignPsbt(const SignPsbt *msg) {
coin->curve_name, input->tap_bip32_path.key_origin.path,
input->tap_bip32_path.key_origin.path_len, NULL);
if (!s_node) return;
sig_hasher_final(&hasher);
sig_hasher_hash_341(&hasher, i, SIGHASH_ALL_TAPROOT, sigmsg_digest,
psbt.tx_version, locktime,
script_path_spending ? leaf_hash : NULL);
Expand Down
19 changes: 15 additions & 4 deletions legacy/firmware/fsm_msg_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,23 @@ bool get_features(Features *resp) {
resp->capabilities[6] = Capability_Capability_U2F;
#endif
if (ble_name_state()) {
resp->has_ble_name = true;
strlcpy(resp->ble_name, ble_get_name(), sizeof(resp->ble_name));
char *ble_name = ble_get_name();
if (ble_name) {
resp->has_ble_name = true;
strlcpy(resp->ble_name, ble_name, sizeof(resp->ble_name));
resp->has_onekey_ble_name = true;
strlcpy(resp->onekey_ble_name, ble_name, sizeof(resp->onekey_ble_name));
}
}
if (ble_ver_state()) {
resp->has_ble_ver = true;
strlcpy(resp->ble_ver, ble_get_ver(), sizeof(resp->ble_ver));
char *ble_ver = ble_get_ver();
if (ble_ver) {
resp->has_ble_ver = true;
strlcpy(resp->ble_ver, ble_ver, sizeof(resp->ble_ver));
resp->has_onekey_ble_version = true;
strlcpy(resp->onekey_ble_version, ble_ver,
sizeof(resp->onekey_ble_version));
}
}
if (ble_switch_state()) {
resp->has_ble_enable = true;
Expand Down
8 changes: 5 additions & 3 deletions legacy/firmware/ton.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ bool ton_sign_message(const TonSignMessage *msg, const HDNode *node,

// create payload
if (is_raw_data) {
if (!ton_parse_boc(raw_data, data_len, payload, payload_bits, payload_ref)) {
if (!ton_parse_boc(raw_data, data_len, payload, payload_bits,
payload_ref)) {
fsm_sendFailure(FailureType_Failure_ProcessError,
"Failed to create raw data body");
return false;
Expand Down Expand Up @@ -342,8 +343,9 @@ bool ton_sign_message(const TonSignMessage *msg, const HDNode *node,
msg->expire_at, msg->seqno, parsed_dest.is_bounceable,
parsed_dest.workchain, parsed_dest.hash, msg->ton_amount, msg->mode,
!comment_inline ? payload : NULL, is_jetton,
comment_inline ? msg->comment : NULL, payload_bits, payload_ref, ext_destination_ptrs,
msg->ext_ton_amount, ext_payload_ptrs, ext_dest_count, digest);
comment_inline ? msg->comment : NULL, payload_bits, payload_ref,
ext_destination_ptrs, msg->ext_ton_amount, ext_payload_ptrs,
ext_dest_count, digest);

if (!create_digest) {
fsm_sendFailure(FailureType_Failure_ProcessError,
Expand Down
87 changes: 45 additions & 42 deletions legacy/firmware/ton_cell.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ bool ton_create_jetton_transfer_body(uint8_t dest_workchain, uint8_t* dest_hash,
}

bool build_message_ref(bool is_bounceable, uint8_t dest_workchain,
uint8_t* dest_hash, uint64_t value, CellRef_t* payload, bool is_jetton,
const char* payload_str, BitString_t* payload_bits, CellRef_t* payload_ref, CellRef_t* out_message_ref) {
uint8_t* dest_hash, uint64_t value, CellRef_t* payload,
bool is_jetton, const char* payload_str,
BitString_t* payload_bits, CellRef_t* payload_ref,
CellRef_t* out_message_ref) {
BitString_t bits;
bitstring_init(&bits);

Expand Down Expand Up @@ -134,34 +136,34 @@ bool build_message_ref(bool is_bounceable, uint8_t dest_workchain,
return ton_hash_cell(&bits, NULL, 0, out_message_ref);

} else if (payload != NULL) {
// check if raw data inline
// if (false) {
if (bits.data_cursor + payload_bits->data_cursor <= 1023 && !is_jetton) {
bitstring_write_bit(&bits, 0); // no state-init
bitstring_write_bit(&bits, 0); // body in line

for (int i = 0; i < payload_bits->data_cursor; i++) {
int src_byte = i / 8;
int src_bit = 7 - (i % 8);
int src_value = (payload_bits->data[src_byte] >> src_bit) & 1;
bitstring_write_bit(&bits, src_value);
}

// append payload ref in message ref
if (payload->max_depth > 0) {
struct CellRef_t refs[1] = {*payload_ref};
return ton_hash_cell(&bits, refs, 1, out_message_ref);

} else {
return ton_hash_cell(&bits, NULL, 0, out_message_ref);
}
// check if raw data inline
// if (false) {
if (bits.data_cursor + payload_bits->data_cursor <= 1023 && !is_jetton) {
bitstring_write_bit(&bits, 0); // no state-init
bitstring_write_bit(&bits, 0); // body in line

for (int i = 0; i < payload_bits->data_cursor; i++) {
int src_byte = i / 8;
int src_bit = 7 - (i % 8);
int src_value = (payload_bits->data[src_byte] >> src_bit) & 1;
bitstring_write_bit(&bits, src_value);
}

// append payload ref in message ref
if (payload->max_depth > 0) {
struct CellRef_t refs[1] = {*payload_ref};
return ton_hash_cell(&bits, refs, 1, out_message_ref);

} else {
bitstring_write_bit(&bits, 0); // no state-init
bitstring_write_bit(&bits, 1); // body in ref
return ton_hash_cell(&bits, NULL, 0, out_message_ref);
}

struct CellRef_t refs[1] = {*payload};
return ton_hash_cell(&bits, refs, 1, out_message_ref);
} else {
bitstring_write_bit(&bits, 0); // no state-init
bitstring_write_bit(&bits, 1); // body in ref

struct CellRef_t refs[1] = {*payload};
return ton_hash_cell(&bits, refs, 1, out_message_ref);
}
} else {
bitstring_write_bit(&bits, 0); // no state-init
Expand All @@ -171,18 +173,18 @@ bool build_message_ref(bool is_bounceable, uint8_t dest_workchain,
}
}

bool ton_create_message_digest(uint32_t expire_at, uint32_t seqno,
bool is_bounceable, uint8_t dest_workchain,
uint8_t* dest_hash, uint64_t value, uint8_t mode,
CellRef_t* payload, bool is_jetton, const char* payload_str,
BitString_t* payload_bits, CellRef_t* payload_ref, const char** ext_dest,
const uint64_t* ext_ton_amount,
const char** ext_payload, uint8_t ext_dest_count,
uint8_t* digest) {
bool ton_create_message_digest(
uint32_t expire_at, uint32_t seqno, bool is_bounceable,
uint8_t dest_workchain, uint8_t* dest_hash, uint64_t value, uint8_t mode,
CellRef_t* payload, bool is_jetton, const char* payload_str,
BitString_t* payload_bits, CellRef_t* payload_ref, const char** ext_dest,
const uint64_t* ext_ton_amount, const char** ext_payload,
uint8_t ext_dest_count, uint8_t* digest) {
// Build Internal Message
struct CellRef_t internalMessageRef;
if (!build_message_ref(is_bounceable, dest_workchain, dest_hash, value,
payload, is_jetton, payload_str, payload_bits, payload_ref, &internalMessageRef)) {
payload, is_jetton, payload_str, payload_bits,
payload_ref, &internalMessageRef)) {
return false;
}

Expand Down Expand Up @@ -218,11 +220,11 @@ bool ton_create_message_digest(uint32_t expire_at, uint32_t seqno,
memset(&ext_payload_ref, 0, sizeof(CellRef_t));
}

if (!build_message_ref(parsed_addr.is_bounceable,
(uint8_t)parsed_addr.workchain, parsed_addr.hash,
ext_ton_amount[i],
ext_payload[i] ? &ext_payload_ref : NULL, false, NULL, NULL,
NULL, &extMessageRefs[ext_message_count])) {
if (!build_message_ref(
parsed_addr.is_bounceable, (uint8_t)parsed_addr.workchain,
parsed_addr.hash, ext_ton_amount[i],
ext_payload[i] ? &ext_payload_ref : NULL, false, NULL, NULL, NULL,
&extMessageRefs[ext_message_count])) {
return false;
}
ext_message_count++;
Expand Down Expand Up @@ -292,7 +294,8 @@ void set_top_upped_array(uint8_t* array, size_t array_len,
}

bool ton_parse_boc(const uint8_t* input_boc, size_t input_boc_len,
CellRef_t* payload, BitString_t* payload_bits, CellRef_t* payload_ref) {
CellRef_t* payload, BitString_t* payload_bits,
CellRef_t* payload_ref) {
if (input_boc_len < 5 || input_boc_len > 1024) {
return false;
}
Expand Down
19 changes: 9 additions & 10 deletions legacy/firmware/ton_cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ bool ton_create_jetton_transfer_body(uint8_t dest_workchain, uint8_t* dest_hash,
uint8_t resp_workchain, uint8_t* resp_hash,
CellRef_t* payload);

bool ton_create_message_digest(uint32_t expire_at, uint32_t seqno,
bool is_bounceable, uint8_t dest_workchain,
uint8_t* dest_hash, uint64_t value, uint8_t mode,
CellRef_t* payload, bool is_jetton, const char* payload_str,
BitString_t* payload_bits, CellRef_t* payload_ref,
const char** ext_dest,
const uint64_t* ext_ton_amount,
const char** ext_payload, uint8_t ext_dest_count,
uint8_t* digest);
bool ton_create_message_digest(
uint32_t expire_at, uint32_t seqno, bool is_bounceable,
uint8_t dest_workchain, uint8_t* dest_hash, uint64_t value, uint8_t mode,
CellRef_t* payload, bool is_jetton, const char* payload_str,
BitString_t* payload_bits, CellRef_t* payload_ref, const char** ext_dest,
const uint64_t* ext_ton_amount, const char** ext_payload,
uint8_t ext_dest_count, uint8_t* digest);

bool ton_parse_boc(const uint8_t* input_boc, size_t input_boc_len,
CellRef_t* payload, BitString_t* payload_bits, CellRef_t* payload_ref);
CellRef_t* payload, BitString_t* payload_bits,
CellRef_t* payload_ref);
6 changes: 3 additions & 3 deletions legacy/firmware/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#define ONEKEY_VER_MAJOR 3
#define ONEKEY_VER_MINOR 10
#define ONEKEY_VER_PATCH 0
#define ONEKEY_VER_PATCH 1

#define ONEKEY_VERSION "3.10.0"
#define ONEKEY_VERSION_HEX 0x3A00
#define ONEKEY_VERSION "3.10.1"
#define ONEKEY_VERSION_HEX 0x3A01

0 comments on commit eb12d12

Please sign in to comment.