Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
17a8e1b
add public key multiply to elliptic curve. need to get feedback
pegasusjcrawford Feb 28, 2022
4414e38
rename Hashing to Crypto to allow for Curve Actions
pegasusjcrawford Feb 28, 2022
ebce2cf
move elliptic curve actions into common crypto folder
pegasusjcrawford Feb 28, 2022
070cbb2
updates to feature flags & messge type enums for onion routing
pegasusjcrawford Feb 28, 2022
d408674
some base entities for onion routing. eclair inspired
pegasusjcrawford Feb 28, 2022
972a697
stub out the beginnings of the onion message serializer. need to add …
pegasusjcrawford Feb 28, 2022
6a290ae
Start building up some of the Sphinx primitives. Modeled after eclair…
pegasusjcrawford Feb 28, 2022
2150f92
Merge branch 'master' of https://github.com/block-core/lyn into block…
pegasusjcrawford Feb 28, 2022
f431250
Merge branch 'block-core-master' into feature/onion-routing
pegasusjcrawford Feb 28, 2022
88bd97d
fix files i broke with my silly crypto rename
pegasusjcrawford Feb 28, 2022
7889243
save wip onion stuff for great migration to new VM :c
pegasusjcrawford Mar 9, 2022
d9fb3ba
rework some more of the onion tests
pegasusjcrawford Mar 11, 2022
432d3a0
refactor message & packet serialization
pegasusjcrawford Mar 11, 2022
c911e03
more wip for peeling the onion message
pegasusjcrawford Mar 11, 2022
6961486
extract peelonion into the sphinx class
pegasusjcrawford Mar 11, 2022
870e015
fix the peekpayloadlength function & get generate filler passing some…
pegasusjcrawford Mar 12, 2022
9b3e364
Get the tests for the create & peel of an onion packet using the fixe…
pegasusjcrawford Mar 20, 2022
0189011
add two of the variable length sphinx tests
pegasusjcrawford Mar 20, 2022
380e9bc
refactor the sphinx tests to pull refernce vectors from a class for now
pegasusjcrawford Sep 9, 2022
f53206a
extract the payload length test vectors
pegasusjcrawford Sep 9, 2022
f6c3d0d
refactor some of the test cases to use less boilerplate code
pegasusjcrawford Sep 9, 2022
743e627
move ephemeral key reference data to class
pegasusjcrawford Sep 9, 2022
8bc4f9b
add the islastpacket test and fix some logic
pegasusjcrawford Nov 10, 2022
745b7d9
start deprecating the legacy onion format - PeekPayloadLength throws …
pegasusjcrawford Nov 14, 2022
ce5338c
refactor a few more of the payload tests + flesh out Bad Onion details
pegasusjcrawford Nov 14, 2022
54e0f2e
add test case for OneHopPayload
pegasusjcrawford Nov 14, 2022
900eddc
some improvements to the sphinx class based on gpt notes
pegasusjcrawford Dec 11, 2022
756d5cf
first pass at porting the failure messages
pegasusjcrawford Dec 12, 2022
6df0494
start to implement failure message serialization and get some tests s…
pegasusjcrawford Dec 16, 2022
0697a33
majorly incomplete failure packet work - still gluing things together…
pegasusjcrawford Dec 19, 2022
abd99b9
WIP RouteBlinding
pegasusjcrawford Dec 24, 2022
15bfe53
add new multiply with private key to try and fix the first hop
pegasusjcrawford Dec 26, 2022
946aed2
nit cleanup
pegasusjcrawford Dec 28, 2022
d57730e
get testr to the point where i can concatenate routes and verify the …
pegasusjcrawford Dec 28, 2022
904904d
add Eve's blinded key validation
pegasusjcrawford Dec 28, 2022
db247a7
get route blinding e2e validated up until it's time for Tlv Packets
pegasusjcrawford Dec 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Lyn.Protocol.Bolt9;
using Lyn.Protocol.Common;
using Lyn.Protocol.Common.Blockchain;
using Lyn.Protocol.Common.Hashing;
using Lyn.Protocol.Common.Crypto;
using Lyn.Protocol.Common.Messages;
using Lyn.Protocol.Connection;
using Lyn.Types;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using Lyn.Protocol.Bolt9;
using Lyn.Protocol.Common;
using Lyn.Protocol.Common.Blockchain;
using Lyn.Protocol.Common.Hashing;
using Lyn.Protocol.Common.Crypto;
using Lyn.Protocol.Common.Messages;
using Lyn.Protocol.Connection;
using Lyn.Types;
Expand Down
2 changes: 1 addition & 1 deletion src/Lyn.Protocol.Tests/Bolt3/Bolt3CommitmentTestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Lyn.Protocol.Bolt3;
using Lyn.Protocol.Bolt3.Types;
using Lyn.Protocol.Common;
using Lyn.Protocol.Common.Hashing;
using Lyn.Protocol.Common.Crypto;
using Lyn.Protocol.Common.Messages;
using Lyn.Types;
using Lyn.Types.Bitcoin;
Expand Down
2 changes: 1 addition & 1 deletion src/Lyn.Protocol.Tests/Bolt3/Bolt3CommitmentTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using Lyn.Protocol.Bolt3.Types;
using Lyn.Protocol.Common.Hashing;
using Lyn.Protocol.Common.Crypto;
using Lyn.Types;
using Lyn.Types.Bitcoin;
using Lyn.Types.Fundamental;
Expand Down
83 changes: 83 additions & 0 deletions src/Lyn.Protocol.Tests/Bolt4/Data/SphinxReferenceVectors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Lyn.Types.Fundamental;

