@@ -97,37 +97,61 @@ func hopFromPayload(p *Payload) (*route.Hop, uint64) {
9797
9898// FuzzPayloadFinal fuzzes final hop payloads, providing the additional context
9999// that the hop should be final (which is usually obtained by the structure
100- // of the sphinx packet).
101- func FuzzPayloadFinal (f * testing.F ) {
102- fuzzPayload (f , true )
100+ // of the sphinx packet) for the case where a blinding point was provided in
101+ // UpdateAddHtlc.
102+ func FuzzPayloadFinalBlinding (f * testing.F ) {
103+ fuzzPayload (f , true , true )
104+ }
105+
106+ // FuzzPayloadFinal fuzzes final hop payloads, providing the additional context
107+ // that the hop should be final (which is usually obtained by the structure
108+ // of the sphinx packet) for the case where no blinding point was provided in
109+ // UpdateAddHtlc.
110+ func FuzzPayloadFinalNoBlinding (f * testing.F ) {
111+ fuzzPayload (f , true , false )
103112}
104113
105114// FuzzPayloadIntermediate fuzzes intermediate hop payloads, providing the
106115// additional context that a hop should be intermediate (which is usually
107- // obtained by the structure of the sphinx packet).
108- func FuzzPayloadIntermediate (f * testing.F ) {
109- fuzzPayload (f , false )
116+ // obtained by the structure of the sphinx packet) for the case where a
117+ // blinding point was provided in UpdateAddHtlc.
118+ func FuzzPayloadIntermediateBlinding (f * testing.F ) {
119+ fuzzPayload (f , false , true )
110120}
111121
112- func fuzzPayload (f * testing.F , finalPayload bool ) {
122+ // FuzzPayloadIntermediate fuzzes intermediate hop payloads, providing the
123+ // additional context that a hop should be intermediate (which is usually
124+ // obtained by the structure of the sphinx packet) for the case where no
125+ // blinding point was provided in UpdateAddHtlc.
126+ func FuzzPayloadIntermediateNoBlinding (f * testing.F ) {
127+ fuzzPayload (f , false , false )
128+ }
129+
130+ func fuzzPayload (f * testing.F , finalPayload , updateAddBlinded bool ) {
113131 f .Fuzz (func (t * testing.T , data []byte ) {
114132 if len (data ) > sphinx .MaxPayloadSize {
115133 return
116134 }
117135
118136 r := bytes .NewReader (data )
119137
120- payload1 , _ , err := NewPayloadFromReader ( r , finalPayload )
138+ payload1 , parsed , err := ParseTLVPayload ( r )
121139 if err != nil {
122140 return
123141 }
124142
143+ if err = ValidateParsedPayloadTypes (
144+ parsed , finalPayload , updateAddBlinded ,
145+ ); err != nil {
146+ return
147+ }
148+
125149 var b bytes.Buffer
126150 hop , nextChanID := hopFromPayload (payload1 )
127151 err = hop .PackHopPayload (& b , nextChanID , finalPayload )
128152 switch {
129153 // PackHopPayload refuses to encode an AMP record
130- // without an MPP record. However, NewPayloadFromReader
154+ // without an MPP record. However, ValidateParsedPayloadTypes
131155 // does allow decoding an AMP record without an MPP
132156 // record, since validation is done at a later stage. Do
133157 // not report a bug for this case.
@@ -136,17 +160,22 @@ func fuzzPayload(f *testing.F, finalPayload bool) {
136160
137161 // PackHopPayload will not encode regular payloads or final
138162 // hops in blinded routes that do not have an amount or expiry
139- // TLV set. However, NewPayloadFromReader will allow creation
140- // of payloads where these TLVs are present, but they have
141- // zero values because validation is done at a later stage.
163+ // TLV set. However, ValidateParsedPayloadTypes will allow
164+ // creation of payloads where these TLVs are present, but they
165+ // have zero values because validation is done at a later stage.
142166 case errors .Is (err , route .ErrMissingField ):
143167 return
144168
145169 default :
146170 require .NoError (t , err )
147171 }
148172
149- payload2 , _ , err := NewPayloadFromReader (& b , finalPayload )
173+ payload2 , parsed , err := ParseTLVPayload (& b )
174+ require .NoError (t , err )
175+
176+ err = ValidateParsedPayloadTypes (
177+ parsed , finalPayload , updateAddBlinded ,
178+ )
150179 require .NoError (t , err )
151180
152181 require .Equal (t , payload1 , payload2 )
0 commit comments