What changed, and why it matters
This commit cleans up two places where TON (The Open Network) checksums were being converted to hex strings by hand-written loops, replacing them with a single helper function `ByteArrayToHexStr`. It also adds a debug print statement showing whether the TON and BIP39 mnemonic comparisons succeeded during the 'forget TON' flow. The title 'fix ton forget' suggests the change is meant to fix a bug in the process of forgetting/removing a TON wallet, but the diff itself does not show an obvious security vulnerability or a clear behavioral fix beyond code simplification and extra logging.
Treat this as a low-confidence maintenance commit. Review the full history around this change to identify the actual bug being fixed. Verify that `ByteArrayToHexStr` correctly null-terminates the output and handles the 65-byte buffer size. Consider whether the added `printf` in `ModelTonForgetPass` could leak sensitive comparison results to any accessible log interface, and remove or downgrade it if so.
Security signals we found
Refactoring of cryptographic checksum serialization
Use of safer-looking helper `ByteArrayToHexStr` instead of repeated `snprintf_s`
Debug logging added to sensitive mnemonic-comparison path
Commit title suggests bug fix in wallet deletion/forget flow
Evidence from the diff
The patch refactors two call sites that convert a 32-byte TON checksum to a 64-character hex string plus null terminator. Previously both sites used snprintf_s in loops; now both call ByteArrayToHexStr(checksum, sizeof(checksum), ptr/value). In gui_model.c’s ModelTonForgetPass, a printf was added to log tonRet and bip39Ret. The commit title implies a bug fix for TON wallet forgetting, but the diff does not reveal the actual bug or any corrected logic. The change could be a defensive cleanup to ensure consistent, correct hex encoding, or it could be part of a larger fix not visible in this commit.
Changed components
src/crypto/account_public_info.csrc/ui/gui_model/gui_model.cTON wallet public info storageTON/BIP39 mnemonic comparison during forget-password flowInspect captured patch +3 / −11
diff --git a/src/crypto/account_public_info.c b/src/crypto/account_public_info.c
index 1075430..00caefa 100644
--- a/src/crypto/account_public_info.c
+++ b/src/crypto/account_public_info.c
@@ -903,9 +903,7 @@ int32_t AccountPublicSavePublicInfo(uint8_t accountIndex, const char *password,
g_accountPublicInfo[PUBLIC_INFO_TON_CHECKSUM].value = SRAM_MALLOC(65);
char* ptr = g_accountPublicInfo[PUBLIC_INFO_TON_CHECKSUM].value;
memset_s(ptr, 65, 0, 65);
- for (size_t i = 0; i < 32; i++) {
- snprintf_s(ptr + i * 2, 65 - i * 2, "%02x", checksum[i]);
- }
+ ByteArrayToHexStr(checksum, sizeof(checksum), ptr);
} else {
#endif
for (int i = 0; i < NUMBER_OF_ARRAYS(g_chainTable); i++) {
diff --git a/src/ui/gui_model/gui_model.c b/src/ui/gui_model/gui_model.c
index c6c0600..43e1678 100644
--- a/src/ui/gui_model/gui_model.c
+++ b/src/ui/gui_model/gui_model.c
@@ -663,14 +663,7 @@ static int32_t ModelComparePubkey(MnemonicType mnemonicType, uint8_t *ems, uint8
CalculateTonChecksum(entropyResult->data, checksum);
free_VecFFI_u8(entropyResult);
char value[65] = {0};
- size_t offset = 0;
- for (size_t i = 0; i < 32 && offset < 64; i++) {
- int written = snprintf_s(value + offset, 65 - offset, "%02x", checksum[i]);
- if (written > 0) {
- offset += written;
- }
- }
- value[64] = '\0';
+ ByteArrayToHexStr(checksum, sizeof(checksum), value);
existIndex = SpecifiedXPubExist(value, ton);
if (index != NULL) {
*index = existIndex;
@@ -1804,6 +1797,7 @@ static int32_t ModelTonForgetPass(const void *inData, uint32_t inDataLen)
CHECK_ERRCODE_BREAK("save low power", ret);
bip39Ret = ModelComparePubkey(MNEMONIC_TYPE_BIP39, NULL, 0, 0, false, 0, NULL);
tonRet = ModelComparePubkey(MNEMONIC_TYPE_TON, NULL, 0, 0, false, 0, NULL);
+ printf("tonRet: %d, bip39Ret: %d\r\n", tonRet, bip39Ret);
if (tonRet != SUCCESS_CODE && bip39Ret != SUCCESS_CODE) {
GuiApiEmitSignal(SIG_FORGET_TON_BIP39_SUCCESS, NULL, 0);
} else if (tonRet != SUCCESS_CODE) {
Why this scored 28/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.