From 497e5c870c2f3d0e99669db2cc71eee114401c1d Mon Sep 17 00:00:00 2001 From: Liuhaai Date: Mon, 30 Sep 2024 10:04:46 -0700 Subject: [PATCH 1/2] recipient validation --- action/transfer.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/action/transfer.go b/action/transfer.go index 1d77eff5f6..b62427fa97 100644 --- a/action/transfer.go +++ b/action/transfer.go @@ -133,6 +133,10 @@ func (tsf *Transfer) SanityCheck() error { if tsf.Amount().Sign() < 0 { return ErrNegativeValue } + // check if recipient's address is valid + if _, err := address.FromString(tsf.recipient); err != nil { + return errors.Wrapf(err, "error when validating contract's address %s", tsf.recipient) + } return nil } From d5c576dd8f00406439f13163a414ef791d391e02 Mon Sep 17 00:00:00 2001 From: Liuhaai Date: Mon, 30 Sep 2024 16:14:53 -0700 Subject: [PATCH 2/2] add height --- action/protocol/generic_validator.go | 8 +++++++- action/transfer.go | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/action/protocol/generic_validator.go b/action/protocol/generic_validator.go index 57b749a8f1..6a72d8a8a9 100644 --- a/action/protocol/generic_validator.go +++ b/action/protocol/generic_validator.go @@ -59,7 +59,13 @@ func (v *GenericValidator) Validate(ctx context.Context, selp *action.SealedEnve return errors.New("failed to get address") } if err = selp.Envelope.SanityCheck(); err != nil { - return err + // Skip sanity check for TolerateLegacyAddress feature + if errors.Cause(err) != action.ErrAddress { + return err + } + if featureCtx, ok := GetFeatureCtx(ctx); ok && !featureCtx.TolerateLegacyAddress { + return err + } } // Reject action if nonce is too low if action.IsSystemAction(selp) { diff --git a/action/transfer.go b/action/transfer.go index b62427fa97..a40c756485 100644 --- a/action/transfer.go +++ b/action/transfer.go @@ -135,7 +135,7 @@ func (tsf *Transfer) SanityCheck() error { } // check if recipient's address is valid if _, err := address.FromString(tsf.recipient); err != nil { - return errors.Wrapf(err, "error when validating contract's address %s", tsf.recipient) + return errors.Wrapf(ErrAddress, "error when validating contract's address %s", tsf.recipient) } return nil }