@@ -309,44 +309,50 @@ func (ap *actPool) GetActionByHash(hash hash.Hash32B) (*iproto.ActionPb, error)
309
309
func (ap * actPool ) validateTsf (tsf * action.Transfer ) error {
310
310
// Reject coinbase transfer
311
311
if tsf .IsCoinbase {
312
- logger .Error ().Msg ("Error when validating transfer" )
312
+ logger .Error ().Msg ("Error when validating whether transfer is coinbase " )
313
313
return errors .Wrapf (ErrTransfer , "coinbase transfer" )
314
314
}
315
315
// Reject oversized transfer
316
316
if tsf .TotalSize () > TransferSizeLimit {
317
- logger .Error ().Msg ("Error when validating transfer" )
317
+ logger .Error ().Msg ("Error when validating transfer's data size " )
318
318
return errors .Wrapf (ErrActPool , "oversized data" )
319
319
}
320
320
// Reject transfer of negative amount
321
321
if tsf .Amount .Sign () < 0 {
322
- logger .Error ().Msg ("Error when validating transfer" )
322
+ logger .Error ().Msg ("Error when validating transfer's amount " )
323
323
return errors .Wrapf (ErrBalance , "negative value" )
324
324
}
325
+
325
326
// check if sender's address is valid
326
- _ , err := iotxaddress .GetPubkeyHash (tsf .Sender )
327
- if err != nil {
328
- return errors .Wrap (err , "error when getting the pubkey hash" )
327
+ if _ , err := iotxaddress .GetPubkeyHash (tsf .Sender ); err != nil {
328
+ logger .Error ().Msg ("Error when validating transfer sender's address" )
329
+ return errors .Wrapf (err , "error when validating sender's address %s" , tsf .Sender )
330
+ }
331
+ // check if recipient's address is valid
332
+ if _ , err := iotxaddress .GetPubkeyHash (tsf .Recipient ); err != nil {
333
+ logger .Error ().Msg ("Error when validating transfer recipient's address" )
334
+ return errors .Wrapf (err , "error when validating recipient's address %s" , tsf .Recipient )
329
335
}
330
336
331
337
sender , err := iotxaddress .GetAddressByPubkey (iotxaddress .IsTestnet , iotxaddress .ChainID , tsf .SenderPublicKey )
332
338
if err != nil {
333
- logger .Error ().Err (err ).Msg ("Error when validating transfer" )
339
+ logger .Error ().Err (err ).Msg ("Error when validating transfer sender's public key " )
334
340
return errors .Wrapf (err , "invalid address" )
335
341
}
336
342
// Verify transfer using sender's public key
337
343
if err := tsf .Verify (sender ); err != nil {
338
- logger .Error ().Err (err ).Msg ("Error when validating transfer" )
344
+ logger .Error ().Err (err ).Msg ("Error when validating transfer's signature " )
339
345
return errors .Wrapf (err , "failed to verify Transfer signature" )
340
346
}
341
347
// Reject transfer if nonce is too low
342
348
confirmedNonce , err := ap .bc .Nonce (tsf .Sender )
343
349
if err != nil {
344
- logger .Error ().Err (err ).Msg ("Error when validating transfer" )
350
+ logger .Error ().Err (err ).Msg ("Error when validating transfer's nonce " )
345
351
return errors .Wrapf (err , "invalid nonce value" )
346
352
}
347
353
pendingNonce := confirmedNonce + 1
348
354
if pendingNonce > tsf .Nonce {
349
- logger .Error ().Msg ("Error when validating transfer" )
355
+ logger .Error ().Msg ("Error when validating transfer's nonce " )
350
356
return errors .Wrapf (ErrNonce , "nonce too low" )
351
357
}
352
358
return nil
@@ -365,33 +371,42 @@ func (ap *actPool) validateExecution(exec *action.Execution) error {
365
371
}
366
372
// Reject execution of negative amount
367
373
if exec .Amount .Sign () < 0 {
368
- logger .Error ().Msg ("Error when validating execution amount" )
374
+ logger .Error ().Msg ("Error when validating execution's amount" )
369
375
return errors .Wrapf (ErrBalance , "negative value" )
370
376
}
377
+
371
378
// check if executor's address is valid
372
379
if _ , err := iotxaddress .GetPubkeyHash (exec .Executor ); err != nil {
373
- return errors .Wrap (err , "error when getting the pubkey hash" )
380
+ logger .Error ().Msg ("Error when validating executor's address" )
381
+ return errors .Wrapf (err , "error when validating executor's address %s" , exec .Executor )
382
+ }
383
+ // check if contract's address is valid
384
+ if exec .Contract != action .EmptyAddress {
385
+ if _ , err := iotxaddress .GetPubkeyHash (exec .Contract ); err != nil {
386
+ logger .Error ().Msg ("Error when validating contract's address" )
387
+ return errors .Wrapf (err , "error when validating contract's address %s" , exec .Contract )
388
+ }
374
389
}
375
390
376
391
executor , err := iotxaddress .GetAddressByPubkey (iotxaddress .IsTestnet , iotxaddress .ChainID , exec .ExecutorPubKey )
377
392
if err != nil {
378
- logger .Error ().Err (err ).Msg ("Error when validating execution " )
393
+ logger .Error ().Err (err ).Msg ("Error when validating executor's public key " )
379
394
return errors .Wrapf (err , "invalid address" )
380
395
}
381
396
// Verify transfer using executor's public key
382
397
if err := exec .Verify (executor ); err != nil {
383
- logger .Error ().Err (err ).Msg ("Error when validating execution" )
398
+ logger .Error ().Err (err ).Msg ("Error when validating execution's signature " )
384
399
return errors .Wrapf (err , "failed to verify Execution signature" )
385
400
}
386
401
// Reject transfer if nonce is too low
387
402
confirmedNonce , err := ap .bc .Nonce (executor .RawAddress )
388
403
if err != nil {
389
- logger .Error ().Err (err ).Msg ("Error when validating execution" )
404
+ logger .Error ().Err (err ).Msg ("Error when validating execution's nonce " )
390
405
return errors .Wrapf (err , "invalid nonce value" )
391
406
}
392
407
pendingNonce := confirmedNonce + 1
393
408
if pendingNonce > exec .Nonce {
394
- logger .Error ().Msg ("Error when validating execution" )
409
+ logger .Error ().Msg ("Error when validating execution's nonce " )
395
410
return errors .Wrapf (ErrNonce , "nonce too low" )
396
411
}
397
412
return nil
@@ -401,57 +416,66 @@ func (ap *actPool) validateExecution(exec *action.Execution) error {
401
416
func (ap * actPool ) validateVote (vote * action.Vote ) error {
402
417
// Reject oversized vote
403
418
if vote .TotalSize () > VoteSizeLimit {
404
- logger .Error ().Msg ("Error when validating vote" )
419
+ logger .Error ().Msg ("Error when validating vote's data size " )
405
420
return errors .Wrapf (ErrActPool , "oversized data" )
406
421
}
407
422
selfPublicKey , err := vote .SelfPublicKey ()
408
423
if err != nil {
409
- return err
424
+ logger .Error ().Err (err ).Msg ("Error when validating voter's public key" )
425
+ return errors .Wrapf (err , "failed to get voter's public key" )
426
+ }
427
+
428
+ // check if voter's address is valid
429
+ if _ , err := iotxaddress .GetPubkeyHash (vote .GetVote ().VoterAddress ); err != nil {
430
+ logger .Error ().Err (err ).Msg ("Error when validating voter's address" )
431
+ return errors .Wrapf (err , "error when validating voter's address %s" , vote .GetVote ().VoterAddress )
432
+ }
433
+ // check if votee's address is valid
434
+ if vote .GetVote ().VoteeAddress != action .EmptyAddress {
435
+ if _ , err := iotxaddress .GetPubkeyHash (vote .GetVote ().VoteeAddress ); err != nil {
436
+ logger .Error ().Err (err ).Msg ("Error when validating votee's address" )
437
+ return errors .Wrapf (err , "error when validating votee's address %s" , vote .GetVote ().VoteeAddress )
438
+ }
410
439
}
440
+
411
441
voter , err := iotxaddress .GetAddressByPubkey (iotxaddress .IsTestnet , iotxaddress .ChainID , selfPublicKey )
412
442
if err != nil {
413
- logger .Error ().Err (err ).Msg ("Error when validating vote " )
414
- return errors .Wrapf (err , "invalid voter address" )
443
+ logger .Error ().Err (err ).Msg ("Error when validating voter's public key " )
444
+ return errors .Wrapf (err , "invalid address" )
415
445
}
416
446
// Verify vote using voter's public key
417
447
if err := vote .Verify (voter ); err != nil {
418
- logger .Error ().Err (err ).Msg ("Error when validating vote" )
448
+ logger .Error ().Err (err ).Msg ("Error when validating vote's signature " )
419
449
return errors .Wrapf (err , "failed to verify Vote signature" )
420
450
}
421
451
422
452
// Reject vote if nonce is too low
423
453
confirmedNonce , err := ap .bc .Nonce (voter .RawAddress )
424
454
if err != nil {
425
- logger .Error ().Err (err ).Msg ("Error when validating vote" )
455
+ logger .Error ().Err (err ).Msg ("Error when validating vote's nonce " )
426
456
return errors .Wrapf (err , "invalid nonce value" )
427
457
}
428
458
pbVote := vote .GetVote ()
429
459
if pbVote .VoteeAddress != "" {
430
460
// Reject vote if votee is not a candidate
431
- if err != nil {
432
- logger .Error ().
433
- Err (err ).Hex ("voter" , pbVote .SelfPubkey [:]).Str ("votee" , pbVote .VoteeAddress ).
434
- Msg ("Error when validating vote" )
435
- return errors .Wrapf (err , "invalid votee public key: %s" , pbVote .VoteeAddress )
436
- }
437
461
voteeState , err := ap .bc .StateByAddr (pbVote .VoteeAddress )
438
462
if err != nil {
439
463
logger .Error ().Err (err ).
440
464
Hex ("voter" , pbVote .SelfPubkey [:]).Str ("votee" , pbVote .VoteeAddress ).
441
- Msg ("Error when validating vote " )
465
+ Msg ("Error when validating votee's state " )
442
466
return errors .Wrapf (err , "cannot find votee's state: %s" , pbVote .VoteeAddress )
443
467
}
444
468
if voter .RawAddress != pbVote .VoteeAddress && ! voteeState .IsCandidate {
445
469
logger .Error ().Err (ErrVotee ).
446
470
Hex ("voter" , pbVote .SelfPubkey [:]).Str ("votee" , pbVote .VoteeAddress ).
447
- Msg ("Error when validating vote " )
471
+ Msg ("Error when validating votee's state " )
448
472
return errors .Wrapf (ErrVotee , "votee has not self-nominated: %s" , pbVote .VoteeAddress )
449
473
}
450
474
}
451
475
452
476
pendingNonce := confirmedNonce + 1
453
477
if pendingNonce > vote .Nonce {
454
- logger .Error ().Msg ("Error when validating vote" )
478
+ logger .Error ().Msg ("Error when validating vote's nonce " )
455
479
return errors .Wrapf (ErrNonce , "nonce too low" )
456
480
}
457
481
return nil
0 commit comments