From b14cfeb65438880e62f727aa690c323be28bc064 Mon Sep 17 00:00:00 2001 From: dustinxie Date: Thu, 10 Oct 2024 23:54:35 -0700 Subject: [PATCH] [action] check special address --- action/action.go | 24 ++++++++++++++++++++++++ action/const.go | 1 + action/protocol/context.go | 2 ++ action/protocol/generic_validator.go | 3 +++ e2etest/blobtx_test.go | 10 ++++++++++ 5 files changed, 40 insertions(+) diff --git a/action/action.go b/action/action.go index 6e35bb8421..81ed48ed8b 100644 --- a/action/action.go +++ b/action/action.go @@ -132,3 +132,27 @@ func CheckTransferAddress(act Action) error { } return nil } + +func CheckSpecialAddress(act Action) bool { + switch act := act.(type) { + case *Transfer: + return address.IsAddrV1Special(act.recipient) + case *Execution: + return address.IsAddrV1Special(act.contract) + case *CandidateRegister: + return address.IsAddrV1Special(act.rewardAddress.String()) || + address.IsAddrV1Special(act.operatorAddress.String()) || + (act.ownerAddress != nil && address.IsAddrV1Special(act.ownerAddress.String())) + case *CandidateUpdate: + return (act.rewardAddress != nil && address.IsAddrV1Special(act.rewardAddress.String())) || + (act.operatorAddress != nil && address.IsAddrV1Special(act.operatorAddress.String())) + case *CandidateTransferOwnership: + return address.IsAddrV1Special(act.newOwner.String()) + case *TransferStake: + return address.IsAddrV1Special(act.voterAddress.String()) + case *ClaimFromRewardingFund: + return act.address != nil && address.IsAddrV1Special(act.address.String()) + default: + return false + } +} diff --git a/action/const.go b/action/const.go index 4742216401..9f92a45902 100644 --- a/action/const.go +++ b/action/const.go @@ -44,6 +44,7 @@ var ( ErrGasTipOverFeeCap = errors.New("tip cap is greater than fee cap") ErrMissRequiredField = errors.New("missing required field") ErrValueVeryHigh = errors.New("value is very high") + ErrSpecialAddress = errors.New("special address not allowed") ) // LoadErrorDescription loads corresponding description related to the error diff --git a/action/protocol/context.go b/action/protocol/context.go index 6b8d3cd350..3831bf7ec7 100644 --- a/action/protocol/context.go +++ b/action/protocol/context.go @@ -152,6 +152,7 @@ type ( VerifyNotContainerBeforeRun bool ValidateActionWithState bool CheckStakingDurationUpperLimit bool + DisallowSpecialAddressInTx bool FixRevertSnapshot bool } @@ -316,6 +317,7 @@ func WithFeatureCtx(ctx context.Context) context.Context { VerifyNotContainerBeforeRun: g.IsVanuatu(height), ValidateActionWithState: g.IsVanuatu(height), CheckStakingDurationUpperLimit: g.IsVanuatu(height), + DisallowSpecialAddressInTx: g.IsVanuatu(height), FixRevertSnapshot: g.IsVanuatu(height), }, ) diff --git a/action/protocol/generic_validator.go b/action/protocol/generic_validator.go index 4e0ccece39..4f66bcd10a 100644 --- a/action/protocol/generic_validator.go +++ b/action/protocol/generic_validator.go @@ -85,6 +85,9 @@ func (v *GenericValidator) Validate(ctx context.Context, selp *action.SealedEnve return action.ErrNonceTooLow } } + if featureCtx.DisallowSpecialAddressInTx && action.CheckSpecialAddress(selp.Action()) { + return action.ErrSpecialAddress + } if !featureCtx.EnableAccessListTx && selp.TxType() == action.AccessListTxType { return errors.Wrap(action.ErrInvalidAct, "access list tx is not enabled") } diff --git a/e2etest/blobtx_test.go b/e2etest/blobtx_test.go index e366deb24c..dccad2a4b2 100644 --- a/e2etest/blobtx_test.go +++ b/e2etest/blobtx_test.go @@ -197,6 +197,16 @@ func TestBlobTx(t *testing.T) { r.Equal(act.BlobTxSidecar(), blobs[0].BlobSidecar) }}}, }, + { + name: "reject special address", + act: &actionWithTime{ + mustNoErr(action.Sign(action.NewEnvelope(newBlobTx(test.nonceMgr[(sender)], nil, []common.Hash{{}}), action.NewTransfer(big.NewInt(1), address.StakingBucketPoolAddr, nil)), senderSK)), + time.Now(), + }, + expect: []actionExpect{&functionExpect{func(test *e2etest, act *action.SealedEnvelope, receipt *action.Receipt, err error) { + r.ErrorIs(err, action.ErrSpecialAddress) + }}}, + }, { name: "6 blobs per block at most", acts: []*actionWithTime{