Skip to content

Commit

Permalink
chore: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Jun 21, 2024
1 parent b2e32e8 commit 5fb1bf1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
5 changes: 2 additions & 3 deletions app/submodule/eth/eth_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/builtin"
builtintypes "github.com/filecoin-project/go-state-types/builtin"
"github.com/filecoin-project/go-state-types/builtin/v10/eam"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/go-state-types/exitcode"
Expand Down Expand Up @@ -549,12 +548,12 @@ func ethTxFromNativeMessage(ctx context.Context, msg *types.Message, ca v1.IChai
// Then we try to see if it's "special". If we fail, we ignore the error and keep treating
// it as a native message. Unfortunately, the user is free to send garbage that may not
// properly decode.
if msg.Method == builtintypes.MethodsEVM.InvokeContract {
if msg.Method == builtin.MethodsEVM.InvokeContract {
// try to decode it as a contract invocation first.
if inp, err := decodePayload(msg.Params, codec); err == nil {
ethTx.Input = []byte(inp)
}
} else if msg.To == builtin.EthereumAddressManagerActorAddr && msg.Method == builtintypes.MethodsEAM.CreateExternal {
} else if msg.To == builtin.EthereumAddressManagerActorAddr && msg.Method == builtin.MethodsEAM.CreateExternal {
// Then, try to decode it as a contract deployment from an EOA.
if inp, err := decodePayload(msg.Params, codec); err == nil {
ethTx.Input = []byte(inp)
Expand Down
8 changes: 4 additions & 4 deletions venus-shared/actors/types/eth_1559_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (tx *Eth1559TxArgs) InitialiseSignature(sig typescrypto.Signature) error {
}

func (tx *Eth1559TxArgs) packTxFields() ([]interface{}, error) {
chainId, err := formatInt(tx.ChainID)
chainID, err := formatInt(tx.ChainID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -202,7 +202,7 @@ func (tx *Eth1559TxArgs) packTxFields() ([]interface{}, error) {
}

res := []interface{}{
chainId,
chainID,
nonce,
maxPriorityFeePerGas,
maxFeePerGas,
Expand Down Expand Up @@ -233,7 +233,7 @@ func parseEip1559Tx(data []byte) (*Eth1559TxArgs, error) {
return nil, xerrors.Errorf("not an EIP-1559 transaction: should have 12 elements in the rlp list")
}

chainId, err := parseInt(decoded[0])
chainID, err := parseInt(decoded[0])
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -301,7 +301,7 @@ func parseEip1559Tx(data []byte) (*Eth1559TxArgs, error) {
}

args := Eth1559TxArgs{
ChainID: chainId,
ChainID: chainID,
Nonce: nonce,
To: to,
MaxPriorityFeePerGas: maxPriorityFeePerGas,
Expand Down
22 changes: 11 additions & 11 deletions venus-shared/actors/types/eth_legacy_155_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (tx *EthLegacy155TxArgs) ToRawTxBytesSigned() ([]byte, error) {
return nil, err
}

packed1 = packed1[:len(packed1)-3] // remove chainId, r and s as they are only used for signature verification
packed1 = packed1[:len(packed1)-3] // remove chainID, r and s as they are only used for signature verification

packed2, err := packSigFields(tx.legacyTx.V, tx.legacyTx.R, tx.legacyTx.S)
if err != nil {
Expand Down Expand Up @@ -160,8 +160,8 @@ func (tx *EthLegacy155TxArgs) ToVerifiableSignature(sig []byte) ([]byte, error)
}

// See https://github.com/ethereum/go-ethereum/blob/86a1f0c39494c8f5caddf6bd9fbddd4bdfa944fd/core/types/transaction_signing.go#L424
chainIdMul := big.Mul(big.NewIntUnsigned(uint64(Eip155ChainID)), big.NewInt(2))
vValue = big.Sub(vValue, chainIdMul)
chainIDMul := big.Mul(big.NewIntUnsigned(uint64(Eip155ChainID)), big.NewInt(2))
vValue = big.Sub(vValue, chainIDMul)
vValue = big.Sub(vValue, big8)

// Adjust 'v' value for compatibility with new transactions: 27 -> 0, 28 -> 1
Expand Down Expand Up @@ -238,8 +238,8 @@ func (tx *EthLegacy155TxArgs) packTxFields() ([]interface{}, error) {
return nil, err
}

chainIdBigInt := big.NewIntUnsigned(uint64(Eip155ChainID))
chainId, err := formatBigInt(chainIdBigInt)
chainIDBigInt := big.NewIntUnsigned(uint64(Eip155ChainID))
chainID, err := formatBigInt(chainIDBigInt)
if err != nil {
return nil, err
}
Expand All @@ -261,16 +261,16 @@ func (tx *EthLegacy155TxArgs) packTxFields() ([]interface{}, error) {
formatEthAddr(tx.legacyTx.To),
value,
tx.legacyTx.Input,
chainId,
chainID,
r, s,
}
return res, nil
}

func validateEIP155ChainId(v big.Int) error {
chainId := deriveEIP155ChainId(v)
if !chainId.Equals(big.NewIntUnsigned(uint64(Eip155ChainID))) {
return fmt.Errorf("invalid chain id, expected %d, got %s", Eip155ChainID, chainId.String())
chainID := deriveEIP155ChainId(v)
if !chainID.Equals(big.NewIntUnsigned(uint64(Eip155ChainID))) {
return fmt.Errorf("invalid chain id, expected %d, got %s", Eip155ChainID, chainID.String())
}
return nil
}
Expand All @@ -290,8 +290,8 @@ func deriveEIP155ChainId(v big.Int) big.Int {
}

func calcEIP155TxSignatureLen(chain uint64, v int) int {
chainId := big.NewIntUnsigned(chain)
vVal := big.Add(big.Mul(chainId, big.NewInt(2)), big.NewInt(int64(v)))
chainID := big.NewIntUnsigned(chain)
vVal := big.Add(big.Mul(chainID, big.NewInt(2)), big.NewInt(int64(v)))
vLen := len(vVal.Int.Bytes())

// EthLegacyHomesteadTxSignatureLen includes the 1 byte legacy tx marker prefix and also 1 byte for the V value.
Expand Down
14 changes: 7 additions & 7 deletions venus-shared/actors/types/eth_legacy_155_transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,39 +107,39 @@ func TestDeriveEIP155ChainId(t *testing.T) {
tests := []struct {
name string
v big.Int
expectedChainId big.Int
expectedChainID big.Int
}{
{
name: "V equals 27",
v: big.NewInt(27),
expectedChainId: big.NewInt(0),
expectedChainID: big.NewInt(0),
},
{
name: "V equals 28",
v: big.NewInt(28),
expectedChainId: big.NewInt(0),
expectedChainID: big.NewInt(0),
},
{
name: "V small chain ID",
v: big.NewInt(37), // (37 - 35) / 2 = 1
expectedChainId: big.NewInt(1),
expectedChainID: big.NewInt(1),
},
{
name: "V large chain ID",
v: big.NewInt(1001), // (1001 - 35) / 2 = 483
expectedChainId: big.NewInt(483),
expectedChainID: big.NewInt(483),
},
{
name: "V very large chain ID",
v: big.NewInt(1 << 20), // (1048576 - 35) / 2 = 524770
expectedChainId: big.NewInt(524270),
expectedChainID: big.NewInt(524270),
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := deriveEIP155ChainId(tt.v)
require.True(t, result.Equals(tt.expectedChainId), "Expected %s, got %s for V=%s", tt.expectedChainId.String(), result.String(), tt.v.String())
require.True(t, result.Equals(tt.expectedChainID), "Expected %s, got %s for V=%s", tt.expectedChainID.String(), result.String(), tt.v.String())
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions venus-shared/actors/types/eth_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ func parseLegacyTx(data []byte) (EthTransaction, error) {
S: s,
}

chainId := deriveEIP155ChainId(v)
if chainId.Equals(big.NewInt(0)) {
chainID := deriveEIP155ChainId(v)
if chainID.Equals(big.NewInt(0)) {
// This is a legacy Homestead transaction
if !v.Equals(big.NewInt(27)) && !v.Equals(big.NewInt(28)) {
return nil, fmt.Errorf("legacy homestead transactions only support 27 or 28 for v, got %d", v.Uint64())
Expand Down

0 comments on commit 5fb1bf1

Please sign in to comment.