forked from trezor/trezor-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
xmr: serializer test fix (+34 squashed commits)
Squashed commits: [823ee19] xmr: crypto comment cleanup [6debfb6] xmr: ring_ct cleanup [759f52b] xmr: tsx signer code style, hintins [0b175bc] xmr: tsx builder external state removed [fee4a5a] xmr: builder state fix [92736fa] xmr: sign_tx unimport [a570ecb] xmr: misc code cleanup [4a496bb] xmr: hash wrapper not needed in writer [fefdb83] xmr: signer serialization improved [8fa6eec] xmr: signer mem clean [66c53fe] xmr: isort [6996bd9] xmr: black [59915a8] xmr: tsx input serialization refactored [326af13] xmr: msg dump with prefix [6e39801] xmr: manual serialization of tx prefix [9e5e047] xmr: manual serialization improvements [d07cee6] xmr: manual serialization of txout elements [8d56c80] xmr: TxOut custom serialization optimized II [c19ba12] xmr: TxOut custom serialization optimized [ce0d9b0] xmr: TxOut manual serialization [44e3834] xmr: sing_tx unimport [61ac61b] xmr: lite log trace rename [176b427] xmr: de-async overhaul [89ae3ba] xmr: diag style [5ccb2fb] xmr: wrappers cleanup [aa86fb1] xmr: py3 only inheritance [8031b1b] xmr: builder, log_trace -> mem_trace for clarity [25bf70d] xmr: debugging logging only in debug mode [c7c8d3c] xmr: iface cleanup [b037339] xmr: lite debug only [b1f6ce0] xmr: diag only in debug [de7d718] xmr: tsx counter removed [76729be] xmr: tsx_sign removed [c6e6ffa] Merge commit 'ba500bf4ec1ef9cd953bdf5a47888c5226db8d0b' into xmr
- Loading branch information
Showing
31 changed files
with
806 additions
and
1,472 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,114 @@ | ||
import gc | ||
import micropython | ||
import sys | ||
if __debug__: | ||
import gc | ||
import micropython | ||
import sys | ||
|
||
from trezor import log | ||
|
||
PREV_MEM = gc.mem_free() | ||
CUR_MES = 0 | ||
|
||
def log_trace(x=None): | ||
log.debug( | ||
__name__, | ||
"Log trace %s, ... F: %s A: %s, S: %s", | ||
x, | ||
gc.mem_free(), | ||
gc.mem_alloc(), | ||
micropython.stack_use(), | ||
) | ||
|
||
def check_mem(x=""): | ||
global PREV_MEM, CUR_MES | ||
|
||
gc.collect() | ||
free = gc.mem_free() | ||
diff = PREV_MEM - free | ||
log.debug( | ||
__name__, | ||
"======= {} {} Diff: {} Free: {} Allocated: {}".format( | ||
CUR_MES, x, diff, free, gc.mem_alloc() | ||
), | ||
) | ||
micropython.mem_info() | ||
gc.collect() | ||
CUR_MES += 1 | ||
PREV_MEM = free | ||
|
||
def retit(**kwargs): | ||
from trezor.messages.Failure import Failure | ||
|
||
return Failure(**kwargs) | ||
|
||
async def diag(ctx, msg, **kwargs): | ||
log.debug(__name__, "----diagnostics") | ||
gc.collect() | ||
|
||
if msg.ins == 0: | ||
check_mem(0) | ||
return retit() | ||
|
||
elif msg.ins == 1: | ||
check_mem(1) | ||
micropython.mem_info(1) | ||
return retit() | ||
|
||
elif msg.ins == 2: | ||
log.debug(__name__, "_____________________________________________") | ||
log.debug(__name__, "_____________________________________________") | ||
log.debug(__name__, "_____________________________________________") | ||
return retit() | ||
|
||
elif msg.ins == 3: | ||
pass | ||
|
||
elif msg.ins == 4: | ||
total = 0 | ||
monero = 0 | ||
|
||
for k, v in sys.modules.items(): | ||
log.info(__name__, "Mod[%s]: %s", k, v) | ||
total += 1 | ||
if k.startswith("apps.monero"): | ||
monero += 1 | ||
log.info(__name__, "Total modules: %s, Monero modules: %s", total, monero) | ||
return retit() | ||
|
||
elif msg.ins in [5, 6, 7]: | ||
check_mem() | ||
from apps.monero.xmr import bulletproof as bp | ||
|
||
check_mem("BP Imported") | ||
from apps.monero.xmr import crypto | ||
|
||
check_mem("Crypto Imported") | ||
|
||
bpi = bp.BulletProofBuilder() | ||
bpi.gc_fnc = gc.collect | ||
bpi.gc_trace = log_trace | ||
|
||
vals = [crypto.sc_init((1 << 30) - 1 + 16), crypto.sc_init(22222)] | ||
masks = [crypto.random_scalar(), crypto.random_scalar()] | ||
check_mem("BP pre input") | ||
|
||
if msg.ins == 5: | ||
bp_res = bpi.prove_testnet(vals[0], masks[0]) | ||
check_mem("BP post prove") | ||
bpi.verify_testnet(bp_res) | ||
check_mem("BP post verify") | ||
|
||
elif msg.ins == 6: | ||
bp_res = bpi.prove(vals[0], masks[0]) | ||
check_mem("BP post prove") | ||
bpi.verify(bp_res) | ||
check_mem("BP post verify") | ||
|
||
elif msg.ins == 7: | ||
bp_res = bpi.prove_batch(vals, masks) | ||
check_mem("BP post prove") | ||
bpi.verify(bp_res) | ||
check_mem("BP post verify") | ||
|
||
return retit() | ||
|
||
from trezor import log | ||
|
||
PREV_MEM = gc.mem_free() | ||
CUR_MES = 0 | ||
|
||
|
||
def log_trace(x=None): | ||
log.debug( | ||
__name__, | ||
"Log trace %s, ... F: %s A: %s, S: %s", | ||
x, | ||
gc.mem_free(), | ||
gc.mem_alloc(), | ||
micropython.stack_use(), | ||
) | ||
|
||
|
||
def check_mem(x=""): | ||
global PREV_MEM, CUR_MES | ||
|
||
gc.collect() | ||
free = gc.mem_free() | ||
diff = PREV_MEM - free | ||
log.debug( | ||
__name__, | ||
"======= {} {} Diff: {} Free: {} Allocated: {}".format( | ||
CUR_MES, x, diff, free, gc.mem_alloc() | ||
), | ||
) | ||
micropython.mem_info() | ||
gc.collect() | ||
CUR_MES += 1 | ||
PREV_MEM = free | ||
|
||
|
||
def retit(**kwargs): | ||
from trezor.messages.Failure import Failure | ||
|
||
return Failure(**kwargs) | ||
|
||
|
||
async def diag(ctx, msg, **kwargs): | ||
log.debug(__name__, "----diagnostics") | ||
gc.collect() | ||
|
||
if msg.ins == 0: | ||
check_mem(0) | ||
return retit() | ||
|
||
elif msg.ins == 1: | ||
check_mem(1) | ||
micropython.mem_info(1) | ||
return retit() | ||
|
||
elif msg.ins == 2: | ||
log.debug(__name__, "_____________________________________________") | ||
log.debug(__name__, "_____________________________________________") | ||
log.debug(__name__, "_____________________________________________") | ||
return retit() | ||
|
||
elif msg.ins == 3: | ||
pass | ||
|
||
elif msg.ins == 4: | ||
total = 0 | ||
monero = 0 | ||
|
||
for k, v in sys.modules.items(): | ||
log.info(__name__, "Mod[%s]: %s", k, v) | ||
total += 1 | ||
if k.startswith("apps.monero"): | ||
monero += 1 | ||
log.info(__name__, "Total modules: %s, Monero modules: %s", total, monero) | ||
return retit() | ||
|
||
elif msg.ins in [5, 6, 7]: | ||
check_mem() | ||
from apps.monero.xmr import bulletproof as bp | ||
|
||
check_mem("BP Imported") | ||
from apps.monero.xmr import crypto | ||
|
||
check_mem("Crypto Imported") | ||
|
||
bpi = bp.BulletProofBuilder() | ||
bpi.gc_fnc = gc.collect | ||
bpi.gc_trace = log_trace | ||
|
||
vals = [crypto.sc_init((1 << 30) - 1 + 16), crypto.sc_init(22222)] | ||
masks = [crypto.random_scalar(), crypto.random_scalar()] | ||
check_mem("BP pre input") | ||
|
||
if msg.ins == 5: | ||
bp_res = bpi.prove_testnet(vals[0], masks[0]) | ||
check_mem("BP post prove") | ||
bpi.verify_testnet(bp_res) | ||
check_mem("BP post verify") | ||
|
||
elif msg.ins == 6: | ||
bp_res = bpi.prove(vals[0], masks[0]) | ||
check_mem("BP post prove") | ||
bpi.verify(bp_res) | ||
check_mem("BP post verify") | ||
|
||
elif msg.ins == 7: | ||
bp_res = bpi.prove_batch(vals, masks) | ||
check_mem("BP post prove") | ||
bpi.verify(bp_res) | ||
check_mem("BP post verify") | ||
|
||
return retit() | ||
|
||
return retit() |
Oops, something went wrong.