Commit graph

13125 commits

Author SHA1 Message Date
Jason Rhinelander
3d4d6ba916 Inline get_unlock_time to resolve build dep issue
device_ledger needs to call it, but can't link against
cryptonote_basic, so provide an inline version.
2020-12-14 13:54:05 -04:00
Jason Rhinelander
438f403c01 Don't invoke cryptonote_core functions from device code
We can't call cryptonote::add_tx_secret_key_to_tx_extra from `device`
code because that isn't necessarily available in `device` (though for
some odd reason this only actually showed up on the i386 build).

This amends the call to just get the secret key, leaving the actual job
of adding it to tx.extra to the caller (which is a cleaner way to do it
anyway).
2020-12-14 11:51:29 -04:00
Jason Rhinelander
c7dde1c3d4 Annotate and fix double spend test
For some reason we aren't keeping the old chain as an alt chain anymore,
but that shouldn't be a problem: fix the test as well as make some
improvements in the tests it does.
2020-12-13 23:46:31 -04:00
Jason Rhinelander
7d9a565a8f Remove invalid Borromean test case
What we are passing here is invalid, and so raises an exception, but the
test structure here doesn't have a nice way to catch that, so just
disable the test.
2020-12-13 22:02:51 -04:00
Jason Rhinelander
aeefb62815 Fix multisig tests: switch to CLSAG txes 2020-12-13 21:49:20 -04:00
Jason Rhinelander
1f03bb41b7 Test suite: add tx version hack and remove broken tests
This adds a variable hack into loki-core that lets us disable the
transaction hard fork requirement so that the test suite can still
generate transactions under older tx rules even though the transactions
will be modern CLSAG txes.

These are sort of bastardized txes that can never occur on the proper
mainnet, but let us keep tests that apply to v2/v3 transactions even
though we can't actually generate proper v2/v3 transactions anymore.

A few tests got removed here because they are testing for old invalid
bulletproof formats that don't matter anymore because they will never be
accepted on the current chain anyway.
2020-12-13 21:42:10 -04:00
Jason Rhinelander
9cbb2261c7 Make deferred properly movable
Moving it does what you'd expect: moves the lambda, copies the current
cancel status, and cancels the old one.

