Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rewarding] move claim address check to LoadProto() and SanityCheck() #4304

Merged
merged 2 commits into from
Jun 20, 2024

Conversation

dustinxie
Copy link
Member

@dustinxie dustinxie commented Jun 17, 2024

Description

#4277 added a claimTo field to receive claim reward, so other EOA can help claim reward on another's behalf.

move the address check from inside protocol.Handle to the action's LoadProto() and SanityCheck(), which is consistent with other action's behavior

Fixes #(issue)

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • Code refactor or improvement
  • [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [] make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

Copy link

sonarcloud bot commented Jun 17, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
5.9% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@CoderZhi
Copy link
Collaborator

#4277 added a new field address to action ClaimFromRewardingFund, and the purpose is to help other accounts to claim rewards (not claiming rewards to some other accounts).
claimTo is just a parameter name, which may be confusing. a better naming for this parameter is claimFrom.

if err != nil {
log.L().Debug("Invalid claim to address", zap.Error(err))
return p.settleUserAction(ctx, sm, uint64(iotextypes.ReceiptStatus_Failure), si, nil)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this address check can (and should) be done before Handle() in the action's LoadProto() and SanityCheck(), this is consistent with other actions like candidate register

@dustinxie dustinxie changed the title [rewarding] must claim from action caller [rewarding] move claim address check to LoadProto() and SanityCheck() Jun 18, 2024
@dustinxie dustinxie force-pushed the enter branch 4 times, most recently from 6da2e90 to 041292a Compare June 18, 2024 22:56
Copy link
Collaborator

@CoderZhi CoderZhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, except the comment below

if claimTo == "" {
claimTo = protocol.MustGetActionCtx(ctx).Caller.String()
addr := protocol.MustGetActionCtx(ctx).Caller
if protocol.MustGetFeatureCtx(ctx).AddClaimRewardAddress && act.Address() != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we reject an action if !protocol.MustGetFeatureCtx(ctx).AddClaimRewardAddress && act.Address() != nil?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can check it when validating

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@@ -217,8 +232,16 @@ func NewClaimFromRewardingFundFromABIBinary(data []byte) (*ClaimFromRewardingFun
if ac.data, ok = paramsMap["data"].([]byte); !ok {
return nil, errDecodeFailure
}
if ac.address, ok = paramsMap["address"].(string); !ok {
var s string
if s, ok = paramsMap["address"].(string); !ok {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should keep backword compatibility, allowing without address param

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a 2nd commit to keep both v1 and v2 ABI

"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to keep the current (v1) ABI for backward compatibility

"4d26d0736ebd9e69bd5994f3730b05a2d48c810b3bb54818be65d02004cf4ff4",
"04830579b50e01602c2015c24e72fbc48bca1cca1e601b119ca73abe2e0b5bd61fcb7874567e091030d6b644f927445d80e00b3f9ca0c566c21c30615e94c343da",
"8d38efe45794d7fceea10b2262c23c12245959db",
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is test with v1 ABI, fixed and restored
the original #4277 shouldn't have broken this

Copy link
Collaborator

@CoderZhi CoderZhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverse order if doesn't hurt, because data is useless for now

return nil, err
}
return append(_claimRewardingMethodV1.ID, data...), nil
}
var addr string
if c.address != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 249 to 259
var (
act *ClaimFromRewardingFund
err error
)
if act, err = newClaimFromRewardingFundFromABIv2(data); err == nil {
return act, nil
}
if err != errWrongMethodSig {
// data is v2-encoded, but got error when decoding
return nil, err
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    if len(data) >= 4 {
        switch {
        case bytes.Equal(_claimRewardingMethodV2.ID[:], data[:4]):
              ....
        case bytes.Equal(_claimRewardingMethodV1.ID[:], data[:4]):
              ....
        }
    }
    return nil, errDecodeFailure

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@dustinxie dustinxie merged commit f001407 into iotexproject:master Jun 20, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants