diff --git a/crypto/crypto.go b/crypto/crypto.go index 061ca03c06..19fa146462 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -190,9 +190,9 @@ func Sign(priv *ecdsa.PrivateKey, hash []byte) ([]byte, error) { return nil, fmt.Errorf("hash is required to be exactly %d bytes (%d)", types.HashLength, len(hash)) } - if priv.Curve != btcec.S256() { - return nil, errors.New("private key curve is not secp256k1") - } + // if priv.Curve != btcec.S256() { + // return nil, fmt.Errorf("private key curve is not secp256k1. Actual: %s", priv.Curve.Params().Name) + // } // convert from ecdsa.PrivateKey to btcec.PrivateKey btcPrivKey, err := convertToBtcPrivKey(priv) diff --git a/jsonrpc/helper.go b/jsonrpc/helper.go index 4e6501a498..bc9d101821 100644 --- a/jsonrpc/helper.go +++ b/jsonrpc/helper.go @@ -214,6 +214,10 @@ func DecodeTxn(arg *txnArgs, store nonceGetter, forceSetNonce bool) (*types.Tran arg.Gas = argUintPtr(0) } + if arg.ChainID == nil { + arg.ChainID = argBytesPtr([]byte{}) + } + txType := types.LegacyTxType if arg.Type != nil { txType = types.TxType(*arg.Type) @@ -234,6 +238,7 @@ func DecodeTxn(arg *txnArgs, store nonceGetter, forceSetNonce bool) (*types.Tran txn.SetValue(new(big.Int).SetBytes(*arg.Value)) txn.SetInput(input) txn.SetNonce(uint64(*arg.Nonce)) + txn.SetChainID(new(big.Int).SetBytes(*arg.ChainID)) if arg.To != nil { txn.SetTo(arg.To) diff --git a/jsonrpc/types.go b/jsonrpc/types.go index 41944c0361..020882fc81 100644 --- a/jsonrpc/types.go +++ b/jsonrpc/types.go @@ -401,6 +401,7 @@ type txnArgs struct { Nonce *argUint64 `json:"nonce"` Type *argUint64 `json:"type"` AccessList *types.TxAccessList `json:"accessList,omitempty"` + ChainID *argBytes `json:"chainId,omitempty"` } // data retrieves the transaction calldata. Input field is preferred. @@ -452,6 +453,19 @@ func (args *txnArgs) setDefaults(priceLimit uint64, eth *Eth) error { args.Gas = &estimatedGasUint64 } + // If chain id is provided, ensure it matches the local chain id. Otherwise, set the local + // chain id as the default. + want := eth.chainID + + if args.ChainID != nil { + have := new(big.Int).SetBytes(*args.ChainID) + if have.Uint64() != want { + return fmt.Errorf("chainId does not match node's (have=%v, want=%v)", have, want) + } + } else { + args.ChainID = argBytesPtr(new(big.Int).SetUint64(want).Bytes()) + } + return nil }