Skip to content

Commit

Permalink
Temporary Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-scherbina committed May 7, 2024
1 parent 310d310 commit ed9f029
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions x/evm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (
"encoding/json"
"fmt"

Check failure on line 21 in x/evm/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

File is not `gofumpt`-ed (gofumpt)
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/evmos/ethermint/x/evm/statedb"
"math/big"

Check failure on line 25 in x/evm/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

File is not `gofumpt`-ed (gofumpt)
"strconv"

govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
Expand Down Expand Up @@ -166,24 +168,37 @@ func (k *Keeper) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams)
newEnabledPrecompiles := req.Params.EnabledPrecompiles
newEnabledPrecompilesMap := make(map[common.Address]struct{}, len(newEnabledPrecompiles))

txConfig := statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes()))
stateDB := statedb.New(ctx, k, txConfig)

for _, hexAddr := range newEnabledPrecompiles {
addr := common.HexToAddress(hexAddr)
newEnabledPrecompilesMap[addr] = struct{}{}

// Set the nonce of the precompile's address (as is done when a contract is created) to ensure
// that it is marked as non-empty and will not be cleaned up when the statedb is finalized.
stateDB.SetNonce(addr, PrecompileNonce)
codeHash := crypto.Keccak256Hash(PrecompileCode)
err := k.SetAccount(ctx, addr, statedb.Account{
Nonce: PrecompileNonce,
Balance: big.NewInt(0),
CodeHash: codeHash[:],
})
if err != nil {
return nil, err
}

// Set the code of the precompile's address to a non-zero length byte slice to ensure that the precompile
// can be called from within Solidity contracts. Solidity adds a check before invoking a contract to ensure
// that it does not attempt to invoke a non-existent contract.
stateDB.SetCode(addr, PrecompileCode)
k.SetCode(ctx, codeHash[:], PrecompileCode)
}

for _, hexAddr := range oldEnabledPrecompiles {
addr := common.HexToAddress(hexAddr)
if _, ok := newEnabledPrecompilesMap[addr]; ok {
continue
}

if err := k.DeleteAccount(ctx, addr); err != nil {
return nil, err
}
}

if err := k.SetParams(ctx, req.Params); err != nil {
Expand Down

0 comments on commit ed9f029

Please sign in to comment.