Skip to content

Upgrade go-ethereum to 1.13 #116

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

Draft
wants to merge 6 commits into
base: feat/geth-1.13
Choose a base branch
from

Conversation

vladjdk
Copy link
Member

@vladjdk vladjdk commented Apr 29, 2025

requires: cosmos/go-ethereum#2
closes: #115

@vladjdk vladjdk changed the title Bump geth to v1.13 Upgrade go-ethereum to 1.13 Apr 29, 2025
// use Cosmos-SDK fork to enable Ledger functionality
github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.50.13-0.20250319183239-53dea340efc7
// use Cosmos geth fork
github.com/ethereum/go-ethereum => github.com/cosmos/go-ethereum v1.10.26-evmos-rc4.0.20250402013457-cf9d288f0147
github.com/ethereum/go-ethereum => github.com/TacBuild/go-ethereum v0.0.0-20250428082551-b4f5a8f8420a
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -137,6 +137,12 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
# Enable precompiles in EVM params
jq '.app_state["evm"]["params"]["active_static_precompiles"]=["0x0000000000000000000000000000000000000100","0x0000000000000000000000000000000000000400","0x0000000000000000000000000000000000000800","0x0000000000000000000000000000000000000801","0x0000000000000000000000000000000000000802","0x0000000000000000000000000000000000000803","0x0000000000000000000000000000000000000804","0x0000000000000000000000000000000000000805"]' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"

# Set EVM config
jq '.app_state["evm"]["params"]["chain_config"]["chain_id"]="262144"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use the $CHAINID variable here?


// check that caller has enough balance to cover asset transfer for **topmost** call
// NOTE: here the gas consumed is from the context with the infinite gas meter
if msg.Value().Sign() > 0 && !evm.Context.CanTransfer(stateDB, msg.From(), msg.Value()) {
if msg.Value.Sign() > 0 && !evm.Context.CanTransfer(stateDB, msg.From, uint256.MustFromBig(msg.Value)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it actually safe to panic here? Seems like we want to return an error on failure.

@@ -75,7 +76,7 @@ func (p *Precompile) Transfer(
// NOTE: This ensures that the changes in the bank keeper are correctly mirrored to the EVM stateDB
// when calling the precompile from another smart contract.
// This prevents the stateDB from overwriting the changed balance in the bank keeper when committing the EVM state.
amt := msg.Token.Amount.BigInt()
amt := uint256.MustFromBig(msg.Token.Amount.BigInt())
Copy link
Contributor

Choose a reason for hiding this comment

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

Also not sure if we should panic here ever.

@@ -242,7 +243,7 @@ func (p *Precompile) Delegate(

// Need to scale the amount to 18 decimals for the EVM balance change entry
scaledAmt := evmtypes.ConvertAmountTo18DecimalsBigInt(msg.Amount.Amount.BigInt())
p.SetBalanceChangeEntries(cmn.NewBalanceChangeEntry(delHexAddr, scaledAmt, cmn.Sub))
p.SetBalanceChangeEntries(cmn.NewBalanceChangeEntry(delHexAddr, uint256.MustFromBig(scaledAmt), cmn.Sub))
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

cosmosAddr := sdk.AccAddress(addr.Bytes())

// Get the balance via bank wrapper to convert it to 18 decimals if needed.
coin := k.bankWrapper.GetBalance(ctx, cosmosAddr, types.GetEVMCoinDenom())

return coin.Amount.BigInt()
return uint256.MustFromBig(coin.Amount.BigInt())
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

ret, _, leftoverGas, vmErr = evm.Create(sender, msg.Data(), leftoverGas, msg.Value())
stateDB.SetNonce(sender.Address(), msg.Nonce()+1)
stateDB.SetNonce(sender.Address(), msg.Nonce)
ret, _, leftoverGas, vmErr = evm.Create(sender, msg.Data, leftoverGas, uint256.MustFromBig(msg.Value))
Copy link
Contributor

Choose a reason for hiding this comment

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

MustFromBig--same as above

// DefaultAllowUnprotectedTxs rejects all unprotected txs (i.e false)
DefaultAllowUnprotectedTxs = false
// DefaultStaticPrecompiles defines the default active precompiles.
DefaultStaticPrecompiles []string
// DefaultExtraEIPs defines the default extra EIPs to be included.
// On v15, EIP 3855 was enabled
DefaultExtraEIPs = []int64{
3855, // NOTE: we suggest to enable EIP-3855 on all chains to support new Solidity versions >=v0.8.20
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this now default enabled so we don't need to add it to extra eips?

Comment on lines +21 to +25
DefaultEVMDenom = "atest"
// DefaultEVMChainID is the default value for the evm chain ID
DefaultEVMChainID = "cosmos_262144-1"
// DefaultEVMDecimals is the default value for the evm denom decimal precision
DefaultEVMDecimals uint64 = 18
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this stuff is probably best specified via the chain itself--like evmd could use these variables, but other chains should just get these as defaults.

@dongsam
Copy link
Member

dongsam commented Apr 30, 2025

Hi, I’d like to ask a few questions regarding the upgrade to go-ethereum 1.15.x after this PR:

  1. It seems that EIP-4844: Shard Blob Transactions is not applied in this v1.13 PR which added on Cancun(Dencun) hardfork with geth v1.13. Was this exclusion intentional, and is it expected to remain excluded?
  2. Since BlobTxType is mainly used for rollup purposes from L2 to L1, is it acceptable to proceed with the 1.15.x upgrade even without including it? Have there been any indications of necessity from major chains that plan to use cosmos/evm?

c.c. @zsystm

@@ -188,8 +190,8 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*t
evmDenom := types.GetEVMCoinDenom()

// refund gas in order to match the Ethereum gas consumption instead of the default SDK one.
if err = k.RefundGas(ctx, msg, msg.Gas()-res.GasUsed, evmDenom); err != nil {
return nil, errorsmod.Wrapf(err, "failed to refund gas leftover gas to sender %s", msg.From())
if err = k.RefundGas(ctx, *msg, msg.GasLimit-res.GasUsed, evmDenom); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

@vladjdk

It looks like msg.GasLimit - res.GasUsed could underflow if GasUsed > GasLimit, resulting in a large wrapped uint64 value due to Go's unsigned arithmetic.

Might be safer to guard it like this:

remainingGas := uint64(0)
if msg.GasLimit > res.GasUsed {
    remainingGas = msg.GasLimit - res.GasUsed
}

And then pass remainingGas into RefundGas(...).

What do you think?

Comment on lines +12 to +13
// MigrateStore migrates the x/evm module state from the consensus version 5 to
// version 6. Specifically, it migrates the geth chain configuration
Copy link
Contributor

Choose a reason for hiding this comment

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

@vladjdk

Suggested change
// MigrateStore migrates the x/evm module state from the consensus version 5 to
// version 6. Specifically, it migrates the geth chain configuration
// MigrateStore migrates the x/evm module state from the consensus version 8 to
// version 9. Specifically, it migrates the geth chain configuration

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.

6 participants