Research/Bitcoin Dev Archive / lightning-dev list
Speculations on hardware wallet support for Lightning
4 messages, Jan 14 to 16, 2020. Started by ZmnSCPxj.
ZmnSCPxj (2), devrandom, Antoine Riard
Good morning list,
I have been thinking of this for some time without really getting any good results, and in any case [this C-Lightning mailing list post](https://lists.ozlabs.org/pipermail/c-lightning/2019-December/000172.html) brings up similar topic. As well, 0 or more people have asked me opinions on related topics as well.
In any case, the goal is to have some hardware unit, using only a simple communications channel with the software, to act as signer for all Lightning-related things (channel funding, channel updates, reclaiming funds after channel close). As is typical for such Bitcoin-related hardware units, it might possess its own user interface by which it can require confirmation of certain actions. Also, to reduce risk of hacking, the hardware unit does not have a connection to the netwrok, only a communications channel that is restricted to a local direct connection (such as USB).
I will now demonstrate that such a design cannot achieve what an onchain Bitcoin hardware wallet does, namely that the hardware need not tr\*st the software and need not keep any state beyond the private key (which remains constant). For Lightning, it seems any hardware would require tr\*st in the software *and* some state.
Cast of characters:
* The hardware for this node. * The software for this node. * The other node.
What I will attempt here would be to create a hardware that has as little tr\*st in the software as possible, and reduce the state that the hardware signer has to store. If these two goals conflict, I will attempt to reduce the tr\*st in the software.
Channel Updates ===============
Onchain hardware wallets do not require user interaction just to receive funds. Thus, let us consider this goal.
On Lightning, funds are received by getting an HTLC that this node can claim from the other node on the channel. This incoming HTLC deducts from the funds owned by the remote node.
Thus, the hardware only needs to verify that:
* The funds owned by this node on the channel remains the same. * A new HTLC is added that this node can claim if it knows the preimage.
This requires that the hardware be able to compare a current state with a proposed new state. Presumably, the software for this node provides the current state, then the proposed new state, then if the hardware confirms that the state changes "correctly", it will sign the proposed new state.
The problem is, how can the hardware check that the "current state" is correct? For example, suppose a channel was funded by this node, and thus all funds are owned by this node. Then the software is corrupted, and then it claims to the hardware that the current state is that all funds are owned by the other node and that the other node is offering an HTLC. The hardware believes this claim of what the current state is, and signs the state where almost all the funds are owned by the other node.
Note that we cannot have the software send the entire history of the channel to the hardware either. The software can be corrupted into sending only a partial history, rewinding some set of recent channel updates, then a new history can be created on top of that, where this node is paid far less. On the blockchain the longer and presumably "more true" history can be attested to with proof-of-work, but the hardware does not have a network connection and is thus under a persistent state of Sybil attack from the node software.
Thus, the hardware has to remember at least what the current state is, and store this knowledge in persistent, secure, modifiable memory that the software cannot touch. It need not store the *whole* state: for example, it could store just a commitment to the current state (and have the software store the entire state). In fact, it is best for the hardware to store the *signature* for the commitment transaction:
* The signature commits to the commitment transaction, which is a representation of the current state, thus the signature itself is a sufficient commitment to the current state.
* There is the issue of outputs with values too small to have outputs on the commitment transactions (i.e. below the dust limit).
* We can use sign-to-contract, where the signature commits to *another* preimage, one which contains the outputs that are too small to put on the Bitcoin-level commitment transaction.
* In case of a communication breakdown between the hardware and the software, the hardware can re-send the signature of the latest commitment transaction.
* This is important since the hardware and the software now have to synchronize their state storage!
The procedure is:
* The software stores the new state in a "proposed" slot in its persistent memory.
* The software sends the current and proposed states to the hardware for signing the proposed state.
* The hardware validates the update, then signs the proposed state and replaces the signature in its persistent memory.
* The hardware sends the new signature.
* The software moves the state in the proposed slot to the current slot.
* With the above, if the software ever starts up with a state in the "proposed" slot for a channel, it can query the hardware for the most recent signature, and determine if the most recent signed is in the "proposed" or "current" slot.
* Thus, the hardware only requires an atomic update to its persistent memory.
The hardware can safely resend the most recent signature, assuming it can trust its own persistent modifiable memory. This is because presumably it validated every update leading to the most recent signature in the past, else this signature in its memory would not have existed in the first place.
As each channel has two sets of commitment transactions, the hardware has to store two commitments to commitment transactions for *each* channel.
Another point is that revocations of *own* old commitment transactions can be issued by the hardware itself. This requires only a shachain; the hardware can hash the concatenation of the private key plus some channel-unique data (the full channel ID may be enough) to form the shachain seed for the revocation sequence of *own* commitment transactions.
Tr\*sted Eventual Synchrony of Two Commitments ==============================================
Each channel has two commitment transactions, one for each node. The commitment transaction for a particular node identifies which of the two nodes actually performed the unilateral close. In particular, the BOLT spec allows both commitment transactions to drift out of synchrony with each other.
Eventually, if the channel becomes relatively inactive (no updates going through it), then it is expected that the two commitment transactions will eventually converge into a single common state. But the two commitments may remain not completely in-synch indefinitely.
In order to properly determine synchrony, the hardware has to have an honest account of the transcript between the software for this node, and the other node. The only source of this information is the software. The software cannot falsely give a signature from the other node that updates our *own* commitment transaction, but the software can definitely lie and deny that the remote side has done so. Thus, the two commitment transactions may drift out of synch significantly.
There might not be any significant attacks enabled by having the two commitments out-of-sync indefinitely. This may prevent some HTLCs from being safely forwardable, but that only means stalls in payment forwarding.
Non-publication of Revoked Transactions =======================================
With Poon-Dryja, publication of old state is fatal and is an easy way for a corrupted node software to donate money to the other node. Even with Decker-Wattenhofer or Decker-Russell-Osuntokun, a corrupted node software can simply publish an old state where most of the money is allocated to the other node, and not publish the latest state, so switching to Decker-Russell-Osuntokun ("eltoo") is not a large increase in security for a hardware signer.
To prevent publication of our *own* commitment transaction at least, the hardware can simply not sign *own* commitment transactions as they are created. (the hardware still has to immediately sign the *remote* commitment transaction, as part of the update protocol requires handing over that signature to the other node.)
Instead of storing a signature for our "own* commitment transaction, the hardware can store a simple hash or txid of the latest *own* commitment transaction. Thus:
* The hardware stores: * The latest signature for the *remote* commitment transaction. * The latest txid for the *own* commitment transaction.
The hardware will only sign an *own* commitment transaction that matches the txid currently stored in it. Further, this particular commitment must now become the *last* commitment and the hardware should subsequently reject all attempts to further advance the state.
When updating the *own* commitment transaction, the software must provide the signature from the other node for the next commitment transaction, as well as the current and proposed-next commitment transaction. The hardware validates that the state change is valid, changes the *own* commitment txid, and then returns the equivalent revocation key for the just-replaced commitment transaction.
Communications breakdown between the hardware and software can still occur between the time the hardware sends the signature for the latest (and last) commitment transaction, and when the software receives it. Thus, the hardware has to have a concept of a "closed" channel, where it marks that the current txid for the *own* commitment transaction is the last one, and it will provide the signature for that commitment transaction, but refuse to sign any other commitment transaction and refuse to advance the state of the channel. To reduce the complexity of the software-hardware interface, we could also allow the hardware to sign a mutual close transaction that matches the *own* and *remote* commitment transactions even in this "closed" state. Finally the channel can later be removed from the (presumably limited) persistent storage of the hardware.
Thus the protocol for our own unilateral or mutual close would be:
* The software requests to close the channel. * The hardware marks the channel as closed, which prevents the channel from updating in the future. * The software requests a signature for the final commitment or mutual close transaction. * For mutual closes it provides the commitment transaction and the mutual close, and the hardware validates that the mutual close matches the commitment transaction. * For unilateral closes the hardware also provides the signatures to claim the revocable outputs. * The software receives the signature and broadcasts the commitment or mutual close transaction onchain. * Once the transaction is deeply confirmed, the software requests the channel to be deleted from the hardware persistent storage.
Thus the hardware provides three APIs:
* Mark-as-close. * Get-final-signature (unilateral or mutual close option). * Delete-closed.
At restart, the software can query the hardware for any channels that are currently being closed, and can check the mempool and blockchain for whether they have completed the close or not.
Tr\*sted Revocation of Old Remote State =======================================
Unfortunately, the hardware has to tr\*st the software to check that the other node is not cheating. As the hardware itself is not capable of accessing the blockchain or mempool, it cannot do this checking directly. Thus, revocation of old remote state is not ensurable by the hardware.
As revocation can only be done by the software anyway, the revocation secrets for the *remote* commitment transactions can be stored by the software only. The hardware need never learn the revocation secrets as it can do nothing with them anyway.
Opening a Channel =================
Of course, before we even start having updates to channel state, first we must have opened channels.
Opening will of course allocate a slot in the hardware persistent memory for the channel. Further, it must respect the opening sequence.
When opening a channel where the other node is the only funder, then it is sufficient to just propose some initial state for both commitment transactions and have the hardware initialize a slot in its persistent memory with this channel open.
However, when opening a channel where some of the funds come from this node, the hardware will also later sign the funding transaction spending its own funds and feeding into the channel to be funded. The software provides the other node signature for the *own* initial commitment transaction. The hardware then validates that it is able to claim the equivalent amount in both the *own* and *remote* commitment transactions. If there is a difference, that implies that this node is what pays the fee, and the hardware should probably double-confirm with the user using its UI whether the paid fees are acceptab;e.
Tr\*sted Forwarding ===================
Forwarding should be automated and not require a confirmation from the user on the hardware unit UI. Unfortunately, the hardware has to trust the software to actually perform forwarding correctly. (indeed, it is unlikely that confirmation from the user would be able to give users a good way to understand what is being asked when a forwarding attempt is made)
When forwarding, the hardware has to sign off on an update that actively spends money from funds owned by this node, on the basis of a promise that some other HTLC is offering money of greater value to this node. Certainly the hardware can demand that the software provide a current channel state showing the incoming HTLC, before it signs off on an updated channel state that instantiates the outgoing HTLC from the funds owned by this node.
However, the hardware has to keep track that an incoming HTLC only has at most one outgoing HTLC,. It cannot identify using the hash, incidentally: it is theoretically possible for a route to loop through a node twice, e.g. A -> B -> C -> D -> E -> C -> F, where C appears twice. Further, if a payment attempt fails, then the ultimate payer might still try to route through this node, giving a different postfix past this node, so this node may forward the same hash twice on two or more different payment attempts. Thus, the software and the hardware have to agree on some other identifier on HTLCs. In C-Lightning, for example, HTLCs are internally identified by the database ID that they happen to get assigned to; database IDs are simply automatically-incremented counters.
Regardless, even if we somehow, the *enforcement* of HTLCs is still controlled by the software:
* The hardware has no access to the blockchain, thus it cannot know if the incoming HTLC is in fact something in the deep past already. A corrupted software can induce the hardware to create an outgoing HTLC whose timelock is deeply in the past, then refuse to take the timelock branch of the outgoing HTLC while letting the timelock branch of the incoming HTLC be claimed by the other nodes.
Thus, forwarding is still trusted.
Alternately, we can also point out that the only purpose of forwarding is actually just to improve our privacy. (in case it is not obvious, this is hyperbole) By forwarding, it becomes ambiguous whether we are the ultimate payee if we get an incoming HTLC, and ambiguous whether we are the ultimate payer if we send an outgoing HTLC. If we never forward, then this privacy is lost. (This is the same argument that rejects unpublished channels: nodes that only have unpublished channels cannot forward, thus every activity on their node is obviously arising or terminating at their node: unpublished channels delenda est)
I will also point out that I laid out the goals for this exercise would be to reduce trust requirements first and state requirements second: privacy was not listed. Thus, removing the ability to forward automatically can be removed for the purpose of this exercise.
Retrying Payments =================
When trying a payment once, the hardware can confirm to the user via its own UI whether to authorize the payment. However, when *re*trying a payment, it would be onerous if the hardware had to keep asking the user to confirm each payment attempt.
Instead, the hardware can keep track of exactly one pending outgoing payment that the software will try its best to deliver. The hardware can store the hash of this payment, and a maximum sendable amount (the nominal payment amount plus any extra that would pay for fees and any other privacy-improving routing techniques the software may apply). Initially the payment slot will be empty. Then, when the software initiates a payment, the hardware can be given the various data in the invoice, which it can display to the user in its UI, and when the user confirms the payment, it can load the hash and maximum allowed value into the payment slot.
Then, when the software requests a new channel state, such that a new HTLC matching the payment slot hash is created from funds owned by this node, the hardware can keep track of the number of such HTLCs currently instantiated. As the HTLC has to be instantiated on both commitment transactions, the hardware has to keep track, in persistent memory, a single counter that goes from 0 to 2. When such an HTLC is instantiated from the own node funds, the hardware increments this pointer if it is less than two. Then if such an HTLC is removed, and the funds returned to our own node funds, the hardware decrements this pointer. If the HTLC is removed with the funds given to the other node, then the hardware must demand the preimage of the hash, as proof that indeed, the payment occurred. Then it can decrement that counter and set a flag that the payment has been completed (and thus the outgoing HTLC cannot be added again, i.e. the counter cannot be incremented). Then when the counter has fallen to zero with the payment-complete flag set, the hardware can clear the payment slot.
The hardware can support having multiple payments in parallel running by providing more than one payment slot.
Accepting Payments ==================
This is trivial: the hardware will sign off on all state updates that retain or increase the amount of funds owned by this node. Payment preimages for incoming payments need not even be known by the hardware, ever. Thus there is no trust or storage requirements for accepting payments.
Reducing Storage Size =====================
The hardware can, instead of storing multiple channel slots and payment slots in its own persistent memory, can instead just store a single *commitment* to the current state it knows to be valid. This can be done by transforming its state into a purely-functional data structure and merklizing it.
A purely-functional data structure is a data structure where structural nodes, once constructed, cannot be modified. For example, a singly-linked list can be made into a purely-functional data structure, If we have a list A -> B -> C -> null, then we can "mutate" this structure by creating a new list with a different prefix, such as Q -> R -> C -> null. The old C -> null node in the original list can be reused.
Binary search trees are also easily transformed into purely-functional data structures. Generally, the Okasaki book is the primary reference for purely-functional data structures.
Then, to Merklize a purely-functional data structure, simply means that all pointers are replaced with hashes.
Thus, a Merkle tree is nothing more than a plain binary tree, Merklized.
Quoted text (1 line)
>From this point of view, the blockchain is nothing more than a Merklized singly-linked list, with the `prevBlockHash` serving as the "next" pointer.
New blocks are prepended to the front of this singly-linked list, and the "null" terminating the singly-linked list is nothing more than genesis.
For the hardware state, the top node can contain two "pointers", one for the channel data and one for the running-payments data. The root is then the "pointer" to the current top node. Those "pointers" then point to two red-black (or other balanced purely functional) trees, one for the channel data and one for the running payments. When channel data only is updated, the top node is replaced, but the node for the running payments data is just copied from the previous top node. Similarly, only the path to the channel data through the red-black tree is affected.
Using a Merklized purely-functional data structure to store the entire hardware state allows the hardware to only absolutely require a secure persistent memory that fits 32 bytes, enough for a single commitment. This can allow some leeway in storing this root data redundantly in multiple places, and to encode it with error correction and detection, and so on.
Whenever the software makes a request to the hardware, which in the above discussion requires the hardware to read its internal state, the software instead serializes the internal state. Then the hardware can validate that the software has not given it incorrect state. Similarly, when the hardware has to update its state, it can give the reserialization of the modified data, and update its internal state. The cute thing is that, just as a standard Merkle tree inclusion proof only requires sending a small subset of the entire Merkle tree, the software need not send the *entire* hardware state --- it can send only those parts that are relevant to the specific channel(s) and outgoing payment attempt(s) that it is currently asking for. This can let the hardware be very cheap and limited, with the software handling all of the *actual* state storage.
However, we must now be very careful to ensure that the state of both hardware and software remain the same even if both become powered off or some communication failure occurs. My suggestion is for the software to store two copies of the hardware state (both "copies" can share some data files due to he purely-functional nature of the data, but some nodes will exist in only one copy or the other). Then, whenever the hardware has to update the state:
* The software gives the part of the state that needs updating by the hardware. * The hardware provides the updated state data, plus a signature of the concatenation of the old root plus the new root as well as the new root. * The software stores the new state data (but retains the old state data). * The software asks the hardware to update its single root variable. It provides the current root plus the new root, as well as the previous signature of the concatenation of those. * The hardware validates that the current root in its slot matches, that the signature is indeed a valid signature of itself, then updates its root slot. * The software deletes the parts of the old state data that were not reused in the new state.
At any time, if power is shut off, the software and hardware can recover by checking the current root held in the hardware.
Regards, ZmnSCPxj
Thank you for the detailed evaluation. Please see inline comments. To make reading easier, I've replaced some uncontroversial text with [...].
On Tue, Jan 14, 2020 at 7:15 AM ZmnSCPxj via Lightning-dev <lightning-dev at lists.linuxfoundation.org> wrote:
Quoted text (8 lines)
> > [...] > In any case, the goal is to have some hardware unit, using only a simple communications channel with the software, to act as signer for all Lightning-related things (channel funding, channel updates, reclaiming funds after channel close). > As is typical for such Bitcoin-related hardware units, it might possess its own user interface by which it can require confirmation of certain actions. > Also, to reduce risk of hacking, the hardware unit does not have a connection to the netwrok, only a communications channel that is restricted to a local direct connection (such as USB). > > I will now demonstrate that such a design cannot achieve what an onchain Bitcoin hardware wallet does, namely that the hardware need not tr\*st the software and need not keep any state beyond the private key (which remains constant). > For Lightning, it seems any hardware would require tr\*st in the software *and* some state.
Agreed, any external signer must maintain state because it must not sign revoked transactions, etc. .
Quoted text (6 lines)
> > Channel Updates > =============== > > [...] > Thus, the hardware has to remember at least what the current state is, and store this knowledge in persistent, secure, modifiable memory that the software cannot touch.
Agreed.
Quoted text (2 lines)
> It need not store the *whole* state: for example, it could store just a commitment to the current state (and have the software store the entire state). > In fact, it is best for the hardware to store the *signature* for the commitment transaction:
I would say that's not enough, if we assume that the attacker can destroy the underlying data, and destroy all backups. If the attacker can do that, the node is at the mercy of channel partners, since they will be able to publish old state without the possibility of retaliation. Thus there needs to be a secure form of storage where at least one backup must be recoverable at all times within the penalty time window.
I do agree that a low-resource hardware wallet may just store the signature, or other commitment to the state. In that case, we could store the full data using an append-only log to a hardened machine that specializes in preventing destruction of data by an attacker.
Quoted text (7 lines)
> > [...] > > Tr\*sted Eventual Synchrony of Two Commitments > ============================================== > [...] > This may prevent some HTLCs from being safely forwardable, but that only means stalls in payment forwarding.
This is a good point we haven't considered in our original writeup. Intuitively, you are right that this can only result in stalls.
Quoted text (8 lines)
> > > > Non-publication of Revoked Transactions > ======================================= > > [...] > To prevent publication of our *own* commitment transaction at least, the hardware can simply not sign *own* commitment transactions as they are created.
Agreed.
Quoted text (3 lines)
> > [...] > Thus, the hardware has to have a concept of a "closed" channel, where it marks that the current txid for the *own* commitment transaction is the last one, and it
Agreed.
Quoted text (7 lines)
> > [...] > Thus the hardware provides three APIs: > > * Mark-as-close. > * Get-final-signature (unilateral or mutual close option). > * Delete-closed.
It seems that the first API call can be folded into the second. Also, delete must be only performed once enough time has passed so that the closing tx is unlikely to be reorged out of existence. This requires the hardware wallet to have a trusted source of knowledge about the state of the blockchain or current time. We wrote about UTXO set oracle and the use of roughtime oracles in our original writeup.
Quoted text (8 lines)
> > [...] > Tr\*sted Revocation of Old Remote State > ======================================= > > Unfortunately, the hardware has to tr\*st the software to check that the other node is not cheating. > As the hardware itself is not capable of accessing the blockchain or mempool, it cannot do this checking directly. > Thus, revocation of old remote state is not ensurable by the hardware.
I am more optimistic about this. Publishing of penalty transactions can be delegated to a quorum of watchtowers, some possibly run by other entities. The node software can prove to the hardware that the watchtowers have been informed of new state by providing a receipt signed by the watchtowers. Thus it's possible to reduce trust in the node software.
Quoted text (4 lines)
> > > As revocation can only be done by the software anyway, the revocation secrets for the *remote* commitment transactions can be stored by the software only. > The hardware need never learn the revocation secrets as it can do nothing with them anyway.
I would at least back up the secrets in the secure storage attached to the hardware store, so that the node can be recreated if the node software has been catastrophically compromised.
Quoted text (6 lines)
> > Opening a Channel > ================= > > [...] > If there is a difference, that implies that this node is what pays the fee, and the hardware should probably double-confirm with the user using its UI whether the paid fees are acceptab;e.
If the fee is under a preset threshold, it can be auto-approved.
Quoted text (7 lines)
> > > Tr\*sted Forwarding > =================== > > Forwarding should be automated and not require a confirmation from the user on the hardware unit UI. > Unfortunately, the hardware has to trust the software to actually perform forwarding correctly.
Let's look at this carefully, I feel it should be possible to prove correctness of forwarding to the hardware.
Quoted text (3 lines)
> > However, the hardware has to keep track that an incoming HTLC only has at most one outgoing HTLC,. > It cannot identify using the hash, incidentally: it is theoretically possible for a route to loop through a node twice, e.g. A -> B -> C -> D -> E -> C -> F, where C appears twice.
I think it's enough to require that each incoming HTLC can be associated with a single outgoing HTLC. The hardware would have to maintain state about which HTLCs have been "used up" in this way.
Quoted text (2 lines)
> > Further, if a payment attempt fails, then the ultimate payer might still try to route through this node, giving a different postfix past this node, so this node may forward the same hash twice on two or more different payment attempts.
hmm... that doesn't sound safe, because then two different nodes would be able to claim the funds from us, and we can only propagate back to a single input, so we lose funds. If the Lightning protocol allows this, then it sounds like a design issue. Seems like the failed HTLC should be invalidated first. The invalidation can be proven to the hardware (a new commitment tx is signed, removing the HTLC, or the outgoing channel is closed).
Quoted text (6 lines)
> > [...] > Regardless, even if we somehow, the *enforcement* of HTLCs is still controlled by the software: > > * The hardware has no access to the blockchain, thus it cannot know if the incoming HTLC is in fact something in the deep past already. > A corrupted software can induce the hardware to create an outgoing HTLC whose timelock is deeply in the past, then refuse to take the timelock branch of the outgoing HTLC while letting the timelock branch of the incoming HTLC be claimed by the other nodes.
See above about watchtowers, and trusted sources of time/blockchain state.
Quoted text (9 lines)
> > > Thus, forwarding is still trusted. > > [...] > Reducing Storage Size > ===================== > > The hardware can, instead of storing multiple channel slots and payment slots in its own persistent memory, can instead just store a single *commitment* to the current state it knows to be valid.
Agreed, but see the need to have a reliable backup above.
Quoted text (5 lines)
> > > > Regards, > ZmnSCPxj
Good morning ZmnSCPxj,
Quoted text (11 lines)
> > > It need not store the whole state: for example, it could store just a commitment to the current state (and have the software store the entire state). > > In fact, it is best for the hardware to store the signature for the commitment transaction: > > I would say that's not enough, if we assume that the attacker can > destroy the underlying data, and destroy all backups. If the attacker > can do that, the node is at the mercy of channel partners, since they > will be able to publish old state without the possibility of > retaliation. Thus there needs to be a secure form of storage where at > least one backup must be recoverable at all times within the penalty > time window.
Right, that does seem correct.
Quoted text (16 lines)
> > > [...] > > Tr\*sted Revocation of Old Remote State > > > > ============================================== > > > > Unfortunately, the hardware has to tr\*st the software to check that the other node is not cheating. > > As the hardware itself is not capable of accessing the blockchain or mempool, it cannot do this checking directly. > > Thus, revocation of old remote state is not ensurable by the hardware. > > I am more optimistic about this. Publishing of penalty transactions > can be delegated to a quorum of watchtowers, some possibly run by > other entities. The node software can prove to the hardware that the > watchtowers have been informed of new state by providing a receipt > signed by the watchtowers. Thus it's possible to reduce trust in the > node software.
I had not thought of having the watchtower(s) sign a receipt of the channel state being backed up there, thank you.
Quoted text (7 lines)
> > > As revocation can only be done by the software anyway, the revocation secrets for the remote commitment transactions can be stored by the software only. > > The hardware need never learn the revocation secrets as it can do nothing with them anyway. > > I would at least back up the secrets in the secure storage attached to > the hardware store, so that the node can be recreated if the node > software has been catastrophically compromised.
Well, if the hardware itself has only a tiny secure storage (e.g. the example of only being able to store a commitment to the entire state) there would be no space to put those in as well, even with shachains. Further, all previous HTLC hashes and timelocks need to be stored as well, since old commitment transactions will only have P2WSH output to represent those HTLC hashes and timelocks, and the actual HTLC hashes and timelocks need to be shown as well in order to revoke the old HTLCs. It seems to me that, since the amount of storage needed would be linear on the number of HTLCs that ever appeared on the channel, a hardware with storage limits would not be appropriate to store this state and your append-only log machine might do better for that purpose.
Quoted text (9 lines)
> > > Opening a Channel > > > > ================== > > > > [...] > > If there is a difference, that implies that this node is what pays the fee, and the hardware should probably double-confirm with the user using its UI whether the paid fees are acceptab;e. > > If the fee is under a preset threshold, it can be auto-approved.
It would have to be a sophisticated threshold: a corrupted software would split up the node funds into tiny 546-satoshi channels, paying a funding tx fee each time. I suppose when considering autopilot it would have to be auto-approved though.
Quoted text (10 lines)
> > > Tr\*sted Forwarding > > > > ==================== > > > > Forwarding should be automated and not require a confirmation from the user on the hardware unit UI. > > Unfortunately, the hardware has to trust the software to actually perform forwarding correctly. > > Let's look at this carefully, I feel it should be possible to prove > correctness of forwarding to the hardware.
I believe not. Consider this sequence of events:
* The hardware approves an outgoing HTLC on one channel based on the existence of an incoming HTLC on another channel. * Both channels are dropped unilaterally onchain, with their respective latest states, before the outgoing HTLC can be claimed offchain. * The software lets the outgoing HTLC to be claimed by the other node using the hashlock branch. * The software lets time pass and lets the incoming HTLC be claimed by the other node using the timelock branch.
As the hardware is incapable of actually pushing transactions onchain, it cannot do anything about the incoming HTLC getting lapsed (though since it has its own UI, if it had read access to the UTXO set somehow, it could give a warning to the user using its UI and maybe hope the user notices?). Indeed it is hard to give the hardware even read access to the blockchain in order to even *know* about the outgoing HTLC getting claimed by hashlock, without serious increases in hackability, storage, and sophistication of the hardware. Once you start having a hardware *that* sophisticated, it becomes more and more like a complete Lightning node, and if you could implement that in a *secure* unit, you would not need a separate software to drive it, the software would effectively *be* inside the trusted hardware unit (when the entire point of this exercise is to have a separate software we have reduced trust in).
Quoted text (17 lines)
> > > However, the hardware has to keep track that an incoming HTLC only has at most one outgoing HTLC,. > > It cannot identify using the hash, incidentally: it is theoretically possible for a route to loop through a node twice, e.g. A -> B -> C -> D -> E -> C -> F, where C appears twice. > > I think it's enough to require that each incoming HTLC can be > associated with a single outgoing HTLC. The hardware would have to > maintain state about which HTLCs have been "used up" in this way. > > > Further, if a payment attempt fails, then the ultimate payer might still try to route through this node, giving a different postfix past this node, so this node may forward the same hash twice on two or more different payment attempts. > > hmm... that doesn't sound safe, because then two different nodes would > be able to claim the funds from us, and we can only propagate back to > a single input, so we lose funds. If the Lightning protocol allows > this, then it sounds like a design issue. Seems like the failed HTLC > should be invalidated first. The invalidation can be proven to the > hardware (a new commitment tx is signed, removing the HTLC, or the > outgoing channel is closed).
Well, the incoming HTLC would have to be deleted as well before the payer re-attempts (otherwise the payer could give out multiple HTLCs that are simultaneously claimable). The "flag" we associate with each incoming HTLC would be deleted when the incoming HTLC is deleted as well, and separate incoming HTLCs would have to be used to authorize separate outgoing HTLCs.
In any case the point of this digression above was that we cannot key on the *hash* of the HTLC, we have to have some identifier of HTLC (shared between software and hardware) that is *not* the *hash*, but some other identifier.
Quoted text (9 lines)
> > > [...] > > Regardless, even if we somehow, the enforcement of HTLCs is still controlled by the software: > > > > - The hardware has no access to the blockchain, thus it cannot know if the incoming HTLC is in fact something in the deep past already. > > A corrupted software can induce the hardware to create an outgoing HTLC whose timelock is deeply in the past, then refuse to take the timelock branch of the outgoing HTLC while letting the timelock branch of the incoming HTLC be claimed by the other nodes. > > > > See above about watchtowers, and trusted sources of time/blockchain state.
Watchtowers, at least as currently designed, treat each channel in isolation. Forwarding is about events on two channels. So you would need a more sophisticated watchtower design as well.
Quoted text (11 lines)
> > > Thus, forwarding is still trusted. > > > > [...] > > Reducing Storage Size > > > > ============================ > > > > The hardware can, instead of storing multiple channel slots and payment slots in its own persistent memory, can instead just store a single commitment to the current state it knows to be valid. > > Agreed, but see the need to have a reliable backup above.
I imagine that secure of a memory would be expensive to implement and thus limited, thus if you implement it all in the hardware, you would impose limits on the number of channels and updates and so on.
The idea of having a secure append-only log could also be used for the off-hardware state storage as well anyway, if you are trusting it enough to be able to recover the node state. The append-only log machine can even just accept new hardware states when it sees the signature from the hardware attesting the change in root as well, so that it forms a secure channel between the hardware and the append-only log machine.
Regards, ZmnSCPxj
Hey Zeeman,
tl;dr A LN node paired with an external signer can be distrusted and LN funds be safe in any case if signer is connected to a N-set of watchtowers and at least one of them is non-compromised.
Thanks for this interesting post, I was thinking about LN hardware wallets support for a while too, I do think LN model has its own pitfalls compare to base layer but that doesn't mean we can't substantially improve current one monolithic-LN-node-with-unsafe-key-material-in-RAM deployment and still have automatic processing of HTLCs.
LN security model differs compare to base layer by requiring onchain monitoring and reaction to keep your funds safe. That's quite the contrary on how HW have been designed until now where UTXO state access isn't assumed to be secure. That's said the cool thing is you may have multiple monitoring bckends/watchtowers running on different infrastructures, if one of them stay non-compromised and enforce protocol rules you should be fine [0].
So let's go through whole LN operations with a deployment such that Alice the LN processing node, Bob and Caroll the channel peers, Sally the external signer, Will a set of N watchtowers. Will is part of the same entity than Alice, run on different infra, is seeded with same secret (to derive same local keys), and have authenticated communication with Sally.
Attacks scenario are 1) node compromised, where an attacker would leverage secret keys to sign closing/justice/sweep transaftions to a attacker-controlled address. 2) node compromised + peer collusion, where an attacker broadcast revoked commitment/non-revoked commitment with a HTLC to timeout/obtain a commitment with outgoing HTLC but not incoming one.
Quoted text (1 line)
>From the perspective of signer, you can't dissociate peer collusion so it
should always be assumed and the straighter policy enforced.
Alice inits Sally with 2 funding_transactions+remote_sigs+per_commitment_point+balances states, for both link AB and AC. Balance states have to be user-input validated (or can be deduced if Sally is also an onchain wallet and fundings spent from controlled-keys modulo push_msat max being hardcoded).
Sally send to Will these requests through Alice. When Will see fundings confirmed it replies the computed channel_id to Sally and stores sigs, who then can safely considers these channels activated.
Bob initiates a payment to Caroll through link AB+AC, Alice receives the messages and ask Sally to sign Bob's remote, as it's a balance increases, no proof is asked. Sally send to Will vector of HTLCs (hash+locktime)+previous_state revocation secret+per_commitment_point. Will can return Sally an error if locktime are in the past of channel has been closed so Sally won't accept latter outgoing HTLC paired with such incoming channel. If a revoked commitment is broadcast on AB and Alice is compromised, Will generate justice transactions and take the funds back.
Alice builds outgoing payment and asks Sally to sign outgoing commitment decreasing local balance with incoming HTLC as a proof. Sally can send Will the new outgoing commitment tied with HTLC proof, if HTLC proof can't be tied to an incoming valid chan, an error should be returned to Sally and signature aborted.
At HTLC fulfillement by Caroll, Alice should pass the preimage to Caroll who pass it to Will. If Alice is compromised, Will be able to claim incoming HTLC. Will should also be able to parse onchain HTLCs and extract preimage to claim backward in case of Alice withholding the preimage.
At any block reception, Will should be able to broadcast commitment and timeout HTLCs in case of Alice being unreliable/compromised.
To avoid burning-to-fees attack, if Alice asks Sally to sign a decrasing-balance commitment without a HTLC proof, which is credible for update_fee, fees can be bounded to some value. Bounds should scope dust HTLCs too.
At channel closing, Will can observe it, if Sally ask to valid any HTLC proof, return an error.
External signer should store commitment numbers and balances for each channel and do key derivation locally (at least for local, for remote you can't trust provided per_commitment_point anyway).
Voila, I think this describes a master-slaves scheme, where external signer is coupled with watchtowers to serve as UTXO oracles, while mitigating node compromised. It would be fairly complex to design and implement it right but on the long-term it's worth it if you assume a world of wumbo channels and mutiple-btcs HTLCs [1]
Devrandom work is a pretty headstart towards such safe API and we should keep experimenting with this to patch unthought corner-cases. The futur alternative is every HW vendor designing its LN-implementation specific support, and a lot of them being flawed by missing LN security model oddities. A lack of such standard programming interface on base layer HW and the number of vuln due to mishandling change or derivation is something to meditate on.
Quoted text (5 lines)
> It would have to be a sophisticated threshold: a corrupted software would split up the node funds into tiny 546-satoshi channels, paying a funding tx fee each time. > I suppose when considering autopilot it would have to be auto-approved though.
A signer can implement further checks to asses channel opening utility. Like a channels provider signer would verify than no more than X channels with Y liquidity are opened on time period Z. And you may ask for a user invoice signed by a different component than your LN node.
Quoted text (3 lines)
> > It cannot identify using the hash, incidentally: it is theoretically possible for a route to loop through a node twice, e.g. A -> B -> C -> D -> E -> C -> F, where C appears twice.
If you store latest HTLC outputs on the watchtower, at incoming link update, if there is discrepancy between stored set and submitted by node set, something is wrong. Further, hash replay isn't safe right now : https://eprint.iacr.org/2019/1149.pdf
Quoted text (1 line)
> So you would need a more sophisticated watchtower design as well.
In most watchtowers discussion, it's only assumed to do justice delegation. But if you're a routing node, that's not enough to be safe, you should also timeout HTLC and do outgoing-to-incoming preimage passing in case of regular node failure. Luckily, watchtowers aren't specified yet...
Quoted text (3 lines)
> I imagine that secure of a memory would be expensive to implement and thus limited, thus if you implement it all in the hardware, you would impose limits on the number of channels and updates and so.
All this discussion may be irrelevant anyway, I've heard about 10-100MB HSM with hardened Linux, so just run a minimal LN node on it but that would create a dependency on HSM vendors and there is only a few of them..
Antoine
[0] Introducing watchtowers opens some problems like state must be synchronized to avoid spurious broadcast of revoked commitments and trusted external signer to avoid one of them spending to a malicious addresses. Though they provide also a security boost against p2p sybil attacks if each run its own full-node.
[1] This kind of deployment may only serve important processing LN nodes first, but designing specialized hardware/interfaces for them will also benefit more thrifty nodes operators by commoditization on the long term
Le mer. 15 janv. 2020 à 20:36, ZmnSCPxj via Lightning-dev < lightning-dev at lists.linuxfoundation.org> a écrit :
Quoted text (214 lines)
> Good morning ZmnSCPxj, > > > > > > It need not store the whole state: for example, it could store just a > commitment to the current state (and have the software store the entire > state). > > > In fact, it is best for the hardware to store the signature for the > commitment transaction: > > > > I would say that's not enough, if we assume that the attacker can > > destroy the underlying data, and destroy all backups. If the attacker > > can do that, the node is at the mercy of channel partners, since they > > will be able to publish old state without the possibility of > > retaliation. Thus there needs to be a secure form of storage where at > > least one backup must be recoverable at all times within the penalty > > time window. > > Right, that does seem correct. > > > > > > [...] > > > Tr\*sted Revocation of Old Remote State > > > > > > ============================================== > > > > > > Unfortunately, the hardware has to tr\*st the software to check that > the other node is not cheating. > > > As the hardware itself is not capable of accessing the blockchain or > mempool, it cannot do this checking directly. > > > Thus, revocation of old remote state is not ensurable by the hardware. > > > > I am more optimistic about this. Publishing of penalty transactions > > can be delegated to a quorum of watchtowers, some possibly run by > > other entities. The node software can prove to the hardware that the > > watchtowers have been informed of new state by providing a receipt > > signed by the watchtowers. Thus it's possible to reduce trust in the > > node software. > > I had not thought of having the watchtower(s) sign a receipt of the > channel state being backed up there, thank you. > > > > > > As revocation can only be done by the software anyway, the revocation > secrets for the remote commitment transactions can be stored by the > software only. > > > The hardware need never learn the revocation secrets as it can do > nothing with them anyway. > > > > I would at least back up the secrets in the secure storage attached to > > the hardware store, so that the node can be recreated if the node > > software has been catastrophically compromised. > > Well, if the hardware itself has only a tiny secure storage (e.g. the > example of only being able to store a commitment to the entire state) there > would be no space to put those in as well, even with shachains. > Further, all previous HTLC hashes and timelocks need to be stored as well, > since old commitment transactions will only have P2WSH output to represent > those HTLC hashes and timelocks, and the actual HTLC hashes and timelocks > need to be shown as well in order to revoke the old HTLCs. > It seems to me that, since the amount of storage needed would be linear on > the number of HTLCs that ever appeared on the channel, a hardware with > storage limits would not be appropriate to store this state and your > append-only log machine might do better for that purpose. > > > > > > Opening a Channel > > > > > > ================== > > > > > > [...] > > > If there is a difference, that implies that this node is what pays the > fee, and the hardware should probably double-confirm with the user using > its UI whether the paid fees are acceptab;e. > > > > If the fee is under a preset threshold, it can be auto-approved. > > It would have to be a sophisticated threshold: a corrupted software would > split up the node funds into tiny 546-satoshi channels, paying a funding tx > fee each time. > I suppose when considering autopilot it would have to be auto-approved > though. > > > > > > Tr\*sted Forwarding > > > > > > ==================== > > > > > > Forwarding should be automated and not require a confirmation from the > user on the hardware unit UI. > > > Unfortunately, the hardware has to trust the software to actually > perform forwarding correctly. > > > > Let's look at this carefully, I feel it should be possible to prove > > correctness of forwarding to the hardware. > > I believe not. > Consider this sequence of events: > > * The hardware approves an outgoing HTLC on one channel based on the > existence of an incoming HTLC on another channel. > * Both channels are dropped unilaterally onchain, with their respective > latest states, before the outgoing HTLC can be claimed offchain. > * The software lets the outgoing HTLC to be claimed by the other node > using the hashlock branch. > * The software lets time pass and lets the incoming HTLC be claimed by the > other node using the timelock branch. > > As the hardware is incapable of actually pushing transactions onchain, it > cannot do anything about the incoming HTLC getting lapsed (though since it > has its own UI, if it had read access to the UTXO set somehow, it could > give a warning to the user using its UI and maybe hope the user notices?). > Indeed it is hard to give the hardware even read access to the blockchain > in order to even *know* about the outgoing HTLC getting claimed by > hashlock, without serious increases in hackability, storage, and > sophistication of the hardware. > Once you start having a hardware *that* sophisticated, it becomes more and > more like a complete Lightning node, and if you could implement that in a > *secure* unit, you would not need a separate software to drive it, the > software would effectively *be* inside the trusted hardware unit (when the > entire point of this exercise is to have a separate software we have > reduced trust in). > > > > > > However, the hardware has to keep track that an incoming HTLC only has > at most one outgoing HTLC,. > > > It cannot identify using the hash, incidentally: it is theoretically > possible for a route to loop through a node twice, e.g. A -> B -> C -> D -> > E -> C -> F, where C appears twice. > > > > I think it's enough to require that each incoming HTLC can be > > associated with a single outgoing HTLC. The hardware would have to > > maintain state about which HTLCs have been "used up" in this way. > > > > > Further, if a payment attempt fails, then the ultimate payer might > still try to route through this node, giving a different postfix past this > node, so this node may forward the same hash twice on two or more different > payment attempts. > > > > hmm... that doesn't sound safe, because then two different nodes would > > be able to claim the funds from us, and we can only propagate back to > > a single input, so we lose funds. If the Lightning protocol allows > > this, then it sounds like a design issue. Seems like the failed HTLC > > should be invalidated first. The invalidation can be proven to the > > hardware (a new commitment tx is signed, removing the HTLC, or the > > outgoing channel is closed). > > Well, the incoming HTLC would have to be deleted as well before the payer > re-attempts (otherwise the payer could give out multiple HTLCs that are > simultaneously claimable). > The "flag" we associate with each incoming HTLC would be deleted when the > incoming HTLC is deleted as well, and separate incoming HTLCs would have to > be used to authorize separate outgoing HTLCs. > > In any case the point of this digression above was that we cannot key on > the *hash* of the HTLC, we have to have some identifier of HTLC (shared > between software and hardware) that is *not* the *hash*, but some other > identifier. > > > > > > [...] > > > Regardless, even if we somehow, the enforcement of HTLCs is still > controlled by the software: > > > > > > - The hardware has no access to the blockchain, thus it cannot know > if the incoming HTLC is in fact something in the deep past already. > > > A corrupted software can induce the hardware to create an outgoing > HTLC whose timelock is deeply in the past, then refuse to take the timelock > branch of the outgoing HTLC while letting the timelock branch of the > incoming HTLC be claimed by the other nodes. > > > > > > > See above about watchtowers, and trusted sources of time/blockchain > state. > > Watchtowers, at least as currently designed, treat each channel in > isolation. > Forwarding is about events on two channels. > So you would need a more sophisticated watchtower design as well. > > > > > > Thus, forwarding is still trusted. > > > > > > [...] > > > Reducing Storage Size > > > > > > ============================ > > > > > > The hardware can, instead of storing multiple channel slots and > payment slots in its own persistent memory, can instead just store a single > commitment to the current state it knows to be valid. > > > > Agreed, but see the need to have a reliable backup above. > > > I imagine that secure of a memory would be expensive to implement and thus > limited, thus if you implement it all in the hardware, you would impose > limits on the number of channels and updates and so on. > > The idea of having a secure append-only log could also be used for the > off-hardware state storage as well anyway, if you are trusting it enough to > be able to recover the node state. > The append-only log machine can even just accept new hardware states when > it sees the signature from the hardware attesting the change in root as > well, so that it forms a secure channel between the hardware and the > append-only log machine. > > Regards, > ZmnSCPxj > > _______________________________________________ > Lightning-dev mailing list > Lightning-dev at lists.linuxfoundation.org > https://www.learnbitcoin.com/archive/lists/lightning-dev >