Skip to content

Commit 9735116

Browse files
Nonce handling fixes
One test had a nonce way too big that was causing issue with the recent refactoring
1 parent 3fa410f commit 9735116

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src_common/uint256.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,20 @@ bool tostring256(const uint256_t *const number,
230230
UPPER(LOWER(base)) = 0;
231231
LOWER(LOWER(base)) = baseParam;
232232
uint32_t offset = 0;
233-
if ((baseParam < 2) || (baseParam > 16)) {
233+
if ((outLength == 0) || (baseParam < 2) || (baseParam > 16)) {
234234
return false;
235235
}
236236
do {
237-
if (offset > (outLength - 1)) {
238-
return false;
239-
}
240237
divmod256(&rDiv, &base, &rDiv, &rMod);
241238
out[offset++] = HEXDIGITS[(uint8_t) LOWER(LOWER(rMod))];
242-
} while (!zero256(&rDiv));
239+
} while (!zero256(&rDiv) && (offset < outLength));
243240

244-
if (offset > (outLength - 1)) {
241+
if (offset == outLength) { // destination buffer too small
242+
if (outLength > 3) {
243+
strcpy(out, "...");
244+
} else {
245+
out[0] = '\0';
246+
}
245247
return false;
246248
}
247249

tests/speculos/test_sign_cmd.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ def test_sign_blind_and_nonce_display(cmd):
619619

620620
transaction = Transaction(
621621
txType=0xEB,
622-
nonce=2**64-1,
622+
nonce=1844674,
623623
gasPrice=0x0306dc4200,
624624
gasLimit=0x5208,
625625
to="0x5a321744667052affa8386ed49e00ef223cbffc3",
@@ -699,6 +699,6 @@ def test_sign_blind_and_nonce_display(cmd):
699699

700700
v, r, s = result
701701

702-
assert v == 0x25 # 37
703-
assert r.hex() == "737c07042022d37286216312d62163c4238536d82c5b45937ce9fbf259d11b7d"
704-
assert s.hex() == "5604485e0cf37e465a84290eb26a18e40a430f1b0fda184c56b2c3a51ada2e6c"
702+
assert v == 0x26 # 38
703+
assert r.hex() == "c8d7cd5c1711ea1af7da048d15d1a95fc9347d4622afa11f32320d73384984d1"
704+
assert s.hex() == "3165ca0a27f565e1a87560ed3d3a144c4ac9732370428da5e6952e93659f6ac2"

0 commit comments

Comments
 (0)