From 53b91cb872c40b0ed4f2c2c5e932223f052cc971 Mon Sep 17 00:00:00 2001 From: Andrew Low Date: Wed, 14 Feb 2024 22:05:55 -0500 Subject: [PATCH] properly evmMarshal evm_log_params --- analyzer/evmabibackfill/evm_abi_backfill.go | 2 +- analyzer/runtime/abiparse/abiparse.go | 8 ++++---- analyzer/runtime/abiparse/abiparse_test.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/analyzer/evmabibackfill/evm_abi_backfill.go b/analyzer/evmabibackfill/evm_abi_backfill.go index 5b89e6089..54eb3535d 100644 --- a/analyzer/evmabibackfill/evm_abi_backfill.go +++ b/analyzer/evmabibackfill/evm_abi_backfill.go @@ -280,7 +280,7 @@ func marshalArgs(abiArgs abi.Arguments, argVals []interface{}) ([]*abiEncodedArg args = append(args, &abiEncodedArg{ Name: abiArgs[i].Name, EvmType: abiArgs[i].Type.String(), - Value: v, + Value: abiparse.EvmPreMarshal(v, abiArgs[i].Type), }) } diff --git a/analyzer/runtime/abiparse/abiparse.go b/analyzer/runtime/abiparse/abiparse.go index 14761ea06..d0062477a 100644 --- a/analyzer/runtime/abiparse/abiparse.go +++ b/analyzer/runtime/abiparse/abiparse.go @@ -9,11 +9,11 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" ) -// evmPreMarshal converts v to a type that gives us the JSON serialization that we like: +// EvmPreMarshal converts v to a type that gives us the JSON serialization that we like: // - large integers are JSON strings instead of JSON numbers // - byte array types are JSON strings of base64 instead of JSON arrays of numbers // Contrived dot for godot linter: . -func evmPreMarshal(v interface{}, t abi.Type) interface{} { +func EvmPreMarshal(v interface{}, t abi.Type) interface{} { switch t.T { case abi.IntTy, abi.UintTy: if t.Size > 32 { @@ -23,14 +23,14 @@ func evmPreMarshal(v interface{}, t abi.Type) interface{} { rv := reflect.ValueOf(v) slice := make([]interface{}, 0, rv.Len()) for i := 0; i < rv.Len(); i++ { - slice = append(slice, evmPreMarshal(rv.Index(i).Interface(), *t.Elem)) + slice = append(slice, EvmPreMarshal(rv.Index(i).Interface(), *t.Elem)) } return slice case abi.TupleTy: rv := reflect.ValueOf(v) m := map[string]interface{}{} for i, fieldName := range t.TupleRawNames { - m[fieldName] = evmPreMarshal(rv.Field(i).Interface(), *t.TupleElems[i]) + m[fieldName] = EvmPreMarshal(rv.Field(i).Interface(), *t.TupleElems[i]) } case abi.FixedBytesTy, abi.FunctionTy: c := reflect.New(t.GetType()).Elem() diff --git a/analyzer/runtime/abiparse/abiparse_test.go b/analyzer/runtime/abiparse/abiparse_test.go index ec5ae6f12..1ea16a83e 100644 --- a/analyzer/runtime/abiparse/abiparse_test.go +++ b/analyzer/runtime/abiparse/abiparse_test.go @@ -46,7 +46,7 @@ func TestParseTypes(t *testing.T) { "{\"n\":1,\"s\":\"a\"}", // O } for i, input := range method.Inputs { - transducedArg := evmPreMarshal(args[i], input.Type) + transducedArg := EvmPreMarshal(args[i], input.Type) jsonBytesArg, err1 := json.Marshal(transducedArg) require.NoError(t, err1) require.Equal(t, jsonExpected[i], string(jsonBytesArg))