The implicit move constructor could malfunction: the old one wouldn't
necessarily end up cancelled.
2020-12-13 21:34:40 -04:00
Jason Rhinelander
b2536f0d4b Make hf table generation non-sequential
There's no reason we need intermediate blocks, so make it just generate
v7@0 (for genesis), v14s to make funds, and the the target.  (Or just
v7@0 + target for <v14 hard fork versions).
2020-12-10 20:22:34 -04:00
Jason Rhinelander
c49705dfdc Test fixes for old tx construction removal
- updates tests to work properly with current HF
- makes loki_generate_sequential_hard_fork_table jump 7->14....->15->16
rather than intermediate 8-9-10-11-12-13 blocks.  (The 14 sequence is
the generate block rewards before 15 lowers and 16 eliminates mining
rewards).
- remove test relying on the old 30-day expiry; that only worked on old
HFs, but also required old (pre-v4) txes which don't work anymore, so I
just removed the test.
2020-12-10 20:01:28 -04:00
Jason Rhinelander
5c00b1b9d6 Test fix: confirm SNs before adding a dereg
Updating this test to the latest HF broke it because it was relying on a
pre-HF13 bug that allowed deregs in the same height as the registration.
2020-12-10 03:11:48 -04:00
Jason Rhinelander
8e992f5e15 Test suite: add big junk tx generator
When we need to fill a block we are currently generating a ton of
transactions, but that is fairly slow: much faster to generate a small
number of huge txes.
2020-12-10 03:10:52 -04:00
Jason Rhinelander
62b88d4006 Add debugging to SN vote disallowing 2020-12-10 03:07:53 -04:00
Jason Rhinelander
0cd7fd272e Stake unlock: catch and show exceptions properly
Exceptions (e.g. because you denied the tx on the Ledger) were printing
and being immediately (mostly) overwritten by the wallet prompt.  This
fixes them to be returned as proper errors (and thus bright red,
consistent with other returned simplewallet errors).
2020-12-10 01:58:09 -04:00
Jason Rhinelander
af22617d07 Reset mode after making LNS signature
Not resetting leaves the ledger in a bad state, preventing other
updates/txes/etc. from working.
2020-12-09 22:54:57 -04:00
Jason Rhinelander
698677ef07 Rename hw::reset_mode to hw::mode_resetter
This isn't *doing* something, it is an RAII class that does the thing on
destruction.  Class names as verbs is confusing, so fix it.
2020-12-09 22:53:52 -04:00
Jason Rhinelander
409aa0f685 Minor code cleanup
Changed this while debugging something else, but it's slightly better so
keep it.
2020-12-08 22:34:58 -04:00
Jason Rhinelander
d952a53691 Remove pre-HF16 CLSAG check and gen CLSAG txes in core test
Core tests were breaking because of the removal of pre-CLSAG
transaction generation support.  This fixes it by allowing and using
CLSAG transactions before HF16 (which is safe to do now that we are well
past the hard fork).
2020-12-08 22:34:30 -04:00
Jason Rhinelander
33242dff47 Replace keypair::generate with a keypair constructor taking a hwdev
This makes it a bit nicer, and allows in-place construction rather than
needing to construct-and-copy.
2020-12-08 22:31:54 -04:00
Jason Rhinelander
0450f3dad6 De-inline cryptonote_basic
Moves a bunch of inline methods out into a new cryptonote_basic.cpp
compilation unit.  (Given how widely cryptonote_basic.h gets included it
seems desirable to have as little code needing compilation as possible).
2020-12-08 22:28:37 -04:00
Jason Rhinelander
38fc9fbcd6 Disable uninitialized value warning in jh.c
This is *probably* a false positive, but the code is such a mess that
it's hard to be sure.  Just switch off the warning and hope for the
best.
2020-12-08 22:01:48 -04:00
Jason Rhinelander
8ec73662c5 Add missing <vector> header 2020-12-08 17:10:56 -04:00
Jason Rhinelander
b717d34557 Cleanups
- rename INS_STEALTH to INS_ENCRYPT_PAYMENT_ID
- remove no-longer-valid (and unused) INS_MANAGE_SEEDWORDS
- hard-code CLSAG rct type prehashing and remove pre-CLSAG code paths
- remove unused decrypt(rct key vector)
- use a constexpr rather than memset & loop for dummy view/spend key
values
- fix speeling mistacks
- fix shitty code formatting
2020-12-08 16:00:07 -04:00
Jason Rhinelander
338d017b3d Properly display SW_WRONG_LENGTH errors
SW_WRONG_LENGTH is a range of errors: the least significant two bytes
carry the failed length.
2020-12-08 15:34:57 -04:00
Jason Rhinelander
192e7e5edf Remove "wrong account index" from error message
The Loki ledger doesn't have account indices (those are a
semi-deprecated thing in the Monero app).
2020-12-07 12:14:14 -04:00
Jason Rhinelander
2e18a905fb Revert wallet-side clsag c generation
Being able to pass the hash to the Ledger might be abusable (e.g. if it
passed a different hash, with a different secret key to try to sign
something else using the device's secret keys).
2020-12-06 23:22:00 -04:00
Jason Rhinelander
200be25574 Fix key image signature instruction code 2020-12-06 23:21:46 -04:00
Jason Rhinelander
46b25d5ef4 Move LNS signature generation into device code
Includes Ledger implementation.
2020-12-06 23:21:24 -04:00
Jason Rhinelander
4104244576 Fix extracted txversion/txtype 2020-12-06 23:19:20 -04:00
Jason Rhinelander
07aad36120 Ledger: Add stake unlock signature support 2020-12-06 23:17:07 -04:00
Jason Rhinelander
d60548ac0a Move txversion/txtype outside of cryptonote_basic.h
This is simply enough that it can be used from device (which is above
cryptonote_basic in the deps hierarchy).
2020-12-06 23:11:23 -04:00
Jason Rhinelander
333a5f6cc3 De-inline LNS methods 2020-12-06 23:10:43 -04:00
Jason Rhinelander
4f9f39c6ab Remove nonce (replace with 0) from stake unlock
There is no reason at all to sign a *different* message in every stake
unlock; signatures already have their own nonce.

Having something that serves no purpose is worse than not having it
(because it leads to questions about why such a thing is there), so this
commit removes it by always using 0 as a nonce and comments about it.

Removing this from the broadcast tx would require a new tx extra field
so that isn't worth doing for now (but can be done in the future if we
change the tx extra structure for unlocks).

This also simplifies the nonce-to-hash code and fixes an endian bug in
it.
2020-12-04 15:08:02 -04:00
Jason Rhinelander
ff26b83b45 Add tx secret key via device layer
We add the tx secret key to the tx_extra in staking transactions so that
values can be decoded, but the tx secret key value that we have on hand
is encrypted and so we can't access it.

This moves the call that adds the secret key into the device code so
that devices can provide this.  It also adds the tx version/type earlier
in the process (into `open_tx`) so that the device can know early on
that this is a stake transaction and therefore that leaking the tx
secret key is okay (and can also apply other stake-specific behaviour).
2020-12-04 11:56:46 -04:00
Jason Rhinelander
052d012745 Move key image signature generation into device
We don't have access to output private keys, so without this we can't
generate staking transactions.
2020-12-04 11:54:33 -04:00
Jason Rhinelander
da439dd9eb Fix: annotate and split up 2020-12-03 18:08:28 -04:00
Jason Rhinelander
1d31b97c28 Improve crypto test code
Changing crypto random functions broke the test code horribly (because
it depends on a deterministic random order), but it has no nice way to
reproduce it!

