diff --git a/go/common/gethencoding/geth_encoding.go b/go/common/gethencoding/geth_encoding.go index 812dbc527a..bac9685bfb 100644 --- a/go/common/gethencoding/geth_encoding.go +++ b/go/common/gethencoding/geth_encoding.go @@ -77,54 +77,6 @@ func NewGethEncodingService(storage storage.Storage, logger gethlog.Logger) Enco } } -// ExtractEthCallMapString extracts the eth_call gethapi.TransactionArgs from an interface{} -// it ensures that : -// - All types are string -// - All keys are lowercase -// - There is only one key per value -// - From field is set by default -func ExtractEthCallMapString(paramBytes interface{}) (map[string]string, error) { - // geth lowercase the field name and uses the last seen value - var valString string - var ok bool - callMsg := map[string]string{ - // From field is set by default - "from": gethcommon.HexToAddress("0x0").Hex(), - } - for field, val := range paramBytes.(map[string]interface{}) { - if val == nil { - continue - } - valString, ok = val.(string) - if !ok { - return nil, fmt.Errorf("unexpected type supplied in `%s` field", field) - } - if len(strings.TrimSpace(valString)) == 0 { - continue - } - switch strings.ToLower(field) { - case callFieldTo: - callMsg[callFieldTo] = valString - case CallFieldFrom: - callMsg[CallFieldFrom] = valString - case callFieldData, callFieldInput: - callMsg[callFieldInput] = valString - case callFieldValue: - callMsg[callFieldValue] = valString - case callFieldGas: - callMsg[callFieldGas] = valString - case callFieldMaxFeePerGas: - callMsg[callFieldMaxFeePerGas] = valString - case callFieldMaxPriorityFeePerGas: - callMsg[callFieldMaxPriorityFeePerGas] = valString - default: - callMsg[field] = valString - } - } - - return callMsg, nil -} - // ExtractAddress returns a gethcommon.Address given an interface{}, errors if unexpected values are used func ExtractAddress(param interface{}) (*gethcommon.Address, error) { if param == nil { @@ -140,7 +92,7 @@ func ExtractAddress(param interface{}) (*gethcommon.Address, error) { return nil, fmt.Errorf("no address specified") } - addr := gethcommon.HexToAddress(param.(string)) + addr := gethcommon.HexToAddress(paramStr) return &addr, nil } @@ -183,10 +135,13 @@ func ExtractBlockNumber(param interface{}) (*gethrpc.BlockNumberOrHash, error) { blockAndHash, ok := param.(map[string]any) if !ok { - return nil, fmt.Errorf("invalid block or hash parameter %s", param.(string)) + return nil, fmt.Errorf("invalid block or hash parameter") } if blockAndHash["blockNumber"] != nil { - b := blockAndHash["blockNumber"].(string) + b, ok := blockAndHash["blockNumber"].(string) + if !ok { + return nil, fmt.Errorf("invalid blockNumber parameter") + } blockNumber := gethrpc.BlockNumber(0) err := blockNumber.UnmarshalJSON([]byte(b)) if err != nil { @@ -195,11 +150,17 @@ func ExtractBlockNumber(param interface{}) (*gethrpc.BlockNumberOrHash, error) { blockNo = &blockNumber } if blockAndHash["blockHash"] != nil { - bh := blockAndHash["blockHash"].(gethcommon.Hash) + bh, ok := blockAndHash["blockHash"].(gethcommon.Hash) + if !ok { + return nil, fmt.Errorf("invalid blockhash parameter") + } blockHa = &bh } if blockAndHash["RequireCanonical"] != nil { - reqCanon = blockAndHash["RequireCanonical"].(bool) + reqCanon, ok = blockAndHash["RequireCanonical"].(bool) + if !ok { + return nil, fmt.Errorf("invalid RequireCanonical parameter") + } } return &gethrpc.BlockNumberOrHash{ @@ -222,7 +183,12 @@ func ExtractEthCall(param interface{}) (*gethapi.TransactionArgs, error) { // if gas is not set it should be null gas := (*hexutil.Uint64)(nil) - for field, val := range param.(map[string]interface{}) { + ethCallMap, ok := param.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("invalid eth call parameter") + } + + for field, val := range ethCallMap { if val == nil { continue } diff --git a/go/enclave/components/batch_executor.go b/go/enclave/components/batch_executor.go index 77aae4e75f..cfead4334b 100644 --- a/go/enclave/components/batch_executor.go +++ b/go/enclave/components/batch_executor.go @@ -379,7 +379,7 @@ func (executor *batchExecutor) populateOutboundCrossChainData(ctx context.Contex encodedTree, err := json.Marshal(xchainTree) if err != nil { - panic(err) //todo: figure out what to do + panic(err) // todo: figure out what to do } batch.Header.CrossChainTree = encodedTree diff --git a/go/enclave/crosschain/common.go b/go/enclave/crosschain/common.go index b6ee881c89..1d64083dbb 100644 --- a/go/enclave/crosschain/common.go +++ b/go/enclave/crosschain/common.go @@ -234,7 +234,7 @@ func (ms MessageStructs) HashPacked(index int) gethcommon.Hash { }, } - //todo @siliev: err + // todo @siliev: err packed, _ := args.Pack(messageStruct.Sender, messageStruct.Sequence, messageStruct.Nonce, messageStruct.Topic, messageStruct.Payload, messageStruct.ConsistencyLevel) hash := crypto.Keccak256Hash(packed) return hash diff --git a/go/enclave/genesis/testnet_genesis.go b/go/enclave/genesis/testnet_genesis.go index 49b48c16ca..fed93c6f0d 100644 --- a/go/enclave/genesis/testnet_genesis.go +++ b/go/enclave/genesis/testnet_genesis.go @@ -9,8 +9,10 @@ import ( ) const TestnetPrefundedPK = "8dfb8083da6275ae3e4f41e3e8a8c19d028d32c9247e24530933782f2a05035b" // The genesis main account private key. -var GasBridgingKeys, _ = crypto.GenerateKey() // todo - make static -var GasWithdrawalKeys, _ = crypto.GenerateKey() // todo - make static +var ( + GasBridgingKeys, _ = crypto.GenerateKey() // todo - make static + GasWithdrawalKeys, _ = crypto.GenerateKey() // todo - make static +) var TestnetGenesis = Genesis{ Accounts: []Account{ diff --git a/go/enclave/nodetype/common.go b/go/enclave/nodetype/common.go index 197fef08d1..a99dc0f690 100644 --- a/go/enclave/nodetype/common.go +++ b/go/enclave/nodetype/common.go @@ -40,6 +40,6 @@ func ExportCrossChainData(ctx context.Context, storage storage.Storage, fromSeqN L1BlockHash: block.Hash(), L1BlockNum: big.NewInt(0).Set(block.Header().Number), CrossChainRootHashes: crossChainHashes, - } //todo: check fromSeqNo + } // todo: check fromSeqNo return bundle, nil } diff --git a/go/enclave/nodetype/sequencer.go b/go/enclave/nodetype/sequencer.go index a0283c2312..16e5117590 100644 --- a/go/enclave/nodetype/sequencer.go +++ b/go/enclave/nodetype/sequencer.go @@ -468,6 +468,7 @@ func (s *sequencer) signCrossChainBundle(bundle *common.ExtCrossChainBundle) err } return nil } + func (s *sequencer) OnL1Block(ctx context.Context, block *types.Block, result *components.BlockIngestionType) error { // nothing to do return nil diff --git a/go/enclave/rpc/SubmitTx.go b/go/enclave/rpc/SubmitTx.go index ab93317f4b..fe3d2af7fe 100644 --- a/go/enclave/rpc/SubmitTx.go +++ b/go/enclave/rpc/SubmitTx.go @@ -1,6 +1,7 @@ package rpc import ( + "errors" "fmt" gethcommon "github.com/ethereum/go-ethereum/common" @@ -9,7 +10,11 @@ import ( ) func SubmitTxValidate(reqParams []any, builder *CallBuilder[common.L2Tx, gethcommon.Hash], _ *EncryptionManager) error { - l2Tx, err := ExtractTx(reqParams[0].(string)) + txStr, ok := reqParams[0].(string) + if !ok { + return errors.New("unsupported format") + } + l2Tx, err := ExtractTx(txStr) if err != nil { builder.Err = fmt.Errorf("could not extract transaction. Cause: %w", err) return nil diff --git a/go/enclave/storage/enclavedb/events.go b/go/enclave/storage/enclavedb/events.go index 2723c9a3a2..67a0a90ca7 100644 --- a/go/enclave/storage/enclavedb/events.go +++ b/go/enclave/storage/enclavedb/events.go @@ -364,7 +364,10 @@ func stringToHash(ns sql.NullString) gethcommon.Hash { if err != nil { return [32]byte{} } - s := value.(string) + s, ok := value.(string) + if !ok { + return [32]byte{} + } result := gethcommon.Hash{} result.SetBytes([]byte(s)) return result