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

Commit

Permalink
refactor(type-alias): pruning go-ethereum type alias (backport #1329) (
Browse files Browse the repository at this point in the history
…#1331)

This is an automatic backport of pull request #1329 done by
[Mergify](https://mergify.com).


---


<details>
<summary>Mergify commands and options</summary>

<br />

More conditions and actions can be found in the
[documentation](https://docs.mergify.com/).

You can also trigger Mergify actions by commenting on this pull request:

- `@Mergifyio refresh` will re-evaluate the rules
- `@Mergifyio rebase` will rebase this PR on its base branch
- `@Mergifyio update` will merge the base branch into this PR
- `@Mergifyio backport <destination>` will backport this PR on
`<destination>` branch

Additionally, on Mergify [dashboard](https://dashboard.mergify.com) you
can:

- look at your merge queues
- generate the Mergify configuration with the config editor.

Finally, you can contact us on https://mergify.com
</details>

Co-authored-by: hunter-bera <[email protected]>
  • Loading branch information
mergify[bot] and hunter-bera authored Nov 27, 2023
1 parent b4bee83 commit 987d7b5
Show file tree
Hide file tree
Showing 135 changed files with 637 additions and 1,016 deletions.
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

0 comments on commit 987d7b5

Please sign in to comment.