Skip to content

Commit

Permalink
add switch
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-nguy committed Sep 26, 2023
1 parent 668a84e commit c04a708
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 8 deletions.
20 changes: 16 additions & 4 deletions x/cronos/keeper/precompiles/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import (
)

const (
EVMDenomPrefix = "evm/"
BankContractRequiredGas = 21000
EVMDenomPrefix = "evm/"
)

var (
Expand Down Expand Up @@ -53,8 +52,21 @@ func (bc *BankContract) Address() common.Address {

// RequiredGas calculates the contract gas use
func (bc *BankContract) RequiredGas(input []byte) uint64 {
// TODO estimate required gas
return BankContractRequiredGas
methodID := input[:4]
method, err := bankABI.MethodById(methodID)
if err != nil {
return 0
}
switch method.Name {
case "mint", "burn":

Check failure on line 61 in x/cronos/keeper/precompiles/bank.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

string `mint` has 3 occurrences, make it a constant (goconst)
return 1000
case "balanceOf":
return 1000
case "transfer":
return 1000
default:
return 0
}
}

func (bc *BankContract) IsStateful() bool {
Expand Down
16 changes: 15 additions & 1 deletion x/cronos/keeper/precompiles/ica.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,21 @@ func (ic *IcaContract) Address() common.Address {

// RequiredGas calculates the contract gas use
func (ic *IcaContract) RequiredGas(input []byte) uint64 {
return ICAContractRequiredGas
methodID := input[:4]
method, err := icaABI.MethodById(methodID)
if err != nil {
return 0
}
switch method.Name {
case "registerAccount":
return 1000
case "queryAccount":
return 1000
case "submitMsgs":
return 1000
default:
return 0
}
}

func (ic *IcaContract) IsStateful() bool {
Expand Down
40 changes: 37 additions & 3 deletions x/cronos/keeper/precompiles/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
cronosevents "github.com/crypto-org-chain/cronos/v2/x/cronos/events"
)

const RelayerContractRequiredGas = 300000

var RelayerContractAddress = common.BytesToAddress([]byte{101})

type RelayerContract struct {
Expand All @@ -37,7 +35,43 @@ func (bc *RelayerContract) Address() common.Address {

// RequiredGas calculates the contract gas use
func (bc *RelayerContract) RequiredGas(input []byte) uint64 {
return RelayerContractRequiredGas
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:
return 300000
case prefixUpdateClient:
return 300000
case prefixUpgradeClient:
return 300000
case prefixSubmitMisbehaviour:
return 300000
case prefixConnectionOpenInit:
return 300000
case prefixConnectionOpenTry:
return 300000
case prefixConnectionOpenAck:
return 300000
case prefixConnectionOpenConfirm:
return 300000
case prefixChannelOpenInit:
return 300000
case prefixChannelOpenTry:
return 300000
case prefixChannelOpenAck:
return 300000
case prefixChannelOpenConfirm:
return 300000
case prefixRecvPacket:
return 300000
case prefixAcknowledgement:
return 300000
case prefixTimeout:
return 300000
case prefixTimeoutOnClose:
return 300000
default:
return 0
}
}

func (bc *RelayerContract) IsStateful() bool {
Expand Down

0 comments on commit c04a708

Please sign in to comment.