Skip to content

Commit

Permalink
Merge branch 'main' into remove-pointer-restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
cordt-sei authored Sep 12, 2024
2 parents 1eca792 + 8defdf4 commit b636c66
Show file tree
Hide file tree
Showing 15 changed files with 189 additions and 35 deletions.
50 changes: 50 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,56 @@ Ref: https://keepachangelog.com/en/1.0.0/
-->

# Changelog
## v5.8.0
sei-chain
* [#1840](https://github.com/sei-protocol/sei-chain/pull/1840) Add migration for new params
* [#1837](https://github.com/sei-protocol/sei-chain/pull/1837) Move token id from Data to Topic in ERC721 Event
* [#1836](https://github.com/sei-protocol/sei-chain/pull/1836) Properly handle gas in pointer precompile
* [#1835](https://github.com/sei-protocol/sei-chain/pull/1835) Check TX nonce before registering hook to bump nonce for failed tx
* [#1832](https://github.com/sei-protocol/sei-chain/pull/1832) Show CW transactions that have synthetic EVM events in eth_getBlock response
* [#1831](https://github.com/sei-protocol/sei-chain/pull/1831) Fork event manager when creating EVM snapshots
* [#1830](https://github.com/sei-protocol/sei-chain/pull/1830) Add wasm contract query gas limit
* [#1826](https://github.com/sei-protocol/sei-chain/pull/1826) limit MsgExec max nested level
* [#1821](https://github.com/sei-protocol/sei-chain/pull/1821) Add antehandler for EVM to check gas exceed limit or not
* [#1818](https://github.com/sei-protocol/sei-chain/pull/1818) Prevent ddos against associate msgs
* [#1816](https://github.com/sei-protocol/sei-chain/pull/1816) Actually remove dex module
* [#1813](https://github.com/sei-protocol/sei-chain/pull/1813) Tune Configs
* [#1812](https://github.com/sei-protocol/sei-chain/pull/1812) Evidence Max Bytes Update
* [#1785](https://github.com/sei-protocol/sei-chain/pull/1785) Allow CW->ERC pointers to be called through wasmd precompile
* [#1778](https://github.com/sei-protocol/sei-chain/pull/1778) Bump nonce even if tx fails

sei-cosmos
* [#535](https://github.com/sei-protocol/sei-cosmos/pull/535) init app earliest version correctly after state sync
* [#534](https://github.com/sei-protocol/sei-cosmos/pull/534) Stop executing the handler when proposal is submitted
* [#533](https://github.com/sei-protocol/sei-cosmos/pull/533) Delete kvstore specified in store upgrades
* [#532](https://github.com/sei-protocol/sei-cosmos/pull/532) Add max gas limit check in ante handler
* [#528](https://github.com/sei-protocol/sei-cosmos/pull/528) Add logs for snapshot export and impor

sei-wasmd
* [63](https://github.com/sei-protocol/sei-wasmd/pull/63) Add CW dispatch call depth
* [62](https://github.com/sei-protocol/sei-wasmd/pull/62) Patch Gas mispricing in CW VM

sei-tendermint
* [#242](https://github.com/sei-protocol/sei-tendermint/pull/242) Allow hyphen in event query

## v5.7.5
sei-chain
* [#1795](https://github.com/sei-protocol/sei-chain/pull/1795) Do not charge gas for feecollector address query
* [#1782](https://github.com/sei-protocol/sei-chain/pull/1782) Update excessBlobGas and BlobBaseFee to fix simulate evmcontext
* [#1741](https://github.com/sei-protocol/sei-chain/pull/1782) Update excessBlobGas and BlobBaseFee to fix simulate evmcontext

sei-cosmos
* [#530](https://github.com/sei-protocol/sei-cosmos/pull/530) Add EVMEntryViaWasmdPrecompile flag
* [#519](https://github.com/sei-protocol/sei-cosmos/pull/519) Genesis export stream
* [#529](https://github.com/sei-protocol/sei-cosmos/pull/529) Add DeliverTx callback
* [#528](https://github.com/sei-protocol/sei-cosmos/pull/528) Add logs for snapshot export and import

sei-wasmd
* [58](https://github.com/sei-protocol/sei-wasmd/pull/58) Genesis Export OOM

sei-tendermint
* [#239](https://github.com/sei-protocol/sei-tendermint/pull/239) Use Marshal and UnmarshalJSON For HexBytes

## v5.7.1 & v5.7.2
sei-chain
* [#1779](https://github.com/sei-protocol/sei-chain/pull/1779) Fix subscribe logs empty params crash
Expand Down
9 changes: 6 additions & 3 deletions evmrpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func (a *BlockAPI) GetBlockByHash(ctx context.Context, blockHash common.Hash, fu
if err != nil {
return nil, err
}
return EncodeTmBlock(a.ctxProvider(LatestCtxHeight), block, blockRes, a.keeper, a.txConfig.TxDecoder(), fullTx)
blockBloom := a.keeper.GetBlockBloom(a.ctxProvider(block.Block.Height))
return EncodeTmBlock(a.ctxProvider(LatestCtxHeight), block, blockRes, blockBloom, a.keeper, a.txConfig.TxDecoder(), fullTx)
}

func (a *BlockAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (result map[string]interface{}, returnErr error) {
Expand All @@ -89,7 +90,8 @@ func (a *BlockAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber,
if err != nil {
return nil, err
}
return EncodeTmBlock(a.ctxProvider(LatestCtxHeight), block, blockRes, a.keeper, a.txConfig.TxDecoder(), fullTx)
blockBloom := a.keeper.GetBlockBloom(a.ctxProvider(block.Block.Height))
return EncodeTmBlock(a.ctxProvider(LatestCtxHeight), block, blockRes, blockBloom, a.keeper, a.txConfig.TxDecoder(), fullTx)
}

func (a *BlockAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (result []map[string]interface{}, returnErr error) {
Expand Down Expand Up @@ -154,6 +156,7 @@ func EncodeTmBlock(
ctx sdk.Context,
block *coretypes.ResultBlock,
blockRes *coretypes.ResultBlockResults,
blockBloom ethtypes.Bloom,
k *keeper.Keeper,
txDecoder sdk.TxDecoder,
fullTx bool,
Expand Down Expand Up @@ -231,7 +234,7 @@ func EncodeTmBlock(
"nonce": ethtypes.BlockNonce{}, // inapplicable to Sei
"mixHash": common.Hash{}, // inapplicable to Sei
"sha3Uncles": ethtypes.EmptyUncleHash, // inapplicable to Sei
"logsBloom": k.GetBlockBloom(ctx, block.Block.Height),
"logsBloom": blockBloom,
"stateRoot": appHash,
"miner": miner,
"difficulty": (*hexutil.Big)(big.NewInt(0)), // inapplicable to Sei
Expand Down
12 changes: 4 additions & 8 deletions evmrpc/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,7 @@ func verifyBlockResult(t *testing.T, resObj map[string]interface{}) {
require.Equal(t, "0x5", resObj["gasUsed"])
require.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000001", resObj["hash"])
// see setup_tests.go, which have one transaction for block 0x8 (latest)
if resObj["number"] == "0x8" {
require.Equal(t, "0x00002000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000200000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000", resObj["logsBloom"])
} else {
require.Equal(t, "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", resObj["logsBloom"])
}
require.Equal(t, "0x00002000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000200000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000", resObj["logsBloom"])
require.Equal(t, "0x0000000000000000000000000000000000000005", resObj["miner"])
require.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000000", resObj["mixHash"])
require.Equal(t, "0x0000000000000000", resObj["nonce"])
Expand Down Expand Up @@ -174,7 +170,7 @@ func TestEncodeTmBlock_EmptyTransactions(t *testing.T) {
}

// Call EncodeTmBlock with empty transactions
result, err := evmrpc.EncodeTmBlock(ctx, block, blockRes, k, Decoder, true)
result, err := evmrpc.EncodeTmBlock(ctx, block, blockRes, ethtypes.Bloom{}, k, Decoder, true)
require.Nil(t, err)

// Assert txHash is equal to ethtypes.EmptyTxsHash
Expand Down Expand Up @@ -220,7 +216,7 @@ func TestEncodeBankMsg(t *testing.T) {
},
},
}
res, err := evmrpc.EncodeTmBlock(ctx, &resBlock, &resBlockRes, k, Decoder, true)
res, err := evmrpc.EncodeTmBlock(ctx, &resBlock, &resBlockRes, ethtypes.Bloom{}, k, Decoder, true)
require.Nil(t, err)
txs := res["transactions"].([]interface{})
require.Equal(t, 0, len(txs))
Expand Down Expand Up @@ -268,7 +264,7 @@ func TestEncodeWasmExecuteMsg(t *testing.T) {
},
},
}
res, err := evmrpc.EncodeTmBlock(ctx, &resBlock, &resBlockRes, k, Decoder, true)
res, err := evmrpc.EncodeTmBlock(ctx, &resBlock, &resBlockRes, ethtypes.Bloom{}, k, Decoder, true)
require.Nil(t, err)
txs := res["transactions"].([]interface{})
require.Equal(t, 1, len(txs))
Expand Down
8 changes: 6 additions & 2 deletions evmrpc/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,13 @@ func (f *LogFetcher) GetLogsForBlock(ctx context.Context, block *coretypes.Resul

func (f *LogFetcher) FindBlockesByBloom(begin, end int64, filters [][]bloomIndexes) (res []int64) {
//TODO: parallelize
ctx := f.ctxProvider(LatestCtxHeight)
for height := begin; height <= end; height++ {
blockBloom := f.k.GetBlockBloom(ctx, height)
if height == 0 {
// no block bloom on genesis height
continue
}
ctx := f.ctxProvider(height)
blockBloom := f.k.GetBlockBloom(ctx)
if MatchFilters(blockBloom, filters) {
res = append(res, height)
}
Expand Down
2 changes: 1 addition & 1 deletion evmrpc/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func TestFilterGetFilterChanges(t *testing.T) {
EVMKeeper.SetTxHashesOnHeight(Ctx, 9, []common.Hash{
common.HexToHash("0x123456789012345678902345678901234567890123456789012345678900005"),
})
EVMKeeper.SetBlockBloom(Ctx, 9, []ethtypes.Bloom{bloom})
EVMKeeper.SetBlockBloom(Ctx, []ethtypes.Bloom{bloom})
Ctx = Ctx.WithBlockHeight(9)
resObj = sendRequest(t, TestPort, "getFilterChanges", filterId)
Ctx = Ctx.WithBlockHeight(8)
Expand Down
18 changes: 13 additions & 5 deletions evmrpc/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,13 @@ func (m *MockBadClient) BroadcastTx(context.Context, tmtypes.Tx) (*coretypes.Res

var EVMKeeper *keeper.Keeper
var Ctx sdk.Context
var MultiTxCtx sdk.Context

func init() {
types.RegisterInterfaces(EncodingConfig.InterfaceRegistry)
testApp := app.Setup(false, false)
Ctx = testApp.GetContextForDeliverTx([]byte{}).WithBlockHeight(8)
MultiTxCtx, _ = Ctx.CacheContext()
EVMKeeper = &testApp.EvmKeeper
EVMKeeper.InitGenesis(Ctx, *evmtypes.DefaultGenesis())
seiAddr, err := sdk.AccAddressFromHex(common.Bytes2Hex([]byte("seiAddr")))
Expand All @@ -427,6 +429,12 @@ func init() {
panic(err)
}
testApp.Commit(context.Background())
ctxProvider := func(height int64) sdk.Context {
if height == MultiTxBlockHeight {
return MultiTxCtx
}
return Ctx
}
// Start good http server
goodConfig := evmrpc.DefaultConfig
goodConfig.HTTPPort = TestPort
Expand All @@ -437,7 +445,7 @@ func init() {
if err != nil {
panic(err)
}
HttpServer, err := evmrpc.NewEVMHTTPServer(infoLog, goodConfig, &MockClient{}, EVMKeeper, func(int64) sdk.Context { return Ctx }, TxConfig, "")
HttpServer, err := evmrpc.NewEVMHTTPServer(infoLog, goodConfig, &MockClient{}, EVMKeeper, ctxProvider, TxConfig, "")
if err != nil {
panic(err)
}
Expand All @@ -449,7 +457,7 @@ func init() {
badConfig := evmrpc.DefaultConfig
badConfig.HTTPPort = TestBadPort
badConfig.FilterTimeout = 500 * time.Millisecond
badHTTPServer, err := evmrpc.NewEVMHTTPServer(infoLog, badConfig, &MockBadClient{}, EVMKeeper, func(int64) sdk.Context { return Ctx }, TxConfig, "")
badHTTPServer, err := evmrpc.NewEVMHTTPServer(infoLog, badConfig, &MockBadClient{}, EVMKeeper, ctxProvider, TxConfig, "")
if err != nil {
panic(err)
}
Expand All @@ -458,7 +466,7 @@ func init() {
}

// Start ws server
wsServer, err := evmrpc.NewEVMWebSocketServer(infoLog, goodConfig, &MockClient{}, EVMKeeper, func(int64) sdk.Context { return Ctx }, TxConfig, "")
wsServer, err := evmrpc.NewEVMWebSocketServer(infoLog, goodConfig, &MockClient{}, EVMKeeper, ctxProvider, TxConfig, "")
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -723,8 +731,8 @@ func setupLogs() {
EVMKeeper.SetTxHashesOnHeight(Ctx, MockHeight, []common.Hash{
multiTxBlockTx4.Hash(),
})
EVMKeeper.SetBlockBloom(Ctx, MultiTxBlockHeight, []ethtypes.Bloom{bloom1, bloom2, bloom3})
EVMKeeper.SetBlockBloom(Ctx, MockHeight, []ethtypes.Bloom{bloom4})
EVMKeeper.SetBlockBloom(MultiTxCtx, []ethtypes.Bloom{bloom1, bloom2, bloom3})
EVMKeeper.SetBlockBloom(Ctx, []ethtypes.Bloom{bloom4})
}

//nolint:deadcode
Expand Down
4 changes: 4 additions & 0 deletions x/evm/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func InitGenesis(ctx sdk.Context, k *keeper.Keeper, genState types.GenesisState)
k.SetNonce(ctx, common.HexToAddress(nonce.Address), nonce.Nonce)
}
for _, serialized := range genState.Serialized {
if len(serialized.Key) == 0 {
ctx.KVStore(k.GetStoreKey()).Set(serialized.Prefix, serialized.Value)
continue
}
k.PrefixStore(ctx, serialized.Prefix).Set(serialized.Key, serialized.Value)
}
}
Expand Down
4 changes: 2 additions & 2 deletions x/evm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestExportImportGenesis(t *testing.T) {
keeper.SetState(ctx, codeAddr, common.BytesToHash([]byte("123")), common.BytesToHash([]byte("456")))
keeper.SetNonce(ctx, evmAddr, 2)
keeper.MockReceipt(ctx, common.BytesToHash([]byte("789")), &types.Receipt{TxType: 2})
keeper.SetBlockBloom(ctx, 5, []ethtypes.Bloom{{1}})
keeper.SetBlockBloom(ctx, []ethtypes.Bloom{{1}})
keeper.SetTxHashesOnHeight(ctx, 5, []common.Hash{common.BytesToHash([]byte("123"))})
keeper.SetERC20CW20Pointer(ctx, "cw20addr", codeAddr)
genesis := evm.ExportGenesis(ctx, keeper)
Expand All @@ -42,7 +42,7 @@ func TestExportImportGenesis(t *testing.T) {
require.Equal(t, keeper.GetNonce(ctx, evmAddr), keeper.GetNonce(origctx, evmAddr))
_, err := keeper.GetReceipt(origctx, common.BytesToHash([]byte("789")))
require.Nil(t, err)
require.Equal(t, keeper.GetBlockBloom(ctx, 5), keeper.GetBlockBloom(origctx, 5))
require.Equal(t, keeper.GetBlockBloom(ctx), keeper.GetBlockBloom(origctx))
require.Equal(t, keeper.GetTxHashesOnHeight(ctx, 5), keeper.GetTxHashesOnHeight(origctx, 5))
_, _, exists := keeper.GetERC20CW20Pointer(origctx, "cw20addr")
require.True(t, exists)
Expand Down
42 changes: 34 additions & 8 deletions x/evm/keeper/log.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package keeper

import (
"bytes"
"encoding/binary"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -11,7 +11,21 @@ import (
"github.com/sei-protocol/sei-chain/x/evm/types"
)

func (k *Keeper) GetBlockBloom(ctx sdk.Context, height int64) (res ethtypes.Bloom) {
func (k *Keeper) GetBlockBloom(ctx sdk.Context) (res ethtypes.Bloom) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.BlockBloomPrefix)
if bz != nil {
res.SetBytes(bz)
return
}
cutoff := k.GetLegacyBlockBloomCutoffHeight(ctx)
if cutoff == 0 || ctx.BlockHeight() < cutoff {
res = k.GetLegacyBlockBloom(ctx, ctx.BlockHeight())
}
return
}

func (k *Keeper) GetLegacyBlockBloom(ctx sdk.Context, height int64) (res ethtypes.Bloom) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.BlockBloomKey(height))
if bz != nil {
Expand All @@ -20,19 +34,31 @@ func (k *Keeper) GetBlockBloom(ctx sdk.Context, height int64) (res ethtypes.Bloo
return
}

func (k *Keeper) SetBlockBloom(ctx sdk.Context, height int64, blooms []ethtypes.Bloom) {
func (k *Keeper) SetBlockBloom(ctx sdk.Context, blooms []ethtypes.Bloom) {
blockBloom := make([]byte, ethtypes.BloomByteLength)
for _, bloom := range blooms {
or := make([]byte, ethtypes.BloomByteLength)
bitutil.ORBytes(or, blockBloom, bloom[:])
blockBloom = or
}
if bytes.Equal(blockBloom, make([]byte, ethtypes.BloomByteLength)) {
// early return if bloom is empty
return
}
store := ctx.KVStore(k.storeKey)
store.Set(types.BlockBloomKey(height), blockBloom)
store.Set(types.BlockBloomPrefix, blockBloom)
}

func (k *Keeper) SetLegacyBlockBloomCutoffHeight(ctx sdk.Context) {
store := ctx.KVStore(k.storeKey)
bz := make([]byte, 8)
binary.BigEndian.PutUint64(bz, uint64(ctx.BlockHeight()))
store.Set(types.LegacyBlockBloomCutoffHeightKey, bz)
}

func (k *Keeper) GetLegacyBlockBloomCutoffHeight(ctx sdk.Context) int64 {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.LegacyBlockBloomCutoffHeightKey)
if len(bz) == 0 {
return 0
}
return int64(binary.BigEndian.Uint64(bz))
}

func GetLogsForTx(receipt *types.Receipt) []*ethtypes.Log {
Expand Down
16 changes: 13 additions & 3 deletions x/evm/keeper/log_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package keeper
package keeper_test

import (
"testing"
Expand All @@ -7,6 +7,8 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"

testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper"
"github.com/sei-protocol/sei-chain/x/evm/keeper"
evmtypes "github.com/sei-protocol/sei-chain/x/evm/types"
)

Expand All @@ -26,7 +28,7 @@ func TestConvertEthLog(t *testing.T) {
}

// Convert the ethtypes.Log to a types.Log
log := ConvertEthLog(ethLog)
log := keeper.ConvertEthLog(ethLog)

// Check that the fields match
require.Equal(t, ethLog.Address.Hex(), log.Address)
Expand Down Expand Up @@ -67,7 +69,7 @@ func TestGetLogsForTx(t *testing.T) {
}

// Convert the types.Receipt to a list of ethtypes.Log objects
logs := GetLogsForTx(receipt)
logs := keeper.GetLogsForTx(receipt)

// Check that the fields match
require.Equal(t, len(receipt.Logs), len(logs))
Expand All @@ -81,3 +83,11 @@ func TestGetLogsForTx(t *testing.T) {
require.Equal(t, uint(receipt.Logs[i].Index), log.Index)
}
}

func TestLegacyBlockBloomCutoffHeight(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx([]byte{}).WithBlockHeight(123)
require.Equal(t, int64(0), k.GetLegacyBlockBloomCutoffHeight(ctx))
k.SetLegacyBlockBloomCutoffHeight(ctx)
require.Equal(t, int64(123), k.GetLegacyBlockBloomCutoffHeight(ctx))
}
25 changes: 25 additions & 0 deletions x/evm/migrations/migrate_block_bloom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package migrations

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/sei-protocol/sei-chain/x/evm/keeper"
"github.com/sei-protocol/sei-chain/x/evm/types"
)

func MigrateBlockBloom(ctx sdk.Context, k *keeper.Keeper) error {
k.SetLegacyBlockBloomCutoffHeight(ctx)

prefsToDelete := [][]byte{}
k.IterateAll(ctx, types.BlockBloomPrefix, func(key, _ []byte) bool {
if len(key) > 0 {
prefsToDelete = append(prefsToDelete, key)
}
return false
})
store := k.PrefixStore(ctx, types.BlockBloomPrefix)
for _, pref := range prefsToDelete {
store.Delete(pref)
}

return nil
}
Loading

0 comments on commit b636c66

Please sign in to comment.