Skip to content

Commit 3b52023

Browse files
committed
rename fat to attributable [squash]
1 parent e1d305a commit 3b52023

5 files changed

+109
-103
lines changed

fat_error_crypto.go renamed to attributable_error_crypto.go

+21-18
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ package sphinx
33
import (
44
"crypto/hmac"
55
"crypto/sha256"
6-
"encoding/binary"
76
)
87

9-
var byteOrder = binary.BigEndian
10-
11-
type FatErrorStructure struct {
12-
MaxHops int
13-
MaxPayloadSize int
8+
type AttributableErrorStructure struct {
9+
HopCount int
10+
FixedPayloadLen int
1411
}
1512

16-
type fatErrorBase struct {
13+
type attributableErrorBase struct {
1714
maxHops int
1815
totalHmacs int
1916
allHmacsLen int
@@ -23,34 +20,40 @@ type fatErrorBase struct {
2320
payloadDataLen int
2421
}
2522

26-
func newFatErrorBase(structure *FatErrorStructure) fatErrorBase {
23+
func newAttributableErrorBase(
24+
structure *AttributableErrorStructure) attributableErrorBase {
25+
2726
var (
28-
payloadDataLen = structure.MaxPayloadSize
27+
payloadDataLen = structure.FixedPayloadLen
2928

30-
// payloadLen is the size of the per-node payload. It consists of a 1-byte
31-
// payload type followed by the payload data.
29+
// payloadLen is the size of the per-node payload. It consists of a
30+
// 1-byte payload type followed by the payload data.
3231
payloadLen = 1 + payloadDataLen
3332

34-
totalHmacs = (structure.MaxHops * (structure.MaxHops + 1)) / 2
33+
totalHmacs = (structure.HopCount *
34+
(structure.HopCount + 1)) / 2
35+
3536
allHmacsLen = totalHmacs * sha256.Size
36-
allPayloadsLen = payloadLen * structure.MaxHops
37+
allPayloadsLen = payloadLen * structure.HopCount
3738
hmacsAndPayloadsLen = allHmacsLen + allPayloadsLen
3839
)
3940

40-
return fatErrorBase{
41+
return attributableErrorBase{
4142
totalHmacs: totalHmacs,
4243
allHmacsLen: allHmacsLen,
4344
hmacsAndPayloadsLen: hmacsAndPayloadsLen,
4445
allPayloadsLen: allPayloadsLen,
45-
maxHops: structure.MaxHops,
46+
maxHops: structure.HopCount,
4647
payloadLen: payloadLen,
4748
payloadDataLen: payloadDataLen,
4849
}
4950
}
5051

5152
// getMsgComponents splits a complete failure message into its components
5253
// without re-allocating memory.
53-
func (o *fatErrorBase) getMsgComponents(data []byte) ([]byte, []byte, []byte) {
54+
func (o *attributableErrorBase) getMsgComponents(data []byte) ([]byte, []byte,
55+
[]byte) {
56+
5457
payloads := data[len(data)-o.hmacsAndPayloadsLen : len(data)-o.allHmacsLen]
5558
hmacs := data[len(data)-o.allHmacsLen:]
5659
message := data[:len(data)-o.hmacsAndPayloadsLen]
@@ -61,8 +64,8 @@ func (o *fatErrorBase) getMsgComponents(data []byte) ([]byte, []byte, []byte) {
6164
// calculateHmac calculates an hmac given a shared secret and a presumed
6265
// position in the path. Position is expressed as the distance to the error
6366
// source. The error source itself is at position 0.
64-
func (o *fatErrorBase) calculateHmac(sharedSecret Hash256, position int,
65-
message, payloads, hmacs []byte) []byte {
67+
func (o *attributableErrorBase) calculateHmac(sharedSecret Hash256,
68+
position int, message, payloads, hmacs []byte) []byte {
6669

6770
umKey := generateKey("um", &sharedSecret)
6871
hash := hmac.New(sha256.New, umKey[:])

fat_error_crypto_test.go renamed to attributable_error_crypto_test.go

+38-35
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import (
1111
"github.com/stretchr/testify/require"
1212
)
1313

14-
var fatErrorTestStructure = &FatErrorStructure{
15-
MaxHops: 27,
16-
MaxPayloadSize: 8,
14+
var attributableErrorTestStructure = &AttributableErrorStructure{
15+
HopCount: 27,
16+
FixedPayloadLen: 8,
1717
}
1818

19-
// TestFatOnionFailure checks the ability of sender of payment to decode the
20-
// obfuscated onion error.
21-
func TestFatOnionFailure(t *testing.T) {
19+
// TestAttributableOnionFailure checks the ability of sender of payment to
20+
// decode the obfuscated onion error.
21+
func TestAttributableOnionFailure(t *testing.T) {
2222
t.Parallel()
2323

2424
// Create numHops random sphinx paymentPath.
@@ -33,8 +33,8 @@ func TestFatOnionFailure(t *testing.T) {
3333
require.NoError(t, err)
3434

3535
// Emulate creation of the obfuscator on node where error have occurred.
36-
obfuscator := NewOnionFatErrorEncrypter(
37-
sharedSecrets[len(errorPath)-1], fatErrorTestStructure,
36+
obfuscator := NewOnionAttributableErrorEncrypter(
37+
sharedSecrets[len(errorPath)-1], attributableErrorTestStructure,
3838
)
3939

4040
// Emulate the situation when last hop creates the onion failure
@@ -50,8 +50,8 @@ func TestFatOnionFailure(t *testing.T) {
5050
for i := len(errorPath) - 2; i >= 0; i-- {
5151
// Emulate creation of the obfuscator on forwarding node which
5252
// propagates the onion failure.
53-
obfuscator = NewOnionFatErrorEncrypter(
54-
sharedSecrets[i], fatErrorTestStructure,
53+
obfuscator = NewOnionAttributableErrorEncrypter(
54+
sharedSecrets[i], attributableErrorTestStructure,
5555
)
5656

5757
intermediatePayload := [8]byte{byte(100 + i)}
@@ -64,10 +64,10 @@ func TestFatOnionFailure(t *testing.T) {
6464
}
6565

6666
// Emulate creation of the deobfuscator on the receiving onion error side.
67-
deobfuscator := NewOnionFatErrorDecrypter(&Circuit{
67+
deobfuscator := NewOnionAttributableErrorDecrypter(&Circuit{
6868
SessionKey: sessionKey,
6969
PaymentPath: paymentPath,
70-
}, fatErrorTestStructure)
70+
}, attributableErrorTestStructure)
7171

7272
// Emulate that sender node receive the failure message and trying to
7373
// unwrap it, by applying obfuscation and checking the hmac.
@@ -103,22 +103,24 @@ func TestOnionFailureCorruption(t *testing.T) {
103103
require.NoError(t, err)
104104

105105
// Emulate creation of the obfuscator on node where error have occurred.
106-
obfuscator := NewOnionFatErrorEncrypter(
107-
sharedSecrets[len(errorPath)-1], fatErrorTestStructure,
106+
obfuscator := NewOnionAttributableErrorEncrypter(
107+
sharedSecrets[len(errorPath)-1], attributableErrorTestStructure,
108108
)
109109

110110
// Emulate the situation when last hop creates the onion failure
111111
// message and send it back.
112112
payload := [8]byte{1}
113-
obfuscatedData, err := obfuscator.EncryptError(true, failureData, payload[:])
113+
obfuscatedData, err := obfuscator.EncryptError(
114+
true, failureData, payload[:],
115+
)
114116
require.NoError(t, err)
115117

116118
// Emulate that failure message is backward obfuscated on every hop.
117119
for i := len(errorPath) - 2; i >= 0; i-- {
118120
// Emulate creation of the obfuscator on forwarding node which
119121
// propagates the onion failure.
120-
obfuscator = NewOnionFatErrorEncrypter(
121-
sharedSecrets[i], fatErrorTestStructure,
122+
obfuscator = NewOnionAttributableErrorEncrypter(
123+
sharedSecrets[i], attributableErrorTestStructure,
122124
)
123125

124126
payload := [8]byte{byte(100 + i)}
@@ -135,10 +137,10 @@ func TestOnionFailureCorruption(t *testing.T) {
135137
}
136138

137139
// Emulate creation of the deobfuscator on the receiving onion error side.
138-
deobfuscator := NewOnionFatErrorDecrypter(&Circuit{
140+
deobfuscator := NewOnionAttributableErrorDecrypter(&Circuit{
139141
SessionKey: sessionKey,
140142
PaymentPath: paymentPath,
141-
}, fatErrorTestStructure)
143+
}, attributableErrorTestStructure)
142144

143145
// Emulate that sender node receive the failure message and trying to
144146
// unwrap it, by applying obfuscation and checking the hmac.
@@ -163,10 +165,10 @@ type specVector struct {
163165

164166
// TestOnionFailureSpecVector checks that onion error corresponds to the
165167
// specification.
166-
func TestFatOnionFailureSpecVector(t *testing.T) {
168+
func TestAttributableFailureSpecVector(t *testing.T) {
167169
t.Parallel()
168170

169-
vectorBytes, err := os.ReadFile("testdata/fat_error.json")
171+
vectorBytes, err := os.ReadFile("testdata/attributable_error.json")
170172
require.NoError(t, err)
171173

172174
var vector specVector
@@ -191,8 +193,9 @@ func TestFatOnionFailureSpecVector(t *testing.T) {
191193
expectedSharedSecret, err := hex.DecodeString(test.SharedSecret)
192194
require.NoError(t, err)
193195

194-
obfuscator := NewOnionFatErrorEncrypter(
195-
sharedSecrets[len(sharedSecrets)-1-i], fatErrorTestStructure,
196+
obfuscator := NewOnionAttributableErrorEncrypter(
197+
sharedSecrets[len(sharedSecrets)-1-i],
198+
attributableErrorTestStructure,
196199
)
197200

198201
require.Equal(t, expectedSharedSecret, obfuscator.sharedSecret[:])
@@ -222,10 +225,10 @@ func TestFatOnionFailureSpecVector(t *testing.T) {
222225
require.Equal(t, expectedEncryptErrorData, obfuscatedData)
223226
}
224227

225-
deobfuscator := NewOnionFatErrorDecrypter(&Circuit{
228+
deobfuscator := NewOnionAttributableErrorDecrypter(&Circuit{
226229
SessionKey: sessionKey,
227230
PaymentPath: paymentPath,
228-
}, fatErrorTestStructure)
231+
}, attributableErrorTestStructure)
229232

230233
// Emulate that sender node receives the failure message and trying to
231234
// unwrap it, by applying obfuscation and checking the hmac.
@@ -244,19 +247,19 @@ func TestFatOnionFailureSpecVector(t *testing.T) {
244247
require.Equal(t, len(paymentPath), decryptedError.SenderIdx)
245248
}
246249

247-
// TestFatOnionFailureZeroesMessage checks that a garbage failure is attributed
248-
// to the first hop.
249-
func TestFatOnionFailureZeroesMessage(t *testing.T) {
250+
// TestAttributableOnionFailureZeroesMessage checks that a garbage failure is
251+
// attributed to the first hop.
252+
func TestAttributableOnionFailureZeroesMessage(t *testing.T) {
250253
t.Parallel()
251254

252255
// Create numHops random sphinx paymentPath.
253256
sessionKey, paymentPath := generateRandomPath(t)
254257

255258
// Emulate creation of the deobfuscator on the receiving onion error side.
256-
deobfuscator := NewOnionFatErrorDecrypter(&Circuit{
259+
deobfuscator := NewOnionAttributableErrorDecrypter(&Circuit{
257260
SessionKey: sessionKey,
258261
PaymentPath: paymentPath,
259-
}, fatErrorTestStructure)
262+
}, attributableErrorTestStructure)
260263

261264
// Emulate that sender node receive the failure message and trying to
262265
// unwrap it, by applying obfuscation and checking the hmac.
@@ -268,19 +271,19 @@ func TestFatOnionFailureZeroesMessage(t *testing.T) {
268271
require.Equal(t, 1, decryptedError.SenderIdx)
269272
}
270273

271-
// TestFatOnionFailureShortMessage checks that too short failure is attributed
272-
// to the first hop.
273-
func TestFatOnionFailureShortMessage(t *testing.T) {
274+
// TestAttributableOnionFailureShortMessage checks that too short failure is
275+
// attributed to the first hop.
276+
func TestAttributableOnionFailureShortMessage(t *testing.T) {
274277
t.Parallel()
275278

276279
// Create numHops random sphinx paymentPath.
277280
sessionKey, paymentPath := generateRandomPath(t)
278281

279282
// Emulate creation of the deobfuscator on the receiving onion error side.
280-
deobfuscator := NewOnionFatErrorDecrypter(&Circuit{
283+
deobfuscator := NewOnionAttributableErrorDecrypter(&Circuit{
281284
SessionKey: sessionKey,
282285
PaymentPath: paymentPath,
283-
}, fatErrorTestStructure)
286+
}, attributableErrorTestStructure)
284287

285288
// Emulate that sender node receive the failure message and trying to
286289
// unwrap it, by applying obfuscation and checking the hmac.

0 commit comments

Comments
 (0)