@@ -89,6 +89,14 @@ func (c *CertificationService) Call(context view.Context) (interface{}, error) {
8989 return nil , errors .Errorf ("invalid certification request: no token IDs provided [%s]" , cr )
9090 }
9191
92+ if len (cr .IDs ) > MaxTokensPerRequest {
93+ return nil , errors .Errorf ("invalid certification request: too many token IDs (%d > %d) [%s]" , len (cr .IDs ), MaxTokensPerRequest , cr )
94+ }
95+
96+ if len (cr .Request ) > MaxRequestBytes {
97+ return nil , errors .Errorf ("invalid certification request: request payload too large (%d > %d bytes) [%s]" , len (cr .Request ), MaxRequestBytes , cr )
98+ }
99+
92100 logger .Debugf ("received certification request [%v]" , cr )
93101
94102 // 3. load token outputs
@@ -97,6 +105,13 @@ func (c *CertificationService) Call(context view.Context) (interface{}, error) {
97105 return nil , errors .WithMessagef (err , "failed getting tokens [%s:%s][%v]" , cr .Channel , cr .Namespace , cr .IDs )
98106 }
99107
108+ if len (tokenOutputs ) != len (cr .IDs ) {
109+ return nil , errors .Errorf (
110+ "token output count mismatch: backend returned %d outputs for %d IDs [%s]" ,
111+ len (tokenOutputs ), len (cr .IDs ), cr ,
112+ )
113+ }
114+
100115 // 4. certify token output
101116 logger .Debugf ("certify commitments for [%v]..." , cr .IDs )
102117 tms , err := token2 .GetManagementService (
@@ -160,7 +175,7 @@ type CertificationRequest struct {
160175}
161176
162177func (cr * CertificationRequest ) String () string {
163- return fmt .Sprintf ("CertificationRequest[%s,%s, %s][%v ]" , cr .Request , cr .Channel , cr .Namespace , cr .IDs )
178+ return fmt .Sprintf ("CertificationRequest[%s:%s: %s][ids=%d,req=%d bytes ]" , cr .Network , cr .Channel , cr .Namespace , len ( cr .IDs ), len ( cr . Request ) )
164179}
165180
166181type CertificationRequestView struct {
@@ -252,6 +267,13 @@ func (i *CertificationRequestView) Call(context view.Context) (interface{}, erro
252267 return nil , errors .WithMessagef (err , "failed verifying certifications of [%v] from [%s]" , i .ids , i .certifier )
253268 }
254269
270+ if len (processedCertifications ) != len (i .ids ) {
271+ return nil , errors .Errorf (
272+ "certification manager returned %d processed certifications for %d token IDs from [%s]" ,
273+ len (processedCertifications ), len (i .ids ), i .certifier ,
274+ )
275+ }
276+
255277 logger .Debugf ("certifications of [%v] from [%s] are valid" , i .ids , i .certifier )
256278
257279 // 5. return token certifications in the form of a map
0 commit comments