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

[action] add NewEthSigner() and pass Signer as input to rlpRawHash() and rlpSignedHash() #3967

Merged
merged 2 commits into from Nov 11, 2023

Conversation

dustinxie
Copy link
Member

Description

Small pre-requisite code change to make (#3965) easier.

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

codecov bot commented Nov 10, 2023

Codecov Report

Merging #3967 (ebe7f41) into master (e1f0636) will increase coverage by 0.80%.
Report is 98 commits behind head on master.
The diff coverage is 78.52%.

❗ Current head ebe7f41 differs from pull request most recent head 1c885fa. Consider uploading reports for the commit 1c885fa to get more accurate results

@@            Coverage Diff             @@
##           master    #3967      +/-   ##
==========================================
+ Coverage   75.38%   76.18%   +0.80%     
==========================================
  Files         303      329      +26     
  Lines       25923    28026    +2103     
==========================================
+ Hits        19541    21352    +1811     
- Misses       5360     5576     +216     
- Partials     1022     1098      +76     
Files Coverage Δ
action/candidate_register.go 90.00% <100.00%> (ø)
action/candidate_update.go 89.01% <100.00%> (+0.12%) ⬆️
action/claimreward.go 90.62% <100.00%> (-0.42%) ⬇️
action/depositreward.go 87.50% <100.00%> (-0.56%) ⬇️
action/protocol/context.go 67.66% <100.00%> (+0.49%) ⬆️
action/protocol/execution/evm/evmstatedbadapter.go 66.77% <ø> (ø)
action/protocol/execution/protocol.go 42.10% <100.00%> (ø)
action/protocol/rewarding/protocol.go 80.08% <ø> (+0.67%) ⬆️
action/protocol/rewarding/reward.go 90.07% <100.00%> (+0.60%) ⬆️
...tion/protocol/staking/candidate_buckets_indexer.go 89.31% <100.00%> (-0.47%) ⬇️
... and 70 more

... and 3 files with indirect coverage changes

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

return nil, err
}
} else {
signer = types.HomesteadSigner{}
Copy link
Member

Choose a reason for hiding this comment

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

why use HomesteadSigner?

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 for native tx (the signature format is same as Homestead)

@@ -134,8 +142,8 @@ func (sealed *SealedEnvelope) loadProto(pbAct *iotextypes.Action, evmID uint32)
if err != nil {
return err
}
encoding := pbAct.GetEncoding()
switch encoding {
sealed.encoding = pbAct.GetEncoding()
Copy link
Collaborator

Choose a reason for hiding this comment

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

even through errors are returned in line 151, 159, and 162, the encoding value of sealed has been modified. Unless we are not sure that the sealed.encoding won't be used any where else or the sealed instance won't be reused again.
Thus, we may want to introduce a local variable encoding here.

Copy link
Member Author

Choose a reason for hiding this comment

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

reverted

@@ -155,7 +156,8 @@ func TestBlockObjectMarshal(t *testing.T) {

t.Run("BlockWithDetail", func(t *testing.T) {
raw := types.NewContractCreation(2, unit.ConvertIotxToRau(1000), 21000, unit.ConvertIotxToRau(1), []byte{})
ethTx, err := action.RawTxToSignedTx(raw, 0, sevlp.Signature())
signer, _ := action.NewEthSigner(iotextypes.Encoding_ETHEREUM_RLP, 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

require.Nil(err)

return nil, err
}
} else {
signer = types.HomesteadSigner{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

when will this happen?

Copy link
Member Author

@dustinxie dustinxie Nov 10, 2023

Choose a reason for hiding this comment

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

this is for native tx (the signature format is same as Homestead)

"github.com/pkg/errors"
"golang.org/x/crypto/sha3"
)

func rlpRawHash(rawTx *types.Transaction, chainID uint32) (hash.Hash256, error) {
h := types.NewEIP155Signer(big.NewInt(int64(chainID))).Hash(rawTx)
func rlpRawHash(rawTx *types.Transaction, signer types.Signer) (hash.Hash256, error) {
Copy link
Member

Choose a reason for hiding this comment

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

signer and hasher are of different roles

Copy link
Member Author

@dustinxie dustinxie Nov 10, 2023

Choose a reason for hiding this comment

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

chatted offline, it's probably not worth the effort to define a new interface Hasher for this, the code calling signer.Hash() is quite clear

Comment on lines 131 to 132
signer = types.HomesteadSigner{}
}
Copy link
Member

Choose a reason for hiding this comment

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

revert this change in this pr and keep only refactoring part?

Copy link
Member Author

@dustinxie dustinxie Nov 10, 2023

Choose a reason for hiding this comment

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

this is for native tx (the signature format is same as Homestead)

Copy link

sonarcloud bot commented Nov 10, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@@ -88,5 +88,13 @@ func DecodeRawTx(rawData string, chainID uint32) (tx *types.Transaction, sig []b
// NewEthSigner returns the proper signer for Eth-compatible tx
func NewEthSigner(txType iotextypes.Encoding, chainID uint32) (types.Signer, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if the signer of iotex format could be returned, the name of this function should be updated to NewSigner

@dustinxie dustinxie merged commit 7e93d69 into master Nov 11, 2023
4 checks passed
@dustinxie dustinxie deleted the pass branch November 11, 2023 06:06
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.

None yet

4 participants