This restructures it a bit and significantly improves it, also updating
it for the new generated crypto values, and adding support for setting a
`REGEN=1` environment variable to generate a new test file.
2020-12-03 13:43:07 -04:00
Jason Rhinelander
c2dd3fc5f0 Add random_scalar returning function
Allows slightly cleaner calling code in a few places.
2020-12-03 13:43:07 -04:00
Jason Rhinelander
74db1800ef Annotate and split up ring signature code
We use generate_ring_signature and check_ring_signature somewhat
inappropriately to sign and check a signature of a single key image.
While it works for that, the full ring signature algorithm adds quite a
bit of complexity that we don't need (and simply doesn't run) for the
key image proof included in stake transactions and exported key images
from the wallet.

This splits it up, makes the key image interface considerably simpler,
and adds annotation comments through it (and also adds comments into the
"main" signature code).

This is a necessary step to getting stake transactions and key image
exports working with Ledger, without implementing the full ring
signature (because that is quite involved, and not needed for most of
these cases).

Also remove unused gen/check_ring_signatures interfaces: The raw pointer
code is never called, except through the vector version and one place in
the test suite, so just remove it and make the vector version the main
implementation.
2020-12-03 13:43:07 -04:00
Jason Rhinelander
6b56b48d6c Fix keccak include 2020-12-03 13:43:07 -04:00
Jason Rhinelander
db745d3024 C++ code nastiness cleanups
- A static function inside an anonymous namespace is pointless.

- Add comments above the sheer nastiness that is overloading `&` to
avoid having to reinterpret_cast a char to an unsigned char.  This
horror needs to die.

- Replace nasty C99 flexible array members reinterpret_cast'ed into a
value and then stuffed into a shared_ptr with a proper struct.

- Don't predeclare a bunch of crap long before the crap is used; this is
C++, not C.
2020-12-03 12:55:11 -04:00
Jason Rhinelander
fcdd8c0dc8 fix 2020-12-03 12:55:11 -04:00
Jason Rhinelander
51786d398f Fix awful random scalar generating code
This code is nasty:

- every time through the loop requires a mutex acquire and release
rather than holding the mutex around the loop.

- the comment about the limit is confusing af: eventually I figured out
that the "limit" equals 15L, and that this code is basically trying to
generate a value in (0, 15L) then mod L the number to get an unbiased
value in (0, L).

- However, the code is broken in two ways:
  - it can return 0 because (nL % L == 0) for integer n > 0
  - the while condition is broken af so that the while loop can *never*
    repeat, and thus the entire function is just always returning
    (random % L) which thus has the slight bias.

This commit fixes all these issues by moving the mutex outside the loop
and borrowing libsodium's approach for the generation: generate a random
value, mask off the 3 most significant bits, then repeat until this
yields a value in (0, L), which happens slightly more than 1/2 the time.

This is a bit slower than the 15L approach, but much simpler and
generating random scalars is not a performance bottleneck.
2020-12-03 12:43:17 -04:00
Jason Rhinelander
7151ccf0f9 Remove long-done TODO 2020-12-01 23:53:32 -04:00
Jason Rhinelander
8297b051f7 Use send_u32 2020-11-30 00:47:12 -04:00
Jason Rhinelander
343687dd6e Fix buggy, wrong command IDs
Monero's codes are extremely broken (relative to Monero's own ledger app
code) with wrong codes, omissions, and status codes that don't exist at
all.
2020-11-30 00:47:12 -04:00
Jason Rhinelander
7ecab90008 Clean up how options get set with VALIDATE 2020-11-30 00:47:12 -04:00
Jason Rhinelander
540d097810 Improve crappy ledger C++ code
Fixes lots of crappy C++ code.  I strongly get the impression from these
changes that whoever wrote this code was a C programmer with very little
C++ experience.  Sadly no one in the upstream Monero PR review tried to
help or seemed to care about the code quality.

- Get rid of superfluous `this->` throughout the ledger code.
- DRY: abstract away sending sequences of bytes, replacing:
    memmove(buffer, this->buffer_send+offset, 32);
    offset += 32
  with:
    send_bytes(buffer, 32, offset);
- DRY: abstract sending/receiving u32
- DRY: abstract receiving bytes/u32
- properly prefix memcpy/memmove with std::
- use std::string_view and std::string for setting/retrieving name
- rename `this->controle_device` to `debug_device`
- replace `f(void)` -> `f()` (on C++ methods, FFS!)
- DRY: replace set-length-then-exchange dance with a function
- DRY: merge nearly-identical exchange() and exchange_wait_for_input()
- remove never-used ok/mask arguments from exchange()
- Remove ASSERT_SW macro used only in one place
- Replace dumb ASSERT_X macro that was just an alias for another macro
- remove ASSERT_T0 macro that isn't used anywhere
2020-11-30 00:47:12 -04:00
Jason Rhinelander
1b97f37e35 Ledger: don't send nulls for no reason
don't send 32 null bytes for no reason in INS_GEN_TXOUT_KEYS when there
is no additional txkey    (this doesn't even match the case when there
is one since we send it encrypted, requiring 64 bytes).
2020-11-30 00:47:12 -04:00
Jason Rhinelander
a56284e311 Switch version strings to string_view's 2020-11-30 00:47:12 -04:00
Jason Rhinelander
3eeb295f16 Code cleanups 2020-11-30 00:47:12 -04:00