From cc8504522bebd9dfee15f8602e40d3551db346ed Mon Sep 17 00:00:00 2001 From: Ryan Tinianov Date: Fri, 10 Nov 2023 13:50:59 -0500 Subject: [PATCH] Parse evm types to create structs that we can encode/decode --- core/services/ocr2/plugins/median/services.go | 4 +- core/services/relay/evm/codec_entry.go | 150 +++++++++++++ core/services/relay/evm/codec_entry_test.go | 137 ++++++++++++ .../relay/evm/types/byte_types_gen.go | 201 +++++++++--------- core/services/relay/evm/types/gen.go | 14 +- .../services/relay/evm/types/int_types_gen.go | 57 +++-- go.mod | 6 +- go.sum | 6 +- 8 files changed, 430 insertions(+), 145 deletions(-) create mode 100644 core/services/relay/evm/codec_entry.go create mode 100644 core/services/relay/evm/codec_entry_test.go diff --git a/core/services/ocr2/plugins/median/services.go b/core/services/ocr2/plugins/median/services.go index d3c666c83a8..2d213b3fa76 100644 --- a/core/services/ocr2/plugins/median/services.go +++ b/core/services/ocr2/plugins/median/services.go @@ -130,12 +130,12 @@ func NewMedianServices(ctx context.Context, CreatedAt: time.Now(), }, lggr) - if medianProvider.ChainReader() != nil { + /*if medianProvider.ChainReader() != nil { medianProvider = medianProviderWrapper{ medianProvider, // attach newer MedianContract which uses ChainReader newMedianContract(provider.ChainReader(), common.HexToAddress(spec.ContractID)), } - } + }*/ if cmdName := env.MedianPluginCmd.Get(); cmdName != "" { diff --git a/core/services/relay/evm/codec_entry.go b/core/services/relay/evm/codec_entry.go new file mode 100644 index 00000000000..2f32ddf752e --- /dev/null +++ b/core/services/relay/evm/codec_entry.go @@ -0,0 +1,150 @@ +package evm + +import ( + "reflect" + "strings" + + "github.com/ethereum/go-ethereum/accounts/abi" + relaytypes "github.com/smartcontractkit/chainlink-relay/pkg/types" + + "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types" +) + +type CodecEntry struct { + Args abi.Arguments + unwrappedArgs abi.Arguments + encodingPrefix []byte + checkedType reflect.Type + checkedArrayType reflect.Type + arraySize int + nativeType reflect.Type +} + +func (info *CodecEntry) Init() error { + if info.checkedType != nil { + return nil + } + + args := UnwrapArgs(info.Args) + info.unwrappedArgs = args + argLen := len(args) + native := make([]reflect.StructField, argLen) + checked := make([]reflect.StructField, argLen) + + for i, arg := range args { + if len(arg.Name) == 0 { + return relaytypes.InvalidTypeError{} + } + nativeArg, checkedArg, err := getNativeAndCheckedTypes(&arg.Type) + if err != nil { + return err + } + tag := reflect.StructTag(`json:"` + arg.Name + `"`) + name := strings.ToUpper(arg.Name[:1]) + arg.Name[1:] + native[i] = reflect.StructField{Name: name, Type: nativeArg, Tag: tag} + checked[i] = reflect.StructField{Name: name, Type: checkedArg, Tag: tag} + } + + info.nativeType = reflect.StructOf(native) + info.checkedType = reflect.StructOf(checked) + info.checkedArrayType, info.arraySize = getArrayType(checked) + return nil +} + +func UnwrapArgs(args abi.Arguments) abi.Arguments { + // Unwrap an unnamed tuple so that callers don't need to wrap it + // Eg: If you have struct Foo { ... } and return an unnamed Foo, you should be able ot decode to a go Foo{} directly + if len(args) != 1 || args[0].Name != "" { + return args + } + + elms := args[0].Type.TupleElems + if len(elms) != 0 { + names := args[0].Type.TupleRawNames + args = make(abi.Arguments, len(elms)) + for i, elm := range elms { + args[i] = abi.Argument{ + Name: names[i], + Type: *elm, + } + } + } + return args +} + +func getNativeAndCheckedTypes(curType *abi.Type) (reflect.Type, reflect.Type, error) { + converter := func(t reflect.Type) reflect.Type { return t } + for curType.Elem != nil { + prior := converter + switch curType.GetType().Kind() { + case reflect.Slice: + converter = func(t reflect.Type) reflect.Type { + return prior(reflect.SliceOf(t)) + } + curType = curType.Elem + case reflect.Array: + tmp := curType + converter = func(t reflect.Type) reflect.Type { + return prior(reflect.ArrayOf(tmp.Size, t)) + } + curType = curType.Elem + default: + return nil, nil, relaytypes.InvalidTypeError{} + } + } + base, ok := types.GetType(curType.String()) + if ok { + return converter(base.Native), converter(base.Checked), nil + } + + return createTupleType(curType, converter) +} + +func createTupleType(curType *abi.Type, converter func(reflect.Type) reflect.Type) (reflect.Type, reflect.Type, error) { + if len(curType.TupleElems) == 0 { + return nil, nil, relaytypes.InvalidTypeError{} + } + + nativeFields := make([]reflect.StructField, len(curType.TupleElems)) + checkedFields := make([]reflect.StructField, len(curType.TupleElems)) + for i, elm := range curType.TupleElems { + name := curType.TupleRawNames[i] + nativeFields[i].Name = name + checkedFields[i].Name = name + nativeArgType, checkedArgType, err := getNativeAndCheckedTypes(elm) + if err != nil { + return nil, nil, err + } + nativeFields[i].Type = nativeArgType + checkedFields[i].Type = checkedArgType + } + return converter(reflect.StructOf(nativeFields)), converter(reflect.StructOf(checkedFields)), nil +} + +func getArrayType(checked []reflect.StructField) (reflect.Type, int) { + checkedArray := make([]reflect.StructField, len(checked)) + length := 0 + for i, f := range checked { + kind := f.Type.Kind() + if kind == reflect.Slice { + if i == 0 { + length = 0 + } else if length != 0 { + return nil, 0 + } + } else if kind == reflect.Array { + if i == 0 { + length = f.Type.Len() + } else { + if f.Type.Len() != length { + return nil, 0 + } + } + } else { + return nil, 0 + } + + checkedArray[i] = reflect.StructField{Name: f.Name, Type: f.Type.Elem()} + } + return reflect.SliceOf(reflect.StructOf(checkedArray)), length +} diff --git a/core/services/relay/evm/codec_entry_test.go b/core/services/relay/evm/codec_entry_test.go new file mode 100644 index 00000000000..9fd4a6f4d15 --- /dev/null +++ b/core/services/relay/evm/codec_entry_test.go @@ -0,0 +1,137 @@ +package evm + +import ( + "math/big" + "reflect" + "testing" + + "github.com/ethereum/go-ethereum/accounts/abi" + relaytypes "github.com/smartcontractkit/chainlink-relay/pkg/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types" +) + +func TestCodecEntry(t *testing.T) { + t.Run("basic types", func(t *testing.T) { + type1, err := abi.NewType("uint16", "", []abi.ArgumentMarshaling{}) + require.NoError(t, err) + type2, err := abi.NewType("string", "", []abi.ArgumentMarshaling{}) + require.NoError(t, err) + type3, err := abi.NewType("uint24", "", []abi.ArgumentMarshaling{}) + require.NoError(t, err) + type4, err := abi.NewType("int24", "", []abi.ArgumentMarshaling{}) + require.NoError(t, err) + entry := CodecEntry{ + Args: abi.Arguments{ + {Name: "Field1", Type: type1}, + {Name: "Field2", Type: type2}, + {Name: "Field3", Type: type3}, + {Name: "Field4", Type: type4}, + }, + } + require.NoError(t, entry.Init()) + native := reflect.New(entry.nativeType) + iNative := reflect.Indirect(native) + iNative.FieldByName("Field1").Set(reflect.ValueOf(uint16(2))) + iNative.FieldByName("Field2").Set(reflect.ValueOf("any string")) + iNative.FieldByName("Field3").Set(reflect.ValueOf(big.NewInt( /*2^24 - 1*/ 16777215))) + iNative.FieldByName("Field4").Set(reflect.ValueOf(big.NewInt( /*2^23 - 1*/ 8388607))) + // native and checked point to the same item, even though they have different "types" + // they have the same memory layout so this is safe per unsafe casting rules, see unsafe.Pointer for details + checked := reflect.NewAt(entry.checkedType, native.UnsafePointer()) + iChecked := reflect.Indirect(checked) + checkedField := iChecked.FieldByName("Field3").Interface() + + sbi, ok := checkedField.(types.SizedBigInt) + require.True(t, ok) + assert.NoError(t, sbi.Verify()) + bi, ok := iNative.FieldByName("Field3").Interface().(*big.Int) + require.True(t, ok) + bi.Add(bi, big.NewInt(1)) + assert.IsType(t, relaytypes.InvalidTypeError{}, sbi.Verify()) + bi, ok = iNative.FieldByName("Field4").Interface().(*big.Int) + require.True(t, ok) + bi.Add(bi, big.NewInt(1)) + assert.IsType(t, relaytypes.InvalidTypeError{}, sbi.Verify()) + }) + + t.Run("tuples", func(t *testing.T) { + type1, err := abi.NewType("uint16", "", []abi.ArgumentMarshaling{}) + require.NoError(t, err) + tupleType, err := abi.NewType("tuple", "", []abi.ArgumentMarshaling{ + {Name: "Field3", Type: "uint24"}, + {Name: "Field4", Type: "int24"}, + }) + entry := CodecEntry{ + Args: abi.Arguments{ + {Name: "Field1", Type: type1}, + {Name: "Field2", Type: tupleType}, + }, + } + require.NoError(t, entry.Init()) + native := reflect.New(entry.nativeType) + iNative := reflect.Indirect(native) + iNative.FieldByName("Field1").Set(reflect.ValueOf(uint16(2))) + f2 := iNative.FieldByName("Field2") + f2.FieldByName("Field3").Set(reflect.ValueOf(big.NewInt( /*2^24 - 1*/ 16777215))) + f2.FieldByName("Field4").Set(reflect.ValueOf(big.NewInt( /*2^23 - 1*/ 8388607))) + // native and checked point to the same item, even though they have different "types" + // they have the same memory layout so this is safe per unsafe casting rules, see unsafe.Pointer for details + checked := reflect.NewAt(entry.checkedType, native.UnsafePointer()) + tuple := reflect.Indirect(checked).FieldByName("Field2") + checkedField := tuple.FieldByName("Field3").Interface() + + sbi, ok := checkedField.(types.SizedBigInt) + require.True(t, ok) + assert.NoError(t, sbi.Verify()) + bi, ok := f2.FieldByName("Field3").Interface().(*big.Int) + require.True(t, ok) + bi.Add(bi, big.NewInt(1)) + assert.IsType(t, relaytypes.InvalidTypeError{}, sbi.Verify()) + bi, ok = f2.FieldByName("Field4").Interface().(*big.Int) + require.True(t, ok) + bi.Add(bi, big.NewInt(1)) + assert.IsType(t, relaytypes.InvalidTypeError{}, sbi.Verify()) + }) + + t.Run("unwrapped types", func(t *testing.T) { + // This exists to allow you to decode single returned values without naming the parameter + wrappedTuple, err := abi.NewType("tuple", "", []abi.ArgumentMarshaling{ + {Name: "Field1", Type: "int16"}, + }) + require.NoError(t, err) + entry := CodecEntry{ + Args: abi.Arguments{{Name: "", Type: wrappedTuple}}, + } + require.NoError(t, entry.Init()) + native := reflect.New(entry.nativeType) + iNative := reflect.Indirect(native) + iNative.FieldByName("Field1").Set(reflect.ValueOf(int16(2))) + }) + + t.Run("slice types", func(t *testing.T) { + type1, err := abi.NewType("int16[]", "", []abi.ArgumentMarshaling{}) + require.NoError(t, err) + entry := CodecEntry{ + Args: abi.Arguments{{Name: "Field1", Type: type1}}, + } + require.NoError(t, entry.Init()) + native := reflect.New(entry.nativeType) + iNative := reflect.Indirect(native) + iNative.FieldByName("Field1").Set(reflect.ValueOf([]int16{2, 3})) + }) + + t.Run("array types", func(t *testing.T) { + type1, err := abi.NewType("int16[3]", "", []abi.ArgumentMarshaling{}) + require.NoError(t, err) + entry := CodecEntry{ + Args: abi.Arguments{{Name: "Field1", Type: type1}}, + } + require.NoError(t, entry.Init()) + native := reflect.New(entry.nativeType) + iNative := reflect.Indirect(native) + iNative.FieldByName("Field1").Set(reflect.ValueOf([3]int16{2, 3, 30})) + }) +} diff --git a/core/services/relay/evm/types/byte_types_gen.go b/core/services/relay/evm/types/byte_types_gen.go index e87b11c2336..568f60dc7f2 100755 --- a/core/services/relay/evm/types/byte_types_gen.go +++ b/core/services/relay/evm/types/byte_types_gen.go @@ -1,300 +1,303 @@ + package types import "reflect" -type bytes1 [1]byte +type bytes1 [1]byte func init() { - typeMap["bytes1"] = &AbiEncodingType{ - Native: reflect.TypeOf([1]byte{}), + typeMap["bytes1"] = &AbiEncodingType { + Native: reflect.TypeOf([1]byte{}), Checked: reflect.TypeOf(bytes1{}), } } -type bytes2 [2]byte +type bytes2 [2]byte func init() { - typeMap["bytes2"] = &AbiEncodingType{ - Native: reflect.TypeOf([2]byte{}), + typeMap["bytes2"] = &AbiEncodingType { + Native: reflect.TypeOf([2]byte{}), Checked: reflect.TypeOf(bytes2{}), } } -type bytes3 [3]byte +type bytes3 [3]byte func init() { - typeMap["bytes3"] = &AbiEncodingType{ - Native: reflect.TypeOf([3]byte{}), + typeMap["bytes3"] = &AbiEncodingType { + Native: reflect.TypeOf([3]byte{}), Checked: reflect.TypeOf(bytes3{}), } } -type bytes4 [4]byte +type bytes4 [4]byte func init() { - typeMap["bytes4"] = &AbiEncodingType{ - Native: reflect.TypeOf([4]byte{}), + typeMap["bytes4"] = &AbiEncodingType { + Native: reflect.TypeOf([4]byte{}), Checked: reflect.TypeOf(bytes4{}), } } -type bytes5 [5]byte +type bytes5 [5]byte func init() { - typeMap["bytes5"] = &AbiEncodingType{ - Native: reflect.TypeOf([5]byte{}), + typeMap["bytes5"] = &AbiEncodingType { + Native: reflect.TypeOf([5]byte{}), Checked: reflect.TypeOf(bytes5{}), } } -type bytes6 [6]byte +type bytes6 [6]byte func init() { - typeMap["bytes6"] = &AbiEncodingType{ - Native: reflect.TypeOf([6]byte{}), + typeMap["bytes6"] = &AbiEncodingType { + Native: reflect.TypeOf([6]byte{}), Checked: reflect.TypeOf(bytes6{}), } } -type bytes7 [7]byte +type bytes7 [7]byte func init() { - typeMap["bytes7"] = &AbiEncodingType{ - Native: reflect.TypeOf([7]byte{}), + typeMap["bytes7"] = &AbiEncodingType { + Native: reflect.TypeOf([7]byte{}), Checked: reflect.TypeOf(bytes7{}), } } -type bytes8 [8]byte +type bytes8 [8]byte func init() { - typeMap["bytes8"] = &AbiEncodingType{ - Native: reflect.TypeOf([8]byte{}), + typeMap["bytes8"] = &AbiEncodingType { + Native: reflect.TypeOf([8]byte{}), Checked: reflect.TypeOf(bytes8{}), } } -type bytes9 [9]byte +type bytes9 [9]byte func init() { - typeMap["bytes9"] = &AbiEncodingType{ - Native: reflect.TypeOf([9]byte{}), + typeMap["bytes9"] = &AbiEncodingType { + Native: reflect.TypeOf([9]byte{}), Checked: reflect.TypeOf(bytes9{}), } } -type bytes10 [10]byte +type bytes10 [10]byte func init() { - typeMap["bytes10"] = &AbiEncodingType{ - Native: reflect.TypeOf([10]byte{}), + typeMap["bytes10"] = &AbiEncodingType { + Native: reflect.TypeOf([10]byte{}), Checked: reflect.TypeOf(bytes10{}), } } -type bytes11 [11]byte +type bytes11 [11]byte func init() { - typeMap["bytes11"] = &AbiEncodingType{ - Native: reflect.TypeOf([11]byte{}), + typeMap["bytes11"] = &AbiEncodingType { + Native: reflect.TypeOf([11]byte{}), Checked: reflect.TypeOf(bytes11{}), } } -type bytes12 [12]byte +type bytes12 [12]byte func init() { - typeMap["bytes12"] = &AbiEncodingType{ - Native: reflect.TypeOf([12]byte{}), + typeMap["bytes12"] = &AbiEncodingType { + Native: reflect.TypeOf([12]byte{}), Checked: reflect.TypeOf(bytes12{}), } } -type bytes13 [13]byte +type bytes13 [13]byte func init() { - typeMap["bytes13"] = &AbiEncodingType{ - Native: reflect.TypeOf([13]byte{}), + typeMap["bytes13"] = &AbiEncodingType { + Native: reflect.TypeOf([13]byte{}), Checked: reflect.TypeOf(bytes13{}), } } -type bytes14 [14]byte +type bytes14 [14]byte func init() { - typeMap["bytes14"] = &AbiEncodingType{ - Native: reflect.TypeOf([14]byte{}), + typeMap["bytes14"] = &AbiEncodingType { + Native: reflect.TypeOf([14]byte{}), Checked: reflect.TypeOf(bytes14{}), } } -type bytes15 [15]byte +type bytes15 [15]byte func init() { - typeMap["bytes15"] = &AbiEncodingType{ - Native: reflect.TypeOf([15]byte{}), + typeMap["bytes15"] = &AbiEncodingType { + Native: reflect.TypeOf([15]byte{}), Checked: reflect.TypeOf(bytes15{}), } } -type bytes16 [16]byte +type bytes16 [16]byte func init() { - typeMap["bytes16"] = &AbiEncodingType{ - Native: reflect.TypeOf([16]byte{}), + typeMap["bytes16"] = &AbiEncodingType { + Native: reflect.TypeOf([16]byte{}), Checked: reflect.TypeOf(bytes16{}), } } -type bytes17 [17]byte +type bytes17 [17]byte func init() { - typeMap["bytes17"] = &AbiEncodingType{ - Native: reflect.TypeOf([17]byte{}), + typeMap["bytes17"] = &AbiEncodingType { + Native: reflect.TypeOf([17]byte{}), Checked: reflect.TypeOf(bytes17{}), } } -type bytes18 [18]byte +type bytes18 [18]byte func init() { - typeMap["bytes18"] = &AbiEncodingType{ - Native: reflect.TypeOf([18]byte{}), + typeMap["bytes18"] = &AbiEncodingType { + Native: reflect.TypeOf([18]byte{}), Checked: reflect.TypeOf(bytes18{}), } } -type bytes19 [19]byte +type bytes19 [19]byte func init() { - typeMap["bytes19"] = &AbiEncodingType{ - Native: reflect.TypeOf([19]byte{}), + typeMap["bytes19"] = &AbiEncodingType { + Native: reflect.TypeOf([19]byte{}), Checked: reflect.TypeOf(bytes19{}), } } -type bytes20 [20]byte +type bytes20 [20]byte func init() { - typeMap["bytes20"] = &AbiEncodingType{ - Native: reflect.TypeOf([20]byte{}), + typeMap["bytes20"] = &AbiEncodingType { + Native: reflect.TypeOf([20]byte{}), Checked: reflect.TypeOf(bytes20{}), } } -type bytes21 [21]byte +type bytes21 [21]byte func init() { - typeMap["bytes21"] = &AbiEncodingType{ - Native: reflect.TypeOf([21]byte{}), + typeMap["bytes21"] = &AbiEncodingType { + Native: reflect.TypeOf([21]byte{}), Checked: reflect.TypeOf(bytes21{}), } } -type bytes22 [22]byte +type bytes22 [22]byte func init() { - typeMap["bytes22"] = &AbiEncodingType{ - Native: reflect.TypeOf([22]byte{}), + typeMap["bytes22"] = &AbiEncodingType { + Native: reflect.TypeOf([22]byte{}), Checked: reflect.TypeOf(bytes22{}), } } -type bytes23 [23]byte +type bytes23 [23]byte func init() { - typeMap["bytes23"] = &AbiEncodingType{ - Native: reflect.TypeOf([23]byte{}), + typeMap["bytes23"] = &AbiEncodingType { + Native: reflect.TypeOf([23]byte{}), Checked: reflect.TypeOf(bytes23{}), } } -type bytes24 [24]byte +type bytes24 [24]byte func init() { - typeMap["bytes24"] = &AbiEncodingType{ - Native: reflect.TypeOf([24]byte{}), + typeMap["bytes24"] = &AbiEncodingType { + Native: reflect.TypeOf([24]byte{}), Checked: reflect.TypeOf(bytes24{}), } } -type bytes25 [25]byte +type bytes25 [25]byte func init() { - typeMap["bytes25"] = &AbiEncodingType{ - Native: reflect.TypeOf([25]byte{}), + typeMap["bytes25"] = &AbiEncodingType { + Native: reflect.TypeOf([25]byte{}), Checked: reflect.TypeOf(bytes25{}), } } -type bytes26 [26]byte +type bytes26 [26]byte func init() { - typeMap["bytes26"] = &AbiEncodingType{ - Native: reflect.TypeOf([26]byte{}), + typeMap["bytes26"] = &AbiEncodingType { + Native: reflect.TypeOf([26]byte{}), Checked: reflect.TypeOf(bytes26{}), } } -type bytes27 [27]byte +type bytes27 [27]byte func init() { - typeMap["bytes27"] = &AbiEncodingType{ - Native: reflect.TypeOf([27]byte{}), + typeMap["bytes27"] = &AbiEncodingType { + Native: reflect.TypeOf([27]byte{}), Checked: reflect.TypeOf(bytes27{}), } } -type bytes28 [28]byte +type bytes28 [28]byte func init() { - typeMap["bytes28"] = &AbiEncodingType{ - Native: reflect.TypeOf([28]byte{}), + typeMap["bytes28"] = &AbiEncodingType { + Native: reflect.TypeOf([28]byte{}), Checked: reflect.TypeOf(bytes28{}), } } -type bytes29 [29]byte +type bytes29 [29]byte func init() { - typeMap["bytes29"] = &AbiEncodingType{ - Native: reflect.TypeOf([29]byte{}), + typeMap["bytes29"] = &AbiEncodingType { + Native: reflect.TypeOf([29]byte{}), Checked: reflect.TypeOf(bytes29{}), } } -type bytes30 [30]byte +type bytes30 [30]byte func init() { - typeMap["bytes30"] = &AbiEncodingType{ - Native: reflect.TypeOf([30]byte{}), + typeMap["bytes30"] = &AbiEncodingType { + Native: reflect.TypeOf([30]byte{}), Checked: reflect.TypeOf(bytes30{}), } } -type bytes31 [31]byte +type bytes31 [31]byte func init() { - typeMap["bytes31"] = &AbiEncodingType{ - Native: reflect.TypeOf([31]byte{}), + typeMap["bytes31"] = &AbiEncodingType { + Native: reflect.TypeOf([31]byte{}), Checked: reflect.TypeOf(bytes31{}), } } -type bytes32 [32]byte +type bytes32 [32]byte func init() { - typeMap["bytes32"] = &AbiEncodingType{ - Native: reflect.TypeOf([32]byte{}), + typeMap["bytes32"] = &AbiEncodingType { + Native: reflect.TypeOf([32]byte{}), Checked: reflect.TypeOf(bytes32{}), } } -type bytes0 [0]byte +type bytes0 [0]byte func init() { - typeMap["bytes0"] = &AbiEncodingType{ - Native: reflect.TypeOf([0]byte{}), + typeMap["bytes0"] = &AbiEncodingType { + Native: reflect.TypeOf([0]byte{}), Checked: reflect.TypeOf(bytes0{}), } } + + diff --git a/core/services/relay/evm/types/gen.go b/core/services/relay/evm/types/gen.go index 0fe0df08cd9..4a8a314eb6b 100644 --- a/core/services/relay/evm/types/gen.go +++ b/core/services/relay/evm/types/gen.go @@ -31,13 +31,8 @@ func genInts() { continue } - signed := &IntType{Size: i} - - unsigned := &IntType{ - Prefix: "u", - Size: i, - Signed: true, - } + signed := &IntType{Size: i, Signed: false} + unsigned := &IntType{Prefix: "u", Size: i} intTypes = append(intTypes, signed, unsigned) } runTemplate("ints", intsTemplate, "int_types_gen.go", intTypes) @@ -77,7 +72,7 @@ import "reflect" {{ range . }} type bytes{{.Size}} [{{.Size}}]byte func init() { - typeMap["bytes{{.Size}}"] = &abiEncodingType { + typeMap["bytes{{.Size}}"] = &AbiEncodingType { Native: reflect.TypeOf([{{.Size}}]byte{}), Checked: reflect.TypeOf(bytes{{.Size}}{}), } @@ -95,7 +90,6 @@ import ( "github.com/fxamacker/cbor/v2" "github.com/smartcontractkit/chainlink-relay/pkg/types" - "github.com/smartcontractkit/chainlink-relay/pkg/codec" ) type SizedBigInt interface { @@ -145,7 +139,7 @@ func (i *{{.Prefix}}int{{.Size}}) Verify() error { func (i *{{.Prefix}}int{{.Size}}) private() {} func init() { - typeMap["{{.Prefix}}int{{.Size}}"] = &abiEncodingType { + typeMap["{{.Prefix}}int{{.Size}}"] = &AbiEncodingType { Native: reflect.TypeOf((*big.Int)(nil)), Checked: reflect.TypeOf((*{{.Prefix}}int{{.Size}})(nil)), } diff --git a/core/services/relay/evm/types/int_types_gen.go b/core/services/relay/evm/types/int_types_gen.go index d22b6050fe9..2bf1e0672f8 100755 --- a/core/services/relay/evm/types/int_types_gen.go +++ b/core/services/relay/evm/types/int_types_gen.go @@ -5,7 +5,6 @@ import ( "reflect" "github.com/fxamacker/cbor/v2" - "github.com/smartcontractkit/chainlink-relay/pkg/codec" "github.com/smartcontractkit/chainlink-relay/pkg/types" ) @@ -82,7 +81,7 @@ func (i *uint24) UnmarshalText(input []byte) error { func (i *uint24) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(24, bi) { + if bi.BitLen() > 24 { return types.InvalidTypeError{} } @@ -160,7 +159,7 @@ func (i *uint40) UnmarshalText(input []byte) error { func (i *uint40) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(40, bi) { + if bi.BitLen() > 40 { return types.InvalidTypeError{} } @@ -238,7 +237,7 @@ func (i *uint48) UnmarshalText(input []byte) error { func (i *uint48) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(48, bi) { + if bi.BitLen() > 48 { return types.InvalidTypeError{} } @@ -316,7 +315,7 @@ func (i *uint56) UnmarshalText(input []byte) error { func (i *uint56) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(56, bi) { + if bi.BitLen() > 56 { return types.InvalidTypeError{} } @@ -394,7 +393,7 @@ func (i *uint72) UnmarshalText(input []byte) error { func (i *uint72) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(72, bi) { + if bi.BitLen() > 72 { return types.InvalidTypeError{} } @@ -472,7 +471,7 @@ func (i *uint80) UnmarshalText(input []byte) error { func (i *uint80) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(80, bi) { + if bi.BitLen() > 80 { return types.InvalidTypeError{} } @@ -550,7 +549,7 @@ func (i *uint88) UnmarshalText(input []byte) error { func (i *uint88) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(88, bi) { + if bi.BitLen() > 88 { return types.InvalidTypeError{} } @@ -628,7 +627,7 @@ func (i *uint96) UnmarshalText(input []byte) error { func (i *uint96) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(96, bi) { + if bi.BitLen() > 96 { return types.InvalidTypeError{} } @@ -706,7 +705,7 @@ func (i *uint104) UnmarshalText(input []byte) error { func (i *uint104) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(104, bi) { + if bi.BitLen() > 104 { return types.InvalidTypeError{} } @@ -784,7 +783,7 @@ func (i *uint112) UnmarshalText(input []byte) error { func (i *uint112) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(112, bi) { + if bi.BitLen() > 112 { return types.InvalidTypeError{} } @@ -862,7 +861,7 @@ func (i *uint120) UnmarshalText(input []byte) error { func (i *uint120) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(120, bi) { + if bi.BitLen() > 120 { return types.InvalidTypeError{} } @@ -940,7 +939,7 @@ func (i *uint128) UnmarshalText(input []byte) error { func (i *uint128) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(128, bi) { + if bi.BitLen() > 128 { return types.InvalidTypeError{} } @@ -1018,7 +1017,7 @@ func (i *uint136) UnmarshalText(input []byte) error { func (i *uint136) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(136, bi) { + if bi.BitLen() > 136 { return types.InvalidTypeError{} } @@ -1096,7 +1095,7 @@ func (i *uint144) UnmarshalText(input []byte) error { func (i *uint144) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(144, bi) { + if bi.BitLen() > 144 { return types.InvalidTypeError{} } @@ -1174,7 +1173,7 @@ func (i *uint152) UnmarshalText(input []byte) error { func (i *uint152) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(152, bi) { + if bi.BitLen() > 152 { return types.InvalidTypeError{} } @@ -1252,7 +1251,7 @@ func (i *uint160) UnmarshalText(input []byte) error { func (i *uint160) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(160, bi) { + if bi.BitLen() > 160 { return types.InvalidTypeError{} } @@ -1330,7 +1329,7 @@ func (i *uint168) UnmarshalText(input []byte) error { func (i *uint168) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(168, bi) { + if bi.BitLen() > 168 { return types.InvalidTypeError{} } @@ -1408,7 +1407,7 @@ func (i *uint176) UnmarshalText(input []byte) error { func (i *uint176) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(176, bi) { + if bi.BitLen() > 176 { return types.InvalidTypeError{} } @@ -1486,7 +1485,7 @@ func (i *uint184) UnmarshalText(input []byte) error { func (i *uint184) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(184, bi) { + if bi.BitLen() > 184 { return types.InvalidTypeError{} } @@ -1564,7 +1563,7 @@ func (i *uint192) UnmarshalText(input []byte) error { func (i *uint192) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(192, bi) { + if bi.BitLen() > 192 { return types.InvalidTypeError{} } @@ -1642,7 +1641,7 @@ func (i *uint200) UnmarshalText(input []byte) error { func (i *uint200) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(200, bi) { + if bi.BitLen() > 200 { return types.InvalidTypeError{} } @@ -1720,7 +1719,7 @@ func (i *uint208) UnmarshalText(input []byte) error { func (i *uint208) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(208, bi) { + if bi.BitLen() > 208 { return types.InvalidTypeError{} } @@ -1798,7 +1797,7 @@ func (i *uint216) UnmarshalText(input []byte) error { func (i *uint216) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(216, bi) { + if bi.BitLen() > 216 { return types.InvalidTypeError{} } @@ -1876,7 +1875,7 @@ func (i *uint224) UnmarshalText(input []byte) error { func (i *uint224) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(224, bi) { + if bi.BitLen() > 224 { return types.InvalidTypeError{} } @@ -1954,7 +1953,7 @@ func (i *uint232) UnmarshalText(input []byte) error { func (i *uint232) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(232, bi) { + if bi.BitLen() > 232 { return types.InvalidTypeError{} } @@ -2032,7 +2031,7 @@ func (i *uint240) UnmarshalText(input []byte) error { func (i *uint240) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(240, bi) { + if bi.BitLen() > 240 { return types.InvalidTypeError{} } @@ -2110,7 +2109,7 @@ func (i *uint248) UnmarshalText(input []byte) error { func (i *uint248) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(248, bi) { + if bi.BitLen() > 248 { return types.InvalidTypeError{} } @@ -2188,7 +2187,7 @@ func (i *uint256) UnmarshalText(input []byte) error { func (i *uint256) Verify() error { bi := (*big.Int)(i) - if !codec.FitsInNBitsSigned(256, bi) { + if bi.BitLen() > 256 { return types.InvalidTypeError{} } diff --git a/go.mod b/go.mod index 62f1823671a..5d612b4c5d8 100644 --- a/go.mod +++ b/go.mod @@ -387,10 +387,14 @@ replace ( // until merged upstream: https://github.com/hashicorp/go-plugin/pull/257 github.com/hashicorp/go-plugin => github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306 + // until merged upstream: https://github.com/mitchellh/mapstructure/pull/343 + github.com/mitchellh/mapstructure v1.5.0 => github.com/nolag/mapstructure v1.5.1 + // until merged upstream: https://github.com/mwitkow/grpc-proxy/pull/69 github.com/mwitkow/grpc-proxy => github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f github.com/smartcontractkit/chainlink-cosmos => github.com/smartcontractkit/chainlink-cosmos v0.0.0-20231102020720-36bfe1e78327 - github.com/smartcontractkit/chainlink-relay => github.com/smartcontractkit/chainlink-relay v0.0.0-20231107215547-ee2e975fb9d9 github.com/smartcontractkit/chainlink-solana => github.com/smartcontractkit/chainlink-solana v0.0.0-20231101173529-89dcfddba1e5 github.com/smartcontractkit/chainlink-starknet/relayer => github.com/smartcontractkit/chainlink-starknet/relayer v0.0.0-20231102015854-0056a86b5f79 ) + +replace github.com/smartcontractkit/chainlink-relay => ../chainlink-relay diff --git a/go.sum b/go.sum index fe53fb41bc9..d65e9b0a8aa 100644 --- a/go.sum +++ b/go.sum @@ -1216,8 +1216,6 @@ github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS4 github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= -github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= @@ -1300,6 +1298,8 @@ github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E= +github.com/nolag/mapstructure v1.5.1 h1:jEMB2AM8NXEosSMTPXlbycOpBsqttEBh5owT0gJs9/I= +github.com/nolag/mapstructure v1.5.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249 h1:NHrXEjTNQY7P0Zfx1aMrNhpgxHmow66XQtm0aQLY0AE= github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249/go.mod h1:mpRZBD8SJ55OIICQ3iWH0Yz3cjzA61JdqMLoWXeB2+8= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= @@ -1466,8 +1466,6 @@ github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumv github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M= github.com/smartcontractkit/chainlink-cosmos v0.0.0-20231102020720-36bfe1e78327 h1:xK/s3uOJ/61f8Uft0dmdzcP/mAur3EW7r+enB30E7QE= github.com/smartcontractkit/chainlink-cosmos v0.0.0-20231102020720-36bfe1e78327/go.mod h1:O+lgu0V2gxAjT2iFUQbR5VmIwKBodc18t/GqMcM5DpY= -github.com/smartcontractkit/chainlink-relay v0.0.0-20231107215547-ee2e975fb9d9 h1:Hcf/XrETO4AJLrgYxS9k2Nm1oOf2CouWNnWdx+cOL8M= -github.com/smartcontractkit/chainlink-relay v0.0.0-20231107215547-ee2e975fb9d9/go.mod h1:Mjha9nHB4BUvHvLKVQ5uko42sahSMjbLoznqjnjxEUQ= github.com/smartcontractkit/chainlink-solana v0.0.0-20231101173529-89dcfddba1e5 h1:uySFwg07nbs/klbSpTP/JVvMALhaHwSK3ZBfIaISu1s= github.com/smartcontractkit/chainlink-solana v0.0.0-20231101173529-89dcfddba1e5/go.mod h1:s8/Dcey8y1C88zap2G2hAjO0sN8LbxW/t3PZ1Y2T/xk= github.com/smartcontractkit/chainlink-starknet/relayer v0.0.0-20231102015854-0056a86b5f79 h1:nVgHp+0dX8q+m+wWGJiBsSkgktarMx2iV+G0qEKEpmU=