Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

refactor(type-alias): pruning go-ethereum type alias (backport #1329) #1331

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cosmos/config/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import (

"github.com/spf13/cast"

"github.com/berachain/polaris/eth/common"
"github.com/berachain/polaris/eth/common/hexutil"

servertypes "github.com/cosmos/cosmos-sdk/server/types"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
)

// baseTen is for the big.Int string conversation.
Expand Down
5 changes: 3 additions & 2 deletions cosmos/config/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import (
"time"

"github.com/berachain/polaris/cosmos/config/mocks"
"github.com/berachain/polaris/eth/common"
"github.com/berachain/polaris/eth/common/hexutil"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down
5 changes: 3 additions & 2 deletions cosmos/crypto/hd/algo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import (

ethsecp256k1 "github.com/berachain/polaris/cosmos/crypto/keys/ethsecp256k1"
"github.com/berachain/polaris/eth/accounts"
"github.com/berachain/polaris/eth/common"
crypto "github.com/berachain/polaris/eth/crypto"
"github.com/berachain/polaris/lib/utils"

"github.com/cosmos/cosmos-sdk/crypto/keyring"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down
3 changes: 2 additions & 1 deletion cosmos/crypto/keyring/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ import (
cryptocodec "github.com/berachain/polaris/cosmos/crypto/codec"
"github.com/berachain/polaris/cosmos/crypto/hd"
accounts "github.com/berachain/polaris/eth/accounts"
"github.com/berachain/polaris/eth/common"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/std"

"github.com/ethereum/go-ethereum/common"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down
16 changes: 8 additions & 8 deletions cosmos/crypto/keys/ethsecp256k1/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
"crypto/ecdsa"
"crypto/subtle"

"github.com/berachain/polaris/eth/crypto"

cmcrypto "github.com/cometbft/cometbft/crypto"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"

ethcrypto "github.com/ethereum/go-ethereum/crypto"
)

const (
Expand Down Expand Up @@ -66,7 +66,7 @@ func (privKey PrivKey) PubKey() cryptotypes.PubKey {
}

return &PubKey{
Key: crypto.CompressPubkey(&ecdsaPrivKey.PublicKey),
Key: ethcrypto.CompressPubkey(&ecdsaPrivKey.PublicKey),
}
}

Expand All @@ -84,19 +84,19 @@ func (privKey PrivKey) Type() string {
// GenPrivKey generates a new random private key. It returns an error upon
// failure.
func GenPrivKey() (*PrivKey, error) {
priv, err := crypto.GenerateEthKey()
priv, err := ethcrypto.GenerateKey()
if err != nil {
return nil, err
}

return &PrivKey{
Key: crypto.FromECDSA(priv),
Key: ethcrypto.FromECDSA(priv),
}, nil
}

// ToECDSA returns the ECDSA private key as a reference to ecdsa.PrivateKey type.
func (privKey PrivKey) ToECDSA() (*ecdsa.PrivateKey, error) {
return crypto.ToECDSA(privKey.Bytes())
return ethcrypto.ToECDSA(privKey.Bytes())
}

// ===============================================================================================
Expand All @@ -113,12 +113,12 @@ var _ cryptotypes.PubKey = &PubKey{}
// Address returns the address of the ECDSA public key.
// The function will return an empty address if the public key is invalid.
func (pubKey PubKey) Address() cmcrypto.Address {
key, err := crypto.DecompressPubkey(pubKey.Key)
key, err := ethcrypto.DecompressPubkey(pubKey.Key)
if err != nil {
return nil
}

return cmcrypto.Address(crypto.PubkeyToAddress(*key).Bytes())
return cmcrypto.Address(ethcrypto.PubkeyToAddress(*key).Bytes())
}

// Bytes returns the pubkey byte format.
Expand Down
4 changes: 2 additions & 2 deletions cosmos/crypto/keys/ethsecp256k1/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ package ethsecp256k1
import (
"testing"

ethcrypto "github.com/berachain/polaris/eth/crypto"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"

ethcrypto "github.com/ethereum/go-ethereum/crypto"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down
16 changes: 8 additions & 8 deletions cosmos/crypto/keys/ethsecp256k1/signature_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
package ethsecp256k1

import (
"github.com/berachain/polaris/eth/crypto"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
)

// Sign signs the provided message using the ECDSA private key. It returns an error if the
Expand All @@ -30,16 +30,16 @@ import (
// where the last byte contains the recovery ID.
func (privKey PrivKey) Sign(digestBz []byte) ([]byte, error) {
// We hash the provided input since EthSign expects a 32byte hash.
if len(digestBz) != crypto.DigestLength {
digestBz = crypto.Keccak256(digestBz)
if len(digestBz) != ethcrypto.DigestLength {
digestBz = ethcrypto.Keccak256(digestBz)
}

key, err := privKey.ToECDSA()
if err != nil {
return nil, err
}

return crypto.EthSign(digestBz, key)
return ethcrypto.Sign(digestBz, key)
}

// VerifySignature verifies that the ECDSA public key created a given signature over
Expand All @@ -49,16 +49,16 @@ func (pubKey PubKey) VerifySignature(msg, sig []byte) bool {
// does not hash messages, we have to accept an unhashed message and hash it.
// NOTE: this function will not work correctly if a msg of length 32 is provided, that is actually
// the hash of the message that was signed.
if len(msg) != crypto.DigestLength {
msg = crypto.Keccak256(msg)
if len(msg) != ethcrypto.DigestLength {
msg = ethcrypto.Keccak256(msg)
}

// The signature length must be correct.
if len(sig) == crypto.SignatureLength {
if len(sig) == ethcrypto.SignatureLength {
// remove recovery ID (V) if contained in the signature
sig = sig[:len(sig)-1]
}

// The signature needs to be in [R || S] format when provided to `VerifySignature`.
return crypto.VerifySignature(pubKey.Key, msg, sig)
return ethcrypto.VerifySignature(pubKey.Key, msg, sig)
}
8 changes: 4 additions & 4 deletions cosmos/crypto/keys/ethsecp256k1/signature_cgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package ethsecp256k1
import (
"crypto/ecdsa"

"github.com/berachain/polaris/eth/crypto"
ethcrypto "github.com/ethereum/go-ethereum/crypto"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -44,9 +44,9 @@ var _ = Describe("PrivKey_PubKey", func() {
It("validates signing bytes", func() {
msg := []byte("hello world")
// for the eth case, we have to manually hash in the test.
sigHash := crypto.Keccak256(msg)
sigHash := ethcrypto.Keccak256(msg)

expectedSig, err := crypto.EthSign(sigHash, ecdsaPrivKey)
expectedSig, err := ethcrypto.Sign(sigHash, ecdsaPrivKey)
Expect(err).ToNot(HaveOccurred())

sig, err := privKey.Sign(msg)
Expand All @@ -56,7 +56,7 @@ var _ = Describe("PrivKey_PubKey", func() {

It("validates signature", func() {
msg := []byte("hello world")
sigHash := crypto.Keccak256(msg)
sigHash := ethcrypto.Keccak256(msg)
sig, err := privKey.Sign(sigHash)
Expect(err).ToNot(HaveOccurred())

Expand Down
2 changes: 1 addition & 1 deletion cosmos/lib/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package lib
import (
"cosmossdk.io/core/address"

"github.com/berachain/polaris/eth/common"
"github.com/ethereum/go-ethereum/common"
)

/* -------------------------------------------------------------------------- */
Expand Down
3 changes: 2 additions & 1 deletion cosmos/lib/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ package lib_test

import (
cosmlib "github.com/berachain/polaris/cosmos/lib"
"github.com/berachain/polaris/eth/common"

addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/ethereum/go-ethereum/common"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down
3 changes: 2 additions & 1 deletion cosmos/lib/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ import (
"github.com/berachain/polaris/contracts/bindings/cosmos/precompile/governance"
"github.com/berachain/polaris/contracts/bindings/cosmos/precompile/staking"
"github.com/berachain/polaris/cosmos/precompile"
"github.com/berachain/polaris/eth/common"
"github.com/berachain/polaris/lib/utils"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/ethereum/go-ethereum/common"
)

/**
Expand Down
5 changes: 3 additions & 2 deletions cosmos/lib/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import (

"github.com/berachain/polaris/cosmos/x/evm/plugins/precompile"
"github.com/berachain/polaris/eth/accounts/abi"
"github.com/berachain/polaris/eth/common"
ethprecompile "github.com/berachain/polaris/eth/core/precompile"
"github.com/berachain/polaris/eth/core/vm"
"github.com/berachain/polaris/lib/utils"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
)

// TODO: Add these functions to the EVM object itself to allow enforcing calls into
Expand Down
3 changes: 2 additions & 1 deletion cosmos/precompile/bank/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ import (
"github.com/berachain/polaris/contracts/bindings/cosmos/lib"
bankgenerated "github.com/berachain/polaris/contracts/bindings/cosmos/precompile/bank"
cosmlib "github.com/berachain/polaris/cosmos/lib"
"github.com/berachain/polaris/eth/common"
ethprecompile "github.com/berachain/polaris/eth/core/precompile"
"github.com/berachain/polaris/eth/core/vm"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

"github.com/ethereum/go-ethereum/common"
)

// Contract is the precompile contract for the bank module.
Expand Down
3 changes: 2 additions & 1 deletion cosmos/precompile/bank/bank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
testutils "github.com/berachain/polaris/cosmos/testutil"
pclog "github.com/berachain/polaris/cosmos/x/evm/plugins/precompile/log"
evmtypes "github.com/berachain/polaris/cosmos/x/evm/types"
"github.com/berachain/polaris/eth/common"
ethprecompile "github.com/berachain/polaris/eth/core/precompile"
"github.com/berachain/polaris/eth/core/vm"
"github.com/berachain/polaris/lib/utils"
Expand All @@ -45,6 +44,8 @@ import (
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

"github.com/ethereum/go-ethereum/common"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down
7 changes: 4 additions & 3 deletions cosmos/precompile/distribution/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ import (
generated "github.com/berachain/polaris/contracts/bindings/cosmos/precompile/distribution"
cosmlib "github.com/berachain/polaris/cosmos/lib"
"github.com/berachain/polaris/cosmos/precompile/staking"
"github.com/berachain/polaris/eth/common"
ethprecompile "github.com/berachain/polaris/eth/core/precompile"
"github.com/berachain/polaris/eth/core/vm"
pvm "github.com/berachain/polaris/eth/core/vm"

sdk "github.com/cosmos/cosmos-sdk/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"

"github.com/ethereum/go-ethereum/common"
)

// Contract is the precompile contract for the distribution module.
Expand Down Expand Up @@ -80,7 +81,7 @@ func (c *Contract) SetWithdrawAddress(
withdrawAddress common.Address,
) (bool, error) {
delAddr, err := cosmlib.StringFromEthAddress(
c.addressCodec, vm.UnwrapPolarContext(ctx).MsgSender(),
c.addressCodec, pvm.UnwrapPolarContext(ctx).MsgSender(),
)
if err != nil {
return false, err
Expand Down
3 changes: 2 additions & 1 deletion cosmos/precompile/governance/governance.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
generated "github.com/berachain/polaris/contracts/bindings/cosmos/precompile/governance"
cosmlib "github.com/berachain/polaris/cosmos/lib"
"github.com/berachain/polaris/cosmos/x/evm/plugins/precompile/log"
"github.com/berachain/polaris/eth/common"
ethprecompile "github.com/berachain/polaris/eth/core/precompile"
"github.com/berachain/polaris/eth/core/vm"

Expand All @@ -40,6 +39,8 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"

"github.com/ethereum/go-ethereum/common"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion cosmos/precompile/governance/governance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
cbindings "github.com/berachain/polaris/contracts/bindings/cosmos/lib"
generated "github.com/berachain/polaris/contracts/bindings/cosmos/precompile/governance"
testutils "github.com/berachain/polaris/cosmos/testutil"
"github.com/berachain/polaris/eth/common"
ethprecompile "github.com/berachain/polaris/eth/core/precompile"
"github.com/berachain/polaris/eth/core/vm"
"github.com/berachain/polaris/lib/utils"
Expand All @@ -49,6 +48,8 @@ import (
governancetypes "github.com/cosmos/cosmos-sdk/x/gov/types"
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"

"github.com/ethereum/go-ethereum/common"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down
3 changes: 2 additions & 1 deletion cosmos/precompile/governance/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
storetypes "cosmossdk.io/store/types"

testutils "github.com/berachain/polaris/cosmos/testutil"
"github.com/berachain/polaris/eth/common"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/runtime"
Expand All @@ -47,6 +46,8 @@ import (
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/ethereum/go-ethereum/common"

//nolint:stylecheck,revive // Ginkgo is the testing framework.
. "github.com/onsi/ginkgo/v2"
)
Expand Down
Loading