@@ -181,17 +181,17 @@ impl IHandshakeState for ResponderAwaitingActOneState {
181181 // https://github.com/lightningnetwork/lightning-rfc/blob/master/08-transport.md#act-two (sender)
182182 fn next ( self , input : & [ u8 ] ) -> Result < ( Option < Act > , HandshakeState ) , String > {
183183 let mut act_one_builder = self . act_one_builder ;
184- let remaining = act_one_builder. fill ( input) ;
184+ let bytes_read = act_one_builder. fill ( input) ;
185185
186- // Any payload larger than ACT_ONE_LENGTH indicates a bad peer since initiator data
187- // is required to generate act3 (so it can't come before we transition)
188- if remaining . len ( ) != 0 {
186+ // Any payload that is not fully consumed by the builder indicates a bad peer since responder
187+ // data is required to generate act3 (so it can't come before we transition)
188+ if bytes_read < input . len ( ) {
189189 return Err ( "Act One too large" . to_string ( ) ) ;
190190 }
191191
192192 // In the event of a partial fill, stay in the same state and wait for more data
193193 if !act_one_builder. is_finished ( ) {
194- assert_eq ! ( remaining . len( ) , 0 ) ;
194+ assert_eq ! ( bytes_read , input . len( ) ) ;
195195 return Ok ( (
196196 None ,
197197 HandshakeState :: ResponderAwaitingActOne ( Self {
@@ -247,17 +247,17 @@ impl IHandshakeState for InitiatorAwaitingActTwoState {
247247 // https://github.com/lightningnetwork/lightning-rfc/blob/master/08-transport.md#act-three (sender)
248248 fn next ( self , input : & [ u8 ] ) -> Result < ( Option < Act > , HandshakeState ) , String > {
249249 let mut act_two_builder = self . act_two_builder ;
250- let remaining = act_two_builder. fill ( input) ;
250+ let bytes_read = act_two_builder. fill ( input) ;
251251
252- // Any payload larger than ACT_TWO_LENGTH indicates a bad peer since responder data
252+ // Any payload that is not fully consumed by the builder indicates a bad peer since responder data
253253 // is required to generate post-authentication messages (so it can't come before we transition)
254- if remaining . len ( ) != 0 {
254+ if bytes_read < input . len ( ) {
255255 return Err ( "Act Two too large" . to_string ( ) ) ;
256256 }
257257
258258 // In the event of a partial fill, stay in the same state and wait for more data
259259 if !act_two_builder. is_finished ( ) {
260- assert_eq ! ( remaining . len( ) , 0 ) ;
260+ assert_eq ! ( bytes_read , input . len( ) ) ;
261261 return Ok ( (
262262 None ,
263263 HandshakeState :: InitiatorAwaitingActTwo ( Self {
@@ -325,11 +325,11 @@ impl IHandshakeState for ResponderAwaitingActThreeState {
325325 // https://github.com/lightningnetwork/lightning-rfc/blob/master/08-transport.md#act-three (receiver)
326326 fn next ( self , input : & [ u8 ] ) -> Result < ( Option < Act > , HandshakeState ) , String > {
327327 let mut act_three_builder = self . act_three_builder ;
328- let remaining = act_three_builder. fill ( input) ;
328+ let bytes_read = act_three_builder. fill ( input) ;
329329
330330 // In the event of a partial fill, stay in the same state and wait for more data
331331 if !act_three_builder. is_finished ( ) {
332- assert_eq ! ( remaining . len( ) , 0 ) ;
332+ assert_eq ! ( bytes_read , input . len( ) ) ;
333333 return Ok ( (
334334 None ,
335335 HandshakeState :: ResponderAwaitingActThree ( Self {
@@ -392,7 +392,7 @@ impl IHandshakeState for ResponderAwaitingActThreeState {
392392
393393 // Any remaining data in the read buffer would be encrypted, so transfer ownership
394394 // to the Conduit for future use.
395- conduit. read ( remaining ) ;
395+ conduit. read ( & input [ bytes_read.. ] ) ;
396396
397397 Ok ( (
398398 None ,
0 commit comments