Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-nguy committed Sep 26, 2023
1 parent c04a708 commit 408def7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
16 changes: 10 additions & 6 deletions x/cronos/keeper/precompiles/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (

const (
EVMDenomPrefix = "evm/"
MintName = "mint"
BurnName = "burn"
BalanceOfName = "balanceOf"
TransferName = "transfer"
)

var (
Expand Down Expand Up @@ -58,11 +62,11 @@ func (bc *BankContract) RequiredGas(input []byte) uint64 {
return 0
}
switch method.Name {
case "mint", "burn":
case MintName, BurnName:
return 1000
case "balanceOf":
case BalanceOfName:
return 1000
case "transfer":
case TransferName:
return 1000
default:
return 0
Expand Down Expand Up @@ -94,7 +98,7 @@ func (bc *BankContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) (
stateDB := evm.StateDB.(ExtStateDB)
precompileAddr := bc.Address()
switch method.Name {
case "mint", "burn":
case MintName, BurnName:
if readonly {
return nil, errors.New("the method is not readonly")
}
Expand Down Expand Up @@ -138,7 +142,7 @@ func (bc *BankContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) (
return nil, err
}
return method.Outputs.Pack(true)
case "balanceOf":
case BalanceOfName:
args, err := method.Inputs.Unpack(contract.Input[4:])
if err != nil {
return nil, errors.New("fail to unpack input arguments")
Expand All @@ -148,7 +152,7 @@ func (bc *BankContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) (
// query from storage
balance := bc.bankKeeper.GetBalance(stateDB.CacheContext(), sdk.AccAddress(addr.Bytes()), EVMDenom(token)).Amount.BigInt()
return method.Outputs.Pack(balance)
case "transfer":
case TransferName:
if readonly {
return nil, errors.New("the method is not readonly")
}
Expand Down
19 changes: 11 additions & 8 deletions x/cronos/keeper/precompiles/ica.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
)

// TODO: Replace this const with adjusted gas cost corresponding to input when executing precompile contract.
const ICAContractRequiredGas = 10000
const (
RegisterAccountName = "registerAccount"
QueryAccountName = "queryAccount"
SubmitMsgsName = "submitMsgs"
)

var (
icaABI abi.ABI
Expand Down Expand Up @@ -60,11 +63,11 @@ func (ic *IcaContract) RequiredGas(input []byte) uint64 {
return 0
}
switch method.Name {
case "registerAccount":
case RegisterAccountName:
return 1000
case "queryAccount":
case QueryAccountName:
return 1000
case "submitMsgs":
case SubmitMsgsName:
return 1000
default:
return 0
Expand All @@ -90,7 +93,7 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([
converter := cronosevents.IcaConvertEvent
var execErr error
switch method.Name {
case "registerAccount":
case RegisterAccountName:
if readonly {
return nil, errors.New("the method is not readonly")
}
Expand All @@ -112,7 +115,7 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([
return nil, execErr
}
return method.Outputs.Pack(true)
case "queryAccount":
case QueryAccountName:
args, err := method.Inputs.Unpack(contract.Input[4:])
if err != nil {
return nil, errors.New("fail to unpack input arguments")
Expand All @@ -134,7 +137,7 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([
icaAddress = response.InterchainAccountAddress
}
return method.Outputs.Pack(icaAddress)
case "submitMsgs":
case SubmitMsgsName:
if readonly {
return nil, errors.New("the method is not readonly")
}
Expand Down
3 changes: 3 additions & 0 deletions x/cronos/keeper/precompiles/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func (bc *RelayerContract) Address() common.Address {

// RequiredGas calculates the contract gas use
func (bc *RelayerContract) RequiredGas(input []byte) uint64 {
if len(input) < prefixSize4Bytes {
return 0
}
prefix := int(binary.LittleEndian.Uint32(input[:prefixSize4Bytes]))

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion Error

Potential integer overflow by integer type conversion
switch prefix {
case prefixCreateClient:
Expand Down

0 comments on commit 408def7

Please sign in to comment.