88 "testing"
99
1010 "github.com/btcsuite/btcd/btcec/v2"
11+ "github.com/stretchr/testify/require"
1112)
1213
1314// TestOnionFailure checks the ability of sender of payment to decode the
@@ -35,29 +36,40 @@ func TestOnionFailure(t *testing.T) {
3536 }
3637
3738 // Emulate creation of the obfuscator on node where error have occurred.
38- obfuscator := NewOnionErrorEncrypter (sharedSecrets [len (errorPath )- 1 ])
39+ obfuscator := NewOnionErrorEncrypter (
40+ sharedSecrets [len (errorPath )- 1 ], attributableErrorTestStructure ,
41+ )
3942
4043 // Emulate the situation when last hop creates the onion failure
4144 // message and send it back.
42- obfuscatedData := obfuscator .EncryptError (true , failureData )
45+ legacyData , attrData , err := obfuscator .EncryptError (
46+ true , failureData , nil , 0 ,
47+ )
48+ require .NoError (t , err )
4349
4450 // Emulate that failure message is backward obfuscated on every hop.
4551 for i := len (errorPath ) - 2 ; i >= 0 ; i -- {
4652 // Emulate creation of the obfuscator on forwarding node which
4753 // propagates the onion failure.
48- obfuscator = NewOnionErrorEncrypter (sharedSecrets [i ])
49- obfuscatedData = obfuscator .EncryptError (false , obfuscatedData )
54+ obfuscator = NewOnionErrorEncrypter (
55+ sharedSecrets [i ], attributableErrorTestStructure ,
56+ )
57+
58+ legacyData , attrData , err = obfuscator .EncryptError (
59+ false , legacyData , attrData , 1 ,
60+ )
61+ require .NoError (t , err )
5062 }
5163
5264 // Emulate creation of the deobfuscator on the receiving onion error side.
5365 deobfuscator := NewOnionErrorDecrypter (& Circuit {
5466 SessionKey : sessionKey ,
5567 PaymentPath : paymentPath ,
56- })
68+ }, attributableErrorTestStructure )
5769
5870 // Emulate that sender node receive the failure message and trying to
5971 // unwrap it, by applying obfuscation and checking the hmac.
60- decryptedError , err := deobfuscator .DecryptError (obfuscatedData )
72+ decryptedError , err := deobfuscator .DecryptError (legacyData , attrData )
6173 if err != nil {
6274 t .Fatalf ("unable to de-obfuscate the onion failure: %v" , err )
6375 }
@@ -191,11 +203,13 @@ func TestOnionFailureSpecVector(t *testing.T) {
191203 t .Fatalf ("unable to get specification session key: %v" , err )
192204 }
193205
194- var obfuscatedData []byte
195206 sharedSecrets , err := generateSharedSecrets (paymentPath , sessionKey )
196207 if err != nil {
197208 t .Fatalf ("Unexpected error while generating secrets: %v" , err )
198209 }
210+
211+ var legacyData , attrData []byte
212+
199213 for i , test := range onionErrorData {
200214 // Decode the shared secret and check that it matchs with
201215 // specification.
@@ -206,14 +220,15 @@ func TestOnionFailureSpecVector(t *testing.T) {
206220 }
207221 obfuscator := NewOnionErrorEncrypter (
208222 sharedSecrets [len (sharedSecrets )- 1 - i ],
223+ attributableErrorTestStructure ,
209224 )
210225
211226 var b bytes.Buffer
212227 if err := obfuscator .Encode (& b ); err != nil {
213228 t .Fatalf ("unable to encode obfuscator: %v" , err )
214229 }
215230
216- obfuscator2 := NewOnionErrorEncrypter (Hash256 {})
231+ obfuscator2 := NewOnionErrorEncrypter (Hash256 {}, attributableErrorTestStructure )
217232 obfuscatorReader := bytes .NewReader (b .Bytes ())
218233 if err := obfuscator2 .Decode (obfuscatorReader ); err != nil {
219234 t .Fatalf ("unable to decode obfuscator: %v" , err )
@@ -232,11 +247,13 @@ func TestOnionFailureSpecVector(t *testing.T) {
232247 if i == 0 {
233248 // Emulate the situation when last hop creates the onion failure
234249 // message and send it back.
235- obfuscatedData = obfuscator .EncryptError (true , failureData )
250+ legacyData , attrData , err = obfuscator .EncryptError (true , failureData , nil , 0 )
251+ require .NoError (t , err )
236252 } else {
237253 // Emulate the situation when forward node obfuscates
238254 // the onion failure.
239- obfuscatedData = obfuscator .EncryptError (false , obfuscatedData )
255+ legacyData , attrData , err = obfuscator .EncryptError (false , legacyData , attrData , 0 )
256+ require .NoError (t , err )
240257 }
241258
242259 // Decode the obfuscated data and check that it matches the
@@ -246,21 +263,22 @@ func TestOnionFailureSpecVector(t *testing.T) {
246263 t .Fatalf ("unable to decode spec obfusacted " +
247264 "data: %v" , err )
248265 }
249- if ! bytes .Equal (expectedEncryptErrordData , obfuscatedData ) {
266+ if ! bytes .Equal (expectedEncryptErrordData , legacyData ) {
250267 t .Fatalf ("obfuscated data not match spec: expected %x, " +
251268 "got %x" , expectedEncryptErrordData [:],
252- obfuscatedData [:])
269+ legacyData [:])
253270 }
254271 }
255272
256273 deobfuscator := NewOnionErrorDecrypter (& Circuit {
257274 SessionKey : sessionKey ,
258275 PaymentPath : paymentPath ,
259- })
276+ }, attributableErrorTestStructure ,
277+ )
260278
261279 // Emulate that sender node receives the failure message and trying to
262280 // unwrap it, by applying obfuscation and checking the hmac.
263- decryptedError , err := deobfuscator .DecryptError (obfuscatedData )
281+ decryptedError , err := deobfuscator .DecryptError (legacyData , attrData )
264282 if err != nil {
265283 t .Fatalf ("unable to de-obfuscate the onion failure: %v" , err )
266284 }
0 commit comments