namespace Lyn.Protocol.Tests.Bolt4.Data
{
public static class SphinxReferenceVectors
{
public static byte[] InvalidVersionPayload => new[] { (byte)0x00 };
public static List<byte[]> ExpectedEphemeralKeys = new List<byte[]>() {
Convert.FromHexString("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619"),
Convert.FromHexString("028f9438bfbf7feac2e108d677e3a82da596be706cc1cf342b75c7b7e22bf4e6e2"),
Convert.FromHexString("03bfd8225241ea71cd0843db7709f4c222f62ff2d4516fd38b39914ab6b83e0da0"),
Convert.FromHexString("031dde6926381289671300239ea8e57ffaf9bebd05b9a5b95beaf07af05cd43595"),
Convert.FromHexString("03a214ebd875aab6ddfd77f22c5e7311d7f77f17a169e599f157bbcdae8bf071f4")
};

public static List<byte[]> ExpectedEphemeralSecrets = new List<byte[]>() {
Convert.FromHexString("53eb63ea8a3fec3b3cd433b85cd62a4b145e1dda09391b348c4e1cd36a03ea66"),
Convert.FromHexString("a6519e98832a0b179f62123b3567c106db99ee37bef036e783263602f3488fae"),
Convert.FromHexString("3a6b412548762f0dbccce5c7ae7bb8147d1caf9b5471c34120b30bc9c04891cc"),
Convert.FromHexString("21e13c2d7cfe7e18836df50872466117a295783ab8aab0e7ecc8c725503ad02d"),
Convert.FromHexString("b5756b9b542727dbafc6765a49488b023a725d631af688fc031217e90770c328")
};

public static (byte[], int)[] PaylodLengths = new (byte[], int)[] {
(Convert.FromHexString("01"), 34),
(Convert.FromHexString("08"), 41),
(Convert.FromHexString("fc"), 285),
(Convert.FromHexString("fd00fd"), 288),
(Convert.FromHexString("fdffff"), 65570)
};

public static PrivateKey SessionKey = new PrivateKey(Convert.FromHexString("4141414141414141414141414141414141414141414141414141414141414141"));

public static List<PrivateKey> PrivateKeys = new List<PrivateKey>() {
new PrivateKey(Convert.FromHexString("4141414141414141414141414141414141414141414141414141414141414141")),
new PrivateKey(Convert.FromHexString("4242424242424242424242424242424242424242424242424242424242424242")),
new PrivateKey(Convert.FromHexString("4343434343434343434343434343434343434343434343434343434343434343")),
new PrivateKey(Convert.FromHexString("4444444444444444444444444444444444444444444444444444444444444444")),
new PrivateKey(Convert.FromHexString("4545454545454545454545454545454545454545454545454545454545454545"))
};

public static List<PublicKey> PublicKeys = new List<PublicKey>() {
new PublicKey(Convert.FromHexString("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619")),
new PublicKey(Convert.FromHexString("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c")),
new PublicKey(Convert.FromHexString("027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007")),
new PublicKey(Convert.FromHexString("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991")),
new PublicKey(Convert.FromHexString("02edabbd16b41c8371b92ef2f04c1185b4f03b6dcd52ba9b78d9d7c89c8f221145"))
};

// origin -> node #0 -> node #1 -> node #2 -> node #3 -> node #4
public static List<byte[]> ReferencePaymentPayloads = new List<byte[]>() {
Convert.FromHexString("1202023a98040205dc06080000000000000001"),
Convert.FromHexString("52020236b00402057806080000000000000002fd02013c0102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f"),
Convert.FromHexString("12020230d4040204e206080000000000000003"),
Convert.FromHexString("1202022710040203e806080000000000000004"),
Convert.FromHexString("fd011002022710040203e8082224a33562c54507a9334e79f0dc4f17d407e6d7c61f0e2f3d0d38599502f617042710fd012de02a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a")
};

// This test vector uses multiple payloads to fill the whole onion packet.
// origin -> node #0 -> node #1 -> node #2 -> node #3 -> node #4
public static List<byte[]> PaymentPayloadsFull = new List<byte[]>() {
Convert.FromHexString("8b09000000000000000030000000000000000000000000000000000000000000000000000000000025000000000000000000000000000000000000000000000000250000000000000000000000000000000000000000000000002500000000000000000000000000000000000000000000000025000000000000000000000000000000000000000000000000"),
Convert.FromHexString("fd012a08000000000000009000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000200000000000000000000000000000000000000020000000000000000000000000000000000000002000000000000000000000000000000000000000200000000000000000000000000000000000000020000000000000000000000000000000000000002000000000000000000000000000000000000000200000000000000000000000000000000000000020000000000000000000000000000000000000002000000000000000000000000000000000000000"),
Convert.FromHexString("620800000000000000900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
Convert.FromHexString("fc120000000000000000000000240000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000"),
Convert.FromHexString("fd01582200000000000000000000000000000000000000000022000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000")
};

public static List<byte[]> OneHopPaymentPayload = new List<byte[]>() {
Convert.FromHexString("fd04f16500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
};

public static byte[] AssociatedData = Convert.FromHexString("4242424242424242424242424242424242424242424242424242424242424242");

public static byte[] GenerateFiller_ExpectedFiller = Convert.FromHexString("51c30cc8f20da0153ca3839b850bcbc8fefc7fd84802f3e78cb35a660e747b57aa5b0de555cbcf1e6f044a718cc34219b96597f3684eee7a0232e1754f638006cb15a14788217abdf1bdd67910dc1ca74a05dcce8b5ad841b0f939fca8935f6a3ff660e0efb409f1a24ce4aa16fc7dc074cd84422c10cc4dd4fc150dd6d1e4f50b36ce10fef29248dd0cec85c72eb3e4b2f4a7c03b5c9e0c9dd12976553ede3d0e295f842187b33ff743e6d685075e98e1bcab8a46bff0102ca8b2098ae91798d370b01ca7076d3d626952a03663fe8dc700d1358263b73ba30e36731a0b72092f8d5bc8cd346762e93b2bf203d00264e4bc136fc142de8f7b69154deb05854ea88e2d7506222c95ba1aab06");
}
}
49 changes: 49 additions & 0 deletions src/Lyn.Protocol.Tests/Bolt4/FailureMessageSerializerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Lyn.Protocol.Bolt4;
using Lyn.Protocol.Bolt4.Entities;
using Lyn.Protocol.Bolt4.Messages;
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace Lyn.Protocol.Tests.Bolt4
{
// need to implement tests so we have parity with FailureMessageCodecsSpec.scala from eclair
public class FailureMessageSerializerTests
{

[Fact]
public void EncodeAllFailureMessages()
{
var failureMessages = new List<FailureMessage>() {
new InvalidRealmMessage(),
new TemporaryNodeFailureMessage(),
new PermanentNodeFailureMessage(),
new RequiredNodeFeatureMissingMessage()
};

var serializer = new FailureMessageSerializer();
// loop through all failure messages, serialize them, and then deserialize them and compare the result
foreach (var failureMessage in failureMessages)
{
var bufferWriter = new ArrayBufferWriter<byte>(256);
int bytesWritten = serializer.Serialize(failureMessage, bufferWriter, null);
var failureMessageBytes = bufferWriter.WrittenSpan.ToArray();

Assert.Equal(bytesWritten, failureMessageBytes.Length);

var failureMessaegSequence = new ReadOnlySequence<byte>(failureMessageBytes);
var failureMessageSequenceReader = new SequenceReader<byte>(failureMessaegSequence);

var failureMessageDeserialized = serializer.Deserialize(ref failureMessageSequenceReader, null);

Assert.Equal(failureMessage, failureMessageDeserialized);
}
}

}
}
37 changes: 37 additions & 0 deletions src/Lyn.Protocol.Tests/Bolt4/OnionRoutingPacketSerializerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Lyn.Protocol.Bolt4.Entities;
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace Lyn.Protocol.Tests.Bolt4
{
public class OnionRoutingPacketSerializerTests
{

[Fact]
public void SmallOnion_Serialization()
{
var onionToSerialize = new OnionRoutingPacket();
onionToSerialize.Version = 1;
onionToSerialize.EphemeralKey = Convert.FromHexString("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991");
onionToSerialize.PayloadData = Convert.FromHexString("0012345679abcdef");
onionToSerialize.Hmac = Convert.FromHexString("0000111122223333444455556666777788889999aaaabbbbccccddddeeee0000");

var bufferWriter = new ArrayBufferWriter<byte>(256);

var serializer = new OnionRoutingPacketSerializer();
int bytesWritten = serializer.Serialize(onionToSerialize, bufferWriter, null);
var onionBytes = bufferWriter.WrittenSpan.ToArray();

Assert.Equal(bytesWritten, onionBytes.Length);
// todo: figure out what to do about varint length here??
Assert.Equal(Convert.FromHexString("004a01032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e6686809910012345679abcdef0000111122223333444455556666777788889999aaaabbbbccccddddeeee0000"), onionBytes);
}

}
}
Loading