Skip to content

#4: Add specification onion error obfuscation - #8

Merged
Roasbeef merged 2 commits into
lightningnetwork:masterfrom
avemeva:sphinx_error_propogation
Jul 14, 2017
Merged

Roasbeef merged 2 commits into
lightningnetwork:masterfrom
avemeva:sphinx_error_propogation

Conversation

@avemeva

@avemeva avemeva commented Jun 8, 2017 •

Copy link
Copy Markdown
Contributor

Issue: #4

@avemeva
avemeva force-pushed the sphinx_error_propogation branch 4 times, most recently from ad0a979 to f33493c Compare June 27, 2017 16:28
Add BOLT#4 data obfuscation, which will be used inside lnd in order to
obfuscate the payment failures.
@avemeva
avemeva force-pushed the sphinx_error_propogation branch from f33493c to f6a3f30 Compare June 28, 2017 11:16
@avemeva avemeva changed the title Add specification onion error obfuscation #4: Add specification onion error obfuscation Jun 29, 2017
@avemeva
avemeva force-pushed the sphinx_error_propogation branch from f6a3f30 to 3fe194e Compare June 30, 2017 11:25

@Roasbeef Roasbeef left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I've been anticpating this PR so we can finally be compliant with the way encrypted errors are defined within the spec.

Most of my comments are minor, the only major one being a bug I observed when handling error replies by the originator of a payment.

Carrying over my comment from the other PR, a sphinx.Circuit object (fields defined in that comment) should be added to the package.

Comment thread obfuscation.go Outdated
}, nil
}

// Obfuscate is used to make data obfuscation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The paragraph should be properly folded to 80 characters.

Comment thread obfuscation.go
"github.com/roasbeef/btcd/btcec"
)

// onionObfuscation obfuscates the data with compliance with BOLT#4.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either a newline should be inserted, or the line below should be properly wrapped (respecting the 80 character limit) into the one above.

Comment thread error.go Outdated
ErrReplayedPacket = fmt.Errorf("sphinx packet replay attempted")

// ErrInvalidOnionVersion is returned during decoding of the onion packet, when
// received packet has unknown version byte.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when -> when the

has unknown -> has an unknown

Comment thread error.go Outdated
ErrInvalidOnionVersion = fmt.Errorf("invalid onion packet version")

// ErrInvalidOnionHMAC is returned during onion parsing process, when received
// mac do not corresponds to the generated one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not -> does not

Comment thread error.go Outdated
ErrInvalidOnionHMAC = fmt.Errorf("invalid mismathed mac")

// ErrInvalidOnionKey is returned during onion parsing process, when
// onion key is invalid - not belongs to the secp256k1 curve.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latter portion of the comment should likely be re-written a bit.

Comment thread obfuscation.go Outdated
// obfuscation in reverse order.
func (o *OnionDeobfuscator) Deobfuscate(obfuscatedData []byte) (*btcec.PublicKey,
[]byte, error) {
for i, sharedSecret := range generateSharedSecrets(o.paymentPath,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be mis-understanding something, but to me, as currently, written this function is semantically incorrect. Correct me if I'm wrong, but instead we need a double for-loop in order to attempt to decode the packet properly. This is due to the fact that any of the participants on the original route may have originally encrypted the packet. As a result, there are N^2 different possibilities.

Let's take a route of A -> B -> C. Let's say that B was the one who originally created the error. From my reading, this loop would first start with C, apply the stream cipher bytes, then proceed to B finally. This would result in an invalid final packet as C's stream cipher bytes were erroneously applied.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this function assumes that the error will always be sent by the last participant in a route. This is an incorrect assumption.

Comment thread obfuscation.go Outdated
}

// Decode initializes the deobfuscator from the byte stream.
func (o *OnionDeobfuscator) Decode(r io.Reader) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these encode and decode methods really necessary? Where are they used?

I guess we may use them within lnd later when we start to persist the raw circuit information as well? In that case they should be removed to the to-be-create sphinx.Circuit struct.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree!

Comment thread obfuscation_test.go

// Emulate creation of the obfuscator on node where error have occurred.
obfuscator := &OnionObfuscator{
sharedSecret: sharedSecrets[len(errorPath)-1],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test should also test the case of the error originating from a node that isn't the last hop. I think this would've exposed the issue I pointed out above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am already doing this, I reduced the path slightly higher in the diff.

obfuscation_test.go
26:  +    // Reduce the error path on one node, in order to check that we are
27:  +    // able to receive the error not only from last hop.
28:  +    errorPath := paymentPath[:len(paymentPath)-1]

Comment thread obfuscation_test.go Outdated
"9b8e6faa83b81fbfa6133c0af5d6b07c017f7158fa94f0d206ba" +
"f12dda6b68f785b773b360fd",
},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the extra new lines in-between successive elements of the slice literal.

Comment thread sphinx.go
func NewOnionPacket(paymentPath []*btcec.PublicKey, sessionKey *btcec.PrivateKey,
hopsData []HopData, assocData []byte) (*OnionPacket, error) {

func generateSharedSecrets(paymentPath []*btcec.PublicKey,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a godoc comment.

In order to properly handle errors during decoding and parsing process
the distinct variables of errors have been created.
@avemeva
avemeva force-pushed the sphinx_error_propogation branch from 231f731 to c3968ec Compare July 13, 2017 11:53

@Roasbeef Roasbeef left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💎

@Roasbeef
Roasbeef merged commit a14a926 into lightningnetwork:master Jul 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants