@@ -135,6 +135,36 @@ func receiveRecipientPayment(t *testing.T, e *PaymentEngine, key *ecdsa.PrivateK
135135 return receive ()
136136}
137137
138+ func TestRecipientHMACExpirationCopies (t * testing.T ) {
139+ e , _ , key , _ := newRecipientTestEngine (t )
140+ info := issueRecipientParams (t , e , key )
141+ for _ , copies := range []string {"both" , "top-level" , "nested" } {
142+ t .Run (copies , func (t * testing.T ) {
143+ payment := wire.Payment {PayerAddress : crypto .PubkeyToAddress (key .PublicKey ).Bytes (), TicketParams : info .TicketParams , Expiration : info .TicketParams .Expiration , ExpectedPrice : info .Price }
144+ if copies == "top-level" {
145+ // go-livepeer omits the nested copy.
146+ payment .TicketParams .Expiration = wire.ExpirationParams {}
147+ } else if copies == "nested" {
148+ payment .Expiration = wire.ExpirationParams {}
149+ }
150+ payment , err := wire .DecodePayment (wire .EncodePayment (payment ))
151+ require .NoError (t , err )
152+ params , _ , err := e .authenticatePayment (payment , info .Auth )
153+ require .NoError (t , err )
154+ require .Equal (t , info .TicketParams .Expiration .CreationRound , params .ExpirationParams .CreationRound )
155+ require .Equal (t , info .TicketParams .Expiration .CreationRoundBlockHash , params .ExpirationParams .CreationRoundBlockHash .Bytes ())
156+ if copies != "nested" {
157+ payment .Expiration .CreationRound ++
158+ }
159+ if copies != "top-level" {
160+ payment .TicketParams .Expiration .CreationRound ++
161+ }
162+ _ , _ , err = e .authenticatePayment (payment , info .Auth )
163+ require .ErrorIs (t , err , ErrInvalidPayment , "the selected expiration must be bound by the HMAC" )
164+ })
165+ }
166+ }
167+
138168func TestRecipientHMACRejectsTamperedParameters (t * testing.T ) {
139169 e , _ , key , _ := newRecipientTestEngine (t )
140170 original := issueRecipientParams (t , e , key )
@@ -147,6 +177,22 @@ func TestRecipientHMACRejectsTamperedParameters(t *testing.T) {
147177 "expiry block" : func (p * wire.Payment , _ * wire.AuthToken ) { p .TicketParams .ExpirationBlock = big .NewInt (91 ).Bytes () },
148178 "price numerator" : func (p * wire.Payment , _ * wire.AuthToken ) { p .ExpectedPrice .PricePerUnit ++ },
149179 "price denominator" : func (p * wire.Payment , _ * wire.AuthToken ) { p .ExpectedPrice .UnitsPerPrice ++ },
180+ "no expiration" : func (p * wire.Payment , _ * wire.AuthToken ) {
181+ p .Expiration = wire.ExpirationParams {}
182+ p .TicketParams .Expiration = wire.ExpirationParams {}
183+ },
184+ "top round missing" : func (p * wire.Payment , _ * wire.AuthToken ) { p .Expiration .CreationRound = 0 },
185+ "top hash missing" : func (p * wire.Payment , _ * wire.AuthToken ) { p .Expiration .CreationRoundBlockHash = nil },
186+ "split expiration" : func (p * wire.Payment , _ * wire.AuthToken ) {
187+ p .Expiration .CreationRoundBlockHash = nil
188+ p .TicketParams .Expiration .CreationRound = 0
189+ },
190+ "round conflict" : func (p * wire.Payment , _ * wire.AuthToken ) { p .TicketParams .Expiration .CreationRound ++ },
191+ "hash conflict" : func (p * wire.Payment , _ * wire.AuthToken ) {
192+ p .TicketParams .Expiration .CreationRoundBlockHash = ethcommon .HexToHash ("0x4321" ).Bytes ()
193+ },
194+ "round omitted" : func (p * wire.Payment , _ * wire.AuthToken ) { p .TicketParams .Expiration .CreationRound = 0 },
195+ "hash omitted" : func (p * wire.Payment , _ * wire.AuthToken ) { p .TicketParams .Expiration .CreationRoundBlockHash = nil },
150196 "round" : func (p * wire.Payment , _ * wire.AuthToken ) {
151197 p .Expiration .CreationRound ++
152198 p .TicketParams .Expiration .CreationRound ++
0 commit comments