Skip to content
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

fix: audit #83

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 0 additions & 6 deletions jsonrpc/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ const (
// DefaultMaxOpenConnections is the default maximum number of simultaneous connections
// for the server listener.
DefaultMaxOpenConnections = 100
// DefaultLogsCap is the default max number of results can be returned from single `eth_getLogs` query.
DefaultLogsCap int32 = 100
// DefaultFilterCap is the default global cap for total number of filters that can be created.
DefaultFilterCap int32 = 200
// DefaultBlockRangeCap is the default max block range allowed for `eth_getLogs` query.
DefaultBlockRangeCap int32 = 100
// DefaultAddress defines the default HTTP server to listen on.
DefaultAddress = "127.0.0.1:8545"
// DefaultAddressWS defines the default WebSocket server address to bind to.
Expand Down
4 changes: 2 additions & 2 deletions x/evm/precompiles/cosmos/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (e CosmosPrecompile) ExtendedRun(caller vm.ContractRef, input []byte, suppl
switch r.(type) {
case storetypes.ErrorOutOfGas:
// convert cosmos out of gas error to EVM out of gas error
usedGas = suppliedGas + 1
err = nil
usedGas = suppliedGas
err = vm.ErrOutOfGas
default:
panic(r)
}
Expand Down
40 changes: 16 additions & 24 deletions x/evm/precompiles/cosmos/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ func Test_CosmosPrecompile_IsBlockedAddress(t *testing.T) {
require.NoError(t, err)

// out of gas error
_, gasUsed, err := cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.IS_BLOCKED_ADDRESS_GAS-1, true)
require.NoError(t, err)
require.Equal(t, precompiles.IS_BLOCKED_ADDRESS_GAS, gasUsed)
_, _, err = cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.IS_BLOCKED_ADDRESS_GAS-1, true)
require.ErrorIs(t, err, vm.ErrOutOfGas)

retBz, _, err := cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.IS_BLOCKED_ADDRESS_GAS+uint64(len(inputBz)), true)
require.NoError(t, err)
Expand Down Expand Up @@ -127,9 +126,8 @@ func Test_CosmosPrecompile_IsModuleAddress(t *testing.T) {
require.NoError(t, err)

// out of gas error
_, gasUsed, err := cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.IS_MODULE_ADDRESS_GAS-1, true)
require.NoError(t, err)
require.Equal(t, precompiles.IS_MODULE_ADDRESS_GAS, gasUsed)
_, _, err = cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.IS_MODULE_ADDRESS_GAS-1, true)
require.ErrorIs(t, err, vm.ErrOutOfGas)

retBz, _, err := cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.IS_MODULE_ADDRESS_GAS+uint64(len(inputBz)), true)
require.NoError(t, err)
Expand Down Expand Up @@ -173,9 +171,8 @@ func Test_CosmosPrecompile_ToCosmosAddress(t *testing.T) {
require.NoError(t, err)

// out of gas error
_, gasUsed, err := cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.TO_COSMOS_ADDRESS_GAS-1, true)
require.NoError(t, err)
require.Equal(t, precompiles.TO_COSMOS_ADDRESS_GAS, gasUsed)
_, _, err = cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.TO_COSMOS_ADDRESS_GAS-1, true)
require.ErrorIs(t, err, vm.ErrOutOfGas)

retBz, _, err := cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.TO_COSMOS_ADDRESS_GAS+uint64(len(inputBz)), true)
require.NoError(t, err)
Expand Down Expand Up @@ -204,9 +201,8 @@ func Test_CosmosPrecompile_ToEVMAddress(t *testing.T) {
require.NoError(t, err)

// out of gas error
_, gasUsed, err := cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.TO_EVM_ADDRESS_GAS-1, true)
require.NoError(t, err)
require.Equal(t, precompiles.TO_EVM_ADDRESS_GAS, gasUsed)
_, _, err = cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.TO_EVM_ADDRESS_GAS-1, true)
require.ErrorIs(t, err, vm.ErrOutOfGas)

retBz, _, err := cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.TO_EVM_ADDRESS_GAS+uint64(len(inputBz)), true)
require.NoError(t, err)
Expand Down Expand Up @@ -245,9 +241,8 @@ func Test_ExecuteCosmos(t *testing.T) {
require.NoError(t, err)

// out of gas error
_, gasUsed, err := cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.EXECUTE_COSMOS_GAS-1, false)
require.NoError(t, err)
require.Equal(t, precompiles.EXECUTE_COSMOS_GAS, gasUsed)
_, _, err = cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.EXECUTE_COSMOS_GAS-1, false)
require.ErrorIs(t, err, vm.ErrOutOfGas)

// cannot call execute in readonly mode
_, _, err = cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.EXECUTE_COSMOS_GAS+uint64(len(inputBz)), true)
Expand Down Expand Up @@ -333,9 +328,8 @@ func Test_QueryCosmos(t *testing.T) {
require.NoError(t, err)

// out of gas error
_, gasUsed, err := cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.QUERY_COSMOS_GAS-1, false)
require.NoError(t, err)
require.Equal(t, precompiles.QUERY_COSMOS_GAS, gasUsed)
_, _, err = cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.QUERY_COSMOS_GAS-1, false)
require.ErrorIs(t, err, vm.ErrOutOfGas)

// succeed
retBz, _, err := cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.QUERY_COSMOS_GAS+uint64(len(inputBz)), true)
Expand Down Expand Up @@ -380,9 +374,8 @@ func Test_ToDenom(t *testing.T) {
require.NoError(t, err)

// out of gas error
_, gasUsed, err := cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.TO_DENOM_GAS-1, false)
require.NoError(t, err)
require.Equal(t, precompiles.TO_DENOM_GAS, gasUsed)
_, _, err = cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.TO_DENOM_GAS-1, false)
require.ErrorIs(t, err, vm.ErrOutOfGas)

// succeed
retBz, _, err := cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.TO_DENOM_GAS+uint64(len(inputBz)), true)
Expand Down Expand Up @@ -422,9 +415,8 @@ func Test_ToErc20(t *testing.T) {
require.NoError(t, err)

// out of gas panic
_, gasUsed, err := cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.TO_ERC20_GAS-1, false)
require.NoError(t, err)
require.Equal(t, precompiles.TO_ERC20_GAS, gasUsed)
_, _, err = cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.TO_ERC20_GAS-1, false)
require.ErrorIs(t, err, vm.ErrOutOfGas)

// succeed
retBz, _, err := cosmosPrecompile.ExtendedRun(vm.AccountRef(evmAddr), inputBz, precompiles.TO_ERC20_GAS+uint64(len(inputBz)), true)
Expand Down
Loading