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] use correct signer for web3 action #3937

Closed
wants to merge 1 commit into from
Closed

Conversation

dustinxie
Copy link
Member

Description

as title.

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)

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

@dustinxie dustinxie marked this pull request as draft October 11, 2023 15:44
@sonarcloud
Copy link

sonarcloud bot commented Oct 11, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

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

No Coverage information No Coverage information
20.5% 20.5% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@codecov
Copy link

codecov bot commented Oct 11, 2023

Codecov Report

Merging #3937 (8ad343c) into master (e1f0636) will increase coverage by 0.71%.
Report is 86 commits behind head on master.
The diff coverage is 77.24%.

❗ Current head 8ad343c differs from pull request most recent head 52bacd6. Consider uploading reports for the commit 52bacd6 to get more accurate results

@@            Coverage Diff             @@
##           master    #3937      +/-   ##
==========================================
+ Coverage   75.38%   76.09%   +0.71%     
==========================================
  Files         303      328      +25     
  Lines       25923    27968    +2045     
==========================================
+ Hits        19541    21283    +1742     
- Misses       5360     5588     +228     
- Partials     1022     1097      +75     
Files Coverage Δ
action/action.go 82.85% <100.00%> (+0.50%) ⬆️
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 70.14% <100.00%> (+2.97%) ⬆️
action/protocol/execution/evm/evmstatedbadapter.go 66.77% <ø> (ø)
action/protocol/execution/protocol.go 42.10% <100.00%> (ø)
action/protocol/generic_validator.go 92.59% <100.00%> (+0.28%) ⬆️
action/protocol/rewarding/reward.go 90.07% <100.00%> (+0.60%) ⬆️
... and 72 more

... and 3 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Comment on lines +18 to +22
if useLondontSigner {
signer = types.NewLondonSigner(big.NewInt(int64(chainID)))
} else {
signer = types.NewEIP155Signer(big.NewInt(int64(chainID)))
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

create a util function to generate signer

@@ -13,13 +13,19 @@ import (
"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, chainID uint32, useLondontSigner bool) (hash.Hash256, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

signer types.Signer

return hash.BytesToHash256(h[:]), nil
}

func rlpSignedHash(tx *types.Transaction, chainID uint32, sig []byte) (hash.Hash256, error) {
signedTx, err := reconstructSignedRlpTxFromSig(tx, chainID, sig)
func rlpSignedHash(tx *types.Transaction, chainID uint32, sig []byte, useLondonSigner bool) (hash.Hash256, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

signer types.Signer

@@ -30,7 +36,7 @@ func rlpSignedHash(tx *types.Transaction, chainID uint32, sig []byte) (hash.Hash
return hash.BytesToHash256(h.Sum(nil)), nil
}

func reconstructSignedRlpTxFromSig(rawTx *types.Transaction, chainID uint32, sig []byte) (*types.Transaction, error) {
func reconstructSignedRlpTxFromSig(rawTx *types.Transaction, chainID uint32, sig []byte, useLondonSigner bool) (*types.Transaction, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

signer types.Signer

signature []byte
srcAddress address.Address
hash hash.Hash256
useLondonSigner bool
Copy link
Collaborator

Choose a reason for hiding this comment

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

delete

@@ -39,7 +45,7 @@ func (sealed *SealedEnvelope) envelopeHash() (hash.Hash256, error) {
if err != nil {
return hash.ZeroHash256, err
}
return rlpRawHash(tx, sealed.evmNetworkID)
return rlpRawHash(tx, sealed.evmNetworkID, sealed.useLondonSigner)
Copy link
Collaborator

Choose a reason for hiding this comment

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

signer

@@ -71,7 +77,7 @@ func (sealed *SealedEnvelope) calcHash() (hash.Hash256, error) {
if err != nil {
return hash.ZeroHash256, err
}
return rlpSignedHash(tx, sealed.evmNetworkID, sealed.Signature())
return rlpSignedHash(tx, sealed.evmNetworkID, sealed.Signature(), sealed.useLondonSigner)
Copy link
Collaborator

Choose a reason for hiding this comment

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

signer

@@ -146,7 +152,7 @@ func (sealed *SealedEnvelope) loadProto(pbAct *iotextypes.Action, evmID uint32)
if err != nil {
return err
}
if _, err = rlpSignedHash(tx, evmID, pbAct.GetSignature()); err != nil {
if _, err = rlpSignedHash(tx, evmID, pbAct.GetSignature(), sealed.useLondonSigner); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

signer

@@ -30,7 +30,7 @@ func SignedTransfer(recipientAddr string, senderPriKey crypto.PrivateKey, nonce
SetGasPrice(gasPrice).
SetGasLimit(gasLimit).
SetAction(transfer).Build()
selp, err := Sign(elp, senderPriKey)
selp, err := Sign(elp, senderPriKey, false)
Copy link
Collaborator

Choose a reason for hiding this comment

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

signer = nil

@dustinxie dustinxie closed this Nov 6, 2023
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.

2 participants